#!/usr/bin/perl
# modhosts.cgi
# ...  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 './stta-lib.pl';
&ReadParse();
if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) {
     do "ldap-lib.pl";
}

&headerstta($text{'index_modhosts'}, "", "modhosts",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
print "<hr><p>\n"; 
&foreign_require("proc", "proc-lib.pl");

 $type_cmd = $in{ttacmd};
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_modhosts'}</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 $hostname=$in{hostname};
 $location=$in{location};
 $descrip=$in{descrip};
 $ntdomain=$in{ntdomain};
 $ipaddress=$in{ipaddress};
 $maxsess=$in{maxsess};
 $portalive=$in{portalive};
 $aliashosts=$in{aliashosts};
 $usergrphosts=$in{usergrphosts};

 if (!$hostname)  { &footHere; exit; }
 $alias=$aliashosts;
 %h_hosts=&list_hosts();
 if ( $h_hosts{$aliashosts}->{'alias'} ne $aliashosts ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $grp_name="";
 $dn_host="";
 $ens_host="";
 $dn_host=$h_hosts{$aliashosts}->{'obj'};
 $ens_host=$h_hosts{$aliashosts}->{'ens'};
 %h_grphosts=&list_grphosts();
 $grp_name=$h_grphosts{$usergrphosts}->{'name'};
 if ( $dn_host eq "" ) {
       $dn_org = "ou=$hostname";
       $ens_org = "cn=$hostname";
 } else {
       $dn_org = $dn_host;
       $ens_org = $ens_host;
 }
 $ens_obj = "--name \"".$config{tta_base}."/$ens_org\"";
 $| = 1;
 $temp = &tempname();
 open(TEMP, ">$temp");
        print TEMP "#!/bin/sh\n";
        print TEMP $env;
        print TEMP "export $export\n" if ($export);
        print TEMP "$str\n";
 close(TEMP);
 $temp_f = &tempname();
 open(TEMPF, ">$temp_f");
     print TEMPF "$ens_obj \\\n";
     if ( $ntdomain ne "" ) {print TEMPF "  --ntdomain \"$ntdomain\"\\\n"; }
     if ( $location ne "" ) {print TEMPF "  --location \"$location\"\\\n"; }
     if ( $descrip ne "" ) {print TEMPF "  --description \"$descrip\"\\\n"; }
     print TEMPF "  --address \"$ipaddress\"\n"; 
 close(TEMPF);
 if (&run_tta_cmd($type_cmd,$ens_obj,$temp_f)) { 
       print "</pre><tr $cb><td><b>$text{'user_update'}... Tarantella </td></tr>\n";
 } else { &html_errshow("tta")};
 # Default object para LDAP cache ...
 if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) { 
      $obj_descrip=$in{descrip};
      $dnldap = "default";
      $dn_cache=$dn_org;
      $task="mod";
      $ldapcache_server=1;
      &connect_cache ();
      $default_obj="cn=$config{ldapcache_defaultobj}";
      $dn_wk=$default_obj.",".$dn_cache.",".$config{ldapcache_base};
      $cur_entry=&sel_cache_obj($dn_wk,"cn=*");
      if ( !defined($cur_entry) || $cur_entry->dn ne $dn_wk) { $task="add"; };
      @tta3tier=&set_tta3tier($default_obj,$dn_cache,$dnldap,$task,"host");
      if ( &cache_obj(\%tta3tier) eq 0 ) {
           if ( $config{ldapcache2_server}.length gt 0 ) {
                $ldapcache_server=2;
                &connect_cache ();
                if ( &cache_obj(\%tta3tier) ne 0 ) { &err_replication() }
           }
      } else { &html_errshow("ldap")};
  } 
  $lin_hosts=$aliashosts."::".$hostname."::".$usergrphosts."::"."$dn_org"."::"."$ens_org"."::".$ipaddress."::".$maxsess."::".$portalive."::".$descrip."::";
  &out_objslist( "modify", "modhosts.cgi", "hosts", "hosts_list", $aliashosts, $lin_hosts, \%h_hosts );
  print "<tr><p><b>".$text{'user_update'}.$hostname." ->  ".$grp_name."</b></tr>\n";
  print "<tr></tr>\n";
#     print "<tr><form METHOD=POST name=modhosts ACTION=\"tta_modhosts.cgi?hostname=$hostname&userhosts=$userhosts\" >\n"; 
#     print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"modhosts\"\n";
#     print "  <input TYPE=\"hidden\" NAME=\"hostname\" VALUE=\"",$hostname,"\"\n";
#     print "  <input TYPE=\"hidden\" NAME=\"ipaddress\" VALUE=\"",$ipaddress,"\"\n";
#     print "  <input TYPE=\"hidden\" NAME=\"maxsess\" VALUE=\"",$maxsess,"\"\n";
#     print "  <input TYPE=\"hidden\" NAME=\"descrip\" VALUE=\"",$descrip,"\">\n";
#     print "  <input TYPE=\"hidden\" NAME=\"location\" VALUE=\"",$location,"\">\n";
#     print "  <input TYPE=\"hidden\" NAME=\"ntdomain\" VALUE=\"",$ntdomain,"\">\n";
#     print "  <input TYPE=\"hidden\" NAME=\"aliashosts\" VALUE=\"",$aliashosts,"\">\n";
#     print "  <input TYPE=\"hidden\" NAME=\"dn\" VALUE=\"",$dn,"\">\n";
#     print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_modatt'},"\" VALUE=\"",$text{'f_modatt'},"\">\n";
#     print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
#     print "	</form>\n"; 
 if ( $debug lt 2 )  { unlink($temp_f); }
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;

