#!/usr/bin/perl
# tta_delgrphosts.cgi
# Delete Hosts Group from Services with Tarantella
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

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

 $usergrphosts=$in{usergrphosts};
 &headerstta($text{'index_delgrphosts'}, "", "delgrphosts",undef,1,1,$text{headpage_rigth} ); 
 print "<hr><p>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_delgrphosts'} $usergrphosts </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

if ($usergrphosts ) {
    $obj_name="";
    $ens_grphosts="";
    $dn_grphosts="";
    %h_grphosts=&list_grphosts();
    if ( $h_grphosts{$usergrphosts}->{'alias'} ne $usergrphosts) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
    }
    $ens_grphosts=$h_grphosts{$usergrphosts}->{ens};
    $dn_grphosts=$h_grphosts{$usergrphosts}->{obj};
    $obj_name=$h_grphosts{$usergrphosts}->{name};
}
if (!$dn_grphosts ) { &footHere; exit }  ;    
print "<tr></tr><tr></tr>\n";
print "<tr><td><pre>\n";
if (!$ens_grphosts ) { &footHere; exit }  ;    
    $ens_obj = "--name \"".$config{tta_base}."/$ens_grphosts\" --children";
    $type_cmd="delete";
    if (&run_tta_cmd("delete",$ens_obj)) { 
           print "</pre><tr><p><b>$text{'user_delete'}... Tarantella </b></tr>\n";
           &webmin_log($config{'grphosts_list'}, "grphosts", "delete",$h_grphosts{$usergrphosts});
           delete $h_grphosts{$usergrphosts};
           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";
             }
           close (FILEGRPHOSTS);
           &unlock_file($config{'grphosts_list'});
           $str=$text{'user_delete'}.$usergrphosts;
           &additional_log('delgrphosts.cgi', "grphosts", $str);
           &webmin_log($config{'grphosts_list'}, "grphosts", "delete");
           %h_hosts=&list_hosts();
           foreach $item (keys (%h_hosts)) { push (@listhosts,$h_hosts{$item}); }
           @list__hosts = sort {$a->{'name'} cmp $b->{'name'}} @listhosts;
           &lock_file($config{'hosts_list'});
           open(FILEHOSTS, ">$config{'hosts_list'}");
           foreach $hosts (@list__hosts) {
              if ( $hosts->{'grpalias'} ne $usergrphosts) {
                  $lin_hosts=$hosts->{'alias'}."::".$hosts->{'name'}."::".
                             $hosts->{'grpalias'}."::".$hosts->{'obj'}."::".
                             $hosts->{'ens'}."::".$hosts->{'ipname'}."::".
                             $hosts->{'maxsess'}."::".$hosts->{'descrip'}."::\n";
                  print FILEHOSTS "$lin_hosts";
              } else {
                 &webmin_log($config{'hosts_list'}, "hosts", "delete grphosts",@hosts);
              }
           }
           close (FILEHOSTS);
           &unlock_file($config{'hosts_list'});
           $str=$text{'user_delete'}.$usergrphosts;
           &additional_log('delhosts.cgi', "hosts", $str);
           &webmin_log($config{'hosts_list'}, "hosts", "delete grphosts");
           if ( $config{'is_ldapcache'} eq "true" ) {
                $dn="$dn_grphosts,".$config{ldapcache_base}; 
                if ( &del_ldap_obj($dn) eq 0 ) {   
                     print "<tr><b>".$text{'user_delete'}."... LDAP CACHE ... </b></tr>\n";        
                } else { &html_errshow("ldap")};
           } 
    } else { &html_errshow("tta")};
 print "</tr></td></pre>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
