root/trunk/midgard/tools/yamp/insert_login.pl

Revision 6552, 2.3 kB (checked in by philipp, 8 years ago)
  • replace_host.pl: neues script zum ersetzen von hostname, port
    und prefix eines hostrecords
  • insert_login.pl: kleine verbesserungen (sauberes handling von
    CDATA-sections, usage output)
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl
2 # - - - - -
3 # $Id$
4 # - - - - -
5 #
6 # insert_login
7 #
8 # Insert login and password into a repligard XML person record
9 #
10 #
11 # Copyright (C) 2001 Linksystem Muenchen GmbH, Philipp Rotmann
12 #                    <ph.rotmann@buero.link-m.de>
13 #
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU Library General Public
25 # License along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
27 # USA
28 # - - - - -
29
30 use XML::DOM;
31
32 if (@ARGV == 3) {
33         ($guid, $new_username, $new_password) = @ARGV;
34
35 } else {
36         print <<"END_USAGE";
37
38 insert_login guid username password
39
40   guid       The Global Unique ID of the person record to change
41   username   Login name to insert
42   password   Password to insert
43
44 The XML stream is expected from STDIN.
45 END_USAGE
46 }
47
48
49 $xdp = new XML::DOM::Parser(Style => Tree, KeepCDATA => 1);
50 $xml = $xdp->parse(*STDIN);
51
52 foreach my $pnode ($xml->getElementsByTagName('person')) {
53         next unless ($pnode->getAttribute('id') eq $guid);
54
55         print STDERR "Found person record $guid:\n";
56
57         $uelement = ${$pnode->getElementsByTagName('username')}[0];
58         if ($username = $uelement->getFirstChild) {
59                 print STDERR "Old username: ", $username->getData, "\n";
60         } else {
61                 die "$!" unless ($username =
62                   $uelement->appendChild($xml->createCDATASection("")));
63         }
64
65         $pelement = ${$pnode->getElementsByTagName('password')}[0];
66         if ($password = $pelement->getFirstChild) {
67                 print STDERR "Old password: ", $password->getData, "\n";
68         } else {
69                 die "$!" unless ($password =
70                   $pelement->appendChild($xml->createCDATASection("")));
71         }
72
73         print STDERR "Changing username and password ... ";
74         $username->setData($new_username); $password->setData($new_password);
75         print STDERR "done.\n";
76 }
77
78 $xml->printToFileHandle(\*STDOUT);
79 $xml->dispose;
Note: See TracBrowser for help on using the browser.