http://www.elcappuccino.ch/cgi/chmod/chmod.pl
#!/usr/bin/perl
#
#!perl
use strict;
use warnings;
use constant { NL => "\n", CRLF => "\015\012"};
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">","error.txt") or die "Unable to append to error.txt: $!\n";
carpout(*LOG);
}
use Cwd;
my $cwd = getcwd();
my $cf = $cwd.'/'.'chmod.txt';
my $report;
$report .= 'CWD is: '.$cwd.NL.NL;
$report .= test($cwd,'');
$report .= NL;
foreach( 0777, 0606, 0404,0777 ){
$report .= chm($cf, 0777);
$report .= test($cf,'');
}
print "Content-Type: text/plain; charset=ISO-8859-1",CRLF,CRLF,
$report;
exit;
sub chm{
my $report;
$_[0] or return( "Need a File or Folder!".NL );
$_[1] or return( "Need a Octalnumber!".NL );
chmod( $_[1], $_[0] )
or return(
NL.sprintf("FAILURE chmod %o on %s because of %s", $_[1],$_[0], "$!" ).NL
);
$report .= sprintf("SUCCESS chmod %o on %s", $_[1],$_[0] ).NL;
return $report;
}
sub test{
my $report;
$_[0] or return( "Need a File or Folder!".NL );
$_[1] and $report .= $_[1].NL;
(-e $_[0]) and $report .= "exists ". $_[0].NL;
(-r $_[0]) and $report .= "can read ". $_[0].NL;
(-w $_[0]) and $report .= "can write ". $_[0].NL;
(-e $_[0]) and $report .= "can execute ". $_[0].NL;
my $mode = ( stat($_[0]) )[2];
$report .= sprintf( "Permissions are %04o\n",$mode & 07777 ).NL;
return $report;
}
PS keinen Bock auf -T