From: pcanterino <> Date: Sun, 25 Apr 2004 13:04:06 +0000 (+0000) Subject: Splitted the configuration file into three parts: X-Git-Tag: version_2_0~26 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/e34b89e8690b4766fc19a868ee97aa30c1ac3143 Splitted the configuration file into three parts: - devedit.dat: The main configuration file - errors.dat: Contains the error messages - templates.dat: Contains the path to the templates files --- diff --git a/devedit.dat b/devedit.dat index 79ad3db..05837ec 100644 --- a/devedit.dat +++ b/devedit.dat @@ -3,61 +3,14 @@ # # Please don't use quotation marks around the keys and values! -fileroot = D:/WWW/dokumente/devedit-test -httproot = /devedit-test/ -timeformat = %d.%m.%Y %H:%M -uselist_file = uselist -lock_file = uselist.lock -lock_timeout = 10 +fileroot = D:/WWW/dokumente/devedit-test +httproot = /devedit-test/ +timeformat = %d.%m.%Y %H:%M +uselist_file = uselist +lock_file = uselist.lock +lock_timeout = 10 -# ======================================================== -# You don't need to change the values below this comment -# ======================================================== - -# Templates - -tpl_dirlist = templates/dirlist.htm -tpl_viewfile = templates/viewfile.htm -tpl_editfile = templates/editfile.htm -tpl_copyfile = templates/copyfile.htm -tpl_renamefile = templates/renamefile.htm -tpl_mkfile = templates/mkfile.htm -tpl_mkdir = templates/mkdir.htm -tpl_upload = templates/upload.htm -tpl_confirm_rmfile = templates/confirm_rmfile.htm -tpl_confirm_rmdir = templates/confirm_rmdir.htm -tpl_confirm_unlock = templates/confirm_unlock.htm -tpl_confirm_replace = templates/confirm_replace.htm -tpl_dirlist_file = templates/dirlist_file.htm -tpl_dirlist_dir = templates/dirlist_dir.htm -tpl_dirlist_up = templates/dirlist_up.htm -tpl_error = templates/error.htm -tpl_about = templates/about.htm - -# Error messages - -err_binary = This editor is not able to view/edit binary files. -err_editdir = You cannot edit directories. -err_noedit = You have not enough permissions to edit this file. -err_file_in_use = The file '{FILE}' is currently edited by someone else. -err_edit_failed = Saving of file '{FILE}' failed. The file could be damaged, please check its integrity. -err_delete_failed = Could not delete file '{FILE}'. -err_dir_read_fail = Reading of directory '{DIR}' failed. -err_mkfile_failed = Could not create file '{FILE}'. -err_mkdir_failed = Could not create directory '{DIR}'. -err_copy_failed = Could not copy '{FILE}' to '{NEW_FILE}'. -err_rename_failed = Could not move/rename '{FILE}' to '{NEW_FILE}'. -err_above_root = Accessing files and directories above the virtual root directory is forbidden. -err_create_ar = You aren't allowed to create files and directories above the virtual root directory. -err_file_exists = A file or directory called '{FILE}' already exists. -err_exist_edited = The target file '{FILE}' already exists and is edited by someone else. -err_in_use = The file '{FILE}' is currently edited by someone else. -err_noview = You have not enough permissions to view this file. -err_nocopy = You have not enough permissions to copy this file. -err_dircopy = This editor is not able to copy directories. -err_cmd_unknown = Unknown command: {COMMAND} -err_lock_failed = Locking of '{USELIST}' failed. Try it again in a moment. If the problem persists, ask someone to recreate the lock file ('{LOCK_FILE}'). -err_not_exist = File/directory does not exist. -err_dir_not_exist = The directory where you want to create this file or directory doesn't exist. +error_file = D:/WWW/cgi-bin/devedit/errors.dat +template_file = D:/WWW/cgi-bin/devedit/templates.dat # End of configuration file \ No newline at end of file diff --git a/devedit.pl b/devedit.pl index 543d220..ef2e7b5 100644 --- a/devedit.pl +++ b/devedit.pl @@ -6,7 +6,7 @@ # Dev-Editor's main program # # Author: Patrick Canterino -# Last modified: 2004-03-06 +# Last modified: 2004-04-25 # use strict; @@ -30,7 +30,7 @@ use constant CONFIGFILE => 'devedit.dat'; # Read the configuration file my $config = read_config(CONFIGFILE); -error_template($config->{'tpl_error'}); # Yes, I'm lazy... +error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy... # Read the most important form data @@ -61,14 +61,14 @@ if($newfile ne '') unless(-d clean_path($config->{'fileroot'}."/".$dir)) { - abort($config->{'err_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->{'err_create_ar'}); + abort($config->{'errors'}->{'create_ar'}); } # Create the physical and the virtual path @@ -89,7 +89,7 @@ if(-e clean_path($config->{'fileroot'}."/".$file)) lockfile => $config->{'lock_file'}, timeout => $config->{'lock_timeout'}); - $uselist->lock or abort($config->{'err_lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}}); + $uselist->lock or abort($config->{'errors'}->{'lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}}); $uselist->load; # Create a hash with data submitted by user @@ -111,12 +111,12 @@ if(-e clean_path($config->{'fileroot'}."/".$file)) } else { - abort($config->{'err_above_root'}); + abort($config->{'errors'}->{'above_root'}); } } else { - abort($config->{'err_not_exist'}); + abort($config->{'errors'}->{'not_exist'}); } # diff --git a/errors.dat b/errors.dat new file mode 100644 index 0000000..7a66dee --- /dev/null +++ b/errors.dat @@ -0,0 +1,27 @@ +# This file contains the error messages of Dev-Editor + +binary = This editor is not able to view/edit binary files. +editdir = You cannot edit directories. +noedit = You have not enough permissions to edit this file. +file_in_use = The file '{FILE}' is currently edited by someone else. +edit_failed = Saving of file '{FILE}' failed. The file could be damaged, please check its integrity. +delete_failed = Could not delete file '{FILE}'. +dir_read_fail = Reading of directory '{DIR}' failed. +mkfile_failed = Could not create file '{FILE}'. +mkdir_failed = Could not create directory '{DIR}'. +copy_failed = Could not copy '{FILE}' to '{NEW_FILE}'. +rename_failed = Could not move/rename '{FILE}' to '{NEW_FILE}'. +above_root = Accessing files and directories above the virtual root directory is forbidden. +create_ar = You aren't allowed to create files and directories above the virtual root directory. +file_exists = A file or directory called '{FILE}' already exists. +exist_edited = The target file '{FILE}' already exists and is edited by someone else. +in_use = The file '{FILE}' is currently edited by someone else. +noview = You have not enough permissions to view this file. +nocopy = You have not enough permissions to copy this file. +dircopy = This editor is not able to copy directories. +cmd_unknown = Unknown command: {COMMAND} +lock_failed = Locking of '{USELIST}' failed. Try it again in a moment. If the problem persists, ask someone to recreate the lock file ('{LOCK_FILE}'). +not_exist = File/directory does not exist. +dir_not_exist = The directory where you want to create this file or directory doesn't exist. + +# End of configuration file \ No newline at end of file diff --git a/modules/Command.pm b/modules/Command.pm index e2a0063..e0bcb7c 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-03-15 +# Last modified: 2004-04-25 # use strict; @@ -61,7 +61,7 @@ sub exec_command($$$) { my ($command,$data,$config) = @_; - return error($config->{'err_cmd_unknown'},'/',{COMMAND => $command}) unless($dispatch{$command}); + return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => $command}) unless($dispatch{$command}); my $output = &{$dispatch{$command}}($data,$config); return $output; @@ -104,7 +104,7 @@ sub exec_show($$) my @stat = stat($physical."/.."); my $udtpl = new Template; - $udtpl->read_file($config->{'tpl_dirlist_up'}); + $udtpl->read_file($config->{'templates'}->{'dirlist_up'}); $udtpl->fillin("UPPER_DIR",encode_entities(upper_path($virtual))); $udtpl->fillin("DATE",strftime($config->{'timeformat'},localtime($stat[9]))); @@ -120,7 +120,7 @@ sub exec_show($$) my $virt_path = encode_entities($virtual.$dir."/"); my $dtpl = new Template; - $dtpl->read_file($config->{'tpl_dirlist_dir'}); + $dtpl->read_file($config->{'templates'}->{'dirlist_dir'}); $dtpl->fillin("DIR",$virt_path); $dtpl->fillin("DIR_NAME",$dir); @@ -141,7 +141,7 @@ sub exec_show($$) my $in_use = $data->{'uselist'}->in_use($virtual.$file); my $ftpl = new Template; - $ftpl->read_file($config->{'tpl_dirlist_file'}); + $ftpl->read_file($config->{'templates'}->{'dirlist_file'}); $ftpl->fillin("FILE",$virt_path); $ftpl->fillin("FILE_NAME",$file); @@ -162,7 +162,7 @@ sub exec_show($$) $dirlist .= $ftpl->get_template; } - $tpl->read_file($config->{'tpl_dirlist'}); + $tpl->read_file($config->{'templates'}->{'dirlist'}); $tpl->fillin("DIRLIST",$dirlist); $tpl->fillin("DIR",$virtual); @@ -173,7 +173,7 @@ sub exec_show($$) { # View a file - return error($config->{'err_noview'},upper_path($virtual)) unless(-r $physical); + return error($config->{'errors'}->{'noview'},upper_path($virtual)) unless(-r $physical); # Check on binary files # We have to do it in this way, or empty files @@ -183,7 +183,7 @@ sub exec_show($$) { # Binary file - return error($config->{'err_binary'},upper_path($virtual)); + return error($config->{'errors'}->{'binary'},upper_path($virtual)); } else { @@ -192,7 +192,7 @@ sub exec_show($$) my $content = file_read($physical); $$content =~ s/\015\012|\012|\015/\n/g; - $tpl->read_file($config->{'tpl_viewfile'}); + $tpl->read_file($config->{'templates'}->{'viewfile'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -224,9 +224,9 @@ sub exec_beginedit($$) my $virtual = $data->{'virtual'}; my $uselist = $data->{'uselist'}; - return error($config->{'err_editdir'},upper_path($virtual)) if(-d $physical); - return error($config->{'err_in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual)); - return error($config->{'err_noedit'},upper_path($virtual)) unless(-r $physical && -w $physical); + return error($config->{'errors'}->{'editdir'},upper_path($virtual)) if(-d $physical); + return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual)); + return error($config->{'errors'}->{'noedit'},upper_path($virtual)) unless(-r $physical && -w $physical); # Check on binary files @@ -234,7 +234,7 @@ sub exec_beginedit($$) { # Binary file - return error($config->{'err_binary'},upper_path($virtual)); + return error($config->{'errors'}->{'binary'},upper_path($virtual)); } else { @@ -247,7 +247,7 @@ sub exec_beginedit($$) $$content =~ s/\015\012|\012|\015/\n/g; my $tpl = new Template; - $tpl->read_file($config->{'tpl_editfile'}); + $tpl->read_file($config->{'templates'}->{'editfile'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -317,11 +317,11 @@ sub exec_endedit($$) # Check if someone else is editing the new file - return error($config->{'err_in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual)); + return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual)); } - return error($config->{'err_editdir'},upper_path($virtual)) if(-d $physical); - return error($config->{'err_noedit'}, upper_path($virtual)) unless(-r $physical && -w $physical); + return error($config->{'errors'}->{'editdir'},upper_path($virtual)) if(-d $physical); + return error($config->{'errors'}->{'noedit'}, upper_path($virtual)) unless(-r $physical && -w $physical); if(file_save($physical,\$content)) { @@ -336,7 +336,7 @@ sub exec_endedit($$) } else { - return error($config->{'err_edit_failed'},upper_path($virtual),{FILE => $virtual}); + return error($config->{'errors'}->{'edit_failed'},upper_path($virtual),{FILE => $virtual}); } } @@ -357,9 +357,9 @@ sub exec_mkfile($$) my $dir = upper_path($new_virtual); $new_virtual = encode_entities($new_virtual); - return error($config->{'err_file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); + return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); - file_create($new_physical) or return error($config->{'err_mkfile_failed'},$dir,{FILE => $new_virtual}); + file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual}); return devedit_reload({command => 'show', file => $dir}); } @@ -380,9 +380,9 @@ sub exec_mkdir($$) my $dir = upper_path($new_virtual); $new_virtual = encode_entities($new_virtual); - return error($config->{'err_file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); + return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); - mkdir($new_physical,0777) or return error($config->{'err_mkdir_failed'},$dir,{DIR => $new_virtual}); + mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual}); return devedit_reload({command => 'show', file => $dir}); } @@ -410,14 +410,14 @@ sub exec_upload($$) my $file_phys = $physical."/".$filename; my $file_virt = $virtual."".$filename; - return error($config->{'err_file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys); + return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys); my $ascii = $cgi->param('ascii'); my $handle = $cgi->upload('uploaded_file'); local *FILE; - open(FILE,">$file_phys") or return error($config->{'err_mkfile_failed'},$virtual,{FILE => $file_virt}); + open(FILE,">$file_phys") or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt}); binmode(FILE) unless($ascii); my $data; @@ -435,7 +435,7 @@ sub exec_upload($$) else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_upload'}); + $tpl->read_file($config->{'templates'}->{'upload'}); $tpl->fillin("DIR",$virtual); $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); @@ -464,7 +464,7 @@ sub exec_copy($$) my $virtual = encode_entities($data->{'virtual'}); my $new_physical = $data->{'new_physical'}; - return error($config->{'err_nocopy'}) unless(-r $physical); + return error($config->{'errors'}->{'nocopy'}) unless(-r $physical); if($new_physical) { @@ -474,16 +474,16 @@ sub exec_copy($$) if(-e $new_physical) { - return error($config->{'err_exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); if(-d $new_physical) { - return error($config->{'err_dircopy'}); + return error($config->{'errors'}->{'dircopy'}); } elsif(not $data->{'cgi'}->param('confirmed')) { my $tpl = new Template; - $tpl->read_file($config->{'tpl_confirm_replace'}); + $tpl->read_file($config->{'templates'}->{'confirm_replace'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("NEW_FILE",$new_virtual); @@ -502,13 +502,13 @@ sub exec_copy($$) } } - copy($physical,$new_physical) or return error($config->{'err_copy_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual}); + copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual}); return devedit_reload({command => 'show', file => $dir}); } else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_copyfile'}); + $tpl->read_file($config->{'templates'}->{'copyfile'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -538,7 +538,7 @@ sub exec_rename($$) my $virtual = $data->{'virtual'}; my $new_physical = $data->{'new_physical'}; - return error($config->{'err_in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); + return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); if($new_physical) { @@ -548,16 +548,16 @@ sub exec_rename($$) if(-e $new_physical) { - return error($config->{'err_exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); if(-d $new_physical) { - return error($config->{'err_dircopy'}); + return error($config->{'errors'}->{'dircopy'}); } elsif(not $data->{'cgi'}->param('confirmed')) { my $tpl = new Template; - $tpl->read_file($config->{'tpl_confirm_replace'}); + $tpl->read_file($config->{'templates'}->{'confirm_replace'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("NEW_FILE",$new_virtual); @@ -576,13 +576,13 @@ sub exec_rename($$) } } - rename($physical,$new_physical) or return error($config->{'err_rename_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual}); + rename($physical,$new_physical) or return error($config->{'errors'}->{'rename_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual}); return devedit_reload({command => 'show', file => $dir}); } else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_renamefile'}); + $tpl->read_file($config->{'templates'}->{'renamefile'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -623,7 +623,7 @@ sub exec_remove($$) else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_confirm_rmdir'}); + $tpl->read_file($config->{'templates'}->{'confirm_rmdir'}); $tpl->fillin("DIR",$virtual); $tpl->fillin("UPPER_DIR",upper_path($virtual)); @@ -640,17 +640,17 @@ sub exec_remove($$) { # Remove a file - return error($config->{'err_in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); + return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); if($data->{'cgi'}->param('confirmed')) { - unlink($physical) or return error($config->{'err_delete_failed'},upper_path($virtual),{FILE => $virtual}); + unlink($physical) or return error($config->{'errors'}->{'delete_failed'},upper_path($virtual),{FILE => $virtual}); return devedit_reload({command => 'show', file => upper_path($virtual)}); } else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_confirm_rmfile'}); + $tpl->read_file($config->{'templates'}->{'confirm_rmfile'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -688,7 +688,7 @@ sub exec_unlock($$) else { my $tpl = new Template; - $tpl->read_file($config->{'tpl_confirm_unlock'}); + $tpl->read_file($config->{'templates'}->{'confirm_unlock'}); $tpl->fillin("FILE",$virtual); $tpl->fillin("DIR",upper_path($virtual)); @@ -716,7 +716,7 @@ sub exec_about($$) my ($data,$config) = @_; my $tpl = new Template; - $tpl->read_file($config->{'tpl_about'}); + $tpl->read_file($config->{'templates'}->{'about'}); $tpl->fillin("SCRIPT",$script); diff --git a/modules/Config/DevEdit.pm b/modules/Config/DevEdit.pm index 8adfd35..e423819 100644 --- a/modules/Config/DevEdit.pm +++ b/modules/Config/DevEdit.pm @@ -3,10 +3,10 @@ package Config::DevEdit; # # Dev-Editor - Module Config::DevEdit # -# Parse the configuration file +# Read and parse the configuration files # # Author: Patrick Canterino -# Last modified: 2004-01-16 +# Last modified: 2004-04-25 # use strict; @@ -22,13 +22,33 @@ use base qw(Exporter); # read_config() # -# Parse the configuration file +# Read the configuration files of Dev-Editor # # Params: Path to configuration file # # Return: Configuration (Hash Reference) sub read_config($) +{ + my $file = shift; + + my $config = parse_config($file); + + $config->{'errors'} = parse_config($config->{'error_file'}); + $config->{'templates'} = parse_config($config->{'template_file'}); + + return $config; +} + +# parse_config() +# +# Parse an INI-style configuration file +# +# Params: Path to configuration file +# +# Return: Configuration (Hash Reference) + +sub parse_config($) { my $file = shift; local *CF; diff --git a/templates.dat b/templates.dat new file mode 100644 index 0000000..6f065b8 --- /dev/null +++ b/templates.dat @@ -0,0 +1,22 @@ +# This file contains the paths to the template files +# used by Dev-Editor + +dirlist = templates/dirlist.htm +viewfile = templates/viewfile.htm +editfile = templates/editfile.htm +copyfile = templates/copyfile.htm +renamefile = templates/renamefile.htm +mkfile = templates/mkfile.htm +mkdir = templates/mkdir.htm +upload = templates/upload.htm +confirm_rmfile = templates/confirm_rmfile.htm +confirm_rmdir = templates/confirm_rmdir.htm +confirm_unlock = templates/confirm_unlock.htm +confirm_replace = templates/confirm_replace.htm +dirlist_file = templates/dirlist_file.htm +dirlist_dir = templates/dirlist_dir.htm +dirlist_up = templates/dirlist_up.htm +error = templates/error.htm +about = templates/about.htm + +# End of configuration file \ No newline at end of file