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

require './stta-lib.pl';
do "ldap-lib.pl";

&headerstta($text{'index_delapp'}, "", "delapp",undef,1,1,$text{headpage_rigth} ); 
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }
&foreign_require("proc", "proc-lib.pl");
$ldapcache_server=1;
&connect_cache();
&ReadParse();

 $appname=$in{appname};

    if ($appname ) {
        $descrip="";
        $ensapp="";
        $dnsapp="";
        $obj_name="";
        %h_apps=&list_apps();
        if ( $h_apps{$appname}->{'alias'} ne $appname ) {
               $err_msg=$text{'list_errno'};
               &footHere;
               exit;
        }
        $dnapp=$h_apps{$appname}->{'obj'};
        $obj_name=$h_apps{$appname}->{'name'};
        $ensapp=$h_apps{$appname}->{'ens'};
        $descrip=$h_apps{$appname}->{'descrip'};
        $grpalias=$h_apps{$appname}->{'grpalias'};
    }
    print "<table width=100% border>\n";
    print "<tr $tb> <td><b>$text{'titidx_delapp'} $appname - $obj_name </b></td> </tr>\n";
    print "<tr $cb> <td><table width=100%>\n";
    print "<center>\n";
    if (!$dnapp ) { &footHere; exit }  ;
    print "<tr></tr><tr></tr>\n";
    print "<tr><td><pre>\n";
    if (!$ensapp ) { &footHere; exit }  ;
    $ens_obj = "--name \"".$config{tta_ldapcacheApps}."/$ensapp\" --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{'app_list'}, "apps", "delete",$h_apps{$appname});
         delete $h_apps{$appname};
         foreach $item (keys (%h_apps)) { push (@listapps,$h_apps{$item}); }
         @list__apps = sort {$a->{'name'} cmp $b->{'name'}} @listapps;
         &lock_file($config{'app_list'});
         open(FILEAPPS, ">$config{'app_list'}");
              foreach $app (@list__apps) {
                       $linapp=$app->{'alias'}."::".$app->{'name'}."::".
                               $app->{'grpalias'}."::".$app->{'obj'}."::".
                               $app->{'ens'}."::".$app->{'maxsess'}."::".
                               $app->{'descrip'}."::\n";
                       print FILEAPPS "$linapp";
              }
          close (FILEAPPS);
          &unlock_file($config{'app_list'});
          $str=$text{'user_delete'}.$appname;
          &additional_log('delapps.cgi', "apps", $str);
          &webmin_log($config{'app_list'}, "apps", "delete");
          if ( $config{'is_ldapcache'} eq "true" ) {
               $ldapcache_server=1;
               &connect_cache ();
               $dn = "$dnapp,".$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")};
          }
          print "</tr></td></pre>\n";
#    } else { &html_errshow("tta")};
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
