| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 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; |
|---|