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