]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 09-22-2003
25 use POSIX
qw(strftime) ;
28 $script = $ENV { 'SCRIPT_NAME' };
32 use base
qw(Exporter) ;
34 @EXPORT = qw(exec_show
47 # View a directory or a file
49 # Params: 1. Reference to user input hash
50 # 2. Reference to config hash
52 # Return: Output of the command (Scalar Reference)
56 my ( $data , $config ) = @_ ;
57 my $physical = $data ->{ 'physical' };
58 my $virtual = $data ->{ 'virtual' };
63 # Create directory listing
65 my $direntries = dir_read
( $physical );
66 return error
( "Reading of directory $virtual failed" ) unless ( $direntries );
68 my $files = $direntries ->{ 'files' };
69 my $dirs = $direntries ->{ 'dirs' };
71 $output .= htmlhead
( "Directory listing of $virtual " );
72 $output .= equal_url
( $config ->{ 'httproot' }, $virtual );
73 $output .= "<hr> \n\n <pre> \n " ;
75 # Create the link to the upper directory
76 # (only if we are not in the root directory)
78 unless ( $virtual eq "/" )
80 my $upper = $physical . "/.." ;
81 my @stat = stat ( $upper );
83 $output .= " [SUBDIR] " ;
84 $output .= strftime
( " %d . %m . %Y %H : %M " , localtime ( $stat [ 9 ]));
86 $output .= "<a href= \" $script ?command=show&file=" . upper_path
( $virtual ). " \" >../</a> \n " ;
89 # Get the longest file/directory name
93 foreach ( @
$dirs , @
$files )
95 my $length = length ( $_ );
96 $max_name_len = $length if ( $length > $max_name_len );
101 foreach my $dir ( @
$dirs )
103 my @stat = stat ( $physical . "/" . $dir );
106 $output .= "[SUBDIR] " ;
107 $output .= strftime
( " %d . %m . %Y %H : %M " , localtime ( $stat [ 9 ]));
109 $output .= "<a href= \" $script ?command=show&file= $virtual $dir / \" >" . encode_entities
( $dir ). "/</a> \n " ;
114 foreach my $file ( @
$files )
116 my @stat = stat ( $physical . "/" . $file );
117 my $virt_path = $virtual . $file ;
118 my $in_use = $data ->{ 'uselist' }-> in_use ( $virtual . $file );
120 $output .= " " x
( 10 - length ( $stat [ 7 ]));
123 $output .= strftime
( " %d . %m . %Y %H : %M " , localtime ( $stat [ 9 ]));
124 $output .= ( $in_use ) ?
" (IN USE) " : " " x
10 ;
125 $output .= encode_entities
( $file );
126 $output .= " " x
( $max_name_len - length ( $file )). " \t (" ;
127 $output .= "<a href= \" $script ?command=show&file= $virt_path \" >View</a> | " ;
130 ?
'<span style="color:#C0C0C0">Edit</span>'
131 : "<a href= \" $script ?command=beginedit&file= $virt_path \" >Edit</a>" ;
133 $output .= " | <a href= \" $script ?command=workwithfile&file= $virt_path \" >Do other stuff</a>) \n " ;
136 $output .= "</pre> \n\n <hr> \n\n " ;
140 <td>Create new directory:</td>
141 <td> $virtual <input type="text" name="newdirname"> <input type="submit" value="Create!"></td>
144 <td>Create new file:</td>
145 <td> $virtual <input type="text" name="newfilename"> <input type="submit" value="Create!"></td>
157 # Check on binary files
163 return error
( "This editor is not able to view/edit binary files." );
169 $output = htmlhead
( "Contents of file $virtual " );
170 $output .= equal_url
( $config ->{ 'httproot' }, $virtual );
171 $output .= dir_link
( $virtual );
173 $output .= '<div style="background-color:#FFFFE0;border:1px solid black;margin-top:10px;width:100%">' . " \n " ;
174 $output .= '<pre style="color:#0000C0;">' . " \n " ;
175 $output .= encode_entities
(${ file_read
( $physical )});
176 $output .= " \n </pre> \n </div>" ;
187 # Lock a file and display a form to edit it
189 # Params: 1. Reference to user input hash
190 # 2. Reference to config hash
192 # Return: Output of the command (Scalar Reference)
194 sub exec_beginedit
($$)
196 my ( $data , $config ) = @_ ;
197 my $physical = $data ->{ 'physical' };
198 my $virtual = $data ->{ 'virtual' };
199 my $uselist = $data ->{ 'uselist' };
201 return error
( "You cannot edit directories." ) if (- d
$physical );
202 return error_in_use
( $virtual ) if ( $uselist -> in_use ( $virtual ));
204 # Check on binary files
210 return error
( "This editor is not able to view/edit binary files." );
216 $uselist -> add_file ( $virtual );
219 my $dir = upper_path
( $virtual );
220 my $content = encode_entities
(${ file_read
( $physical )});
222 my $output = htmlhead
( "Edit file $virtual " );
223 $output .= equal_url
( $config ->{ 'httproot' }, $virtual );
225 <p><b style="color:#FF0000">Caution!</b> This file is locked for other users while you are editing it. To unlock it, click <i>Save and exit</i> or <i>Exit WITHOUT saving</i>. Please <b>don't</b> click the <i>Reload</i> button in your browser! This will confuse the editor.</p>
227 <form action=" $ENV {'SCRIPT_NAME'}" method="get">
228 <input type="hidden" name="command" value="canceledit">
229 <input type="hidden" name="file" value=" $virtual ">
230 <p><input type="submit" value="Exit WITHOUT saving"></p>
233 <form action=" $ENV {'SCRIPT_NAME'}" method="post">
234 <input type="hidden" name="command" value="endedit">
235 <input type="hidden" name="file" value=" $virtual ">
237 <table width="100%" border="1">
239 <td width="50%" align="center"><input type="checkbox" name="save_as_new_file" value="1"> Save as new file: $dir <input type=text name="new_filename" value=""></td>
240 <td width="50%" align="center"><input type="checkbox" name="encode_iso" value="1"> Encode ISO-8859-1 special chars</td>
243 <td align="center"><input type="reset" value="Reset form"></td>
244 <td align="center"><input type="submit" value="Save and exit"></td>
248 <textarea name="filecontent" rows="25" cols="120"> $content </textarea>
260 # Save a file, unlock it and return to directory view
262 # Params: 1. Reference to user input hash
263 # 2. Reference to config hash
265 # Return: Output of the command (Scalar Reference)
269 my ( $data , $config ) = @_ ;
270 my $physical = $data ->{ 'physical' };
271 my $virtual = $data ->{ 'virtual' };
272 my $content = $data ->{ 'cgi' }-> param ( 'filecontent' );
274 return error
( "You cannot edit directories." ) if (- d
$physical );
276 if ( $data ->{ 'cgi' }-> param ( 'encode_iso' ))
278 # Encode all ISO-8859-1 special chars
280 $content = encode_entities
( $content , " \200 - \377 " );
283 if ( file_save
( $physical , \
$content ))
285 # Saving of the file was successfull - so unlock it!
287 return exec_unlock
( $data , $config );
291 return error
( "Saving of file ' $virtual ' failed'" );
297 # Create a file and return to directory view
299 # Params: 1. Reference to user input hash
300 # 2. Reference to config hash
302 # Return: Output of the command (Scalar Reference)
311 # Create a directory and return to directory view
313 # Params: 1. Reference to user input hash
314 # 2. Reference to config hash
316 # Return: Output of the command (Scalar Reference)
323 # exec_workwithfile()
325 # Display a form for renaming/copying/deleting/unlocking a file
327 # Params: 1. Reference to user input hash
328 # 2. Reference to config hash
330 # Return: Output of the command (Scalar Reference)
332 sub exec_workwithfile
($$)
334 my ( $data , $config ) = @_ ;
335 my $physical = $data ->{ 'physical' };
336 my $virtual = $data ->{ 'virtual' };
337 my $unused = $data ->{ 'uselist' }-> unused ( $virtual );
339 my $output = htmlhead
( "Work with file $virtual " );
340 $output .= equal_url
( $config ->{ 'httproot' }, $virtual );
341 $output .= dir_link
( $virtual );
342 $output .= "<p><b>Note:</b> On UNIX systems, filenames are <b>case-sensitive</b>!</p> \n\n " ;
344 $output .= "<p>Someone else is currently editing this file. So not all features are available.</p> \n\n " unless ( $unused );
351 <p>Copy file ' $virtual ' to: <input type="text" name="newfilename" size="50"> <input type="submit" value="Copy!"></p>
362 <p>Move/Rename file ' $virtual ' to: <input type="text" name="newfilename" size="50"> <input type="submit" value="Move/Rename!"></p>
368 <form action=" $script " method="get">
369 <input type="hidden" name="file" value=" $virtual ">
370 <input type="hidden" name="command" value="remove">
371 <p><input type="submit" value="Delete file ' $virtual '!"></p>
380 <p>Someone else is currently editing this file. At least, the file is marked so. Maybe, someone who was editing the file, has forgotten to unlock it. In this case (and <b>only</b> in this case) you can unlock the file using this button:</p>
382 <form action=" $script " method="get">
383 <input type="hidden" name="file" value=" $virtual ">
384 <input type="hidden" name="command" value="unlock">
385 <p><input type="submit" value="Unlock file ' $virtual '"></p>
398 # Copy a file and return to directory view
400 # Params: 1. Reference to user input hash
401 # 2. Reference to config hash
403 # Return: Output of the command (Scalar Reference)
412 # Rename/move a file and return to directory view
414 # Params: 1. Reference to user input hash
415 # 2. Reference to config hash
417 # Return: Output of the command (Scalar Reference)
426 # Remove a file and return to directory view
428 # Params: 1. Reference to user input hash
429 # 2. Reference to config hash
431 # Return: Output of the command (Scalar Reference)
435 my ( $data , $config ) = @_ ;
436 my $physical = $data ->{ 'physical' };
437 my $virtual = $data ->{ 'virtual' };
439 return error_in_use
( $virtual ) if ( $data ->{ 'uselist' }-> in_use ( $virtual ));
441 my $dir = upper_path
( $virtual );
445 my $output = redirect
( "http:// $ENV {'HTTP_HOST'} $script ?command=show&file= $dir " );
451 # Remove a file from the list of used files and
452 # return to directory view
454 # Params: 1. Reference to user input hash
455 # 2. Reference to config hash
457 # Return: Output of the command (Scalar Reference)
461 my ( $data , $config ) = @_ ;
462 my $physical = $data ->{ 'physical' };
463 my $virtual = $data ->{ 'virtual' };
464 my $uselist = $data ->{ 'uselist' };
466 my $dir = upper_path
( $virtual );
468 $uselist -> remove_file ( $virtual );
471 my $output = redirect
( "http:// $ENV {'HTTP_HOST'} $script ?command=show&file= $dir " );
475 # it's true, baby ;-)
patrick-canterino.de