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