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

 require './stta-lib.pl';
 &headerstta($text{'index_delprofcache'}, "", "delprofcache",undef,1,1,$text{headpage_rigth} ); 
 if ( $config{'is_ldapcache'} eq "true" ) {
     $err_msg=$text{'ldapcache_enable'};
     &footCacheHere;
     exit;
 }

 &ReadParse();
 $profilename=$in{profilename};
 print "<hr><p>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_delprofcache'} $profcache </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center> \n";

if ($profilename) {
    print "<tr><td><pre>\n";
    print "<tr></tr><tr></tr>\n";
    %h_profcache=&list_profcache();
    &webmin_log($config{'profcache_list'}, "profcache", "delete",$h_profcache{$profilename});
    delete $h_profcache{$profilename};
    foreach $item (keys (%h_profcache)) { push (@listprofcache,$h_profcache{$item}); }
    @list_profcache = sort {$a->{'name'} cmp $b->{'name'}} @listprofcache;
    &lock_file($config{'profcache_list'});
    open(FILEPROFCACHE, ">$config{'profcache_list'}");
    foreach $list_profcache (@list_profcache) {
            $lin_profcache=$list_profcache->{'alias'}."::".$list_profcache->{'name'};
            $lin_profcache=$lin_profcache."::".$list_profcache->{'hostusername'};
            $lin_profcache=$lin_profcache."::".$list_profcache->{'hostname'};
            $lin_profcache=$lin_profcache."::".$list_profcache->{'usergrphosts'};
            $lin_profcache=$lin_profcache."::".$list_profcache->{'username'};
            $lin_profcache=$lin_profcache."::".$list_profcache->{'userou'};
            print FILEPROFCACHE "$lin_profcache\n";
    }
    close (FILEPROFCACHE);
    &unlock_file($config{'profcache_list'});
    $str=$text{'user_delete'}.$profilename;
    &additional_log('delprofcache.cgi', "profcache", $str);
    &webmin_log($config{'profcache_list'}, "profcache", "delete");
    print "</pre><tr><p><b>$text{'user_delete'}... Tarantella </b></tr>\n";
    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;
