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