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.
class ExtractWindow extends FixedFrame implements CbButtonCallback
{
- CbButton yes, yesdelete, no;
+ CbButton yes, yesdelete, no, show;
FileManager filemgr;
RemoteFile file;
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();
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();
}
}
+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();
+ }
+ }
+}
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
--- /dev/null
+#!/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";
+ }
+
}
}
-# 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);
}
else {
return $text{'zip_ename'};
}
-if ($_[1]) {
- unlink($_[0]);
+if ($contents) {
+ return (undef, split(/\r?\n/, $out));
+ }
+elsif ($delete) {
+ unlink($path);
}
return undef;
}
# 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'}) {
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