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