#!/usr/bin/perl
# tta_delgrphosts.cgi
# Delete Hosts Group from Tarantella Services

 require './tarantella-lib.pl';
&foreign_require("proc", "proc-lib.pl");
do "ldap-lib.pl";
&ReadParse();

 $usergrphosts=$in{usergrphosts};
 &header($text{'index_delgrphosts'}, "", "");
 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 ) {
    $organizationname="";
    $ens_grphosts="";
    $dns_grphosts="";
    foreach $grphosts (&list_grphosts()) {
         if ( $grphosts->{'alias'} eq $usergrphosts) {
            $ens_grphosts=$grphosts->{ens};
            $dn_grphosts=$grphosts->{obj};
            $organizationname=$grphosts->{name};
            last;
         }
    }
}
if ( $dn_grphosts ne "" ) {
    $dn = "$dn_grphosts,".$config{ldap_base};
              print "<tr></tr><tr></tr>\n";
              print "<tr><td><pre>\n";
              if ( $ens_grphosts ne "" ) {
                   $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";

                      $lin_grphosts=$aliasgrphosts."::".$grphostsname."::"."cn=$grphostsname,$dn_grphosts"."::"."$ens_grphosts/cn=$grphostsname";
                      @listgrphosts=&list_grphosts();
                      @list__grphosts = sort {$a->{'name'} cmp $b->{'name'}} @listgrphosts;
                      &lock_file($config{'grphosts_list'});
	              open(FILEGRPHOSTS, ">$config{'grphosts_list'}");
                      foreach $grphosts (@list__grphosts) {
                         if ( $grphosts->{'alias'} ne $usergrphosts) {
                             $lin_grphosts=$grphosts->{'alias'}."::".$grphosts->{'name'}."::".$grphosts->{'obj'}."::".$grphosts->{'ens'}."::".$grphosts->{'descrip'}."\n";
                             print FILEGRPHOSTS "$lin_grphosts";
                            
                         }
                      }
                      close (FILEGRPHOSTS);
                      $str=$text{'user_delete'}.$usergrphosts;
                      &additional_log('delgrphosts.cgi', undef, $str);
                      &webmin_log($config{'grphosts_list'}, undef, "delete");
                      &unlock_file($config{'grphosts_list'});
                   }
              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;
