Option to show contents of compressed file instead of extracting
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Nov 2008 06:00:50 +0000 (06:00 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Nov 2008 06:00:50 +0000 (06:00 +0000)
file/CHANGELOG
file/FileManager.java
file/Makefile
file/contents.cgi [new file with mode: 0755]
file/file-lib.pl
file/filesystems.cgi
file/lang/en
file/plugin.jar [new file with mode: 0644]

index 957cbb7..07ccf68 100644 (file)
@@ -43,3 +43,5 @@ Added a Module Config option to specify file extensions to treat as HTML, rather
 Use of the Preview button can now be controlled on the access control page.
 ---- Changes since 1.430 ----
 POSIX ACLs can now be edited on FreeBSD, if the setfacl and getfacl commands are installed.
+---- Changes since 1.440 ----
+Added a button to the compressed file extraction dialog to show the contents of a ZIP or tar file, instead of extracting it.
index 667a911..817f43a 100644 (file)
@@ -4475,7 +4475,7 @@ class ImagePanel extends Panel
 
 class ExtractWindow extends FixedFrame implements CbButtonCallback
 {
-       CbButton yes, yesdelete, no;
+       CbButton yes, yesdelete, no, show;
        FileManager filemgr;
        RemoteFile file;
 
@@ -4499,6 +4499,7 @@ class ExtractWindow extends FixedFrame implements CbButtonCallback
        bot.add(yes = new CbButton(filemgr.text("yes"), this));
        bot.add(yesdelete = new CbButton(filemgr.text("extract_yes"), this));
        bot.add(no = new CbButton(filemgr.text("no"), this));
+       bot.add(show = new CbButton(filemgr.text("extract_show"), this));
        add("South", bot);
        pack();
        show();
@@ -4530,6 +4531,20 @@ class ExtractWindow extends FixedFrame implements CbButtonCallback
                        new ErrorWindow(filemgr.text("extract_err", rv[0]));
                        }
                }
+       else if (b == show) {
+               // Open window just showing contents
+               String rv[] = filemgr.get_text("contents.cgi?file="+
+                                              filemgr.urlize(file.path));
+               dispose();
+               if (rv[0].equals("")) {
+                       // Worked - show the files
+                       new ContentsWindow(file, filemgr, rv);
+                       }
+               else {
+                       // Failed - show the error
+                       new ErrorWindow(filemgr.text("extract_err2", rv[0]));
+                       }
+               }
        else {
                // Just close the window
                dispose();
@@ -4537,4 +4552,48 @@ class ExtractWindow extends FixedFrame implements CbButtonCallback
        }
 }
 
+class ContentsWindow extends FixedFrame implements CbButtonCallback
+{
+       RemoteFile file;
+        FileManager filemgr;
+        CbButton close_b;
+
+       ContentsWindow(RemoteFile f, FileManager p, String rv[])
+       {
+       file = f;
+       filemgr = p;
+
+       // Create UI
+       setTitle(f.path);
+       setLayout(new BorderLayout());
+       Panel bot = new Panel();
+       bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
+       bot.add(close_b = new CbButton(filemgr.get_image("cancel.gif"),
+                                       filemgr.text("close"),
+                                       CbButton.LEFT, this));
+       add("South", bot);
+
+       // Create text area showing contents
+       String lines = "";
+       for(int i=1; i<rv.length; i++) {
+               lines = lines + rv[i] + "\n";
+               }
+       TextArea contents = new TextArea(lines, 30, 60);
+       contents.setEditable(false);
+       add("Center", contents);
+       add("North", new Label(filemgr.text("extract_shown")));
+
+       Util.recursiveBody(this);
+       pack();
+       show();
+       }
+
+       public void click(CbButton b)
+       {
+       if (b == close_b) {
+               // Just close
+               dispose();
+               }
+       }
+}
 
index 5c5c394..6b8ef5f 100644 (file)
@@ -1,4 +1,3 @@
 file.jar:              FileManager.java Util.java
-                       CLASSPATH=/usr/local/netscape7/plugins/java2/lib/javaplugin.jar:. javac -target 1.2 -source 1.2 *.java
+                       CLASSPATH=plugin.jar:. javac -target 1.2 -source 1.2 *.java
                        jar cf file.jar *.class
-                       [ -d "../zomos-virtual" ] && jar cf ../zomos-virtual/file.jar *.class
diff --git a/file/contents.cgi b/file/contents.cgi
new file mode 100755 (executable)
index 0000000..4bec9d7
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/local/bin/perl
+# Show the contents of a zip, tar, tar.gz or tar.bz file on the server
+
+require './file-lib.pl';
+&ReadParse();
+print "Content-type: text/plain\n\n";
+
+# Check permissions
+$disallowed_buttons{'upload'} && &error($text{'ebutton'});
+if (!&can_access($in{'file'})) {
+       print &text('extract_eperm', $in{'file'}),"\n";
+       exit(0);
+       }
+
+# Go for it
+$realfile = &unmake_chroot($in{'file'});
+&switch_acl_uid();
+($err, @lines) = &extract_archive($realfile, 0, 1);
+print $err,"\n";
+foreach my $l (@lines) {
+       print $l,"\n";
+       }
+
index 212840a..abad711 100644 (file)
@@ -292,50 +292,72 @@ else {
        }
 }
 
-# extract_archive(path, delete)
+# extract_archive(path, delete-after, get-contents)
 # Called by upload to extract some zip or tar.gz file. Returns undef if
 # something was actually done, an error message otherwise.
 sub extract_archive
 {
+local ($path, $delete, $contents) = @_;
 local $out;
-$_[0] =~ /^(\S*\/)/ || return 0;
+$path =~ /^(\S*\/)/ || return 0;
 local $dir = $1;
 local $qdir = quotemeta($dir);
-local $qpath = quotemeta($_[0]);
-if ($_[0] =~ /\.zip$/i) {
+local $qpath = quotemeta($path);
+if ($path =~ /\.zip$/i) {
        # Extract zip file
        return &text('zip_ecmd', "unzip") if (!&has_command("unzip"));
-       $out = `(cd $qdir; unzip -o $qpath) 2>&1 </dev/null`;
+       if ($contents) {
+               $out = `(cd $qdir; unzip -l $qpath) 2>&1 </dev/null`;
+               }
+       else {
+               $out = `(cd $qdir; unzip -o $qpath) 2>&1 </dev/null`;
+               }
        if ($?) {
                return &text('zip_eunzip', $out);
                }
        }
-elsif ($_[0] =~ /\.tar$/i) {
+elsif ($path =~ /\.tar$/i) {
        # Extract un-compressed tar file
        return &text('zip_ecmd', "tar") if (!&has_command("tar"));
-       $out = `(cd $qdir; tar xf $qpath) 2>&1 </dev/null`;
+       if ($contents) {
+               $out = `(cd $qdir; tar tf $qpath) 2>&1 </dev/null`;
+               }
+       else {
+               $out = `(cd $qdir; tar xf $qpath) 2>&1 </dev/null`;
+               }
        if ($?) {
                return &text('zip_euntar', $out);
                }
        }
-elsif ($_[0] =~ /\.(tar\.gz|tgz|tar\.bz|tbz|tar\.bz2|tbz2)$/i) {
+elsif ($path =~ /\.(tar\.gz|tgz|tar\.bz|tbz|tar\.bz2|tbz2)$/i) {
        # Extract gzip or bzip2-compressed tar file
        local $zipper = $_[0] =~ /bz(2?)$/i ? "bunzip2"
                                            : "gunzip";
        return &text('zip_ecmd', "tar") if (!&has_command("tar"));
        return &text('zip_ecmd', $zipper) if (!&has_command($zipper));
-       $out = `(cd $qdir; $zipper -c $qpath | tar xf -) 2>&1`;
+       if ($contents) {
+               $out = `(cd $qdir; $zipper -c $qpath | tar tf -) 2>&1`;
+               }
+       else {
+               $out = `(cd $qdir; $zipper -c $qpath | tar xf -) 2>&1`;
+               }
        if ($?) {
                return &text('zip_euntar2', $out);
                }
        }
-elsif ($_[0] =~ /\.gz$/i) {
+elsif ($path =~ /\.gz$/i) {
        # Uncompress gzipped file
        return &text('zip_ecmd', "gunzip") if (!&has_command("gunzip"));
        local $final = $_[0];
        $final =~ s/\.gz$//;
        local $qfinal = quotemeta($final);
-       $out = `(cd $qdir; gunzip -c $qpath >$qfinal) 2>&1`;
+       if ($contents) {
+               $out = $final;
+               $out =~ s/^.*\///;
+               }
+       else {
+               $out = `(cd $qdir; gunzip -c $qpath >$qfinal) 2>&1`;
+               }
        if ($?) {
                return &text('zip_euntar2', $out);
                }
@@ -343,8 +365,11 @@ elsif ($_[0] =~ /\.gz$/i) {
 else {
        return $text{'zip_ename'};
        }
-if ($_[1]) {
-       unlink($_[0]);
+if ($contents) {
+       return (undef, split(/\r?\n/, $out));
+       }
+elsif ($delete) {
+       unlink($path);
        }
 return undef;
 }
index cdf8cd0..23a3616 100755 (executable)
@@ -2,6 +2,7 @@
 # filesystems.cgi
 # List all filesystems and their types
 
+$trust_unknown_referers = 1;
 require './file-lib.pl';
 print "Content-type: text/plain\n\n";
 if (!&foreign_check("mount") || !$access{'filesystems'}) {
index 8c13363..5aa9dcd 100644 (file)
@@ -426,3 +426,6 @@ extract_rusure=Are you sure you want to extract the compressed file :
 extract_rusure2=Existing files in the same directory may be overwritten.
 extract_err=Failed to extract file : $1
 extract_yes=Yes, then delete
+extract_show=Show contents
+extract_err2=Failed to get file contents : $1
+extract_shown=Contents of compressed file
diff --git a/file/plugin.jar b/file/plugin.jar
new file mode 100644 (file)
index 0000000..91059dc
Binary files /dev/null and b/file/plugin.jar differ