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

require './stta-lib.pl';
&ReadParse();
if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) {
     do "ldap-lib.pl";
}

&headerstta($text{'index_modgrphosts'}, "", "modgrphosts",undef,1,1,$text{headpage_rigth} );
print "<hr><p>\n"; 

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

 $descrip=$in{descrip};
 $maxsess=$in{maxsess};
 $aliasgrphosts=$in{aliasgrphosts};
 $grphostsname=$in{grphostsname};

 if ( !$aliasgrphosts) { &footHere; exit }  ;
 $grphostsname="";
 $dn_grphosts="";
 $ens_grphosts="";
 $alias="";
 %h_grphosts=&list_grphosts();
 if ( $h_grphosts{$aliasgrphosts}->{'alias'} ne $aliasgrphosts ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $dn_grphosts=$h_grphosts{$aliasgrphosts}->{obj};
 $ens_grphosts=$h_grphosts{$aliasgrphosts}->{ens};
 $alias=$h_grphosts{$aliasgrphosts}->{alias};
 if ( $dn_grphosts eq "" ) {
       $dn_org = "ou=$grphostsname";
       $ens_org = "cn=$grphostsname";
 } else {
       $dn_org = $dn_grphosts;
       $ens_org = $ens_grphosts;
 }
 # Default object para LDAP cache ...
 $ens_obj = "--name \"".$config{tta_base}."/$ens_grphosts\"";
 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,"grphosts");
         if ( &cache_obj(\%tta3tier) eq 0 ) {
              if ( $config{ldapcache2_server}.length ) {
                   $ldapcache_server=2;
                   &connect_cache ();
                   if ( &cache_obj(\%tta3tier) ne 0 ) { &err_replication() }
              }
         } else { &html_errshow("ldap")};
 } 
 delete $h_grphosts{$aliasgrphosts};
 foreach $item (keys (%h_grphosts)) { push (@listgrphosts, $h_grphosts{$item}); }
 @list__grphosts = sort {$a->{'name'} cmp $b->{'name'}} @listgrphosts;
 &lock_file($config{'grphosts_list'});
 open(FILEGRPHOSTS, ">$config{'grphosts_list'}");
      foreach $grphosts (@list__grphosts) {
              $lin_grphosts=$grphosts->{'alias'}."::".$grphosts->{'name'}."::".
                                $grphosts->{'obj'}."::".$grphosts->{'ens'}."::".
                                $grphosts->{'maxsess'}."::".$grphosts->{'descrip'}."::\n";
              print FILEGRPHOSTS "$lin_grphosts";
      }
      $lin_grphosts=$aliasgrphosts."::".$grphostsname."::"."$dn_org"."::"."$ens_org"."::".$maxsess."::".$descrip."::";
      print FILEGRPHOSTS "$lin_grphosts";
 close (FILEGRPHOSTS);
 &unlock_file($config{'grphosts_list'});
 $str=$text{'user_update'}.$aliasgrphosts;
 &additional_log('modgrphosts.cgi', "grphosts", $str);
 &webmin_log($config{'grphosts_list'}, "grphosts", "update",$lin_grphosts);
 print "<tr><p><b>".$text{'user_update'}.$aliasgrphosts." ->  ".$grphostsname."</b></tr>\n";
 print "<tr></tr>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
