]> git.p6c8.net - devedit.git/blobdiff - modules/Command.pm
- Dev-Editor is now able to forbid accessing a file using the configuration file
[devedit.git] / modules / Command.pm
index bbad3f105eff30a7164c7aff67cc0b6f279bde48..b827368f0e4232d41acd717ae19bf3747813c5d8 100644 (file)
@@ -6,7 +6,7 @@ package Command;
 # Execute Dev-Editor's commands
 #
 # Author:        Patrick Canterino <patrick@patshaping.de>
-# Last modified: 2005-04-22
+# Last modified: 2005-06-09
 #
 
 use strict;
@@ -31,17 +31,17 @@ use Template;
 my $script = encode_html($ENV{'SCRIPT_NAME'});
 my $users  = eval('getpwuid(0)') && eval('getgrgid(0)');
 
-my %dispatch = ('show'       => \&exec_show,
-                'beginedit'  => \&exec_beginedit,
-                'endedit'    => \&exec_endedit,
-                'mkdir'      => \&exec_mkdir,
-                'mkfile'     => \&exec_mkfile,
-                'upload'     => \&exec_upload,
-                'copy'       => \&exec_copy,
-                'rename'     => \&exec_rename,
-                'remove'     => \&exec_remove,
-                'chprop'     => \&exec_chprop,
-                'about'      => \&exec_about
+my %dispatch = ('show'      => \&exec_show,
+                'beginedit' => \&exec_beginedit,
+                'endedit'   => \&exec_endedit,
+                'mkdir'     => \&exec_mkdir,
+                'mkfile'    => \&exec_mkfile,
+                'upload'    => \&exec_upload,
+                'copy'      => \&exec_copy,
+                'rename'    => \&exec_rename,
+                'remove'    => \&exec_remove,
+                'chprop'    => \&exec_chprop,
+                'about'     => \&exec_about
                );
 
 ### Export ###
@@ -101,7 +101,7 @@ sub exec_show($$)
   return error($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r $physical && -x $physical);
 
   my $direntries = dir_read($physical);
-  return error($config->{'errors'}->{'dir_read_fail'},$upper_path->{'normal'},{DIR => encode_html($virtual)}) unless($direntries);
+  return error($config->{'errors'}->{'dir_read_failed'},$upper_path->{'normal'},{DIR => encode_html($virtual)}) unless($direntries);
 
   my $files = $direntries->{'files'};
   my $dirs  = $direntries->{'dirs'};
@@ -148,6 +148,7 @@ sub exec_show($$)
    $dtpl->fillin('DATE',encode_html(strftime($config->{'timeformat'},($config->{'use_gmt'}) ? gmtime($stat[9]) : localtime($stat[9]))));
    $dtpl->fillin('URL',equal_url(encode_html($config->{'httproot'}),$virt_path->{'html'}));
 
+   $dtpl->parse_if_block('forbidden',is_forbidden_file($config->{'forbidden'},$virt_path->{'normal'}));
    $dtpl->parse_if_block('readable',-r $phys_path && -x $phys_path);
    $dtpl->parse_if_block('users',$users && -o $phys_path);
 
@@ -178,11 +179,11 @@ sub exec_show($$)
    $ftpl->fillin('URL',equal_url(encode_html($config->{'httproot'}),$virt_path->{'html'}));
 
    $ftpl->parse_if_block('link',-l $phys_path);
-   $ftpl->parse_if_block('no_link',not -l $phys_path);
-   $ftpl->parse_if_block('not_readable',not -r $phys_path);
+   $ftpl->parse_if_block('readable',-r $phys_path);
+   $ftpl->parse_if_block('writeable',-w $phys_path);
    $ftpl->parse_if_block('binary',-B $phys_path);
-   $ftpl->parse_if_block('readonly',not -w $phys_path);
 
+   $ftpl->parse_if_block('forbidden',is_forbidden_file($config->{'forbidden'},$virt_path->{'normal'}));
    $ftpl->parse_if_block('viewable',(-r $phys_path && -T $phys_path && not $too_large) || -l $phys_path);
    $ftpl->parse_if_block('editable',(-r $phys_path && -w $phys_path && -T $phys_path && not $too_large) && not -l $phys_path);
 
@@ -294,7 +295,7 @@ sub exec_beginedit($$)
 
  return error($config->{'errors'}->{'file_too_large'},$dir,{SIZE => $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s $physical > $config->{'max_file_size'});
 
- # ... and show the editing form
+ # Show the editing form
 
  my $content =  file_read($physical);
  my $md5sum  =  md5_hex($$content);
@@ -804,9 +805,9 @@ sub exec_chprop($$)
  my $dir            = upper_path($virtual);
 
  return error($config->{'errors'}->{'no_users'},$dir,{FILE => encode_html($virtual)})  unless($users);
- return error($config->{'errors'}->{'chprop_root'},'/')                   if($virtual eq '/');
+ return error($config->{'errors'}->{'chprop_root'},'/')                                if($virtual eq '/');
  return error($config->{'errors'}->{'not_owner'},$dir,{FILE => encode_html($virtual)}) unless(-o $physical);
- return error($config->{'errors'}->{'chprop_link'},$dir)                  if(-l $physical);
+ return error($config->{'errors'}->{'chprop_link'},$dir)                               if(-l $physical);
 
  my $cgi   = $data->{'cgi'};
  my $mode  = $cgi->param('mode');
@@ -818,6 +819,7 @@ sub exec_chprop($$)
   {
    # Change the mode
 
+   return error($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
    chmod(oct($mode),$physical);
   }
 

patrick-canterino.de