#!/usr/bin/perl
# delact.cgi
# delete Action for Services with Tarantella Monitor

require './stta-lib.pl';
if ( ! $access{'monitor'} )   { &redirect("index.cgi"); }
if ( $config{'has_monitor'} ne "true" )  { &redirect("index.cgi"); }
&ReadParse();
if ( !$in{aliasAct} ) { &redirect("mon_actdef.cgi"); }
&headerstta($text{'index_monitor_act'}, "", "monitor_act",undef,1,1,$text{headpage_rigth} ); 
$aliasAct=$in{aliasAct};
$descrip=$in{descrip};
$postform=$in{postform};
$monTarget=$in{monTarget};
$monCondition=$in{monCondition};
$monAction=$in{monAction};
$monConditionValue=$in{monConditionValue};
$monScript=$in{monScript};
$monHow=$in{monHow};
$monWhen=$in{monWhen};
 if ( $monTarget eq "user" ) {
    $objectAct=$in{'username'};
 } elsif  ( $monTarget eq "ou" ) {
     $objectAct=$in{'user_ou'};
 } elsif  ( $monTarget eq "host" ) {
     $objectAct=$in{'hostname'};
 } elsif  ( $monTarget eq "grphosts" ) {
     $objectAct=$in{'usergrphosts'};
 } elsif  ( $monTarget eq "app" ) {
     $objectAct=$in{'appname'};
 } elsif  ( $monTarget eq "grpapps" ) {
     $objectAct=$in{'grpappsname'};
 }

print "<table width=100% border>\n";
print "<tr $tb> <td><i>$text{'titidx_monitor_delact'}:</i><b> $aliasAct - $descrip </b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
 if ( $aliasAct ne "" ) {
    %h_actions=&list_actions();
    &webmin_log($config{'act_list'}, "act", "delete",\$h_actions{$aliasAct});
    delete $h_actions{$aliasAct};
    foreach $item (keys (%h_actions)) { push (@listactions,$h_actions{$item}); }
    @list__actions = sort {$a->{'name'} cmp $b->{'name'}} @listactions;
    &lock_file($config{'act_list'});
    open(FILEACT, ">$config{'act_list'}");
       foreach $action (@list__actions) {
               $linact= $action->{'alias'}."::".$action->{'name'}."::".$action->{'target'}."::".$action->{'object'}."::".$action->{'condition'}."::".$action->{'conditionValue'}."::".$action->{'action'}."::".$action->{'script'}."::".$action->{'when'}."::".$action->{'how'}."::";
               print FILEACT "$linact\n";
       }
    close (FILEACT);
    $str=$text{'user_delete'}.$aliasAct." ->  ".$objectAct;
    &additional_log('delact.cgi', "act", $str);
    &webmin_log($config{'act_list'}, "act", "delete");
    &unlock_file($config{'act_list'});
    print "<tr><p><b>".$text{'user_delete'}.$aliasAct." ->  ".$objectAct."</b></tr>\n";
    print "<tr></tr>\n";
 }
 &footHere;
 exit;
