From: pcanterino <> Date: Tue, 29 Dec 2009 12:52:03 +0000 (+0000) Subject: Allow to execute a HTTP download of a file X-Git-Tag: version_3_2~27 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/4fa9e31f2057e1c99651b8da1c59e278890d4f40?ds=inline Allow to execute a HTTP download of a file --- diff --git a/errors.conf b/errors.conf index 5357936..244501f 100644 --- a/errors.conf +++ b/errors.conf @@ -33,6 +33,7 @@ no_copy = You have not enough permissions to copy this file. no_delete = You have not enough permissions to delete this file. no_dir_access = You have not enough permissions to access this directory. no_directory = '{FILE}' is not a directory. +no_download = You are not allowed to download '{FILE}'. no_edit = You have not enough permissions to edit this file. no_rename = You have not enough permissions to move/rename this file. no_root_access = You have not enough permissions to access the root directory. diff --git a/modules/Command.pm b/modules/Command.pm index cc996ca..8fcf6d6 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-05-11 +# Last modified: 2009-12-29 # # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann # Copyright (C) 2003-2009 Patrick Canterino @@ -42,6 +42,7 @@ my $users = eval('getpwuid(0)') && eval('getgrgid(0)'); my %dispatch = ('show' => \&exec_show, 'beginedit' => \&exec_beginedit, 'endedit' => \&exec_endedit, + 'download' => \&exec_download, 'mkdir' => \&exec_mkdir, 'mkfile' => \&exec_mkfile, 'upload' => \&exec_upload, @@ -444,6 +445,32 @@ sub exec_endedit($$) return devedit_reload({command => 'beginedit', file => $virtual}); } +# exec_download() +# +# Execute a HTTP download of a file +# +# Params: 1. Reference to user input hash +# 2. Reference to config hash +# +# Return: Output of the command (Scalar Reference) + +sub exec_download($$) +{ + my ($data,$config) = @_; + my $physical = $data->{'physical'}; + my $virtual = $data->{'virtual'}; + my $dir = upper_path($virtual); + + return return error($config->{'errors'}->{'no_download'},$dir,{FILE => $virtual}) if(-d $physical || -l $physical); + + my $filename = file_name($virtual); + + my $output = header(-type => 'application/octet-stream', -attachment => $filename); + $output .= ${ file_read($physical,1) }; + + return \$output; +} + # exec_mkfile() # # Create a file and return to directory view diff --git a/templates/dirlist_file.htm b/templates/dirlist_file.htm index fd342fe..5b9b734 100644 --- a/templates/dirlist_file.htm +++ b/templates/dirlist_file.htm @@ -3,5 +3,5 @@ {SIZE} {DATE}{IF gmt} (GMT){ENDIF} {IF forbidden}{FILE_NAME}{ELSE}{FILE_NAME}{ENDIF} -({IF !forbidden}{IF viewable}View{ELSE}View{ENDIF} | {IF editable}Edit{ELSE}Edit{ENDIF}{IF !link}{IF readable} | Copy{ENDIF}{ENDIF}{IF dir_writeable} | Rename | Delete{ENDIF} |{IF !link}{IF users} Chmod/Chgrp |{ENDIF}{ENDIF} {ENDIF}View in Browser) +({IF !forbidden}{IF viewable}View{ELSE}View{ENDIF} | {IF editable}Edit{ELSE}Edit{ENDIF}{IF !link}{IF readable}| Download | Copy{ENDIF}{ENDIF}{IF dir_writeable} | Rename | Delete{ENDIF} |{IF !link}{IF users} Chmod/Chgrp |{ENDIF}{ENDIF} {ENDIF}View in Browser) diff --git a/templates/viewfile.htm b/templates/viewfile.htm index 4aaf594..7303f1f 100644 --- a/templates/viewfile.htm +++ b/templates/viewfile.htm @@ -20,7 +20,10 @@ -{IF editable}

Edit this file

{ELSE}
{ENDIF} +