]> git.p6c8.net - devedit.git/commitdiff
Added rudimentary support for unpacking archive files using Archive::Extract.
authorpcanterino <>
Mon, 27 Dec 2010 21:08:50 +0000 (21:08 +0000)
committerpcanterino <>
Mon, 27 Dec 2010 21:08:50 +0000 (21:08 +0000)
It works but needs a lot of fine tuning.

modules/Command.pm
modules/File/Access.pm
modules/Tool.pm
templates.conf
templates/dirlist_file.htm
templates/unpack.htm [new file with mode: 0644]

index 5d0e653e3fb22b1aff97f9027c035ff1ea10bffd..0880c8c62823f7e51491d788d69f17a4d71fc692 100644 (file)
@@ -46,6 +46,7 @@ my %dispatch = ('show'         => \&exec_show,
                 'mkdir'        => \&exec_mkdir,
                 'mkfile'       => \&exec_mkfile,
                 'upload'       => \&exec_upload,
+                'unpack'       => \&exec_unpack,
                 'copy'         => \&exec_copy,
                 'rename'       => \&exec_rename,
                 'remove'       => \&exec_remove,
@@ -212,6 +213,8 @@ sub exec_show($$)
 
    $ftpl->parse_if_block('users',$users && -o $phys_path);
 
+   $ftpl->parse_if_block('archive',$File::Access::has_archive_extract && is_archive($file));
+
    $ftpl->parse_if_block('even',($count % 2) == 0);
 
    $dirlist .= $ftpl->get_template;
@@ -493,7 +496,7 @@ sub exec_mkfile($$)
   return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
 
   file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual});
-  
+
   if($data->{'cgi'}->param('edit'))
   {
    return devedit_reload({command => 'beginedit', file => $new_virtual});
@@ -630,6 +633,48 @@ sub exec_upload($$)
  }
 }
 
+# exec_unpack()
+#
+# Unpack an archive
+#
+# Params: 1. Reference to user input hash
+#         2. Reference to config hash
+#
+# Return: Output of the command (Scalar Reference)
+
+sub exec_unpack($$)
+{
+ my ($data,$config) = @_;
+ my $physical       = $data->{'physical'};
+ my $virtual        = $data->{'virtual'};
+ my $dir            = upper_path($virtual);
+ my $new_physical   = $data->{'new_physical'};
+ my $new_virtual    = $data->{'new_virtual'};
+ my $cgi            = $data->{'cgi'};
+
+ if($new_physical)
+ {
+  archive_unpack($physical,$new_physical);
+  return devedit_reload({command => 'show', file => $new_virtual});
+ }
+ else
+ {
+  my $tpl = new Template;
+  $tpl->read_file($config->{'templates'}->{'unpack'});
+
+  $tpl->fillin('FILE',encode_html($virtual));
+  $tpl->fillin('DIR',encode_html($dir));
+  $tpl->fillin('DIR_URL',escape($dir));
+  $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual)));
+  $tpl->fillin('SCRIPT',$script);
+
+  my $output = header(-type => 'text/html');
+  $output   .= $tpl->get_template;
+
+  return \$output;
+ }
+}
+
 # exec_copy()
 #
 # Copy a file and return to directory view
index a96dd093c3b453c33f0ae66efe01ffdb47479dbc..5e5cca10f8e143e08de9c920ed3b12b4d1a0dda8 100644 (file)
@@ -7,7 +7,7 @@ package File::Access;
 # using only one command
 #
 # Author:        Patrick Canterino <patrick@patshaping.de>
-# Last modified: 2005-08-01
+# Last modified: 2010-12-27
 #
 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
 # Copyright (C) 2003-2009 Patrick Canterino
@@ -21,7 +21,8 @@ package File::Access;
 use strict;
 
 use vars qw(@EXPORT
-            $has_flock);
+            $has_flock
+            $has_archive_extract);
 
 use Fcntl qw(:DEFAULT
              :flock);
@@ -32,7 +33,8 @@ use File::Copy;
 
 use base qw(Exporter);
 
-@EXPORT = qw(dir_copy
+@EXPORT = qw(archive_unpack
+             dir_copy
              dir_read
              file_create
              file_lock
@@ -49,10 +51,47 @@ use base qw(Exporter);
 
 $has_flock = eval { local $SIG{'__DIE__'}; flock(STDOUT,0); 1 };
 
+# Check if Archive::Extract is available
+
+$has_archive_extract = eval { local $SIG{'__DIE__'}; require Archive::Extract; 1 };
+
 # Predeclaration of dir_copy()
 
 sub dir_copy($$);
 
+# archive_unpack()
+#
+# Unpack an archive
+# (archive type must be supported by Archive::Extract)
+#
+# Params: 1. Archive path
+#         2. Path to extract (optional)
+#
+# Return: - Status code (Boolean)
+#         - undef if Archive::Extract is not available
+
+sub archive_unpack($;$)
+{
+ my ($archive,$path) = @_;
+
+ return undef unless($has_archive_extract);
+
+ return unless(-f $archive);
+ return if($path && not -d $path);
+
+ my $ae = Archive::Extract->new(archive => $archive);
+ return unless($ae);
+
+ if($path)
+ {
+  return $ae->extract(to => $path);
+ }
+ else
+ {
+  return $ae->extract;
+ }
+}
+
 # dir_copy()
 #
 # Copy a directory
index e810c8b70a94454937060b00b246dfb7be058bd3..4dc6fa29e50d7b9aea731cb7d8a00d0f63d1ef5d 100644 (file)
@@ -40,12 +40,15 @@ use base qw(Exporter);
              encode_html
              equal_url
              file_name
+             is_archive
              in_array
              is_disabled_command
              is_forbidden_file
              mode_string
              multi_string
              upper_path);
+             
+my @archive_exts = ('.zip', 'tar.gz', 'tar.bz2');
 
 # check_path()
 #
@@ -290,6 +293,27 @@ sub in_array($$)
  return;
 }
 
+# is_archive()
+#
+# Check if a file is an archive
+# (currently only by file extension)
+#
+# Params: Archive file name
+#
+# Return: Status code (Boolean)
+
+sub is_archive($)
+{
+ my $file = shift;
+ foreach my $ext(@archive_exts)
+ {
+  return 1 if(lc(substr($file,length($file)-length($ext),length($ext))) eq lc($ext));
+ }
+ return;
+}
+
 # is_disabled_command()
 #
 # Check if a command is disabled
index c2874668f7343e57eddb7206b8a56e19d2380442..e6e197a052e8ba66f85d93517f9b7e7a81b2144b 100644 (file)
@@ -19,6 +19,7 @@ mkdir           = templates/mkdir.htm
 mkfile          = templates/mkfile.htm
 renamefile      = templates/renamefile.htm
 rmmulti         = templates/rmmulti.htm
+unpack          = templates/unpack.htm
 upload          = templates/upload.htm
 viewfile        = templates/viewfile.htm
 viewlink        = templates/viewlink.htm
index 4f6192a469a89a17496c5cb55680a23026df27a6..8fbbf104aed08e3b4d6cee91d310de53f57b993a 100644 (file)
@@ -3,5 +3,5 @@
 <td align="right" style="white-space:nowrap">{SIZE}</td>
 <td style="padding-left:15pt;white-space:nowrap;">{DATE}{IF gmt} (GMT){ENDIF}</td>
 <td style="padding-left:15pt;white-space:nowrap;">{IF forbidden}<span title="File access forbidden by Dev-Editor's configuration">{FILE_NAME}</span>{ELSE}{FILE_NAME}{ENDIF}</td>
-<td style="padding-left:15pt;white-space:nowrap;">({IF !forbidden}{IF viewable}<a href="{SCRIPT}?command=show&amp;file={FILE_URL}">View</a>{ELSE}<span title="{IF !readable}Not readable{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}">View</span>{ENDIF} | {IF editable}<a href="{SCRIPT}?command=beginedit&amp;file={FILE_URL}">Edit</a>{ELSE}<span title="{IF link}Symbolic link{ELSE}{IF !readable}Not readable{ELSE}{IF !writeable}Read only{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}{ENDIF}{ENDIF}">Edit</span>{ENDIF}{IF !link}{IF readable}| <a href="{SCRIPT}?command=download&file={FILE_URL}">Download</a> | <a href="{SCRIPT}?command=copy&amp;file={FILE_URL}">Copy</a>{ENDIF}{ENDIF}{IF dir_writeable} | <a href="{SCRIPT}?command=rename&amp;file={FILE_URL}">Rename</a> | <a href="{SCRIPT}?command=remove&amp;file={FILE_URL}">Delete</a>{ENDIF} |{IF !link}{IF users} <a href="{SCRIPT}?command=chprop&amp;file={FILE_URL}">Chmod/Chgrp</a> |{ENDIF}{ENDIF} {ENDIF}<a href="{URL}" target="_blank">View in Browser</a>)</td>
+<td style="padding-left:15pt;white-space:nowrap;">({IF !forbidden}{IF viewable}<a href="{SCRIPT}?command=show&amp;file={FILE_URL}">View</a>{ELSE}<span title="{IF !readable}Not readable{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}">View</span>{ENDIF} | {IF editable}<a href="{SCRIPT}?command=beginedit&amp;file={FILE_URL}">Edit</a>{ELSE}<span title="{IF link}Symbolic link{ELSE}{IF !readable}Not readable{ELSE}{IF !writeable}Read only{ELSE}{IF binary}Binary file{ELSE}{IF too_large}File too large{ENDIF}{ENDIF}{ENDIF}{ENDIF}{ENDIF}">Edit</span>{ENDIF}{IF !link}{IF readable}| <a href="{SCRIPT}?command=download&file={FILE_URL}">Download</a> {IF archive}| <a href="{SCRIPT}?command=unpack&amp;file={FILE_URL}">Unpack</a> {ENDIF}| <a href="{SCRIPT}?command=copy&amp;file={FILE_URL}">Copy</a>{ENDIF}{ENDIF}{IF dir_writeable} | <a href="{SCRIPT}?command=rename&amp;file={FILE_URL}">Rename</a> | <a href="{SCRIPT}?command=remove&amp;file={FILE_URL}">Delete</a>{ENDIF} |{IF !link}{IF users} <a href="{SCRIPT}?command=chprop&amp;file={FILE_URL}">Chmod/Chgrp</a> |{ENDIF}{ENDIF} {ENDIF}<a href="{URL}" target="_blank">View in Browser</a>)</td>
 </tr>
diff --git a/templates/unpack.htm b/templates/unpack.htm
new file mode 100644 (file)
index 0000000..fdab3d0
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+<title>Unpack file {FILE}</title>
+<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
+</head>
+<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
+
+<h1>Unpack file {FILE}</h1>
+
+<p>(equals <a href="{URL}" target="_blank">{URL}</a>)</p>
+
+<p><a href="{SCRIPT}?command=show&amp;file={DIR_URL}">Back to {DIR}</a></p>
+
+<hr>
+
+<form action="{SCRIPT}" method="post">
+<input type="hidden" name="command" value="unpack">
+<input type="hidden" name="file" value="{FILE}">
+
+<p>Unpack file '{FILE}' to:<br>
+<input type="text" name="newfile" value="{DIR}"><!-- <input type="checkbox" name="confirmed" id="overwrite"><label for="overwrite">Overwrite existing file</label> --></p>
+
+<p><input type="submit" value="Unpack file!"></p>
+</form>
+
+<hr>
+
+<p align="right"><a href="{SCRIPT}?command=about" target="_blank"><i>About Dev-Editor</i></a></p>
+</body>
+</html>
\ No newline at end of file

patrick-canterino.de