@@ -1,40 +0,0 @@
1−#!/usr/bin/env perl
2−use strict;
3−use CGI qw/:standard/;
4−use CGI::Carp 'fatalsToBrowser';
5−
6−$CGI::POST_MAX=1024 * 100; # max 100K posts
7−$CGI::DISABLE_UPLOADS = 1; # no uploads
8−
9−param('url') && param('format') or die "Missing url and/or format parameters.\n";
10−
11−my $options = '-r html --standalone --reference-links';
12−my $url = param('url');
13−my $format = param('format') || 'markdown';
14−if ($format =~ /^markdown$/) {
15− $options .= ' --strict';
16−}
17−if ($format =~ /^markdown\+$/) {
18− $format = 'markdown';
19−}
20−
21−# Validate URL and format
22−unless ($url =~ /^(https?:\/\/)?[\w#_-]+(\.[\w#_-]+)+(:\d+)?[\w\/#=:?_.-]*$/) {
23− die "Illegal URL: $url\n" ;
24−}
25−unless ($format =~ /^markdown\+?|rst|latex|context|rtf|man|docbook$/) {
26− die "Illegal format: $format\n";
27−}
28−
29−# Note - pass through head to truncate file to 100K if greater.
30−# This should prevent certain kinds of DoS attacks.
31−my $output = `wget -O- $url | head -c100000 | tidy -asxhtml -utf8 | pandoc -w $format $options`;
32−if ($output =~ /^\s*$/) {
33− print start_html,
34− h1("No output"),
35− p("Either $url could not be retrieved, or its HTML was too malformed to parse."),
36− end_html;
37− exit 0;
38−}
39−print header(-charset=>"utf8",-type=>"text/plain"),
40− $output;