# All rights reserved (c) 2002;  Author: Daniel Dinev;  http://chatologica.com

package MTS4::ADMIN::DeleteFile;                            # DELETE FILE

use strict;
use MTS4::STD::Common;
use MTS4::STD::CGI_Response;



sub run                                                     # THE LOGIC OF THIS NAVIGATION DESTINATION
{
    my ($class) = @_;
    my $me = {}; bless $me, $class;                         # setting standard object variables:
    my $P = $$me{'P'} = ${$UNIVERSAL::MTS4}{'Parameters'};
    my $E = $$me{'E'} = ${$UNIVERSAL::MTS4}{'ENV'};
    my $in = $$me{'in'} = $$E{'CGI_INPUT_HASH'};
    my $R = $$me{'R'} = new MTS4::STD::CGI_Response;
    my $out = $$me{'out'} = $$R{'out'};                     # init input fields:
    &init_keys($in,[qw(file)],1);
    if($$in{'file'} !~ m{^(data|MTS4/MODULES/)}){           # check for allowed directories
        $R->DieMsg("You are not allowed to delete <I>'$$in{'file'}'</I> file!");
    };
    $$in{'file'} =~ s/\.\.//g;
    &untaint(\$$in{'file'});
    if(! -e "$$in{'file'}") {
        $R->DieMsg("File '$$in{'file'}' does not exist! Maybe it is deleted already.");
    };
    if(unlink($$in{'file'})) {
        $R->DieMsg("File '$$in{'file'}' has been deleted successfully!");
    } else {
        $R->DieMsg("Can't delete file '$$in{'file'}': $!");
    };
};



1; # must return TRUE


