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