# installupd-lib.pl # STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo --- license GNU GPL # stta: (@#) 1.31051043346- [2004_01_29_102036] # Common functions for Install / update sub out_javascript { print "\n"; print "\n"; } sub out_initJS { print "\n"; } sub out_head_instupd { print " \n"; print "\n"; } else { print "$text{$task}\n"; } print "\n"; } sub head_lock_button { if ( $button_lock eq 1 ) { return } $opLock="unlockstta"; if ( $STTA_LOCK eq 0 ) { $opLock="lockstta"; } $opLock_msg=$opLock,"_msg"; print "\n"; $button_lock=1; } #To set $tdone and ruleHash sub set_hashes_rules { if ( $task eq "" ) { return }; my $task_proc = $task."_proc"; my $task_steps = $task."_steps"; my $task_brand = $task."_brand"; $rulesHash{'proc'}=$rules{$task_proc}; if ( defined($rules{$task_brand} ) ) { $rulesHash{'brand'}=$rules{$task_brand};} my @ruleline = split(/,/,$rules{$task},-1); my @tdoneline = split(/,/,$tdone,-1); my @stepsline = split(/,/,$rules{$task_steps},-1); if ( $tdone eq "" ) { $tdone=""; for ( $i = 0 ; $i < $#ruleline ; $i++ ) { $tdone.= "0,"; } $tdone.= "0"; } @tdoneline = split(/,/,$tdone,-1); $i=0; foreach $r (@ruleline) { $rulesHash{$r}=$stepsline[$i].":".$tdoneline[$i]; if ( $r eq "lockstta" && $nextStep eq $r && $STTA_LOCK eq 1 && $StepCheck eq "" ) { my @lineStep = split(/:/,$rulesHash{$r},-1); $nextStep=$ruleline[$i+1]; $rulesHash{$r}=$lineStep[0].":".$lineStep[1]++; }; $i++; } $rulesHash{'ntask'}=$i; if ( $nextStep eq "" ) { $nextStep=$ruleline[0]; if ( $ruleline[0] eq "lockstta" && $STTA_LOCK eq 1 ) { $nextStep=$ruleline[1] }; } if ( $Step eq "" ) { $Step=$ruleline[0]; if ( $ruleline[0] eq "lockstta" && $lockDo eq "lockstta" ) { my @lineStep = split(/:/,$rulesHash{'lockstta'},-1); $rulesHash{'lockstta'}=$lineStep[0].":".$lineStep[1]++; $Step=$ruleline[1]; }; } } # To track visited links !!! and set Step & nextStep sub check_visit_tasks { my @ruleline = split(/,/,$rules{$task},-1); my @lineStep =(); $tdone=""; $i=0; foreach $r (@ruleline) { my @lineStep = split(/:/,$rulesHash{$r},-1); if ( $Step eq $r ) { if ( $StepCheck eq "" ) { if ( $Step eq $nextStep ) { $nextStep=$ruleline[$i+1]; } $lineStep[1]++; } } $tdone.= $lineStep[1].","; $rulesHash{$r}=$lineStep[0].":".$lineStep[1]; $i++; } } sub make_steps_tables { my @statStep =(); my @ruleline = split(/,/,$rules{$task},-1); my $newLine=0; my $jsString=""; my $langf=""; local $help=""; print "

"; print "     \n"; if ( $task eq "" ) { print "$text{installupd_title}

     "; if ( $STTA_LOCK eq 1 ) { print "(".$text{mode_run}.")"; } else { print "(".$text{mode_browse}.")"; } print "
\n"; print "     ".&hlink("",$opLock)."\n"; print "
\n"; print "
\n"; print "\n"; &close_form_hidden(); print "\n"; print "\n"; print "
\n"; print "\n"; print "
$text{menu}   $text{$task}
\n"; print "\n"; print ""; print "\n"; $i++; } print ""; print "\n"; print "
\n"; print "      $text{work_secuence}:

\n"; $i=0; foreach $r (@ruleline) { $newLine=0; @statStep = split(/:/,$rulesHash{$r},-1); print "
"; if ( $statStep[0] eq 1 ) { $jsString.=" if ( step == \"$r\" ) { alreadyrun= 1;}\n ";} if ( $nextStep eq $r ) { print ""; } else { print "      "; } if ( $statStep[0] eq 1 && $statStep[1] gt 0 ) { print ""; if ( $Step eq $r ) { print "";} } else { print ""; } else { print ">"; } } if ( $statStep[0] eq 1 ) { print "";} if ( $statStep[0] eq 1 && $statStep[1] gt 0 ) { print ""; $newLine=1 } if ( $statStep[1] gt 0 ) { $newLine=1 } print "   ".$text{$r}."\n"; if ( $newLine eq 1 ) { print "
       "; print "          "; } if ( $nextStep eq $r ) { print "($text{nextstep})"; } if ( $newLine eq 1 ) { print "      "; } if ( $statStep[0] eq 1 && $statStep[1] gt 0 ) { print "($text{'done'})"; } if ( $statStep[1] gt 0 ) { print "($text{'visited'} $statStep[1])"; } print "

$text{opc_msg}      "; print "      "; if ( $STTA_LOCK eq 1 ) { print ""; } else { print ""; } print "
\n"; print "\n"; print "
$text{info}   $text{$Step}
\n"; print "\n"; print "
\n"; # First try info files for particular $task/tmp/info .. if got it.. last # Second try info files order for global $task/info.. if got it ... last $infoTmpDirInstall= "$DirInstall/tmp/info"; $infoDirInstall= "$DirInstall/info"; $langf="$infoTmpDirInstall/$Step.html"; if ( ! -r $langf ) { $langf="$infoDirInstall/$Step.html"; if ( ! -r $langf ) { $langf=""; } } # foreach $l (@lang_order_list) { # $langf="$infoTmpDirInstall/$l/$Step.html"; # if ( -r $langf ) { last; }; # $langf="$infoDirInstall/$l/$Step.html"; # if ( -r $langf ) { last; }; # $langf=""; # } if ( $langf ) { unless ( open(INDEXPAGE,$langf) ) { &write_help_info_file($langf,$Step) } my @ary = ; close INDEXPAGE; foreach $line (@ary) { $help.=$line; } } if ( $help ) { &make_help_html(); } if ( $help ) { $help =~s///g; $help =~s///g; $help =~s/<\/BODY>//g; $help =~s/<\/body>//g; $help =~s///g; $help =~s///g; $help =~s/<\/HTML>//g; $help =~s/<\/html>//g; # split html to find href and changes to window.open # This is hard work ... probably there is an other easier way to do it @thisline=split(/href=/, $help, -1); my $outline="$thisline[0]"; for ( $i = 1 ; $i <= $#thisline ; $i++ ) { @wordline=split(/"/, $thisline[$i], -1); $outline.= " onclick=\" window.open('$wordline[1]','help',". "'toolbar=no,menubar=no,scrollbars=yes,". "width=$config{help_width},height=$config{help_heigth},resizable=yes'); return false\" ". " class='menu1' href=\"$wordline[1]\" "; $restLine=$thisline[$i]; $restLine=~s/"$wordline[1]"//; $outline.=$restLine; } print "$outline"; } print "
\n"; print "\n"; print "
$text{help}:   $text{'index_installupd'}
\n"; print ""; print "\n"; print ""; print "\n"; print ""; print "\n"; print ""; print "\n"; print ""; print "\n"; print "\n"; print ""; print " "; print ""; print "\n"; print ""; print "\n"; print "\n"; print "
$text{menu}".&text('menu_panel',$text{$task})."
$text{info}".&text('info_panel',$text{$Step})."
$text{run}".&text('run_panel',$text{$Step})."
$text{help}".&text('help_panel',$text{'index_installupd'})."
$text{black_line}$text{step_runonce}
$text{this_colorline}"; print "$text{step_current}
($text{'visited'} N)$text{'nro_visited'}
$text{step_next} -- ($text{nextstep})
$text{steps_done} -- ($text{done})
"; print "$text{note}$text{help_msg1}
\n"; print "\n"; print "\n"; print "\n"; } sub hrefwin { return ""; } sub close_form_hidden { print " \n"; print " \n"; print " \n"; print " \n"; } sub write_help_info_file { open (FILE, ">$_[0]"); print FILE "\n"; print FILE "
$_[1]
\n"; print FILE "\n"; close (FILE); } sub out_sel_task { print " \n"; print "\n"; print "
$text{f_taskinstupd} \n"; print "
\n"; print " \n"; print "\n"; print " \n"; print " \n"; print "\n"; print "
",&hlink("$text{'f_taskinstupd'}","ftaskinstupd")," 
\n"; print "\n"; } sub out_sel_sttasrv { print " \n"; print "\n"; print "
$text{f_sttasrvs} \n"; print "
\n"; print " \n"; local %servers = &list_servers(); print "\n"; print " \n"; print " \n"; print " \n"; print "\n"; print "
",&hlink("$text{'f_sttasrvs'}","fsttasrvs")," 
\n"; print "$text{'msg_sttasrvs'} \n"; print "\n"; } sub get_file_updpatch { if ($file) { return }; print "\n"; print "\n"; print "\n"; print "
".&text('tit_fileupdpatch',$text{$task})."
\n"; print "\n"; print "\n"; print "\n"; print "
",&hlink("$text{'f_fileupdpatch'}","ftargetfile")," \n"; print "
\n"; print "         \n"; &close_form_hidden(); print " \n"; print "
\n"; print " $text{'warn_updpatch'}\n"; } sub do_instupdfile { my $wkdir="$DirInstall/tmp"; if ( -r "$wkdir/$task.pl" ) { do "$wkdir/$task.pl"; } } sub run_instupd_procedure { if ( $rulesHash{'proc'} ne "" ) { print "($Step) $text{msg_processing} ".eval("\$text{$rulesHash{proc}}")."($rulesHash{proc})
\n"; if ( !defined(eval("&$rulesHash{proc}"))) { print &text('error_unknown_step', $rulesHash{'proc'}, $text{$Step}); } } } sub running_fileName { my $wkdir="$DirInstall/tmp"; if ( $wkdir eq "/tmp") { print &text('dir_erraccess DirInstall ',$wkdir)."\n"; return; } print "\n"; print "\n"; print "
".&text('tit_runfilename',$fileName)."
\n"; print "
\n";
    if ( ! -r $fileName || $fileName =~ /^(\/\*)/ ) {
         print &text('file_erraccess',$fileName)."  \n";
    } else {
       if ( ! -d $wkdir ) { system("mkdir -p $wkdir")  }
       if ( ! -d $wkdir ) { 
               print &text('dir_erraccess',$wkdir)."\n";
       } else {
          system("rm -f $wkdir/* 2>/dev/null");
          $str="cd $wkdir; ";
          if ( ! $config{unziptool} || $config{unziptool} eq "" ) { $config{unziptool}="gunzip"; }
          if ( $fileName =~  /.tar.gz$/ || $fileName =~  /.wbm.gz$/ ) {
                 $str.="cat $fileName | $config{unziptool} | tar xvf -" }
          elsif ( $fileName =~  /.cpio.gz$/ ) { $str.="cat $fileName | $config{unziptool} | cpio -idumv " }
          elsif ( $fileName =~  /.gz$/ ) {
                 @line=split(/\//, $fileName, -1);
                 $nomf=$line[$#line];
                 $nomf=~s/.gz$//g;
                 $str.="cat $fileName | $config{unziptool} > $nomf";
          }
          elsif ( $fileName =~  /.cpio$/ ) { $str.="cpio -idumvI $fileName" }
          elsif ( $fileName =~  /.tar$/ || $fileName =~  /.wbm$/ ) {
                  $str.="tar xvf $fileName" }
          elsif ( $fileName =~  /.shx$/ ) { $str.="sh $fileName" }
          else  { $str = "cp $fileName . ";}
          if ( ! &run_cmd($str))  { &html_errshow("cmd")};
          #print "$str\n";
          open(FILEINSTALL, ">>$logInsUpd");
             print FILEINSTALL "$task: ".&text('tit_runfilename',$fileName)." -".&set_now($now)."\n";
          close (FILEINSTALL);
       }
    }
    print "
\n"; } sub lock_insupd_stta { my $task_steps = $task."_steps"; open(FILEINSTALL, ">>$config_directory/$module_name/.insupd.lock"); print FILEINSTALL "# ----$_[0]---$task---------------------------\n"; if ( $task ) { print FILEINSTALL "task=$task\n"; } print FILEINSTALL "now=".&set_now($now)."\n"; if ( $Step ) {print FILEINSTALL "step=$Step\n"; } if ( $nextStep ) {print FILEINSTALL "next=$nextStep\n"; } if ( $rules{$task} ) {print FILEINSTALL "rule=$rules{$task}\n"; } if ( $tdone ) {print FILEINSTALL "tdone=$tdone\n"; } if ( $rules{$task_steps} ) {print FILEINSTALL "steps=$rules{$task_steps}\n";} if ( $rulesHash{'proc'} ) {print FILEINSTALL "proc=$rulesHash{'proc'}\n"; } if ( $rulesHash{'brand'} ) {print FILEINSTALL "brand=$rulesHash{'brand'}\n"; } close (FILEINSTALL); $STTA_LOCK=1; } sub task_log { open(TASKLOG,">>$config_directory/$module_name/.insupd.lock"); print TASKLOG $now." ".$_[0]." ".$_[1]." ".$_[2]." ".$_[3]." ".$_[4]."\n"; close (TASKLOG); &webmin_log($_[0], $_[1], $_[2], $_[3], $_[4]); } # Unlock STTA and move all to $task logfile sub unlock_insupd_stta { my $Line=""; unless ( open(FILELOG,"$config_directory/$module_name/.insupd.lock") ) { return -1} &lock_insupd_stta($_[0]); @ary = ; close (FILELOG); my $ahoraf=&out_now_filename($now); my $logfile="$config_directory/$module_name/$task"; if ( ! -d $logfile ) { system (" mkdir $logfile "); } $logfile.="/".$ahoraf."_log"; open(FILEINSTALL, ">>$logfile"); foreach $line (@ary) { print FILEINSTALL "$line"; } close (FILEINSTALL); open(FILEINSTALL, ">>$logInsUpd"); open(FILEINSTALL, ">>$logfile"); print FILEINSTALL "$task: done $ahoraf $rulesHash{'brand'}"; close (FILEINSTALL); system (" rm -f $config_directory/$module_name/.insupd.lock"); my $wkdir="$DirInstall/tmp"; if ( $wkdir ne "/tmp") { system("rm -rf $wkdir 2>/dev/null"); } $STTA_LOCK=0; } sub run_fix_brand_data { # my $task_brand = $task."_brand"; # local %minfo=&load_minfo(); # $minfo{$task_brand}=$rulesHash{'brand'}; &dump_brandinfo("","",1); } sub stepcheck_button { $StepCheck=$_[0]; print " \n"; print " \n"; print "    $text{make_msg1}\n"; } sub doStep { if ( $Step eq "" ) { return }; my $foo=""; my @statStep = split(/:/,$rulesHash{$Step},-1); if ( $Step eq "lockstta" ) { &lock_insupd_stta("lock"); } if ( $Step eq "unlockstta" ) { &unlock_insupd_stta; } if ( $Step =~ /lockstta/ || $Step =~ /readme/ ) { return } print "\n"; print "\n"; print "
$text{run}   $text{$Step}
\n"; print "
\n";
    if ( $statStep[0] eq 1 &&  $statStep[1] gt 1  ) { 
         print &text('error_runonce_step', $text{$Step});
    } else { 
         &lock_insupd_stta($Step);
         if ( $Step eq "dataconf" )  {
              print "$text{done}\n";
              $JScodeInit="showWin('config','')";
         } elsif ( $Step eq "checklist" )  {
              $foo="";  # Do nothing so all test will be at the end of page
              print "$text{done}\n";
         } elsif ( $Step eq "fixbrand" )  {
                   &run_fix_brand_data();
         } elsif ( $Step eq "doupdate" )  {
                   &run_instupd_procedure();
         } elsif ( $Step eq "doupgrade" ) {
                   &run_instupd_procedure();
         } elsif ( $Step eq "dopatch" ) {
                   &run_instupd_procedure();
         } elsif ( $Step eq "doloadfiles" ) {
                   &run_instupd_procedure();
         } else  {    # Wanderland new function can be added and loaded on the fly 
                 if ( !defined(eval("\&step_$Step"))) {
                     print &text('error_unknown_step', $Step, $text{$Step});
                 }
         }
    }
    print "
\n"; } 1; # Return true