=================================================================== RCS file: /cvs/cvsweb/cvsweb.cgi,v retrieving revision 1.1.1.37 retrieving revision 4.40 diff -u -p -r1.1.1.37 -r4.40 --- cvsweb/cvsweb.cgi 2007/03/17 21:52:33 1.1.1.37 +++ cvsweb/cvsweb.cgi 2019/11/30 13:08:41 4.40 @@ -1,4 +1,6 @@ -#!/usr/bin/perl -T +#!/usr/bin/perl +# $Id: cvsweb.cgi,v 4.40 2019/11/30 13:08:41 schwarze Exp $ +# $knu: cvsweb.cgi,v 1.299 2010/11/13 16:37:18 simon # # cvsweb - a CGI interface to CVS trees. # @@ -44,59 +46,46 @@ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -# -# $FreeBSD: projects/cvsweb/cvsweb.cgi,v 1.295 2005/09/25 20:28:51 scop Exp $ -# $zId: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $ -# $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 1.84 2001/10/07 20:50:10 knu Exp $ -# -### require 5.006; use strict; - use warnings; use filetest qw(access); use vars qw ( $VERSION $CheckoutMagic $MimeTypes $DEBUG - $config $allow_version_select - @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr - %MIRRORS %DEFAULTVALUE %ICONS %MTYPES - %DIFF_COMMANDS @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS + @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr %DEFAULTVALUE %MTYPES + @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS %alltags %fileinfo %tags @branchnames %nameprinted %symrev %revsym @allrevisions %date %author @revdisplayorder @revisions %state %difflines %log %branchpoint @revorder $keywordsubstitution - $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi - $doCheckout $scriptname $scriptwhere - $where $Browser $nofilelinks $maycompress @stickyvars %funcline_regexp + $mancgi $doCheckout $scriptname $scriptwhere + $where $Browser $nofilelinks $maycompress @stickyvars $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased %input $query $barequery $sortby $bydate $byrev $byauthor $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot - $charset $output_filter - @command_path %CMD $allow_compress $backicon $diricon $fileicon $graphicon - $fullname $cvstreedefault $logo $defaulttitle $address $binfileicon - $long_intro $short_instruction $shortLogLen $show_author - $tablepadding $hr_breakable $showfunc $hr_ignwhite $hr_ignkeysubst - $inputTextSize $mime_types $allow_annotate $allow_markup $allow_mailtos + %CMD $allow_compress $backicon $diricon $fileicon + $fullname $logo $defaulttitle $address $binfileicon $iconsdir + $shortLogLen $show_author $hr_breakable $hr_ignwhite $hr_ignkeysubst + $mime_types $allow_annotate $allow_markup $allow_mailtos $allow_log_extra $allow_dir_extra $allow_source_extra - $allow_cvsgraph $cvsgraph_config $use_java_script $edit_option_form + $edit_option_form $show_subdir_lastmod $show_log_in_markup $preformat_in_markup $tabstop $state $annTable $sel @ForbiddenFiles - $use_descriptions %descriptions @mytz $dwhere + $use_descriptions %descriptions $dwhere $use_moddate $gzip_open $file_list_len - $allow_tar @tar_options @gzip_options @zip_options @cvs_options + $allow_tar @tar_options @cvs_options @annotate_options @rcsdiff_options - $HTML_DOCTYPE $HTML_META $cssurl $CSS $cvshistory_url - $allow_enscript @enscript_options %enscript_types + $HTML_DOCTYPE $HTML_META $cssurl $CSS ); +require Compress::Zlib; use Cwd qw(abs_path); -use File::Basename qw(dirname); use File::Path qw(rmtree); use File::Spec::Functions qw(canonpath catdir catfile curdir devnull rootdir tmpdir updir); -use File::Temp qw(tempdir tempfile); +use File::Temp qw(tempdir); use IPC::Run qw(); use Time::Local qw(timegm); use URI::Escape qw(uri_escape uri_unescape); @@ -108,9 +97,6 @@ use constant CVSWEBMARKUP => qr{^text/(x-cvsweb|vnd\.v use constant LOG_FILESEPR => qr/^={77}$/o; use constant LOG_REVSEPR => qr/^-{28}$/o; -use constant HAS_ZLIB => eval { require Compress::Zlib; }; -use constant HAS_EDIFF => eval { require String::Ediff; }; - # ----------------------------------------------------------------------------- # All global initialization that can be done in compile time should go to @@ -119,7 +105,7 @@ use constant HAS_EDIFF => eval { require String::Ed BEGIN { - $VERSION = '3.0.6'; + $VERSION = '3.1'; $HTML_DOCTYPE = ' - - + EOM @@ -144,10 +129,10 @@ EOM # ----------------------------------------------------------------------------- -sub printDiffSelect($); +sub printDiffSelect(); sub printDiffSelectStickyVars(); sub getDiffLinks($$$); -sub printLogSortSelect($); +sub printLogSortSelect(); sub findLastModifiedSubdirs(@); sub htmlify_sub(&$); sub htmlify($;$); @@ -155,20 +140,14 @@ sub spacedHtmlText($;$); sub link($$); sub revcmp($$); sub fatal($$@); -sub config_error($$); sub redirect($;$); sub safeglob($); sub search_path($); -sub getEnscriptHL($); sub getMimeType($;$); sub head($;$); sub scan_directives(@); -sub openOutputFilter(); sub doAnnotate($$); sub doCheckout($$$); -sub doEnscript($$$;$); -sub doGraph(); -sub doGraphView(); sub cvswebMarkup($$$$$$;$); sub viewable($); sub doDiff($$$$$$); @@ -183,14 +162,11 @@ sub plural_write($$); sub readableTime($$); sub clickablePath($$); sub chooseCVSRoot(); -sub chooseMirror(); sub fileSortCmp(); sub download_url($$;$); sub download_link($$$;$); sub display_url($$;$); sub display_link($$;$$); -sub graph_link($;$); -sub history_link($$;$); sub toggleQuery($;$); sub htmlquote($); sub htmlunquote($); @@ -202,46 +178,100 @@ sub link_tags($); sub forbidden($); sub startproc(@); sub runproc(@); -sub checkout_to_temp($$$); # Get rid of unsafe environment vars. Don't do this in the BEGIN block # (think mod_perl)... delete(@ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}); -my ($mydir) = (dirname($0) =~ /(.*)/); # untaint +# Helps to achieve read only access to the repositories +# with cvs >= 1.12.1 and doesn't hurt other versions. +$ENV{CVSREADONLYFS} = 1; -##### Start of Configuration Area ######## +######## configuration defaults ######### -# == EDIT this == -# Locations to search for user configuration, in order: -for (catfile($mydir, 'cvsweb.conf'), '/usr/local/etc/cvsweb/cvsweb.conf') { - if (-r $_) { - $config = $_; - last; - } -} +%CMD = ( + cvs => '/usr/bin/cvs', + rcsdiff => '/usr/bin/rcsdiff', + rlog => '/usr/bin/rlog', + tar => '/bin/tar', +); -##### End of Configuration Area ######## +%DEFAULTVALUE = ( + f => 'u', + hideattic => 1, + hidecvsroot => 0, + hidenonreadable => 1, + ignorecase => 0, + ln => 0, + logsort => 'date', + sortby => 'file', +); -undef $mydir; +@ForbiddenFiles = ( + qr|^CVSROOT/+passwd$|o, # CVSROOT/passwd should not be 'cvs add'ed though. + qr|/\.cvspass$|o, # Ditto. Just in case. +); -######## Configuration parameters ######### +%MTYPES = ( + gif => 'image/gif', + html => 'text/html', + jpeg => 'image/jpeg', + jpg => 'image/jpeg', + png => 'image/png', +); -@CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS = - %MTYPES = %tags = %alltags = %fileinfo = %DIFF_COMMANDS = (); +$address = 'CVSweb'; +$allow_annotate = 1; +$allow_compress = 0; +$allow_dir_extra = 1; +$allow_log_extra = 1; +$allow_mailtos = 1; +$allow_markup = 1; +$allow_source_extra = 1; +$allow_tar = 0; +@annotate_options = qw(-f -R); +$cssurl = '/css/cvsweb.css'; +@cvs_options = qw(-f -R); +@CVSrepositories = ('local', ['Local Repository', '/cvs']); +$DEBUG = 0; +$defaulttitle = 'CVS Repository'; +$edit_option_form = 1; +$file_list_len = 0; +$hr_breakable = 1; +$hr_ignkeysubst = 1; +$hr_ignwhite = 0; +$iconsdir = '/icons'; +$logo = undef; +$mancgi = 'https://man.openbsd.org/%s.%s'; +$mime_types = '/conf/mime.types'; +$preformat_in_markup = 0; +@rcsdiff_options = qw(-q); +$shortLogLen = 80; +$show_author = 1; +$show_log_in_markup = 1; +$show_subdir_lastmod = 0; +$tabstop = 8; +@tar_options = qw(); +$use_descriptions = 0; +$use_moddate = 1; -$cvstreedefault = $logo = $defaulttitle = - $address = $long_intro = $short_instruction = $shortLogLen = $show_author = - $tablepadding = $hr_breakable = $showfunc = $hr_ignwhite = - $hr_ignkeysubst = $inputTextSize = $mime_types = $allow_annotate = - $allow_markup = $allow_compress = $use_java_script = $edit_option_form = - $show_subdir_lastmod = $show_log_in_markup = $preformat_in_markup = - $tabstop = $use_moddate = $gzip_open = $DEBUG = $allow_cvsgraph = - $cvsgraph_config = $cvshistory_url = $allow_tar = undef; +######## load configuration ######### -$allow_version_select = $allow_mailtos = $allow_log_extra = 1; +{ + my $config = '/conf/cvsweb/cvsweb.conf'; + last unless -e $config; + defined do $config and last; + $@ and fatal '500 Internal Error', + 'Error loading configuration file "%s":
%s
', + $config, $@; + fatal '500 Internal Error', + 'Cannot read configuration file "%s": %s', + $config, $! || 'unknown error'; +} -@DIFFTYPES = qw(h H u c s); +######## other global variables ######### + +@DIFFTYPES = qw(h H u c); @DIFFTYPES{@DIFFTYPES} = ( { 'descr' => 'colored', @@ -263,12 +293,6 @@ $allow_version_select = $allow_mailtos = $allow_log_ex 'opts' => ['-c'], 'colored' => 0, }, - { - 'descr' => 'side by side', - # width=168 should be enough to support 80 character line lengths - 'opts' => ['--side-by-side', '--width=168'], - 'colored' => 0, - }, ); @LOGSORTKEYS = qw(cvs date rev); @@ -278,8 +302,16 @@ $allow_version_select = $allow_mailtos = $allow_log_ex { descr => 'Revision', }, ); -##### End of configuration parameters ##### +%alltags = (); +@CVSROOT = (); +%CVSROOT = (); +%CVSROOTdescr = (); +%fileinfo = (); +$gzip_open = 0; +%tags = (); +######## end of global variables ######### + my $pathinfo = ''; if (defined($ENV{PATH_INFO}) && $ENV{PATH_INFO} ne '') { ($pathinfo) = ($ENV{PATH_INFO} =~ VALID_PATH) @@ -299,7 +331,7 @@ $scriptname = '' unless defined($scriptname); $where = $pathinfo; $doCheckout = $where =~ s|^/$CheckoutMagic/|/|o; $where =~ s|^/||; -$scriptname =~ s|^/*|/|; +$scriptname =~ s|^/+||; # Let's workaround thttpd's stupidity.. if ($scriptname =~ m|/$|) { @@ -307,6 +339,7 @@ if ($scriptname =~ m|/$|) { my $re = quotemeta $pathinfo; $scriptname =~ s/$re$//; } +$scriptname = "/$scriptname" if $scriptname; # $scriptname : the URI escaped path to this script # $where : the path in the CVS repository (without leading /, or only /) @@ -343,7 +376,7 @@ $maycompress = ( && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/) || $is_mozilla3) && !$is_msie - && !(defined($ENV{MOD_PERL}) && !HAS_ZLIB) + && !(defined($ENV{MOD_PERL})) ); # Parameters that will be sticky in all constructed links/query strings. @@ -351,16 +384,6 @@ $maycompress = ( qw(cvsroot hideattic ignorecase sortby logsort f only_with_tag ln hidecvsroot hidenonreadable); -# -# Load configuration. -# -if (-f $config) { - do "$config" or config_error($config, $@); -} else { - fatal("500 Internal Error", - 'Configuration not found. Set the parameter $config in cvsweb.cgi to your cvsweb.conf configuration file first.'); -} - # Try to find a readable dir where we can cd into. Some abs_path() # implementations as well as various cvs operations require such a dir to # work properly. @@ -384,9 +407,17 @@ if (defined($ENV{QUERY_STRING})) { $p =~ y/+/ /; my ($key, $val) = split(/=/, $p, 2); next unless defined($key); - $val = 1 unless defined($val); - ($key = uri_unescape($key)) =~ /[[:graph:]]/ or next; - ($val = uri_unescape($val)) =~ /[[:graph:]]/ or next; + $key = uri_unescape($key); + $key =~ /([^a-z_12-])/ and fatal('404 Not Found', + 'Invalid character "%s" in query parameter "%s"', $1, $key); + if (defined $val) { + $val = uri_unescape($val); + $val =~ /([^a-zA-Z_01-9.\/-])/ and fatal('404 Not Found', + 'Invalid character "%s" in the value "%s" of the query parameter "%s"', + $1, $val, $key); + } else { + $val = 1; + } $query{$key} = $val; } } @@ -394,8 +425,8 @@ if (defined($ENV{QUERY_STRING})) { undef %input; my $t; -for my $p (qw(graph hideattic hidecvsroot hidenonreadable ignorecase ln copt - makeimage options tarball)) { +for my $p (qw(hideattic hidecvsroot hidenonreadable ignorecase ln copt + options tarball)) { $t = $query{$p}; if (defined($t)) { ($input{$p}) = ($t =~ /^([01]|on)$/) @@ -497,33 +528,17 @@ for (my $i = 0; $i < scalar(@CVSrepositories); $i += 2 next; } $rootfound ||= 1; - $cvstreedefault = $key unless defined($cvstreedefault); $CVSROOTdescr{$key} = $descr; $CVSROOT{$key} = $root; push(@CVSROOT, $key); } unless ($rootfound) { - fatal('500 Internal Error', - 'No valid CVS roots found! See @CVSrepositories in ' . - 'the configuration file (%s).', - $config); + fatal('500 Internal Error', 'no valid CVS roots found'); } undef $rootfound; -# -# Default CVS root -# -if (!defined($CVSROOT{$cvstreedefault})) { - fatal("500 Internal Error", - '$cvstreedefault points to a repository (%s) not ' . - 'defined in @CVSrepositories in your configuration ' . - 'file (%s).', - $cvstreedefault, - $config); -} +$DEFAULTVALUE{cvsroot} = $CVSrepositories[0]; -$DEFAULTVALUE{cvsroot} = $cvstreedefault; - while (my ($key, $defval) = each %DEFAULTVALUE) { # Replace not given parameters with defaults. @@ -558,33 +573,6 @@ foreach (@stickyvars) { } } -if ($allow_enscript) { - push(@DIFFTYPES, qw(uc cc sc)); - @DIFFTYPES{qw(uc cc sc)} = ( - { - 'descr' => 'unified, colored', - 'opts' => ['-u'], - 'colored' => 0, - }, - { - 'descr' => 'context, colored', - 'opts' => ['-c'], - 'colored' => 0, - }, - { - 'descr' => 'side by side, colored', - # width=168 should be enough to support 80 character line lengths - 'opts' => ['--side-by-side', '--width=168'], - 'colored' => 0, - }, - ); -} else { - # No Enscript -> respect difftype, but don't offer colorization. - if ($input{f} && $input{f} =~ /^([ucs])c$/) { - $input{f} = $1; - } -} - # is there any query ? if (@barequery) { $barequery = join (';', @barequery); @@ -628,39 +616,27 @@ $logsort = $input{logsort}; if ($input{cvsroot} && $CVSROOT{$input{cvsroot}}) { $cvstree = $input{cvsroot}; } else { - $cvstree = $cvstreedefault; + $cvstree = $CVSrepositories[0]; } $cvsroot = $CVSROOT{$cvstree}; -# create icons out of description -foreach my $k (keys %ICONS) { - my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}}; - no strict 'refs'; - if ($ipath) { - ${"${k}icon"} = - sprintf('%s', - htmlquote($ipath), htmlquote($itxt), $iwidth, $iheight); - } else { - ${"${k}icon"} = $itxt; - } +if ($iconsdir) { + $backicon = '[BACK]'; + $diricon = '[DIR]'; + $fileicon = '[TXT]'; + $binfileicon = '[BIN]'; +} else { + $backicon = 'back'; + $diricon = 'dir'; + $fileicon = 'file'; + $binfileicon = 'binfile'; } -my $config_cvstree = "$config-$cvstree"; - -# Do some special configuration for cvstrees -if (-f $config_cvstree) { - do "$config_cvstree" - or fatal("500 Internal Error", - 'Error in loading configuration file: %s

%s
', - $config_cvstree, $@); -} -undef $config_cvstree; - -$re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories; -$re_prkeyword = quotemeta($prkeyword) if defined($prkeyword); -$prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/; - $fullname = catfile($cvsroot, $where); my $rewrite = 0; @@ -706,7 +682,7 @@ if ($input{tarball}) { my ($module) = ($where =~ m,^/?(.*),); # untaint $module =~ s,/([^/]*)$,,; - my ($ext) = ($1 =~ /(\.t(?:ar\.)?gz|\.zip)$/); + my ($ext) = ($1 =~ /(\.t(?:ar\.)?gz)$/); my ($basedir) = ($module =~ m,([^/]+)$,); if ($basedir eq '' || $module eq '') { @@ -714,18 +690,9 @@ if ($input{tarball}) { 'You cannot download the top level directory.'); } - my $istar = ($ext eq '.tar.gz' || $ext eq '.tgz'); - if ($istar) { - fatal('500 Internal Error', 'tar command not found.') unless $CMD{tar}; - fatal('500 Internal Error', 'gzip command not found.') unless $CMD{gzip}; + unless ($ext eq '.tar.gz' || $ext eq '.tgz') { + fatal('404 Not Found', 'Unsupported archive type.'); } - my $iszip = ($ext eq '.zip'); - if ($iszip && !$CMD{zip}) { - fatal('500 Internal Error', 'zip command not found.'); - } - if (!$istar && !$iszip) { - fatal('500 Internal Error', 'Unsupported archive type.'); - } my $tmpexportdir; eval { @@ -756,39 +723,25 @@ if ($input{tarball}) { ('500 Internal Error', 'Export failure (exit status %s), output:
%s
', $errcode, $err || $export_err); - } else { - $| = 1; # Essential to get the buffering right. local (*TAR_OUT); - - my (@cmd, $ctype); - if ($istar) { - my @tar = ($CMD{tar}, @tar_options, '-cf', '-', $basedir); - my @gzip = ($CMD{gzip}, @gzip_options, '-c'); - push(@cmd, \@tar, '|', \@gzip); - $ctype = 'application/x-gzip'; - } elsif ($iszip) { - my @zip = ($CMD{zip}, @zip_options, '-r', '-', $basedir); - push(@cmd, \@zip, \''); - $ctype = 'application/zip'; - } - push(@cmd, '>pipe', \*TAR_OUT); - - my ($h, $err) = startproc(@cmd); + my ($h, $err) = startproc($CMD{tar}, @tar_options, '-czf', '-', + $basedir, '>pipe', \*TAR_OUT); if ($h) { - print "Content-Type: $ctype\r\n\r\n"; + print "Content-Type: application/x-gzip\r\n\r\n"; local $/ = undef; print ; $h->finish(); } else { @fatal = ('500 Internal Error', - '%s failure (exit status %s), output:
%s
', - $istar ? 'Tar' : 'Zip', $? >> 8 || -1, $err); + 'tar failure (exit status %s), output:
%s
', + $? >> 8 || -1, $err); } } # Clean up. + chdir(".."); rmtree($tmpexportdir); &fatal(@fatal) if @fatal; @@ -810,8 +763,6 @@ if (-d $fullname) { if ($where eq '/') { html_header($defaulttitle); - $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g; - print $long_intro; } else { html_header($where); my $html = (-f catfile($fullname, 'README.cvs.html,v') || @@ -848,7 +799,6 @@ if (-d $fullname) { } $h->finish(); } - print $short_instruction; } if ($use_descriptions && @@ -865,15 +815,9 @@ if (-d $fullname) { # give direct access to dirs if ($where eq '/') { - chooseMirror(); chooseCVSRoot(); - } else { print '

Current directory: ', clickablePath($where, 0), ''; - if ($cvshistory_url) { - (my $d = $where) =~ s|^/*(.*?)/*$|$1|; - print ' - ', history_link($d, ''); - } print "

\n"; print "

Current tag: ", htmlquote($input{only_with_tag}), "

\n" if $input{only_with_tag}; @@ -884,7 +828,7 @@ if (-d $fullname) { my $infocols = 1; printf(< + EOF printf('\n\n\n\n\n\n", ($dirrow % 2) ? 'even' : 'odd'; - printf '\n\n\n\n\n @@ -3272,8 +2900,8 @@ EOF $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0]; - printf(< + printf(< @@ -3290,7 +2918,7 @@ EOF @@ -3299,14 +2927,14 @@ EOF if (@branchnames) { - printf(< @@ -3350,8 +2978,8 @@ EOF next if ($_ eq "f"); next if ($_ eq "only_with_tag"); next if ($_ eq "logsort"); - printf("\n", - htmlquote($input{$_})) + printf("\n", + $_, htmlquote($input{$_})) if (defined($input{$_}) && (!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})); } @@ -3377,214 +3005,6 @@ EOF } } elsif ($state eq "PreChange") { # state eq "PreChange" # we got removes with subsequent adds - if (HAS_EDIFF) { - # construct the suffix tree - my $left_diff = join("\n", @$leftColRef[0..$leftRow-1]); - my $right_diff = join("\n", @$rightColRef[0..$rightRow-1]); - my $diff_str = String::Ediff::ediff($left_diff, $right_diff); - - my @diff_str = split(/ /, $diff_str); - my $INFINITY = 10000000; - push(@diff_str, ($INFINITY) x 8); - my ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - (0, @diff_str[0..7]); - my ($l_cul, $r_cul) = (0, 0); - my ($ldx, $rdx) = (0, 0); - my (@left_html, @right_html); - for (my $j = 0; $j < $leftRow; $j++) { - my $line_len = length(@$leftColRef[$j]); - my $line = @$leftColRef[$j]; - $l_cul += length($line) + 1; # includes "\n" - my $l_culx = $l_cul - 1; # not includes "\n" - if ($j < $lb1) { - $line = spacedHtmlText($line); - push(@left_html, ""); - } elsif ($lb1 == $j) { - my $html_line; - while ($lb1 == $j) { - my $begin_char = $l_culx - $b1; - - $line =~ /^(.*)(.{$begin_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - last if ($j != $le1); - - my $end_char = $l_culx - $e1; - $line =~ /^(.*)(.{$end_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - - $idx++; - my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) = - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2); - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - @diff_str[$idx*8..($idx+1)*8-1]; - $lb1 = $INFINITY if ($lb1 < 0); - $lb2 = $INFINITY if ($lb2 < 0); - $le1 = $INFINITY if ($le1 < 0); - $le2 = $INFINITY if ($le2 < 0); - if ($te1 > $b1) { - ($b1, $lb1) = ($te1, $tle1); - } - if ($te2 > $b2) { - ($b2, $lb2) = ($te2, $tle2); - } - } - push(@left_html, - sprintf('', - $html_line, spacedHtmlText($line))); - } elsif ($le1 == $j) { - my $html_line; - while ($le1 == $j) { - my $end_char = $l_culx - $e1; - $line =~ /^(.*)(.{$end_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - - $idx++; - my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) = - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2); - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - @diff_str[$idx*8..($idx+1)*8-1]; - $lb1 = $INFINITY if ($lb1 < 0); - $lb2 = $INFINITY if ($lb2 < 0); - $le1 = $INFINITY if ($le1 < 0); - $le2 = $INFINITY if ($le2 < 0); - if ($te1 > $b1) { - ($b1, $lb1) = ($te1, $tle1); - } - if ($te2 > $b2) { - ($b2, $lb2) = ($te2, $tle2); - } - - last if ($lb1 != $j); - - my $begin_char = $l_culx - $b1; - - $line =~ /^(.*)(.{$begin_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - } - push(@left_html, - sprintf('', - $html_line, spacedHtmlText($line))); - } else { - $line = spacedHtmlText($line); - push(@left_html, ""); - } - } - ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - (0, @diff_str[0..7]); - $lb1 = $INFINITY if ($lb1 < 0); - $lb2 = $INFINITY if ($lb2 < 0); - $le1 = $INFINITY if ($le1 < 0); - $le2 = $INFINITY if ($le2 < 0); - for (my $j = 0; $j < $rightRow; $j++) { - my $line_len = length(@$rightColRef[$j]); - my $line = @$rightColRef[$j]; - $r_cul += length($line) + 1; # includes "\n" - my $r_culx = $r_cul - 1; # not includes "\n" - if ($j < $lb2) { - $line = spacedHtmlText($line); - push(@right_html, ""); - } elsif ($lb2 == $j) { - my $html_line; - while ($lb2 == $j) { - my $begin_char = $r_culx - $b2; - - $line =~ /^(.*)(.{$begin_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - - last if ($j != $le2); - - my $end_char = $r_culx - $e2; - $line =~ /^(.*)(.{$end_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - - $idx++; - my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) = - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2); - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - @diff_str[$idx*8..($idx+1)*8-1]; - $lb1 = $INFINITY if ($lb1 < 0); - $lb2 = $INFINITY if ($lb2 < 0); - $le1 = $INFINITY if ($le1 < 0); - $le2 = $INFINITY if ($le2 < 0); - if ($te1 > $b1) { - ($b1, $lb1) = ($te1, $tle1); - } - if ($te2 > $b2) { - ($b2, $lb2) = ($te2, $tle2); - } - } - push(@right_html, - sprintf('', - $html_line, spacedHtmlText($line))); - } elsif ($le2 == $j) { - my $html_line; - while ($le2 == $j) { - my $end_char = $r_culx - $e2; - $line =~ /^(.*)(.{$end_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - - $idx++; - my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) = - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2); - ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) = - @diff_str[$idx*8..($idx+1)*8-1]; - $lb1 = $INFINITY if ($lb1 < 0); - $lb2 = $INFINITY if ($lb2 < 0); - $le1 = $INFINITY if ($le1 < 0); - $le2 = $INFINITY if ($le2 < 0); - if ($te1 > $b1) { - ($b1, $lb1) = ($te1, $tle1); - } - if ($te2 > $b2) { - ($b2, $lb2) = ($te2, $tle2); - } - - last if ($lb2 != $j); - - my $begin_char = $r_culx - $b2; - $line =~ /^(.*)(.{$begin_char})$/; - $html_line .= spacedHtmlText($1) . - ''; - $line = $2; - } - push(@right_html, - sprintf('', - $html_line, spacedHtmlText($line))); - } else { - $line = spacedHtmlText ($line); - push @right_html, ""; - } - } - for (my $j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols - print ''; - if ($j < $leftRow) { - print $left_html[$j]; - } else { - print ''; - } - if ($j < $rightRow) { - print $right_html[$j]; - } else { - print ''; - } - print "\n"; - } - } else { for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols print "\n"; if ($j < $leftRow) { @@ -3603,7 +3023,6 @@ EOF } print "\n\n"; } - } } } @@ -3774,7 +3193,7 @@ EOF
', ($byfile ? ' class="sorted"' : '')); @@ -1028,8 +972,13 @@ EOF # Show last change in dir if ($filename) { - print "\n "; - print readableTime(time() - $date, 0) if $date; + my $ageclass = 'age'; + my $age = ''; + if ($date) { + $age = readableTime(time() - $date, 0); + $ageclass .= " $1" if ($age =~ /^\d+ ([a-z]+)/); + } + print " $age"; print "", htmlquote($author) if $show_author; print ""; @@ -1077,15 +1026,19 @@ EOF $filesfound++; printf "
', $allow_cvsgraph ? '' : ' colspan="2"'; + printf ''; my $icon = $isbinary ? $binfileicon : $fileicon; print $nofilelinks ? $icon : &link($icon, $url); print ' ', &link(htmlquote($file), $url), $attic; - print '', graph_link($fileurl) if $allow_cvsgraph; print "", display_link($fileurl, $rev); - print ""; - print readableTime(time() - $date, 0) if $date; + my $ageclass = 'age'; + my $age = ''; + if ($date) { + $age = readableTime(time() - $date, 0); + $ageclass .= " $1" if ($age =~ /^\d+ ([a-z]+)/); + } + print "$age"; print "", htmlquote($author) if $show_author; print ""; @@ -1135,17 +1088,17 @@ EOF if (scalar %tags || $input{only_with_tag}) { print "
\n

\n"; foreach my $var (@stickyvars) { - printf("\n", - htmlquote($input{$var})) + printf("\n", + $var, htmlquote($input{$var})) if (defined($input{$var}) && (!defined($DEFAULTVALUE{$var}) || $input{$var} ne $DEFAULTVALUE{$var}) && $var ne 'only_with_tag'); } - printf(<


\n", '
Download this directory in '; # Mangle the filename so browsers show a reasonable filename to download. - my @types = (); $basefile = uri_escape($basefile); - push(@types, &link('tarball', "$basefile.tar.gz$q")) if $havetar; - push(@types, &link('zip archive', "$basefile.zip$q")) if $havezip; - print join(' or ', @types), "
\n"; + print &link('tarball', "$basefile.tar.gz$q"); + print "\n"; } } @@ -1192,11 +1141,11 @@ EOF General options EOF - for my $v qw(hidecvsroot hidenonreadable) { + for my $v (qw(hidecvsroot hidenonreadable)) { printf(qq{\n}, $v, $input{$v} || 0); } - if ($cvstree ne $cvstreedefault) { + if ($cvstree ne $CVSrepositories[0]) { print "\n"; } print <
EOF - printLogSortSelect(0); + printLogSortSelect(); print < @@ -1262,7 +1211,7 @@ EOF EOF - printDiffSelect(0); + printDiffSelect(); print < @@ -1301,16 +1250,6 @@ elsif (-f $fullname . ',v') { exit; } - if ($allow_cvsgraph && $input{graph}) { - if ($input{makeimage}) { - doGraph(); - } else { - doGraphView(); - } - gzipclose(); - exit; - } - &doLog($fullname); } @@ -1348,16 +1287,6 @@ elsif (do { (my $tmp = $fullname) =~ s|/([^/]+)$|/Atti } -elsif (0 && (my @files = &safeglob($fullname . ",v"))) { - http_header("text/plain"); - print "You matched the following files:\n"; - print join ("\n", @files); - - # TODO: - # Find the tags from each file - # Display a form offering diffs between said tags -} - else { # Assume it's a module name with a potential path following it. my $module; @@ -1386,12 +1315,9 @@ gzipclose(); ## End MAIN -sub printDiffSelect($) +sub printDiffSelect() { - my ($use_java_script) = @_; - print '\n"; for my $sortkey (@LOGSORTKEYS) { @@ -1514,40 +1437,6 @@ sub htmlify($;$) } if ($extra) { - - # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn" - if (defined($prcgi) && defined($re_prkeyword)) { - my $prev; - - do { - $prev = $_; - - $_ = htmlify_sub { - s{ - (\b$re_prkeyword[:\#]?\s* - (?: - \#? - \d+[,\s]\s* - )* - \#?) - (\d+)\b - }{ - $1 . &link($2, sprintf($prcgi, $2)) - }egix; - } $_; - } while ($_ ne $prev); - - if (defined($re_prcategories)) { - $_ = htmlify_sub { - s{ - (\b$re_prcategories/(\d+)\b) - }{ - &link($1, sprintf($prcgi, $2)) - }egox; - } $_; - } - } - # get manpage specs as link: "foo.1" "foo(1)" if (defined($mancgi)) { $_ = htmlify_sub { @@ -1563,7 +1452,7 @@ sub htmlify($;$) }{ my($text, $name, $section) = ($1, $2, defined($3) ? $3 : $4); ($name =~ /[A-Za-z]/ && $name !~ /\.(:|$)/) - ? &link($text, sprintf($mancgi, $section, uri_escape($name))) + ? &link($text, sprintf($mancgi, uri_escape($name), $section)) : $text; }egx; } $_; @@ -1644,17 +1533,6 @@ sub fatal($$@) # -# Signal a (fatal) configuration error. -# -sub config_error($$) -{ - fatal('500 Internal Error', - 'Error loading configuration file "%s":

' . - '%s
', @_); -} - - -# # Sends a redirect to the given URL. # sub redirect($;$) @@ -1711,35 +1589,6 @@ sub safeglob($) # -# Searches @command_path for the given executable file. -# -sub search_path($) -{ - my ($command) = @_; - for my $d (@command_path) { - my $cmd = catfile($d, $command); - return $cmd if (-x $cmd && !-d _); - } - return ''; -} - - -# -# Gets the enscript(1) highlight mode corresponding to the given filename, -# or undef if unsupported. -# -sub getEnscriptHL($) -{ - return undef unless $allow_enscript; - my ($filename) = @_; - while (my ($hl, $regex) = each %enscript_types) { - return $hl if ($filename =~ $regex); - } - return undef; -} - - -# # Gets the MIME type for the given file name. # sub getMimeType($;$) @@ -1812,18 +1661,6 @@ sub scan_directives(@) } -sub openOutputFilter() -{ - return unless $output_filter; - - open(STDOUT, "|-") and return; - - # child of child - open(STDERR, '>', devnull()) unless $DEBUG; - exec($output_filter) or exit -1; -} - - ############################### # show Annotation ############################### @@ -2167,14 +2004,8 @@ EOF printf '
', $url . $barequery; } else { - print "
\n";
     my $linenumbers = $input{ln} || 0;
-
-    if (my $enscript_hl = getEnscriptHL($filename)) {
-      doEnscript($filehandle, $enscript_hl, $linenumbers);
-
-    } else {
       my $ln  = 0;
       my @buf = ();
       my $ts  = undef;
@@ -2194,8 +2025,6 @@ EOF
         }
         print $preformat_in_markup ? spacedHtmlText($_, $ts) : htmlquote($_);
       }
-    }
-
     print "
\n"; } html_footer(); @@ -2251,60 +2080,6 @@ sub doDiff($$$$$$) my $mimetype = getMimeType($fullname); - # - # Check for per-MIME type diff commands. - # - my $diffcmd = undef; - if (my $diffcmds = $DIFF_COMMANDS{lc($mimetype)}) { - if ($f =~ /^ext(\d*)$/) { - my $n = $1 || 0; - $diffcmd = $diffcmds->[$n]; - } - } - if ($diffcmd && $diffcmd->{cmd} && $diffcmd->{name}) { - - if ($diffcmd->{args} && ref($diffcmd->{args}) ne 'ARRAY') { - fatal('500 Internal Error', - 'Configuration error: arguments to external diff tools must ' . - 'be given as array refs. See "%s" in ' . - '%%DIFF_COMMANDS.', - $diffcmd->{name}); - } - - (my $cvsname = $where) =~ s/\.diff$//; - - # Create two temporary files with the two revisions - my $temp_fn1 = checkout_to_temp($cvsroot, $cvsname, $rev1); - my $temp_fn2 = checkout_to_temp($cvsroot, $cvsname, $rev2); - - # Execute chosen diff binary. - local (*DIFF_OUT); - my @cmd = ($diffcmd->{cmd}); - push(@cmd, @{$diffcmd->{args}}) if $diffcmd->{args}; - push(@cmd, $temp_fn1, $temp_fn2); - my ($h, $err) = startproc(\@cmd, \"", '>pipe', \*DIFF_OUT); - if (!$h) { - unlink($temp_fn1); - unlink($temp_fn2); - fatal('500 Internal Error', - 'Diff failure (exit status %s), output:
%s
', - $? >> 8 || -1, $err); - } - - http_header($diffcmd->{type} || 'text/plain'); - local $/ = undef; - print ; - $h->finish(); - unlink($temp_fn1); - unlink($temp_fn2); - - exit; - } - - # - # Normal CVS diff. - # - $f = $DEFAULTVALUE{f} || 'u' if ($f =~ /^ext\d*$/); my $difftype = $DIFFTYPES{$f}; if (!$difftype) { @@ -2314,18 +2089,8 @@ sub doDiff($$$$$$) my @difftype = @{$difftype->{opts}}; my $human_readable = $difftype->{colored}; - # Apply special diff options. -p and -F are not available with side by side - # diffs and may cause problems with older (< 2.8) versions of diffutils if - # used with --side-by-side. - if ($showfunc && $f !~ /^s/) { - push(@difftype, '-p'); - while (my ($re1, $re2) = each %funcline_regexp) { - if ($fullname =~ $re1) { - push(@difftype, '-F', $re2); - last; - } - } - } + # Apply special diff options. + push @difftype, '-p'; if ($human_readable) { push(@difftype, '-w') if $hr_ignwhite; @@ -2335,7 +2100,6 @@ sub doDiff($$$$$$) my $fh = do { local (*FH); }; if (!open($fh, "-|")) { # child open(STDERR, ">&STDOUT"); # Redirect stderr to stdout - openOutputFilter(); exec($CMD{rcsdiff}, @rcsdiff_options, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1; } @@ -2348,36 +2112,6 @@ sub doDiff($$$$$$) html_footer(); gzipclose(); exit; - - } elsif ($f =~ /^([ucs])c$/) { - # - # Enscript colored diff. - # - my $hl = 'diff'; - $hl .= $1 if ($1 eq 'u' || $1 eq 's'); - (my $where_nd = $where) =~ s/\.diff$//; - (my $pathname = $where_nd) =~ s|((?<=/)Attic/)?[^/]*$||; - (my $filename = $where_nd) =~ s|^.*/||; - (my $swhere = $scriptwhere) =~ s|\.diff$||; - navigateHeader($swhere, $pathname, $filename, $rev2, 'diff'); - printf(<Diff for /%s between versions %s and %s -
-EOF
-    doEnscript(\$fh, $hl, 0, 'cvsweb_diff');
-    print <
-
- -EOF - printDiffSelectStickyVars(); - print 'Diff format: '; - printDiffSelect($use_java_script); - print "\n\n"; - html_footer(); - gzipclose(); - exit; - } else { # # Plain diff. @@ -2472,7 +2206,6 @@ sub getDirLogs($$@) my $fh = do { local (*FH); }; if (!open($fh, '-|')) { # Child open(STDERR, '>', devnull()) unless $DEBUG; # Ignore rlog's complaints. - openOutputFilter(); if ($file_list_len && $file_list_len > 1) { while (scalar(@files) > $file_list_len) { # Process files in chunks. system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1; @@ -2626,10 +2359,9 @@ sub getDirLogs($$@) if ($linesread == 0) { fatal('500 Internal Error', - 'Failed to spawn GNU rlog on "%s".

Did you set the @command_path in your configuration file correctly? (Currently: "%s")', - htmlquote(join(', ', @files)), join(':', @command_path)); + 'Failed to spawn rlog on "%s"', + htmlquote(join(', ', @files))); } - return @unreadable; } @@ -2651,7 +2383,6 @@ sub readLog($;$) my $fh = do { local (*FH); }; if (!open($fh, "-|")) { # child - openOutputFilter(); $revision = defined($revision) ? "-r$revision" : ''; if ($revision =~ /\./) { # Normal revision, not a branch/tag name. @@ -2877,13 +2608,6 @@ sub getDiffLinks($$$) &link(htmlquote(lc($DIFFTYPES{$difftype}{descr})), "$url;f=$f")); } } - if (my $extdiffs = $DIFF_COMMANDS{lc($mimetype)}) { - for my $i (0 .. scalar(@$extdiffs)-1) { - my $extdiff = $extdiffs->[$i]; - push(@links, &link(htmlquote($extdiff->{name}), "$url;f=ext$i")) - if ($extdiff->{cmd} && $extdiff->{name}); - } - } return @links; } @@ -2935,7 +2659,7 @@ sub printLog($$$;$$) print ' - view: ', join(', ', @vlinks) if @vlinks; undef @vlinks; - if (!$isbin && $allow_version_select) { + unless ($isbin) { print ' - '; if ($isSelected) { print '[selected for diffs]'; @@ -2945,18 +2669,11 @@ sub printLog($$$;$$) $fileurl, $_, $barequery, $_)); } } - print ' - ', graph_link('', 'revision graph') - if (!$inlogview && $allow_cvsgraph); } print "
\n"; print ''; - if (defined @mytz) { - my ($est) = $mytz[(localtime($date{$_}))[8]]; - print scalar localtime($date{$_}), " $est ("; - } else { - print scalar gmtime($date{$_}), " UTC ("; - } + print scalar gmtime($date{$_}), ' UTC ('; print readableTime(time() - $date{$_}, 1), ' ago)'; print ' by ', htmlquote($author{$_}), "
\n"; @@ -3079,89 +2796,6 @@ sub printLog($$$;$$) } -# -# Generates the HTML view for CvsGraph. -# -sub doGraphView() -{ - (my $pathname = $where) =~ s|[^/]*$||; - (my $filename = $where) =~ s|^.*/||; - - navigateHeader($scriptwhere, $pathname, $filename, undef, 'graph'); - - my $title = 'Revision graph of ' . htmlquote($pathname . $filename); - my $mapname = 'CvsGraphMap'; - - printf(<%s -
%s -EOF - - # Remove any pre-existing tag/branch names from branch links. - (my $notag_query = $barequery) =~ s/;+only_with_tag=.*?(?=;|$)//g; - - my @graph_cmd = - ($CMD{cvsgraph}, - '-r', $cvsroot, - '-m', $pathname, - '-i', - '-M', $mapname, - '-x', 'x', - "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$notag_query\\\"\"", - "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$barequery\\\"\"", - "-Omap_diff_href=\"href=\\\"%(%F%).diff" . - "?r1=%(%P%);r2=%(%R%)$barequery\\\"\"", - ); - push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config; - push(@graph_cmd, $filename . ',v'); - - local *CVSGRAPH_OUT; - my ($h, $err) = - startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT); - fatal('500 Internal Error', $err) unless $h; - - # Browser compatibility kludge: many browsers do not support client side - # image maps where the element contains only the id attribute. Let's - # add the corresponding name attribute to it on the fly. - while () { - s/(/$1 name="$2">/; - print; - } - - $h->finish(); - print "
\n"; - - html_footer(); -} - - -# -# Generates a graph using CvsGraph. -# -sub doGraph() -{ - (my $pathname = $where) =~ s|[^/]*$||; - (my $filename = $where) =~ s|^.*/||; - - http_header('image/png'); - - my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot, '-m', $pathname); - push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config; - push(@graph_cmd, $filename . ',v'); - - local *CVSGRAPH_OUT; - my ($h, $err) = - startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT); - fatal('500 Internal Error', $err) unless $h; - { - local $/ = undef; - binmode(\*STDOUT); - print ; - } - $h->finish(); -} - - sub doLog($) { my ($fullname) = @_; @@ -3186,12 +2820,6 @@ sub doLog($) &clickablePath($upwhere, 1), "\n

\n"; print "

\n "; print &link('Request diff between arbitrary revisions', '#diff'); - print ' - ', &graph_link('', 'Display revisions graphically') - if $allow_cvsgraph; - if ($cvshistory_url) { - (my $d = $upwhere) =~ s|/+$||; - print ' - ', history_link($d, $filename); - } print "\n

\n
\n"; print "

\n"; @@ -3255,8 +2883,8 @@ EOF my $diffrev = defined($input{r1}) ? $input{r1} : $revdisplayorder[$#revdisplayorder]; - printf(< + printf(<

EOF - printDiffSelect($use_java_script); + printDiffSelect(); print < - EOF my @tmp = (); @@ -3339,7 +2967,7 @@ EOF EOF - printLogSortSelect($use_java_script); + printLogSortSelect(); print < $line%s%s%s%s$line$line%s%s%s%s$line