# html-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 

# header(title, image, [help], [config], [nomodule], [nowebmin], [rightside],
#        [header], [body])
# Output a page header with some title and image. The header may also
# include a link to help, and a link to the config page.
# The header will also have a link to to webmin index, and a link to the
# module menu if there is no config link

use Net::LDAP::Util qw(ldap_error_name ldap_error_text);
sub headerstta
{
   local $text_str;
   local $html_str;
   local %minfo=&load_minfo("$root_directory/$module_name/");

   &set_interface_colors();   #  just to be sure !!!
   $text_str=" ";
   $html_str="";
   if ( $config{check_services} eq "true" ) { 
         &checkSTTA_services("all","status",\$text_str);
   }
   if ($current_theme eq "mscstyle3" && $_[6] =~ /<img /) {
        # This theme does not like images in $_[6]
        $_[6]=~s/<img ([^<]+)>/$text{index_title}/ge;
   }
   if ( ! -r "$root_directory/$module_name/help/$_[2].html" ) {
        &header($_[0],$_[1],'',$_[3],$_[4],$_[5],$_[6],$_[7],$_[8]);
   } else {
        &header($_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6],$_[7],$_[8]);
   }
   print &out_css(); 
   print "<table border=0 width=100%><tr>";
   if ( $config{motd} ne ""  &&  -r $config{motd} ) { 
        print "<td align=\"left\">";
        print "<table border=0 $tb><tr><td background=\"images/bkg/help.jpg\">";
        print "<img SRC='/stta/images/info.gif' width=20 heigth=20 align=top border=0>&nbsp;&nbsp;</td>";
        print "<td background=\"images/bkg/help.jpg\"><i><b>";
        if ( $config{motd_style} eq "marquee" ) {
             print "<marquee border=\"0\" align=\"center\" scrolldelay=\"80\" width=\"375\" height=\"14\">";
        }
        open(MOTDPAGE,$config{motd});
             while(<MOTDPAGE>) {
                if ( $config{motd_style} ne "marquee" ) {
                     s/\r|\n/<br>/g;
                }
                if (/\S/ && !/^[#\+\-]/) {
                     s/\$(\S+){(\S+)}/text_subs($2,\%{$1})/ge;
                     print $_; 
                }
             }
        close MOTDPAGE;
        if ( $config{motd_style} eq "marquee" ) { print "</marquee>"; }
        print "</i></b></td></tr></table></td>\n"; 
   }
   print "<td align=\"center\">";
   &out_tabserv_chk();
   print "</td>";
   if ( $config{stta_srvtitle} ne "" ) { 
        print "<td align=\"right\">";
        print "<table border=0 $tb><tr><td background=\"images/bkg/help.jpg\"><b> $config{stta_srvtitle} </b></td>\n";
        print "</tr></table></td>\n"; 
   }
   print "</tr></table>";
    print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
    print "/******************************************************************\n";
    print "   show_stta(item)\n";
    print "*******************************************************************/\n";
    print "function show_stta(item) {\n";
    print "   w_stta= window.open('','stta_ops','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');\n";
    print "   w_stta.document.writeln('<head><title>STTA</title>');\n";
    print "   w_stta.document.writeln(\"".&out_css()."\")\n";
    print "   w_stta.document.writeln('</head> ')\n";
    print "  w_stta.document.writeln('<body bgcolor=#$bgcolor link=#$link vlink=#$link text=#$text $bgimage $tconfig{'inbody'}>');\n";
    print "   w_stta.document.writeln('<table BORDER=0 WIDTH=100%>');\n";
    print "   w_stta.document.writeln('<tr>');\n";
    print "   w_stta.document.writeln(\"<td valign=top align=left><a class='menu1' href='help.cgi/stta/toc'> <img align=middle border=0 alt='$text{index}' src='images/stta_button.gif'><tt>$text{index}</tt></a></td>\");\n";
    print "   w_stta.document.writeln(\"<td valign=top align=right>",
          "<a class='menu1' href='javascript:self.close()'>",
          "<img align=middle border=0 alt=$text{index_title}",
          " src='images/$current_lang/stta_title.gif' width='300' height='39'>",
          " <tt>$text{msg_close}</tt></a></td>\");\n";
    print "   w_stta.document.writeln('</tr></table>');\n";
    print "   w_stta.document.writeln('<HR noshade size=2>');\n";

    &printSTTA_config(\$text_str,"=");
    $text_str=~s/STTA:/<tr><td><li>/g;
    $text_str=~s/\n/<\/b><\/td><\/tr>/g;
    $text_str=~s/==/<td><b>/g;
    $html_str.="<table width=100% border><tr $tb> <td><font color=$revtext><b>".$text{srvSTATUS}."</b> &nbsp;&nbsp;&nbsp;Webmin $ver -  $hostname  -  $ostr </font></td></tr>";
    $html_str.="<tr $cb> <td><table width=100%><td>";
    $html_str.="<ul>$text_str</ul>";
    $html_str.="</table>";
    if ( $minfo{brand} ne "" ) {
      $html_str.="<tr $tb> <td><font color=$revtext>$minfo{name} &nbsp;&nbsp;&nbsp; $minfo{version} &nbsp;&nbsp;&nbsp; ( $minfo{brand} &nbsp;&nbsp;&nbsp; $minfo{stamp} )</font></td></tr>";
    }
    $html_str.="</table>";
    print "   w_stta.document.writeln('".$html_str."');\n";

    if ($access{'global'} && $access{'supervision'} == 1) { &js_sttamenu(\%minfo); }
    if ( $config{check_services} ne "true" ) { 
         print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('stta_view.cgi', 'stta_view','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='stta_view.cgi'>$text{srvSTATUS}</A>\");\n";
    }
    print "   w_stta.document.writeln('<HR noshade size=2>');\n";
    print "   w_stta.document.close();\n";
    print "}\n";
    print "</SCRIPT>\n";
}

# JavaScript with in depth menu
sub js_sttamenu
{
    local %minfo=%{$_[0]};
    local $text_str;

    @line=split(/\//, $config{'tta_daemon'}, -1);
    $daemonTTA=$line[$#line];
    @line=split(/\//, $config{'ldap_daemon'}, -1);
    $daemonLDAP=$line[$#line];
    @line=split(/\//, $config{'ldapache_daemon'}, -1);
    $daemonLDAPCACHE=$line[$#line];

    print "   w_stta.document.writeln('<table width=100%>');\n";
    print "   w_stta.document.writeln('<ul><tr><td><li>');\n";

    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('stta_proc.cgi?srv=tta', 'tta-proc-list','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='stta_poc.cgi?srv=tta'>$text{ttaps_list_title}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('stta_proc.cgi?srv=ldap', 'ldap-proc-list','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='stta_poc.cgi?srv=ldap'>$text{ldapps_list_title}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";

    if ( $config{'is_ldapcache'} eq "true" ) {
        print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('stta_proc.cgi?srv=ldapcache', 'ldapcache-proc-list','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='stta_poc.cgi?srv=ldapcache'>$text{ldapcacheps_list_title}</A>\");\n";
        print "   w_stta.document.writeln('<tr><td><li>');\n";
    }

    print "   w_stta.document.writeln(\"",
    &html_objlink("config","STTA $text{'config_title'}",\%config,$text{'config_title'},"docwrite"),"\");\n";
    if ( $config{check_services} eq "true" ) { 
         print "   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "   w_stta.document.writeln(\"",
               &html_objlink("ttaprops",$text{'index_ttaproperties'},\%ttaprops,$text{index_globaltta},"docwrite"),"\");\n";
         print "   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "   w_stta.document.writeln(\"",
         &html_objlink("ttaparams tta",$text{ttastatus_title},\%{$sttaparams{tta}},$text{ttastatus_title},"docwrite"),"\");\n";
         print"   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "w_stta.document.writeln(\"",
         &html_objlink("ttaparams ldap",$text{index_ldap},\%{$sttaparams{ldap}},$text{index_ldap},"docwrite"),"\");\n";
         $lnum=0;
         print "   w_stta.document.writeln('</tr></td>');\n";
         foreach $item (@ttahosts) {
            print "   w_stta.document.writeln('<tr><td><li>');\n";
            print "   w_stta.document.writeln(\"",
                 &html_objlink("host",$item->{name},\%{$ttahosts[$lnum]},$item->{name},"docwrite"),"\");\n";
            $lnum++;
            print"   w_stta.document.writeln('</td></tr>');\n";
         }
    }
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"",
    &html_objlink("module stta",$text{index_module},\%minfo,$text{index_module},"docwrite"),"\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"",
    &html_objlink("access stta",$text{index_acl},\%access,$text{index_acl},"docwrite"),"\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('tta_alivehosts.cgi', 'hostsalive','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='tta_alivehosts.cgi'>$text{index_alivehosts}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('/proc/index_search.cgi?user=&mode=1&match=$daemonLDAPslapd&cpu=&fs=%2F&files=', 'ldap-proc','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='/proc/index_search.cgi?user=&mode=1&match=slapd&cpu=&fs=%2F&files='>$text{ldapps_title}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('/proc/index_search.cgi?user=&mode=1&match=$daemonLDAPCACHEslapd&cpu=&fs=%2F&files=', 'ldap-proc','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='/proc/index_search.cgi?user=&mode=1&match=slapd&cpu=&fs=%2F&files='>$text{ldapcacheps_title}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('/proc/index_search.cgi?user=&mode=1&match=$daemonTTA&cpu=&fs=%2F&files=:', 'tta-proc','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" class='menu1' href='/proc/index_search.cgi?user=&mode=1&match=ttaauxserv&cpu=&fs=%2F&files=:'>$text{ttaps_title}</A>\");\n";
    print "   w_stta.document.writeln('</ul></td></tr>');\n";
    print "   w_stta.document.writeln('</table><BR>');\n";
}
# config_icons(context, program)
# Displays up to 17 icons, one for each type of configuration directive, for
# some context (global, virtual, directory or htaccess)
sub config_icons
{
local($m, $func, $e, %etype, $i, $c);
      foreach $m (sort { $a cmp $b } (keys %httpd_modules)) {
              $func = $m."_directives";
	      foreach $e (&$func($httpd_modules{$m})) {
		      if ($e->{$_[0]}) { $etype{$e->{'type'}}++; }
		      }
              }
      print "<table width=100% cellpadding=5>\n";
      for($i=0; $text{"type_$i"}; $i++) {
	      if ($etype{$i} && $access_types{$i}) {
		      if ($c%5 == 0) { print "<tr>\n"; }
		      print "<td valign=top align=center width=20%>\n";
		      &generate_icon("images/type_icon_$i.gif", $text{"type_$i"},
			             $_[1]."type=$i");
		      print "</td>\n";
		      if ($c%5 == 4) { print "<tr>\n"; }
		      $c++;
		      }
	      }
      for($i=2; $i<@_; $i++) {
              next if ( !$_[$i]->{'link'} || $_[$i]->{'link'} eq "" );
	      if ($c%5 == 0) { print "<tr>\n"; }
	      print "<td valign=top align=center width=20%>\n";
	      &generate_icon($_[$i]->{'icon'}, $_[$i]->{'name'}, $_[$i]->{'link'});
	      print "</td>\n";
	      if ($c%5 == 4) { print "<tr>\n"; }
	      $c++;
	      }
      print "</table><p>\n";
}

sub footHere
{

        if ( $err_msg ) { 
              print "<hr><table width=100% border>\n";
              print "<tr></tr><tr $cb><td align=center><b>$err_msg</b></td></tr>\n";
              print "<tr><tr><table>\n";
        }
        print "<tr><tr></table></table><hr><p>\n";
        &footer($config{'back_return'},$text{'index'});
        print "<p><p><p>\n";
        do "footer.pl";
}

# restart_button()
# Returns HTML for a link to put in the top-right corner of every page
sub restart_button
{
  my $fullOps=0;
  local $rv="";

 if ( $access{stop} ne 1 ) { return }
 if ( $config{interface} eq "index" ) { $fullOps=1 }
 if ( $in{cat} eq "admin" || $in{cat} eq "supervision" ) { $fullOps=1 }

 if ( $fullOps eq 1 || $in{cat} eq "tta" ) {   
     $rv .="<a class=\"menu1\" href=\"tta_restart.cgi\">$text{'tta_restart'}</a>|\n"; 
 }
 if ( $fullOps eq 1 || $in{cat} eq "ldap" ) {   
     $rv .= "<a class=\"menu1\" href=\"ldap_restart.cgi\">$text{'ldap_restart'}</a>\n";
 }
 if ( $config{'is_ldapcache'} eq "true" ) {
     if ( $fullOps eq 1 || $in{cat} eq "ldapcache" ) {   
          $rv .= "|<a class=\"menu1\" href=\"ldapcache_restart.cgi\">$text{'ldapcache_restart'}</a>\n";
     }
  }
return $rv;
}

# show_error([message])
# Display an error message and exit. The variable $whatfailed must be set
# to the name of the operation that failed.
sub show_error
{
	print "<hr>\n";
	print "<h3>",($whatfailed ? "$whatfailed : " : ""),@_,"</h3>\n";
	print "<hr>\n";
}

sub SrvError
{
      if ( $cginame ne "stta_warn.cgi" ) {
           &redirect("stta_warn.cgi?msg=$err_msg");
      }
}

# footCacheHere()
# Display a message, close tables and put page foot ... 
# almost ready to exit with good look & feel
sub footCacheHere {
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>|</b></font></td> </tr>\n";
 if ( !$err_msg ) { $err_msg=$text{'ldapcache_disable'}; }
 print "<tr></tr><tr $cb><td td align=center><b>$err_msg</center></b></td></tr>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
}

# htmlCacheapp(msgObj,formObj)
# Display all htmls labels to get input for "ttacacheapp" object 
sub htmlCacheapp 
{
 if ( $msgObj eq $text{'default_obj'} ) {
      print "<tr><td valign=top>".&hlink('<img SRC="/stta/images/info.gif" width=20 heigth=20 align=top border=0>','cacheobj');
      print "&nbsp;<b>$msgObj</b><td>$text{msg_fieldsreq}</td></tr>\n";
 } else {
      print "<tr><td valign=top><b>$msgObj</b><td>$text{msg_fieldsreq}</td></tr>\n";
 }
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierlogin'}</b>","f3tierlogin"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_login\" VALUE=\"$tta3tier_login\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierpassword'}</b>","f3tierpassword"),"\n"; 
 print "	<td valign=top><input TYPE=\"password\" NAME=\"tta3tier_password\" VALUE=\"$tta3tier_password\" cols=\"20\" size=\"20\" ALIGN=left>\n"; 
 print "	<input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswd($formObj);\" ></td></tr>"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tiertitle'}</b>","f3tiertitle"),"&nbsp;</td>\n";
print "		<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_title\" VALUE=\"$tta3tier_title\" cols=\"30'\" size=\"30\" ALIGN=left></td></tr>\n"; 
 print "  	<tr><td valign=top>",&hlink("<b>$text{'f_3tierdomain'}</b>","f3tierdomain"),"</td>\n"; 
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_domain\" VALUE=\"$tta3tier_domain\" cols=\"12\" size=\"12\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierstringcmd'}</b>","f3tierstringcmd"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_stringcmd\" VALUE=\"$tta3tier_stringcmd\" cols=\"60\" size=\"40\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey1'}</b>","f3tierappkey1"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey1\" VALUE=\"$tta3tier_appkey1\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey2'}</b>","f3tierappkey2"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey2\" VALUE=\"$tta3tier_appkey2\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey3'}</b>","f3tierappkey3"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey3\" VALUE=\"$tta3tier_appkey3\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey4'}</b>","f3tierappkey4"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey4\" VALUE=\"$tta3tier_appkey4\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey5'}</b>","f3tierappkey5"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey5\" VALUE=\"$tta3tier_appkey5\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey6'}</b>","f3tierappkey6"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey6\" VALUE=\"$tta3tier_appkey6\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_3tiermaxsess'}</b>","f3tiermaxsess"),"&nbsp;</td>\n";
 if ( $tta3tier_maxsess eq "" ) { $tta3tier_maxsess=$config{default_maxsess}; }
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_maxsess\" VALUE=\"$tta3tier_maxsess\" cols=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";

if ( $config{'check_ticket'} eq "false"  && $tta3tier_ticketstatus eq "" ) { $tta3tier_ticketstatus="no"; }
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_ticketstatus'}</b>","fticketstatus"),"&nbsp;</td><td valign=top><select NAME=\"tta3tier_ticketstatus\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_ticketstatus_sel'}</b>","fticket_status_sel"),"\n";
 
@l_target = split(/,/,$text{'ticket_status_value'}, -1);
$nItems=0;
foreach $item (@l_target) {
     print "         <option ";
     if ( $item eq $tta3tier_ticketstatus ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     $targetext='ticket_'.$item.'_tit';
     print ">$text{$targetext}</b>\n";
     $nItems++;
}
print "        </select></td></tr>\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_endticket'}</b>","fendticket"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_endticket\" VALUE=\"$tta3tier_endticket\" cols=\"10\" size=\"10\" ALIGN=left onChange=\"\">\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_ticketcounter'}</b>","fticketcounter"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_ticketcounter\" VALUE=\"$tta3tier_ticketcounter\" cols=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_doifendticket'}</b>","fdoifendticket"),"&nbsp;</td>\n";
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_doifendticket\" VALUE=\"$tta3tier_doifendticket\" cols=\"45\" size=\"45\" ALIGN=left></td></tr>\n"; 
print "</td></tr>\n";
}

#script_cache_chek()
#Print javascript lines to check "ttacacheapp" object input fields
#
sub script_cache_chek
{
    print "     if ( emptyField(obj.tta3tier_login) == false ) {\n";
    print "          if ( emptyField(obj.tta3tier_password) == true ) {\n";
    print "                 alert(obj.tta3tier_password.name+\":\"+msg1+\"->\"+obj.tta3tier_password.value+\"<-\");\n";
    print "                 obj.tta3tier_password.focus();\n";
    print "                 return false;\n";
    print "          }\n";
    print "          if ( emptyField(obj.tta3tier_title) == true ) {\n";
    print "                 alert(obj.tta3tier_title.name+\":\"+msg1+\"->\"+obj.tta3tier_title.value+\"<-\");\n";
    print "                 obj.tta3tier_title.focus();\n";
    print "                 return false;\n";
    print "          }\n";
    print "          nro=parseInt(obj.tta3tier_maxsess.value);\n";
    print "          if ( nro+1 > 0) { \n";
    print "               obj.tta3tier_maxsess.value=nro;\n";
    print "          } else {;\n";
    print "               alert(obj.tta3tier_maxsess.name+\":\"+msg1+\"->\"+obj.tta3tier_maxsess.value+\"<-\");\n";
    print "               obj.tta3tier_maxsess.focus();\n";
    print "               return false;\n";
    print "          };\n";
    print "          if ( get_value(\"select\",obj.tta3tier_ticketstatus) == \"none\" ) {\n";
    print "                alert(obj.tta3tier_ticketstatus.name+\":\"+msg1+\"->\"+obj.tta3tier_ticketstatus.value+\"<-\");\n";
    print "                      obj.tta3tier_ticketstatus.focus();\n";
    print "                      return false;\n";
    print "          }   \n";
    print "          if ( get_value(\"select\",obj.tta3tier_ticketstatus) != \"no\" ) {\n";
    print "               if ( emptyField(obj.tta3tier_endticket) == true ) {\n";
    print "                      alert(obj.tta3tier_endticket.name+\":\"+msg1+\"->\"+obj.tta3tier_endticket.value+\"<-\");\n";
    print "                      obj.tta3tier_endticket.focus();\n";
    print "                      return false;\n";
    print "               }\n";
    print "               nro=parseInt(obj.tta3tier_ticketcounter.value);\n";
    print "               if ( nro+1 > 0) { \n";
    print "                    obj.tta3tier_ticketcounter.value=nro;\n";
    print "               } else {;\n";
    print "                    alert(obj.tta3tier_ticketcounter.name+\":\"+msg1+\"->\"+obj.tta3tier_ticketcounter.value+\"<-\");\n";
    print "                    obj.tta3tier_ticketcounter.focus();\n";
    print "                    return false;\n";
    print "               };\n";
    print "          }   \n";
    print "     }\n";
}

# htmlCacheShowPassw(msgObj,formObj)
# Display all htmls labels to get input for "ttacacheapp" object 
sub htmlCacheaShowPassw
{
 print "/******************************************************************\n"; 
 print "   showPasswd(formObj)\n"; 
 print "   Show Password value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function showPasswd(formObj) {\n"; 
 print "   alert(\"Password:\"+formObj.tta3tier_password.value+\"\");\n"; 
 print "}\n"; 
}

# htmlCheckAlias
# Out javascript to control aliases, it is need to get @_ with hash object list
sub htmlCheckAlias
{
  local (%h_obj);         

  print "/******************************************************************\n"; 
  print "   checkAlias_$_[0](Obj)\n"; 
  print "   checkAlias from the array and return false is already exist\n"; 
  print "*******************************************************************/\n"; 
  print "function checkAlias_$_[0](Obj) {\n"; 
  print "   var isalready = false; \n";
  print "   var listAlias = new Array();\n"; 
  if ( "$_[0]" eq "hostaddress" ) {
       %h_obj=&list_hosts();
  } else {
       %h_obj=eval("\&list_$_[0]()");
  }
  $nItem=0;
  foreach $item (keys (%h_obj)) {
      if ( "$_[0]" eq "hostaddress" ) {
         if ( $ipaddress eq "" && $h_obj{$item}->{'ipname'} ne $ipaddress ) { 
              print " listAlias[".$nItem++."] = \"".$h_obj{$item}->{'ipname'}."\";\n";
         }
      } else {
         print " listAlias[".$nItem++."] = \"".$h_obj{$item}->{'alias'}."\";\n";
      }
  }
  print "   \n"; 
  print "   for (var i=0; i < listAlias.length; i++) {\n"; 
  print "       if ( Obj.value == listAlias[i] ) { \n"; 
  print "            isalready = true; \n";
  print "            break;\n"; 
  print "       }\n"; 
  print "   }\n"; 
  print "   if ( isalready == true ) { \n"; 
  print "          alert(Obj.name+\":\"+msg1+\"->\"+Obj.value+\"<-\");\n";
  print "                    Obj.focus();\n";
  print "   }\n"; 
  print "   return isalready;\n"; 
  print "}\n"; 
}

# htmlWinLdapUsers(msgObj,formObj)
# Open Window to show Users
sub htmlWinLdapUsers
{
 print "<input type=button onClick='window.open(\"tta_selusr.cgi?form=winldapusers\", \"selusr\", \"toolbar=no,menubar=no,scrollbar=yes,width=750,height=450\")' value=\"?\">\n";
}

sub outicons_table
# This is to output code for the "Tabs" interface menu 
{
          local $per=20;
          local $cols=5;
          local ($i) = 0;
          foreach $lnk (@olinks) {
             print "<td valign=top align=center width=$per\%>\n";
             print "<table border bgcolor=#ffffff><tr><td><a href=$lnk>",
                   "<img src=$oicons[$i] alt=\"\" border=0></a>",
                   "</td></tr></table>\n";
             print "<a href=$lnk class='menu1'>$otitles[$i]</a></td>\n";
             $i++;
             if ($pos++ % $cols == $cols - 1) { print "</tr><tr>\n"; }
          }
          while($pos++ % $cols) {
                print "<td width=$per\%></td>\n";
          }
          print "</tr><tr>\n"; 
}

sub outconfig_icons
{
        local $per=20;
        local $cols=5;
	local($i);
        local ($n) = 0;
	for($i=2; $i<@_; $i++) {
             next if ( !$_[$i]->{'link'} || $_[$i]->{'link'} eq "" );
             print "<td valign=top align=center width=$per\%>\n";
             print "<table border bgcolor=#ffffff><tr><td><a href=$_[$i]->{'link'}>",
                   "<img src=$_[$i]->{'icon'} alt=\"\" border=0></a>",
                   "</td></tr></table>\n";
             print "<a href=$_[$i]->{'link'} class='menu1'>$_[$i]->{'name'}</a></td>\n";
             $n++;
             if ($pos++ % $cols == $cols - 1) { print "</tr><tr>\n"; }
        }
        while($pos++ % $cols) {
                print "<td width=$per\%></td>\n";
        }
        print "</tr><tr>\n"; 
}

# html_objlink($type,$object,%{$p},$anchor,$_[4]);
# $_[4] = return | print | docwrite | report
sub html_objlink
{
   local $text_str="";
   local $html_str="<head><title>STTA: $_[3]</title></head>";
   local $item;

   return undef if (!%{$_[2]}); 
 
        $no_out=0;
        $text_str="";
        if ($_[3] eq $text{index_acl}  ) {
            local %h_lst=%{$_[2]};
            foreach $item (keys (%h_lst)) {
                $text_str.=eval("\$text{'acl_$item'}")."===";
                if ( $h_lst{$item} eq 1 ) { $text_str.=$text{yes}; }
                elsif ( $h_lst{$item} eq 0 ) { $text_str.=$text{no}; }
                else { $text_str.=$h_lst{$item}; }
                $text_str.="===($item)\n";
            }
        } elsif ( $_[3] eq $text{config_title}  ) {
            local %h_lst=%{$_[2]};
            local @configList,@configInfo;
            &read_file("$root_directory/stta/config.info.$current_lang", \%textcfg);
            foreach $item (keys (%textcfg)) { push (@configList,{'name' => $item, 'text' => $textcfg{$item}} ); }
            @configInfo = sort {$a->{text} cmp $b->{text}} @configList;
            foreach $tcfg (@configInfo) {
                $item=$tcfg->{name};
                @line=();
                if ( $textcfg{$item} ne "" ) { 
                    @line=split(/,/, $textcfg{$item}, -1);
                    $text_str.=$line[0]."===".$h_lst{$item}."===($item)\n"; }
            }
        } else {
            &show_hash(\%{$_[2]},"","=","",\$text_str);
        }
        $text_str=~s/\n/<\/td><\/tr><tr><td>/g;
        $text_str=~s/===/<\/td><td>/g;
        $html_str.="<table width=100% border><tr $tb> <td><font color=$revtext><b>$_[0]: $_[1]</b></font></td></tr>";
        $html_str.="<tr $cb> <td><table width=100%><td>";
        $html_str.="<tr><td>$text_str</td></tr>";
        $html_str.="</td></tr></table></table>";
   if ( $_[4] eq "print" ) {
        print "<A onClick=\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\" class='menu1' href=\"javascript:\" >$_[3]</A>";
   } elsif ( $_[4] eq "report" ) {
        print "$html_str";
   } elsif ( $_[4] eq "docwrite" ) {
        return "<A onClick=\\\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\\\" class='menu1' href='javascript:' ><b>$_[3]</b></A>";
   } else {
        return "<A onClick=\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\" class='menu1' href=\"javascript:\" >$_[3]</A>";
   }

}
sub html_errshow
{
    local $where_err = $_[0]; 

    print "<hr><table width=100% border><tr></tr><tr $cb><td align=center>\n";
    if ( "$where_err" eq "ldap-rep" )  {
            print "($dn):<br><b>".$text{'replica_err'} ."-->".$line_conn."</b><br>\n";
            print "<b> ".$text{'replica_msg'} ."</b><br>\n";
    } elsif ( "$where_err" eq "tta" )  {
            print "<b>$text{f_error}: $text{'msgerr_tta'}</b><br>\n";
    } elsif ( "$where_err" eq "cmd" )  {
            print "<b>$text{f_error}: $text{'msgerr_cmd'}</b><br>\n";
    } elsif ( "$where_err" eq "sync" )  {
            print "<b>$text{f_error}: ".&text('msgerr_sync',$_[1])."</b><br>\n";
    } 
    if ( $err_msg ) { print "<b>$err_msg</b><br>\n"; }
    if ( $err gt 0 ) {
        print "$text{f_error} ($err):<b>".eval("\$text{'msgerr_$err'}")."</b><br>\n";
    }
    if ( $debug gt 0 ) { print &text('viewlog_action',$stta_sid); }
    print "<tr><tr></table>\n";
    if ( $config{'iferror_objects'} eq "stop" ) {
         $err_msg=$text{'error_found'};
         &footHere;
         exit;
    }
}
sub out_htmlfile
{
  local $to_out= "0";

   unless ( open(INDEXPAGE,$_[0]) ) { return -1}
   @ary = <INDEXPAGE>;
   close INDEXPAGE;
   foreach $line (@ary) {
         if ( $line =~/^<\/BODY/  ||  $line =~/^<\/body/ ) { $to_out="0"  }
         if ( $to_out eq "1" ) {
             if ( $_[1] ) { 
                  ${$_[1]}.=$line;
             } else { 
    #             chomp ($line);
                 print "$line\n";
             }
         }
         if ( $line =~/^<BODY/ ||  $line =~/^<body/ ) { $to_out="1" }
   }
   return 0;
}

sub get_processes_list
{
#        It is need to use next two lines in main::
#        &foreign_require("proc", "proc-lib.pl");
#        @procs = &foreign_call("proc", "list_processes");

        my ($matchPS) = $_[0];
        my ($out_html) = $_[1] || 0;
        my ($edit_ps) = $_[2] || 0;
        my @pidlist = ();
        
        if ( $_[3] ) { select(${$_[3]})}
        if ( $ReportOut ) { select(REPORTOUT)}
	# search by regexp
	@dis = grep { $_->{'args'} =~ /\Q$matchPS\E/i } @procs;
		# Ignore this process and any children
#		@dis = grep { $_->{'pid'} != $$ && $_->{'ppid'} != $$ } @dis;

	# display matches
	if (@dis) {
            if ( $out_html eq 1 ) {
                print "<table border width=100%>\n";
                print "<tr $tb> <td><font color='$revtext'><b>$text{'pid'}</b></font></td>\n";
                print "         <td><font color='$revtext'><b>$text{'owner'}</b></font></td>\n";
                print "         <td><font color='$revtext'><b>$text{'cpu'}</b></font></td>\n";
                print "         <td><font color='$revtext'><b>$text{'command'}</b></font></td> </tr>\n";
            }
	    foreach $d (@dis) {
		 $p = $d->{'pid'};
		 push(@pidlist, $p);
                 if ( $out_html eq 1 ) {
                        if ($edit_ps eq 1 ) {
                            print "<tr $cb> <td><a class='menu1' href=\"/proc/edit_proc.cgi?$p\">",
                                  "$p</a> $d->{ppid}</td>\n";
                        } else { print "<tr $cb> <td>$p - $d->{ppid}</td>\n"; }
			print "<td>$d->{user}</td>\n";
			print "<td>$d->{cpu}</td>\n";
			print "<td>",&html_escape(foreign_call("proc", "cut_string",$d->{args}));
#cut_string($d->{args})),
			      "</td> </tr>\n";
                 }
	    }
            if ( $out_html eq 1 ) { print "</table><p>\n"; }
	}
        if ( $_[3] ) { $| =1; select(STDOUT);}
        return @pidlist;
}

sub show_tta_serv_table
{  
 if ( $ReportOut ) { select(REPORTOUT)}
 &load_ttaprops();
 &scanSTTA_services("all");
$text_str="";
 &checkSTTA_services("all","status",\$text_str);
 &printSTTA_config(\$text_str,"=");
 $text_str=~s/STTA:/<tr><td><li>/g;
 $text_str=~s/\n/<\/b><\/td><\/tr>/g;
 $text_str=~s/==/<td><b>/g;
 $html_str.="<tr $cb><td><table width=100% border><tr $tb> <td><font color='$revtext'><big><b>".$text{srvSTATUS}."</b></big></font></td></tr>";
 $html_str.="<tr $cb> <td><table width=100% $cb><td>";
 $html_str.="<ul>$text_str</ul>";
 $html_str.="</table>";
 print $html_str;
 print "</td></tr>\n";
}

sub show_procServ
{
  my ($serv) = $_[0] || return undef;
  my ($outhtml) = $_[1] || 1;
  my ($edit_ps) = $_[2] || 1;

  if ( $ReportOut ) { select(REPORTOUT)}
  $title_list=$serv."ps_list_title";
  $title_idx=$serv."ps_title";
  print "<tr $tb> <td align><font color='$revtext'><big><b>$text{$title_idx}</b></big></font></td> </tr>\n";

  $daemon=$serv."_daemon";
  @line=split(/\//, $config{$daemon}, -1);
  $daemonStr=$line[$#line];

  return &get_processes_list($daemonStr,$outhtml,$edit_ps);
}

sub check_ps_serv
{
 if ( $ReportOut ) { select(REPORTOUT)}
 print "<tr $cb> <td><table width=100% border border><td>";
 print "<a name=\"procServTTA\">\n";
 @ttaps=&show_procServ("tta");
 print "<tr $cb> <td><table width=100% border><td>";
 print "<a name=\"procServLDAP\">\n";
 @ldapps=&show_procServ("ldap",1,1,\$_[0]);
 if ( $config{'is_ldapcache'} ne "true" ) { return } 
 print "<tr $cb> <td><table width=100% border><td>";
 print "<a name=\"procServLDAPCACHE\">\n";
 @ldapcacheps=&show_procServ("ldapcache");
}

sub check_ttabase
{
 if ( $ReportOut ) { select(REPORTOUT)}
 if ( $debug eq 0 ) { $debug=1 };
 print "<tr $cb> <td><table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b><big>Tarantella:  </big>$text{chk_srv_title} - $config{tta_base} - </b></font></td></tr>\n";
   # loading object attributes ...
 $ens_obj=$config{tta_base};
    $op="attributes";
    $type_cmd="attributes";
    $status_cmd=&run_tta_cmd($type_cmd,$ens_obj);
    if ( !$status_cmd ) { 
         print "<tr><td> ".$text{'tta_noobject'}."</td></tr>";
         &html_errshow("tta");
    } else {
        # Assigning and collecting values to be used in the form ...
        %h_ttaobj=&load_ttaobj();
    }
    if ( $debug lt 2 )  { unlink($temp_f); }
    print "<tr $cb><td>".&text('viewlog_action',$stta_sid)."</b></td></tr>\n";
   print &parse_webminlog();
 print "</tr></td></table>\n";
}

sub parse_webminlog
{
    local ($user, $script, $action, $type, $object, $p) = @_;
    local $text_str;
    local $html_str;
    $debug=4;  # Just uncoment here and bypass $config{debug}
    local %h_obj;
    local @line, $line_str, $LDAP_msgerr;

    if ( $cginame eq "view.cgi" ) {
         # This is need to fix parse log for STTA  and avoid webmin master changes
         # In STTA action, type and object are always among quotes ....
         open(LOG, $webmin_logfile);
         while(<LOG>) {
              @line=split(/ /, $_, -1);               
              if ( $line[0] eq $stta_sid ) {
                   $line_str=$_;
                   last;
              }
         }
         close(LOG);
         if ( $line_str ne "" ) {
              @line=split(/ "/, $line_str, -1);               
              if ( $line[1] ne "" ) { ${action} = $line[1]; }
              if ( $line[2] ne "" ) { ${type} = $line[2]; }
              if ( $line[3] ne "" ) { 
                   ${object} = $line[3];
                   @line=split(/"/, ${object}, -1);               
                   ${object} = $line[0];
              }
              ${action}=~s/"//g;
              ${type}=~s/"//g;
         }
         if ( ${object} =~ /\|\|/ ) {
              local @obj= split(/\|\|/, ${object}, -1);               
              foreach $item (@obj) {
                      local @objdata= split(/=>/, $item, -1);               
                      if ( ${action} =~ /^tta/ && $objdata[0] eq "cmd" ) { 
                          $objdata[1] =~ s/\\\\/<nl>/g;
                          $objdata[1] =~ s/\\/<br>/g;
                          $objdata[1] =~ s/<nl>/\\<br>/g;
                          $objdata[1] =~ s/'/"/g;
                      }
                      if (defined($h_obj{$objdata[0]}) ) {
                          $h_obj{$objdata[0]} .= ", ".$objdata[1];
                      } else {
                          $h_obj{$objdata[0]} = $objdata[1];
                      }
              }
              if ( $obj[0] gt 0 ) {
                  if ( ${action} =~ /^tta/ ) { 
                       $h_obj{$obj[0]}="<pre>$text{f_error}:$text{'msgerr_tta'}</pre>";
                  } else {
                       $LDAP_msgerr.=&ldap_error_text($obj[0]);
                       $LDAP_msgerr=~s/\n/<br>/g;
                       $h_obj{$obj[0]}="<pre>$LDAP_msgerr</pre>";
                  }
              } elsif ($obj[0] eq 0 ) {$h_obj{$obj[0]}="<pre>$text{'msgerr_0'}</pre>"}
         };
         $text_str=&text("log_stta", "<tt><b>$texto</b></tt><br>");
         if ($debug gt 1  && %{$p} ) { 
             $html_str=${action};
             if ( ! %h_obj ) { $html_str=" <b>${type}</b> <i>${object}</i>"; }
             $html_str=&html_objlink(${type},$html_str,\%{$p},${action}); 
             $html_str=~s/\0/, /g; #webminlog-lib.pl in &parse_logline
                                   # will add "\0" in a multivalue field
			           # it will crash javascript:window.document.writeln()
         } else {
             $html_str=" ${action}";
             $html_str.=" <b>${type}</b>"; 
             if ( ! %h_obj ) { $html_str.=" <i>${object}</i>"; }
         }
         if ( %h_obj ) {
                  &show_hash(\%h_obj,"","=","",\$text_str);
                  $text_str=~s/'//g;
                  $text_str=~s/\n/<\/tr><tr><td>/g;
                  $text_str=~s/===/:<\/td><td>/g;
                  $html_str.="<table width=100% border>";
                  $html_str.="<tr><td>$text_str</td></tr></table>";
         }
    }
    if ( $cginame eq "search.cgi" ) {
         $html_str=${script}.":".${action}." ".${type};
    }
    return "<tt>$html_str</tt>";
}

sub make_STTA_Report
{
 if ( $ReportOut ) { select(REPORTOUT)}
 
 $cginame="view.cgi";
 $indexTopHtml="</table><table><tr><td><br><div align=left><a class='menu1' href=\"#top-page\">$text{index}</a></div></td></tr>\n";
 $nowis=&set_now($now);
 print "<hr><p>\n";
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'sttareport_title'} $nowis </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";

#  From here all checking staff .....
# print "<tr $cb> <td align=center><table $cb><tr $cb><td>\n";
$config{iferror_services}="warn";

print "<table border=0 align=left>\n";
print "<a name=\"top-page\">\n";
     print "<tr $cb><td><ul></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#srvSTATUS\">$text{srvSTATUS}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","srvSTATUS"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#procServTTA\">$text{ttaps_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","procServTTA"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#procServLDAP\">$text{ldapps_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","procServLDAP"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#procServLDAPCACHE\">$text{ldapcache_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","procServLDAPCACHE"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#checkTTA\">Tarantella: $text{chk_srv_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","checkTTA"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#checkldap\">Ldap: $text{chk_srv_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","checkldap"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#checkLDAPCACHE\">Ldap Cache: $text{chk_srv_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","checkLDAPCACHE"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#sttaconfig\">$text{config_title}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","sttaconfig"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#acl\">$text{index_acl}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","acl"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#ttaproperties\">$text{index_ttaproperties}</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>","ttaproperties"),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
 $lnum=0;
foreach $item (@ttahosts) {
     print "<tr $cb><td valign=center><li><a class='menu1' href=\"#host-".$item->{name}."\">".$item->{name}."</a></td><td>",&hlink("<img SRC='/stta/images/info.gif' alt='?' width=20 heigth=20 align=top border=0>",$item->{name}),"</td><td align=rigth> - $d&nbsp;</li></td></tr>\n";
      $lnum++;
}
print "</ul></table>\n";

print "$indexTopHtml";
print "<tr><td><a name=\"srvSTATUS\">\n";
print "</table>\n";
&show_tta_serv_table();
print "$indexTopHtml";
&check_ps_serv();
print "$indexTopHtml";
print "<tr><td><a name=\"checkTTA\">\n";
&check_ttabase();

   if ( $debug eq 0 ) { $debug=2 }

print "$indexTopHtml";
print "<tr $cb> <td><table width=100% border><tr $cb><td>\n";
   $ldap_server=$in{ldapserver} || "1";
   print " <tr $tb> <td><font color='$revtext'><big><b>\n";
   if ( "$ldap_server" eq "1" ) {
        print $config{ldap_type}.":".$config{ldap_server}.":".$config {ldap_port};
   } elsif ( "$ldap_server" eq "2" ) {
        print $config{ldap2_type}.":".$config{ldap2_server}.":".$config {ldap2_port};
   }
   print "</b></big></td></tr>\n";
   if ( $ldap_ok eq true ) {
        print "<tr $cb><td><b><big>LDAP:  </big>$text{chk_srv_title} - $config{ldap_base} - </b></td></tr>\n";
        print "<tr><td><a name=\"checkldap\">\n";
        &connect();
        $dn=$config{ldap_base};
        $cur_entry=&sel_ldap_obj($dn,"o=*");
        if ( !defined($cur_entry)  ||  $cur_entry->dn ne $dn) {
             &html_errshow("ldap")
        } else { 
             &ldap_logerr("browse $dn");
             print "<tr $cb><td>".&text('viewlog_action',$stta_sid)."</td></tr>\n";
        }
   } else { print "<tr $cb><td><b><big>LDAP:  </big> - $config{ldap_base} - ???? </b></td></tr>\n";}
   print &parse_webminlog();

print "$indexTopHtml";
print "<tr $cb> <td><table width=100% border><tr $cb><td>\n";
   $ldapcache_server=$in{ldapcacheserver} || "1";
   print " <tr $tb> <td><font color='$revtext'><big><b>\n";
   if ( "$ldapcache_server" eq "1" ) {
        print $config{ldapcache_type}.":".$config{ldapcache_server}.":".$config {ldapcache_port};
   } elsif ( "$ldapcache_server" eq "2" ) {
        print $config{ldapcache2_type}.":".$config{ldapcache2_server}.":".$config {ldapcache2_port};
   }
   print "</b></big></td></tr>\n";
   if ( $ldapcache_ok eq true ) {
        print "<tr $cb><td><b><big>LDAP Cache:  </big>$text{chk_srv_title} - $config{ldapcache_base} - </b></td></tr>\n";
        print "<tr><td><a name=\"checkLDAPCACHE\">\n";
        &connect_cache();
        $dnCache=$config{ldapcache_base};
        $cur_entry=&sel_cache_obj($dnCache,"o=*");
        if ( !defined($cur_entry)  ||  $cur_entry->dn ne $dnCache) { 
             &html_errshow("ldapcache")
        } else { 
             &ldapcache_logerr("browse $dnCache");
             print "<tr $cb><td>".&text('viewlog_action',$stta_sid)."</td></tr>\n";
        }
   } else {  print "<tr $cb><td><b><big>LDAP Cache:  </big>$text{chk_srv_title} - $config{ldapcache_base} - ???? </b></td></tr>\n"};
   print &parse_webminlog();
print "<table>";
 print "</table>\n";
print "$indexTopHtml";
print "<tr><td><a name=\"ttaproperties\">\n";
  &html_objlink("ttaprops",$text{'index_ttaproperties'},\%ttaprops,$text{index_globaltta},"report"),"\");\n";
  $lnum=0;
foreach $item (@ttahosts) {
      print "$indexTopHtml";
      print "<a name=\"host-".$item->{name}."\">\n";
      &html_objlink("host",$item->{name},\%{$ttahosts[lnum]},$item->{name},"report"),"\");\n";
      $lnum++;
}
print "$indexTopHtml";
print "<tr><td><a name=\"acl\">\n";
  &html_objlink("access stta",$text{index_acl},\%access,$text{index_acl},"report"),"\");\n";
print "$indexTopHtml";
 if ( $ReportOut ) { $| =1; select(STDOUT);}
}

sub sel_tta_app
{
     local $file_path=&get_tta_app_path();
     local %h_tta_apps=&load_tta_apptypes();
     print "<tr><td valign=top>",&hlink("<b>$text{'f_ttaapptype'}</b>","fttaapptype"),"</td>\n";
     print " <td valign=top><select NAME=\"ttaapptype\">\n";
     print "                <option VALUE=\"none\" selected>$text{'f_selobj'}\n";
     local $nItems=0;
     foreach $item (keys (%h_tta_apps)) {
          print "         <option ";
          print "VALUE=\"$item\" ";
          print ">$h_tta_apps{$item}\n";
          $nItems++;
     }
     print "  </select></td></tr>\n";
}

sub out_tta_app_js
{
 local (@appdef) =@_;
 foreach $data (@appdef) {
   next  if ( $data->{att} eq "name" );
   next  if ( $data->{att} eq "description" );
   if ( $data->{need} eq 1 ) {
     if ( $data->{opstype} eq "select" ) {
        print "     if ( get_value(\"select\",obj.".$data->{att}.") == \"none\" ) {\n";
        print "           alert(obj.".$data->{att}.".name+\":\"+msg1+\"->\"+obj.".$data->{att}.".value+\"<-\");\n";
        print "                 obj.".$data->{att}.".focus();\n";
        print "                 return false;\n";
        print "     }   \n";
     } else {
        print "     if ( emptyField(obj.".$data->{att}.") == true || obj.".$data->{att}.".value == '$data->{ops}' ) {\n";
        print "            alert(obj.".$data->{att}.".name+\":\"+msg1+\"->\"+obj.".$data->{att}.".value+\"<-\");\n";
        print "            obj.".$data->{att}.".focus();\n";
        print "            return false;\n";
        print "     }\n";
     }
   }
 }
}

sub out_tta_appform
{
 local (@appdef) =@_;
 local $f_name="";
 &load_more_text('tta_apps'); 

# print "<tr><td> $#appdef </td></tr>";
 foreach $data (@appdef) {
   next  if ( $data->{att} eq "name" );
   next  if ( $data->{att} eq "description" );
   $f_name=$text{'f_tta_'.$data->{att}};
   print "<tr><td><b>";
   if ( $data->{need} eq 1 ) { print "*<u>"; };
   if ( $f_name eq "" ) { $f_name=$data->{att} }
   print "$f_name";
   if ( $data->{need} eq 1 ) { print "</u>"; };
   print "</b></td>\n";
#   print "<td valign=top><input TYPE=\"hidden\" NAME=\"".$data->{att}."_need\" VALUE=\"$data->{need}\"></td>\n";
   if ( $data->{opstype} eq "select" ) {
     print " <td><select NAME=\"".$data->{att}."\">\n";
     local @l_ops = split(/\|/,$data->{ops}, -1);
     local $nItems=0;
     $fvalue=$data->{value};
     if ( $data->{need} eq 0 && $fvalue eq "" ) {
          print "         <option selected value=\"none\">$text{index_default}" ; 
     }
     foreach $item (@l_ops) {
          $f_name=$text{'f_tta_'.$item};
          if ( $f_name eq "" ) { $f_name=$item }
          print "         <option ";
          print "VALUE=\"$item\" ";
          if ( $fvalue eq $item ) { print "selected"; }
          print ">$f_name\n";
#          print ">$f_name -- $fvalue\n";
          $nItems++;
     }
     print "  </select></td>\n";
   } else {
       $fvalue=$data->{value};
       if ( $data->{att} eq "appserv" ) {
           print "   <td>\n";
           print "<textarea wrap=auto name=appserv rows=5 cols=10>",
                  join("\n", split(/,/ , $fvalue)),"</textarea>\n";
           print "<input type=button onClick='ifield = document.forms[0].appserv; chooser = window.open(\"/stta/host_chooser.cgi?multi=1&host=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=700,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"...\">\n";
          print "<input type=button onClick='ifield = document.forms[0].appserv; if ( ifield.value == \"$fvalue\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=hosts&multi=1&ord=ens&deft=alias&f=textarea&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";
       } else {
          if ( $data->{att} eq "width" && $fvalue eq "" ) { $fvalue=$config{tta_appwidth} }
          if ( $data->{att} eq "height" && $fvalue eq "" ) { $fvalue=$config{tta_appheigth} }
          if ( $data->{att} eq "ntdomain" && $fvalue eq "" ) { $fvalue=$config{companyntdomain} }
          if ( $fvalue eq "" ) { $fvalue = $data->{ops} };
          print "<td><input TYPE=\"text\" NAME=\"$data->{att}\" VALUE=\"$fvalue\" cols=\"22\" size=\"42\" ALIGN=left></td>\n";
       }
   }
   $f_name=$data->{line};
   $f_name=~ s/"/'/g;
   $f_name=~ s/\$text{(\S+)}/tta_textOut($1)/ge;
   print "<td>";
   print "$f_name";
#   eval ("print \"$f_name\"");
   print "</td></tr>\n";
 }
}

sub tta_textOut
{
 if ( $_[0] eq "f_fdefault" ) { return "<b>".$text{$_[0]}."</b>" }
 return "<u>".$text{$_[0]}."</u>";  
}

# output select html options code between <select name="???"> and  </select> labels 
# out_htmlselobj [hash-objects] [sort_attr_name] [default_attr_name-in-hash] [default_attr_value-in-hash]
sub out_htmlselobj
{
   local %h_obj=%{$_[0]};
   local $obj_sort_attr=$_[1];
   local $obj_default_attr=$_[2];
   local $obj_default_value=$_[3];
   local @listobjs=();
   local @list_objs=();
   local $nItems=0;

   foreach $item (keys (%h_obj)) { push (@listobjs, $h_obj{$item}); }
   @list_objs = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
   foreach $item (@list_objs) {
      print " <option VALUE=\"".$item->{$obj_default_attr}."\"";
      if ( $item->{$obj_default_attr} eq $obj_default_value ) { print " selected"; }
      print ">". $item->{$obj_sort_attr}."\n";
      $nItems++;
   }
}

sub out_objdata
{
   local $obj_type=$_[0];
   local %h_obj=%{$_[1]};
   local $html_str="w_objs=window.open('', '$obj_type','toolbar=no,menubar=no,scrollbars=yes,width=600,height=300,resizable=yes');";

   $html_str .= "w_objs.document.writeln('<p><table border=1><tr $tb><td><b><font color=$revtext>$obj_type</b></td><td><b><font color=$revtext>$_[2]</font></b></td></tr>');";
   foreach $itematt (keys (%h_obj)) { 
         next if ( $itematt eq "targets" || $itematt eq "numtargets" );
         $html_str .= "w_objs.document.writeln('<tr $cb><td>$itematt</td><td>".$h_obj{$itematt}."</td></tr>');";
   }
   $html_str .= "w_objs.document.writeln('</table>'); return false";
   return $html_str;
}
# output OM html icons &  labels 
# out_htmlOMobj [objtype] [hash-objects] [sort_attr_name] [default_attr_name-in-hash] [default_attr_value-in-hash] [href ]
sub out_htmlOMobj
{
 local $objtype=$_[0];
 local $grpobjtype=$_[0];
 local %h_obj=%{$_[1]};
 local $obj_sort_attr=$_[2];
 local $obj_default_attr=$_[3];
 local $obj_default_value=$_[4];
 local $obj_href=$_[5];
 local @listobjs=();
 local @list_objs=();
 local @list_targets=();
 local $nItems=0;
 local $nTabs=0;
 local $lastgrp="";
 local $linegrp="";
 local @line=();
 local @ensline=();
 local $lineUrl="";
 local %h_target=();
 local $has_grp="false";
 local $iconType="";
 local $targetalias="";
 
 foreach $item (keys (%h_obj)) { 
       $h_obj{$item}->{'targets'}=();
       $h_obj{$item}->{'numtargets'}=-1;
 }
 if ( $objtype eq "ous" ) { $has_grp="false" }
 if ( $objtype eq "domains" ) { $has_grp="false" }
 if ( $objtype eq "links" ) { $has_grp="false" }
 if ( $objtype eq "hosts" ) { 
       %h_target=%h_obj;
       foreach $item (keys (%h_target)) { push (@listobjs, $h_target{$item}); }
       @list_targets = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
       %h_obj=&list_grphosts();
       $has_grp="true";
       $grpobjtype="grphosts";
 }
 if ( $objtype eq "grphosts" ) {
       %h_target=&list_hosts(); 
       foreach $item (keys (%h_target)) { push (@listobjs, $h_target{$item}); }
       @list_targets = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
       $has_grp="true";
 }
 if ( $objtype eq "grpapps" ) {
       %h_target=&list_apps(); 
       foreach $item (keys (%h_target)) { push (@listobjs, $h_target{$item}); }
       @list_targets = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
       $has_grp="true";
 }
 if ( $objtype eq "apps" ) { 
       %h_target=%h_obj;
       foreach $item (keys (%h_target)) { push (@listobjs, $h_target{$item}); }
       @list_targets = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
       %h_obj=&list_grpapps();
       $has_grp="true";
       $grpobjtype="grpapps";
 }
 if ( $objtype eq "sysusers" ) { 
       %h_target=%h_obj;
       foreach $item (keys (%h_target)) { push (@listobjs, $h_target{$item}); }
       @list_targets = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
       %h_obj=&list_ous();
       $has_grp="true";
       $grpobjtype="ous";
 }
 @listobjs=();
 foreach $item (keys (%h_obj)) { push (@listobjs, $h_obj{$item}); }
 @list_objs = sort {$a->{$obj_sort_attr} cmp $b->{$obj_sort_attr}} @listobjs;
 print "<table width=100% border=0>\n";
 $nItems=0;
 foreach $item (@list_objs) {
     @ensline=split(/\//, $item->{ens}, -1);
     $nTabs=$#ensline+1;
     $linegrp=$item->{$obj_sort_attr};
     @a_target=$item->{'targets'};
     if ( $item->{$obj_sort_attr} =~ /\// ) {
          @line=split(/\//, $item->{$obj_sort_attr}, -1);
          $linegrp=~ s/$line[$#line]$//;
     } else {
          $linegrp=$item->{$obj_sort_attr};
     }
#     print "<tr><td> --$linegrp -- $lastgrp -- $nTabs -- $has_grp--></td></tr>";
     if ( $obj_default_value =~ /$item->{$obj_default_attr}/ ) {
         print "<tr $tb ><td>";
     } else {
         print "<tr $cb ><td>";
     }
     for ( $i = 0 ; $i < $nTabs ; $i++ ) {
        if ( $i gt 0 ) {
            print "<img align=middle border=0 alt='spacetab' src='images/omicons/spacetab.gif'>";
        }
         print "<img align=middle border=0 alt='vertline' src='images/omicons/vertline.gif'>";
     }
     if ( $nTabs gt 0 ) {
         print "<img align=middle border=0 alt='spacetab' src='images/omicons/spacetab.gif'>";
         print "<img align=middle border=0 alt='tvertline' src='images/omicons/tvertline.gif'>";
     }
    if ( $has_grp eq "true" ) {
         print " <img align=middle border=0 alt='minus' src='images/omicons/minus.gif'> ";
    } else {
         print " <img align=middle border=0 alt='plus' src='images/omicons/plus.gif'> ";
    }
    if ( $item->{$obj_sort_attr} eq "" && $obj_sort_attr eq "ens" ) {
#         print "<a class='menu1' href=\"\" onClick=\"alert('".$config{tta_base}."');\" >";
         print "<a class='menu1' href=\"\" onClick=\"".&out_objdata($grpobjtype,$item,$item->{name})."\" >";
         print " <img align=middle border=0 alt='ou' src='images/omicons/org.gif'> ";
    } else {
#         print "<a class='menu1' href=\"\" onClick=\"alert('".$item->{$obj_sort_attr}."');\" >";
         print "<a class='menu1' href=\"\" onClick=\"".&out_objdata($grpobjtype,$item,$item->{name})."\" >";
         print " <img align=middle border=0 alt='ou' src='images/omicons/ou.gif'> ";
    }
    print "</a>\n";
    if ( $has_grp ne "true" || $objtype =~ /^grp/ ) {
        if ( $obj_href =~ /^onClick=/ ) {
             $lineUrl=$obj_href;
             $lineUrl=~ s/VALUE/$item->{$obj_default_attr}/g;
             print "<a class='menu1' href=\"\" $lineUrl ";
        } else {
             print "<a class='menu1' href=\"$obj_href".$item->{$obj_default_attr};
        }
        print ">";
        if ( $obj_default_value =~ /$item->{$obj_default_attr}/ ) { print "<font color='$revtext'><b>"; }
        print $item->{'descrip'};
        if ( $obj_default_value =~ /$item->{$obj_default_attr}/ ) { print "</b></font>"; }
        print "  <td><b>";
        if ( $obj_default_value =~ /$item->{$obj_default_attr}/ ) { print "<font color='$revtext'><b>"; }
        print $item->{'name'};
        if ( $obj_default_value =~ /$item->{$obj_default_attr}/ ) { print "</b></font>"; }
        print "</b></td></a>";
    } else {
        print $item->{'descrip'}."  <td><b>".$item->{'name'}."</b></td>";
    }
    print "</td></tr>\n";
    $nItems++;
    next if ( $has_grp ne "true" );
    foreach $item_target (@list_targets) {
           next if ( $item->{'alias'} ne $item_target->{'grpalias'} );
           $targetalias=$item_target->{'alias'};
           if ( $obj_default_value =~ /$item_target->{$obj_default_attr}/) {
                print "<tr $tb ><td>";
           } else {
                print "<tr $cb ><td>";
           }
           for ( $i = 0 ; $i < $nTabs+1 ; $i++ ) {
               if ( $i gt 0 ) {
                   print "<img align=middle border=0 alt='spacetab' src='images/omicons/spacetab.gif'>";
               }
               print "<img align=middle border=0 alt='vertline' src='images/omicons/vertline.gif'>";
           }
           if ( $objtype =~ /host/ ) {
                $iconType="host";
           } else {
                $iconType=$item_target->{'apptype'}; 
           }
           print "<img align=middle border=0 alt='spacetab' src='images/omicons/spacetab.gif'>";
           print "<img align=middle border=0 alt='tvertline' src='images/omicons/tvertline.gif'>";
           print "<img align=middle border=0 alt='horizline' src='images/omicons/horizline.gif'>";
           #print "<a class='menu1' href=\"\" onClick=\"alert('".$item_target->{'ens'}."');\" >";
           print "<a class='menu1' href=\"\" onClick=\"".&out_objdata($objtype,$h_target{$targetalias},$item_target->{name})."\" >";
           print "<img align=middle border=0 alt='icon' src='images/omicons/".$iconType.".gif'>";
           print "</a>\n";
           if ( $objtype =~ /^grp/ ) {
               print $item_target->{'descrip'}."  <td><i>".$item_target->{'name'}."</i></td>";
           } else {
               if ( $obj_href =~ /^onClick=/ ) {
                  $lineUrl=$obj_href;
                  $lineUrl=~ s/VALUE/$item_target->{$obj_default_attr}/g;
                  print "<a class='menu1' href=\"\" $lineUrl ";
               } else {
                  print "<a class='menu1' href=\"$obj_href".$item_target->{$obj_default_attr};
               }
               print ">";
               if ( $obj_default_value =~ /$item_target->{$obj_default_attr}/) { print "<font color='$revtext'><b>"; }
               print $item_target->{'descrip'};
               if ( $obj_default_value =~ /$item_target->{$obj_default_attr}/ ) {  print "</b></font>"; }
               print "  <td><i>";
               if ( $obj_default_value =~ /$item_target->{$obj_default_attr}/) { print "<font color='$revtext'><b>"; }
               print   $item_target->{'name'};
               if ( $obj_default_value =~ /$item_target->{$obj_default_attr}/ ) {  print "</b></font>"; }
               print  "</i></td>";
               print "</a>";
           }
           print "</td></tr>\n";
    }
 }
 print " </table> ";
}

# Output status warning services 
sub out_tabserv_chk
{
  if ( $tta_ok ne true ) {
        print "<a onClick='show_stta();return false' href='javascript:show_stta(),return false'><img align=middle border=0 alt= 'TTA ' src='images/warn_tta.gif'></a>\n";
  }
  if ( $ldap_ok ne true && $config{has_ldapusers} eq "true" ) {
        print "<a onClick='show_stta();return false' href='javascript:show_stta(), return false'><img align=middle border=0 alt= 'LDAP ' src='images/warn_ldap.gif'></a>\n";
  }
  if ( $ldapcache_ok ne true && $config{is_ldapcache} eq "true" ) {
        print "<a onClick='show_stta();return false' href='javascript:show_stta(), return false'><img align=middle border=0 alt= 'LDAPCACHE ' src='images/warn_ldapcache.gif'></a>\n";
  }
}

sub out_css 
{
   my $str="";
   $str .="<link rel='stta' href='/stta/images/favicon.ico' type='image/x-icon' >";
#   return "<link href='stta/stta.css' rel='stylesheet' type='text/css'> ";
   $str .= "<style type='text/css'>";
   $str .= ".menu1	{ ";
   $str .= "	line-height: 20px; ";
   $str .= "	text-decoration: none; ";
   $str .= "	padding-left: 2px; ";
   if ( $config{cs_text} =~  /#/ ) {
        $str .= "	color : $config{cs_text}; ";
   }
   $str .= "	} ";
   $str .= ".menu1:Hover    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	color : $config{cs_revtext}; ";
   $str .= "	background-color: $config{cs_header}; ";
   $str .= "	} ";
   $str .= ".menu1:Visited    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	} ";
   $str .= ".menu1:Active    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	} ";
   $str .= ".menu2	{ ";
   $str .= "	line-height: 20px; ";
   $str .= "	text-decoration: none; ";
   $str .= "	padding-left: 2px; ";
   $str .= "	color : $config{cs_revtext}; ";
   $str .= "	} ";
   $str .= ".menu2:Hover    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	color : $config{cs_header}; ";
   $str .= "	background-color: $config{cs_table}; ";
   $str .= "	} ";
   $str .= ".menu2:Visited    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	} ";
   $str .= ".menu2:Active    { ";
   $str .= "	text-decoration: none; ";
   $str .= "	} ";
   $str .= "</style>";
}
1;  # Return true
