# --- This is a perl file --- BEGIN{ push(@INC,"/usr/mwdata/users/olga/myperl/lib/site_perl/5.005","/usr/mwdata/users/olga/myperl/lib/site_perl/5.005/sun4-solaris","/usr/local/perl-5.005/lib/5.00502","."); } do "xmlHandler.pl"; package UNIVERSAL; sub SetLogfile{ my $self = shift; my $file = shift; $self->{logfile}=$file; } sub printlog{ my $self = shift; my @param=@_; my $log=undef; if ( -f $self->{logfile} ){$log=$self->{logfile};} else{$log=$::logfile;} open(LOGFILE,">>$log")|| print STDOUT "Cannot open $log: $! \n"; if (! -w LOGFILE){print "In printlog, cannot write into $log\n";} printf LOGFILE "@param"; close(LOGFILE); printf ""; } sub trace{ my $self = shift; my ($level,$component,$message)=@_; #print "level=$level,trace=$::trace\n"; if ($level <= $::trace){ $self->printlog("#trace $level:$component:$message"); } } sub print2{ my $self = shift; my $message = shift; my $log = undef; if (-f $self->{logfile}){$log=$self->{logfile};} else{$log=$::logfile;} open(LOGFILE,">>$log")|| print STDOUT "Cannot open $log: $! \n"; if (! -w LOGFILE){print "in print2, cannot write into $log\n";} print LOGFILE "$message"; close(LOGFILE); if (ref($::report) eq "customerReport"){ print "$message"; } } sub printf2{ my $self = shift; my @param=@_; my $log = undef; if (-f $self->{logfile}){$log=$self->{logfile};} else{$log=$::logfile;} open(LOGFILE,">>$log")|| print STDOUT "Cannot open $log: $! \n"; if (! -w LOGFILE){print "in printf2, cannot write into $log\n";} printf LOGFILE @param; close(LOGFILE); if (ref($::report) eq "customerReport"){ printf @param; } printf ""; } ################################################################## # Subrutine: ConvertPath # Purpose: get path and convert it to the new path without '..' # Return: new path ################################################################## sub ConvertPath{ my $self = shift; my $path= shift; my @dirs=split(/\//,$path); my @new_dirs=undef; foreach $dir (@dirs){ if ("$dir" ne "..") {push(@new_dirs,$dir);} else{pop(@new_dirs);} } if ("$new_dirs[0]" eq ""){shift @new_dirs;} $new_path = join("/",@new_dirs); return $new_path; } ################################################################## # Subrutine: ExecCommand # Purpose: put commands into shell script and run it # Return command result ################################################################## sub ExecCommand{ my $self= shift; my $CommandFile=shift; @lines=@_; system("touch $CommandFile"); #Create exec_command file chmod(0777,"$CommandFile"); open(COMMAND,">$CommandFile") || print STDOUT "Cannot open command $CommandFile: $! \n"; if (! -w COMMAND){return 1;} ## Cannot execute command print COMMAND "#!/bin/sh\n"; foreach $line (@lines){ print COMMAND "$line\n"; } close(COMMAND); $ENV{"ENV"}=""; # execute command by runung exec_file @command_results=`$CommandFile < /dev/null 2> /dev/null`; # $command_result =~ s/^\s+//; # $command_result =~ s/\n$//; unlink $CommandFile ; # remove exec_command file @result=(0,\@command_results); return @result; } ###################################### # Subrutine: match_clause # Purpose: Check if $clause in $SysID # Return 1 if yes ;0 in the other case ###################################### sub match_clause{ my $self = shift; my $clause = shift; my $MainParam = shift; my $equal=0; my($last_param,$first_params); @Sys=split(/\s+/,$MainParam); if ($clause =~ /binutils/){ ($trush,$version)=split(/\//,$clause); @version_params=split(/\./,$version); $last_param=pop(@version_params); $first_params=join(".",@version_params); } foreach $elem (@Sys){ $clause =~ s/\+\+/\+\\\+/g; $self->trace(5,"Universal","Matching clause $clause with System ID: $SysID, elem: $elem\n"); if (($clause =~ /binutils/)&& ($elem =~ /binutils\/$first_params/)){ $first_params =~ s/\.//g; $required_version=$first_params.$last_param; $elem =~ s/binutils\///; $elem =~ s/\.//g; #print "elem=$elem, required_version=$required_version\n"; if ($elem >= $required_version){ $equal=1;return $equal; } else{return $equal;} } if ($elem =~ /$clause/){$equal=1;return $equal;} } $equal; } ################################################################## # Subrutine: eval_prereq # Purpose: get sentence of pre-requirements, devide it to clauses # by || or && delimiter, call match_clause for each clause # and build the new sentence with 0/1 instead of clause # Return 1 if sentence match the system, 0 in other case ################################################################## sub eval_prereq{ my $self = shift; my $prereq = shift; my $MainParam= shift; my(@prereq_clauses,$clause,@sentance,$result); @prereq_clauses=split(/\s+/,$prereq); $self->trace(5,"Universal","Evaluate prereq $prereq\n"); foreach $clause (@prereq_clauses){ next if ($clause eq ""); #print "clause : $clause\n"; if (("$clause" eq "!") || ("$clause" eq "\(") || ("$clause" eq "\)") || ("$clause" eq "\&\&") || ("$clause" eq "\|\|")){ push(@sentance,$clause); } elsif ( $self->match_clause($clause,$MainParam)){ push(@sentance,"1");} else{ push(@sentance,"0");} } #print "\neval_prereq: sentance=@sentance; prereq=$prereq ;prereq_clauses=@prereq_clauses \n"; if ( eval "@sentance") { $result=1; } else { $result=0; } $self->trace(5,"Universal","\nRESULT OF MATCH @prereq_clauses with SYSID:$SysID IS $result\n\n"); $result; } 1; package Report; { sub new{ my $type = shift; # my ($component,$match,$requiredVersion) = @_; my $self = bless {}, $type; return $self; } } package enduserReport;@ISA=qw(Report); { sub DefaultReport{ my $self = shift; my ($component,$match,$requiredVersion) = @_; $self->printf2("Product: %s : %s : %s : %s : %s\n",$component->{fullname},$component->{CompGroup},$component->{version}, $requiredVersion, $match); } sub PatchReport{ my $self = shift; my ($status,$patch) = (shift,shift); $self->printf2("%s : %s : %s : %s : %s \n", $patch->{Name},$status,$patch->{Detected},$patch->{MinLevel},$patch->{Description}); } } package customerReport;@ISA=qw(Report); { sub DefaultReport{ my $self = shift; my ($component,$match,$requiredVersion,$ProductName)=@_; if ($component->{message}){ $self->print2("\n$component->{message}\n"); } if (($component->{Name} =~ /Compiler/) || ($component->{Name} =~ /JavaSDK/)){ my $productVersion=" Product Version: $component->{version}"; $self->print2(" Product Name: $component->{fullname}\n"); $self->print2(" Product Directory: $component->{basedir}\n"); $self->printf2("%s"."."x(70-length($productVersion))."%s\n",$productVersion,$match); } else{ $self->printf2("%s"."."x(70-length("$ProductName"))."%s\n","$ProductName",$match); } if (! $component->{MatchFlag}->GetParam("Passed") && $component->{Name} !~ /ML/){ $self->printf2(" "x (5)."Detected version: $component->{version}\n"); $self->printf2(" "x (5)."Supported version: $requiredVersion\n"); } } sub PatchReport{ my $self = shift; my ($status,$patch) = (shift,shift); if (!$patch->{PatchIsBad}){ $self->printf2(" "x (8)."Detected patch: $patch->{Detected}\n"); $self->printf2(" "x (8)."Certified patch: $patch->{Name}\n"); $self->printf2(" "x (8)."Description: $patch->{Description}\n\n"); } else{ $self->printf2(" "x (8)."Problematic patch detected: $patch->{Name}\n"); } } } package Requirement; sub new { my $classname = shift; my ($RequireName,$RequireData,$found,$isMandatory,$group,$isBad, $exact)=@_; my $class = ref($classname) || $classname; my $self={}; $self->{Name}=$RequireName; if ($isBad){ $self->{badData}=$RequireData; } else {$self->{badData}=undef;} $self->{Data}=$RequireData; $self->{Found}=$found; $self->{Match}=new Match(); $self->{group}=$group; $self->{ifMandatory}=$isMandatory; $self->{ExistVersion}=undef; $self->{exact}=$exact; # 1 - if the version have to be exactly like requirement bless($self,$class); } sub AddRequirementData{ my $self = shift; my $newdata = shift; my $isBad = shift; if ($isBad){ $self->{badData}=$newdata; } elsif(!$self->{Data}){$self->{Data}=$newdata;} else{$self->{Data}=$self->{Data}." || ".$newdata;} } sub AddExistVersion{ my $self = shift; my $version = shift; if (!defined $self->{ExistVersion}){ $self->{ExistVersion}=$version; } elsif (!($self->{ExistVersion} =~ /$version/)){ $self->{ExistVersion}=$self->{ExistVersion}." || ".$version; } } sub AddMatch{ my $self = shift; my $status = shift; $self->{Match}->AddStatus($status); } sub GetMatch{ my $self = shift; my $match=$self->{Match}->GetMatch($self->{Name}); return ($match); } sub CheckIfMiss{ my $self = shift; my $compGroup=shift; if (($self->{group} eq $compGroup) && (!$self->{Found})){return 1;} else {return 0;} } sub RequirementReport{ my $self = shift; my $fullname = shift; my $match = $self->GetMatch(); if ($self->{Found} && ($match eq "[PASSED]")){ $status="[PASSED]"; } elsif(!$self->{Found} || ($match eq "[FAILED]")){ $status="[FAILED]"; } else{ $status="[WARNING]"; } $self->trace(4,"Requirement","requirement=$self->{Name}, status=$status, Match=$match, MatchPatch=$self->{PatchMatch}\n"); $self->printf2("%s"."."x(70-length($fullname))."%s\n",$fullname,$status); } 1; package Patch; sub new{ my $classname = shift; my($Patch,$PatchType,$IfAbsent,$Description,$MinLevel,$PatchIsBad)=@_; my $class = ref($classname) || $classname; my $self={}; $self->{Name}=$Patch; $self->{Type}=$PatchType; $self->{IfAbsent}=$IfAbsent; $self->{Description}=$Description; if ($MinLevel){$self->{MinLevel}=$MinLevel;} $self->{Found}=0; $self->{Detected}="None"; $self->{OutdatedFlag}=0; $self->{UncertifiedFlag}=0; $self->{PatchIsBad}=$PatchIsBad; bless($self,$class); #print "in new Patch PatchType=$self->{Type}\n"; } sub PatchReport{ my $self = shift; if (!$self->{PatchIsBad}){ $self->printf2(" "x (8)."Detected patch: $self->{Detected}\n"); $self->printf2(" "x (8)."Certified patch: $self->{Name}\n"); $self->printf2(" "x (8)."Description: $self->{Description}\n\n"); } else{ $self->printf2(" "x (8)."Problematic patch detected: $self->{Name}\n"); } } 1; package Component; sub new{ my $classname = shift; my $fullname = shift; my $ComponentGroup = shift; my $class = ref($classname) || $classname; my $self={}; $self->{CompGroup}=$ComponentGroup; $self->{fullname}=$fullname; $self->{MissingPatches}=0; $self->{OutdatedPatches}=0; $self->{UncertifiedPatches}=0; $self->{BadPatchesFound}=0; $self->{PatchFlag}=undef; $self->{PatchesFlag}=new Match(); $self->{MatchFlag}=new Match(); $self->{version}=undef; bless($self,$class); } sub PrintComponent{ my $self = shift; if ($self->{fullname} ne "no") { $self->printf2("%-23s %s\n",$self->{fullname},$self->{version}); } $self->print2("\n"); } sub AddPatchToProblem{ my $self = shift; my ($problem, $patch)=@_; @patchlist=undef; if (defined $self->{$problem}){ $patchpnt=$self->{$problem}; @patchlist=@$patchpnt; push(@patchlist,$patch); $self->{$problem}=\@patchlist; } else{ push(@patchlist,$patch); if ($patchlist[0] eq ""){shift @patchlist;} $self->{$problem}=\@patchlist; } } sub MatchPatch{ my $self = shift; my ($InstalledPatches,$patch,$Platform)=@_; my @Patches=split(/\s+/,$InstalledPatches); my $MissFlag=0; my $OutdateFlag=0; my $UncertifiedFlag=0; my $PatchExist=undef; $self->{PatchesFlag}->AddStatus("Passed"); $self->trace(4,"Component","Matching patch $patch->{Name}, PatchIsBad=$patch->{PatchIsBad}\n"); if ($InstalledPatches !~ /$patch->{Name}/){ $self->trace(4,"Component","Patch $patch->{Name} is not installed\n"); if ($patch->{IfAbsent}){ ($status,$installedPatch)=$self->ExecCommand("/tmp/exec_command.$$",$patch->{IfAbsent}); chomp($installedPatch); if ($installedPatch =~ /$patch->{Name}/){ $patch->{Found}=1; if ($patch->{PatchIsBad}){ $self->{PatchesFlag}->AddStatus("Failed"); $self->{BadPatchesFound}=1; } } #elsif(! $patch->{PatchIsBad}){$MissFlag=1;} } if( !$patch->{Found} && ($Platform =~ /Solaris/) && (! $patch->{PatchIsBad})){ ($PatchBase,$PatchLevel)=split(/-/,$patch->{Name}); #print "PatchBase=$PatchBase; InstalledPatches=$InstalledPatches\n"; if ($InstalledPatches =~ /$PatchBase/){ # patch found but have wrong level $patch->{Found}=1; @MatchPatches=grep(/$PatchBase/,@Patches); $MaxPatchLevel=$MatchPatches[0]; #find the max level for PatchBase $MaxPatchLevel =~ s/\d*-//; foreach $patchlevel (@MatchPatches){ $patchlevel =~ s/\d*-//; if ($patchlevel gt $MaxPatchLevel){$MaxPatchLevel=$patchlevel;} } $PatchExist=$PatchBase."-".$MaxPatchLevel; $PatchLevel=$PatchExist; $PatchLevel=~ s/\-//; #patch exist number $MinLevel=$patch->{MinLevel}; $MinLevel=~ s/\-//; # minimal level patch number if ($PatchLevel >= $MinLevel){ $patch->{UncertifiedFlag}=1; $self->{UncertifiedPatches}=+1; $patch->{Detected}=$PatchExist; $self->{PatchesFlag}->AddStatus("Warning"); } else{ $patch->{OutdatedFlag}=1; $self->{OutdatedPatches}=+1; $patch->{Detected}=$PatchExist; $self->{PatchesFlag}->AddStatus("Failed"); } } elsif (! $patch->{PatchIsBad}){$MissFlag=1;} } elsif(! $patch->{PatchIsBad}){$MissFlag=1;} } else { $self->trace(4,"Component","Found patch $patch->{Name}\n"); $patch->{Found}=1; $patch->{Detected}=$patch->{Name}; if ($patch->{PatchIsBad}){ $self->{PatchesFlag}->AddStatus("Failed"); $self->{BadPatchesFound}=1; } } if ($MissFlag || (!$patch->{Found} &&(! $patch->{PatchIsBad})) ){ $self->{MissedPatches}=1; $patch->{Detected}="None"; $self->{PatchesFlag}->AddStatus("Failed"); } $self->trace(4,"Component","patch=$patch->{Name},PatchIsBad=$patch->{PatchIsBad}, Found=$patch->{Found}, Detected=$patch->{Detected}\n"); if (!$self->{PatchesFlag}->GetParam("Warning") && !$self->{PatchesFlag}->GetParam("Failed")){ $self->{PatchesFlag}->AddStatus("Passed"); } } sub PatchesReport{ my $self = shift; my $Platform = shift; my $InstalledPatches = shift; my $patchpnt=undef;# all patches required for component if (@_){$patchpnt=shift;} my $match; my @patchlist=undef; if (defined $patchpnt){ @patchlist=@$patchpnt; foreach $patch (@patchlist){ next if ($patch eq ""); $self->MatchPatch($InstalledPatches,$patch,$Platform); } } ##### define PatchFlag ####### if ($self->{PatchesFlag}->GetParam("Failed")){ $self->{PatchFlag}="[FAILED]"; } elsif($self->{PatchesFlag}->GetParam("Warning")){ $self->{PatchFlag}="[WARNING]"; } else{$self->{PatchFlag}="[PASSED]";} ############## if ($self->{CompGroup} eq "OSComp"){ $self->printf2("%s"."."x(70-length("OS patches"))."%s\n","OS patches",$self->{PatchFlag}); } else{ $self->printf2("%s"."."x(70-length(" Product patches"))."%s\n"," Product patches",$self->{PatchFlag}); } #print "PatchFlag is $self->{PatchFlag}\n"; if ($self->{PatchFlag} eq "[PASSED]"){return $self->{PatchFlag};} if ($self->{MissedPatches}){ if (ref($self) eq "customerReport"){ $self->printf2(" "x (5)."Missing patches:\n"); } foreach $patch (@patchlist){ if (($patch->{Found}== 0) && !$patch->{PatchIsBad}){ $::report->PatchReport("Missing",$patch); } } } if ($self->{OutdatedPatches}){ if (ref($self) eq "customerReport"){ $self->printf2(" "x (5)."Outdated patches:\n"); } foreach $patch (@patchlist){ if ($patch->{OutdatedFlag}){ $::report->PatchReport("Outdated",$patch); } } } if ($self->{UncertifiedPatches}){ if (ref($self) eq "customerReport"){ $self->printf2(" "x (5)."Uncertified patches:\n"); } foreach $patch (@patchlist){ if ($patch->{UncertifiedFlag}){ $::report->PatchReport("Uncertified",$patch); } } } if ($self->{BadPatchesFound}){ $self->printf2(" "x (5)."Problematic patches:\n"); foreach $patch (@patchlist){ if ($patch->{PatchIsBad} && $patch->{Found}){ $::report->PatchReport("PatchIsBad",$patch); } } } return ($self->{PatchFlag}); } sub MatchComponent{ my $self = shift; my $requirement = shift; my $InstalledPatches = shift; my $Platform = shift; my $patchpnt = shift; my $MatchStatus; my $PatchOK=0; my $ProductName=undef; # for nice print $self->trace(4,"Component","Matching component $self->{Name}: requirement=$requirement,version=$self->{version}\n"); next if ($requirement eq "OK"); #{$MatchFlag=1;} if ($self->eval_prereq($requirement->{Data},$self->{version})){ if ((defined $requirement->{badData}) && ($requirement->{badData} =~$self->{version})){ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } else{ $Match="[PASSED]"; $MatchStatus=0; $self->{MatchFlag}->AddStatus("Passed"); } } else{ $require_ver=$requirement->{Data}; $require_ver=~ s/.*\///; if ($requirement->{exact}){ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } elsif ( $require_ver lt $self->{version}){ $Match="[WARNING]"; $MatchStatus=1; $self->{MatchFlag}->AddStatus("Warning"); } else{ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } } #report for product $ProductName=" Product version"; $::report->DefaultReport($self, $Match,$requirement->{Data},$ProductName); if ($patchpnt eq "[PASSED]"){ $self->{PatchFlag}="[PASSED]"; } if ($self->{MatchFlag}->GetParam("Failed")){ $self->printf2("%s"."."x(70-length(" Product patches"))."%s\n"," Product patches","[N/A]"); $self->{PatchFlag}="[PASSED]";# not relevant for this requirement } elsif ($patchpnt ne "[PASSED]"){ $self->PatchesReport($Platform,$InstalledPatches,$patchpnt); } else{$self->PatchesReport($Platform,$InstalledPatches);} $self->trace(4,"Component","Match component status=$MatchStatus, PatchFlag=$self->{PatchFlag}\n"); return ($MatchStatus,$self->{PatchFlag});# return 0 if passed , 1 if failed } 1; package Software;@ISA = qw(Component); sub new{ my $classname = shift; my $class = ref($classname) || $classname; my $component=shift; my $fullname = shift; my $ComponentGroup = shift; my ($name,$basedir,$version,$fixed)=split(/:/,$component); #print "name=$name,basedir=$basedir,version=$version,fixed=$fixed\n"; if ("$fullname" eq ""){$fullname=$name;} $self=new Component($fullname,$ComponentGroup); $self->{Name}=$name; $self->{basedir}=$basedir; $self->{version}=$version; $self->{fixed}=$fixed; if ("$self->{basedir}" ne ""){ $self->{message}="Analyzing $self->{fullname} ($self->{basedir}; V $self->{version})..."; } else{ $self->{message}="Analyzing $self->{fullname} (V $self->{version})..."; } bless($self,$class); } sub PrintComponent{ my $self = shift; if ($self->{fullname} ne "no") { $self->printf2("%-23s %s\n","Product Name:",$self->{fullname}); if ($self->{basedir} ne ""){ $self->printf2("%-23s %s\n","Product Directory:",$self->{basedir}); } $self->printf2("%-23s %s\n","Product Version:",$self->{version}); } $self->print2("\n"); } 1; package QualityPack;@ISA = qw(Software); sub new{ my $classname = shift; my $class = ref($classname) || $classname; $self = new Software(@_); bless($self,$class); } sub MatchComponent{ my $self = shift; my $requirement = shift; my $InstalledPatches = shift; my $Platform = shift; my $patchpnt = shift; my $MatchStatus; my $PatchOK=0; my $ProductName=undef; # for nice print %month_convert=(January=>"01",February=>"02",March=>"03",April=>"04",May=>"05",June=>"06",July=>"07",August=>"08",September=>"09",October=>"10",November=>"11",December=>"12"); $self->trace(4,"Component","Matching component $self->{Name}: requirement=$requirement,version=$self->{version}\n"); next if ($requirement eq "OK"); #{$MatchFlag=1;} if ($self->eval_prereq($requirement->{Data},$self->{version})){ if ((defined $requirement->{badData}) && ($requirement->{badData} =~$self->{version})){ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } else{ $Match="[PASSED]"; $MatchStatus=0; $self->{MatchFlag}->AddStatus("Passed"); } } else{ $requirement->{Data} =~ /(.*)_(.*)/; $require_month = $1; $require_year = $2; $self->{version} =~ /(.*)_(.*)/; $comp_month = $1; $com_year = $2; $require_ver="$require_year$month_convert{$require_month}"; $comp_ver="$com_year$month_convert{$comp_month}"; # $require_ver=$requirement->{Data}; #$require_ver=~ s/.*\///; #if ($requirement->{exact}){ # $Match="[FAILED]"; # $MatchStatus=2; # $self->{MatchFlag}->AddStatus("Failed"); #} if ( $require_ver lt $comp_ver){ $Match="[WARNING]"; $MatchStatus=1; $self->{MatchFlag}->AddStatus("Warning"); } else{ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } } #report for product $ProductName=" Product version"; $::report->DefaultReport($self, $Match,$requirement->{Data},$ProductName); if ($patchpnt eq "[PASSED]"){ $self->{PatchFlag}="[PASSED]"; } if ($self->{MatchFlag}->GetParam("Failed")){ $self->printf2("%s"."."x(70-length(" Product patches"))."%s\n"," Product patches","[N/A]"); $self->{PatchFlag}="[PASSED]";# not relevant for this requirement } elsif ($patchpnt ne "[PASSED]"){ $self->PatchesReport($Platform,$InstalledPatches,$patchpnt); } else{$self->PatchesReport($Platform,$InstalledPatches);} $self->trace(4,"Component","Match component status=$MatchStatus, PatchFlag=$self->{PatchFlag}\n"); return ($MatchStatus,$self->{PatchFlag});# return 0 if passed , 1 if failed } 1; # We put Open GL in separate package to allow different MatchComponent function package OpenGL;@ISA = qw(Software); sub new{ my $classname = shift; my $class = ref($classname) || $classname; $self = new Software(@_); bless($self,$class); } sub MatchComponent{ # for OpenGL my $self = shift; my $requirement = shift; my $InstalledPatches = shift; my $Platform = shift; my $patchpnt = shift; my $MatchStatus; my $PatchOK=0; my $ProductName=undef; # for nice print $self->trace(4,"Component","Matching component $self->{Name}: requirement=$requirement,version=$self->{version}\n"); next if ($requirement eq "OK"); #{$MatchFlag=1;} if ($self->eval_prereq($requirement->{Data},$self->{version})){ if ((defined $requirement->{badData}) && ($requirement->{badData} =~$self->{version})){ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } else{ $Match="[PASSED]"; $MatchStatus=0; $self->{MatchFlag}->AddStatus("Passed"); } } else{ # do not eqactly Match $require_ver=$requirement->{Data}; # Create list of major versions from required versions. # The major version is 2 first numbers. @requires=split(/ \|\| /,$requirement->{Data}); $required_ver=""; $min_req_ver="999.999"; if ("@requires" ne "$requirement->{Data}"){ foreach $require (@requires){ $require =~ /^[A-Z\.]*(\d+\.\d+)(\.\d+)*(-[\.\d]+)*$/; $major_require_version=$1; if ($required_ver eq "" && $major_require_version ne ""){ $required_ver=$major_require_version; } elsif($major_require_version ne ""){ $required_ver.=" || $major_require_version"; } if ($major_require_version lt $min_req_ver) { $min_req_ver=$major_require_version; } } } else{ $requirement->{Data} =~ /^[A-Z\.]*(\d+\.\d+)(\.\d+)*(-[\.\d]+)*$/; $required_ver=$min_req_ver=$1; } $self->{version} =~ /^[A-Z\.]*(\d+\.\d+)(\.\d+)*(-[\.\d]+)*$/; $major_comp_version=$1; #if ($requirement->{exact}){ # $Match="[FAILED]"; # $MatchStatus=2; # $self->{MatchFlag}->AddStatus("Failed"); #} if ($self->eval_prereq($required_ver,$major_comp_version) || $major_comp_version ge $min_req_ver){ # if($major_require_version eq $major_comp_version){ #elsif ( $require_ver lt $self->{version}){ $Match="[WARNING]"; $MatchStatus=1; $self->{MatchFlag}->AddStatus("Warning"); } else{ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } } #report for product $ProductName=" Product version"; $::report->DefaultReport($self, $Match,$requirement->{Data},$ProductName); if ($patchpnt eq "[PASSED]"){ $self->{PatchFlag}="[PASSED]"; } if ($self->{MatchFlag}->GetParam("Failed")){ $self->printf2("%s"."."x(70-length(" Product patches"))."%s\n"," Product patches","[N/A]"); $self->{PatchFlag}="[PASSED]";# not relevant for this requirement } elsif ($patchpnt ne "[PASSED]"){ $self->PatchesReport($Platform,$InstalledPatches,$patchpnt); } else{$self->PatchesReport($Platform,$InstalledPatches);} $self->trace(4,"Component","Match component status=$MatchStatus, PatchFlag=$self->{PatchFlag}\n"); return ($MatchStatus,$self->{PatchFlag});# return 0 if passed , 1 if failed } 1; package Compiler;@ISA = qw(Software); sub new{ my $classname = shift; my $class = ref($classname) || $classname; $self = new Software(@_); if ($self->{Name} =~ /CCompiler/){ $self->{message}="Analyzing C Compiler...\n"; } elsif($self->{Name} =~ /CPPCompiler/){ $self->{message}="Analyzing C++ Compiler...\n"; } elsif($self->{Name} =~ /JavaSDK/){ $self->{message}="Analyzing Java SDK...\n"; } bless($self,$class); } sub MatchComponent { my $self = shift; my $requirement = shift; my $InstalledPatches = shift; my $Platform = shift; my $patchpnt = shift; my $isFirst=shift; my $MatchStatus=0; my $PatchOK=0; my $ProductName=undef; # for nice print $self->trace(4,"Compiler","Matching compiler component $self->{Name}: requirement=$requirement, version=$self->{version}\n"); next if ($requirement eq "OK"); #{$MatchFlag=1;} if ($requirement ne "N/A"){ if ($self->eval_prereq($requirement->{Data},$self->{version})){ if ((defined $requirement->{badData}) && ($requirement->{badData} =~$self->{version})){ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } else{ $Match="[PASSED]"; $MatchStatus=0; $self->{MatchFlag}->AddStatus("Passed"); } } else{ $require_ver=$requirement->{Data}; $require_ver=~ s/.*\///; if ( $require_ver lt $self->{version}){ $Match="[WARNING]"; $MatchStatus=1; $self->{MatchFlag}->AddStatus("Warning"); } else{ $Match="[FAILED]"; $MatchStatus=2; $self->{MatchFlag}->AddStatus("Failed"); } } if ($Match ne "[PASSED]"){ # do not print Compiler if version is wrong $self->{PatchFlag}="[PASSED]"; return($MatchStatus,$self->{PatchFlag}); } $::report->DefaultReport($self,$Match,$requirement->{Data},$self->{fullname}); if ($patchpnt eq "[PASSED]"){ $self->{PatchFlag}="[PASSED]"; } } else{ $::report->DefaultReport($self, "[N/A]", "[N/A]", $self->{fullname}); } if ($patchpnt ne "[PASSED]"){ $self->PatchesReport($Platform,$InstalledPatches,$patchpnt); } else{$self->PatchesReport($Platform,$InstalledPatches);} $self->trace(4,"Compiler","Match compiler status=$MatchStatus, PatchFlag=$self->{PatchFlag}\n"); return ($MatchStatus,$self->{PatchFlag});# return 0 if passed , 1 if failed } 1; package OS;@ISA = qw(Component); sub new{ my $classname = shift; my $class = ref($classname) || $classname; my $component=shift; my $fullname = shift; my $ComponentGroup = shift; my ($name,$version)=split(/\//,$component); if ("$fullname" eq ""){$fullname=$name;} $self=new Component($fullname,$ComponentGroup); $self->{Name}=$name; $self->{version}=$version; bless($self,$class); } sub MatchComponent{ my $self = shift; my $requirement = shift; my $InstalledPatches = shift; my $Platform = shift; my $patchpnt = shift; my $OnlyComp = @_; my $MatchStatus; my $PatchOK=0; my $ProductName=undef; # for nice print next if ($requirement eq "OK"); #{$MatchFlag=1;} $self->trace(4,"OS","Matching software component $self->{Name}: requirement=$requirement->{Name}, bad data=$requirement->{badData},version=$self->{version}\n"); if ($self->eval_prereq($requirement->{Data},$self->{version})){ if ((defined $requirement->{badData}) && ($requirement->{badData} =~$self->{version})){ $MatchStatus=1; $Match="[FAILED]"; $self->{MatchFlag}->AddStatus("Failed"); } else{ $MatchStatus=0; $Match="[PASSED]"; $self->{MatchFlag}->AddStatus("Passed"); } } else{ $require_ver=$requirement->{Data}; $require_ver=~ s/.*\///; $requireVerNumber=$require_ver; $requireVerNumber =~ s/-//; $versionNumber=$self->{version}; $versionNumber=~ s/-//; $self->trace(4,"OS","requirement=requirement->{Name}, requireVerNumber=$requireVerNumber,versionNumber=$versionNumber,exact= $requirement->{exact}\n"); if ($requirement->{exact} || ($requireVerNumber > $versionNumber)){ $MatchStatus=2; $Match="[FAILED]"; $self->{MatchFlag}->AddStatus("Failed"); } else{ $MatchStatus=1; $Match="[WARNING]"; $self->{MatchFlag}->AddStatus("Warning"); } } $ProductName="$self->{fullname}"; $::report->DefaultReport($self, $Match,$requirement->{Data},$ProductName); if ($patchpnt eq "[PASSED]"){ $self->{PatchFlag}="[PASSED]"; } $self->trace(4,"OS","Match OS status=$MatchStatus, PatchFlag=$self->{PatchFlag}"); return ($MatchStatus,$self->{PatchFlag});# return 0 if passed , 1 if failed } 1; package Match; sub new{ my $classname = shift; my $class = ref($classname) || $classname; my $self = {}; $self->{Passed}=0; $self->{Warning}=0; $self->{Failed}=0; bless($self,$class); } sub AddStatus{ my $self = shift; my $status = shift; $self->{$status}+=1; } sub GetParam{ my $self = shift; my $param = shift; return $self->{$param}; } sub GetMatch{ my $self = shift; my $RequireName=shift; #if there is at least one compiler that was passed return PASSED if (($RequireName eq "JavaSDK" || $RequireName =~ /Compiler/) && $self->{Passed} ){ return "[PASSED]"; } if ($self->{Failed}){return "[FAILED]";} elsif($self->{Warning}){return "[WARNING]";} else {return "[PASSED]";} } 1; package Hardware;@ISA = qw(Component); sub new{ my $classname = shift; my $class = ref($classname) || $classname; my $component=shift; my $fullname = shift; my $ComponentGroup = shift; my($name,$version)=split(/\//,$component); if ("$fullname" eq ""){$fullname=$name;} $self=new Component($fullname,$ComponentGroup); $self->{Name}=$name; $self->{version}=$version; $self->{message}="Analyzing $self->{fullname} $self->{version}..."; bless($self,$class); } 1; package Download; #require HTTP::Request; #require LWP; #require HTTP::Status; sub new{ my $classname = shift; my $filename= shift; my $class = ref($classname) || $classname; my $self={}; bless($self,$class); } sub getFile{ my $self=shift; my $file = shift; my $outfile = shift; my $status=0; $ua = LWP::UserAgent->new; $request=HTTP::Request->new(GET => $file); $response = $ua->request($request); # see codes in HTTP::Status for _rc #if (($response->{_rc} >= 200) && ($response->{_rc} <= 300)){ $self->print2("\nDownloading '$file' ... "); if (HTTP::Status::is_success($response->{_rc})){ open(OUTFILE,">$outfile") || die "Cannot open target file $outfile: $!\n"; print OUTFILE $response->content; close(OUTFILE); $self->print2("Done.\n"); } else{ # $self->trace(3,"Download","Failed download $file: $response->{_msg}"); $self->print2("Failed.\n\t***$response->{_msg}\n"); $status=1; } return $status;# 0- if success , 1 - in the other case } 1; #This package handling working with inifile package Inifile; sub new{ my $classname = shift; my $filename= shift; my $class = ref($classname) || $classname; my $self={}; $self->{name}=$filename; bless($self,$class); } #the function return list of key=value for specific section sub GetProfileSection{ my $self = shift; my ($section,$default) = @_; my @list=undef; open(CONFIG,"$self->{name}")|| die "Cannot open configuration file $self->{name}: $!\n"; @lines=; close(CONFIG); while ($line = shift @lines){ chomp($line); next if (($Ruleset==0) && ($line !~ /\[$section\]/)); if (($Ruleset == 1) && ($line =~ /^\[/)){ $Ruleset=0;last; } if ($line =~ /\[$section\]/){ $Ruleset=1;next; } if ($Ruleset == 1){ push(@list,$line);next; } } if (!defined @list ){return $default;} if ("$list[0]" eq ""){shift @list;} return @list; } #This function return the value for specific key in specific section sub GetProfileString{ my $self = shift; my ($section,$key,$default)=@_; my $Ruleset=0; my $string=undef; open(CONFIG,"$self->{name}")|| die "Cannot open configuration file $self->{name}: $!\n"; @lines=; close(CONFIG); while ($line = shift @lines){ next if (($Ruleset==0) && ($line !~ /\[$section\]/)); if (($Ruleset == 1) && ($line =~ /^\[/)){ $Ruleset=0;last; } if ($line =~ /^\[$section\]/){ $Ruleset=1;next; } if ($line =~ /^$key/){ ($trush,$string)=split(/=/,$line); } } if (defined $string){return $string;} else {return $default;} } #This function return insert the value for specific key in specific section sub WriteProfileString{ my $self = shift; my ($section,$key,$string)=@_; my $Ruleset=0; my $string=undef; my $key_found=0;#evaluate if the key found in the section open(CONFIG,"$self->{name}")|| die "Cannot read configuration file $self->{name}: $!\n"; @lines=; close(CONFIG); open(CONFIG,">$self->{name}")|| die "Cannot write into configuration file $self->{name}: $!\n"; while ($line = shift @lines){ if (($Ruleset==0) && ($line !~ /\[$section\]/)){ print CONFIG "$line";next; } if (($Ruleset==1) && ($line =~ /^\[/)){ $Ruleset=0; if ($key_found==0){# if the key does not exist add the key=value to the section print CONFIG "$key=$string\n"; } print CONFIG "$line";next; } if ($line =~ /\[$section\]/){ $Ruleset=1; print CONFIG "$line";next; } if (($line =~ /^$key/)&& ($Ruleset==1)){ $line=$key."=".$string; $key_found=1; print CONFIG "$line";next; } print CONFIG "$line"; } close(CONFIG); } 1; package System; sub new{ my $classname = shift; my $class = ref($classname) || $classname; my $self={}; $self->{SysID}="None"; #will be set by find_platform $self->{uname}=`uname`;chomp($self->{uname}); $self->{OnlyOS}=0; # check only Operating System staff $self->{OnlyComp}=0; # check only Compiler staff $self->{CheckOSOnly}=0;# check only OS Level $self->{doUpdate}=0; # do download of database files $self->{SystemDBfile}=undef; # database contain commands to dedicate compinents on different platform $self->{ExelRequireFile}=undef; # contain requirements $self->{TxtRequireFile}=undef; $self->{PatchDBfile}=undef; #contain commands to find patches on different platforms $self->{ExelSolutionFile}=undef; # contain requirement patches $self->{TxtSolutionFile}=undef; $self->{ExecCommandFile}=undef; #file used by find_platform to run commands $self->{logfile}=undef; $self->{UserMode}=undef; #can be 'dev' or 'run' $self->{DoTrace}=0; #debug flag $self->{OSComp}=undef; #list of OS Component objects $self->{SoftwareComp}=undef; #list of Software Component objects $self->{HardwareComp}=undef; #list of Hardware Component objects $self->{CCompilerComp}=undef; #list of C Compiler Software Component objects $self->{CPPCompilerComp}=undef; #list of C++ Compiler Software Component objects $self->{ReleaseNum}=undef; $self->{RequirementData}=undef; #list of Requirement objects $self->{RequiredPatches}=undef; #list of Patch objects $self->{MandatoryRequirements}=undef; #will be set from kb_systemid.txt $self->{date}=`date`;chomp($self->{date}); $self->{OS}=undef; # will be set from kb_systemid.txt - names of components in OS group $self->{Hardware}=undef; #will be set from kb_systemid.txt - names of components in Hardware group $self->{Software}=undef; #will be set from kb_systemid.txt - names of components in Software group $self->{ComponentFullName}=undef; #will be set from kb_systemid.txt $self->{required_categories}=undef; #set by SetRequiredCategories if exists $self->{config} $self->{errors}=0;# if the platform is OK status is 0, else status=1 , status=100 if there is internal error $self->{warnings}=0; bless($self,$class); } sub printHeader{ my $self = shift; $self->printf2("\n"."="x (78)."\n"); $self->printf2("\n"." "x ((70-length("Visual Mainwin System Requirements Analysis Report"))/2)."%s","Visual Mainwin System Requirements Analysis Report\n\n"); $self->print2("Generated by: mwcheck_platform\n"); my $release=$self->{ReleaseNum}; $release =~ s/MainWin\///; if ($ENV{'MWHOME'}){ $full_release=`$ENV{'MWHOME'}/bin/mwversion 2> /dev/null`; if($? == 0){ $release=$full_release;chomp($release); } $short_release=`$ENV{'MWHOME'}/bin/mwversion -s 2> /dev/null`; if($? == 0){ ($release_num,$trush)=split(/\s+/,$short_release); $self->{ReleaseNum}="MainWin/$release_num"; } if ("$release_num" eq ""){ $self->print2("\nError: Cannot detect release number for this installation\n"); $self->DoExit(1); } } $self->print2("VMW Version: $release\n"); $self->print2("Report Date: $self->{date}\n\n"); $self->printf2("="x (78)."\n"); $self->printf2("\n"." "x ((70-length("Part I: Configuration Scan"))/2)."%s","Part I: Configuration Scan\n\n"); $self->printlog("Collecting system information, please stand by...\n\n"); print STDERR "Collecting system information, please stand by...\n\n"; } sub ParseArguments{ my $self = shift; my @args = @_; while ($arg =shift @args){ if ("$arg" eq "-mwrelease") { $release=shift @args; $self->{ReleaseNum} = "MainWin/".$release; } elsif ("$arg" eq "-host") {$self->{host}=shift @args;} elsif ("$arg" eq "-os") {$self->{OnlyOS}=1;} elsif ("$arg" eq "-compiler") {$self->{OnlyComp}=1;} elsif ("$arg" eq "-oscheck") {$self->{CheckOSOnly}=1;} elsif ("$arg" eq "-update") {$self->{doUpdate}=1;} elsif ("$arg" eq "-dryrun") {$self->{dryrun}=1;} elsif ("$arg" eq "-run") {$self->{enduser}=1;} elsif ("$arg" =~ /-trace/) { $arg =~ /trace(\d*)/; if ($1 eq ""){$::trace=1;} else{$::trace=$1;} } elsif ("$arg" eq "-log") {$self->{logfile}=shift @args;} else {$self->Usage();} } if (($self->{OnlyOS} && $self->{OnlyComp}) || ($self->{OnlyOS} && $self->{CheckOSOnly}) || ($self->{OnlyComp} && $self->{CheckOSOnly}) || ($self->{OnlyOS} && $self->{OnlyComp} && $self->{CheckOSOnly})){ print STDERR "\nuse only one of follow flags: '-os' or '-compiler' or '-oscheck'\n\n"; $self->Usage(); } } sub Usage{ my $self = shift; print "\nUsage: mwcheck_platform [-host ] [-trace] [-os | -compiler | -oscheck]\n"; print "\t-trace - creates a more detailed log file. Helpful for debugging purposes\n"; print "\t-os - check up only Operating System (OS) settings\n"; print "\t-compiler - check up only compiler settings\n"; print "\t-oscheck - check OS level, return 0 if OK or 1 in other case\n"; print "\t-host - launch mwcheck_platform on given remote host\n\n"; exit(1); } #This function check executable permissions for all tools that used for platform and if there is a tool that has no 'x' permission abort the sms sub ErrorPermission{ my $self = shift; my $file = shift; print "\n*** Cannot run $file - no execution permission.\nmwcheck_platform requires this utility in order to complete its execution.\nRun mwcheck_platform as the super user,\nor have the file permissions modified to allow you execution rights.\n\n"; } sub CheckToolsPermissions{ my $self = shift; my $status=0; if ($self->{uname} eq "HP-UX"){ if (! -x "/usr/sbin/swlist"){ $self->ErrorPermission("/usr/sbin/swlist"); $status+=1; } } elsif($self->{uname} eq "SunOS"){ if (! -x "/bin/showrev"){ $self->ErrorPermission("/bin/showrev"); $status+=1; } if (! -x "/bin/pkginfo"){ $self->ErrorPermission("/bin/pkginfo"); $status+=1; } } elsif($self->{uname} eq "AIX"){ if (! -x "/bin/lslpp"){ $self->ErrorPermission("/bin/lslpp"); $status+=1; } if(! -x "/usr/sbin/instfix"){ $self->ErrorPermission("/usr/sbin/instfix"); $status+=1; } } elsif ($self->{uname} eq "Linux"){ if (! -x "/usr/bin/find"){ $self->ErrorPermission("/usr/bin/find"); $status+=1; } } if ($status != 0){$self->DoExit(1);} } #This function is unused now sub SetReleaseNumber{ my $self = shift; my $config_obj=new Inifile($self->{config}); my $release=$config_obj->GetProfileString("CustomerData","VMW_Version","4.0"); $self->{ReleaseNum}="MainWin/".$release; } sub SetCustomerData{ my $self = shift; my $config_obj=new Inifile($self->{config}); #my $logfile=$config_obj->GetProfileString("CustomerData","Logfile","/var/tmp/mwcheck_platform.log.$$");chomp($logfile); #$self->{logfile}=$logfile; $warnMessage=$config_obj->GetProfileString("CustomerData","WarningMessage","System check was finished with warnings. For details see the logfile");chomp($warnMessage); $failureMessage=$config_obj->GetProfileString("CustomerData","WarningMessage","System check was finished with errors. For details see the logfile");chomp($failureMessage); $self->{SuccessMessage}=$config_obj->GetProfileString("CustomerData","WarningMessage","System check was succeded");chomp($self->{SuccessMessage}); $self->{WarningMessage}=$warnMessage." $logfile."; $self->{FailureMessage}=$failureMessage." $logfile."; } sub find_file{ my $self = shift; my($file)=@_; if ( -e "./$file"){return "./$file";} elsif( -e "$ENV{'MWHOME'}/../sms/$file"){return "$ENV{'MWHOME'}/../sms/$file";} elsif( -e "/vobs/build/sms/$file"){return "/vobs/build/sms/$file";} else{ @script=split(/\//,$0); pop(@script); $scriptpath=join("/",@script); chdir($scriptpath); $pathname=`pwd`; chomp($pathname); $filename=$pathname."/".$file; if (-f $filename) {return $filename;} else{return "not found";} } } sub GetSMSDefinitions{ my $self = shift; if (! (-e "$ENV{'MWHOME'}/../sms/sms_sysdef.pl")){ $self->{UserMode}="run"; $sms_definitions=$self->find_file("sms_sysdef.pl"); if ($sms_definitions eq "not found"){ print STDOUT "Cannot find sms_definitions file\n";return 1;} $ScriptPath=$sms_definitions; $ScriptPath=~ s/\/sms_sysdef\.pl//; chdir("$ScriptPath"); open(DEFINITION,"$sms_definitions") || print STDOUT "Cannot read sms_definition file $sms_definitions: $! \n"; @definitions = ; close(DEFINITION); unlink ("$sms_definitions.orig"); rename ("$sms_definitions","$sms_definitions.orig"); $swap_sms=1; open(DEFINITION,">$sms_definitions") || print STDOUT "Cannot open sms_definitions file for write $sms_definitions: $! \n"; if(! -w $sms_definitions){return 1;} print DEFINITION "# This is a -*- perl -*- script\n\n"; print DEFINITION "\$ScriptPath=\"$ScriptPath\";\n"; while($line=shift @definitions){ next if ($line =~ /ScriptPath=/); next if ($line =~ /^$/); next if ($line =~ /\# This is a -\*- perl -\*- script/); print DEFINITION "$line"; } close(DEFINITION); require "$sms_definitions"; } else{ $self->{UserMode}="dev"; require "$ENV{'MWHOME'}/../sms/sms_sysdef.pl"; } # set Compiler dir for linux @com_dir=split(/\//,$ScriptPath); pop(@com_dir); $self->{CompilerDir}=join("/",@com_dir); #------ $self->{SystemDBfile}=$SystemDBfile; $self->{ExelRequireFile}=$ExelRequireFile; $self->{TxtRequireFile}=$TxtRequireFile; $self->{PatchDBfile}=$PatchDBfile; $self->{ExelSolutionFile}=$ExelSolutionFile; $self->{TxtSolutionFile}=$TxtSolutionFile; if (!defined ($self->{logfile})){$self->{logfile}=$logfile;} $self->{ConfigFile}=$ConfigFile; $self->{config}=$config;#contain categories relevant for end-users and dbfiles to download $self->{ExecCommandFile}=$ExecCommandFile; $self->{ScriptPath}=$ScriptPath; $self->{patchConfig}=$PatchConfigFile; $self->{patchDesc}=$PatchDescFile; return 0; } sub DoExit{ my $self = shift; my $exitstatus = shift; close(LOGFILE); exit($exitstatus); } sub PrepCommand{ my $self = shift; my($Property,$Command,$Group,$SysFlag)=@_; my $command_result; my $status= 0; my @result=undef; #print "SysFlag=$SysFlag\n"; #$self->trace(5,"","Property=$Property,Command=$Command\n"); my(@command_lines)=""; if ($SysFlag == 2){ # run on mwspr output file push(@command_lines,"export SprFile=$SprFile\n"); } if ($SysFlag == 3){ # run on mwspr output file push(@command_lines,"export SprPatchFile=$SprPatchFile\n"); } push(@command_lines,$Command); $self->trace(1,"","running command '$Command'\n"); ($status,$command_result_pnt)=$self->ExecCommand($self->{ExecCommandFile},@command_lines); @result=@$command_result_pnt; $self->trace(2,"","command_result=@result, status=$status\n"); if (@result){ if (($SysFlag == 1) || ($SysFlag == 2) || ($SysFlag == 4) || ($SysFlag == 5)) { # run from find_platform if ((($Property =~ /OpenGLVersion/)||($Property=~/Compiler/)) && ($self->{uname} eq "SunOS")){ $FulResult=$self->FindLocalComponents($Property,@result); Analy } elsif(($Property=~/Compiler/) && (($self->{uname} eq "HP-UX") || ($self->{uname} eq "AIX"))){ $command_result=$result[0]; $FulResult=$command_result; } elsif(($Property=~/Compiler/) && ($self->{uname} eq "Linux")){ $command_result=$result[0]; if ($Property=~/CCompiler/){ #C Compiler $comp_path=$self->ConvertPath("$self->{CompilerDir}/misc/linux/gcc/fixed/bin/gcc"); } else{ # C++ compiler $comp_path=$self->ConvertPath("$self->{CompilerDir}/misc/linux/gcc/fixed/bin/g++"); } $self->trace(5,"","Path $self->{CompilerDir}/misc/linux/gcc/fixed/bin/gcc converted to $comp_path\n"); if (-x "$comp_path"){ $FulResult="Software/$Property:$comp_path:2.95-Mainsoft-edition-20000202 $command_result"; } else{ $FulResult=$command_result; } } elsif($Group=~/Software/){ $command_result=$result[0]; $FulResult=$command_result; } else{ $command_result=$result[0]; $FulResult=$Group."/".$Property."/".$command_result; } if ($Property =~ /MWPlatform/){ $self->{Platform}=$command_result; } if ($Property =~ /Open3D/){ # for Digital mashines $command_result =~ s/.*(\d)(\d\d)$/$1.$2/; $FulResult="$Property/$command_result"; } #$FulResult =~ s/\//\\\//g; #if (!($self->{SysID} =~ /$FulResult/)){ $self->{SysID}="$self->{SysID} $FulResult "; # Define System params if (($Group eq "Software")&&($FulResult =~ /Compiler/)){ @compilers=split(/\s+/,$FulResult); foreach $comp (@compilers){ ($comp,$trush,$ver,@trush)=split(/:/,$comp); $self->{System}=$self->{System}." $comp/$ver "; #print "CCC:add to sysytem :$comp/$ver\n"; } } elsif($Group eq "Software"){ ($comp,$trush,$ver,@trush)=split(/:/,$FulResult); $self->{System}=$self->{System}." $comp/$ver "; } else{$self->{System}=$self->{System}."$FulResult ";} #} #$FulResult =~ s/\\//g; $self->trace(5,"","In find_platform SysID: $self->{SysID}\n"); } else{ $command_result=$result[0]; $self->{PatchList}="$self->{PatchList} $command_result"; $self->{PatchList} =~ s/\n/ /; $self->trace(5,"","In find_platform installed PatchList: $PatchList\n"); } } return $status; } sub find_platform{ my $self= shift; my $system_db = shift; my $SysFlag = shift; my @sysid_db=undef; my $Ruleset=0; my $Rule=0; my $status=0; my $Definitions=0; open(SYSID,"$system_db")|| print STDOUT "Cannot read system database file $system_db: $! \n"; if (! -r SYSID){ return 1;} @sysid_db=; close(SYSID); while ($line = shift @sysid_db){ chomp($line); next if ($line =~ /^$/); # empty line if ($line =~ /^Definitions:/){ $Definitions=1;next; } if ($line =~ /^End Definitions/){ $Definitions=0;next; } if ( $line =~ /Ruleset/ ){ $Ruleset=1;next; } if ( $line =~ /^EndRuleset/ ) { $Ruleset=0;next; } next if (($Definitions !=1) &&($Ruleset !=1)); #Set Description part if ($Definitions ==1){ if ($line =~ /^OS components/){ ($trush,$self->{OS})=split(/:/,$line); $self->{OS} =~ s/^\s+//; } elsif($line =~ /^Hardware components/){ ($trush,$self->{Hardware})=split(/:/,$line); $self->{Hardware} =~ s/^\s+//; } elsif($line =~ /^Software components/){ ($trush,$self->{Software})=split(/:/,$line); $self->{Software} =~ s/^\s+//; } elsif($line =~ /^Compiler components/){ ($trush,$self->{Compiler})=split(/:/,$line); $self->{Compiler} =~ s/^\s+//; } elsif($line =~ /^MandatoryRequirements/){ ($trush,$self->{MandatoryRequirements})=split(/:/,$line); $self->{MandatoryRequirements} =~ s/^\s+//; } elsif($line =~ /^$self->{uname}_MandatoryRequirements/){ ($trush,$requirements)=split(/:/,$line); $requirements =~ s/^\s//; $self->{MandatoryRequirements} = $self->{MandatoryRequirements}." $requirements"; } elsif($line =~ /^ComponentFullName/){ $line =~ s/ComponentFullName://; $line=~ s/^\s+//; @names=split(/,/,$line); foreach $name (@names){ ($comp,$fullname)=split(/=/,$name); $self->{ComponentFullName}{$comp}=$fullname; } } #list conatin names of Properties relevant for this category elsif($line =~ /^Category/){ ($category,$list)=split(/:/,$line); $category=~ s/Category_//; $self->{Categories}{$category}=$list; $self->trace(3,"","Category $category contain following list of properties: $list\n"); } elsif ($line =~ /^ExactRequirements/){ $line =~ s/ExactRequirements://; $line=~ s/^\s+//; $self->{ExactRequirements}=$line; } } # Set rules part if ( $line =~ /^Rule/ ){ @line=split(/ /,$line); $Rule= $line[1];next; } if ($line =~ /^Prereq/){ @line=split(/\s+/,$line); shift @line; $Prereq = join(' ',@line); $self->trace(5,"","In find_platform: Prereq is $Prereq\n"); if (! $self->eval_prereq($Prereq,$self->{SysID}) ){ # check if the rule is for the platform #print "\n SHIFTING\n"; shift @sysid_db;shift @sysid_db;shift @sysid_db;next; } else { next;} } if ($line =~ /^Property/){ @line=split(/\s+/,$line); shift @line; $Property = join(' ',@line); #Check If the Propery in required categories list # if (! $self->CheckIfPropertyInCategoryList($Property)){ #shift @sysid_db;shift @sysid_db; #} next; } if ($line =~ /^Group/){ @line=split(/\s+/,$line); shift @line; $Group = join(' ',@line);next; } if ($line =~ /Command/) { @line=split(/\s+/,$line); shift @line; $Command = join(' ',@line); $self->trace(5,"","\n\nThe following rule:$Rule; Ruleset:$Ruleset; Prereq:$Prereq; Property:$Property; Group:$Group; Command:$Command will be executed\n\n"); if ( $Prereq && $Property ){ #next if (($Property =~ /CCompiler/) || ($Property =~ /CPPCompiler/) || ($Property =~ /OpenGLVersion/)); $status+=$self->PrepCommand($Property,$Command,$Group,$SysFlag); } else { print "Rule: $Rule has incorrect format\n";} } $Rule=0; $Prereq=""; $Property=""; } if ($self->{SysID} =~ /None/){$self->{SysID} =~ s/None//;} $self->{SysID} =~ s/^\s+//;#remove spaces in the begining if ($self->{UserMode} eq "dev"){ $self->{SysID}=$self->{SysID}." UserMode/dev"; $self->{System}=$self->{System}." UserMode/dev"; } @system=split(/\s+/,$self->{SysID}); # foreach $comp (@system){ # if ($comp =~ /Compiler/){ # ($comp,$trush1,$ver,@trush)=split(/:/,$comp); # } # } # $self->{SystemID}= return $status; } sub FindLocalComponents{ my $self = shift; my $component = shift; my @lines=@_; my $Prereq=0; my $List=undef; while($line =shift @lines){ chomp($line); next if ("$line" eq ""); if ($line =~ /PKGINST/){ $Prereq=1; } next if (! $Prereq); if ($line =~ /NAME/){ ($trush,$name)=split(/:/,$line); $name =~ s/^\s+//; ($fullname,$trush)=split(/,/,$name); #$fullname =~ s/\d.*$//; # remover version from full name $fullname =~ s/\s+/_/g; next; } if ($line =~ /VERSION/){ ($trush,$version)=split(/:/,$line); $version =~ s/^\s+//; ($ver,$trush)=split(/,/,$version); $version=$ver; # Workshop 5 has 5.0 version and from workshop 6 the versioning is # 5.1 for Workshop 6 # 5.2 - for Workshop 6 update 1, etc # Following code translate Workshop version to real version if ($version =~ /^6/){ my($base,$serial)=split(/\./,$version); $serial++; $base--; $version=$base.".".$serial; } next; } if ($line =~/BASEDIR/){ ($trush,$basedir)=split(/:/,$line); $basedir =~ s/^\s+//; $List=$List." Software/".$component.":".$basedir.":".$version.":".$fullname; $Prereq =0;next; } } $List =~ s/^\n//; $List =~ s/\s+//; return $List; } sub PrintComponents{ my $self = shift; my $compFlag = shift; my @complist=undef; $comlistpnt=$self->{$compFlag}; %components=%$comlistpnt; @complist=keys %components; foreach $component (@complist){ next if ($component eq ""); next if ($self->{OnlyComp} && !($component =~ /Compiler/)); $self->{$compFlag}{$component}->PrintComponent(); } } sub AddRequiredPatch{ my $self = shift; my ($Patch,$PatchType,$IfAbsent,$Description,$MinLevel,$PatchIsBad)=@_; my @patchlist=undef; $self->trace(4,"","Adding patch=$Patch, PatchType=$PatchType to RequiredPatches list\n"); my $patch=new Patch($Patch,$PatchType,$IfAbsent,$Description,$MinLevel,$PatchIsBad); $patch->SetLogfile($self->{logfile}); if (defined $self->{RequiredPatches}){ @patchlist=@{$self->{RequiredPatches}}; push(@patchlist,$patch); } else{ push(@patchlist,$patch); if ($patchlist[0] eq ""){shift @patchlist;} } $self->{RequiredPatches}=\@patchlist; } sub SetComponents{ my $self = shift; my (@OSComp, @HardwareComp, @SoftwareComp,@CompilerComp); my $CompFullNamePnt=$self->{ComponentFullName}; my %ComponentFullName=%$CompFullNamePnt; my $group; foreach $component ( split(/\s+/,$self->{SysID})){ chomp($component); next if ($component eq ""); next if ($component eq "UserMode/dev"); @params=split(/\//,$component); $group = shift @params; $component=join("/",@params); if ($group eq "Software"){ ($comp,$basedir,$ver,$fullname)=split(/:/,$component); } else{($comp,$ver)=split(/\//,$component);} next if ($ComponentFullName{$comp} eq "no"); $group=$self->DefineComponentGroup($comp); $self->trace(4,"","Adding component '$component' to component list of group '$group'\n"); if (($group =~ /Software/) || ($group =~ /Compiler/) || ($group =~ /JavaSDK/)){ if ("$fullname" eq ""){$fullname=$ComponentFullName{$comp};} else{$fullname =~ s/_/ /g;} if (($group =~ /Compiler/) || ($group =~ /JavaSDK/)){ $self->{$group}{$component}=new Compiler($component,$fullname,$group); } elsif($component =~ /QualityPack/){ $self->{$group}{$component}=new QualityPack($component,$fullname,$group); } elsif($component =~ /OpenGL/){ $self->{$group}{$component}=new OpenGL($component,$fullname,$group); } else{ $self->{$group}{$component}=new Software($component,$fullname,$group); } $self->{$group}{$component}->SetLogfile($self->{logfile}); } elsif($group =~ /Hardware/){ $self->{$group}{$component}=new Hardware($component,$ComponentFullName{$comp},$group); $self->{$group}{$component}->SetLogfile($self->{logfile}); } elsif($group =~ /OS/){ $self->{$group}{$component}=new OS($component,$ComponentFullName{$comp},$group); $self->{$group}{$component}->SetLogfile($self->{logfile}); } } } sub PlatformReport{ my $self = shift; if (! $self->{OnlyComp} && !$self->{CheckOsOnly}){ $self->print2("\n"."-"x (78)."\n"); $self->print2("Detected Operating System\n\n"); $self->PrintComponents("OSComp"); $self->print2("\n"."-"x (78)."\n"); $self->print2("Detected Hardware\n\n"); $self->PrintComponents("HardwareComp"); } if (! $self->{OnlyOS} && !$self->{CheckOSOnly}){ $self->print2("\n"."-"x (78)."\n"); $self->print2("Detected Software\n\n"); $self->PrintComponents("SoftwareComp"); $self->PrintComponents("JavaSDKComp"); $self->PrintComponents("CCompilerComp"); $self->PrintComponents("CPPCompilerComp"); } } sub SetRequiredCategories{ my $self=shift; my $config_obj=new Inifile($self->{config}); @categories=$config_obj->GetProfileSection("Categories","none"); foreach $category (@categories){ ($key,$value)=split(/=/,$category); # if ( defined $self->{Categories}{$key}){$key=$self->{Categories}{$key};} if ($value && !defined $self->{required_categories}){ $self->{required_categories}=$key; } elsif($value){ $self->{required_categories}="$self->{required_categories} $key"; } } } sub CheckIfPropertyInCategoryList { #Check if requirement in required categories list #This have to be done after find_platform function that set all lists of Properties for each Category my $self = shift; my $Property = shift; my $match=0; # if (($Property eq "None")||($Property eq "Platform")){return 1;} $self->trace(3,"","Checking property '$Property' in '$self->{required_categories}'..."); if (($self->{required_categories} =~ /$Property/)|| !defined ($self->{required_categories})){ return 1; } #else{return 0;} foreach $category (split(/\s+/,$self->{required_categories})){ next if (! $self->{Categories}{$category}); # category is simple, checked in required_categories $self->trace(3,"","Checking property '$Property' for '$category' in list '$self->{Categories}{$category}'..."); if ($self->{Categories}{$category} =~ /$Property/){ $self->trace(3,"","Found.\n"); $match=1;last; } else{$self->trace(3,"","Not found.\n");} } if (!$match){return 0;} return 1; } sub ExtractRequirements{ my $self = shift; my $Ruleset=0; my @RequirementDataFile; my $releasenum=$self->{ReleaseNum}; # to compare with release in requirements $releasenum =~ s/MainWin\///; open(EXELFILE,"$self->{ExelRequireFile}") || print STDOUT "Cannot read requirement file $self->{ExelRequireFile}: $! \n"; if (! -r EXELFILE){return 1;} @RequirementDataFile=; close(EXELFILE); while($line = shift @RequirementDataFile){ my $bad_requirement=0; chomp($line); $line=~ s/\013//; next if ($line =~ /^$/); if ($line =~ /BeginRuleset/){ $Ruleset=1;next;} last if (($line =~ /EndRulset/) && ($Ruleset==1)); next if ($Ruleset == 0); if ($line =~ /^\#Download site/){ next; } $line =~ s/\^M$//;# to remove ^M sign at the end of line #print "line=$line\n"; @requirements=split(/,/,$line); if ($requirements[0] =~ /(\d)+(\.)*(\d)*/){ # the number if (! $self->eval_prereq($requirements[0],$releasenum)){ $Ruleset = 0; } next; } if ($requirements[1] == 1){ $bad_requirement=1; } if ($requirements[2]){ #Platforms =~ /$requirements[2]/)){ $requirements[2]="MWPlatform/".$requirements[2]; next if (! $self->eval_prereq($requirements[2],$self->{SysID})); shift @requirements; shift @requirements; shift @requirements; } else {next;} #print "bad_requirement=$bad_requirement, requirement=@requirements\n"; if ($requirements[0] eq ""){shift @requirements;} foreach $requirement (@requirements){ next if ("$requirement" eq ""); my $isMandatory=0; my ($RequireName,$RequireData)=split(/\//,$requirement); $self->trace(3,"","Check if requirement $RequireName in required category list\n"); next if (!$self->CheckIfPropertyInCategoryList($RequireName) && (ref($self) eq "EndUserReport")); my $group=$self->DefineComponentGroup($RequireName); if ($self->{MandatoryRequirements} =~ /$RequireName/){ $isMandatory=1; } $self->trace(3,"","Adding requirement=$requirement,requireName=$RequireName,RequireData=$RequireData,group=$group,isMandatory=$isMandatory to RequirementData list\n"); if ($self->{SysID} =~ /$RequireName/){ # add requirement with found=1 if ($self->{RequirementData}{$RequireName}){ $self->{RequirementData}{$RequireName}->AddRequirementData($RequireData,$bad_requirement); } else{ if ($self->{ExactRequirements} =~ /$RequireName/){ $exact=1;} else { $exact=0;} $self->{RequirementData}{$RequireName}=new Requirement($RequireName,$RequireData,1,$isMandatory,$group,$bad_requirement,$exact); $self->{RequirementData}{$RequireName}->SetLogfile($self->{logfile}); } } # add requirements that was not found on system else{ # add requirement with found=0 if ($self->{RequirementData}{$RequireName}){ $self->{RequirementData}{$RequireName}->AddRequirementData($RequireData,$bad_requirement); } else{ $self->{RequirementData}{$RequireName}=new Requirement($RequireName,$RequireData,0,$isMandatory,$group,$bad_requirement); $self->{RequirementData}{$RequireName}->SetLogfile($self->{logfile}); } } } } return 0; } ################################################################### # GetDescription () # function get description from patch description file # that will be shown for customer during dryrun for each patch # ################################################################### sub GetDescription{ my $self = shift; my $Prereq = shift; my @lines = @_; chomp($Prereq); foreach $line (@lines){ chomp($line); ($first, $description, $match) = split(/,/,$line); if ($first == $Prereq){ return ($description); } } return (""); } ################################################################### # GetPatchConfigInfo # funcion read patch configuration file updaed by customer and # set $self->{incluePatches} - patches to check or # $self->{excludePathes} - patches to ingnore for end user ################################################################### sub GetPatchConfigInfo{ my $self = shift; my $configfile = shift; my $xmlHandler = xmlHandler::new("xmlHandler",$configfile); @list=$xmlHandler->GetItemList("include","patch id"); $self->{includePatches}=join (" ",@list); if (!$self->{includePatches}){ @list=$xmlHandler->GetItemList("exclude","patch id"); $self->{excludePatches}=join (" ",@list); } } ################################################################### # AddCustomPatches # Get patches that customer want to check on end-user machine from # patch configuration file and add to required patches list the # patches for apropriate Operating System ################################################################### sub AddCustomPatches{ my $self = shift; my $session = 0; my $line; my $xmlHandler= xmlHandler::new("xmlHandler",$self->{patchConfig}); $xmlHandler->GetSession("New Patch"); foreach $count (keys %{$xmlHandler->{params}}){ $param=$xmlHandler->{params}{$count}; if ($self->{DoTrace}){ $self->trace(2,"Check if relevant patch: $param->{Patch}, platform $param->{OS}, OS Level $param->{OSLevel}\n"); } if ($self->eval_prereq("MWPlatform/$param->{OS} && OSLevel/$param->{OSLevel}",$self->{System})){ if ($self->{DoTrace}){ $self->trace(2,"Added: $param->{Patch}, $param->{PatchType},$param->{Description},$param->{MinLevel}, $param->{PatchIsBad}\n"); } $self->AddRequiredPatch($param->{Patch},$param->{PatchType},"",$param->{Description},$param->{MinLevel},$param->{PatchIsBad},"",""); } elsif($self->{DoTrace}){ $self->trace(2,"Skipped: $param->{Patch} - not relevant"); } } } ################################################################### # ExtractSolution # get patches from solution-database.csv and add patches for # appropriate to current system and MainWin version to required # patches list ################################################################### sub ExtractSolution{ my $self = shift; my($OneSolutionSeen)=0; open(DBEXELFILE,"$self->{ExelSolutionFile}") || print STDOUT "Cannot read solution database file $self->{SolutionExelFile}: $! \n"; if (! -r DBEXELFILE){return 1;} @lines = ; close(DBEXELFILE); # Open file cust_patch for get messages for dryrun - show which patches gong to check without checking open(CUSTFILE,"$self->{patchDesc}")|| print STDOUT "Cannot read configuration file $self->{patchDesc}: $! \n"; if (! -r CUSTFILE){return 1;} @custlines=; close(CUSTFILE); # Open patch configuration file if exist to get which patches to check on end user matchine. This file updated by customer if (-f "$self->{patchConfig}" && $self->{enduser}){ # Set $self->{includePatches} and $self->{excludePatches} $self->GetPatchConfigInfo($self->{patchConfig}); } while($line = shift @lines){ if ($line =~ /^\#Download site/){ ($trash,$file_onsite)=split(/:/,$line); $file_onsite=~ s/^\s+//; $file_onsite=~ s/\s+$//; chomp($file_onsite); next; } my($Num,$junk1,$junk2,$junk3,$Prereq,$PatchType,$IfAbsent,$Description,$junk4,$Patch,$MinLevel,$junk6,$junk7,$junk8,$MainWinVer,$UserMode,$PatchIsBad,$categories,$dryrun_desc_num,@junk9)=split(/,/,$line); #print "MainWinVer=$MainWinVer, ReleaseNum=$self->{ReleaseNum}\n"; if (($Num =~ /^\d*$/) && $Patch && $Prereq && $self->eval_prereq($MainWinVer,$self->{ReleaseNum})){ $OneSolutionSeen=1; if ( $UserMode =~ /dev/){ $UserMode =~ s/\n//; $Prereq = "( $Prereq ) && UserMode/$UserMode"; } if ($PatchIsBad != 1){$PatchIsBad=0;} chomp($PatchIsBad); #check if includePatches defined and this patch is not in list of includePatches next if ($self->{includePatches} && ($self->{includePatches} !~ /$Num/)); next if ($self->{excludePatches} && ($self->{excludePatches} =~ /$Num/)); if ($self->eval_prereq($Prereq,$self->{System})){ my $match=0; #if at least one category in the required list add patch to required patches( for end user) if ($UserMode eq "run" && $self->{enduser}){ foreach $category (split(/\s+/,$categories)){ if ($self->CheckIfPropertyInCategoryList($category)){ $match=1;last; } } } else{$match=1;} if ($match){ $dryrun_decs=$self->GetDescription($dryrun_desc_num,@custlines); if ($dryrun_decs && $self->{dryrun}){ print "Checking patch $Num: $Patch,$dryrun_decs,$Description\n"; } next if ($self->{dryrun}); $self->AddRequiredPatch($Patch,$PatchType,$IfAbsent,$Description,$MinLevel,$PatchIsBad); } } } } # add patches that customer add in configuration file to check # on end user platform if ( -f $self->{patchConfig} && $self->{enduser}){ $self->AddCustomPatches(); } if ( ! $OneSolutionSeen ) { print "Warning: no rules produced in $self->{ExelSolutionFile} for $self->{ReleaseNum}\n"; return 1; } return 0; # return success status } ################################################################## # DefineComponentGroup # get component name and check for which group this component # belong to # Return component group or 'not defined' ################################################################## sub DefineComponentGroup{ my $self=shift; my $component=shift; my $group="not defined"; if ($self->{OS} =~ /$component/){$group="OSComp";} elsif($self->{Software} =~ /$component/){$group ="SoftwareComp";} elsif($self->{Hardware} =~ /$component/){$group ="HardwareComp";} elsif(($self->{Compiler} =~ /$component/) && ($component =~ /CCompiler/)){ $group ="CCompilerComp"; } elsif(($self->{Compiler} =~ /$component/) && ($component =~ /CPPCompiler/)){ $group ="CPPCompilerComp"; } elsif(($self->{Compiler} =~ /$component/) && ($component =~ /JavaSDK/)){ $group ="JavaSDKComp"; } return $group; } ################################################################## # ################################################################## sub GetRequireForComponent{ my $self = shift; my $component = shift; my $group= shift; if (($group =~ /Software/) || ($group =~ /Compiler/)|| ($group =~ /JavaSDK/)){ ($CompName,$basedir,$version) = split(/:/,$component); } else{ ($CompName,$version) = split(/\//,$component); } $self->trace(3,"","Getting requirement for component: CompName=$CompName, RequirementData=$self->{RequirementData}{$CompName}\n"); if (defined $self->{RequirementData}{$CompName}){ return $self->{RequirementData}{$CompName}; } else {return "";} } sub GetRequiredPatchesForComponent{ my $self = shift; my ($component)=shift; my $PatchFound = 0; # there is at least one patch required @PatchList=undef; $patchepnt=$self->{RequiredPatches}; foreach $patch (@$patchepnt){ #print "patch=$patch->{Name},type=$patch->{Type}\n"; if ($patch->{Type} =~ /\//){ ($type,$version)=split(/\//,$patch->{Type}); if (($component =~ /$type/) && ($component =~ /$version/)){ push(@PatchList,$patch); $PatchFound+=1; } } elsif($component =~ /$patch->{Type}/){ push(@PatchList,$patch); $PatchFound+=1; } } if ($PatchList[0] eq ""){shift @PatchList;} if ($PatchFound){return \@PatchList;} else {return "[PASSED]";} } sub GetMissingRequirements{ my $self = shift; my $CompFlag=shift; my $MissRequirementsList; $requirepnt=$self->{RequirementData}; %requirements=%$requirepnt; @reqlist=keys %requirements; foreach $require (keys %requirements){ next if ($require eq "MWPlatform"); next if ($self->{RequirementData}{$require}{Name}eq ""); if (defined $self->{RequirementData}{$require}){ $self->trace(5,"","Check if require=$self->{RequirementData}{$require}{Name} is missing\n"); if($self->{RequirementData}{$require}->CheckIfMiss($CompFlag)){ $self->printf2("\nMissing %s"."."x(70-(length("Missing $self->{ComponentFullName}{$require}")))."[FAILED]\n",$self->{ComponentFullName}{$require}); $self->printf2(" "x (5)."Required version: $self->{RequirementData}{$require}{Data}\n"); } } } } sub MatchRequirements{ my $self = shift; my @CompFlags=("OSComp","HardwareComp","SoftwareComp","CCompilerComp","CPPCompilerComp","JavaSDKComp"); my %Message=("OSComp"=>"Analyzing Operating system..."); my $InstalledPatches=$self->{PatchList}; $self->trace(3,"","CompFlags=@CompFlags\n"); foreach $compFlag (@CompFlags){ next if ($self->{OnlyComp} && ($compFlag !~ "CompilerComp") && ($compFlag ne "OSComp")); next if (($self->{OnlyOS} || $self->{CheckOSOnly})&& ($compFlag ne "OSComp")); #next if ($self->{CheckOSOnly} ); $comlistpnt=$self->{$compFlag}; %components=%$comlistpnt; @complist=keys %components; $self->trace(3,"","MatchRequirements: matching group is $compFlag, message=$Message{$compFlag}\n"); if ($Message{$compFlag} && !$self->{OnlyComp} ){ $self->printlog("$Message{$compFlag}\n"); print STDERR "$Message{$compFlag}\n"; } my $WarningMatch=0; my $FailedMatch=0; my $PassedMatch=0; my $goodCompiler=0; #if ($compFlag =~ /Compiler/){ # print "complist=@complist;compFlag=$compFlag\n"; #} foreach $component (@complist){ next if ("$component" eq ""); next if ($self->{OnlyComp} && ($component !~ /Compiler/) && ($component !~ /OSLevel/)); next if ($self->{CheckOSOnly} && !($component =~ /OSLevel/)); next if (!defined $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}); # no requirement to match my $compMatch=0; my $patchMatch=undef; my $PatchesPnt=undef; #print "component=$component\n"; my $requirement=$self->GetRequireForComponent($component,$compFlag); my $PatchesPnt=$self->GetRequiredPatchesForComponent($component); next if ($requirement eq ""); # match not needed $self->trace(3,"","matching component $component, requirement name=$requirement->{Name},data=$requirement->{Data},PatchesPnt=$PatchesPnt...\n"); if (($compFlag =~ /Compiler/)|| ($compFlag =~ /JavaSDK/)){ $isFirst=$goodCompiler; ($compMatch,$patchMatch)=$self->{$compFlag}{$component}->MatchComponent($requirement,$InstalledPatches,$self->{Platform},$PatchesPnt,$isFirst); } else{ ($compMatch,$patchMatch)=$self->{$compFlag}{$component}->MatchComponent($requirement,$InstalledPatches,$self->{Platform},$PatchesPnt,$self->{OnlyComp}); } $self->trace(3,"","compMatch=$compMatch, patchMatch=$patchMatch\n"); #print "**Component is $component, compMatch=$compMatch, patchMatch=$patchMatch\n"; #Collect Match for OSComp if ($compMatch == 0){ $PassedMatch+=1; if (($compFlag =~ /Compiler/) || ($compFlag =~ /JavaSDK/)){ $goodCompiler++; } } elsif($compMatch == 1){$WarningMatch+=1;} elsif($compMatch == 2){$FailedMatch+=1;} if ($self->{CheckOSOnly} && ($compMatch == 2)){$self->DoExit(1);} elsif ($self->{CheckOSOnly}){$self->DoExit(0);} if (($compMatch == 0)&& ($patchMatch eq "[PASSED]")){# passed $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}->AddMatch("Passed"); $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}->AddExistVersion($self->{$compFlag}{$component}{version}); } elsif(($compMatch == 2)||($patchMatch eq "[FAILED]")){ # failed # print "add failed to $self->{$compFlag}{$component}{Name}\n"; if (($compFlag !~ /Compiler/) && ($compFlag !~ /JavaSDK/)){ $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}->AddMatch("Failed"); } elsif($patchMatch eq "[FAILED]"){#only if patch failed add failed to requirement, because may be exist good compiler $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}->AddMatch("Failed"); } } # For OSLevel patchMatch is not defined in this step, the status will be defined later elsif(($compMatch == 1) || (($compFlag !~ /OSLevel/) && ($patchMatch eq "[WARNING]"))) { # passed with Warning $self->{RequirementData}{$self->{$compFlag}{$component}{Name}}->AddMatch("Warning"); } #print "component=$component, compMatch=$compMatch\n"; if (($component =~ /OSLevel/) && ($compMatch != 0)){ print "\nThis OS Level is not supported\n\n" ;exit 1; } } if ((($compFlag =~ /Compiler/)|| ($compFlag =~ /JavaSDK/)) && ($goodCompiler==0) && !$self->{enduser}){ my $message; my $supportedVersion; if ($compFlag =~ /CCompiler/){ $supportedVersion=$self->{RequirementData}{CCompiler}{Data}; $message="Analyzing C Compiler"; $self->{RequirementData}{CCompiler}->AddMatch("Failed"); } elsif($compFlag =~ /CPPCompiler/){ $supportedVersion=$self->{RequirementData}{CPPCompiler}{Data}; $message="Analyzing C++ Compiler"; $self->{RequirementData}{CPPCompiler}->AddMatch("Failed"); } else{ $supportedVersion=$self->{RequirementData}{JavaSDK}{Data}; $message="Analyzing Java SDK"; $self->{RequirementData}{JavaSDK}->AddMatch("Failed"); } $self->printf2("\n$message"."."x(70-length("$message"))."[FAILED]\n"); $supportedVersion =~ s/\|\|/or/g; $self->printf2(" Supported version $supportedVersion\n"); } # Report patches for all OS group components (for other group report patches for each component if (($compFlag eq "OSComp") && (!$FailedMatch) && !$self->{OnlyComp}){ @comp=grep(/OSLevel/,@complist); $PatchesPnt=$self->GetRequiredPatchesForComponent("OS"); $patchMatch=$self->{$compFlag}{$comp[0]}->PatchesReport($self->{Platform},$InstalledPatches,$PatchesPnt); if ($patchMatch eq "[FAILED]"){ # PatchMatch failed $self->{RequirementData}{OSLevel}->AddMatch("Failed"); } elsif ($WarningMatch){#Match has Warning $self->{RequirementData}{OSLevel}->AddMatch("Warning"); } elsif($patchMatch eq "[PASSED]"){#Match and PatchMatch Passed $self->{RequirementData}{OSLevel}->AddMatch("Passed"); } $self->trace(3,"","patchMatch=$patchMatch, FailedMatch=$FailedMatch,WarningMatch=$WarningMatch, PassedMatch=$PassedMatch\n"); } elsif (($compFlag eq "OSComp") && !$self->{OnlyComp}){ # Match Failed $self->{RequirementData}{OSLevel}->AddMatch("Failed"); $self->printf2("%s"."."x (70-length("OS patches"))."%s\n","OS patches","[N/A]"); } } foreach $requirement (keys %{$self->{RequirementData}}){ # For this case we printed the message later next if ((($requirement =~ /Compiler/)|| ($compFlag =~ /JavaSDK/)) && ($goodCompiler==0) && !$self->{enduser}); next if (!$self->{RequirementData}{$requirement}{ifMandatory}); if (!$self->{RequirementData}{$requirement}{Found}){ my $message="Analyzing $self->{ComponentFullName}{$requirement}"; my $supportedVersion =$self->{RequirementData}{$requirement}{Data}; $supportedVersion =~ s/\|\|/or/g; $self->printf2("\n$message"."."x(70-length("$message"))."[FAILED]\n"); $self->printf2(" Supported version $supportedVersion\n"); } } } sub SummaryReport{ my $self=shift; my @CompFlags=("OSComp","HardwareComp","SoftwareComp"); my $requirepnt=$self->{RequirementData}; my %requirelist=%$requirepnt; my $status; my $count=0; my $fullname; $self->printf2("\n"."-"x (78)."\n"); $self->print2("Mandatory Components\n\n"); foreach $requirement (split(/\s+/,$self->{MandatoryRequirements})){ next if ($self->{OnlyComp} && !($requirement =~ /Compiler/)); next if ($self->{OnlyOS} && !($requirement =~ /OS/)); next if (! $self->CheckIfPropertyInCategoryList($requirement) && (ref($self) eq "EndUserReport")); if ($requirement =~ /OS/){$fullname="Operating System";} else{$fullname=$self->{ComponentFullName}{$requirement};} ## in case requirement was not specified in platform_requirements.txt file it is not in RequirementData list if (defined $self->{RequirementData}{$requirement}){ $self->{RequirementData}{$requirement}->RequirementReport($fullname); } } $self->printf2("\n"."-"x (78)."\n"); $self->print2("\nOptional Components\n\n"); foreach $requirement (keys %requirelist){ next if ($self->{OnlyComp} && !($requirement =~ /Compiler/)); next if ($self->{OnlyOS} && !($requirement =~ /OS/)); $self->trace(5,"","requirement=$requirement\n"); next if ($self->{MandatoryRequirements} =~ /$requirement/); next if ($self->{OS}=~/$requirement/); next if ("$requirement" eq ""); $count++; # to check if any requirements were found $self->{RequirementData}{$requirement}->RequirementReport($self->{ComponentFullName}{$requirement}); } if ($count ==0){ $self->print2("Not found\n"); } $self->printf2("\n\n"); } sub UpdateFiles{ my $self = shift; my $temp = shift; my @files=@_; if (! -w $self->{ScriptPath}){ print "Cannot update files - no write permission for directory $self->{ScriptPath}\n"; return 1; } foreach $file (@files){ $self->trace(3,"","Copying $temp/$file to $self->{ScriptPath}/$file\n"); #add check if .back file exist and have write permission system("mv $self->{ScriptPath}/$file $self->{ScriptPath}/${file}.back; cp $temp/$file $self->{ScriptPath}/$file"); } return 0; } sub updateSms{ my $self=shift; my $key=shift; my @lines; my $Ruleset=0; my $status=0; # 0 - if all file downloaded successfully #my $update=0; # 0 - if there is no files that need update my @updatelist=undef; my $configfile; my $temp="/var/tmp/download$$"; system("mkdir -p $temp");#add check if succeed and if not ask for temp directory if ((-f $self->{config}) && (! -z $self->{config})){ $self->trace(3,"","Configuration ini file is $self->{config}\n"); $config_obj=new Inifile($self->{config}); $datafile=$config_obj->GetProfileString("Download",$key,"none"); $version=$config_obj->GetProfileString("Download","version","none"); chomp($datafile);chomp($version); if ($datafile eq "none"){ $self->print2("No information for download in configuration file $self->{config}\n"); return 1;#failure } if ($version eq "none"){ $version="last"; } $download=new Download(); $configfile="${key}_${version}.ini"; $self->trace(3,"Download","Trying to get data file ${datafile}/$configfile\n"); $status=$download->getFile("${datafile}/$configfile","$temp/$configfile"); if ($status != 0){ $self->print2("Failed to get ${datafile}/$configfile\n"); return 1;#failure } $config_obj=new Inifile("$temp/$configfile"); $files_to_download=$config_obj->GetProfileString("Files",$key,"none"); $self->trace(3,"Download","Following files are in the download list for $key: $files_to_download\n"); if ($files_to_download eq "none"){ $self->print2("\n*** No files to download. Check your configuration file\n"); return 1; } #Compare checksum for hole database and if it is not equal check which files have to be downloaded $required_checksum=$config_obj->GetProfileString("Checksum",$key,"none");chomp($required_checksum); system("rm -f $temp/db 2> /dev/null;cat solution-database.csv kb_systemid.txt kb_patchid.txt platform_requirements.csv > $temp/db"); $checksum=`cksum $temp/db`;#checksum of hole database system("/bin/rm $temp/db`");#remove temp db file ($full_checksum,@trush)=split(/\s+/,$checksum); if ($full_checksum == $required_checksum){ $self->print2("\nNo update needed\n"); return 0; } foreach $file (split(/\s+/,$files_to_download)){ next if ("$file" eq ""); $required_checksum=$config_obj->GetProfileString("Checksum",$file,"none");chomp($required_checksum); $checksum=`cksum $file`;chomp($checksum); ($exist_checksum,@trush)=split(/\s+/,$checksum); $self->trace(3,"Download","Checking checksum for $file: required_checksum=$required_checksum, exist_checksum=$exist_checksum\n"); if ($exist_checksum != $required_checksum){ push(@updatelist,$file); $filename="$datafile/$file"; $outfile="$temp/$file"; if ($download->getFile($filename,$outfile) != 0){ $status+=1; } } } if ("$updatelist[0]" eq ""){shift @updatelist;} if ($status == 0){ if ($self->UpdateFiles($temp,@updatelist) == 0){ print "\nDownloading completed successfully.\n"; } else{ print "Failed update downloaded files\n"; } } else{ print "\nDownloading completed with errors.\n\n"; } } system("/bin/rm -fr $temp"); return $status; } 1; package EndUserReport;@ISA = qw(System); sub printHeader{ my $self = shift; my $config_obj=new Inifile($self->{config}); $product=$config_obj->GetProfileString("CustomerData","ProductName","none");chomp($product); $release=$config_obj->GetProfileString("CustomerData","VMW_Version","none");chomp($release); $self->printf2("\n"."="x (78)."\n"); $self->printf2("\n"." "x ((70-length("$product System Requirements Analysis Report"))/2)."%s","$product System Requirements Analysis Report\n\n"); $self->printlog("Generated by: mwcheck_platform\n"); $self->printlog("VMW Version: $release\n"); $self->printlog("Report Date: $self->{date}\n\n"); $self->printf2("="x (78)."\n\n"); } sub PlatformReport{ my $self = shift; if (! $self->{OnlyComp} && !$self->{CheckOsOnly}){ #$self->print2("\n"."-"x (78)."\n"); #$self->print2("Detected Operating System\n\n"); $self->PrintComponents("OSComp"); #$self->print2("\n"."-"x (78)."\n"); #$self->print2("Detected Hardware\n\n"); $self->PrintComponents("HardwareComp"); } if (! $self->{OnlyOS} && !$self->{CheckOSOnly}){ #$self->print2("\n"."-"x (78)."\n"); #$self->print2("Detected Software\n\n"); $self->PrintComponents("SoftwareComp"); } } sub PrintComponents{ my $self = shift; my $compFlag = shift; my @complist=undef; $comlistpnt=$self->{$compFlag}; %components=%$comlistpnt; @complist=keys %components; #Don't print nothing } sub MatchRequirements{ my $self = shift; my @CompFlags=("OSComp","HardwareComp","SoftwareComp","CCompilerComp","CPPCompilerComp","JavaSDKComp"); my $InstalledPatches=$self->{PatchList}; $self->trace(3,"","CompFlags=@CompFlags\n"); foreach $compFlag (@CompFlags){ next if ($self->{OnlyComp} && !($compFlag =~ "CompilerComp")); next if (($self->{OnlyOS} || $self->{CheckOSOnly})&& ($compFlag ne "OSComp")); if ($compFlag =~ /Compiler/){ next if (!$self->CheckIfPropertyInCategoryList("Compiler")); } $comlistpnt=$self->{$compFlag}; %components=%$comlistpnt; @complist=keys %components; # if compilers missing add it for check end-user patches if (("@complist" eq "") && ($compFlag =~ /CCompiler/)){ $self->{$compFlag}{CCompiler}=new Compiler($compFlag,"C Compiler"); push(@complist,"CCompiler"); } elsif(("@complist" eq "") && ($compFlag =~ /CPPCompiler/)){ $self->{$compFlag}{CPPCompiler}=new Compiler($compFlag,"C++ Compiler"); push(@complist,"CPPCompiler"); } $self->trace(3,"","MatchRequirements: matching group is $compFlag, message=$Message{$compFlag}\n"); my $WarningMatch=0; my $FailedMatch=0; my $PassedMatch=0; my $goodCompiler=0; foreach $component (@complist){ next if ("$component" eq ""); next if ($self->{OnlyComp} && !($component =~ /Compiler/)); next if ($self->{CheckOSOnly} && !($component =~ /OSLevel/)); my $compMatch=0; my $patchMatch=undef; my $PatchesPnt=undef; my $requirement=$self->GetRequireForComponent($component,$compFlag); if ($compFlag =~ "CompilerComp"){ $requirement="N/A"; } my $PatchesPnt=$self->GetRequiredPatchesForComponent($component); #print "component=$component, PatchesPnt=$PatchesPnt\n"; next if ($requirement eq ""); # match not needed $self->trace(3,"","matching component $component, requirement name=$requirement->{Name},data=$requirement->{Data},PatchesPnt=$PatchesPnt...\n"); ($compMatch,$patchMatch)=$self->{$compFlag}{$component}->MatchComponent($requirement,$InstalledPatches,$self->{Platform},$PatchesPnt); $self->trace(3,"","compMatch=$compMatch, patchMatch=$patchMatch\n"); #Collect Match for OSComp if ($compMatch == 0){ $PassedMatch+=1; } elsif($compMatch == 1){$WarningMatch+=1;$self->{warnings}+=1;} elsif($compMatch == 2){$FailedMatch+=1;$self->{errors}+=1;} if ($self->{CheckOSOnly} && ($compMatch == 2)){$self->DoExit(1);} elsif ($self->{CheckOSOnly}){$self->DoExit(0);} if (($compMatch == 0)&& ($patchMatch eq "[PASSED]")){# passed ; } elsif(($compMatch == 2)||($patchMatch eq "[FAILED]")){ # failed $self->{errors}+=1; } else{#($compMatch == 1) # passed with Warning $self->{warnings}+=1; } } # Report patches for all OS group components (for other group report patches for each component if (($compFlag eq "OSComp") && (!$FailedMatch)){ @comp=grep(/OSLevel/,@complist); next if (!@comp); $PatchesPnt=$self->GetRequiredPatchesForComponent("OS"); $patchMatch=$self->{$compFlag}{$comp[0]}->PatchesReport($self->{Platform},$InstalledPatches,$PatchesPnt); if ($patchMatch eq "[FAILED]"){ # PatchMatch failed $self->{errors}+=1; } elsif ($WarningMatch){#Match has Warning $self->{warnings}+=1; } $self->trace(3,"","patchMatch=$patchMatch, FailedMatch=$FailedMatch,WarningMatch=$WarningMatch, PassedMatch=$PassedMatch\n"); } elsif ($compFlag eq "OSComp"){ # Match Failed $self->{errors}+=1; $self->printlog("%s"."."x (70-length("OS patches"))."%s\n","OS patches","[N/A]"); } } foreach $requirement (keys %{$self->{RequirementData}}){ next if ($requirement =~ /Compiler/); if (!$self->{RequirementData}{$requirement}{Found}){ $self->{errors}+=1; $self->printlog("Product: $self->{ComponentFullName}{$requirement}: Missing : $self->{RequirementData}{$requirement}{Data} : [FAILED]\n"); } } } 1;