xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/CGI/eg/diff_upload.cgi (revision 0:68f95e015346)
1#!/usr/local/bin/perl
2
3$DIFF = "/usr/bin/diff";
4$PERL = "/usr/bin/perl";
5
6use CGI qw(:standard);
7use CGI::Carp;
8
9print header;
10print start_html("File Diff Example");
11print "<strong>Version </strong>$CGI::VERSION<p>";
12
13print <<EOF;
14<H1>File Diff Example</H1>
15Enter two files.  When you press "submit" their diff will be
16produced.
17EOF
18    ;
19
20# Start a multipart form.
21print start_multipart_form;
22print "File #1:",filefield(-name=>'file1',-size=>45),"<BR>\n";
23print "File #2:",filefield(-name=>'file2',-size=>45),"<BR>\n";
24print "Diff type: ",radio_group(-name=>'type',
25					-value=>['context','normal']),"<br>\n";
26print reset,submit(-name=>'submit',-value=>'Do Diff');
27print endform;
28
29# Process the form if there is a file name entered
30$file1 = param('file1');
31$file2 = param('file2');
32
33$|=1;				# for buffering
34if ($file1 && $file2) {
35    $realfile1 = tmpFileName($file1);
36    $realfile2 = tmpFileName($file2);
37    print "<HR>\n";
38    print "<H2>$file1 vs $file2</H2>\n";
39
40    print "<PRE>\n";
41    $options = "-c" if param('type') eq 'context';
42    system "$DIFF $options $realfile1 $realfile2 | $PERL -pe 's/>/&gt;/g; s/</&lt;/g;'";
43    close $file1;
44    close $file2;
45    print "</PRE>\n";
46}
47
48print <<EOF;
49<HR>
50<A HREF="../cgi_docs.html">CGI documentation</A>
51<HR>
52<ADDRESS>
53<A HREF="/~lstein">Lincoln D. Stein</A>
54</ADDRESS><BR>
55Last modified 17 July 1996
56EOF
57    ;
58print end_html;
59
60sub sanitize {
61    my $name = shift;
62    my($safe) = $name=~/([a-zA-Z0-9._~#,]+)/;
63    unless ($safe) {
64	print "<strong>$name is not a valid Unix filename -- sorry</strong>";
65	exit 0;
66    }
67    return $safe;
68}
69