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