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