#!/usr/bin/perl
# stta_installupd.cgi
# ...  Init Update Services with Tarantella.
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require '../web-lib.pl';
do 'web-lib.pl';
do 'global-lib.pl';
do 'lists-lib.pl';
do 'html-lib.pl';
do 'print-lib.pl';

&init_config();
&load_dataconf();
$white="#ffffff";
$hostname = &get_system_hostname();
$ver = &get_webmin_version();
&get_miniserv_config(\%miniserv);
if ($gconfig{'real_os_type'}) {
        if ($gconfig{'os_version'} eq "*") {
                $ostr = $gconfig{'real_os_type'};
                }
        else {
                $ostr = "$gconfig{'real_os_type'} $gconfig{'real_os_version'}";
                }
        }
else {
        $ostr = "$gconfig{'os_type'} $gconfig{'os_version'}";
        }
%access = &get_module_acl();
%ttaprops=();
@ttahosts=();
%sttaparams=();
$cginame= $0 =~ /([^\/]+)$/ ? $1 : '-';   
$ldap_ok=true;
$ldapcache_ok=true;
$tta_ok=true;
$button_lock=0;
@access_types = $access{'types'} eq '*' ? (0 .. 100)
				        : split(/\s+/, $access{'types'});
map { $access_types{$_}++ } @access_types;
$debug=$config{debug_code};
$debug=3;

&ReadParse();
$task=$in{task} || "";
$fileName=$in{file} || "" ;
$brandid=$in{brandid} || "" ;
$password=$in{password} || "" ;
$now = time();
$passData=`cat $root_directory/$module_name/install/.passwd 2>/dev/null`;
$passData=~ s/\r|\n//g;

if ( ! $access{'global'} || $access{'admin'} ne 1) { $redir="stta" };

if ( $redir ne "" ) { 
    &headerstta($text{'index_title'}, "images/$current_lang/stta_stta.gif", "sttaintro",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
    do "index/insupd.pl";
    do "footer.pl";
    exit;
}
if ( $config{check_brand} eq "true" ) { &check_brand_cgi() }

&headerstta($text{'index_brandmgr'}, "", "sttabrandmgr" ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}");

print "<SCRIPT SRC=\"global.js\">\n"; 
print "</SCRIPT>\n"; 
print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
print "<!--\n"; 
print "/*  Strings for locales  */\n"; 
print "var msg0=\"".$text{'msg_0'},"\";\n";
print "var msg1=\"".$text{'msg_1'},"\";\n";
print "var msg2=\"".$text{'msg_2'},"\";\n";
print "var msg3=\"".$text{'msg_3'},"\";\n";
print "var msg4=\"".$text{'msg_4'},"\";\n";
print "var msg5=\"".$text{'msg_5'},"\";\n";
print "var msg6=\"".$text{'msg_6'},"\";\n";
print "var msg7=\"".$text{'msg_7'},"\";\n";
print "\n"; 
print "/******************************************************************\n"; 
print "   Check_fields(obj)\n"; 
print "*******************************************************************/\n"; 
print "function Check_fields(obj) {\n"; 
print "     if ( emptyField(obj.password) == true ) {\n"; 
print "          alert(obj.password.name+\":\"+msg1+\"->\"+obj.password.value+\"<-\");\n"; 
print "		    obj.password.focus();\n"; 
print "          return false;\n"; 
print "     }         \n"; 
print "     return true;\n"; 
print "}\n"; 
print "//-->\n"; 
print "</SCRIPT>\n"; 
print "\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td valig=top><font color='$revtext'><b> $text{'titidx_brandmgr'}</b>";
 print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
 print "Webmin $ver -  $hostname  -  $ostr";
 print "</td></td> </tr>\n";

 local %minfo=&load_minfo("$root_directory/$module_name/");
 print "<tr><td><b>  $minfo{name} -- $minfo{version} -- $minfo{brand} -- $minfo{stamp} </b></td></tr>\n";

if ( $password eq $passData ) { 
  if ( $fileName ne "" || $task ne "" ) {
     print "<tr bgcolor=$white><td valign=top><pre>\n";
     if ( $task eq "all" ) {
        &dump_brandinfo($in{brandid},"",1);
     } elsif ( $task eq "fix" ) {
        if ( $fileName ne "" && -r "$root_directory/$fileName" ) {
                &check_brand_data($fileName,"fix",1);
        } else {
                &check_brand_data("","fix",1);
        }
     }
     print "</pre></td></tr>\n";
     &footHere;
     exit;
  }
} else {
  if ( $password ne "" ) { print &text('msgerr_brand',$password)." <br>"; }
}
     print "<tr $cb > <td valign=top><table width=100%>\n";
     print "<form METHOD=POST name=brandmgr ACTION=\"stta_brandmgr.cgi\" onSubmit=\"return Check_fields(this)\">\n";
     print "<tr $cb><td valign=top>",&hlink("<b>$text{'brand_data'}</b>","fbranddata"),"&nbsp;";
     print "        <td valign=top><input TYPE=\"text\" NAME=\"brandid\" VALUE=\"$minfo{brand}\" cols=\"40\" size=\"40\" ALIGN=left></td>\n";
     print "<td align=left valign=top ><select NAME=\"task\">\n";
     print "    <option VALUE=\"fix\" >".$text{brand_broken}."  ";
     print "    <option VALUE=\"all\" >".$text{brand_all}."  ";
     print "        </select></td></tr>\n";
     print "	<tr><td valign=top>",&hlink("<b>$text{'f_password'}</b>","fbrandpassword"),"</td>\n"; 
     print "	<td valign=top><input TYPE=\"password\" NAME=\"password\" VALUE=\"\" cols=\"22\" size=\"12\"></td></tr>\n"; 
     print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
     print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
     print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";
     print "        </form>\n";
sub err_file_open
{
 $err_msg="$text{f_error} $fileName";
 &footHere;
 exit;
}
      print "<table width=100% border>\n";
      print "<tr $tb> <td valig=top><font color='$revtext'><b> $text{'titidx_brandmgr'}</b>";
      print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
      print "Webmin $ver -  $hostname  -  $ostr";
      print "</td></td> </tr>\n";
      print "<tr><td><table width=100% >\n";
      print "<tr $tb>\n";
      print "<td><font color='$revtext'><center><B>".$text{f_filelistName} . "</B></center></font></td>\n";
      print "<td><font color='$revtext'><center><B>".$text{f_fsize} . "</B></center></font></td>\n";
      print "<td><font color='$revtext'><center><B>".$text{brand_data} . "</B></center></font></td>\n";
      print "<td><font color='$revtext'><center><B>".$text{brand_desc} . "</B></center></font></td>\n";
      %h_brandInfo=&load_brandinfo();
      $lins=0;
      $touchFiles=0;
      foreach $item (keys (%h_brandInfo)) { push (@brandInfoList,$h_brandInfo{$item}); }
      @brandInfo = sort {$a->{fname} cmp $b->{fname}} @brandInfoList;
      $brand_warn="0";
      $totSize=0;
      foreach $item (@brandInfo) {
        $lins++;
        my  @st = stat("$root_directory/$item->{fname}");
        my  $data_check=&check_brand_data($item->{fname});

        if ( $st[7] ne $item->{'size'} ||  $data_check eq "false" ) {
            print "<tr $cb>";
            print "<td><a class=\"menu1\" href=\"/stta/stta_brandmgr.cgi?file=$item->{'fname'}&password=$password&task=fix\">$item->{'fname'}</a></td>";
        } else {
            print "<tr background=\"$config{'bgimage'}\">";
            print "<td>$item->{'fname'}</td>";
        }
        if ( $st[7] ne $item->{'size'} ||  $data_check eq "false" ) { print "<td>"; }
        if ( $st[7] ne $item->{'size'} ) { 
             $n=0;
             $n= $n + $item->{'size'}; 
             $n= $st[7] - $n;
             print " $item->{'size'} != $st[7] = $n ";
             $totSize=$totSize + $n;
        }
        if ( $data_check eq "false" ) { print " $text{changed} ";}
        if ( $st[7] ne $item->{'size'}   ||  $data_check eq "false" ) {
            print "</td>";
            $brand_warn="1";
            $touchFiles++;
        } else {
            print "<td>$item->{'size'}</td>";
        }
        print "<td>$item->{'brand'}</td>";
        print "<td>$item->{'descrip'}</td>";
        print "</tr>\n";
      }
      print "</table></td></tr><p>\n";
      print "<tr><tr></table></table><p>\n";
      print "<p><tr><td><b> ".&text('l_total',$lins)."</b></td><td><p>\n"; 
 if ( $brand_warn eq "1" ) {
      print "<img align=middle border=0 alt= 'warn ' src='images/warn.gif'> <font size=+1><b>".&text("msgerr_brandinfo",$touchFiles)." </b> &nbsp;&nbsp;&nbsp;&nbsp; $totSize $text{changed}</font><br>";
 }
 &footer($config{'back_return'},$text{'index'});
 do "footer.pl";
 exit;
