#!/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 'ttasess-lib.pl';
do 'monitor-lib.pl';
do 'print-lib.pl';
do "config_info.pl";
do "ldap-lib.pl";

&init_config();
&load_dataconf();
$white="#ffffff";
&set_variables_cfg();
$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};

&foreign_require("proc", "proc-lib.pl");
@procs = &foreign_call("proc", "list_processes");

&ReadParse();
$toScreen=$in{outscreen} || "";
$fileName=$in{file} || "" ;
$now = time();

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_sttareport'}, "", "sttareport" ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}");
 print "<table width=100% border>\n";
 print "<tr $tb> <td valig=top><font color='$revtext'><b> $text{'titidx_sttareport'}".&set_now($now)."</b>";
 print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
 print "Webmin $ver -  $hostname  -  $ostr";
 print "</td></td> </tr>\n";
 
if ( $toScreen ne 1 && $fileName eq "" ) {
     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.file) == true ) {\n"; 
     print "          if ( obj.outscreen.checked ) {\n";
     print "               return true;\n"; 
     print "          }\n"; 
     print "          alert(obj.file.name+\":\"+msg1+\"->\"+obj.file.value+\"<-\");\n"; 
     print "		    obj.file.focus();\n"; 
     print "          return false;\n"; 
     print "     }         \n"; 
     print "     return true;\n"; 
     print "}\n"; 
     print "//-->\n"; 
     print "</SCRIPT>\n"; 
     print "\n"; 
     print "<tr $cb > <td valign=top><table align=left>\n";
     print "<form METHOD=POST name=sttareport ACTION=\"stta_report.cgi\" onSubmit=\"return Check_fields(this)\">\n";
     print "<tr $cb><td valign=top>",&hlink("<b>$text{'f_filereport'}</b>","ffilereport"),"&nbsp;</td>\n";
     print "        <td valign=top><input TYPE=\"text\" NAME=\"file\" VALUE=\"$fileName\" cols=\"40\" size=\"40\" ALIGN=left></td> </tr>\n";
     print "<tr $cb><td valign=top>$text{viewon_screen}</td>\n";
     print "<td><input type=checkbox name=outscreen value=1 ></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";
     &footHere;
     exit;
}
sub err_file_open
{
 $err_msg="$text{f_error} $fileName";
 &footHere;
 exit;
}

 print "<tr $cb> <td align=center>$text{user_made} $fileName </a></td></tr>\n";
 print "<tr><tr></table></table><p>\n";
$ReportOut="";
if ( $toScreen ne 1 ) {
     $ReportOut=$fileName;
     open (REPORTOUT,">$ReportOut") || &err_file_open();
}
      if ( $ReportOut ) { select(REPORTOUT)}
      print "<html>\n";
      print &out_css();
      print "<body>\n";
      print "<table width=100% border>\n";
      print "<tr $tb> <td valig=top><font color='$revtext'><b> $text{'titidx_sttareport'}</b>";
      print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
      print "Webmin $ver -  $hostname  -  $ostr";
      print "</td></td> </tr>\n";
      print "</body></html>\n";
      &make_STTA_Report();
      if ( $ReportOut ) { select(REPORTOUT)}
      print "<table width=100% border>\n";
      print "<tr $tb> <td valig=top><font color='$revtext'><b> $text{'config_title'}</b>";
      print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Webmin $ver -  $hostname  -  $ostr</td></td> </tr>\n";
      print "<tr $cb><td>\n";
      print "<a name=\"sttaconfig\">\n";
      &config_form("report");
      print "</td></tr></table>\n";
      print "<tr><tr></table></table><p>\n";
 if ( $toScreen ne 1 ) { close(REPORTOUT); }
 if ( $ReportOut ) { $| =1; select(STDOUT);}
 &footer($config{'back_return'},$text{'index'});
 do "footer.pl";
 exit;
