Annotation of cvsweb/cvsweb.cgi, Revision 3.124
3.55 knu 1: #!/usr/bin/perl -wT
1.1 jfieber 2: #
3.1 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
3.12 knu 5: # Written in their spare time by
3.113 scop 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
8: # Henrik Nordstrom <hno@hem.passagen.se>
9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
12: # Jens-Uwe Mager <jum@helios.de>
13: # Ville Skyttä <scop@FreeBSD.org>
14: # Vassilii Khachaturov <vassilii@tarunz.org>
3.1 knu 15: #
16: # Based on:
17: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5 knu 18: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 19: #
1.21 wosch 20: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 21: # (c) 1998-1999 Henner Zeller
3.109 scop 22: # (c) 1999 Henrik Nordstrom
23: # (c) 2000-2002 Akinori MUSHA
24: # (c) 2002 Ville Skyttä
1.21 wosch 25: # All rights reserved.
26: #
27: # Redistribution and use in source and binary forms, with or without
28: # modification, are permitted provided that the following conditions
29: # are met:
30: # 1. Redistributions of source code must retain the above copyright
31: # notice, this list of conditions and the following disclaimer.
32: # 2. Redistributions in binary form must reproduce the above copyright
33: # notice, this list of conditions and the following disclaimer in the
34: # documentation and/or other materials provided with the distribution.
35: #
36: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46: # SUCH DAMAGE.
47: #
3.87 knu 48: # $FreeBSD$
3.82 knu 49: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85 knu 50: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21 wosch 51: #
3.1 knu 52: ###
53:
3.55 knu 54: require 5.000;
55:
3.1 knu 56: use strict;
1.21 wosch 57:
3.1 knu 58: use vars qw (
3.121 scop 59: $VERSION
3.122 scop 60: $uname $config $allow_version_select $verbose
3.120 scop 61: @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
62: %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
63: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
64: %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
65: %symrev %revsym @allrevisions %date %author @revdisplayorder
66: @revisions %state %difflines %log %branchpoint @revorder
67: $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
68: $checkoutMagic $doCheckout $scriptname $scriptwhere
69: $where $pathinfo $Browser $nofilelinks $maycompress
70: @stickyvars @unsafevars
71: %funcline_regexp $is_mod_perl
72: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
73: %input $query $barequery $sortby $bydate $byrev $byauthor
74: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
75: $mimetype $charset $output_filter $defaultTextPlain $defaultViewable
76: $command_path %CMD $allow_compress
77: $backicon $diricon $fileicon
78: $fullname $newname $cvstreedefault
79: $body_tag $body_tag_for_src $logo $defaulttitle $address
80: $long_intro $short_instruction $shortLogLen
81: $show_author $dirtable $tablepadding $columnHeaderColorDefault
82: $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
83: $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
84: $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
85: $difffontsize $inputTextSize $mime_types
86: $allow_annotate $allow_markup
87: $allow_log_extra $allow_dir_extra $allow_source_extra
88: $use_java_script $open_extern_window
89: $extern_window_width $extern_window_height $edit_option_form
90: $show_subdir_lastmod $show_log_in_markup $preformat_in_markup $v
91: $navigationHeaderColor $tableBorderColor $markupLogColor
92: $tabstop $state $annTable $sel $curbranch @HideModules @ForbiddenFiles
93: $module $use_descriptions %descriptions @mytz $dwhere $moddate
94: $use_moddate $has_zlib $gzip_open
95: $allow_tar @tar_options @gzip_options @zip_options @cvs_options
96: $LOG_FILESEPARATOR $LOG_REVSEPARATOR
97: $tmpdir $HTML_DOCTYPE $HTML_META
3.1 knu 98: );
99:
3.122 scop 100: use Cwd qw(abs_path);
101: use File::Basename ();
102: use IPC::Open2 qw(open2);
103: use Time::Local ();
104:
105: # -----------------------------------------------------------------------------
106:
107: # All global initialization that can be done in compile time should go to
108: # the BEGIN block. Persistent environments, such as mod_perl, will benefit
109: # from this.
110:
111: BEGIN
112: {
113: $VERSION = '3.0-dev';
114:
115: $HTML_DOCTYPE =
116: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
117:
118: $HTML_META = <<EOM;
119: <meta name="robots" content="nofollow">
120: <meta name="generator" content="FreeBSD-CVSweb $VERSION">
121: <meta http-equiv="Content-Script-Type" content="text/javascript">
122: <meta http-equiv="Content-Style-Type" content="text/css">
123: EOM
124:
125: # Check if the zlib C library interface is installed, and if yes,
126: # we can avoid using the extra gzip process.
127: eval { require Compress::Zlib; };
128: $has_zlib = !$@;
129:
130: $is_mod_perl = defined($ENV{MOD_PERL});
131:
132: $tmpdir = $ENV{TMPDIR} || '/var/tmp';
133:
134: $LOG_FILESEPARATOR = qr/^={77}$/o;
135: $LOG_REVSEPARATOR = qr/^-{28}$/o;
136: }
137:
138: # -----------------------------------------------------------------------------
139:
3.12 knu 140: sub printDiffSelect($);
3.37 knu 141: sub printDiffLinks($$);
142: sub printLogSortSelect($);
3.12 knu 143: sub findLastModifiedSubdirs(@);
3.36 knu 144: sub htmlify_sub(&$);
3.12 knu 145: sub htmlify($;$);
3.20 knu 146: sub spacedHtmlText($;$);
3.12 knu 147: sub link($$);
148: sub revcmp($$);
3.103 knu 149: sub fatal($$@);
3.12 knu 150: sub redirect($);
151: sub safeglob($);
3.58 knu 152: sub search_path($);
3.12 knu 153: sub getMimeTypeFromSuffix($);
3.24 knu 154: sub head($;$);
155: sub scan_directives(@);
3.86 knu 156: sub openOutputFilter();
3.12 knu 157: sub doAnnotate($$);
158: sub doCheckout($$);
159: sub cvswebMarkup($$$);
160: sub viewable($);
161: sub doDiff($$$$$$);
162: sub getDirLogs($$@);
163: sub readLog($;$);
164: sub printLog($;$);
165: sub doLog($);
166: sub flush_diff_rows($$$$);
167: sub human_readable_diff($);
168: sub navigateHeader($$$$$);
169: sub plural_write($$);
170: sub readableTime($$);
171: sub clickablePath($$);
172: sub chooseCVSRoot();
173: sub chooseMirror();
174: sub fileSortCmp();
175: sub download_url($$;$);
176: sub download_link($$$;$);
177: sub toggleQuery($$);
178: sub urlencode($);
3.35 knu 179: sub htmlquote($);
3.36 knu 180: sub htmlunquote($);
3.48 knu 181: sub hrefquote($);
3.12 knu 182: sub http_header(;$);
183: sub html_header($);
184: sub html_footer();
185: sub link_tags($);
3.81 knu 186: sub forbidden_file($);
3.12 knu 187: sub forbidden_module($);
188:
3.1 knu 189: ##### Start of Configuration Area ########
3.122 scop 190:
191: # Don't put this in BEGIN...
3.59 knu 192: delete $ENV{PATH};
193:
3.122 scop 194: my ($mydir) = (File::Basename::dirname($0) =~ /(.*)/); # untaint
3.58 knu 195:
3.12 knu 196: # == EDIT this ==
3.28 knu 197: # Locations to search for user configuration, in order:
3.80 knu 198: for ("$mydir/cvsweb.conf", '/usr/local/etc/cvsweb/cvsweb.conf') {
3.120 scop 199: if (defined($_) && -r $_) {
200: $config = $_;
201: last;
202: }
3.11 knu 203: }
3.122 scop 204: undef $mydir;
3.1 knu 205:
206: # == Configuration defaults ==
207: # Defaults for configuration variables that shouldn't need
208: # to be configured..
209: $allow_version_select = 1;
3.120 scop 210: $allow_log_extra = 1;
3.1 knu 211:
212: ##### End of Configuration Area ########
213:
214: ######## Configuration variables #########
215: # These are defined to allow checking with perl -cw
3.120 scop 216:
3.80 knu 217: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
3.120 scop 218: %MTYPES = %tags = %alltags = @tabcolors = %fileinfo = ();
219:
3.80 knu 220: $cvstreedefault = $body_tag = $body_tag_for_src = $logo = $defaulttitle =
3.120 scop 221: $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
222: $dirtable = $tablepadding = $columnHeaderColorDefault =
223: $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
224: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
225: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
226: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
227: $allow_markup = $use_java_script = $open_extern_window =
228: $extern_window_width = $extern_window_height = $edit_option_form =
229: $show_subdir_lastmod = $show_log_in_markup = $v = $navigationHeaderColor =
230: $tableBorderColor = $markupLogColor = $tabstop = $use_moddate = $moddate =
3.122 scop 231: $gzip_open = undef;
3.32 knu 232:
3.37 knu 233: @DIFFTYPES = qw(h H u c s);
234: @DIFFTYPES{@DIFFTYPES} = (
3.120 scop 235: {
236: 'descr' => 'colored',
237: 'opts' => ['-u'],
238: 'colored' => 1,
239: },
240: {
241: 'descr' => 'long colored',
242: 'opts' => ['--unified=15'],
243: 'colored' => 1,
244: },
245: {
246: 'descr' => 'unified',
247: 'opts' => ['-u'],
248: 'colored' => 0,
249: },
250: {
251: 'descr' => 'context',
252: 'opts' => ['-c'],
253: 'colored' => 0,
254: },
255: {
256: 'descr' => 'side by side',
257: 'opts' => ['--side-by-side', '--width=164'],
258: 'colored' => 0,
259: },
3.80 knu 260: );
3.37 knu 261:
262: @LOGSORTKEYS = qw(cvs date rev);
263: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.120 scop 264: {'descr' => 'Not sorted',},
265: {'descr' => 'Commit date',},
266: {'descr' => 'Revision',},
3.80 knu 267: );
3.37 knu 268:
3.1 knu 269: ##### End of configuration variables #####
270:
3.120 scop 271: $verbose = $v;
272: $checkoutMagic = "~checkout~";
273: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
274: $where = $pathinfo;
275: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
276: $where =~ s|^/$checkoutMagic/|/|;
277: $where =~ s|^/||;
278: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
279: $scriptname =~ s|^/*|/|;
3.63 knu 280:
3.64 knu 281: # Let's workaround thttpd's stupidity..
3.63 knu 282: if ($scriptname =~ m|/$|) {
3.120 scop 283: $pathinfo .= '/';
284: my $re = quotemeta $pathinfo;
285: $scriptname =~ s/$re$//;
3.63 knu 286: }
287:
3.120 scop 288: $scriptwhere = $scriptname;
3.63 knu 289: $scriptwhere .= '/' . urlencode($where);
290: $where = '/' if ($where eq '');
3.3 knu 291:
3.1 knu 292: # in lynx, it it very annoying to have two links
293: # per file, so disable the link at the icon
294: # in this case:
3.120 scop 295: $Browser = $ENV{HTTP_USER_AGENT} || '';
3.80 knu 296: $is_links = ($Browser =~ m`^Links `);
297: $is_lynx = ($Browser =~ m`^Lynx/`i);
298: $is_w3m = ($Browser =~ m`^w3m/`i);
299: $is_msie = ($Browser =~ m`MSIE`);
3.5 knu 300: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3 knu 301:
3.34 knu 302: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5 knu 303:
304: $nofilelinks = $is_textbased;
3.1 knu 305:
306: # newer browsers accept gzip content encoding
307: # and state this in a header
308: # (netscape did always but didn't state it)
309: # It has been reported that these
310: # braindamaged MS-Internet Exploders claim that they
311: # accept gzip .. but don't in fact and
312: # display garbage then :-/
3.23 knu 313: # Turn off gzip if running under mod_perl and no zlib is available,
314: # piping does not work as expected inside the server.
3.120 scop 315: $maycompress = (
316: ((defined($ENV{HTTP_ACCEPT_ENCODING})
317: && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/)
318: || $is_mozilla3)
319: && !$is_msie
320: && !($is_mod_perl && !$has_zlib)
321: );
3.1 knu 322:
323: # put here the variables we need in order
324: # to hold our state - they will be added (with
3.12 knu 325: # their current value) to any link/query string
3.1 knu 326: # you construct
3.6 knu 327: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
3.97 knu 328: @unsafevars = qw(logsort only_with_tag r1 r2 rev sortby tr1 tr2);
1.1 jfieber 329:
3.1 knu 330: if (-f $config) {
3.120 scop 331: do "$config"
332: or fatal("500 Internal Error",
333: 'Error in loading configuration file: %s<br><br>%s<br>',
334: $config, $@);
3.27 knu 335: } else {
3.120 scop 336: fatal("500 Internal Error",
337: 'Configuration not found. Set the variable <code>$config</code> in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
3.1 knu 338: }
339:
340: undef %input;
3.3 knu 341: $query = $ENV{QUERY_STRING};
342:
3.12 knu 343: if (defined($query) && $query ne '') {
3.120 scop 344: foreach (split (/&/, $query)) {
345: y/+/ /;
346: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
347: if (/(\S+)=(.*)/) {
348: $input{$1} = $2 if ($2 ne "");
349: } else {
350: $input{$_}++;
351: }
352: }
1.7 fenner 353: }
1.10 wosch 354:
3.12 knu 355: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1 knu 356: $input{only_with_tag} = $input{only_on_branch}
3.120 scop 357: if (defined($input{only_on_branch}));
3.97 knu 358:
359: # Prevent cross-site scripting
360: foreach (@unsafevars) {
3.120 scop 361:
362: # Colons are needed in diffs between tags.
363: if (defined($input{$_}) && $input{$_} =~ /[^\w\-.:]/) {
364: fatal("500 Internal Error", 'Malformed query (%s=%s)', $_, $input{$_});
365: }
3.97 knu 366: }
367:
368: if (defined($input{"content-type"})) {
3.120 scop 369: fatal("500 Internal Error", "Unsupported content-type")
370: if ($input{"content-type"} !~ /^[-0-9A-Za-z]+\/[-0-9A-Za-z]+$/);
3.97 knu 371: }
1.10 wosch 372:
3.1 knu 373: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 374:
3.120 scop 375: while (my ($key, $defval) = each %DEFAULTVALUE) {
3.80 knu 376:
3.120 scop 377: # Replace not given parameters with defaults.
378: next unless (defined($defval)
3.121 scop 379: && (!defined($input{$key}) || $input{$key} eq ''));
3.120 scop 380:
381: # Empty checkboxes in forms return nothing, so we define a helper variable
382: # in these forms (copt) which indicates that we just set parameters with a
383: # checkbox.
384: if (defined($input{'copt'})) {
385:
386: # 'copt' is defined -> the result of empty input checkbox
387: # -> set to zero (disable) if default is a boolean (0|1).
388: $input{$key} = 0 if ($defval eq '0' || $defval eq '1');
389:
390: } else {
391:
392: # 'copt' isn't defined --> empty input is not the result
393: # of empty input checkbox --> set default.
394: $input{$key} = $defval;
395: }
1.10 wosch 396: }
3.12 knu 397:
3.1 knu 398: $barequery = "";
3.31 knu 399: my @barequery;
3.1 knu 400: foreach (@stickyvars) {
3.80 knu 401:
3.120 scop 402: # construct a query string with the sticky non default parameters set
403: if (defined($input{$_})
404: && $input{$_} ne ''
405: && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
406: {
407: push @barequery, join ('=', urlencode($_), urlencode($input{$_}));
408: }
3.1 knu 409: }
3.80 knu 410:
3.1 knu 411: # is there any query ?
3.31 knu 412: if (@barequery) {
3.120 scop 413: $barequery = join ('&', @barequery);
414: $query = "?$barequery";
415: $barequery = "&$barequery";
3.80 knu 416: } else {
3.120 scop 417: $query = "";
3.1 knu 418: }
3.31 knu 419: undef @barequery;
3.1 knu 420:
3.120 scop 421: if (defined($input{'path'})) {
422: redirect("$scriptname/$input{path}$query");
3.57 knu 423: }
424:
3.1 knu 425: # get actual parameters
3.120 scop 426: $sortby = $input{'sortby'};
3.80 knu 427: $bydate = 0;
428: $byrev = 0;
3.1 knu 429: $byauthor = 0;
3.80 knu 430: $bylog = 0;
431: $byfile = 0;
3.120 scop 432: if ($sortby eq 'date') {
433: $bydate = 1;
434: } elsif ($sortby eq 'rev') {
435: $byrev = 1;
436: } elsif ($sortby eq 'author') {
437: $byauthor = 1;
438: } elsif ($sortby eq 'log') {
439: $bylog = 1;
3.80 knu 440: } else {
3.120 scop 441: $byfile = 1;
3.1 knu 442: }
443:
3.37 knu 444: $defaultDiffType = $input{'f'};
3.1 knu 445:
3.3 knu 446: $logsort = $input{'logsort'};
1.10 wosch 447:
3.95 knu 448: {
3.120 scop 449: my @tmp = @CVSrepositories;
450:
451: while (my ($key, $val) = splice(@tmp, 0, 2)) {
452: my ($descr, $cvsroot) = @$val;
3.56 knu 453:
3.120 scop 454: next unless -d $cvsroot;
455:
456: $CVSROOTdescr{$key} = $descr;
457: $CVSROOT{$key} = $cvsroot;
458: push(@CVSROOT, $key);
459: }
3.56 knu 460: }
1.12 fenner 461:
3.1 knu 462: ## Default CVS-Tree
463: if (!defined($CVSROOT{$cvstreedefault})) {
3.120 scop 464: fatal("500 Internal Error",
465: '<code>$cvstreedefault</code> points to a repository (%s) not defined in <code>%%CVSROOT</code> (edit your configuration file %s)',
466: $cvstreedefault,
467: $config);
3.1 knu 468: }
469:
470: # alternate CVS-Tree, configured in cvsweb.conf
471: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
3.120 scop 472: $cvstree = $input{'cvsroot'};
3.1 knu 473: } else {
3.120 scop 474: $cvstree = $cvstreedefault;
1.10 wosch 475: }
476:
3.1 knu 477: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 478:
3.1 knu 479: # create icons out of description
3.120 scop 480: foreach my $k (keys %ICONS) {
481: my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
482: no strict 'refs';
483: if ($ipath) {
484: ${"${k}icon"} =
485: sprintf('<img src="%s" alt="%s" border="0" width="%d" height="%d">',
486: hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight);
487: } else {
488: ${"${k}icon"} = $itxt;
489: }
1.24 wosch 490: }
491:
3.27 knu 492: my $config_cvstree = "$config-$cvstree";
493:
3.1 knu 494: # Do some special configuration for cvstrees
3.27 knu 495: if (-f $config_cvstree) {
3.120 scop 496: do "$config_cvstree"
497: or fatal("500 Internal Error",
498: 'Error in loading configuration file: %s<br><br>%s<br>',
499: $config_cvstree, $@);
3.27 knu 500: }
3.31 knu 501: undef $config_cvstree;
3.1 knu 502:
3.120 scop 503: $re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
504: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
505: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24 wosch 506:
3.80 knu 507: $fullname = "$cvsroot/$where";
508: $mimetype = &getMimeTypeFromSuffix($fullname);
3.1 knu 509: $defaultTextPlain = ($mimetype eq "text/plain");
3.80 knu 510: $defaultViewable = $allow_markup && viewable($mimetype);
3.1 knu 511:
3.63 knu 512: my $rewrite = 0;
513:
514: if ($pathinfo =~ m|//|) {
3.120 scop 515: $pathinfo =~ y|/|/|s;
516: $rewrite = 1;
3.63 knu 517: }
518:
3.120 scop 519: if (-d $fullname) {
520: if ($pathinfo !~ m|/$|) {
521: $pathinfo .= '/';
522: $rewrite = 1;
523: }
524: } else {
525: if ($pathinfo =~ m|/$|) {
526: chop $pathinfo;
527: $rewrite = 1;
528: }
3.63 knu 529: }
530:
531: if ($rewrite) {
3.120 scop 532: redirect($scriptname . urlencode($pathinfo) . $query);
3.1 knu 533: }
534:
3.63 knu 535: undef $rewrite;
536:
3.1 knu 537: if (!-d $cvsroot) {
3.120 scop 538: fatal("500 Internal Error",
539: '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
3.1 knu 540: }
541:
542: #
543: # See if the module is in our forbidden list.
544: #
545: $where =~ m:([^/]*):;
546: $module = $1;
547: if ($module && &forbidden_module($module)) {
3.120 scop 548: fatal("403 Forbidden", 'Access to %s forbidden.', $where);
3.1 knu 549: }
3.46 knu 550:
551: #
552: # Handle tarball downloads before any headers are output.
553: #
554: if ($input{tarball}) {
3.120 scop 555: fatal('403 Forbidden', 'Downloading tarballs is prohibited.')
556: unless $allow_tar;
557: my ($module) = ($where =~ m,^/?(.*),); # untaint
558: $module =~ s,/([^/]*)$,,;
559: my ($ext) = ($1 =~ /(\.tar\.gz|\.zip)$/);
560: my ($basedir) = ($module =~ m,([^/]+)$,);
561:
562: if ($basedir eq '' || $module eq '') {
563: fatal('500 Internal Error',
564: 'You cannot download the top level directory.');
565: }
566:
567: my $tmpexportdir = "$tmpdir/.cvsweb.$$." . int(time);
568:
569: mkdir($tmpexportdir, 0700) or
570: fatal('500 Internal Error', 'Unable to make temporary directory: %s', $!);
571:
572: my @fatal;
573:
574: my $tag =
575: (exists $input{only_with_tag} && length $input{only_with_tag})
576: ? $input{only_with_tag}
577: : 'HEAD';
578:
579: $tag = 'HEAD' if $tag eq 'MAIN';
580:
581: if (system($CMD{cvs},
582: @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag, '-d',
583: "$tmpexportdir/$basedir", $module))
584: {
585: @fatal = ('500 Internal Error', 'cvs co failure: %s: %s', $!, $module);
586: } else {
587: $| = 1; # Essential to get the buffering right.
588:
589: if ($ext eq '.tar.gz') {
590: print "Content-Type: application/x-gzip\r\n\r\n";
591:
592: system("$CMD{tar} @tar_options -cf - -C $tmpexportdir $basedir | $CMD{gzip} @gzip_options -c")
593: and @fatal =
594: ('500 Internal Error', 'tar zc failure: %s: %s', $!, $basedir);
595: } elsif ($ext eq '.zip' && $CMD{zip}) {
596: print "Content-Type: application/zip\r\n\r\n";
597:
598: system("cd $tmpexportdir && $CMD{zip} @zip_options -r - $basedir")
599: and @fatal =
600: ('500 Internal Error', 'zip failure: %s: %s', $!, $basedir);
601: } else {
602: @fatal = ('500 Internal Error', 'unsupported file type');
603: }
604: }
3.46 knu 605:
3.120 scop 606: system($CMD{rm}, '-rf', $tmpexportdir) if -d $tmpexportdir;
3.46 knu 607:
3.120 scop 608: &fatal(@fatal) if @fatal;
3.46 knu 609:
3.120 scop 610: exit;
3.46 knu 611: }
612:
3.1 knu 613: ##############################
614: # View a directory
615: ###############################
3.46 knu 616: if (-d $fullname) {
3.120 scop 617: my $dh = do { local (*DH); };
618: opendir($dh, $fullname) or fatal("404 Not Found", '%s: %s', $where, $!);
619: my @dir = readdir($dh);
620: closedir($dh);
621: my @subLevelFiles = findLastModifiedSubdirs(@dir)
622: if ($show_subdir_lastmod);
623: getDirLogs($cvsroot, $where, @subLevelFiles);
624:
625: if ($where eq '/') {
626: html_header($defaulttitle);
627: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
628: print $long_intro;
629: } else {
630: html_header($where);
631: print $short_instruction;
632: }
633:
634: if ($use_descriptions && open(DESC, "<$cvsroot/CVSROOT/descriptions")) {
635: while (<DESC>) {
636: chomp;
637: my ($dir, $description) = /(\S+)\s+(.*)/;
638: $descriptions{$dir} = $description;
639: }
640: close(DESC);
641: }
642:
643: print "<p><a name=\"dirlist\"></a></p>\n";
644:
645: # give direct access to dirs
646: if ($where eq '/') {
647: chooseMirror();
648: chooseCVSRoot();
649: } else {
650: print "<p>Current directory: <b>", &clickablePath($where, 0), "</b></p>\n";
651:
652: print "<p>Current tag: <b>", $input{only_with_tag}, "</b></p>\n"
653: if $input{only_with_tag};
654:
655: }
656:
657: print "<hr noshade>\n";
658:
659: # Using <menu> in this manner violates the HTML2.0 spec but
660: # provides the results that I want in most browsers. Another
661: # case of layout spooging up HTML.
662:
663: my $infocols = 0;
664: if ($dirtable) {
665: print "<table style=\"border-width: 0";
666: print "; background-color: $tableBorderColor"
667: if (defined $tableBorderColor);
668: print
669: "\" width=\"100%\" cellspacing=\"1\" cellpadding=\"$tablepadding\">\n";
670: $infocols++;
671: printf "<tr>\n<th style=\"text-align: left; background-color: %s\">",
672: $byfile
673: ? $columnHeaderColorSorted
674: : $columnHeaderColorDefault;
675:
676: if ($byfile) {
677: print 'File';
678: } else {
679: print &link('File',
680: sprintf('./%s#dirlist', toggleQuery('sortby', 'file')));
681: }
682: print "</th>\n";
683:
684: # do not display the other column-headers, if we do not have any files
685: # with revision information:
686: if (scalar(%fileinfo)) {
687: $infocols++;
688: printf '<th style="text-align: left; background-color: %s">',
689: $byrev
690: ? $columnHeaderColorSorted
691: : $columnHeaderColorDefault;
692:
693: if ($byrev) {
694: print 'Rev.';
695: } else {
696: print &link('Rev.',
697: sprintf('./%s#dirlist', toggleQuery('sortby', 'rev')));
698: }
699: print "</th>\n";
700: $infocols++;
701: printf '<th style="text-align: left; background-color: %s">',
702: $bydate
703: ? $columnHeaderColorSorted
704: : $columnHeaderColorDefault;
705:
706: if ($bydate) {
707: print 'Age';
708: } else {
709: print &link('Age',
710: sprintf('./%s#dirlist', toggleQuery('sortby', 'date')));
711: }
712: print "</th>\n";
713:
714: if ($show_author) {
715: $infocols++;
716: printf '<th style="text-align: left; background-color: %s">',
717: $byauthor
718: ? $columnHeaderColorSorted
719: : $columnHeaderColorDefault;
720:
721: if ($byauthor) {
722: print 'Author';
723: } else {
724: print
725: &link('Author',
726: sprintf('./%s#dirlist', toggleQuery('sortby', 'author')));
727: }
728: print "</th>\n";
729: }
730: $infocols++;
731: printf '<th style="text-align: left; background-color: %s">',
732: $bylog
733: ? $columnHeaderColorSorted
734: : $columnHeaderColorDefault;
735:
736: if ($bylog) {
737: print 'Last log entry';
738: } else {
739: print &link('Last log entry',
740: sprintf('./%s#dirlist', toggleQuery('sortby', 'log')));
741: }
742: print "</th>\n";
743: } elsif ($use_descriptions) {
744: printf '<th style="text-align: left; background-color: s">',
745: $columnHeaderColorDefault;
746: print "Description</th>\n";
747: $infocols++;
748: }
749: print "</tr>\n";
750: } else {
751: print "<menu>\n";
752: }
753: my $dirrow = 0;
754:
755: my $i;
756: lookingforattic:
757: for ($i = 0; $i <= $#dir; $i++) {
758: if ($dir[$i] eq "Attic") {
759: last lookingforattic;
760: }
761: }
762:
763: if (!$input{'hideattic'}
764: && ($i <= $#dir)
765: && opendir($dh, $fullname . '/Attic'))
766: {
767: splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
768: closedir($dh);
769: }
770:
771: my $hideAtticToggleLink =
772: $input{'hideattic'}
773: ? ''
774: : &link('[Hide]', sprintf('./%s#dirlist', &toggleQuery('hideattic')));
775:
776: # Sort without the Attic/ pathname.
777: # place directories first
778:
779: my $attic;
780: my $url;
781: my $fileurl;
782: my $filesexists;
783: my $filesfound;
784:
785: foreach my $file (sort { &fileSortCmp } @dir) {
786:
787: next if ($file eq '.');
788:
789: # ignore CVS lock and stale NFS files
790: next if ($file =~ /^\#cvs\.|^,|^\.nfs/); # \# for XEmacs cperl-mode...
791:
792: # Check whether to show the CVSROOT path
793: next if ($input{'hidecvsroot'} && $file eq 'CVSROOT');
794:
795: # Check whether the module is in the restricted list
796: next if ($file && &forbidden_module($file));
797:
798: # Ignore non-readable files
799: next if ($input{'hidenonreadable'} && !(-r "$fullname/$file"));
800:
801: if ($file =~ s|^Attic/||) {
802: $attic = ' (in the Attic) ' . $hideAtticToggleLink;
803: } else {
804: $attic = '';
805: }
806:
807: if ($file eq '..' || -d "$fullname/$file") {
808: next if ($file eq '..' && $where eq '/');
809: my ($rev, $date, $log, $author, $filename) = @{$fileinfo{$file}}
810: if (defined($fileinfo{$file}));
811: printf "<tr style=\"background-color: %s\">\n<td>",
812: $tabcolors[$dirrow % 2]
813: if $dirtable;
814:
815: if ($file eq '..') {
816: $url = "../$query";
817: if ($nofilelinks) {
818: print $backicon;
819: } else {
820: print &link($backicon, $url);
821: }
822: print ' ', &link("Parent Directory", $url);
823: } else {
824: $url = './' . urlencode($file) . "/$query";
825: print "<a name=\"$file\"></a>";
826:
827: if ($nofilelinks) {
828: print $diricon;
829: } else {
830: print &link($diricon, $url);
831: }
832: print ' ', &link("$file/", $url), $attic;
833:
834: if ($file eq "Attic") {
835: print " ";
836: print &link('[Don\'t hide]',
837: sprintf('./%s#dirlist', &toggleQuery('hideattic')));
838: }
839: }
840:
841: # Show last change in dir
842: if ($filename) {
843: print "</td>\n<td> </td>\n<td> "
844: if ($dirtable);
845: if ($date) {
846: print " <i>", readableTime(time() - $date, 0), "</i>";
847: }
848:
849: if ($show_author) {
850: print "</td>\n<td> " if ($dirtable);
851: print $author;
852: }
853: print "</td>\n<td> " if ($dirtable);
854: $filename =~ s%^[^/]+/%%;
855: print "$filename/$rev";
856: print "<br>" if ($dirtable);
857:
858: if ($log) {
859: print ' <span style="font-size: smaller">',
860: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
861: print '...' if (length($log) > 80);
862: print '</span>';
863: }
864: } else {
865: my $dwhere = ($where ne '/' ? $where : '') . $file;
866:
867: if ($use_descriptions && defined $descriptions{$dwhere}) {
868: print '<td colspan="', ($infocols - 1), '"> '
869: if $dirtable;
870: print $descriptions{$dwhere};
871:
872: } elsif ($dirtable && $infocols > 1) {
873:
874: # close the row with the appropriate number of
875: # columns, so that the vertical seperators are visible
876: my ($cols) = $infocols;
877: while ($cols > 1) {
878: print "</td>\n<td> ";
879: $cols--;
880: }
881: }
882: }
883:
884: if ($dirtable) {
885: print "</td>\n</tr>\n";
886: } else {
887: print "<br>\n";
888: }
889: $dirrow++;
890: } elsif ($file =~ s/,v$//) {
891:
892: # Skip forbidden files now so we'll give no hint
893: # about their existence. This should probably have
894: # been done earlier, but it's straightforward here.
895: next if forbidden_file("$fullname/$file");
896:
897: $fileurl = ($attic ? 'Attic/' : '') . urlencode($file);
898: $url = './' . $fileurl . $query;
899: $filesexists++;
900: next if (!defined($fileinfo{$file}));
901: my ($rev, $date, $log, $author) = @{$fileinfo{$file}};
902: $filesfound++;
903: printf "<tr style=\"background-color: %s\">\n<td>",
904: $tabcolors[$dirrow % 2]
905: if $dirtable;
906: print "<a name=\"$file\"></a>";
907:
908: if ($nofilelinks) {
909: print $fileicon;
910: } else {
911: print &link($fileicon, $url);
912: }
913: print ' ', &link(htmlquote($file), $url), $attic;
914: print "</td>\n<td> " if ($dirtable);
915: download_link($fileurl, $rev, $rev,
916: $defaultViewable
917: ? "text/x-cvsweb-markup"
918: : undef);
919: print "</td>\n<td> " if ($dirtable);
920:
921: if ($date) {
922: print " <i>", readableTime(time() - $date, 0), "</i>";
923: }
924: if ($show_author) {
925: print "</td>\n<td> " if ($dirtable);
926: print $author;
927: }
928: print "</td>\n<td> " if ($dirtable);
929:
930: if ($log) {
931: print ' <span style="font-size: smaller">',
932: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
933: print '...' if (length $log > 80);
934: print '</span>';
935: }
936: print($dirtable ? "</td>\n</tr>" : '<br>');
937: $dirrow++;
938: }
939: print "\n";
940: }
941:
942: print($dirtable ? "</table>\n" : "</menu>\n");
943:
944: if ($filesexists && !$filesfound) {
945: print
946: "<p><b>NOTE:</b> There are $filesexists files, but none matches the current tag ($input{only_with_tag}).</p>\n";
947: }
948:
949: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
950: %tags = %alltags;
951: }
952:
953: if (scalar %tags
954: || $input{only_with_tag}
955: || $edit_option_form
956: || defined($input{"options"}))
957: {
958: print "<hr size=\"1\" noshade>\n";
959: }
960:
961: if (scalar %tags || $input{only_with_tag}) {
962: print "<form method=\"get\" action=\"./\">\n";
963: foreach my $var (@stickyvars) {
964: print "<input type=\"hidden\" name=\"$var\" value=\"$input{$var}\">\n"
965: if (defined($input{$var})
966: && (!defined($DEFAULTVALUE{$var})
967: || $input{$var} ne $DEFAULTVALUE{$var})
968: && $input{$var} ne ""
969: && $var ne 'only_with_tag');
970: }
971: print "<p><label for=\"only_with_tag\" accesskey=\"T\">";
972: print "Show only files with tag:</label>\n";
973: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
974: print " onchange=\"this.form.submit()\"" if $use_java_script;
975: print ">";
976: print "<option value=\"\">All tags / default branch</option>\n";
977:
978: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
979: print "<option", defined($input{only_with_tag})
980: && $input{only_with_tag} eq $tag ? " selected" : "",
981: ">$tag</option>\n";
982: }
983: print "</select>\n";
984: print " <label for=\"path\" accesskey=\"P\">";
985: print "Module path or alias:</label>\n";
986: printf "<input type=\"text\" id=\"path\" name=\"path\" value=\"%s\" size=\"15\">\n", htmlquote($where);
987: print "<input type=\"submit\" value=\"Go\" accesskey=\"G\"></p>\n";
988: print "</form>\n";
989: }
990:
991: if ($allow_tar) {
992: my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
993:
994: if (defined($basefile) && $basefile ne '') {
995: print "<hr noshade>\n",
996: "<div align=\"center\">Download this directory in ";
997:
998: # Mangle the filename so browsers show a reasonable
999: # filename to download.
1000: print
1001: &link("tarball",
1002: "./$basefile.tar.gz$query" . ($query ? "&" : "?") . "tarball=1");
1003: if ($CMD{zip}) {
1004: print " or ",
1005: &link("zip archive",
1006: "./$basefile.zip$query" . ($query ? "&" : "?") . "tarball=1");
1007: }
1008: print "</div>\n";
1009: }
1010: }
1011:
1012: if ($edit_option_form || defined($input{"options"})) {
1013:
1014: my $formwhere = $scriptwhere;
1015: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
1016:
1017: print "<form method=\"get\" action=\"${formwhere}\">\n";
1018: print "<input type=\"hidden\" name=\"copt\" value=\"1\">\n";
1019: if ($cvstree ne $cvstreedefault) {
1020: print "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\">\n";
1021: }
1022: print "<center>\n<table cellpadding=\"0\" cellspacing=\"0\">";
1023: print "\n<tr style=\"background-color: $columnHeaderColorDefault\">\n";
1024: print "<th colspan=\"2\">Preferences</th>\n</tr>\n";
1025: print "<tr>\n<td>";
1026: print "<label for=\"sortby\" accesskey=\"F\">Sort files by ";
1027: print "</label><select id=\"sortby\" name=\"sortby\">\n";
1028: print "<option value=\"\">File</option>\n";
1029: print "<option", $bydate ? " selected" : "",
1030: " value=\"date\">Age</option>\n";
1031: print "<option", $byauthor ? " selected" : "",
1032: " value=\"author\">Author</option>\n"
1033: if ($show_author);
1034: print "<option", $byrev ? " selected" : "",
1035: " value=\"rev\">Revision</option>\n";
1036: print "<option", $bylog ? " selected" : "",
1037: " value=\"log\">Log message</option>\n";
1038: print "</select>\n</td>\n";
1039: print "<td><label for=\"logsort\" accesskey=\"L\">";
1040: print "Sort log by: </label>";
1041: printLogSortSelect(0);
1042: print "</td>\n</tr>\n";
1043: print "<tr>\n<td><label for=\"f\" accesskey=\"D\">";
1044: print "Diff format: </label>";
1045: printDiffSelect(0);
1046: print "</td>\n";
1047: print "<td><label for=\"hideattic\" accesskey=\"A\">";
1048: print "Show Attic files: </label>";
1049: print "<input id=\"hideattic\" name=\"hideattic\" type=\"checkbox\"",
1050: $input{'hideattic'} ? " checked" : "", "></td>\n</tr>\n";
1051: print "<tr>\n<td align=\"center\" colspan=\"2\">";
1052: print "<input type=\"submit\" value=\"Change Options\" accesskey=\"C\">";
1053: print "</td>\n</tr>\n</table>\n</center>\n</form>\n";
1054: }
1055: html_footer();
3.80 knu 1056: }
3.1 knu 1057:
1058: ###############################
1059: # View Files
1060: ###############################
3.80 knu 1061: elsif (-f $fullname . ',v') {
3.114 scop 1062:
3.120 scop 1063: if (forbidden_file($fullname)) {
1064: fatal('403 Forbidden',
1065: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1066: return;
1067: }
1068:
1069: if (defined($input{'rev'}) || $doCheckout) {
1070: &doCheckout($fullname, $input{'rev'});
1071: gzipclose();
1072: exit;
1073: }
1074:
1075: if (defined($input{'annotate'}) && $allow_annotate) {
1076: &doAnnotate($input{'annotate'});
1077: gzipclose();
1078: exit;
1079: }
1080:
1081: if (defined($input{'r1'}) && defined($input{'r2'})) {
1082: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1083: $input{'r2'}, $input{'tr2'}, $input{'f'});
1084: gzipclose();
1085: exit;
1086: }
1087: print("going to dolog($fullname)\n") if ($verbose);
1088: &doLog($fullname);
1089:
1090: ##############################
1091: # View Diff
1092: ##############################
1093: } elsif ($fullname =~ s/\.diff$//
1094: && -f $fullname . ",v"
1095: && $input{'r1'}
1096: && $input{'r2'})
1097: {
1098:
1099: # $where-diff-removal if 'cvs rdiff' is used
1100: # .. but 'cvs rdiff'doesn't support some options
1101: # rcsdiff does (-w and -p), so it is disabled
1102: # $where =~ s/\.diff$//;
1103:
1104: # Allow diffs using the ".diff" extension
1105: # so that browsers that default to the URL
1106: # for a save filename don't save diff's as
1107: # e.g. foo.c
1108: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1109: $input{'r2'}, $input{'tr2'}, $input{'f'});
1110: gzipclose();
1111: exit;
1112: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1|
1113: && -f $newname . ",v")
1114: {
1115:
1116: # The file has been removed and is in the Attic.
1117: # Send a redirect pointing to the file in the Attic.
1118: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1119: if ($ENV{QUERY_STRING} ne "") {
1120: redirect("${newplace}?$ENV{QUERY_STRING}");
1121: } else {
1122: redirect($newplace);
1123: }
1124: exit;
3.80 knu 1125: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.120 scop 1126: http_header("text/plain");
1127: print "You matched the following files:\n";
1128: print join ("\n", @files);
3.80 knu 1129:
3.120 scop 1130: # Find the tags from each file
1131: # Display a form offering diffs between said tags
3.80 knu 1132: } else {
3.120 scop 1133: my $fh = do { local (*FH); };
1134: my ($xtra, $module);
3.80 knu 1135:
3.120 scop 1136: # Assume it's a module name with a potential path following it.
1137: $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
3.80 knu 1138:
3.120 scop 1139: # Is there an indexed version of modules?
1140: if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1141: while (<$fh>) {
1142: if (/^(\S+)\s+(\S+)/o
1143: && $module eq $1
1144: && -d "$cvsroot/$2"
1145: && $module ne $2)
1146: {
1147: redirect("$scriptname/$2$xtra$query");
1148: }
1149: }
1150: }
1151: fatal("404 Not Found", '%s: no such file or directory', $where);
3.80 knu 1152: }
3.23 knu 1153:
3.25 knu 1154: gzipclose();
3.80 knu 1155:
3.1 knu 1156: ## End MAIN
1157:
3.120 scop 1158: sub printDiffSelect($)
1159: {
1160: my ($use_java_script) = @_;
1161: my $f = $input{'f'};
1162:
1163: print '<select id="f" name="f"';
1164: print ' onchange="this.form.submit()"' if $use_java_script;
1165: print ">\n";
1166:
1167: local $_;
1168: for (@DIFFTYPES) {
1169: printf("<option value=\"%s\"%s>%s</option>\n",
1170: $_, $f eq $_ ? ' selected' : '',
1171: "\u$DIFFTYPES{$_}{'descr'}");
1172: }
1173:
1174: print "</select>";
1175: }
1176:
1177: sub printLogSortSelect($)
1178: {
1179: my ($use_java_script) = @_;
1180:
1181: print '<select id="logsort" name="logsort"';
1182: print ' onchange="this.form.submit()"' if $use_java_script;
1183: print ">\n";
1184:
1185: local $_;
1186: for (@LOGSORTKEYS) {
1187: printf("<option value=\"%s\"%s>%s</option>\n",
1188: $_, $logsort eq $_ ? ' selected' : '',
1189: "\u$LOGSORTKEYS{$_}{'descr'}");
1190: }
1191:
1192: print "</select>";
1193: }
1194:
1195: sub findLastModifiedSubdirs(@)
1196: {
1197: my (@dirs) = @_;
1198: my ($dirname, @files);
1199:
1200: foreach $dirname (@dirs) {
1201: next if ($dirname eq ".");
1202: next if ($dirname eq "..");
1203: my ($dir) = "$fullname/$dirname";
1204: next if (!-d $dir);
1205:
1206: my ($lastmod) = undef;
1207: my ($lastmodtime) = undef;
1208: my $dh = do { local (*DH); };
1209:
1210: opendir($dh, $dir) or next;
1211: my (@filenames) = readdir($dh);
1212: closedir($dh);
1213:
1214: foreach my $filename (@filenames) {
1215: $filename = "$dirname/$filename";
1216: my ($file) = "$fullname/$filename";
1217: next if ($filename !~ /,v$/ || !-f $file);
1218:
1219: # Skip forbidden files.
1220: (my $f = $file) =~ s/,v$//;
1221: next if forbidden_file($f);
1222:
1223: $filename =~ s/,v$//;
1224: my $modtime = -M $file;
1225:
1226: if (!defined($lastmod) || $modtime < $lastmodtime) {
1227: $lastmod = $filename;
1228: $lastmodtime = $modtime;
1229: }
1230: }
1231: push (@files, $lastmod) if (defined($lastmod));
1232: }
1233: return @files;
1234: }
1235:
1236: sub htmlify_sub(&$)
1237: {
1238: (my $proc, local $_) = @_;
1239: my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
1240: my $linked;
1241: my $result = '';
1242:
1243: while (($_, $linked) = splice(@a, 0, 2)) {
1244: &$proc();
1245: $result .= $_ if defined($_);
1246: $result .= $linked if defined($linked);
1247: }
1248:
1249: $result;
1250: }
1251:
1252: sub htmlify($;$)
1253: {
1254: (local $_, my $extra) = @_;
1255:
1256: $_ = htmlquote($_);
1257:
1258: # get URL's as link
1259: s{
1260: (http|ftp|https)://\S+
1261: }{
1262: &link($&, htmlunquote($&))
1263: }egx;
1264:
1265: # get e-mails as link
1266: $_ = htmlify_sub {
1267: s<
1268: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1269: ><
1270: &link($&, "mailto:$&")
1271: >egix;
1272: } $_;
1273:
1274: if ($extra) {
1275:
1276: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1277: if (defined($prcgi) && defined($re_prkeyword)) {
1278: my $prev;
1279:
1280: do {
1281: $prev = $_;
1282:
1283: $_ = htmlify_sub {
1284: s{
1285: (\b$re_prkeyword[:\#]?\s*
1286: (?:
1287: \#?
1288: \d+[,\s]\s*
1289: )*
1290: \#?)
1291: (\d+)\b
1292: }{
1293: $1 . &link($2, sprintf($prcgi, $2))
1294: }egix;
1295: } $_;
1296: } while ($_ ne $prev);
1297:
1298: if (defined($re_prcategories)) {
1299: $_ = htmlify_sub {
1300: s{
1301: (\b$re_prcategories/(\d+)\b)
1302: }{
1303: &link($1, sprintf($prcgi, $2))
1304: }egox;
1305: } $_;
1306: }
1307: }
1308:
1309: # get manpage specs as link: "foo.1" "foo(1)"
1310: if (defined($mancgi)) {
1311: $_ = htmlify_sub {
1312: s{
1313: (\b([a-zA-Z][\w.]+)
1314: (?:
1315: \( ([0-9n]) \)\B
1316: |
1317: \.([0-9n])\b
1318: )
1319: )
1320: }{
1321: &link($1, sprintf($mancgi, defined($3) ? $3 : $4, $2))
1322: }egx;
1323: } $_;
1324: }
1325: }
1326:
1327: $_;
1328: }
1329:
1330: sub spacedHtmlText($;$)
1331: {
1332: local $_ = $_[0];
1333: my $ts = $_[1] || $tabstop;
1334:
1335: # Cut trailing spaces and tabs
1336: s/[ \t]+$//;
1337:
1338: if (defined($ts)) {
1339:
1340: # Expand tabs
1341: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1342: }
1343:
1344: # replace <tab> and <space> (\001 is to protect us from htmlify)
1345: # gzip can make excellent use of this repeating pattern :-)
1346: if ($hr_breakable) {
1347:
1348: # make every other space 'breakable'
1349: s/ / \001nbsp;/g; # 2 * <space>
1350: # leave single space as it is
1351: } else {
1352: s/ /\001nbsp;/g;
1353: }
1354:
1355: $_ = htmlify($_, $allow_source_extra);
1356:
1357: # unescape
1358: y/\001/&/;
1359:
1360: return $_;
1361: }
1362:
1363: # Note that this doesn't htmlquote the first argument...
1364: sub link($$)
1365: {
1366: my ($name, $url) = @_;
1367:
1368: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1369: if $url =~ /^[^a-z]/; # relative
1370:
1371: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1372: }
1373:
1374: sub revcmp($$)
1375: {
1376: my ($rev1, $rev2) = @_;
1377:
1378: # make no comparison for a tag or a branch
1379: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1380:
1381: my (@r1) = split (/\./, $rev1);
1382: my (@r2) = split (/\./, $rev2);
1383: my ($a, $b);
1384:
1385: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1386: if ($a != $b) {
1387: return $a <=> $b;
1388: }
1389: }
1390: if (@r1) { return 1; }
1391: if (@r2) { return -1; }
1392: return 0;
1393: }
1394:
1395: sub fatal($$@)
1396: {
1397: my ($errcode, $format, @args) = @_;
1398: if ($is_mod_perl) {
1399: Apache->request->status((split (/ /, $errcode))[0]);
1400: } else {
1401: print "Status: $errcode\r\n";
1402: }
1403: html_header("Error");
1404: print "<p>Error: ", sprintf($format, map(htmlquote($_), @args)), "</p>\n";
1405: html_footer();
1406: exit(1);
1407: }
1408:
1409: sub redirect($)
1410: {
1411: my ($url) = @_;
1412: if ($is_mod_perl) {
1413: Apache->request->status(301);
1414: Apache->request->header_out(Location => $url);
1415: } else {
1416: print "Status: 301 Moved\r\n";
1417: print "Location: $url\r\n";
1418: }
1419: html_header("Moved");
1420: print "<p>This document is located ", &link('here', $url), "</p>\n";
1421: html_footer();
1422: exit(1);
1423: }
1424:
1425: sub safeglob($)
1426: {
1427: my ($filename) = @_;
1428: my ($dirname);
1429: my (@results);
1430: my $dh = do { local (*DH); };
1431:
1432: ($dirname = $filename) =~ s|/[^/]+$||;
1433: $filename =~ s|.*/||;
1434:
1435: if (opendir($dh, $dirname)) {
1436: my $glob = $filename;
1437: my $t;
1438:
1439: # transform filename from glob to regex. Deal with:
1440: # [, {, ?, * as glob chars
1441: # make sure to escape all other regex chars
1442: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1443: $glob =~ s/\*/.*/g;
1444: $glob =~ s/\?/./g;
1445: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1446: foreach (readdir($dh)) {
1447:
1448: if (/^${glob}$/) {
1449: push (@results, "$dirname/" . $_);
1450: }
1451: }
1452: closedir($dh);
1453: }
1454:
1455: @results;
1456: }
1457:
1458: sub search_path($)
1459: {
1460: my ($command) = @_;
1461: my $d;
1462:
1463: for $d (split (/:/, $command_path)) {
1464: return "$d/$command" if -x "$d/$command";
1465: }
1466:
1467: return '';
1468: }
1469:
1470: sub getMimeTypeFromSuffix($)
1471: {
1472: my ($fullname) = @_;
1473: my ($mimetype, $suffix);
1474: my $fh = do { local (*FH); };
1475:
1476: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1477: $mimetype = $MTYPES{$suffix};
1478: $mimetype = $MTYPES{'*'} if (!$mimetype);
1479:
1480: if (!$mimetype && -f $mime_types) {
1481:
1482: # okey, this is something special - search the
1483: # mime.types database
1484: open($fh, "<$mime_types");
1485: while (<$fh>) {
1486: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1487: $mimetype = $1;
1488: last;
1489: }
1490: }
1491: close($fh);
1492: }
1493:
1494: # okey, didn't find anything useful ..
1495: if (!($mimetype =~ /\S\/\S/)) {
1496: $mimetype = "text/plain";
1497: }
1498: return $mimetype;
3.1 knu 1499: }
1500:
1501: ###############################
3.24 knu 1502: # read first lines like head(1)
1503: ###############################
3.120 scop 1504: sub head($;$)
1505: {
1506: my $fh = $_[0];
1507: my $linecount = $_[1] || 10;
3.24 knu 1508:
3.120 scop 1509: my @buf;
1510:
1511: if ($linecount > 0) {
1512: my $i;
1513: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1514: push @buf, scalar <$fh>;
1515: }
1516: } else {
1517: @buf = <$fh>;
1518: }
1519:
1520: @buf;
3.24 knu 1521: }
1522:
1523: ###############################
1524: # scan vim and Emacs directives
1525: ###############################
3.120 scop 1526: sub scan_directives(@)
1527: {
1528: my $ts = undef;
3.24 knu 1529:
3.120 scop 1530: for (@_) {
1531: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1532: }
3.24 knu 1533:
3.120 scop 1534: ('tabstop' => $ts);
3.24 knu 1535: }
1536:
3.120 scop 1537: sub openOutputFilter()
1538: {
1539: return if !defined($output_filter) || $output_filter eq '';
3.86 knu 1540:
3.120 scop 1541: open(STDOUT, "|-") and return;
3.86 knu 1542:
3.120 scop 1543: # child of child
1544: open(STDERR, '>/dev/null');
1545: exec($output_filter) or exit -1;
3.86 knu 1546: }
1547:
3.24 knu 1548: ###############################
3.1 knu 1549: # show Annotation
1550: ###############################
3.120 scop 1551: sub doAnnotate($$)
1552: {
1553: my ($rev) = @_;
1554: my ($pid);
1555: my ($pathname, $filename);
1556: my $reader = do { local (*FH); };
1557: my $writer = do { local (*FH); };
1558:
1559: # make sure the revisions are wellformed, for security
1560: # reasons ..
1561: if ($rev =~ /[^\w.]/) {
1562: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1563: }
1564:
1565: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1566: ($filename = $where) =~ s/^.*\///;
1567:
1568: # this seems to be necessary
1569: $| = 1;
1570: $| = 0; # Flush
1571:
1572: # this annotate version is based on the
1573: # cvs annotate-demo Perl script by Cyclic Software
1574: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1575: # the public domain.
1576: # we could abandon the use of rlog, rcsdiff and co using
1577: # the cvsserver in a similiar way one day (..after rewrite)
1578: $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
1579: or fatal("500 Internal Error",
1580: 'Fatal Error - unable to open cvs for annotation');
1581:
1582: # OK, first send the request to the server. A simplified example is:
1583: # Root /home/kingdon/zwork/cvsroot
1584: # Argument foo/xx
1585: # Directory foo
1586: # /home/kingdon/zwork/cvsroot/foo
1587: # Directory .
1588: # /home/kingdon/zwork/cvsroot
1589: # annotate
1590: # although as you can see there are a few more details.
1591:
1592: print $writer "Root $cvsroot\n";
1593: print $writer
1594: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1595:
1596: # Don't worry about sending valid-requests, the server just needs to
1597: # support "annotate" and if it doesn't, there isn't anything to be done.
1598: print $writer "UseUnchanged\n";
1599: print $writer "Argument -r\n";
1600: print $writer "Argument $rev\n";
1601: print $writer "Argument $where\n";
1602:
3.123 scop 1603: # We'll use this later to check if we have write access to all necessary
1604: # directories, and can avoid using -n in annotate.
1605: my $need_n;
1606:
3.120 scop 1607: # The protocol requires us to fully fake a working directory (at
1608: # least to the point of including the directories down to the one
1609: # containing the file in question).
3.123 scop 1610: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1611: my $path = '';
1612: foreach my $dir (split('/', $where)) {
3.120 scop 1613:
1614: if ($path eq "") {
3.123 scop 1615: # In our example, $dir is "dir".
1616: $path = $dir;
3.120 scop 1617: } else {
1618: print $writer "Directory $path\n";
1619: print $writer "$cvsroot/$path\n";
1620:
3.123 scop 1621: # One non-writable dir is enough to require us to use -n later.
1622: $need_n ||= ! -w "$cvsroot/$path";
1623:
3.120 scop 1624: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1625: # And the next time, "file" and "dir/sdir/file" (which then gets
1626: # ignored, because we don't need to send Directory for the file).
3.123 scop 1627: $path .= "/$dir";
3.120 scop 1628: }
1629: }
3.123 scop 1630: undef $path;
3.120 scop 1631:
1632: # And the last "Directory" before "annotate" is the top level.
1633: print $writer "Directory .\n";
1634: print $writer "$cvsroot\n";
3.123 scop 1635:
1636: print $writer "Global_option -n\n" if $need_n;
3.120 scop 1637:
1638: print $writer "annotate\n";
1639:
1640: # OK, we've sent our command to the server. Thing to do is to
1641: # close the writer side and get all the responses. If "cvs server"
1642: # were nicer about buffering, then we could just leave it open, I think.
1643: close($writer) or die "cannot close: $!";
1644:
1645: http_header();
1646:
1647: navigateHeader($scriptwhere, $pathname, $filename, $rev, "annotate");
1648: print
1649: "<h3 style=\"text-align: center\">Annotation of $pathname$filename, Revision $rev</h3>\n";
1650:
1651: # Ready to get the responses from the server.
1652: # For example:
1653: # E Annotations for foo/xx
1654: # E ***************
1655: # M 1.3 (kingdon 06-Sep-97): hello
1656: # ok
1657: my ($lineNr) = 0;
1658: my ($oldLrev, $oldLusr) = ("", "");
1659: my ($revprint, $usrprint);
1660:
1661: if ($annTable) {
1662: print
1663: "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
1664: } else {
1665: print "<pre>";
1666: }
1667:
1668: # prefetch several lines
1669: my @buf = head($reader);
1670:
1671: my %d = scan_directives(@buf);
1672:
1673: while (@buf || !eof($reader)) {
1674: $_ = @buf ? shift @buf : <$reader>;
1675:
1676: my @words = split;
1677:
1678: # Adding one is for the (single) space which follows $words[0].
1679: my $rest = substr($_, length($words[0]) + 1);
1680: if ($words[0] eq "E") {
1681: next;
1682: } elsif ($words[0] eq "M") {
1683: $lineNr++;
1684: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1685: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1686: my $line = substr($_, 36);
1687: my $isCurrentRev = ($rev eq $lrev);
1688:
1689: # we should parse the date here ..
1690: if ($lrev eq $oldLrev) {
1691: $revprint = sprintf('%-8s', '');
1692: } else {
1693: $revprint = sprintf('%-8s', $lrev);
1694: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1695: $oldLusr = '';
1696: }
1697:
1698: if ($lusr eq $oldLusr) {
1699: $usrprint = '';
1700: } else {
1701: $usrprint = $lusr;
1702: }
1703: $oldLrev = $lrev;
1704: $oldLusr = $lusr;
1705:
1706: # Set bold for text-based browsers only - graphical
1707: # browsers show bold fonts a bit wider than regular fonts,
1708: # so it looks irregular.
1709: print "<b>" if ($isCurrentRev && $is_textbased);
1710:
1711: printf "%s%s %-8s %4d:", $revprint, $isCurrentRev ? '!' : ' ', $usrprint,
1712: $lineNr;
1713: print spacedHtmlText($line, $d{'tabstop'});
1714:
1715: print "</b>" if ($isCurrentRev && $is_textbased);
1716: } elsif ($words[0] eq "ok") {
1717:
1718: # We could complain about any text received after this, like the
1719: # CVS command line client. But for simplicity, we don't.
1720: } elsif ($words[0] eq "error") {
1721: fatal("500 Internal Error",
1722: 'Error occured during annotate: <b>%s</b>', $_);
1723: }
1724: }
1725:
1726: if ($annTable) {
1727: print "</table>";
1728: } else {
1729: print "</pre>";
1730: }
3.124 ! scop 1731: html_footer();
! 1732:
3.120 scop 1733: close($reader) or warn "cannot close: $!";
1734: wait;
3.1 knu 1735: }
1736:
1737: ###############################
1738: # make Checkout
1739: ###############################
3.120 scop 1740: sub doCheckout($$)
1741: {
1742: my ($fullname, $rev) = @_;
1743: my ($mimetype, $revopt);
1744: my $fh = do { local (*FH); };
1745:
1746: if ($rev eq 'HEAD' || $rev eq '.') {
1747: $rev = undef;
1748: }
1749:
1750: # make sure the revisions a wellformed, for security
1751: # reasons ..
1752: if (defined($rev) && $rev =~ /[^\w.]/) {
1753: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1754: }
1755:
1756: # get mimetype
1757: if (defined($input{"content-type"})
1758: && ($input{"content-type"} =~ /\S\/\S/))
1759: {
1760: $mimetype = $input{"content-type"};
1761: } else {
1762: $mimetype = &getMimeTypeFromSuffix($fullname);
1763: }
1764:
1765: if (defined($rev)) {
1766: $revopt = "-r$rev";
1767: if ($use_moddate) {
1768: readLog($fullname, $rev);
1769: $moddate = $date{$rev};
1770: }
1771: } else {
1772: $revopt = "-rHEAD";
1773:
1774: if ($use_moddate) {
1775: readLog($fullname);
1776: $moddate = $date{$symrev{HEAD}};
1777: }
1778: }
1779:
1780: ### just for the record:
1781: ### 'cvs co' seems to have a bug regarding single checkout of
1782: ### directories/files having spaces in it;
1783: ### this is an issue that should be resolved on cvs's side
1784: #
1785: # Safely for a child process to read from.
1786: if (!open($fh, "-|")) { # child
1787: # chdir to $tmpdir before to avoid non-readable cgi-bin directories
1788: chdir($tmpdir);
1789: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1790:
1791: # work around a bug of cvs -p; expand symlinks
1792: exec($CMD{cvs}, @cvs_options, '-d', abs_path($cvsroot), 'co', '-p',
1793: $revopt, $where)
1794: or exit -1;
1795: }
1796:
1797: if (eof($fh)) {
1798: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
1799: }
1800:
1801: #===================================================================
1802: #Checking out squid/src/ftp.c
1803: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1804: #VERS: 1.1.1.28.6.2
1805: #***************
1806:
1807: # Parse CVS header
1808: my ($revision, $filename, $cvsheader);
1809: $filename = "";
1810: while (<$fh>) {
1811: last if (/^\*\*\*\*/);
1812: $revision = $1 if (/^VERS: (.*)$/);
1813:
1814: if (/^Checking out (.*)$/) {
1815: $filename = $1;
1816: $filename =~ s/^\.\/*//;
1817: }
1818: $cvsheader .= $_;
1819: }
1820:
1821: if ($filename ne $where) {
1822: fatal("500 Internal Error",
1823: 'Unexpected output from cvs co: %s', $cvsheader);
1824: }
1825: $| = 1;
1826:
1827: if ($mimetype eq "text/x-cvsweb-markup") {
1828: &cvswebMarkup($fh, $fullname, $revision);
1829: } else {
1830: http_header($mimetype);
1831: print <$fh>;
1832: }
1833: close($fh);
1.12 fenner 1834: }
1835:
3.120 scop 1836: sub cvswebMarkup($$$)
1837: {
1838: my ($filehandle, $fullname, $revision) = @_;
1839: my ($pathname, $filename);
3.1 knu 1840:
3.120 scop 1841: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1842: ($filename = $where) =~ s/^.*\///;
1843: my ($fileurl) = urlencode($filename);
1844:
1845: http_header();
1846:
1847: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
1848: print "<hr noshade>";
1849: print "<table width=\"100%\">\n<tr>\n<td style=\"background-color: $markupLogColor\">";
1850: print "File: ", &clickablePath($where, 1);
1851: print " (";
1852: &download_link($fileurl, $revision, "download");
1853: print ")";
1854:
1855: if (!$defaultTextPlain) {
1856: print " (";
1857: &download_link($fileurl, $revision, "as text", "text/plain");
1858: print ")";
1859: }
1860: print "<br>\n";
1861:
1862: if ($show_log_in_markup) {
1863: readLog($fullname); #,$revision);
1864: printLog($revision, 0);
1865: } else {
1866: print "Version: <b>$revision</b><br>\n";
1867: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
1868: if $input{only_with_tag};
1869: }
1870: print "</td>\n</tr>\n</table>";
1871: my $url = download_url($fileurl, $revision, $mimetype);
1872: print "<hr noshade>";
1873:
1874: if ($mimetype =~ /^image/) {
1875: printf '<img src="%s" alt=""><br>', hrefquote("$url$barequery");
1876: } elsif ($mimetype =~ m%^application/pdf%) {
1877: printf '<embed src="%s" width="100%"><br>', hrefquote("$url$barequery");
1878: } elsif ($preformat_in_markup) {
1879: print "<pre>";
1880:
1881: # prefetch several lines
1882: my @buf = head($filehandle);
1883:
1884: my %d = scan_directives(@buf);
1885:
1886: while (@buf || !eof($filehandle)) {
1887: $_ = @buf ? shift @buf : <$filehandle>;
1888:
1889: print spacedHtmlText($_, $d{'tabstop'});
1890: }
1891: print "</pre>";
1892: } else {
1893: print "<pre>";
1894:
1895: while (<$filehandle>) {
1896: print htmlquote($_);
1897: }
1898: print "</pre>";
1899: }
1900: }
1901:
1902: sub viewable($)
1903: {
1904: my ($mimetype) = @_;
1905:
1906: $mimetype =~ m%^((text|image)/|application/pdf)%;
3.1 knu 1907: }
1908:
1909: ###############################
1910: # Show Colored Diff
1911: ###############################
3.120 scop 1912: sub doDiff($$$$$$)
1913: {
1914: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1915: my $fh = do { local (*FH); };
1916: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1917:
1918: if (&forbidden_file($fullname)) {
1919: fatal("403 Forbidden",
1920: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1921: }
1922:
1923: if ($r1 =~ /([^:]+)(:(.+))?/) {
1924: $rev1 = $1;
1925: $sym1 = $3;
1926: }
1927: if ($r1 eq 'text') {
1928: $rev1 = $tr1;
1929: $sym1 = "";
1930: }
1931:
1932: if ($r2 =~ /([^:]+)(:(.+))?/) {
1933: $rev2 = $1;
1934: $sym2 = $3;
1935: }
1936: if ($r2 eq 'text') {
1937: $rev2 = $tr2;
1938: $sym2 = "";
1939: }
1940:
1941: # make sure the revisions a wellformed, for security
1942: # reasons ..
1943: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1944: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1945: }
1946:
1947: #
1948: # rev1 and rev2 are now both numeric revisions.
1949: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1950: # XXX should we warn about the fact that we do this?
1951: if (&revcmp($rev1, $rev2) > 0) {
1952: my ($tmp1, $tmp2) = ($rev1, $sym1);
1953: ($rev1, $sym1) = ($rev2, $sym2);
1954: ($rev2, $sym2) = ($tmp1, $tmp2);
1955: }
1956: my $difftype = $DIFFTYPES{$f};
1957:
1958: if (!$difftype) {
1959: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
1960: }
1961:
1962: my @difftype = @{$difftype->{'opts'}};
1963: my $human_readable = $difftype->{'colored'};
1964:
1965: # apply special options
1966: if ($showfunc) {
1967: push @difftype, '-p' if $f ne 's';
1968:
1969: my ($re1, $re2);
1970:
1971: while (($re1, $re2) = each %funcline_regexp) {
1972: if ($fullname =~ /$re1/) {
1973: push @difftype, '-F', $re2;
1974: last;
1975: }
1976: }
1977: }
1978:
1979: if ($human_readable) {
1980: if ($hr_ignwhite) {
1981: push @difftype, '-w';
1982: }
1983: if ($hr_ignkeysubst) {
1984: push @difftype, '-kk';
1985: }
1986: }
1987:
1988: if (!open($fh, "-|")) { # child
1989: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1990: openOutputFilter();
1991: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1;
1992: }
1993: if ($human_readable) {
1994: http_header();
1995: &human_readable_diff($fh, $rev2);
1996: html_footer();
1997: gzipclose();
1998: exit;
1999: } else {
2000: http_header("text/plain");
2001: }
2002:
2003: #
2004: #===================================================================
2005: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2006: #retrieving revision 1.16
2007: #retrieving revision 1.17
2008: #diff -c -r1.16 -r1.17
2009: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2010: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2011: #
2012: # Ideas:
2013: # - nuke the stderr output if it's what we expect it to be
2014: # - Add "no differences found" if the diff command supplied no output.
2015: #
2016: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2017: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2018: # (bogus example, but...)
2019: #
2020: if (grep { $_ eq '-u' } @difftype) {
2021: $f1 = '---';
2022: $f2 = '\+\+\+';
2023: } else {
2024: $f1 = '\*\*\*';
2025: $f2 = '---';
2026: }
2027:
2028: while (<$fh>) {
2029: if (m|^$f1 $cvsroot|o) {
2030: s|$cvsroot/||o;
2031: if ($sym1) {
2032: chop;
2033: $_ .= " $sym1\n";
2034: }
2035: } elsif (m|^$f2 $cvsroot|o) {
2036: s|$cvsroot/||o;
2037:
2038: if ($sym2) {
2039: chop;
2040: $_ .= " $sym2\n";
2041: }
2042: }
2043: print $_;
2044: }
2045: close($fh);
1.12 fenner 2046: }
2047:
3.1 knu 2048: ###############################
2049: # Show Logs ..
2050: ###############################
3.120 scop 2051: sub getDirLogs($$@)
2052: {
2053: my ($cvsroot, $dirname, @otherFiles) = @_;
2054: my ($state, $otherFiles, $tag, $file, $date, $branchpoint, $branch, $log);
2055: my ($rev, $revision, $revwanted, $filename, $head, $author);
2056:
2057: $tag = $input{only_with_tag};
2058:
2059: my ($DirName) = "$cvsroot/$where";
2060: my (@files, @filetags);
2061: my $fh = do { local (*FH); };
2062:
2063: push (@files, &safeglob("$DirName/*,v"));
2064: push (@files, &safeglob("$DirName/Attic/*,v"))
2065: if (!$input{'hideattic'});
2066: foreach my $file (@otherFiles) {
2067: push (@files, "$DirName/$file");
2068: }
2069:
2070: # just execute rlog if there are any files
2071: return unless @files;
2072:
2073: if (defined($tag)) {
2074:
2075: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
2076: if (!open($fh, "-|")) { # child
2077: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
2078: openOutputFilter();
2079: exec($CMD{rlog}, @files) or exit -1;
2080: }
2081: } else {
2082:
2083: if (!open($fh, "-|")) { # child
2084: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
2085: openOutputFilter();
2086: exec($CMD{rlog}, '-r', @files) or exit -1;
2087: }
2088: }
2089: $state = "start";
2090:
2091: while (<$fh>) {
2092: if ($state eq "start") {
2093:
2094: #Next file. Initialize file variables
2095: $rev = '';
2096: $revwanted = '';
2097: $branch = '';
2098: $branchpoint = '';
2099: $filename = '';
2100: $log = '';
2101: $revision = '';
2102: %symrev = ();
2103: @filetags = ();
2104:
2105: #jump to head state
2106: $state = "head";
2107: }
2108: print "$state:$_" if ($verbose);
2109: again:
2110:
2111: if ($state eq "head") {
2112:
2113: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2114:
2115: if (/^Working file: (.+)$/) {
2116: $filename = $1;
2117: } elsif (/^head: (.+)$/) {
2118: $head = $1;
2119: } elsif (/^branch: (.+)$/) {
2120: $branch = $1;
2121: } elsif (/^symbolic names:/) {
2122: $state = "tags";
2123: ($branch = $head) =~ s/\.\d+$//
2124: if $branch eq '';
2125: $branch =~ s/(\d+)$/0.$1/;
2126: $symrev{MAIN} = $branch;
2127: $symrev{HEAD} = $branch;
2128: $alltags{MAIN} = 1;
2129: $alltags{HEAD} = 1;
2130: push (@filetags, "MAIN", "HEAD");
2131: } elsif (/$LOG_REVSEPARATOR/o) {
2132: $state = "log";
2133: $rev = '';
2134: $date = '';
2135: $log = '';
2136:
2137: # Try to reconstruct the relative filename if RCS spits out a full path
2138: $filename =~ s%^\Q$DirName\E/%%;
2139: }
2140: next;
2141: }
2142:
2143: if ($state eq "tags") {
2144: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2145: push (@filetags, $1);
2146: $symrev{$1} = $2;
2147: $alltags{$1} = 1;
2148: next;
2149: } elsif (/^\S/) {
2150:
2151: if (defined($tag)) {
2152: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2153: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2154: ($branch = $revwanted) =~ s/\b0\.//;
2155: ($branchpoint = $branch) =~ s/\.?\d+$//;
2156: $revwanted = '' if ($revwanted ne $branch);
2157: } elsif ($tag ne "HEAD") {
2158: print "Tag not found, skip this file" if ($verbose);
2159: $state = "skip";
2160: next;
2161: }
2162: }
2163:
2164: foreach my $tagfound (@filetags) {
2165: $tags{$tagfound} = 1;
2166: }
2167: $state = "head";
2168: goto again;
2169: }
2170: }
2171:
2172: if ($state eq "log") {
2173: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2174:
2175: # End of a log entry.
2176: my $revbranch = $rev;
2177: $revbranch =~ s/\.\d+$//;
2178: print "$filename $rev Wanted: $revwanted ",
2179: "Revbranch: $revbranch Branch: $branch ",
2180: "Branchpoint: $branchpoint\n"
2181: if ($verbose);
2182:
2183: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2184: || !defined($tag))
2185: {
2186: print "File revision $rev found for branch $branch\n"
2187: if ($verbose);
2188: $revwanted = $rev;
2189: }
2190:
2191: if ($revwanted ne ''
2192: ? $rev eq $revwanted
2193: : $branchpoint ne ''
2194: ? $rev eq $branchpoint
2195: : 0
2196: && ($rev eq $head))
2197: { # Don't think head is needed here..
2198: print "File info $rev found for $filename\n"
2199: if ($verbose);
2200: my @finfo = ($rev, $date, $log, $author, $filename);
2201: my ($name);
2202: ($name = $filename) =~ s%/.*%%;
2203: $fileinfo{$name} = [@finfo];
2204: $state = "done" if ($rev eq $revwanted);
2205: }
2206: $rev = '';
2207: $date = '';
2208: $log = '';
2209: } elsif ($date eq ''
2210: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2211: {
2212: my $yr = $1;
2213:
2214: # damn 2-digit year routines :-)
2215: if ($yr > 100) {
2216: $yr -= 1900;
2217: }
2218: $date = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2219: ($author) = /author: ([^;]+)/;
2220: $state = "log";
2221: $log = '';
2222: next;
2223: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2224: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2225: next;
2226: } else {
2227: $log .= $_;
2228: }
2229: }
2230:
2231: if (/$LOG_FILESEPARATOR/o) {
2232: $state = "start";
2233: next;
2234: }
2235: }
2236:
2237: if ($. == 0) {
2238: fatal("500 Internal Error",
2239: 'Failed to spawn GNU rlog on <em>"%s"</em>. <p>Did you set the <b>$command_path</b> in your configuration file correctly ? (Currently "%s"',
2240: join (", ", @files),
2241: $command_path);
2242: }
2243: close($fh);
2244: }
2245:
2246: sub readLog($;$)
2247: {
2248: my ($fullname, $revision) = @_;
2249: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2250: my $fh = do { local (*FH); };
2251:
2252: if (defined($revision)) {
2253: $revision = "-r$revision";
2254: } else {
2255: $revision = "";
2256: }
2257:
2258: undef %symrev;
2259: undef %revsym;
2260: undef @allrevisions;
2261: undef %date;
2262: undef %author;
2263: undef %state;
2264: undef %difflines;
2265: undef %log;
2266:
2267: print("Going to rlog '$fullname'\n") if ($verbose);
2268: if (!open($fh, "-|")) { # child
2269: if ($revision ne '') {
2270: openOutputFilter();
2271: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2272: } else {
2273: openOutputFilter();
2274: exec($CMD{rlog}, $fullname) or exit -1;
2275: }
2276: }
2277:
2278: while (<$fh>) {
2279: print if ($verbose);
2280: if ($symnames) {
2281: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2282: $symrev{$1} = $2;
2283: } else {
2284: $symnames = 0;
2285: }
2286: } elsif (/^head:\s+([\d\.]+)/) {
2287: $head = $1;
2288: } elsif (/^branch:\s+([\d\.]+)/) {
2289: $curbranch = $1;
2290: } elsif (/^symbolic names/) {
2291: $symnames = 1;
2292: } elsif (/^-----/) {
2293: last;
2294: }
2295: }
2296: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2297:
2298: # each log entry is of the form:
2299: # ----------------------------
2300: # revision 3.7.1.1
2301: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2302: # log info
2303: # ----------------------------
2304:
2305: # For a locked revision, the first line after the separator
2306: # becomes smth like
2307: # revision 9.19 locked by: vassilii;
2308:
2309: logentry:
2310:
2311: while (!/$LOG_FILESEPARATOR/o) {
2312: $_ = <$fh>;
2313: last logentry if (!defined($_)); # EOF
2314: print "R:", $_ if ($verbose);
2315: if (/^revision (\d+(?:\.\d+)+)/) {
2316: $rev = $1;
2317: unshift (@allrevisions, $rev);
2318: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2319: next logentry;
2320: } else {
2321:
2322: # The rlog output is syntactically ambiguous. We must
2323: # have guessed wrong about where the end of the last log
2324: # message was.
2325: # Since this is likely to happen when people put rlog output
2326: # in their commit messages, don't even bother keeping
2327: # these lines since we don't know what revision they go with
2328: # any more.
2329: next logentry;
2330: }
2331: $_ = <$fh>;
2332: print "D:", $_ if ($verbose);
2333: if (
2334: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2335: )
2336: {
2337: my $yr = $1;
2338:
2339: # damn 2-digit year routines :-)
2340: if ($yr > 100) {
2341: $yr -= 1900;
2342: }
2343: $date{$rev} = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2344: $author{$rev} = $7;
2345: $state{$rev} = $8;
2346: $difflines{$rev} = $10;
2347: } else {
2348: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2349: }
2350:
2351: line:
2352: while (<$fh>) {
2353: print "L:", $_ if ($verbose);
2354: next line if (/^branches:\s/);
2355: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2356: $log{$rev} .= $_;
2357: }
2358: print "E:", $_ if ($verbose);
2359: }
2360: close($fh);
2361: print "Done reading RCS file\n" if ($verbose);
2362:
2363: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2364: print "Done sorting revisions", join (" ", @revorder), "\n"
2365: if ($verbose);
2366:
2367: #
2368: # HEAD is an artificial tag which is simply the highest tag number on the main
2369: # branch, unless there is a branch tag in the RCS file in which case it's the
2370: # highest revision on that branch. Find it by looking through @revorder; it
2371: # is the first commit listed on the appropriate branch.
2372: # This is not neccesary the same revision as marked as head in the RCS file.
2373: my $headrev = $curbranch || "1";
2374: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2375:
2376: foreach $rev (@revorder) {
2377: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2378: $symrev{"HEAD"} = $rev;
2379: last;
2380: }
2381: }
2382: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2383: if (!defined($symrev{"HEAD"}));
2384: print "Done finding HEAD\n" if ($verbose);
2385:
2386: #
2387: # Now that we know all of the revision numbers, we can associate
2388: # absolute revision numbers with all of the symbolic names, and
2389: # pass them to the form so that the same association doesn't have
2390: # to be built then.
2391: #
2392: undef @branchnames;
2393: undef %branchpoint;
2394: undef $sel;
2395:
2396: foreach (reverse sort keys %symrev) {
2397: $rev = $symrev{$_};
2398: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2399: push (@branchnames, $_);
2400:
2401: #
2402: # A revision number of A.B.0.D really translates into
2403: # "the highest current revision on branch A.B.D".
2404: #
2405: # If there is no branch A.B.D, then it translates into
2406: # the head A.B .
2407: #
2408: # This reasoning also applies to the main branch A.B,
2409: # with the branch number 0.A, with the exception that
2410: # it has no head to translate to if there is nothing on
2411: # the branch, but I guess this can never happen?
2412: #
2413: # (the code below gracefully forgets about the branch
2414: # if it should happen)
2415: #
2416: $head = defined($2) ? $2 : "";
2417: $branch = $3;
2418: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2419: my $regex;
2420: $regex = quotemeta $branchrev;
2421: $rev = $head;
2422:
2423: foreach my $r (@revorder) {
2424: if ($r =~ /^${regex}\b/) {
2425: $rev = $branchrev;
2426: last;
2427: }
2428: }
2429: next if ($rev eq "");
2430:
2431: if ($rev ne $head && $head ne "") {
2432: $branchpoint{$head} .= ", "
2433: if ($branchpoint{$head});
2434: $branchpoint{$head} .= $_;
2435: }
2436: }
2437: $revsym{$rev} .= ", " if ($revsym{$rev});
2438: $revsym{$rev} .= $_;
2439: $sel .= "<option value=\"${rev}:${_}\">$_</option>\n";
2440: }
2441: print "Done associating revisions with branches\n" if ($verbose);
2442:
2443: my ($onlyonbranch, $onlybranchpoint);
2444: if ($onlyonbranch = $input{'only_with_tag'}) {
2445: $onlyonbranch = $symrev{$onlyonbranch};
2446: if ($onlyonbranch =~ s/\b0\.//) {
2447: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2448: } else {
2449: $onlybranchpoint = $onlyonbranch;
2450: }
2451:
2452: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2453: fatal("404 Tag not found", 'Tag %s not defined',
2454: $input{'only_with_tag'});
2455: }
2456: }
2457:
2458: undef @revisions;
2459:
2460: foreach (@allrevisions) {
2461: ($br = $_) =~ s/\.\d+$//;
2462: ($brp = $br) =~ s/\.\d+$//;
2463: next if ($onlyonbranch
2464: && $br ne $onlyonbranch
2465: && $_ ne $onlybranchpoint);
2466: unshift (@revisions, $_);
2467: }
2468:
2469: if ($logsort eq "date") {
2470:
2471: # Sort the revisions in commit order an secondary sort on revision
2472: # (secondary sort needed for imported sources, or the first main
2473: # revision gets before the same revision on the 1.1.1 branch)
2474: @revdisplayorder =
2475: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2476: } elsif ($logsort eq "rev") {
2477:
2478: # Sort the revisions in revision order, highest first
2479: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2480: } else {
2481:
2482: # No sorting. Present in the same order as rlog / cvs log
2483: @revdisplayorder = @revisions;
2484: }
2485:
2486: }
2487:
2488: sub printDiffLinks($$)
2489: {
2490: my ($text, $url) = @_;
2491: my @extra;
2492:
2493: local $_;
2494: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2495: my $f = $_ eq $defaultDiffType ? '' : $_;
2496:
2497: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2498: }
2499:
2500: print &link($text, $url), ' (', join (', ', @extra), ')';
2501: }
2502:
2503: sub printLog($;$)
2504: {
2505: my ($link, $br, $brp);
2506: ($_, $link) = @_;
2507: ($br = $_) =~ s/\.\d+$//;
2508: ($brp = $br) =~ s/\.?\d+$//;
2509: my ($isDead, $prev);
2510:
2511: $link = 1 if (!defined($link));
2512: $isDead = ($state{$_} eq "dead");
2513:
2514: print "<p>\n";
2515: if ($link && !$isDead) {
2516: my ($filename);
2517: ($filename = $where) =~ s/^.*\///;
2518: my ($fileurl) = urlencode($filename);
2519: print "<a name=\"rev$_\"></a>";
2520:
2521: if (defined($revsym{$_})) {
2522: foreach my $sym (split (", ", $revsym{$_})) {
2523: print "<a name=\"$sym\"></a>";
2524: }
2525: }
2526:
2527: if (defined($revsym{$br})
2528: && $revsym{$br}
2529: && !defined($nameprinted{$br}))
2530: {
2531: foreach my $sym (split (", ", $revsym{$br})) {
2532: print "<a name=\"$sym\"></a>";
2533: }
2534: $nameprinted{$br} = 1;
2535: }
2536: print "\n Revision ";
2537: &download_link($fileurl, $_, $_,
2538: $defaultViewable ? "text/x-cvsweb-markup" : undef);
2539:
2540: if ($defaultViewable) {
2541: print " / (";
2542: &download_link($fileurl, $_, "download", $mimetype);
2543: print ")";
2544: }
2545:
2546: if (not $defaultTextPlain) {
2547: print " / (";
2548: &download_link($fileurl, $_, "as text", "text/plain");
2549: print ")";
2550: }
2551:
2552: if (!$defaultViewable) {
2553: print " / (";
2554: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2555: print ")";
2556: }
2557:
2558: if ($allow_annotate) {
2559: print " - ";
2560: print &link('annotate',
2561: sprintf('%s/%s?annotate=%s%s',
2562: $scriptname, urlencode($where), $_, $barequery));
2563: }
2564:
2565: # Plus a select link if enabled, and this version isn't selected
2566: if ($allow_version_select) {
3.121 scop 2567: if (!defined($input{"r1"}) || $input{"r1"} ne $_) {
3.120 scop 2568: print " - ";
2569: print &link('[select for diffs]',
2570: sprintf('%s?r1=%s%s', $scriptwhere, $_, $barequery));
2571: } else {
2572: print " - <b>[selected]</b>";
2573: }
2574: }
2575: } else {
2576: print "Revision <b>$_</b>";
2577: }
2578:
2579: if (/^1\.1\.1\.\d+$/) {
2580: print " <i>(vendor branch)</i>";
2581: }
2582: if (defined @mytz) {
2583: my ($est) = $mytz[(localtime($date{$_}))[8]];
2584: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
2585: } else {
2586: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
2587: }
2588: print readableTime(time() - $date{$_}, 1), " ago)";
2589: print " by ";
2590: print "<i>", $author{$_}, "</i>\n";
2591: print "<br>Branch: <b>", $link ? link_tags($revsym{$br}) : $revsym{$br},
2592: "</b>\n"
2593: if ($revsym{$br});
2594: print "<br>CVS Tags: <b>", $link ? link_tags($revsym{$_}) : $revsym{$_},
2595: "</b>"
2596: if ($revsym{$_});
2597: print "<br>Branch point for: <b>",
2598: $link ? link_tags($branchpoint{$_}) : $branchpoint{$_}, "</b>\n"
2599: if ($branchpoint{$_});
2600:
2601: # Find the previous revision
2602: my @prevrev = split (/\./, $_);
2603: do {
2604: if (--$prevrev[$#prevrev] <= 0) {
2605:
2606: # If it was X.Y.Z.1, just make it X.Y
2607: pop (@prevrev);
2608: pop (@prevrev);
2609: }
2610: $prev = join (".", @prevrev);
2611: } until (defined($date{$prev}) || $prev eq "");
2612:
2613: if ($prev ne "") {
2614: if ($difflines{$_}) {
2615: print "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
2616: }
2617: }
2618:
2619: if ($isDead) {
2620: print "<br><b><i>FILE REMOVED</i></b>\n";
2621: } elsif ($link) {
2622: my %diffrev = ();
2623: $diffrev{$_} = 1;
2624: $diffrev{""} = 1;
2625: print '<br>';
2626: my $diff = 'Diff';
2627:
2628: #
2629: # Offer diff to previous revision
2630: if ($prev) {
2631: $diffrev{$prev} = 1;
2632:
2633: my $url =
2634: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $prev, $_, $barequery);
2635:
2636: print $diff, " to previous ";
2637: $diff = '';
2638: printDiffLinks($prev, $url);
2639: }
2640:
2641: #
2642: # Plus, if it's on a branch, and it's not a vendor branch,
2643: # offer a diff with the branch point.
2644: if ($revsym{$brp}
2645: && !/^1\.1\.1\.\d+$/
2646: && !defined($diffrev{$brp}))
2647: {
2648: my $url =
2649: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp, $_, $barequery);
2650:
2651: print $diff, " to branchpoint ";
2652: $diff = '';
2653: printDiffLinks($brp, $url);
2654: }
2655:
2656: #
2657: # Plus, if it's on a branch, and it's not a vendor branch,
2658: # offer to diff with the next revision of the higher branch.
2659: # (e.g. change gets committed and then brought
2660: # over to -stable)
2661: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2662: my ($i, $nextmain);
2663:
2664: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2665: }
2666: my @tmp2 = split (/\./, $_);
2667: for ($nextmain = ""; $i > 0; $i--) {
2668: my $next = $revorder[$i - 1];
2669: my @tmp1 = split (/\./, $next);
2670:
2671: if (@tmp1 < @tmp2) {
2672: $nextmain = $next;
2673: last;
2674: }
2675:
2676: # Only the highest version on a branch should have
2677: # a diff for the "next main".
2678: last
2679: if (@tmp1 - 1 <= @tmp2
2680: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2681: join (".", @tmp2[0 .. $#tmp1 - 1]));
2682: }
2683:
2684: if (!defined($diffrev{$nextmain})) {
2685: $diffrev{$nextmain} = 1;
2686:
2687: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2688: $scriptwhere, $nextmain, $_, $barequery);
2689:
2690: print $diff, " next main ";
2691: $diff = '';
2692: printDiffLinks($nextmain, $url);
2693: }
2694: }
2695:
2696: # Plus if user has selected only r1, then present a link
2697: # to make a diff to that revision
2698: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2699: $diffrev{$input{"r1"}} = 1;
2700:
2701: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2702: $scriptwhere, $input{'r1'}, $_, $barequery);
2703:
2704: print $diff, " to selected ";
2705: $diff = '';
2706: printDiffLinks($input{'r1'}, $url);
2707: }
2708:
2709: }
2710: print "\n</p>\n<pre>\n";
2711: print &htmlify($log{$_}, $allow_log_extra);
2712: print "</pre>\n";
2713: }
2714:
2715: sub doLog($)
2716: {
2717: my ($fullname) = @_;
2718: my ($diffrev, $upwhere, $filename, $backurl);
2719:
2720: readLog($fullname);
2721:
2722: html_header("CVS log for $where");
2723: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2724: ($filename = $where) =~ s|^.*/||;
2725: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2726: print "<p>\n ";
2727: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
2728: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2729: print "<p>\n ";
2730: print &link('Request diff between arbitrary revisions', '#diff');
2731: print "\n</p>\n<hr noshade>\n";
2732:
2733: print "<p>\n";
2734: if ($curbranch) {
2735: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2736: } else {
2737: print "No default branch";
2738: }
2739: print "<br>\n";
2740:
2741: if ($input{only_with_tag}) {
2742: print "Current tag: $input{only_with_tag}<br>\n";
2743: }
2744: print "</p>\n";
2745:
2746: undef %nameprinted;
2747:
2748: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2749: print "<hr size=\"1\" noshade>\n";
2750: printLog($revdisplayorder[$i]);
2751: }
2752:
2753: print "<hr noshade>\n<p>\n";
2754: print "<a name=\"diff\">\n";
2755: print "This form allows you to request diff's between any two\n";
2756: print "revisions of a file. You may select a symbolic revision\n";
2757: print "name using the selection box or you may type in a numeric\n";
2758: print "name using the type-in text box.\n";
2759: print "</a>\n</p>\n";
2760: print
2761: "<form method=\"get\" action=\"${scriptwhere}.diff\" name=\"diff_select\">\n";
2762:
2763: foreach (@stickyvars) {
2764: printf('<input type="hidden" name="%s" value="%s">', $_, $input{$_})
2765: if (defined($input{$_})
2766: && ((!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})
2767: && $input{$_} ne ""));
2768: }
2769: print "<table style=\"border: none\">\n<tr>\n";
2770: print "<td align=\"right\">";
2771: print "<label for=\"r1\" accesskey=\"1\">Diffs between </label>\n";
2772: print "<select id=\"r1\" name=\"r1\">\n";
2773: print "<option value=\"text\" selected>Use Text Field</option>\n";
2774: print $sel;
2775: print "</select>\n";
2776: $diffrev = $revdisplayorder[$#revdisplayorder];
2777: $diffrev = $input{"r1"} if (defined($input{"r1"}));
2778: print
2779: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr1\" value=\"$diffrev\" onchange=\"this.form.r1.selectedIndex=0\"></td>\n";
2780: print "<td><br></td>\n</tr>\n";
2781: print "<tr>\n<td align=\"right\">";
2782: print "<label for=\"r2\" accesskey=\"2\">and </label>\n";
2783: print "<select id=\"r2\" name=\"r2\">\n";
2784: print "<option value=\"text\" selected>Use Text Field</option>\n";
2785: print $sel;
2786: print "</select>\n";
2787: $diffrev = $revdisplayorder[0];
2788: $diffrev = $input{"r2"} if (defined($input{"r2"}));
2789: print
2790: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr2\" value=\"$diffrev\" onchange=\"this.form.r2.selectedIndex=0\"></td>\n";
2791: print
2792: "<td><input type=\"submit\" value=\" Get Diffs \" accesskey=\"G\"></td>\n";
2793: print "</tr>\n</table>\n";
2794: print "</form>\n";
2795: print "<hr noshade>\n";
2796: print "<form method=\"get\" action=\"$scriptwhere\">\n";
2797: print "<table style=\"border: none\">\n";
2798: print "<tr>\n<td align=\"right\">";
2799: print "<label for=\"f\" accesskey=\"D\">Preferred Diff type:";
2800: print "</label></td>\n";
2801: print "<td>";
2802: printDiffSelect($use_java_script);
2803: print "</td>\n<td></td>\n</tr>\n";
2804:
2805: if (@branchnames) {
2806: print "<tr>\n<td align=\"right\">";
2807: print "<label for=\"only_with_tag\" accesskey=\"B\">";
2808: print "View only Branch:</label></td>\n";
2809: print "<td>";
2810: print "<a name=\"branch\"></a>\n";
2811: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
2812: print " onchange=\"this.form.submit()\"" if $use_java_script;
2813: print ">\n";
2814: print "<option value=\"\"";
2815: print " selected"
2816: if (defined($input{"only_with_tag"})
2817: && $input{"only_with_tag"} eq "");
2818: print ">Show all branches</option>\n";
2819:
2820: foreach (reverse sort @branchnames) {
2821: print "<option";
2822: print " selected"
2823: if (defined($input{"only_with_tag"})
2824: && $input{"only_with_tag"} eq $_);
2825: print ">${_}</option>\n";
2826: }
2827: print "</select></td>\n<td></td>\n</tr>\n";
2828: }
2829:
2830: foreach (@stickyvars) {
2831: next if ($_ eq "f");
2832: next if ($_ eq "only_with_tag");
2833: next if ($_ eq "logsort");
2834: print "<input type=\"hidden\" name=\"$_\" value=\"$input{$_}\">\n"
2835: if (defined($input{$_})
2836: && (!defined($DEFAULTVALUE{$_})
2837: || $input{$_} ne $DEFAULTVALUE{$_})
2838: && $input{$_} ne "");
2839: }
2840: print "<tr>\n<td align=\"right\">";
2841: print "<a name=\"logsort\"></a>\n";
2842: print "<label for=\"logsort\" accesskey=\"L\">Sort log by:";
2843: print "</label></td>\n<td>";
2844: printLogSortSelect($use_java_script);
2845: print "</td>\n";
2846: print "<td><input type=\"submit\" value=\" Set \" accesskey=\"S\"></td>\n";
2847: print "</tr>\n</table>\n";
2848: print "</form>\n";
2849: html_footer();
2850: }
2851:
2852: sub flush_diff_rows($$$$)
2853: {
2854: my $j;
2855: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
2856:
2857: if (!defined($state)) {
2858: return;
2859: }
2860:
2861: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2862: for ($j = 0; $j < $leftRow; $j++) {
2863: print "<tr>\n<td class=\"diff-removed\"> @$leftColRef[$j]</td>\n";
2864: print "<td class=\"diff-empty\"> </td>\n</tr>\n";
2865: }
2866: } elsif ($state eq "PreChange") { # state eq "PreChange"
2867: # we got removes with subsequent adds
2868:
2869: for ($j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump out both cols
2870: print "<tr>\n";
2871: if ($j < $leftRow) {
2872: print "<td class=\"diff-changed\"> @$leftColRef[$j]</td>";
2873: } else {
2874: print "<td class=\"diff-changed-missing\"> </td>";
2875: }
2876: print "\n";
2877:
2878: if ($j < $rightRow) {
2879: print "<td class=\"diff-changed\"> @$rightColRef[$j]</td>";
2880: } else {
2881: print "<td class=\"diff-changed-missing\"> </td>";
2882: }
2883: print "\n</tr>\n";
2884: }
2885: }
3.1 knu 2886: }
2887:
2888: ##
2889: # Function to generate Human readable diff-files
2890: # human_readable_diff(String revision_to_return_to);
2891: ##
3.120 scop 2892: sub human_readable_diff($)
2893: {
2894: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
2895: my ($fh, $rev) = @_;
2896: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2897: my (@rightCol, @leftCol);
2898:
2899: ($where_nd = $where) =~ s/.diff$//;
2900: ($filename = $where_nd) =~ s/^.*\///;
2901: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2902: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2903:
2904: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
2905:
2906: # Read header to pick up read revision and date, if possible
2907: while (<$fh>) {
2908: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2909: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2910: last if (/^\+\+\+ /);
2911: }
2912:
2913: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2914: $rev1 = $r1r;
2915: $date1 = $r1d;
2916: }
2917: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2918: $rev2 = $r2r;
2919: $date2 = $r2d;
2920: }
2921:
2922: print
2923: "<h3 style=\"text-align: center\">Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2924:
2925: # Using style=\"border: none\" here breaks NS 4.x badly...
2926: "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n",
2927: "<tr style=\"background-color: #ffffff\">\n",
2928: "<th width=\"50%\" valign=\"top\">", "version $rev1";
2929: print ", $date1" if (defined($date1));
2930: print "<br>Tag: $sym1\n" if ($sym1);
2931: print "</th>\n", "<th width=\"50%\" valign=\"top\">", "version $rev2";
2932: print ", $date2" if (defined($date2));
2933: print "<br>Tag: $sym2\n" if ($sym1);
2934: print "</th>\n";
2935:
2936: my $leftRow = 0;
2937: my $rightRow = 0;
2938: my ($oldline, $newline, $funname, $diffcode, $rest);
2939:
2940: # Process diff text
2941:
2942: # prefetch several lines
2943: my @buf = head($fh);
2944:
2945: my %d = scan_directives(@buf);
2946:
2947: while (@buf || !eof($fh)) {
2948: $difftxt = @buf ? shift @buf : <$fh>;
2949:
2950: if ($difftxt =~ /^@@/) {
2951: ($oldline, $newline, $funname) =
2952: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2953: $funname = htmlquote($funname);
2954: $funname =~ s/\s/ /go;
2955: print "<tr class=\"diff-heading\">\n<td width=\"50%\">";
2956: print
2957: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $oldline</b>";
2958: print
2959: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>";
2960: print "</td>\n<td width=\"50%\">";
2961: print
2962: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $newline</b>";
2963: print
2964: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>\n";
2965: print "</td>\n";
2966: $state = "dump";
2967: $leftRow = 0;
2968: $rightRow = 0;
2969: } else {
2970: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
2971: $_ = spacedHtmlText($rest, $d{'tabstop'});
2972:
2973: #########
2974: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2975: # in order to get some nice 'ediff'-mode output
2976: # states:
2977: # "dump" - just dump the value
2978: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2979: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2980: ##########
2981:
2982: if ($diffcode eq '+') {
2983: if ($state eq "dump")
2984: { # 'change' never begins with '+': just dump out value
2985: print
2986: "<tr>\n<td class=\"diff-empty\"> </td>\n<td class=\"diff-added\"> $_</td>\n</tr>\n";
2987: } else { # we got minus before
2988: $state = "PreChange";
2989: $rightCol[$rightRow++] = $_;
2990: }
2991: } elsif ($diffcode eq '-') {
2992: $state = "PreChangeRemove";
2993: $leftCol[$leftRow++] = $_;
2994: } else { # empty diffcode
2995: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2996: print
2997: "<tr>\n<td class=\"diff-same\"> $_</td>\n<td class=\"diff-same\"> $_</td>\n</tr>\n";
2998: $state = "dump";
2999: $leftRow = 0;
3000: $rightRow = 0;
3001: }
3002: }
3003: }
3004: close($fh);
3005:
3006: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3007:
3008: # state is empty if we didn't have any change
3009: if (!$state) {
3010: print "<tr>\n<td colspan=\"2\"> </td>\n</tr>\n";
3011: print "<tr class=\"diff-empty\">\n";
3012: print
3013: "<td colspan=\"2\" align=\"center\"><b>- No viewable change -</b></td>\n</tr>\n";
3014: }
3015: print "</table>\n";
3016:
3017: print "<hr style=\"width: 100%\" noshade>\n";
3018: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3019: print "<table style=\"border: none\">\n<tr>\n<td>\n";
3020:
3021: # print legend
3022: print "<table border=\"1\">\n<tr>\n<td>";
3023: print
3024: "Legend:<br><table style=\"border: none\" cellspacing=\"0\" cellpadding=\"1\">\n";
3025: print
3026: "<tr>\n<td align=\"center\" class=\"diff-removed\">Removed from v.$rev1</td>\n<td class=\"diff-empty\"> </td>\n</tr>\n";
3027: print
3028: "<tr class=\"diff-changed\">\n<td align=\"center\" colspan=\"2\">changed lines</td>\n</tr>\n";
3029: print
3030: "<tr>\n<td class=\"diff-empty\"> </td>\n<td align=\"center\" class=\"diff-added\">Added in v.$rev2</td>\n</tr>\n";
3031: print "</table>\n</td>\n</tr>\n</table>\n</td>\n<td>";
3032:
3033: # Print format selector
3034: foreach my $var (keys %input) {
3035: next if ($var eq "f");
3036: next if (defined($DEFAULTVALUE{$var})
3037: && $DEFAULTVALUE{$var} eq $input{$var});
3038: print "<input type=\"hidden\" name=\"", urlencode($var), "\" value=\"",
3039: urlencode($input{$var}), "\">\n";
3040: }
3041: printDiffSelect($use_java_script);
3042: print "<input type=\"submit\" value=\"Show\">\n";
3043: print "</td>\n";
3044:
3045: print "</tr>\n</table>\n";
3046: print "</form>\n";
3047: }
3048:
3049: sub navigateHeader($$$$$)
3050: {
3051: my ($swhere, $path, $filename, $rev, $title) = @_;
3052: $swhere = "" if ($swhere eq $scriptwhere);
3053: $swhere = './' . urlencode($filename) if ($swhere eq "");
3054:
3055: # TODO: this should be moved into external CSS file.
3056: my $css = '';
3057: if ($title eq 'diff') {
3058: $css = "
3.100 knu 3059: <style type=\"text/css\">
3060: .diff-heading {
3061: background-color: $diffcolorHeading;
3062: }
3063: .diff-same {
3064: font-family: $difffontface;
3065: font-size: smaller;
3066: }
3067: .diff-empty {
3068: background-color: $diffcolorEmpty;
3069: }
3070: .diff-added {
3071: background-color: $diffcolorAdd;
3072: font-family: $difffontface;
3073: font-size: smaller;
3074: }
3075: .diff-removed {
3076: background-color: $diffcolorRemove;
3077: font-family: $difffontface;
3078: font-size: smaller;
3079: }
3080: .diff-changed {
3081: background-color: $diffcolorChange;
3082: font-family: $difffontface;
3083: font-size: smaller;
3084: }
3085: .diff-changed-missing {
3086: background-color: $diffcolorDarkChange;
3087: }
3088: </style>";
3.120 scop 3089: }
3.100 knu 3090:
3.120 scop 3091: print <<EOF;
3.100 knu 3092: $HTML_DOCTYPE
3.89 knu 3093: <html>
3094: <head>
3.100 knu 3095: <title>$path$filename - $title - $rev</title>$css
3.106 scop 3096: $HTML_META</head>
3.64 knu 3097: $body_tag_for_src
3.100 knu 3098: <table width="100%" style="border: none; background-color: $navigationHeaderColor" cellspacing="0" cellpadding="1">
3.89 knu 3099: <tr valign="bottom"><td>
3.64 knu 3100: EOF
3101:
3.120 scop 3102: print &link($backicon, "$swhere$query#rev$rev");
3103: print "<b>Return to ", &link($filename, "$swhere$query#rev$rev"), " CVS log";
3104: print "</b> $fileicon</td>";
3105:
3106: print "<td align=\"right\">$diricon <b>Up to ", &clickablePath($path, 1),
3107: "</b></td>";
3108: print "</tr></table>";
3109: }
3110:
3111: sub plural_write($$)
3112: {
3113: my ($num, $text) = @_;
3114: if ($num != 1) {
3115: $text .= "s";
3116: }
3117:
3118: if ($num > 0) {
3119: return join (' ', $num, $text);
3120: } else {
3121: return "";
3122: }
3.1 knu 3123: }
3124:
3125: ##
3126: # print readable timestamp in terms of
3127: # '..time ago'
3128: # H. Zeller <zeller@think.de>
3129: ##
3.120 scop 3130: sub readableTime($$)
3131: {
3132: my ($i, $break, $retval);
3133: my ($secs, $long) = @_;
3134:
3135: # this function works correct for time >= 2 seconds
3136: if ($secs < 2) {
3137: return "very little time";
3138: }
3139:
3140: my %desc = (
3141: 1, 'second', 60, 'minute', 3600, 'hour',
3142: 86400, 'day', 604800, 'week', 2628000, 'month',
3143: 31536000, 'year'
3144: );
3145: my @breaks = sort { $a <=> $b } keys %desc;
3146: $i = 0;
3147:
3148: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3149: $i++;
3150: }
3151: $i--;
3152: $break = $breaks[$i];
3153: $retval = plural_write(int($secs / $break), $desc{$break});
3154:
3155: if ($long == 1 && $i > 0) {
3156: my $rest = $secs % $break;
3157: $i--;
3158: $break = $breaks[$i];
3159: my $resttime = plural_write(int($rest / $break), $desc{$break});
3160: if ($resttime) {
3161: $retval .= ", $resttime";
3162: }
3163: }
3.1 knu 3164:
3.120 scop 3165: return $retval;
3.1 knu 3166: }
3167:
3168: ##
3169: # clickablePath(String pathname, boolean last_item_clickable)
3170: #
3171: # returns a html-ified path whereas each directory is a link for
3172: # faster navigation. last_item_clickable controls whether the
3173: # basename (last directory/file) is a link as well
3174: ##
3.120 scop 3175: sub clickablePath($$)
3176: {
3177: my ($pathname, $clickLast) = @_;
3178: my $retval = '';
3179:
3180: if ($pathname eq '/') {
3181:
3182: # this should never happen - chooseCVSRoot() is
3183: # intended to do this
3184: $retval = "[$cvstree]";
3185: } else {
3186: $retval .=
3187: ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist', $scriptname, $query));
3188: my $wherepath = '';
3189: my ($lastslash) = $pathname =~ m|/$|;
3190:
3191: foreach (split (/\//, $pathname)) {
3192: $retval .= " / ";
3193: $wherepath .= "/$_";
3194: my ($last) = "$wherepath/" eq "/$pathname"
3195: || $wherepath eq "/$pathname";
3196:
3197: if ($clickLast || !$last) {
3198: $retval .= &link($_,
3199: join ('',
3200: $scriptname, urlencode($wherepath),
3201: (!$last || $lastslash ? '/' : ''), $query,
3202: (!$last || $lastslash ? "#dirlist" : "")));
3203: } else { # do not make a link to the current dir
3204: $retval .= $_;
3205: }
3206: }
3207: }
3208: return $retval;
3209: }
3210:
3211: sub chooseCVSRoot()
3212: {
3213:
3214: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3215: if (2 <= @CVSROOT) {
3216: my ($k);
3217: foreach $k (keys %input) {
3218: print "<input type=\"hidden\" name=\"$k\" value=\"$input{$k}\">\n"
3219: if ($input{$k}) && ($k ne "cvsroot");
3220: }
3221:
3222: # Form-Elements look wierd in Netscape if the background
3223: # isn't gray and the form elements are not placed
3224: # within a table ...
3225: print "<table style=\"border: none\">\n<tr>\n";
3226: print
3227: "<td><label for=\"cvsroot\" accesskey=\"C\">CVS Root:</label></td>\n";
3228: print "<td>\n<select id=\"cvsroot\" name=\"cvsroot\"";
3229: print " onchange=\"this.form.submit()\"" if $use_java_script;
3230: print ">\n";
3231:
3232: foreach $k (@CVSROOT) {
3233: print "<option value=\"$k\"";
3234: print " selected" if ($k eq $cvstree);
3235: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
3236: }
3237: print "</select>\n</td>\n<td>";
3238: } else {
3239:
3240: # no choice -- but we need the form to select module/path,
3241: # at least for Netscape
3242: print "<p>\n";
3243: print "CVS Root: <b>[$cvstree]</b>";
3244: }
3245:
3246: print " <label for=\"mpath\" accesskey=\"M\">Module path or alias:";
3247: print "</label>\n";
3248: print
3249: "<input type=\"text\" id=\"mpath\" name=\"path\" value=\"\" size=\"15\">\n";
3250: print "<input type=\"submit\" value=\"Go\" accesskey=\"O\">";
3251:
3252: if (2 <= @CVSROOT) {
3253: print "</td>\n</tr>\n</table>";
3254: } else {
3255: print "</p>";
3256: }
3257: print "\n</form>";
3258: }
3259:
3260: sub chooseMirror()
3261: {
3262:
3263: # This code comes from the original BSD-cvsweb
3264: # and may not be useful for your site; If you don't
3265: # set %MIRRORS this won't show up, anyway.
3266: scalar(%MIRRORS) or return;
3267:
3268: # Should perhaps exclude the current site somehow...
3269: print "\n<p>\nThis CVSweb is mirrored in\n";
3270:
3271: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3272: my $tmp = pop (@tmp);
3273:
3274: if (scalar(@tmp)) {
3275: print join (', ', @tmp), ' and ';
3276: }
3277:
3278: print "$tmp.\n</p>\n";
3279: }
3280:
3281: sub fileSortCmp()
3282: {
3283: my ($comp) = 0;
3284: my ($c, $d, $af, $bf);
3285:
3286: ($af = $a) =~ s/,v$//;
3287: ($bf = $b) =~ s/,v$//;
3288: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3289: if (defined($fileinfo{$af}));
3290: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3291: if (defined($fileinfo{$bf}));
3292:
3293: if ( defined($filename1)
3294: && defined($filename2)
3295: && $af eq $filename1
3296: && $bf eq $filename2)
3297: {
3298:
3299: # Two files
3300: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3301: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3302: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3303: $comp = ($author1 cmp $author2)
3304: if ($byauthor && $author1 && $author2);
3305: }
3306:
3307: if ($comp == 0) {
3308:
3309: # Directories first, then files under version control,
3310: # then other, "rogue" files.
3311: # Sort by filename if no other criteria available.
3312:
3313: my $ad = (
3314: (-d "$fullname/$a")
3315: ? 'D'
3316: : (defined($fileinfo{$af}) ? 'F' : 'R')
3317: );
3318: my $bd = (
3319: (-d "$fullname/$b")
3320: ? 'D'
3321: : (defined($fileinfo{$bf}) ? 'F' : 'R')
3322: );
3323: ($c = $a) =~ s|.*/||;
3324: ($d = $b) =~ s|.*/||;
3325: $comp = ("$ad$c" cmp "$bd$d");
3326: }
3327: return $comp;
3.1 knu 3328: }
3329:
3330: # make A url for downloading
3.120 scop 3331: sub download_url($$;$)
3332: {
3333: my ($url, $revision, $mimetype) = @_;
3.1 knu 3334:
3.120 scop 3335: $revision =~ s/\b0\.//;
3.1 knu 3336:
3.120 scop 3337: if (defined($checkoutMagic)
3338: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3339: {
3340: my $path = $where;
3341: $path =~ s|[^/]+$||;
3342: $url = "$scriptname/$checkoutMagic/${path}$url";
3343: }
3344: $url .= "?rev=$revision";
3345: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3346:
3.120 scop 3347: $url;
3.1 knu 3348: }
3349:
3.12 knu 3350: # Presents a link to download the
3.1 knu 3351: # selected revision
3.120 scop 3352: sub download_link($$$;$)
3353: {
3354: my ($url, $revision, $textlink, $mimetype) = @_;
3355: my ($fullurl) = download_url($url, $revision, $mimetype);
3356:
3357: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3358:
3359: printf '<a href="%s"', hrefquote("$fullurl$barequery");
3360:
3361: if ($open_extern_window
3362: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3363: {
3364: print ' target="cvs_checkout"';
3365:
3366: # we should have
3367: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3368: # in order to allow the user to resize the window; otherwise
3369: # the user may resize the window, but on next checkout - zap -
3370: # its original (configured s. cvsweb.conf) size is back again
3371: # .. annoying (if $extern_window_(width|height) is defined)
3372: # but this if (..) solution is far from perfect
3373: # what we need to do as well is
3374: # 1) save cvswin in an invisible frame that always exists
3375: # (document.cvswin will be void on next load)
3376: # 2) on close of the cvs_checkout - window set the cvswin
3377: # variable to 'null' again - so that it will be
3378: # reopenend with the configured size
3379: # anyone a JavaScript programmer ?
3380: # .. so here without if (..):
3381: # currently, the best way is to comment out the size parameters
3382: # ($extern_window...) in cvsweb.conf.
3383: if ($use_java_script) {
3384: my @attr = qw(resizable scrollbars);
3385:
3386: push @attr, qw(status toolbar)
3387: if (defined($mimetype) && $mimetype eq "text/html");
3388:
3389: push @attr, "width=$extern_window_width"
3390: if (defined($extern_window_width));
3391:
3392: push @attr, "height=$extern_window_height"
3393: if (defined($extern_window_height));
3394:
3395: # We need the "return false" here to prevent browsers
3396: # from following the href after the onclick handler.
3397: # This would effectively load the same document in
3398: # the same window *twice*.
3399: printf q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3400: hrefquote("$fullurl$barequery"), join (',', @attr);
3401: }
3402: }
3403: print "><b>$textlink</b></a>";
3.1 knu 3404: }
3405:
3406: # Returns a Query string with the
3407: # specified parameter toggled
3.120 scop 3408: sub toggleQuery($$)
3409: {
3410: my ($toggle, $value) = @_;
3411: my ($newquery, $var);
3412: my (%vars);
3413: %vars = %input;
3414:
3415: if (defined($value)) {
3416: $vars{$toggle} = $value;
3417: } else {
3418: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3419: }
3420:
3421: # Build a new query of non-default paramenters
3422: $newquery = "";
3423: foreach $var (@stickyvars) {
3424: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3425: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3426:
3427: if ($value ne $default) {
3428: $newquery .= "&" if ($newquery ne "");
3429: $newquery .= urlencode($var) . "=" . urlencode($value);
3430: }
3431: }
3432:
3433: if ($newquery) {
3434: return '?' . $newquery;
3435: }
3436: return "";
3437: }
3438:
3439: sub urlencode($)
3440: {
3441: local ($_) = @_;
3442:
3443: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3444:
3445: $_;
3446: }
3447:
3448: sub htmlquote($)
3449: {
3450: local ($_) = @_;
3451:
3452: # Special Characters; RFC 1866
3453: s/&/&/g;
3454: s/\"/"/g;
3455: s/</</g;
3456: s/>/>/g;
3457:
3458: $_;
3459: }
3460:
3461: sub htmlunquote($)
3462: {
3463: local ($_) = @_;
3464:
3465: # Special Characters; RFC 1866
3466: s/"/\"/g;
3467: s/</</g;
3468: s/>/>/g;
3469: s/&/&/g;
3470:
3471: $_;
3472: }
3473:
3474: sub hrefquote($)
3475: {
3476: local ($_) = @_;
3477:
3478: y/ /+/;
3479:
3480: htmlquote($_);
3481: }
3482:
3483: sub http_header(;$)
3484: {
3485: my $content_type = shift || "text/html";
3486:
3487: $content_type .= "; charset=$charset"
3488: if $content_type =~ m,^text/, && defined($charset) && $charset;
3489:
3490: if (defined($moddate)) {
3491: if ($is_mod_perl) {
3492: Apache->request->header_out(
3493: "Last-Modified" => scalar gmtime($moddate) . " GMT");
3494: } else {
3495: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3496: }
3497: }
3498:
3499: if ($is_mod_perl) {
3500: Apache->request->content_type($content_type);
3501: } else {
3502: print "Content-Type: $content_type\r\n";
3503: }
3504:
3505: if ($allow_compress && $maycompress) {
3506: if ($has_zlib
3507: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
3508: {
3509:
3510: if ($is_mod_perl) {
3511: Apache->request->content_encoding("x-gzip");
3512: Apache->request->header_out(Vary => "Accept-Encoding");
3513: Apache->request->send_http_header;
3514: } else {
3515: print "Content-Encoding: x-gzip\r\n";
3516: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3517: print "\r\n"; # Close headers
3518: }
3519: $| = 1;
3520: $| = 0; # Flush header output
3521:
3522: if ($has_zlib) {
3523: tie *GZIP, __PACKAGE__, \*STDOUT;
3524: }
3525: select(GZIP);
3526: $gzip_open = 1;
3527:
3528: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3529: } else {
3530: if ($is_mod_perl) {
3531: Apache->request->send_http_header;
3532: } else {
3533: print "\r\n"; # Close headers
3534: }
3535: print
3536: "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
3537: }
3538: } else {
3539:
3540: if ($is_mod_perl) {
3541: Apache->request->send_http_header;
3542: } else {
3543: print "\r\n"; # Close headers
3544: }
3545: }
3546: }
3547:
3548: sub html_header($)
3549: {
3550: my ($title) = @_;
3551: http_header("text/html");
3552: print <<EOH;
3.100 knu 3553: $HTML_DOCTYPE
3.1 knu 3554: <html>
3.40 knu 3555: <head>
3.1 knu 3556: <title>$title</title>
3.106 scop 3557: $HTML_META</head>
3.1 knu 3558: $body_tag
3559: $logo <h1 align="center">$title</h1>
3560: EOH
3561: }
3562:
3.120 scop 3563: sub html_footer()
3564: {
3565: print "<hr noshade>\n<address>$address</address>\n</body>\n</html>\n";
3.1 knu 3566: }
3567:
3.120 scop 3568: sub link_tags($)
3569: {
3570: my ($tags) = @_;
3571: my ($ret) = "";
3572: my ($fileurl, $filename);
3573:
3574: ($filename = $where) =~ s/^.*\///;
3575: $fileurl = './' . urlencode($filename);
3576:
3577: foreach my $sym (split (", ", $tags)) {
3578: $ret .= ",\n" if ($ret ne "");
3579: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag', $sym));
3580: }
3581: return "$ret\n";
3.1 knu 3582: }
3583:
3584: #
3.81 knu 3585: # See if a module is listed in the config file's @HideModules list.
3.1 knu 3586: #
3.120 scop 3587: sub forbidden_module($)
3588: {
3589: my ($module) = @_;
3590: local $_;
3591:
3592: for (@HideModules) {
3593: return 1 if $module =~ $_;
3594: }
3595: return 0;
3596: }
3597:
3598: sub forbidden_file($)
3599: {
3600: my ($path) = @_;
3601: $path = substr($path, length($cvsroot) + 1);
3602: local $_;
3603: for (@ForbiddenFiles) {
3604: return 1 if $path =~ $_;
3605: }
3606: return 0;
3.25 knu 3607: }
3608:
3609: # Close the GZIP handle remove the tie.
3610:
3.120 scop 3611: sub gzipclose
3612: {
3613: if ($gzip_open) {
3614: select(STDOUT);
3615: close(GZIP);
3616: untie *GZIP;
3617: $gzip_open = 0;
3618: }
3.23 knu 3619: }
3620:
3621: # implement a gzipped file handle via the Compress:Zlib compression
3622: # library.
3623:
3624: sub MAGIC1() { 0x1f }
3625: sub MAGIC2() { 0x8b }
3.80 knu 3626: sub OSCODE() { 3 }
3.23 knu 3627:
3.120 scop 3628: sub TIEHANDLE
3629: {
3630: my ($class, $out) = @_;
3631: my ($d) = Compress::Zlib::deflateInit(
3632: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3633: -WindowBits => -Compress::Zlib::MAX_WBITS()
3634: )
3635: or return undef;
3636: my ($o) = { handle => $out,
3637: dh => $d,
3638: crc => 0,
3639: len => 0,
3640: };
3641: my ($header) = pack("c10",
3642: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
3643: 0, 0, 0, 0, 0, 0, OSCODE);
3644: print {$o->{handle}} $header;
3645: return bless($o, $class);
3646: }
3647:
3648: sub PRINT
3649: {
3650: my ($o) = shift;
3651: my ($buf) = join (defined $, ? $, : "", @_);
3652: my ($len) = length($buf);
3653: my ($compressed, $status) = $o->{dh}->deflate($buf);
3654: print {$o->{handle}} $compressed if defined($compressed);
3655: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3656: $o->{len} += $len;
3657: return $len;
3658: }
3659:
3660: sub PRINTF
3661: {
3662: my ($o) = shift;
3663: my ($fmt) = shift;
3664: my ($buf) = sprintf($fmt, @_);
3665: my ($len) = length($buf);
3666: my ($compressed, $status) = $o->{dh}->deflate($buf);
3667: print {$o->{handle}} $compressed if defined($compressed);
3668: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3669: $o->{len} += $len;
3670: return $len;
3671: }
3672:
3673: sub WRITE
3674: {
3675: my ($o, $buf, $len, $off) = @_;
3676: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3677: print {$o->{handle}} $compressed if defined($compressed);
3678: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3679: $o->{len} += $len;
3680: return $len;
3681: }
3682:
3683: sub CLOSE
3684: {
3685: my ($o) = @_;
3686: return if !defined($o->{dh});
3687: my ($buf) = $o->{dh}->flush();
3688: $buf .= pack("V V", $o->{crc}, $o->{len});
3689: print {$o->{handle}} $buf;
3690: undef $o->{dh};
3691: }
3692:
3693: sub DESTROY
3694: {
3695: my ($o) = @_;
3696: CLOSE($o);
1.1 jfieber 3697: }
CVSweb