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