#!/usr/bin/perl
# tta_addhosts.cgi
# Add Hosts 
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

require './stta-lib.pl';
	&headerstta($text{'index_addhosts'}, "","addhosts" ,undef,1,1,$text{headpage_rigth} );
 $ttacmd="new_host";
 $ntdomain="";
 $maxsess=$config{default_maxsess};
 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");
 &htmlCheckAlias("hostaddress");
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 ( emptyField(obj.ipaddress) == true ) {\n"; 
 print "          alert(obj.ipaddress.name+\":\"+msg1+\"->\"+obj.ipaddress.value+\"<-\");\n"; 
 print "		    obj.ipaddress.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "     if ( checkAlias_hosts(obj.aliashosts) == true ) {\n";
 print "          return false;\n";
 print "     }         \n";
 print "     if ( checkAlias_hostaddress(obj.ipaddress) == 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";
 print "     nro=parseInt(obj.portalive.value);\n";
 print "     if ( nro+1 > 0) { \n";
 print "          obj.portalive.value=nro;\n";
 print "     } else {;\n";
 print "          alert(obj.portalive.name+\":\"+msg1+\"->\"+obj.portalive.value+\"<-\");\n";
 print "          obj.portalive.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_adhosts'}</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=newhost ACTION=\"addhosts.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"ttacmd\" VALUE=\"",$ttacmd,"\">\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_aliashosts'}</b>","faliashosts"),"&nbsp;</td>\n";
print "         <td valign=top> <input TYPE=\"text\" NAME=\"aliashosts\" VALUE=\"\" cols=\"12\" size=\"12\" ALIGN=left onChange=\"checkAlias_hosts(this)\"></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_hostname'}</b>","fhostsname"),"&nbsp;</td>\n";
print "		<td valign=top><input TYPE=\"text\" NAME=\"hostname\" VALUE=\"\" cols=\"35\" size=\"35\" ALIGN=left></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=\"\" cols=\"20'\" size=\"20\" ALIGN=left onChange=\"checkAlias_hostaddress(this)\"></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";

 print "   <td valign=top><select NAME=\"usergrphosts\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecgrphosts'}</b>","fselecgrphosts"),"\n";
$nItems=0;
%h_grphosts=&list_grphosts();
foreach $item (keys (%h_grphosts)) {
 print " <option VALUE=\"".$h_grphosts{$item}->{'alias'}."\">". $h_grphosts{$item}->{'name'}."\n";
 $nItems++;
}
 print "        </select></td></tr>\n";
 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=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_portalive'}</b>","fportalive"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"portalive\" VALUE=\"$portalive\" cols=\"5\" size=\"5\" 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;



