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