#!<> use INSTALL::common; use INSTALL::global; use INSTALL::parameter; use INSTALL::locale; use strict; my $pParameters = \%INSTALL::parameter::variables; #============================================================================== #------------------------ Default global values #============================================================================== $pParameters->{asphome} = "<>"; $pParameters->{com_layer} = "<>"; INSTALL::common::set_standard_globals; my $pGlobals = \%INSTALL::global::variables; my $pOS = \%INSTALL::os::Details; sub usage { printf("usage: list-sysinfo\n"); exit(1); } #============================================================================== #------------------------ Validate all the required parameters. #============================================================================== if (boolean_value($pParameters->{'--help'})) { usage(); } use INSTALL::os; my $pOS = \%INSTALL::os::Details; #============================================================================== #------------------------ Internal functions #============================================================================== use INSTALL::ini; sub list_databases { (@_ == 1) || die "Invalid number of arguments."; my $asp_server = shift @_; my $odbc_ini = "$asp_server/odbc.ini"; my %driver_hash = ( 'ivInterbase' => 'Interbase', 'libmyodbc' => 'MySQL', 'libodbcpsql' => 'PostgreSQL', 'ase' => 'Sybase', 'db' => 'DB2', 'dbf' => 'dBase', 'inf'=> 'Informix', 'msss' => 'Microsoft SQL Server', 'or' => 'Oracle', 'slk' => 'SequeLink', 'syb' => 'Sybase', 'udb' => 'DB2' ); my $pIni = INSTALL::ini::open($odbc_ini); unless($pIni) { error("Unabled to open $odbc_ini for database collection."); return(); } my %database_hash; my $root; foreach my $section_name (INSTALL::ini::getSectionNames($pIni)) { my $pSection = INSTALL::ini::openSection($pIni,$section_name); next if ($section_name =~ /template/); if (exists $pSection->{Type}) { $database_hash{$pSection->{Type}} = 1; } elsif (exists $pSection->{Driver}) { $root = $pSection->{Driver}; $root =~ s/.*\/Y*([^0-9]*)[0-9\/]*\..*/$1/; if (exists %driver_hash->{$root}) { $database_hash{%driver_hash->{$root}} = 1; } } } return(keys %database_hash); } #------------------------------------------------------------------------------ # Calculate GMT offset in hours. #------------------------------------------------------------------------------ use POSIX; sub calculate_gmt_offset { (@_ == 0) || die "Invalid number of arguments."; my $localtime = POSIX::mktime(localtime); my $gmtime = POSIX::mktime(gmtime); return(($localtime - $gmtime) / (60 * 60)); } #------------------------------------------------------------------------------ # Determine whether Java is enabled #------------------------------------------------------------------------------ sub is_java_Enabled { my $ret = "no"; my $javasetup = "$pGlobals->{asphome}/javasetup.sh"; local *JAVAFILE; if (open(JAVAFILE, "<$javasetup")) { foreach () { if ($_ =~ /BEAN_SUPPORT=(.*)\n/) { close(JAVAFILE); $ret = $1; last; } } } return $ret; } #------------------------------------------------------------------------------ # Generate somewhat 'unique ID'. #------------------------------------------------------------------------------ sub generate_uniqueID { my $tmp_file = "/tmp/.uniqueID-$$"; local *UNIQUE; unless(open(UNIQUE,">$tmp_file")) { error("Unable to open $tmp_file for unique ID generation."); } my $rand_string; for(my $i=0; $i < 100; $i++) { $rand_string .= (rand(~(time * 119) + (time * 17)) * (~0)); } print UNIQUE ($rand_string); close(UNIQUE); my $md5sum = "$pGlobals->{tools_bin_dir}/md5sum"; if (-x $md5sum) { my $result = `$md5sum $tmp_file`; chomp($result); $result =~ s/(.{32}).*/$1/g; unlink($tmp_file); return($result); } else { return(); } } #============================================================================== #------------------------ Global values / functions #============================================================================== my $unknown = "Unknown"; my $none = "None"; my $yes = "Yes"; my $no = "No"; # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) my @localtime = localtime; # Leading _ in key name denotes hidden field (field not shown to the user). my %Collected_Information = ( # Collection date collection_date => sprintf("%02d/%02d/%04d",$localtime[4] + 1,$localtime[3],$localtime[5] + 1900), GMT_offset => calculate_gmt_offset(), # ASP version ASP_version => $pGlobals->{casp_version}, build_number => $unknown, eval_license => $no, # Platform information os => $pOS->{os_name}, os_version => $pOS->{os_version}, distribution => $pOS->{distribution}, distribution_version => $pOS->{distribution_version}, # Hardware information processor_count => $pOS->{processor_count}, # Webserver information webserver_type => $none, webserver_version => $none, # Database information database_list => $none, # Information from VERSION install_date => $unknown, # Unique identifier _unique_ID => $unknown, # Published form version _form_version => 1.0, # Value to verify the validity of the form # information sent (so that people are not # able, without a little work, to send # bogus information to us). _form_verify => undef ); sub add { my $counter = 0; foreach(@_) { $counter += $_; } return($counter); } #------------------------------------------------------------------------------ # Collect webserver information #------------------------------------------------------------------------------ use INSTALL::webserver; my @webserver_list = INSTALL::webserver::load_used_servers(); if (@webserver_list) { $Collected_Information{webserver_type} = $webserver_list[0]->{webserver_type}; $Collected_Information{webserver_version} = $webserver_list[0]->{webserver_version}; } #------------------------------------------------------------------------------ # Collect License Key Information #------------------------------------------------------------------------------ local *LICENSE; my $keystore_ini = "$pGlobals->{asphome}/LICENSE/keystore.ini"; if (-f $keystore_ini) { my $pIni = INSTALL::ini::open($keystore_ini); if ($pIni) { my $pSection = INSTALL::ini::openSection($pIni,"CASP"); if ($pSection && (exists $pSection->{p})) { if ($pSection->{p} =~ /Eval/i) { $Collected_Information{eval_license}=$yes; } else { $Collected_Information{eval_license}=$no; } } } } #------------------------------------------------------------------------------ # Collect database information #------------------------------------------------------------------------------ if (@webserver_list) { my @database_list = list_databases($webserver_list[0]->{engine_dir}); if (@database_list) { $Collected_Information{database_list} = join(",",@database_list); } } #------------------------------------------------------------------------------ # Collect build # #------------------------------------------------------------------------------ my $caspctrlb = "$pGlobals->{bin_dir}/caspctrlb"; if (-x $caspctrlb) { foreach my $line (split(/\n/,`$caspctrlb -version`)) { chomp $line; if ($line =~ /Build:\s*(\d+)/) { $Collected_Information{build_number} = $1; last; } } } #------------------------------------------------------------------------------ # Collect version and installation date information #------------------------------------------------------------------------------ local *VERSION; if (open(VERSION,"<$pGlobals->{asphome}/VERSION")) { for(;;) { my $line = ; if ($line =~ m@installed on (\d+/\d+/\d+)@) { # Last one listed is the latest installation in VERSION. $Collected_Information{install_date} = $1; } else { unless($line) { last; } } } } #------------------------------------------------------------------------------ # Collect unique ID #------------------------------------------------------------------------------ if (-f "$pParameters->{asphome}/.unique_ID") { local *UNIQUE; unless(open(UNIQUE,"<$pParameters->{asphome}/.unique_ID")) { error("Unable to open $pParameters->{asphome}/.unique_ID."); $Collected_Information{_unique_ID} = generate_uniqueID(); if (open(UNIQUE,">$pParameters->{asphome}/.unique_ID")) { print UNIQUE ("$Collected_Information{_unique_ID}\n"); } } else { $Collected_Information{_unique_ID} = ; chomp $Collected_Information{_unique_ID}; close(UNIQUE); } } else { $Collected_Information{_unique_ID} = generate_uniqueID(); if (open(UNIQUE,">$pParameters->{asphome}/.unique_ID")) { print UNIQUE ("$Collected_Information{_unique_ID}\n"); } } #------------------------------------------------------------ # record whether java is enabled #------------------------------------------------------------ $Collected_Information{java_enabled}=ucfirst(lc(is_java_Enabled())); foreach my $key (keys %Collected_Information) { if ($Collected_Information{$key} eq "Unknown") { $Collected_Information{$key} = "Not Applicable"; } } $Collected_Information{_form_verify} = add(map(length($_),values %Collected_Information)); foreach my $key (sort { $a cmp $b } keys %Collected_Information) { print "$key=$Collected_Information{$key}\n"; }