From: pcanterino <> Date: Thu, 6 Jan 2005 11:25:46 +0000 (+0000) Subject: - When composing the temporary virtual path for a new file, don't call X-Git-Tag: version_2_3~5 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/548d69a4ee38cc59612e787f479ac198d5c37741?ds=inline - When composing the temporary virtual path for a new file, don't call clean_path(). It is unnecessary and it also caused a problem if this path would begin with /../, because on UNIX systems, canonpath() removes /../ at the beginning of a path. So if a user wanted to create the file /../file.ext (which he wasn't allowed to), he created /file.ext. - file_name() and upper_path() now remove multiple trailing slashes - Improved configuration file parser: - Allow configuration options with empty values - If a option is defined twice, the line number is shown in the error message - Static values are now surrounded by single quotes. Maybe it helps to increase the speed of Dev-Editor, because Perl doesn't have to try to interpolate variables in the values. --- diff --git a/devedit.pl b/devedit.pl index 94c9f0e..4ddc9e1 100644 --- a/devedit.pl +++ b/devedit.pl @@ -6,7 +6,7 @@ # Dev-Editor's main program # # Author: Patrick Canterino -# Last modified: 2004-12-29 +# Last modified: 2005-01-06 # use strict; @@ -60,7 +60,7 @@ my $new_virtual = ''; if($newfile ne '' && $newfile !~ /^\s+$/) { $curdir = upper_path($file) if($curdir eq ''); - my $path = clean_path($curdir.$newfile); + my $path = $curdir.$newfile; # Extract file and directory name... @@ -69,16 +69,16 @@ if($newfile ne '' && $newfile !~ /^\s+$/) # ... check if the directory exists ... - unless(-d clean_path($config->{'fileroot'}."/".$dir)) + unless(-d clean_path($config->{'fileroot'}.'/'.$dir)) { - abort($config->{'errors'}->{'dir_not_exist'},"/"); + abort($config->{'errors'}->{'dir_not_exist'},'/'); } # ... and check if the path is above the root directory unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir)) { - abort($config->{'errors'}->{'create_ar'},"/"); + abort($config->{'errors'}->{'create_ar'},'/'); } # Check if we have enough permissions to create a file @@ -86,18 +86,18 @@ if($newfile ne '' && $newfile !~ /^\s+$/) unless(-r $new_physical && -w $new_physical && -x $new_physical) { - abort($config->{'errors'}->{'dir_no_create'},"/",{DIR => $new_virtual}); + abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => $new_virtual}); } # Create the physical and the virtual path - $new_physical = File::Spec->canonpath($new_physical."/".$file); + $new_physical = File::Spec->canonpath($new_physical.'/'.$file); $new_virtual .= $file; } # This check has to be performed first or abs_path() will be confused -if(-e clean_path($config->{'fileroot'}."/".$file)) +if(-e clean_path($config->{'fileroot'}.'/'.$file)) { if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file)) { @@ -129,12 +129,12 @@ if(-e clean_path($config->{'fileroot'}."/".$file)) } else { - abort($config->{'errors'}->{'above_root'},"/"); + abort($config->{'errors'}->{'above_root'},'/'); } } else { - abort($config->{'errors'}->{'not_exist'},"/"); + abort($config->{'errors'}->{'not_exist'},'/'); } # diff --git a/modules/Command.pm b/modules/Command.pm index d6df6b2..bb335dd 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: 2005-01-05 +# Last modified: 2005-01-06 # use strict; @@ -28,7 +28,7 @@ use Output; use Template; my $script = encode_entities($ENV{'SCRIPT_NAME'}); -my $users = eval("getpwuid(0)") && eval("getgrgid(0)"); +my $users = eval('getpwuid(0)') && eval('getgrgid(0)'); my %dispatch = ('show' => \&exec_show, 'beginedit' => \&exec_beginedit, @@ -110,7 +110,7 @@ sub exec_show($$) my $dir_writeable = -w $physical; - my $dirlist = ""; + my $dirlist = ''; my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard my $filter2 = ($filter1 && $filter1 ne '*') ? $filter1 : ''; # Wildcard for output @@ -118,15 +118,15 @@ sub exec_show($$) # Create the link to the upper directory # (only if we are not in the root directory) - unless($virtual eq "/") + unless($virtual eq '/') { - my @stat = stat($physical."/.."); + my @stat = stat($physical.'/..'); my $udtpl = new Template; $udtpl->read_file($config->{'templates'}->{'dirlist_up'}); - $udtpl->fillin("UPPER_DIR",$upper_path); - $udtpl->fillin("DATE",encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); + $udtpl->fillin('UPPER_DIR',$upper_path); + $udtpl->fillin('DATE',encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); $dirlist .= $udtpl->get_template; } @@ -137,21 +137,21 @@ sub exec_show($$) { next unless(dos_wildcard_match($filter1,$dir)); - my $phys_path = $physical."/".$dir; - my $virt_path = encode_entities($virtual.$dir."/"); + my $phys_path = $physical.'/'.$dir; + my $virt_path = encode_entities($virtual.$dir.'/'); my @stat = stat($phys_path); my $dtpl = new Template; $dtpl->read_file($config->{'templates'}->{'dirlist_dir'}); - $dtpl->fillin("DIR",$virt_path); - $dtpl->fillin("DIR_NAME",encode_entities($dir)); - $dtpl->fillin("DATE",encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); - $dtpl->fillin("URL",equal_url(encode_entities($config->{'httproot'}),$virt_path)); + $dtpl->fillin('DIR',$virt_path); + $dtpl->fillin('DIR_NAME',encode_entities($dir)); + $dtpl->fillin('DATE',encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); + $dtpl->fillin('URL',equal_url(encode_entities($config->{'httproot'}),$virt_path)); - $dtpl->parse_if_block("readable",-r $phys_path && -x $phys_path); - $dtpl->parse_if_block("users",$users && -o $phys_path); + $dtpl->parse_if_block('readable',-r $phys_path && -x $phys_path); + $dtpl->parse_if_block('users',$users && -o $phys_path); $dirlist .= $dtpl->get_template; } @@ -162,7 +162,7 @@ sub exec_show($$) { next unless(dos_wildcard_match($filter1,$file)); - my $phys_path = $physical."/".$file; + my $phys_path = $physical.'/'.$file; my $virt_path = encode_entities($virtual.$file); my @stat = stat($phys_path); @@ -172,41 +172,41 @@ sub exec_show($$) my $ftpl = new Template; $ftpl->read_file($config->{'templates'}->{'dirlist_file'}); - $ftpl->fillin("FILE",$virt_path); - $ftpl->fillin("FILE_NAME",encode_entities($file)); - $ftpl->fillin("SIZE",$stat[7]); - $ftpl->fillin("DATE",encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); - $ftpl->fillin("URL",equal_url(encode_entities($config->{'httproot'}),$virt_path)); + $ftpl->fillin('FILE',$virt_path); + $ftpl->fillin('FILE_NAME',encode_entities($file)); + $ftpl->fillin('SIZE',$stat[7]); + $ftpl->fillin('DATE',encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); + $ftpl->fillin('URL',equal_url(encode_entities($config->{'httproot'}),$virt_path)); - $ftpl->parse_if_block("not_readable",not -r $phys_path); - $ftpl->parse_if_block("binary",-B $phys_path); - $ftpl->parse_if_block("readonly",not -w $phys_path); + $ftpl->parse_if_block('not_readable',not -r $phys_path); + $ftpl->parse_if_block('binary',-B $phys_path); + $ftpl->parse_if_block('readonly',not -w $phys_path); - $ftpl->parse_if_block("viewable",-r $phys_path && -T $phys_path && not $too_large); - $ftpl->parse_if_block("editable",(-r $phys_path && -w $phys_path && -T $phys_path && not $too_large) && not $in_use); + $ftpl->parse_if_block('viewable',-r $phys_path && -T $phys_path && not $too_large); + $ftpl->parse_if_block('editable',(-r $phys_path && -w $phys_path && -T $phys_path && not $too_large) && not $in_use); - $ftpl->parse_if_block("in_use",$in_use); - $ftpl->parse_if_block("unused",not $in_use); + $ftpl->parse_if_block('in_use',$in_use); + $ftpl->parse_if_block('unused',not $in_use); - $ftpl->parse_if_block("too_large",$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'}); + $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); + $ftpl->parse_if_block('users',$users && -o $phys_path); $dirlist .= $ftpl->get_template; } $tpl->read_file($config->{'templates'}->{'dirlist'}); - $tpl->fillin("DIRLIST",$dirlist); - $tpl->fillin("DIR",encode_entities($virtual)); - $tpl->fillin("SCRIPT",$script); - $tpl->fillin("URL",encode_entities(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('DIRLIST',$dirlist); + $tpl->fillin('DIR',encode_entities($virtual)); + $tpl->fillin('SCRIPT',$script); + $tpl->fillin('URL',encode_entities(equal_url($config->{'httproot'},$virtual))); - $tpl->fillin("FILTER",encode_entities($filter2)); - $tpl->fillin("FILTER_URL",escape($filter2)); + $tpl->fillin('FILTER',encode_entities($filter2)); + $tpl->fillin('FILTER_URL',escape($filter2)); - $tpl->parse_if_block("dir_writeable",$dir_writeable); - $tpl->parse_if_block("filter",$filter2); + $tpl->parse_if_block('dir_writeable',$dir_writeable); + $tpl->parse_if_block('filter',$filter2); } else { @@ -231,17 +231,17 @@ sub exec_show($$) $tpl->read_file($config->{'templates'}->{'viewfile'}); - $tpl->fillin("FILE",encode_entities($virtual)); - $tpl->fillin("DIR",$upper_path); - $tpl->fillin("URL",encode_entities(equal_url($config->{'httproot'},$virtual))); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('FILE',encode_entities($virtual)); + $tpl->fillin('DIR',$upper_path); + $tpl->fillin('URL',encode_entities(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('SCRIPT',$script); - $tpl->parse_if_block("editable",-w $physical && $uselist->unused($virtual)); + $tpl->parse_if_block('editable',-w $physical && $uselist->unused($virtual)); - $tpl->fillin("CONTENT",encode_entities($$content)); + $tpl->fillin('CONTENT',encode_entities($$content)); } - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -289,13 +289,13 @@ sub exec_beginedit($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'editfile'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); - $tpl->fillin("CONTENT",encode_entities($$content)); + $tpl->fillin('FILE',$virtual); + $tpl->fillin('DIR',$dir); + $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); + $tpl->fillin('SCRIPT',$script); + $tpl->fillin('CONTENT',encode_entities($$content)); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -412,10 +412,10 @@ sub exec_mkfile($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'mkfile'}); - $tpl->fillin("DIR","/"); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('DIR','/'); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -451,10 +451,10 @@ sub exec_mkdir($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'mkdir'}); - $tpl->fillin("DIR","/"); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('DIR','/'); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -485,7 +485,7 @@ sub exec_upload($$) # Process file upload my $filename = file_name($uploaded_file); - my $file_phys = $physical."/".$filename; + 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)); @@ -508,18 +508,18 @@ sub exec_upload($$) $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode file_save($file_phys,\$data,not $ascii) or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt}); - return devedit_reload({command => "show", file => $virtual}); + return devedit_reload({command => 'show', file => $virtual}); } else { my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'upload'}); - $tpl->fillin("DIR",$virtual); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('DIR',$virtual); + $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -563,17 +563,17 @@ sub exec_copy($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_replace'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("NEW_FILE",$new_virtual); - $tpl->fillin("NEW_FILENAME",file_name($new_virtual)); - $tpl->fillin("NEW_DIR",$new_dir); - $tpl->fillin("DIR",$dir); + $tpl->fillin('FILE',$virtual); + $tpl->fillin('NEW_FILE',$new_virtual); + $tpl->fillin('NEW_FILENAME',file_name($new_virtual)); + $tpl->fillin('NEW_DIR',$new_dir); + $tpl->fillin('DIR',$dir); - $tpl->fillin("COMMAND","copy"); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('COMMAND','copy'); + $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -588,12 +588,12 @@ sub exec_copy($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'copyfile'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $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"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -617,7 +617,7 @@ sub exec_rename($$) my $dir = upper_path($virtual); my $new_physical = $data->{'new_physical'}; - return error($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/"); + return error($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/'); return error($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path($physical)); return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); @@ -638,17 +638,17 @@ sub exec_rename($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_replace'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("NEW_FILE",$new_virtual); - $tpl->fillin("NEW_FILENAME",file_name($new_virtual)); - $tpl->fillin("NEW_DIR",$new_dir); - $tpl->fillin("DIR",$dir); + $tpl->fillin('FILE',$virtual); + $tpl->fillin('NEW_FILE',$new_virtual); + $tpl->fillin('NEW_FILENAME',file_name($new_virtual)); + $tpl->fillin('NEW_DIR',$new_dir); + $tpl->fillin('DIR',$dir); - $tpl->fillin("COMMAND","rename"); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('COMMAND','rename'); + $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -663,12 +663,12 @@ sub exec_rename($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'renamefile'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $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"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -691,7 +691,7 @@ sub exec_remove($$) my $virtual = $data->{'virtual'}; my $dir = upper_path($virtual); - return error($config->{'errors'}->{'remove_root'},"/") if($virtual eq "/"); + return error($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/'); return error($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path($physical)); if(-d $physical) @@ -708,12 +708,12 @@ sub exec_remove($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_rmdir'}); - $tpl->fillin("DIR",$virtual); - $tpl->fillin("UPPER_DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('DIR',$virtual); + $tpl->fillin('UPPER_DIR',$dir); + $tpl->fillin('URL',equal_url($config->{'httproot'},$virtual)); + $tpl->fillin('SCRIPT',$script); - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -735,12 +735,12 @@ sub exec_remove($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_rmfile'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $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"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -765,7 +765,7 @@ sub exec_chprop($$) my $dir = upper_path($virtual); return error($config->{'errors'}->{'no_users'},$dir,{FILE => $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 => $virtual}) unless(-o $physical); return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); @@ -787,7 +787,7 @@ sub exec_chprop($$) # 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); + system('chgrp',$group,$physical); } return devedit_reload({command => 'show', file => $dir}); @@ -805,28 +805,28 @@ sub exec_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); + $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); + $tpl->fillin('GROUP',encode_entities($group)); + $tpl->parse_if_block('group_detected',1); } else { - $tpl->parse_if_block("group_detected",0); + $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); + $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"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -862,12 +862,12 @@ sub exec_unlock($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_unlock'}); - $tpl->fillin("FILE",$virtual); - $tpl->fillin("DIR",$dir); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); - $tpl->fillin("SCRIPT",$script); + $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"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; @@ -890,33 +890,33 @@ sub exec_about($$) my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'about'}); - $tpl->fillin("SCRIPT",$script); + $tpl->fillin('SCRIPT',$script); # Dev-Editor's version number - $tpl->fillin("VERSION",$data->{'version'}); + $tpl->fillin('VERSION',$data->{'version'}); # Some path information - $tpl->fillin("SCRIPT_PHYS",encode_entities($ENV{'SCRIPT_FILENAME'})); - $tpl->fillin("CONFIG_PATH",encode_entities($data->{'configfile'})); - $tpl->fillin("FILE_ROOT", encode_entities($config->{'fileroot'})); - $tpl->fillin("HTTP_ROOT", encode_entities($config->{'httproot'})); + $tpl->fillin('SCRIPT_PHYS',encode_entities($ENV{'SCRIPT_FILENAME'})); + $tpl->fillin('CONFIG_PATH',encode_entities($data->{'configfile'})); + $tpl->fillin('FILE_ROOT', encode_entities($config->{'fileroot'})); + $tpl->fillin('HTTP_ROOT', encode_entities($config->{'httproot'})); # Perl - $tpl->fillin("PERL_PROG",encode_entities($^X)); - $tpl->fillin("PERL_VER", sprintf("%vd",$^V)); + $tpl->fillin('PERL_PROG',encode_entities($^X)); + $tpl->fillin('PERL_VER', sprintf('%vd',$^V)); # Information about the server - $tpl->fillin("HTTPD",encode_entities($ENV{'SERVER_SOFTWARE'})); - $tpl->fillin("OS", encode_entities($^O)); - $tpl->fillin("TIME", encode_entities(strftime($config->{'timeformat'},localtime))); + $tpl->fillin('HTTPD',encode_entities($ENV{'SERVER_SOFTWARE'})); + $tpl->fillin('OS', encode_entities($^O)); + $tpl->fillin('TIME', encode_entities(strftime($config->{'timeformat'},localtime))); # Process information - $tpl->fillin("PID",$$); + $tpl->fillin('PID',$$); # Check if the functions getpwuid() and getgrgid() are available @@ -928,45 +928,45 @@ sub exec_about($$) my $uid = POSIX::getuid; my $gid = POSIX::getgid; - $tpl->parse_if_block("users",1); + $tpl->parse_if_block('users',1); # ID's of user and group - $tpl->fillin("UID",$uid); - $tpl->fillin("GID",$gid); + $tpl->fillin('UID',$uid); + $tpl->fillin('GID',$gid); # Names of user and group if(my $user = getpwuid($uid)) { - $tpl->fillin("USER",encode_entities($user)); - $tpl->parse_if_block("user_detected",1); + $tpl->fillin('USER',encode_entities($user)); + $tpl->parse_if_block('user_detected',1); } else { - $tpl->parse_if_block("user_detected",0); + $tpl->parse_if_block('user_detected',0); } if(my $group = getgrgid($gid)) { - $tpl->fillin("GROUP",encode_entities($group)); - $tpl->parse_if_block("group_detected",1); + $tpl->fillin('GROUP',encode_entities($group)); + $tpl->parse_if_block('group_detected',1); } else { - $tpl->parse_if_block("group_detected",0); + $tpl->parse_if_block('group_detected',0); } # Process umask - $tpl->fillin("UMASK",sprintf("%04o",umask)); + $tpl->fillin('UMASK',sprintf('%04o',umask)); } else { - $tpl->parse_if_block("users",0); + $tpl->parse_if_block('users',0); } - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; diff --git a/modules/Config/DevEdit.pm b/modules/Config/DevEdit.pm index 9b3cc6c..7402ff1 100644 --- a/modules/Config/DevEdit.pm +++ b/modules/Config/DevEdit.pm @@ -6,7 +6,7 @@ package Config::DevEdit; # Read and parse the configuration files # # Author: Patrick Canterino -# Last modified: 2004-12-31 +# Last modified: 2005-01-06 # use strict; @@ -53,17 +53,20 @@ sub parse_config($) my $file = shift; local *CF; - open(CF,"<".$file) or croak("Open $file: $!"); + open(CF,'<'.$file) or croak("Open $file: $!"); read(CF, my $data, -s $file); close(CF); my @lines = split(/\015\012|\012|\015/,$data); my $config = {}; + my $count = 0; foreach my $line(@lines) { + $count++; + next if($line =~ /^\s*#/); - next if($line !~ /^\s*\S+\s*=.+$/); + next if($line !~ /^\s*\S+\s*=.*$/); my ($key,$value) = split(/=/,$line,2); @@ -74,7 +77,7 @@ sub parse_config($) $value =~ s/^\s+//g; $value =~ s/\s+$//g; - croak "Double defined value '$key' in configuration file '$file'" if($config->{$key}); + croak "Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key}); $config->{$key} = $value; } diff --git a/modules/File/Access.pm b/modules/File/Access.pm index 8958e62..4fa468d 100644 --- a/modules/File/Access.pm +++ b/modules/File/Access.pm @@ -7,7 +7,7 @@ package File::Access; # using only one command # # Author: Patrick Canterino -# Last modified: 2004-12-17 +# Last modified: 2005-01-06 # use strict; @@ -70,9 +70,9 @@ sub dir_read($) foreach my $entry(@entries) { - next if($entry eq "." || $entry eq ".."); + next if($entry eq '.' || $entry eq '..'); - if(-d $dir."/".$entry) + if(-d $dir.'/'.$entry) { push(@dirs,$entry); } diff --git a/modules/Output.pm b/modules/Output.pm index 19fa248..7248922 100644 --- a/modules/Output.pm +++ b/modules/Output.pm @@ -6,7 +6,7 @@ package Output; # HTML generating routines # # Author: Patrick Canterino -# Last modified: 2004-12-17 +# Last modified: 2005-01-06 # use strict; @@ -56,13 +56,13 @@ sub error($;$$) my $tpl = new Template; $tpl->read_file($tpl_error); - $tpl->fillin("ERROR",$message); - $tpl->fillin("BACK",$path); - $tpl->fillin("SCRIPT",encode_entities($ENV{'SCRIPT_NAME'})); + $tpl->fillin('ERROR',$message); + $tpl->fillin('BACK',$path); + $tpl->fillin('SCRIPT',encode_entities($ENV{'SCRIPT_NAME'})); - $tpl->parse_if_block("dir",defined $path); + $tpl->parse_if_block('dir',defined $path); - if(ref($vars) eq "HASH") + if(ref($vars) eq 'HASH') { while(my ($key,$value) = each(%$vars)) { @@ -70,7 +70,7 @@ sub error($;$$) } } - my $output = header(-type => "text/html"); + my $output = header(-type => 'text/html'); $output .= $tpl->get_template; return \$output; diff --git a/modules/Tool.pm b/modules/Tool.pm index a05b459..e3056c5 100644 --- a/modules/Tool.pm +++ b/modules/Tool.pm @@ -6,7 +6,7 @@ package Tool; # Some shared sub routines # # Author: Patrick Canterino -# Last modified: 2005-01-04 +# Last modified: 2005-01-06 # use strict; @@ -56,7 +56,7 @@ sub check_path($$) $path =~ tr!\\!/!; $path =~ s!^/+!!; - $path = $root."/".$path; + $path = $root.'/'.$path; # We extract the last part of the path and create the absolute path @@ -64,7 +64,7 @@ sub check_path($$) my $last = file_name($path); $first = abs_path($first); - $path = $first."/".$last; + $path = $first.'/'.$last; $first = File::Spec->canonpath($first); $path = File::Spec->canonpath($path); @@ -78,8 +78,8 @@ sub check_path($$) my $short_path = substr($path,length($root)); $short_path =~ tr!\\!/!; - $short_path = "/".$short_path if($short_path !~ m!^/!); - $short_path = $short_path."/" if($short_path !~ m!/$! && -d $path); + $short_path = '/'.$short_path if($short_path !~ m!^/!); + $short_path = $short_path.'/' if($short_path !~ m!/$! && -d $path); return ($path,$short_path); } @@ -119,31 +119,31 @@ sub devedit_reload(;$) # Detect the protocol (simple HTTP or SSL encrypted HTTP) # and check if the server listens on the default port - my $protocol = ""; - my $port = ""; + my $protocol = ''; + my $port = ''; if(https) { # SSL encrypted HTTP (HTTPS) - $protocol = "https"; - $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 443); + $protocol = 'https'; + $port = ':'.$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 443); } else { # Simple HTTP - $protocol = "http"; - $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 80); + $protocol = 'http'; + $port = ':'.$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 80); } # The following code is grabbed from Template::_query of # Andre Malo's selfforum (http://sourceforge.net/projects/selfforum/) # and modified by Patrick Canterino - my $query = ""; + my $query = ''; - if(ref($params) eq "HASH") + if(ref($params) eq 'HASH') { $query = '?'.join ('&' => map { @@ -156,7 +156,7 @@ sub devedit_reload(;$) # Create the redirection header - my $header = redirect($protocol."://".virtual_host.$port.$ENV{'SCRIPT_NAME'}.$query); + my $header = redirect($protocol.'://'.virtual_host.$port.$ENV{'SCRIPT_NAME'}.$query); return \$header; } @@ -201,7 +201,7 @@ sub equal_url($$) $root =~ s!/+$!!; $path =~ s!^/+!!; - $url = $root."/".$path; + $url = $root.'/'.$path; return $url; } @@ -219,10 +219,10 @@ sub file_name($) my $path = shift; $path =~ tr!\\!/!; - unless($path eq "/") + unless($path eq '/') { - $path = substr($path,0,-1) if($path =~ m!/$!); - $path = substr($path,rindex($path,"/")+1); + $path =~ s!/+$!!; + $path = substr($path,rindex($path,'/')+1); } return $path; @@ -240,28 +240,28 @@ sub file_name($) sub mode_string($) { my $mode = shift; - my $string = ""; + my $string = ''; # User - $string = ($mode & 00400) ? "r" : "-"; - $string .= ($mode & 00200) ? "w" : "-"; - $string .= ($mode & 00100) ? (($mode & 04000) ? "s" : "x") : - ($mode & 04000) ? "S" : "-"; + $string = ($mode & 00400) ? 'r' : '-'; + $string .= ($mode & 00200) ? 'w' : '-'; + $string .= ($mode & 00100) ? (($mode & 04000) ? 's' : 'x') : + ($mode & 04000) ? 'S' : '-'; # Group - $string .= ($mode & 00040) ? "r" : "-"; - $string .= ($mode & 00020) ? "w" : "-"; - $string .= ($mode & 00010) ? (($mode & 02000) ? "s" : "x") : - ($mode & 02000) ? "S" : "-"; + $string .= ($mode & 00040) ? 'r' : '-'; + $string .= ($mode & 00020) ? 'w' : '-'; + $string .= ($mode & 00010) ? (($mode & 02000) ? 's' : 'x') : + ($mode & 02000) ? 'S' : '-'; # Other - $string .= ($mode & 00004) ? "r" : "-"; - $string .= ($mode & 00002) ? "w" : "-"; - $string .= ($mode & 00001) ? (($mode & 01000) ? "t" : "x") : - ($mode & 01000) ? "T" : "-"; + $string .= ($mode & 00004) ? 'r' : '-'; + $string .= ($mode & 00002) ? 'w' : '-'; + $string .= ($mode & 00001) ? (($mode & 01000) ? 't' : 'x') : + ($mode & 01000) ? 'T' : '-'; return $string; } @@ -279,10 +279,10 @@ sub upper_path($) my $path = shift; $path =~ tr!\\!/!; - unless($path eq "/") + unless($path eq '/') { - $path = substr($path,0,-1) if($path =~ m!/$!); - $path = substr($path,0,rindex($path,"/")+1); + $path =~ s!/+$!!; + $path = substr($path,0,rindex($path,'/')+1); } return $path;