#!/usr/bin/perl
# tta_delhosts.cgi
# Delete Hosts 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");
do "ldap-lib.pl";
&ReadParse();

 $hostname=$in{hostname};
 &headerstta($text{'index_delhosts'}, "", "delhosts",undef,1,1,$text{headpage_rigth} ); 
 print "<hr><p>\n"; 
 print "<table width=100% border>\n";

if ($hostname ) {
    $obj_name="";
    $ens_hosts="";
    $dns_hosts="";
    %h_hosts=&list_hosts();
    if ( $h_hosts{$hostname}->{'alias'} ne $hostname ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
    }
    if ( $h_hosts{$hostname}->{'alias'} eq $hostname) {
         $ens_hosts=$h_hosts{$hostname}->{ens};
         $dn_hosts=$h_hosts{$hostname}->{obj};
         $obj_name=$h_hosts{$hostname}->{name};
    }
}
print "<tr $tb> <td><b>$text{'titidx_delhosts'} $hostname - $obj_name </b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print "<center>\n";
if ( !$dn_hosts) { &footHere; exit }  ;  
     print "<tr></tr><tr></tr>\n";
     print "<tr><td><pre>\n";
     if ( $ens_hosts ne "" ) {
          $ens_obj = "--name \"".$config{tta_base}."/$ens_hosts\"\n";
          $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{'hosts_list'}, "hosts", "delete",$h_hosts{$hostname});
              delete $h_hosts{$hostname};
              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) {
                       $lin_hosts=$hosts->{'alias'}."::".$hosts->{'name'}."::".
                                  $hosts->{'grpalias'}."::".$hosts->{'obj'}."::".
                                  $hosts->{'ens'}."::".$hosts->{'ipname'}."::".
                                  $hosts->{'maxsess'}."::".$hosts->{'portalive'}."::".
                                  $hosts->{'descrip'}."::\n";
                       print FILEHOSTS "$lin_hosts";
                }
              close (FILEHOSTS);
              &unlock_file($config{'hosts_list'});
              $str=$text{'user_delete'}.$hostname;
              &additional_log('delhosts.cgi', "hosts", $str);
              &webmin_log($config{'hosts_list'}, "hosts", "delete");
              if ( $config{'is_ldapcache'} eq "true" ) {
		   $ldapcache_server=1;
                   &connect_cache ();
                   $dn="$dn_hosts,".$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;
