#!/usr/bin/perl
# tta_modhosts.cgi
# Mod Hosts 

require './tarantella-lib.pl';
&foreign_require("proc", "proc-lib.pl");
if ( $config{'is_ldapcache'} eq "true" ) { 
   do "ldap-lib.pl";
}
&ReadParse();

 $aliashosts=$in{hostname};
 if (!$aliashosts) { &redirect("tta_selhosts.cgi?form=modhosts"); }
 $postform = $in{postform};
 &header($text{'index_modhosts'}, "","modhosts" );
 $ttacmd="edit";
 # Cleaning and reset values ...
 $location="";
 $descrip="";
 $ntdomain="";
 $ipaddress="";
 $maxsess="";
 $usergrphosts="";
 $ens_obj="";
 $hostname="";
 $str_cmds="";
 
 foreach $host (&list_hosts()) {
         if ( $host->{'alias'} eq $aliashosts) {
            $dn_host=$host->{obj};
            $ens_host=$host->{ens};
            $usergrphosts=$host->{grpalias};
            $maxsess=$host->{maxsess};
            $hostname=$host->{name};
            $descrip=$host->{descrip};
            $ipaddress=$host->{ipname};
            last;
         }
 }
 if ( $ens_host ne "" ) {
      $ens_obj = " \"".$config{tta_base}."/$ens_host\"";
 }
 if ( $aliashosts ) {
      if ( $in{postform} ) {
           # loading object attributes ...
           $op="attributes";
           $type_cmd="attributes";
           $no_out=1;
           $status_cmd=&run_tta_cmd($type_cmd,$ens_obj);
           if ( $status_cmd eq true ) {$str_cmds="<tr><td> ".$text{'tta_noobject'}."</td></tr>";}
       }
 } else {
      # loading object defaults ....
      $temp_f=$config{'tta_defaults_hosts'}; 
 } 
 # Assigning and collecting values to be used in the form ...
 foreach $i (&load_ttaobj()) {
            if ( $i->{'property'} eq "description" ) { $descrip=$i->{'value'} };
            if ( $i->{'property'} eq "location" ) { $location=$i->{'value'} };
            if ( $i->{'property'} eq "ntdomain" ) { $ntdomain=$i->{'value'} };
            if ( $i->{'property'} eq "address" ) { $ipaddress=$i->{'value'} };
 }
 if ( $aliashosts ) { unlink($temp_f); };

if ( $config{'is_ldapcache'} eq "true" ) { 
   $dn_cache="cn=$config{ldapcache_defaultobj},$dn_host,".$config{ldapcache_base};  
   $ldapcache_server=1;
   &connect_cache();
   # loading variables
   $entry = $conncache->browse ($dn_cache);
   if ($err = $conncache->getErrorCode ()) {
          if ( $debug eq 2 ) { print "<b> mod ($dn_cache): $err:".$conncache->getErrorString ()."</b>\n"; }
          $str_cmds=$str_cmds."<tr><td> ".$text{'ldapcache_norecord'}."</td>";
   } else {
          $tta3tier_domain = $entry->{tta3tierdomain}[0];
          $tta3tier_login = $entry->{tta3tierlogin}[0];
          $tta3tier_password = $entry->{tta3tierpassword}[0];
          $tta3tier_stringcmd = $entry->{tta3tierstringcmd}[0];
          $tta3tier_title = $entry->{tta3tiertitle}[0];
          $tta3tier_oudn = $entry->{tta3tieroudn}[0];
          $tta3tier_appkey1 = $entry->{tta3tierappkey1}[0];
          $tta3tier_appkey2 = $entry->{tta3tierappkey2}[0];
          $tta3tier_appkey3 = $entry->{tta3tierappkey3}[0];
          $tta3tier_appkey4 = $entry->{tta3tierappkey4}[0];
          $tta3tier_appkey5 = $entry->{tta3tierappkey5}[0];
          $tta3tier_appkey6 = $entry->{tta3tierappkey6}[0];
          $tta3tier_maxsess = $entry->{tta3tiermaxsess}[0];
          $tta3tier_ticketstatus = $entry->{tta3tierticketstatus}[0];
          $tta3tier_ticketcounter = $entry->{tta3tierticketcounter}[0];
          $tta3tier_endticket = $entry->{tta3tierendticket}[0];
          $tta3tier_doifendticket = $entry->{tta3tierdoifendticket}[0];
   }
   &webmin_log("tta_modhosts.cgi", "browse", $dn_cache, $err);       
}

 print "<hr><p>\n";
 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 "var ask_confadmin=true;\n"; 
 print "var NTdomain=\"$ntdomain\";\n"; 
 print "\n"; 
 &htmlCheckAlias("hosts");
if ( $config{'is_ldapcache'} eq "true" ) { &htmlCacheaShowPassw }
 print "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Chek_fields(obj) {\n"; 
 print "     if ( get_value(\"select\",obj.usergrphosts) == \"none\" ) {\n";
 print "          alert(obj.usergrphosts.name+\":\"+msg1);\n";
 print "                    obj.usergrphosts.focus();\n";
 print "          return false;\n";
 print "     }         \n";
 print "     if ( emptyField(obj.hostsname) == true ) {\n"; 
 print "          alert(obj.hostsname.name+\":\"+msg1+\"->\"+obj.hostsname.value+\"<-\");\n"; 
 print "		    obj.hostsname.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "     if ( emptyField(obj.aliashosts) == true ) {\n"; 
 print "          alert(obj.aliashosts.name+\":\"+msg1+\"->\"+obj.aliashosts.value+\"<-\");\n"; 
 print "		    obj.aliashosts.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "     if ( checkAlias_hosts(obj.aliashosts) == true ) {\n";
 print "          return false;\n";
 print "     }         \n";
 print "     nro=parseInt(obj.maxsess.value);\n";
 print "     if ( nro+1 > 0) { \n";
 print "          obj.maxsess.value=nro;\n";
 print "     } else {;\n";
 print "          alert(obj.maxsess.name+\":\"+msg1+\"->\"+obj.maxsess.value+\"<-\");\n";
 print "          obj.maxsess.focus();\n";
 print "          return false;\n";
 print "     };\n";
 if ( $config{'is_ldapcache'} eq "true" ) { &script_cache_chek; };
 print "     if ( get_value(\"select\",obj.usergrphosts) != \"none\" ) {\n"; 
 print "          return confirm(obj.hostsname.value+msg7+get_value('select',obj.usergrphosts));\n"; 
 print "     }         \n"; 
 print "\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   setNTdomain(formObj)\n"; 
 print "   check for a NTdomain\n"; 
 print "*******************************************************************/\n"; 
 print "function setNTdomain(formObj) {\n"; 
 print "  if (emptyField(formObj.ntdomain)) {\n"; 
 print "        formObj.ntdomain.value=NTdomain;\n"; 
 print "        setStatusBar(msg0+NTdomain);\n"; 
 print "   }\n"; 
 print "   else {  \n"; 
 print "        name=StringClip(true,formObj.ntdomain.value);\n"; 
 print "        formObj.ntdomain.value=name;\n"; 
 print "   }\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_modhosts'} $aliashosts </b></td></tr>\n";
 print $str_cmds."\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=newhost ACTION=\"modhosts.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"ttacmd\" VALUE=\"",$ttacmd,"\">\n"; 
 print "        <input TYPE=\"hidden\" NAME=\"aliashosts\" VALUE=\"",$aliashosts,"\">\n";
 print "	<input TYPE=\"hidden\" NAME=\"hostname\" VALUE=\"",$hostname,"\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"usergrphosts\" VALUE=\"",$usergrphosts,"\">\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_aliashosts'}</b>","faliashosts"),"&nbsp;</td>\n";
 print "         <td valign=top><b>$aliashosts</b>&nbsp;</td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_hostname'}</b>","fhostsname"),"&nbsp;</td>\n";
 print "         <td valign=top><b>$hostname</b>&nbsp;</td></tr>\n"; 

 print "	<tr><td valign=top>",&hlink("<b>$text{'f_ipaddress'}</b>","fipaddress"),"&nbsp;</td>\n";
print "		<td valign=top><input TYPE=\"text\" NAME=\"ipaddress\" VALUE=\"$ipaddress\" cols=\"20'\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_descrip'}</b>","fdescrip"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"descrip\" VALUE=\"$descrip\" cols=\"40\" size=\"40\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_location'}</b>","flocation"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"location\" VALUE=\"$location\" cols=\"60\" size=\"60\" ALIGN=left></td></tr>\n"; 
 print "  	<tr><td valign=top>",&hlink("<b>$text{'f_ntdomain'}</b>","fntdomain"),"</td>\n"; 
 print "        <td valign=top><input TYPE=\"text\" NAME=\"ntdomain\" VALUE=\"$ntdomain\" cols=\"12\" size=\"12\" ALIGN=left\n"; 
 print "		onChange=\"setNTdomain(newhost)\" onFocus=\"setNTdomain(newhost)\"></td></tr>\n"; 
 print "\n"; 
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_usergrphosts'}</b>","fusergrphosts"),"&nbsp;</td>\n";

foreach $item (&list_grphosts()) {
     if ( $usergrphosts eq $item->{'alias'} ) { 
          print "  <td valign=top><b>".$item->{'name'}."</b>&nbsp;</td></tr>\n"; 
          last;
     }
     $nItems++;
}
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_maxsess'}</b>","fmaxsess"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"maxsess\" VALUE=\"$maxsess\" cols=\"4\" size=\"4\" ALIGN=left onChange=\"isNroThis(this)\">\n";
if ( $config{'is_ldapcache'} eq "true" ) { $formObj="newhost";$msgObj=$text{'default_obj'};&htmlCacheapp(msgObj) }
 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;\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";
 print "	</form>\n"; 
 print "<tr><tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;



