From be101700bb10bac9a432c153490e9db9031a5d61 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 4 Feb 2009 23:33:44 +0100 Subject: [PATCH 01/16] more save/load fixes --- rsbs2.pl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index e25808a..0843330 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -38,7 +38,7 @@ my @fw_vars = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX GATEWAY DIAG_URL ENABLE_ANON_IPMI ENABLE_ANON_PCI ENABLE_ANON_WEB ENABLE_AVR_CHIP_DETECT ENABLE_BMC_AUTODETECT ENABLE_BMC_TIMESYNC ENABLE_CRTC_FETCH ENABLE_DHCP ENABLE_DHCP_HOSTNAME - ENABLE_DNS ENABLE_DS_CONNECTIVITY ENABLE_IO_UART_DECODER ENABLE_LAN_100 + ENABLE_DS_CONNECTIVITY ENABLE_IO_UART_DECODER ENABLE_LAN_100 ENABLE_LAN_AUTONEG ENABLE_LAN_FDUPLEX ENABLE_MEM_UART_DECODER ENABLE_PPP ENABLE_REMOTE_FLOPPY_BOOT ENABLE_SELF_DELETE ENABLE_SERIAL_DBG ETHDRIVER_SID EXPROM_BANNER EXPROM_EBDA_COMPATIBILITY @@ -485,8 +485,15 @@ if (@sprop) { } if ($save ne '') { - my @dontsave = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX GATEWAY - IP_ADDRESS NETMASK TFTP_FIRMWARE_FILE TFTP_ADDR_FIRMWARE ENABLE_DHCP); + my @dontsave = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX + GATEWAY IP_ADDRESS NETMASK TFTP_FIRMWARE_FILE TFTP_ADDR_FIRMWARE + ENABLE_DHCP HELP_LOCATION HELP_LOCATION PPP_PORT PPP2_INIT PPP2_PORT + SERVER_ID SNMP_SERVER_1 SNMP_SERVER_2 SNMP_SERVER_3 SNMP_SERVER_4 + SNMP_SERVER_5 SNMP_SERVER_6 SNMP_SERVER_7 SERVER_AD_NAME + SERVER_AD_NAME2 SERVER_AD_NAME3 SERVER_AD_NAME4 SERVER_MAC_ADDRESS + SERVER_MAC_ADDRESS2 SERVER_MAC_ADDRESS3 SERVER_MAC_ADDRESS4 + MAC_ADDRESS LAST_CARD_NAME LAST_ENABLE_DHCP LAST_GATEWAY + LAST_IP_ADDRESS LAST_NETMASK); open (SAVEFILE, ">${save}") || die "Error opening save-file: $!\n"; foreach my $ts (@fw_vars) { @@ -508,6 +515,10 @@ if ($load ne '') { setprop($p, $v); } close(LOADFILE); + print "Settings loaded, resetting board...\n"; + my $reqstr=''; + _req($reqstr); + exit(0); } if ($enable_debug ne '') { -- 2.39.2 From 3de486aeb82f17284ba67e8a3ab40db20813b5da Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 4 Feb 2009 23:55:49 +0100 Subject: [PATCH 02/16] use unified write_file function everywhere... --- filesystem.c | 30 ++++++++++++++++++------------ filesystem.h | 1 + firmware.c | 19 ++----------------- rsb-lz.c | 3 +-- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/filesystem.c b/filesystem.c index 175cbc4..d4b207e 100644 --- a/filesystem.c +++ b/filesystem.c @@ -86,11 +86,11 @@ void extract_files(unsigned char *fw, int len) fent = get_next_file(fw, len); while (fent) { - printf("%s: unknown: 0x%02x, length: %d", + printf("%s: unknown: 0x%02x, length: %d, ", fent->name, fent->unknown, fent->length); if (fent->length > 0) { - write_file(fent->name, fent->start, fent->length); + write_file(extracted_file(fent->name), fent->start, fent->length); if (*((unsigned int*)fent->start) == LZ_MAGIC) { char *lzname; @@ -105,7 +105,7 @@ void extract_files(unsigned char *fw, int len) } lzname[strlen(lzname) - 3] = 0x00; - printf("%s: packed file found", lzname); + printf("%s: packed file found, ", lzname); extract_lz_file(fent->start, (unsigned char*)lzname, 0); free(lzname); @@ -120,7 +120,7 @@ void extract_files(unsigned char *fw, int len) memcpy(lzname + strlen(lzname), lzpos - 4, 4); lzpos += 4; if (*((unsigned int*)(lzpos)) == LZ_MAGIC) { - printf("%s: compressed firmware part found", lzname); + printf("%s: compressed firmware part found, ", lzname); extract_lz_file(lzpos, (unsigned char*)lzname, 1); } } @@ -174,16 +174,12 @@ void mkdir_p(char *dir) void write_file(char *fname, unsigned char *buf, int len) { - char filename[PATH_MAX]; char *filename_c, *dirn; int fd; int remaining; int ret; - strcpy(filename, "extracted/"); - strcat(filename, fname); - - if ((filename_c = strdup(filename)) == NULL) { + if ((filename_c = strdup(fname)) == NULL) { perror("strdup"); exit(1); } @@ -191,8 +187,8 @@ void write_file(char *fname, unsigned char *buf, int len) mkdir_p(dirn); free(filename_c); - if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) == -1) { - fprintf(stderr, "%s: ", filename); + if ((fd = open(fname, O_WRONLY|O_CREAT, 0644)) == -1) { + fprintf(stderr, "%s: ", fname); perror("open"); exit(1); } @@ -208,7 +204,17 @@ void write_file(char *fname, unsigned char *buf, int len) remaining -= ret; } - printf(", %s written.\n", filename); + printf("%s written.\n", fname); close(fd); } + +char *extracted_file(char *fname) +{ + static char filename[PATH_MAX]; + + strcpy(filename, "extracted/"); + strcat(filename, fname); + + return filename; +} diff --git a/filesystem.h b/filesystem.h index d4b91c7..bf9a4c8 100644 --- a/filesystem.h +++ b/filesystem.h @@ -10,3 +10,4 @@ void extract_files(unsigned char *fw, int len); void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname); void list_files(unsigned char *fw, int len); void write_file(char *fname, unsigned char *buf, int len); +char *extracted_file(char *fname); diff --git a/firmware.c b/firmware.c index 80e12e5..b575012 100644 --- a/firmware.c +++ b/firmware.c @@ -519,23 +519,8 @@ int main(int argc, char **argv) strcpy(newfile, file); strcat(newfile, ".patched"); - printf("Writing %s\n", newfile); - if ((fd = open(newfile, O_WRONLY|O_CREAT, 0644)) == -1) { - fprintf(stderr,"%s: ", newfile); - perror("open"); - exit(1); - } - - remaining = statbuf.st_size; - - while(remaining) { - if ((ret = write(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) { - perror("write"); - exit(1); - } - remaining -= ret; - } - close(fd); + printf("Firmware "); + write_file(newfile, fw, statbuf.st_size); } else { fprintf(stderr,"Can't set correct checksum, aborting...\n"); } diff --git a/rsb-lz.c b/rsb-lz.c index 2e50252..c771b89 100644 --- a/rsb-lz.c +++ b/rsb-lz.c @@ -312,8 +312,7 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch err_exit(__func__); } } - - write_file((char*)name, outbuf, len); + write_file(extracted_file((char*)name), outbuf, len); free(outbuf); } -- 2.39.2 From 8bec7e22a46448bf11aabff62818de14af8c4f06 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 00:00:29 +0100 Subject: [PATCH 03/16] fix comment about ATX connectors --- README.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index d31f16f..33cd625 100644 --- a/README.txt +++ b/README.txt @@ -74,4 +74,5 @@ CONN1: CONN2: CONN3: J1(?): J2(Standby?): D) E) -*) do not use, pulled up to 1,00V when not activated +*) use to connect to the front panel button and pinheader on the mainboard, + beware of the polarity! -- 2.39.2 From 75085d94afa9ad53ae3ac294af7119712b4789e7 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 00:08:31 +0100 Subject: [PATCH 04/16] CLI cleanups --- rsbs2.pl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 0843330..2d7ec2a 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -196,8 +196,10 @@ sub setprop { if ($res->{RESP}->{RC} ne '0x0') { print "Error setting ${property} to ${value}: ".$res->{RESP}->{RC}."\n"; + undef; } else { - print "${property}: ${oldval} -> ${value}\n"; + print "${property}: ${oldval} -> ${value}\n" if ($verbose); + $oldval; } } @@ -480,7 +482,10 @@ if (@gprop) { if (@sprop) { foreach my $p (@sprop) { (my $pr, $v) = split(/=/,$p,2); - setprop($pr, $v); + my $oldval = setprop($pr, $v); + if (defined($oldval)) { + print "${pr}: ${oldval} -> ${v}\n" if (!$verbose); + } } } @@ -496,6 +501,7 @@ if ($save ne '') { LAST_IP_ADDRESS LAST_NETMASK); open (SAVEFILE, ">${save}") || die "Error opening save-file: $!\n"; + print STDERR "saving" if (!$verbose); foreach my $ts (@fw_vars) { next if (grep(/^${ts}$/, @dontsave)); @@ -503,18 +509,23 @@ if ($save ne '') { next if ($phash->{PERMS} ne 'RW'); print SAVEFILE "${ts}=".$phash->{VAL}."\n"; + print STDERR "." if (!$verbose); } close(SAVEFILE); + print STDERR "done\n" if (!$verbose); } if ($load ne '') { open (LOADFILE, "<${load}") || die "Error opening load-file: $!\n"; + print STDERR "loading" if (!$verbose); while() { chomp; (my $p, my $v) = split(/=/, $_); setprop($p, $v); + print STDERR "." if (!$verbose); } close(LOADFILE); + print STDERR "done\n" if (!$verbose); print "Settings loaded, resetting board...\n"; my $reqstr=''; _req($reqstr); -- 2.39.2 From 98f1f9afb96af2660ea590c4d32c27e0a7887202 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 07:57:54 +0100 Subject: [PATCH 05/16] correctly retrieve empty settings --- rsbs2.pl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 2d7ec2a..a481f45 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -151,7 +151,7 @@ sub _req { $request->content($xml); $response = $ua->request($request); die("Error in request: " . $response->status_line . "\n") unless ($response->is_success); - XMLin($response->content); + XMLin($response->content, SuppressEmpty => ''); } sub _getprop { @@ -492,12 +492,7 @@ if (@sprop) { if ($save ne '') { my @dontsave = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX GATEWAY IP_ADDRESS NETMASK TFTP_FIRMWARE_FILE TFTP_ADDR_FIRMWARE - ENABLE_DHCP HELP_LOCATION HELP_LOCATION PPP_PORT PPP2_INIT PPP2_PORT - SERVER_ID SNMP_SERVER_1 SNMP_SERVER_2 SNMP_SERVER_3 SNMP_SERVER_4 - SNMP_SERVER_5 SNMP_SERVER_6 SNMP_SERVER_7 SERVER_AD_NAME - SERVER_AD_NAME2 SERVER_AD_NAME3 SERVER_AD_NAME4 SERVER_MAC_ADDRESS - SERVER_MAC_ADDRESS2 SERVER_MAC_ADDRESS3 SERVER_MAC_ADDRESS4 - MAC_ADDRESS LAST_CARD_NAME LAST_ENABLE_DHCP LAST_GATEWAY + ENABLE_DHCP MAC_ADDRESS LAST_CARD_NAME LAST_ENABLE_DHCP LAST_GATEWAY LAST_IP_ADDRESS LAST_NETMASK); open (SAVEFILE, ">${save}") || die "Error opening save-file: $!\n"; -- 2.39.2 From e726b380eaf48b6af8b06fe28383a183f35ceace Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 08:07:28 +0100 Subject: [PATCH 06/16] fileaccess cleanups --- filesystem.c | 18 +++++++++++++++--- rsb-lz.c | 20 +++++++++----------- rsb-lz.h | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/filesystem.c b/filesystem.c index d4b207e..d644679 100644 --- a/filesystem.c +++ b/filesystem.c @@ -93,6 +93,8 @@ void extract_files(unsigned char *fw, int len) write_file(extracted_file(fent->name), fent->start, fent->length); if (*((unsigned int*)fent->start) == LZ_MAGIC) { char *lzname; + unsigned char *outbuf; + unsigned int outlen; if ((lzname = strdup(fent->name)) == NULL) { perror("strdup"); @@ -107,7 +109,10 @@ void extract_files(unsigned char *fw, int len) printf("%s: packed file found, ", lzname); - extract_lz_file(fent->start, (unsigned char*)lzname, 0); + outbuf = extract_lz_file(fent->start, &outlen, 0); + write_file(extracted_file((char*)lzname), outbuf, outlen); + + free(outbuf); free(lzname); } else if (!strcmp(fent->name, "firmware")) { unsigned char *lzpos; @@ -120,8 +125,15 @@ void extract_files(unsigned char *fw, int len) memcpy(lzname + strlen(lzname), lzpos - 4, 4); lzpos += 4; if (*((unsigned int*)(lzpos)) == LZ_MAGIC) { - printf("%s: compressed firmware part found, ", lzname); - extract_lz_file(lzpos, (unsigned char*)lzname, 1); + unsigned char *outbuf; + unsigned int outlen; + + printf("%s: compressed firmware part found", lzname); + outbuf = extract_lz_file(lzpos, &outlen, 1); + printf(", "); + write_file(extracted_file((char*)lzname), outbuf, outlen); + + free(outbuf); } } } else { diff --git a/rsb-lz.c b/rsb-lz.c index c771b89..bb735d6 100644 --- a/rsb-lz.c +++ b/rsb-lz.c @@ -271,9 +271,8 @@ unsigned int crc_check(unsigned char *buf, unsigned int len, unsigned int magic) return 0; } -void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char check_crc) +unsigned char *extract_lz_file(unsigned char *inbuf, unsigned int *outlen , unsigned char check_crc) { - unsigned int len; unsigned char *outbuf; struct data_in_s data_in; struct data_out_s data_out; @@ -281,23 +280,23 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch if (*((unsigned int*)inbuf) != LZ_MAGIC) err_exit(__func__); - len = *((unsigned int*)(inbuf + 4)); - printf(", length: %d", len); + *outlen = *((unsigned int*)(inbuf + 4)); + printf(", length: %d", *outlen); - if ((outbuf = malloc(len)) == NULL) { + if ((outbuf = malloc(*outlen)) == NULL) { perror("malloc"); exit(1); } - bzero(outbuf, len); + bzero(outbuf, *outlen); data_in.start = inbuf + 8; - data_in.stop = inbuf + len; + data_in.stop = inbuf + *outlen; data_in.byte = 0x00; data_in.bitpos = 0x80; data_out.pos = outbuf; - data_out.end = outbuf + len; + data_out.end = outbuf + *outlen; lz_expand(&data_in, &data_out); @@ -312,7 +311,6 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch err_exit(__func__); } } - write_file(extracted_file((char*)name), outbuf, len); - - free(outbuf); + + return outbuf; } diff --git a/rsb-lz.h b/rsb-lz.h index 442ec43..4cf2c82 100644 --- a/rsb-lz.h +++ b/rsb-lz.h @@ -1,4 +1,4 @@ #define LZ_MAGIC 0x6110beef -void extract_lz_file(unsigned char *buf, unsigned char *name, unsigned char check_crc); +unsigned char *extract_lz_file(unsigned char *inbuf, unsigned int *outlen , unsigned char check_crc); unsigned char *compress_lz(unsigned char *inbuf, int inlen, int *outlen); -- 2.39.2 From d5e3ce21367fc09cdcff59993d66ea9607e2d333 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 08:18:24 +0100 Subject: [PATCH 07/16] retrieve userlist, so user properties can bes saved and restored, too --- rsbs2.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rsbs2.pl b/rsbs2.pl index a481f45..3b752c2 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -279,6 +279,22 @@ sub show_all_vars { } } +sub usrlist { + my $reqstr = ''; + my $res = _req($reqstr); + my @users = (); + + if ($res->{RESP}->{RC} ne '0x0') { + print "FAILED:".$res->{RESP}->{RC}."\n"; + (); + } else { + foreach my $usr (@{$res->{RESP}->{USRLIST}->{USER}}) { + push @users, $usr->{NAME}; + } + } + @users; +} + sub syslog_debug { my $destination_ip = shift; my $bcast = shift; @@ -506,6 +522,9 @@ if ($save ne '') { print SAVEFILE "${ts}=".$phash->{VAL}."\n"; print STDERR "." if (!$verbose); } + foreach my $usr (usrlist()) { + print STDERR "TODO: save user ${usr}\n"; + } close(SAVEFILE); print STDERR "done\n" if (!$verbose); } -- 2.39.2 From e7e46551e4218e6191c676852563d6ccbc098762 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 10:15:17 +0100 Subject: [PATCH 08/16] save and load user settings, too --- rsbs2.pl | 132 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 104 insertions(+), 28 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 3b752c2..35f836a 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -288,19 +288,69 @@ sub usrlist { print "FAILED:".$res->{RESP}->{RC}."\n"; (); } else { - foreach my $usr (@{$res->{RESP}->{USRLIST}->{USER}}) { - push @users, $usr->{NAME}; + if (ref($res->{RESP}->{USRLIST}->{USER}) eq 'ARRAY') { + foreach my $usr (@{$res->{RESP}->{USRLIST}->{USER}}) { + push @users, $usr->{NAME}; + } + } else { + push @users, $res->{RESP}->{USRLIST}->{USER}->{NAME}; } } @users; } +sub getusrprops { + my $usr = shift; + + my $reqstr = ''; + my $res = _req($reqstr)->{RESP}->{USER}->{PROP}; + + $res; +} + +sub usradd { + my $usr = shift; + + my $reqstr=''; + my $res = _req($reqstr); + if ($res->{RESP}->{RC} ne '0x0') { + print "FAILED:".$res->{RESP}->{RC}."\n"; + } +} + +sub setusrprop { + my $usr = shift; + my $property = shift; + my $value = shift; + + my $reqstr=''; + my $res = _req($reqstr); + + my $oldval = ${res}->{RESP}->{USER}->{PROP}->{VAL}; + + if ($value eq $oldval) { + print "${property} is already ${value}\n" if ($verbose); + return; + } + + $reqstr=''.$value.''; + $res = _req($reqstr); + + if ($res->{RESP}->{RC} ne '0x0') { + print "Error setting ${property} to ${value}: ".$res->{RESP}->{RC}."\n"; + undef; + } else { + print "${property}: ${oldval} -> ${value}\n" if ($verbose); + $oldval; + } +} + sub syslog_debug { my $destination_ip = shift; my $bcast = shift; - $reqstr=''.${destination_ip}.''.${bcast}.'FALSE'; - $res = _req($reqstr); + my $reqstr=''.${destination_ip}.''.${bcast}.'FALSE'; + my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "FAILED:".$res->{RESP}->{RC}."\n"; return; @@ -348,26 +398,34 @@ sub login { $sid; } -open(INIFILE,"<$ENV{HOME}/.rsbs2rc") || die("can't open config: $ENV{HOME}/.rsbs2rc: $!"); -my %Config = (); -my @sections = (); -while() { - chomp; - - next if (m/^#/); - - if (m/^\s*\[(.*)\]\s*$/) { - push @sections, $1; - next; - } +sub read_inifile { + my $filename = shift; - if (@sections) { - if (m/^\s*(.+)\s*=\s*(.*)\s*$/) { - ${$Config{$sections[$#sections]}}{$1} = $2; + open(INIFILE,"<${filename}") || die("can't open config: ${filename}: $!"); + my %Ini = (); + my @sections = (); + while() { + chomp; + + next if (m/^#/); + + if (m/^\s*\[(.*)\]\s*$/) { + push @sections, $1; + next; + } + + if (@sections) { + if (m/^\s*([^=]+)\s*=\s*(.*)\s*$/) { + ${$Ini{$sections[$#sections]}}{$1} = $2; + } } } + close(INIFILE); + + %Ini; } -close(INIFILE); + +my %Config = read_inifile("$ENV{HOME}/.rsbs2rc"); my $valid_arg = 0; my $powup = 0; @@ -470,7 +528,7 @@ if (!$valid_arg) { print STDERR "\t-load file\tload configuration from 'file'\n"; print STDERR "\n"; print STDERR "card-alias\tone of: "; - foreach my $alias (@sections) { + foreach my $alias (keys(%Config)) { print STDERR "\"${alias}\" "; } print STDERR "(see ~/.rsbs2rc)\n"; @@ -512,6 +570,7 @@ if ($save ne '') { LAST_IP_ADDRESS LAST_NETMASK); open (SAVEFILE, ">${save}") || die "Error opening save-file: $!\n"; + print SAVEFILE "[global]\n"; print STDERR "saving" if (!$verbose); foreach my $ts (@fw_vars) { next if (grep(/^${ts}$/, @dontsave)); @@ -523,22 +582,39 @@ if ($save ne '') { print STDERR "." if (!$verbose); } foreach my $usr (usrlist()) { - print STDERR "TODO: save user ${usr}\n"; + print SAVEFILE "\n[${usr}]\n"; + foreach my $up (@{getusrprops($usr)}) { + next if ($up->{PERMS} ne 'RW'); + + print SAVEFILE $up->{NAME}."=".$up->{VAL}."\n"; + } + print STDERR "." if (!$verbose); } close(SAVEFILE); print STDERR "done\n" if (!$verbose); } if ($load ne '') { - open (LOADFILE, "<${load}") || die "Error opening load-file: $!\n"; + my %loadfile = read_inifile("${load}"); print STDERR "loading" if (!$verbose); - while() { - chomp; - (my $p, my $v) = split(/=/, $_); - setprop($p, $v); + + foreach my $p (keys(%{$loadfile{'global'}})) { + setprop($p, $loadfile{'global'}->{$p}); print STDERR "." if (!$verbose); } - close(LOADFILE); + + my @users = usrlist(); + foreach my $usr (keys(%loadfile)) { + next if ($usr eq 'global'); + if (!grep(/^${usr}$/, @users)) { + print STDERR "\nAdding user \"${usr}\".\n" if ($verbose); + usradd($usr); + } + foreach my $p (keys(%{$loadfile{$usr}})) { + setusrprop($usr, $p, $loadfile{$usr}->{$p}); + print STDERR "." if (!$verbose); + } + } print STDERR "done\n" if (!$verbose); print "Settings loaded, resetting board...\n"; my $reqstr=''; -- 2.39.2 From 41ae426bddaa63e884dfab84e7a6702be4a063a3 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 5 Feb 2009 10:42:36 +0100 Subject: [PATCH 09/16] don't make up valid card-aliases... --- rsbs2.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsbs2.pl b/rsbs2.pl index 35f836a..debcc87 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -508,7 +508,7 @@ while (defined($ARGV[0])) { } } -if ($valid_arg && (!defined(${$Config{$hostalias}}{'host'}))) { +if ($valid_arg && (!defined($Config{$hostalias}))) { $valid_arg = 0; } -- 2.39.2 From c9427cf83b4389d0a3f03844c55ae990d5bec6f3 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 7 Feb 2009 18:57:23 +0100 Subject: [PATCH 10/16] jumper descriptions added --- README.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index 33cd625..2cb7465 100644 --- a/README.txt +++ b/README.txt @@ -58,10 +58,10 @@ Pinout: | | | | | +---+ +------------+ +------- -CONN1: CONN2: CONN3: J1(?): J2(Standby?): - 1) 1) ATX-PWR +* 1) 1) 1) - 2) 2) ATX-PWR GND* 2) 2) 2) - 3) USB D- 3) ATX-PWR +* 3) +CONN1: CONN2: CONN3: J1: Repair mode enable + 1) 1) ATX-PWR +* 1) J2: Standby power enable + 2) 2) ATX-PWR GND* 2) + 3) USB D- 3) ATX-PWR +* 3) 4) 4) ATX-PWR GND* 5) USB D+ 5) ATX-RESET +* 6) 6) ATX-RESET GND* -- 2.39.2 From 26d316a4420ace66c761458a99f1dc193ac191db Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 12:22:21 +0100 Subject: [PATCH 11/16] add option to show board/server status --- rsbs2.pl | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index debcc87..0d2a682 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -154,6 +154,19 @@ sub _req { XMLin($response->content, SuppressEmpty => ''); } +sub _cmd { + my $cmd = shift; + + my $reqstr=''; + my $res = _req($reqstr); + if ($res->{RESP}->{RC} ne '0x0') { + print "${cmd} failed: ".$res->{RESP}->{RC}."\n"; + undef; + } + + $res->{RESP}; +} + sub _getprop { my $property = shift; @@ -311,7 +324,7 @@ sub getusrprops { sub usradd { my $usr = shift; - my $reqstr=''; + my $reqstr=''; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "FAILED:".$res->{RESP}->{RC}."\n"; @@ -366,6 +379,53 @@ sub syslog_debug { print "Debug messages will be sent to ${destination_ip} (broadcast: ${bcast})\n"; } +sub status { + my $boardstatus = _cmd("boardstatus")->{STATUS}; + my $fw = _cmd("boardfwstatus"); + my $boardfwstatus = $fw->{STATUS}; + my $boardfwprogress = $fw->{PROGRESS}; + $bs = hex($boardstatus); + + print "Server Power:\t\t" . (($bs & 0x01) ? "ON" : "OFF") . "\n"; + print "External PSU:\t\t" . (($bs & 0x02) ? "ON" : "OFF") . "\n"; + print "Battery:\t\t"; + if ($bs & 0x04) { + if ($bs & 0x08) { + print "LOW\n"; + } elsif ($bs & 0x800) { + print "ON\n"; + } else { + print "UNKNOWN\n"; + } + } else { + print "OFF\n"; + } + print "Standby Power:\t\t" . (($bs & 0x08) ? "ON" : "OFF") . "\n"; + print "LAN:\t\t\t" . (($bs & 0x10) ? "CONNECTED" : "NC") . "\n"; + print "I2C:\t\t\t" . (($bs & 0x20) ? "CONNECTED" : "NC") . "\n"; + print "SMM:\t\t\t" . (($bs & 0x40) ? "CONNECTED" : "NC") . "\n"; + print "Instrumentation:\t" . (($bs & 0x200) ? "CONNECTED" : "NC") . "\n"; + print "ICMB:\t\t\t" . (($bs & 0x400) ? "CONNECTED" : "NC") . "\n"; + print "PPP:\t\t\t" . (($bs & 0x10000) ? "ON" : "OFF") . "\n"; + print "Paging:\t\t\t" . (($bs & 0x20000) ? "ON" : "OFF") . "\n"; + print "COM redirection:\t" . (($bs & 0x100000) ? "ON" : "OFF") . "\n"; + print "UART redirect:\t\t" . (($bs & 0x200000) ? "ON" : "OFF") . "\n"; + print "UART redirect pending:\t" . (($bs & 0x400000) ? "TRUE" : "FALSE") . "\n"; + my $fws = hex ($boardfwstatus); + print "FW status:\t\t"; + if ($fws == 3 || $fws == 32771) { + print "WAITING\n"; + } else { + print "DONE\n"; + } + if (($fws & 0x8080) || ($fws & 0x80)) { + printf("FW error:\t\t0x%02x\n", ($fws & 0xff)); + } + print "boardstatus:\t\t${boardstatus}\n"; + print "boardfwstatus:\t\t${boardfwstatus}\n"; + print "fw upgrade progress:\t${boardfwprogress}\n"; +} + sub login { my $user = shift; my $pass = shift; @@ -438,6 +498,7 @@ my $show = 0; my $enable_debug = ""; my $save = ""; my $load = ""; +my $showstat = 0; my $hostalias; while (defined($ARGV[0])) { @@ -487,6 +548,11 @@ while (defined($ARGV[0])) { shift @ARGV; last SWITCH; }; + /^-b$/ && do { + $showstat = 1; + shift @ARGV; + last SWITCH; + }; /^-save$/ && do { shift @ARGV; $save = shift @ARGV; @@ -523,6 +589,7 @@ if (!$valid_arg) { print STDERR "\t-r\t\treset\n"; print STDERR "\t-x\t\tshow all properties, variables and settings\n"; print STDERR "\t-l IP\t\tsend SYSLOG debug messages to IP\n"; + print STDERR "\t-b\t\tshow board/server status\n"; print STDERR "\t-v\t\tverbose\n"; print STDERR "\t-save file\tsave configuration to 'file'\n"; print STDERR "\t-load file\tload configuration from 'file'\n"; @@ -617,8 +684,7 @@ if ($load ne '') { } print STDERR "done\n" if (!$verbose); print "Settings loaded, resetting board...\n"; - my $reqstr=''; - _req($reqstr); + _cmd("boardreset"); exit(0); } @@ -643,4 +709,8 @@ if ($powcyc) { powercycle(); } +if ($showstat) { + status(); +} + logout(); -- 2.39.2 From 3a88950737f06d296baf044920a263ab10e6fd8a Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 13:03:45 +0100 Subject: [PATCH 12/16] add options for resetting RSB S2 board an sending raw XML --- rsbs2.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rsbs2.pl b/rsbs2.pl index 0d2a682..7f5cc0f 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -492,8 +492,10 @@ my $powup = 0; my $powdown = 0; my $powcyc = 0; my $reset = 0; +my $resetrsbs2 = 0; my @sprop = (); my @gprop = (); +my @xmlsend = (); my $show = 0; my $enable_debug = ""; my $save = ""; @@ -538,6 +540,11 @@ while (defined($ARGV[0])) { shift @ARGV; last SWITCH; }; + /^-R$/ && do { + $resetrsbs2 = 1; + shift @ARGV; + last SWITCH; + }; /^-l$/ && do { shift @ARGV; $enable_debug = shift @ARGV; @@ -548,6 +555,11 @@ while (defined($ARGV[0])) { shift @ARGV; last SWITCH; }; + /^-X$/ && do { + shift @ARGV; + push @xmlsend, shift @ARGV; + last SWITCH; + }; /^-b$/ && do { $showstat = 1; shift @ARGV; @@ -587,9 +599,11 @@ if (!$valid_arg) { print STDERR "\t-d\t\tpowerdown\n"; print STDERR "\t-c\t\tpowercycle\n"; print STDERR "\t-r\t\treset\n"; + print STDERR "\t-R\t\treset RSB S2 borad\n"; print STDERR "\t-x\t\tshow all properties, variables and settings\n"; print STDERR "\t-l IP\t\tsend SYSLOG debug messages to IP\n"; print STDERR "\t-b\t\tshow board/server status\n"; + print STDERR "\t-X\t\tsend raw XML string (start with REQ tag)\n"; print STDERR "\t-v\t\tverbose\n"; print STDERR "\t-save file\tsave configuration to 'file'\n"; print STDERR "\t-load file\tload configuration from 'file'\n"; @@ -630,6 +644,12 @@ if (@sprop) { } } +if (@xmlsend) { + foreach my $x (@xmlsend) { + print Dumper(_req(''.$x.'')); + } +} + if ($save ne '') { my @dontsave = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX GATEWAY IP_ADDRESS NETMASK TFTP_FIRMWARE_FILE TFTP_ADDR_FIRMWARE @@ -713,4 +733,10 @@ if ($showstat) { status(); } +if ($resetrsbs2) { + print "Resetting board...\n"; + _cmd("boardreset"); + exit(0); +} + logout(); -- 2.39.2 From 7ef02e7634bc62e7d7d6f1c2a4b350bff8af434a Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 13:06:51 +0100 Subject: [PATCH 13/16] fix boardstatus output --- rsbs2.pl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 7f5cc0f..17f33dc 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -411,19 +411,21 @@ sub status { print "COM redirection:\t" . (($bs & 0x100000) ? "ON" : "OFF") . "\n"; print "UART redirect:\t\t" . (($bs & 0x200000) ? "ON" : "OFF") . "\n"; print "UART redirect pending:\t" . (($bs & 0x400000) ? "TRUE" : "FALSE") . "\n"; + print "Hex BoardStatus:\t${boardstatus}\n"; my $fws = hex ($boardfwstatus); print "FW status:\t\t"; if ($fws == 3 || $fws == 32771) { - print "WAITING\n"; + print "WAITING"; } else { - print "DONE\n"; + print "DONE"; } + print " (${boardfwstatus})\n"; if (($fws & 0x8080) || ($fws & 0x80)) { printf("FW error:\t\t0x%02x\n", ($fws & 0xff)); } - print "boardstatus:\t\t${boardstatus}\n"; - print "boardfwstatus:\t\t${boardfwstatus}\n"; - print "fw upgrade progress:\t${boardfwprogress}\n"; + if ($fws != 0) { + print "FW upgrade progress:\t${boardfwprogress}\n"; + } } sub login { -- 2.39.2 From 762f3898849f6975286d7d0511f9e340cc2eb073 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 13:43:57 +0100 Subject: [PATCH 14/16] cleanup request generation, add sensor list function --- rsbs2.pl | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 17f33dc..4d09c1b 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -148,7 +148,7 @@ sub _req { $request = HTTP::Request->new(POST => "http://${host}/cgi/bin"); $request->header(Cookie => "sid=$sid"); $request->content_type('application/x-www-form-urlencoded'); - $request->content($xml); + $request->content(''.$xml.''); $response = $ua->request($request); die("Error in request: " . $response->status_line . "\n") unless ($response->is_success); XMLin($response->content, SuppressEmpty => ''); @@ -157,7 +157,7 @@ sub _req { sub _cmd { my $cmd = shift; - my $reqstr=''; + my $reqstr=''; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "${cmd} failed: ".$res->{RESP}->{RC}."\n"; @@ -170,7 +170,7 @@ sub _cmd { sub _getprop { my $property = shift; - my $reqstr=''; + my $reqstr=''; my $resp = _req($reqstr); print "get: ${property}\n" if ($verbose); @@ -204,7 +204,7 @@ sub setprop { return; } - my $reqstr=''.$value.''; + my $reqstr=''.$value.''; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { @@ -228,7 +228,7 @@ sub serveraction { setprop("SERVER_POWER_OFF_MODE", sprintf("0x%x", $pmode)); print "${action}...\n" if ($verbose); - my $reqstr=''.$action.''; + my $reqstr=''.$action.''; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { @@ -266,7 +266,7 @@ sub showprop { } sub board_properties { - my $reqstr=''; + my $reqstr=''; my $resp = _req($reqstr); print " * Board Properties:\n"; @@ -276,7 +276,7 @@ sub board_properties { } sub show_boarddesc { - my $reqstr=''; + my $reqstr=''; my $boarddesc64 = _req($reqstr)->{RESP}->{BPROPLIST}->{BPROP}->{VAL}; my $boarddesc = decode_base64($boarddesc64); my @board = split(//, $boarddesc); @@ -293,20 +293,19 @@ sub show_all_vars { } sub usrlist { - my $reqstr = ''; - my $res = _req($reqstr); + my $res = _cmd("usrlist"); my @users = (); - if ($res->{RESP}->{RC} ne '0x0') { - print "FAILED:".$res->{RESP}->{RC}."\n"; + if ($res->{RC} ne '0x0') { + print "FAILED:".$res->{RC}."\n"; (); } else { - if (ref($res->{RESP}->{USRLIST}->{USER}) eq 'ARRAY') { - foreach my $usr (@{$res->{RESP}->{USRLIST}->{USER}}) { + if (ref($res->{USRLIST}->{USER}) eq 'ARRAY') { + foreach my $usr (@{$res->{USRLIST}->{USER}}) { push @users, $usr->{NAME}; } } else { - push @users, $res->{RESP}->{USRLIST}->{USER}->{NAME}; + push @users, $res->{USRLIST}->{USER}->{NAME}; } } @users; @@ -315,7 +314,7 @@ sub usrlist { sub getusrprops { my $usr = shift; - my $reqstr = ''; + my $reqstr = ''; my $res = _req($reqstr)->{RESP}->{USER}->{PROP}; $res; @@ -324,7 +323,7 @@ sub getusrprops { sub usradd { my $usr = shift; - my $reqstr=''; + my $reqstr=''; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "FAILED:".$res->{RESP}->{RC}."\n"; @@ -336,7 +335,7 @@ sub setusrprop { my $property = shift; my $value = shift; - my $reqstr=''; + my $reqstr=''; my $res = _req($reqstr); my $oldval = ${res}->{RESP}->{USER}->{PROP}->{VAL}; @@ -346,7 +345,7 @@ sub setusrprop { return; } - $reqstr=''.$value.''; + $reqstr=''.$value.''; $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { @@ -362,14 +361,14 @@ sub syslog_debug { my $destination_ip = shift; my $bcast = shift; - my $reqstr=''.${destination_ip}.''.${bcast}.'FALSE'; + my $reqstr=''.${destination_ip}.''.${bcast}.'FALSE'; my $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "FAILED:".$res->{RESP}->{RC}."\n"; return; } - $reqstr='TRUE0x10x1FALSE'; + $reqstr='TRUE0x10x1FALSE'; $res = _req($reqstr); if ($res->{RESP}->{RC} ne '0x0') { print "FAILED:".$res->{RESP}->{RC}."\n"; @@ -379,6 +378,19 @@ sub syslog_debug { print "Debug messages will be sent to ${destination_ip} (broadcast: ${bcast})\n"; } +sub sensors { + my $slist= _cmd("sensorlist"); + my %sens = (); + + if ($slist->{RC} ne '0x0') { + print "Error getting sensorlist: ".$slist->{RC}."\n"; + return; + } + + foreach my $s (@{$slist->{SENSORLIST}->{SENSOR}}) { + } +} + sub status { my $boardstatus = _cmd("boardstatus")->{STATUS}; my $fw = _cmd("boardfwstatus"); @@ -426,6 +438,8 @@ sub status { if ($fws != 0) { print "FW upgrade progress:\t${boardfwprogress}\n"; } + print "\nSensors:\n"; + sensors(); } sub login { @@ -648,7 +662,7 @@ if (@sprop) { if (@xmlsend) { foreach my $x (@xmlsend) { - print Dumper(_req(''.$x.'')); + print Dumper(_req($x)); } } -- 2.39.2 From 661b5a0eabc3b2e85e20475cdfe60c702a83aa82 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 14:15:16 +0100 Subject: [PATCH 15/16] show sensor values when boardstatus is requested --- rsbs2.pl | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 4d09c1b..43f4986 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -282,8 +282,8 @@ sub show_boarddesc { my @board = split(//, $boarddesc); foreach my $byte (@board) { printf ("0x%02x ", ord($byte)); -} -print "\n"; + } + print "\n"; } sub show_all_vars { @@ -378,16 +378,51 @@ sub syslog_debug { print "Debug messages will be sent to ${destination_ip} (broadcast: ${bcast})\n"; } -sub sensors { +sub get_sensors { my $slist= _cmd("sensorlist"); - my %sens = (); + my @sensors; if ($slist->{RC} ne '0x0') { print "Error getting sensorlist: ".$slist->{RC}."\n"; return; } + my $req = '0x1'; foreach my $s (@{$slist->{SENSORLIST}->{SENSOR}}) { + $req .= ''; + } + $req .= ''; + + my $sprop = _req($req); + foreach my $s (@{$sprop->{RESP}->{SENSORLIST}->{SENSOR}}) { + my $sensor = {}; + foreach my $sp (@{$s->{PROP}}) { + $sensor->{$sp->{NAME}} = $sp->{VAL}; + } + + next if (!defined($sensor->{NAME})); + $sensor->{VAL} = '0' if ($sensor->{VAL} eq ''); + push @sensors, $sensor; + } + @sensors; +} + +sub show_sensors { + my @sensors = get_sensors(); + + foreach my $sensor (@sensors) { + print $sensor->{NAME}.": ".$sensor->{VAL}.$sensor->{UNITS}." "; + + my @info = (); + foreach my $field qw(MIN MAX LOW_NON_CRITICAL UPPER_NON_CRITICAL LOW_CRITICAL UPPER_CRITICAL) { + if ($sensor->{$field} ne '') { + push @info, "${field}: ".$sensor->{$field}.$sensor->{UNITS}; + } + } + + print " (".join(", ",@info).")" if (@info); + + print "\n"; } } @@ -439,7 +474,7 @@ sub status { print "FW upgrade progress:\t${boardfwprogress}\n"; } print "\nSensors:\n"; - sensors(); + show_sensors(); } sub login { -- 2.39.2 From 06873593de347f3e740d37a9f5416697df662847 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 8 Feb 2009 14:18:57 +0100 Subject: [PATCH 16/16] better sensor output --- rsbs2.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rsbs2.pl b/rsbs2.pl index 43f4986..51d9c64 100755 --- a/rsbs2.pl +++ b/rsbs2.pl @@ -411,7 +411,7 @@ sub show_sensors { my @sensors = get_sensors(); foreach my $sensor (@sensors) { - print $sensor->{NAME}.": ".$sensor->{VAL}.$sensor->{UNITS}." "; + print $sensor->{NAME}.": ".$sensor->{VAL}.$sensor->{UNITS}; my @info = (); foreach my $field qw(MIN MAX LOW_NON_CRITICAL UPPER_NON_CRITICAL LOW_CRITICAL UPPER_CRITICAL) { @@ -420,7 +420,7 @@ sub show_sensors { } } - print " (".join(", ",@info).")" if (@info); + print "\t(".join(", ",@info).")" if (@info); print "\n"; } -- 2.39.2