#!/usr/bin/perl
# delfile.cgi
# Delete file for Services with Tarantella
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require './stta-lib.pl';
&ReadParse();
if ( ! $access{'supervision'} )   { &redirect("index.cgi"); }
$postform = ($in{postform}) ? $in{postform} : "delfile";
$cgiPost = ($in{cgiPost}) ? $in{cgiPost} : "file";
$cgiName = ($in{cgiName}) ? $in{cgiName} : "delfile.cgi";
$wkdir = ($in{wkdir}) ? $in{wkdir} : eval("\$config{'$postform"."_path'}");
if ( ! $in{fName} )   { &redirect("index.cgi"); }
if ( $postform eq "filemgr" ) { $postform="delfile"; }  
$fName=$in{fName};
$cmd=$in{cmd};
if ( $in{fPerm} ) {
     if ( substr($in{fPerm},0,1) ne "-" ) {
        @l_target = split(/,/,$text{'f_perm_value'}, -1);
        @l_target_tit = split(/,/,$text{'f_perm_desc'}, -1);
        $nItems=0;
        foreach $item (@l_target) {
                if ( $item eq $in{fPerm} ) {
                     $fMode=$l_target_tit[$nItems];
                     $fPerm=substr($fMode,2,1);
                     last;
                }
                print  $l_target_tit{$nItems};
                $nItems++;
        }
     } else {
        $fMode=$in{fPerm};
        $fPerm=substr($fMode,2,1);
     }
}
$perm=$in{perm};
if ( $perm ne "new" && substr($in{fPerm},1,3) eq "rwx" ) { $perm="all"; }

&headerstta(eval("\$text{'index_$postform'}"), "", $postform ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" ); 

print "<table width=100% border>\n";
print "<tr $tb> <td><font color='$revtext'><b>";
if ( $postform ne "delfile" ) { print $text{'delete'}; }
print " ".eval("\$text{'titidx_$postform'}")."</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
if ( $fPerm ne "w" ) {
    print "<tr><td>>";
    print &text('file_err',$text{'delete'},$wkdir,$fName,$fMode); 
    print "</td></tr>\n";
    &footHere;
    exit 1;
} 
 $lnum = 0;
 $f_path=$wkdir."/".$fName;
 &unlock_file($f_path);
 unless ( unlink($f_path) ) {
    print "<tr><td>>";
    print &text('file_err',$text{'delete'},$wkdir,$fName,$fMode); 
    print "</td></tr>\n";
    &footHere;
    exit 1;
 }

 &webmin_log("$text{delete} ($perm) ","file","$f_path $fMode");
 print "</tr></td>\n";
 print "<tr><td><b>$text{'user_delete'} <b><i>$wkdir</i>/<b>$fName</b>\n";
 if ( $debug gt 0 ) { print " &nbsp;&nbsp; ($fMode) ";}
 print " </td></tr>\n";
 print "</left><tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
