From aeaff6f362f8e376c592469db74f9da3434ecacc Mon Sep 17 00:00:00 2001 From: pcanterino <> Date: Thu, 29 Jul 2004 13:46:03 +0000 Subject: [PATCH] Dev-Editor is now able to change the mode and the group of files --- errors.dat | 2 + modules/Command.pm | 87 +++++++++++++++++++++++++++++++++++++- modules/File/Access.pm | 24 ++++++++++- modules/Tool.pm | 57 ++++++++++++++++++++++--- templates.dat | 1 + templates/chprop.htm | 46 ++++++++++++++++++++ templates/dirlist_dir.htm | 8 ++-- templates/dirlist_file.htm | 8 ++-- templates/dirlist_up.htm | 6 +-- 9 files changed, 217 insertions(+), 22 deletions(-) create mode 100644 templates/chprop.htm diff --git a/errors.dat b/errors.dat index f867df8..60088f1 100644 --- a/errors.dat +++ b/errors.dat @@ -26,5 +26,7 @@ dir_not_exist = The directory where you want to create this file or directory d file_too_large = The file you want to view or edit is too large (max. {SIZE} Bytes). remove_root = You are not allowed to remove the root directory. rename_root = You are not allowed to move/rename the root directory. +no_users = It seems that your system doesn't support users and groups. +not_owner = You are not the owner of {FILE}, so you are not allowed to change the mode and the group. # End of configuration file \ No newline at end of file diff --git a/modules/Command.pm b/modules/Command.pm index 17f9470..8e47163 100644 --- a/modules/Command.pm +++ b/modules/Command.pm @@ -6,7 +6,7 @@ package Command; # Execute Dev-Editor's commands # # Author: Patrick Canterino -# Last modified: 2004-07-27 +# Last modified: 2004-07-28 # use strict; @@ -26,6 +26,7 @@ use Output; use Template; my $script = $ENV{'SCRIPT_NAME'}; +my $users = eval("getpwuid(0)") && eval("getgrgid(0)"); my %dispatch = ('show' => \&exec_show, 'beginedit' => \&exec_beginedit, @@ -37,6 +38,7 @@ my %dispatch = ('show' => \&exec_show, 'copy' => \&exec_copy, 'rename' => \&exec_rename, 'remove' => \&exec_remove, + 'chprop' => \&exec_chprop, 'unlock' => \&exec_unlock, 'about' => \&exec_about ); @@ -134,6 +136,8 @@ sub exec_show($$) $dtpl->fillin("DATE",strftime($config->{'timeformat'},localtime($stat[9]))); $dtpl->fillin("URL",equal_url($config->{'httproot'},$virt_path)); + $dtpl->parse_if_block("users",$users && -o $physical."/".$dir); + $dirlist .= $dtpl->get_template; } @@ -169,6 +173,8 @@ sub exec_show($$) $ftpl->parse_if_block("too_large",$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'}); + $ftpl->parse_if_block("users",$users && -o $phys_path); + $dirlist .= $ftpl->get_template; } @@ -726,6 +732,83 @@ sub exec_remove($$) } } +# exec_chprop() +# +# Change the mode and the group of a file or a directory +# +# Params: 1. Reference to user input hash +# 2. Reference to config hash +# +# Return: Output of the command (Scalar Reference) + +sub exec_chprop($$) +{ + my ($data,$config) = @_; + 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) + { + if(-o $physical) + { + if($mode || $group) + { + if($mode) + { + my $oct_mode = $mode; + $oct_mode = "0".$oct_mode if(length($oct_mode) == 3); + $oct_mode = oct($oct_mode); + + chmod($oct_mode,$physical); + } + + chgrp($group,$physical) if($group); + + return devedit_reload({command => 'show', file => $dir}); + } + else + { + my @stat = lstat($physical); + + my $mode = $stat[2]; + my $mode_oct = substr(sprintf("%04o",$mode),-4); + my $gid = $stat[5]; + my $group = getgrgid($gid); + + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'chprop'}); + + $tpl->fillin("MODE_OCTAL",$mode_oct); + $tpl->fillin("MODE_STRING",mode_string($mode)); + $tpl->fillin("GID",$gid); + $tpl->fillin("GROUP",$group); + + $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}); + } + } + else + { + return error($config->{'errors'}->{'no_users'},$dir,{FILE => $virtual}); + } +} + # exec_unlock() # # Remove a file from the list of used files and @@ -809,7 +892,7 @@ sub exec_about($$) # Check if the functions getpwuid() and getgrgid() are available - if(eval("getpwuid(0)") && eval("getgrgid(0)")) + if($users) { # Dev-Editor is running on a system which allows users and groups # So we display the user and the group of our process diff --git a/modules/File/Access.pm b/modules/File/Access.pm index 2604d29..31ad87d 100644 --- a/modules/File/Access.pm +++ b/modules/File/Access.pm @@ -7,7 +7,7 @@ package File::Access; # with only one command # # Author: Patrick Canterino -# Last modified: 2004-07-21 +# Last modified: 2004-07-28 # use strict; @@ -20,12 +20,32 @@ use Carp qw(croak); use base qw(Exporter); -@EXPORT = qw(dir_read +@EXPORT = qw(chgrp + dir_read file_create file_read file_save file_unlock); +# chgrp() +# +# Change the group of files or directories +# +# Params: 1. Group name +# 2. List of files +# +# Return: Number of files group successfully changed +# (or false) + +sub chgrp($@) +{ + my ($group,@files) = @_; + my $gid = getgrnam($group); + + return unless($gid); + return chown(-1,$gid,@files); +} + # dir_read() # # Collect the files and directories in a directory diff --git a/modules/Tool.pm b/modules/Tool.pm index 840c134..3a43ffc 100644 --- a/modules/Tool.pm +++ b/modules/Tool.pm @@ -6,7 +6,7 @@ package Tool; # Some shared sub routines # # Author: Patrick Canterino -# Last modified: 2004-07-17 +# Last modified: 2004-07-28 # use strict; @@ -30,6 +30,7 @@ use base qw(Exporter); devedit_reload equal_url file_name + mode_string upper_path); # check_path() @@ -144,12 +145,12 @@ sub devedit_reload($) # and modified by Patrick Canterino my $query = '?'.join ('&' => - map { - (ref) - ? map{escape ($_).'='.escape ($params -> {$_})} @{$params -> {$_}} - : escape ($_).'='.escape ($params -> {$_}) - } keys %$params - ); + map { + (ref) + ? map{escape ($_).'='.escape ($params -> {$_})} @{$params -> {$_}} + : escape ($_).'='.escape ($params -> {$_}) + } keys %$params + ); # Create the redirection header @@ -201,6 +202,48 @@ sub file_name($) return $path; } +# mode_string() +# +# Convert a binary file mode string into a human +# readable string (rwxr-x-r-x) +# +# Params: Binary file mode string +# +# Return: Humand readable mode string + +sub mode_string($) +{ + my $mode = shift; + + my $string = ""; + + # Owner + $string .= (($mode & 0x0100) ? 'r' : '-') . + (($mode & 0x0080) ? 'w' : '-') . + (($mode & 0x0040) ? + (($mode & 0x0800) ? 's' : 'x' ) : + (($mode & 0x0800) ? 'S' : '-') + ); + + # Group + $string .= (($mode & 0x0020) ? 'r' : '-') . + (($mode & 0x0010) ? 'w' : '-') . + (($mode & 0x0008) ? + (($mode & 0x0400) ? 's' : 'x') : + (($mode & 0x0400) ? 'S' : '-') + ); + + # World + $string .= (($mode & 0x0004) ? 'r' : '-') . + (($mode & 0x0002) ? 'w' : '-') . + (($mode & 0x0001) ? + (($mode & 0x0200) ? 't' : 'x' ) : + (($mode & 0x0200) ? 'T' : '-') + ); + + return $string; +} + # upper_path() # # Cut away the last part of a path diff --git a/templates.dat b/templates.dat index 6f065b8..320c132 100644 --- a/templates.dat +++ b/templates.dat @@ -16,6 +16,7 @@ confirm_replace = templates/confirm_replace.htm dirlist_file = templates/dirlist_file.htm dirlist_dir = templates/dirlist_dir.htm dirlist_up = templates/dirlist_up.htm +chprop = templates/chprop.htm error = templates/error.htm about = templates/about.htm diff --git a/templates/chprop.htm b/templates/chprop.htm new file mode 100644 index 0000000..67f362b --- /dev/null +++ b/templates/chprop.htm @@ -0,0 +1,46 @@ + + + + +Change properties of {FILE} + + + + +

Change properties of {FILE}

+ +

(equals {URL})

+ +

Back to {DIR}

+ +

Current mode: {MODE_STRING} (Octal: {MODE_OCTAL})

+ +

Current group: {GROUP} (GID: {GID})

+ +
+ + + + + + + + + + + + + + + + + + +
Change mode:
Change group:
+ +
+ +

About Dev-Editor

+ + \ No newline at end of file diff --git a/templates/dirlist_dir.htm b/templates/dirlist_dir.htm index 04a2daa..c1bf870 100644 --- a/templates/dirlist_dir.htm +++ b/templates/dirlist_dir.htm @@ -1,6 +1,6 @@ -[SUBDIR] -{DATE} -{DIR_NAME}/ -(Rename | Delete | View in Browser) +[SUBDIR] +{DATE} +{DIR_NAME}/ +(Rename | Delete |{IF users} Chmod/Chgrp |{ENDIF} View in Browser) diff --git a/templates/dirlist_file.htm b/templates/dirlist_file.htm index 92d61cc..1de43ca 100644 --- a/templates/dirlist_file.htm +++ b/templates/dirlist_file.htm @@ -1,6 +1,6 @@ -{SIZE} -{DATE} -{FILE_NAME} -({IF viewable}View{ELSE}View{ENDIF} | {IF editable}Edit{ELSE}Edit{ENDIF} | Copy{IF unused} | Rename | Delete{ENDIF}{IF in_use} | Unlock{ENDIF} | View in Browser) +{SIZE} +{DATE} +{FILE_NAME} +({IF viewable}View{ELSE}View{ENDIF} | {IF editable}Edit{ELSE}Edit{ENDIF} | Copy{IF unused} | Rename | Delete{ENDIF}{IF in_use} | Unlock{ENDIF} |{IF users} Chmod/Chgrp |{ENDIF} View in Browser) diff --git a/templates/dirlist_up.htm b/templates/dirlist_up.htm index 734be5c..5f375e5 100644 --- a/templates/dirlist_up.htm +++ b/templates/dirlist_up.htm @@ -1,5 +1,5 @@ -[SUBDIR] -{DATE} -../ +[SUBDIR] +{DATE} +../ -- 2.34.1