]> sipb.mit.edu Git - ikiwiki.git/commitdiff
add virus checking to attachments plugin
authorJoey Hess <joey@kodama.kitenet.net>
Sun, 6 Jul 2008 21:36:26 +0000 (17:36 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Sun, 6 Jul 2008 21:36:26 +0000 (17:36 -0400)
IkiWiki/Plugin/attachment.pm
debian/changelog
doc/ikiwiki.setup
doc/ikiwiki/pagespec/attachment.mdwn
doc/plugins/attachment.mdwn
doc/todo/attachments.mdwn

index 2bb86b78dbf09eb34dfc13549c4f941a34d7a557..cb762e453e9f92c368fed3784c1ad5820455e6f6 100644 (file)
@@ -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;
 
index 1e82ee70cb255561d92f99c63e4a99ab18faf68d..346b1a1bed676e953ede1026c9d6cea02617b97a 100644 (file)
@@ -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.)
index 03d04176d4bd722ef9a409aa872d72a3714d6ba4..6d327fd9861d298cda18b5aaefa74d6a35854922 100644 (file)
@@ -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 -",
 }
index 40de917658f69e47320e84bfd57e61e6a42df711..c6166d013166ccf709343e6667284757f7fe7271 100644 (file)
@@ -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.
index 2b834304296cf184e78d4110573914795d0abaff..dedc4162e050d87c1e4d4e39c809e9bc511258b6 100644 (file)
@@ -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 -".
index 8c5c286158863c8fcb774c9302e296133ac8abf0..d1d2752910aab1cb2aadcb88f7da431fe56bb896 100644 (file)
@@ -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/*)`