2 ###########################################################################
4 ## Simplified perl version of CPQLOCFG
5 ## Copyright 2003,2007 Hewlett Packard Development Company, L.P.
7 ## To use this program, you must have Net::SSLeay and IO::Socket::SSL
8 ## installed. You may obtain these modules from http://www.cpan.org/
10 ## You may use and modify this program to suit your needs.
12 ###########################################################################
21 print " locfg -s server [-l logfile] -f inputfile [-u username -p password]\n";
22 print " Note: Use -u and -p with caution as command line options are\n";
23 print " visible on Linux.\n";
30 print " Both username and password must be specified with the -u and -p switches.\n";
31 print " Use -u and -p with caution as command line options are visible on Linux.\n";
34 ###########################################################################
38 ###########################################################################
40 my $host, $logfile, $file, $verbose, $help, $uname, $pword;
42 $r = GetOptions("server|s=s" => \$host,
43 "logfile|l=s" => \$logfile,
44 "input|f=s" => \$file,
47 "verbose" => \$verbose,
51 if ($help || !$host || !$file) {
55 # Username and Password must be entered together
56 if( ($uname && !($pword)) || (!($uname) && $pword) ) {
61 # If a logfile is specified, open it and select it as the default
63 open(L, ">$logfile") || die "Can't open $logfile\n";
67 # Set the default SSL port number if no port is specified
68 $host .= ":443" unless ($host =~ m/:/);
70 # Open the SSL connection and the input file
71 my $client = new IO::Socket::SSL->new(PeerAddr => $host);
73 print "ERROR: Failed to establish SSL connection with $host.\n";
77 open(F, "<$file") || die "Can't open $file\n";
79 # Send the XML header and begin processing the file
80 print $client '<?xml version="1.0"?>' . "\r\n";
82 # Chomp of any EOL characters
86 if ((($ln =~ ?<[ ]*LOGIN[ ]?) || ($ln =~ ?<[ ]*LOGIN$?)) && ($pword) && ($uname)) {
87 while( !($ln =~ m/\>/i) ) {
90 print $client "<LOGIN USER_LOGIN=\"$uname\" PASSWORD=\"$pword\">\n";
91 print "\n<LOGIN USER_LOGIN=\"$uname\" PASSWORD=\"$pword\">\n" if ($verbose);
92 # print "\nOverriding credentials in scripts with those from command line.\n" if ($verbose);
96 # Special case: UPDATE_RIB_FIRMWARE violates XML. Send the full
97 # UPDATE firmware tag followed by the binary firmware image
98 if ($ln =~ m/UPDATE_RIB_FIRMWARE/i) {
99 if ($ln =~ m/IMAGE_LOCATION=\"(.*)\"/i) {
101 open(G, "<$firmware") || die "Can't open $firmware\n";
103 print $client "\r\n<UPDATE_RIB_FIRMWARE IMAGE_LOCATION=\"$firmware\" IMAGE_LENGTH=\"$len\"/>\r\n";
104 print "\r\n<UPDATE_RIB_FIRMWARE IMAGE_LOCATION=\"$firmware\" IMAGE_LENGTH=\"$len\"/>\r\n" if ($verbose);
105 $x = read(G, $buf, $len);
106 print "Read $x bytes from $firmware\n" if ($verbose);
107 $x = $client->write($buf, $x);
108 print "Wrote $x bytes\n" if ($verbose);
112 # print "\nError: syntax error detected in $ln\n" if ($verbose);
114 # Send the script to the iLO board
115 print $ln . "\n" if ($verbose);
116 print $client $ln . "\r\n" ;
120 print "----\n" if ($verbose);
122 # Ok, now read the responses back from iLO
123 while($ln=<$client>) {
124 last if (length($ln) == 0);
126 # This isn't really required, but it makes the output look nicer
127 $ln =~ s/<\/RIBCL>/<\/RIBCL>\n/g;