aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-07-06 17:36:26 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-07-06 17:36:26 -0400
commit2f3a279f68dcf8c1566d82419fc7257e162ee345 (patch)
tree6d906880657a3f68fb2c19cc5db8fb4b0bca50a9
parent788c1e9eca84093b01d312e4d9f8e736ecc61ea9 (diff)
downloadikiwiki-2f3a279f68dcf8c1566d82419fc7257e162ee345.tar
ikiwiki-2f3a279f68dcf8c1566d82419fc7257e162ee345.tar.gz
add virus checking to attachments plugin
-rw-r--r--IkiWiki/Plugin/attachment.pm38
-rw-r--r--debian/changelog3
-rw-r--r--doc/ikiwiki.setup4
-rw-r--r--doc/ikiwiki/pagespec/attachment.mdwn10
-rw-r--r--doc/plugins/attachment.mdwn6
-rw-r--r--doc/todo/attachments.mdwn6
6 files changed, 58 insertions, 9 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index 2bb86b78d..cb762e453 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -333,6 +333,44 @@ sub match_mimetype ($$;@) { #{{{
}
} #}}}
+sub match_virusfree ($$;@) { #{{{
+ shift;
+ my $wanted=shift;
+
+ my %params=@_;
+ if (! exists $params{file}) {
+ return IkiWiki::FailReason->new("no file specified");
+ }
+
+ if (! exists $IkiWiki::config{virus_checker} ||
+ ! length $IkiWiki::config{virus_checker}) {
+ return IkiWiki::FailReason->new("no virus_checker configured");
+ }
+
+ # The file needs to be fed into the virus checker on stdin,
+ # because the file is not world-readable, and if clamdscan is
+ # used, clamd would fail to read it.
+ eval q{use IPC::Open2};
+ error($@) if $@;
+ open (IN, "<", $params{file}) || return IkiWiki::FailReason->new("failed to read file");
+ binmode(IN);
+ my $sigpipe=0;
+ $SIG{PIPE} = sub { $sigpipe=1 };
+ my $pid=open2(\*CHECKER_OUT, "<&IN", $IkiWiki::config{virus_checker});
+ my $reason=<CHECKER_OUT>;
+ chomp $reason;
+ 1 while (<CHECKER_OUT>);
+ close(CHECKER_OUT);
+ waitpid $pid, 0;
+ $SIG{PIPE}="DEFAULT";
+ if ($sigpipe || $?) {
+ return IkiWiki::FailReason->new("file seems to contain a virus ($reason)");
+ }
+ else {
+ return IkiWiki::SuccessReason->new("file seems virusfree ($reason)");
+ }
+} #}}}
+
sub match_ispage ($$;@) { #{{{
my $filename=shift;
diff --git a/debian/changelog b/debian/changelog
index 1e82ee70c..346b1a1be 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,9 @@
ikiwiki (2.52) UNRELEASED; urgency=low
* attachment: New plugin for uploading and managing attachments.
+ This includes a fairly powerful PageSpec based admin pref for deciding
+ whether to accept a given upload, and an attachment management interface
+ on the edit page.
(Sponsored by The TOVA Company.)
* If attachments are not enabled, configure CGI.pm to disable file
uploads by default. (An anti-DOS measure.)
diff --git a/doc/ikiwiki.setup b/doc/ikiwiki.setup
index 03d04176d..6d327fd98 100644
--- a/doc/ikiwiki.setup
+++ b/doc/ikiwiki.setup
@@ -195,4 +195,8 @@ use IkiWiki::Setup::Standard {
#amazon_s3_location => "EU",
# Uncomment if you need to store each index file twice.
#amazon_s3_dupindex => 1,
+
+ # For use with the attachment plugin, a program that returns
+ # nonzero if its standard input contains an virus.
+ #virus_checker => "clamdscan -",
}
diff --git a/doc/ikiwiki/pagespec/attachment.mdwn b/doc/ikiwiki/pagespec/attachment.mdwn
index 40de91765..c6166d013 100644
--- a/doc/ikiwiki/pagespec/attachment.mdwn
+++ b/doc/ikiwiki/pagespec/attachment.mdwn
@@ -8,10 +8,10 @@ attachments will be accepted, by entering a [[ikiwiki/PageSpec]] in the
"Allowed Attachments" field of their preferences page.
For example, to limit arbitrary files to 50 kilobytes, but allow
-larger mp3 files to be uploaded by joey, a something like this could be
-used:
+larger mp3 files to be uploaded by joey, and check all attachments for
+virii, something like this could be used:
- (user(joey) and *.mp3 and mimetype(audio/mpeg) and maxsize(15mb)) or (!ispage() and maxsize(50kb))
+ virusfree() and ((user(joey) and *.mp3 and mimetype(audio/mpeg) and maxsize(15mb)) or (!ispage() and maxsize(50kb)))
The regular [[ikiwiki/PageSpec]] syntax is expanded with thw following
additional tests:
@@ -50,3 +50,7 @@ additional tests:
This checks the MIME type of the attachment. You can include a glob
in the type, for example `mimetype(image/*)`.
+
+* virusfree()
+
+ Checks the attachment with an antiviral program.
diff --git a/doc/plugins/attachment.mdwn b/doc/plugins/attachment.mdwn
index 2b8343042..dedc4162e 100644
--- a/doc/plugins/attachment.mdwn
+++ b/doc/plugins/attachment.mdwn
@@ -26,3 +26,9 @@ Attachments" field of the wiki admin's preferences page.
This plugin will use the [[cpan File::MimeInfo::Magic]] perl module, if
available, for mimetype checking.
+
+The `virusfree` [[PageSpec|ikiwiki/pagespec/attachment]] requires that
+ikiwiki be configured with a virus scanner program via the `virus_checker`
+option in the setup file. If using `clamav`, with `clamd`, set it to
+"clamdscan -". Or to use clamav without the `clamd` daemon, you
+could set it to "clamscan -".
diff --git a/doc/todo/attachments.mdwn b/doc/todo/attachments.mdwn
index 8c5c28615..d1d275291 100644
--- a/doc/todo/attachments.mdwn
+++ b/doc/todo/attachments.mdwn
@@ -1,15 +1,9 @@
Stuff the [[plugins/attachment]] plugin is currently missing, that might be
nice to add:
-* Virus scanning.
* Add a progress bar for attachment uploads (needs AJAX stuff..)
* Maybe optimise the "Insert Links" button with javascript, so, if
javascript is available, the link is inserted at the current cursor
position in the page edit form, without actually reposting the form.
(Falling back to the current reposting of the form if javascript is not
available of course.)
-* Set `$CGI::POST_MAX` to some sane value (ie, larger than the largest
- configured `maxsize()` in the pagespec, or if none is configured,
- something reasonable. Just as a belt-and-suspenders DOS prevention.
-* Only allow attachments to be added to a given list of pages.
- Maybe a pagespec like `parent(patches/*)`