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