]> git.p6c8.net - devedit.git/commitdiff
- exec_chprop() should have a proper coding style, but it made the routine hard
authorpcanterino <>
Mon, 13 Dec 2004 15:17:44 +0000 (15:17 +0000)
committerpcanterino <>
Mon, 13 Dec 2004 15:17:44 +0000 (15:17 +0000)
  to maintain. Thus, I changed its structure.
- Don't allow to change the properties of a file in use
- Don't allow to upload a file if a file with the same virtual name is currently
  in use

modules/Command.pm
templates/dirlist_file.htm

index d62643ddc5d195181b7f4cedc5b7b9373c7a30de..0915697fe8007984ac27323e177dcf5778c4f121 100644 (file)
@@ -6,7 +6,7 @@ package Command;
 # Execute Dev-Editor's commands
 #
 # Author:        Patrick Canterino <patrick@patshaping.de>
-# Last modified: 2004-12-10
+# Last modified: 2004-12-13
 #
 
 use strict;
@@ -495,6 +495,7 @@ sub exec_upload($$)
   my $file_phys = $physical."/".$filename;
   my $file_virt = $virtual.$filename;
 
+  return error($config->{'errors'}->{'in_use'},$virtual,{FILE => $file_virt})      if($data->{'uselist'}->in_use($file_virt));
   return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys && not $cgi->param('overwrite'));
 
   my $ascii     = $cgi->param('ascii');
@@ -772,94 +773,73 @@ sub exec_chprop($$)
  my $physical       = $data->{'physical'};
  my $virtual        = $data->{'virtual'};
  my $dir            = upper_path($virtual);
- my $cgi            = $data->{'cgi'};
- my $mode           = $cgi->param('mode');
- my $group          = $cgi->param('group');
 
- if($users)
- {
-  # System supports user and groups
+ return error($config->{'errors'}->{'no_users'},$dir,{FILE => $virtual})  unless($users);
+ return error($config->{'errors'}->{'chprop_root'},"/")                   if($virtual eq "/");
+ return error($config->{'errors'}->{'not_owner'},$dir,{FILE => $virtual}) unless(-o $physical);
+ return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual})    if($data->{'uselist'}->in_use($virtual));
 
-  if($virtual ne "/")
+ my $cgi   = $data->{'cgi'};
+ my $mode  = $cgi->param('mode');
+ my $group = $cgi->param('group');
+
+ if($mode || $group)
+ {
+  if($mode)
   {
-   # Not the root directory
+   # Change the mode
 
-   if(-o $physical)
-   {
-    # We own this file
-
-    if($mode || $group)
-    {
-     if($mode)
-     {
-      # Change the mode
-
-      chmod(oct($mode),$physical);
-     }
-
-     if($group)
-     {
-      # Change the group using the `chgrp` system command
-
-      return error($config->{'errors'}->{'invalid_group'},$dir,{GROUP => encode_entities($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
-      system("chgrp",$group,$physical);
-     }
-
-     return devedit_reload({command => 'show', file => $dir});
-    }
-    else
-    {
-     # Display the form
-
-     my @stat = stat($physical);
-     my $mode = $stat[2];
-     my $gid  = $stat[5];
-
-     my $tpl = new Template;
-     $tpl->read_file($config->{'templates'}->{'chprop'});
-
-     # Insert file properties into the template
-
-     $tpl->fillin("MODE_OCTAL",substr(sprintf("%04o",$mode),-4));
-     $tpl->fillin("MODE_STRING",mode_string($mode));
-     $tpl->fillin("GID",$gid);
-
-     if(my $group = getgrgid($gid))
-     {
-      $tpl->fillin("GROUP",encode_entities($group));
-      $tpl->parse_if_block("group_detected",1);
-     }
-     else
-     {
-      $tpl->parse_if_block("group_detected",0);
-     }
-
-     # Insert other information
-
-     $tpl->fillin("FILE",$virtual);
-     $tpl->fillin("DIR",$dir);
-     $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
-     $tpl->fillin("SCRIPT",$script);
-
-     my $output = header(-type => "text/html");
-     $output   .= $tpl->get_template;
-
-     return \$output;
-    }
-   }
-   else
-   {
-    return error($config->{'errors'}->{'not_owner'},$dir,{FILE => $virtual});
-   }
+   chmod(oct($mode),$physical);
   }
-  else
+
+  if($group)
   {
-   return error($config->{'errors'}->{'chprop_root'},"/");
+   # Change the group using the `chgrp` system command
+
+   return error($config->{'errors'}->{'invalid_group'},$dir,{GROUP => encode_entities($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
+   system("chgrp",$group,$physical);
   }
+
+  return devedit_reload({command => 'show', file => $dir});
  }
  else
  {
-  return error($config->{'errors'}->{'no_users'},$dir,{FILE => $virtual});
+  # Display the form
+
+  my @stat = stat($physical);
+  my $mode = $stat[2];
+  my $gid  = $stat[5];
+
+  my $tpl = new Template;
+  $tpl->read_file($config->{'templates'}->{'chprop'});
+
+  # Insert file properties into the template
+
+  $tpl->fillin("MODE_OCTAL",substr(sprintf("%04o",$mode),-4));
+  $tpl->fillin("MODE_STRING",mode_string($mode));
+  $tpl->fillin("GID",$gid);
+
+  if(my $group = getgrgid($gid))
+  {
+   $tpl->fillin("GROUP",encode_entities($group));
+   $tpl->parse_if_block("group_detected",1);
+  }
+  else
+  {
+   $tpl->parse_if_block("group_detected",0);
+  }
+
+  # Insert other information
+
+  $tpl->fillin("FILE",$virtual);
+  $tpl->fillin("DIR",$dir);
+  $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+  $tpl->fillin("SCRIPT",$script);
+
+  my $output = header(-type => "text/html");
+  $output   .= $tpl->get_template;
+
+  return \$output;
  }
 }
 
index 720ae170496c9cb1026f67c1ee67520b3cc0cbe5..7ee1b0c75f692f218e90745e8787d6f81f989084 100644 (file)
@@ -2,5 +2,5 @@
 <td align="right" style="white-space:nowrap">{SIZE}</td>
 <td style="padding-left:15pt;white-space:nowrap;">{DATE}</td>
 <td style="padding-left:15pt;white-space:nowrap;">{FILE_NAME}</td>
-<td style="padding-left:15pt;white-space:nowrap;">({IF viewable}<a href="{SCRIPT}?command=show&amp;file={FILE}">View</a>{ELSE}<span style="color:#C0C0C0" title="{IF not_readable}Not readable{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}">View</span>{ENDIF} | {IF editable}<a href="{SCRIPT}?command=beginedit&amp;file={FILE}">Edit</a>{ELSE}<span style="color:#C0C0C0" title="{IF not_readable}Not readable{ELSE}{IF readonly}Read only{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{IF in_use}In use{ENDIF}{ENDIF}{ENDIF}{ENDIF}">Edit</span>{ENDIF} | <a href="{SCRIPT}?command=copy&amp;file={FILE}">Copy</a>{IF unused}{IF dir_writeable} | <a href="{SCRIPT}?command=rename&amp;file={FILE}">Rename</a> | <a href="{SCRIPT}?command=remove&amp;file={FILE}">Delete</a>{ENDIF}{ENDIF}{IF in_use} | <a href="{SCRIPT}?command=unlock&amp;file={FILE}">Unlock</a>{ENDIF} |{IF users} <a href="{SCRIPT}?command=chprop&amp;file={FILE}">Chmod/Chgrp</a> |{ENDIF} <a href="{URL}" target="_blank">View in Browser</a>)</td>
-</tr>
+<td style="padding-left:15pt;white-space:nowrap;">({IF viewable}<a href="{SCRIPT}?command=show&amp;file={FILE}">View</a>{ELSE}<span style="color:#C0C0C0" title="{IF not_readable}Not readable{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}">View</span>{ENDIF} | {IF editable}<a href="{SCRIPT}?command=beginedit&amp;file={FILE}">Edit</a>{ELSE}<span style="color:#C0C0C0" title="{IF not_readable}Not readable{ELSE}{IF readonly}Read only{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{IF in_use}In use{ENDIF}{ENDIF}{ENDIF}{ENDIF}">Edit</span>{ENDIF} | <a href="{SCRIPT}?command=copy&amp;file={FILE}">Copy</a>{IF unused}{IF dir_writeable} | <a href="{SCRIPT}?command=rename&amp;file={FILE}">Rename</a> | <a href="{SCRIPT}?command=remove&amp;file={FILE}">Delete</a>{ENDIF}{ENDIF}{IF in_use} | <a href="{SCRIPT}?command=unlock&amp;file={FILE}">Unlock</a>{ENDIF} |{IF unused}{IF users} <a href="{SCRIPT}?command=chprop&amp;file={FILE}">Chmod/Chgrp</a> |{ENDIF}{ENDIF} <a href="{URL}" target="_blank">View in Browser</a>)</td>
+</tr>
\ No newline at end of file

patrick-canterino.de