3 # View some package doc file
5 require './man-lib.pl';
8 $in{'file'} = &simplify_path($in{'file'});
9 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
10 &error($text{'doc_epath'});
11 foreach $d (split(/\s+/, $config{'doc_dir'})) {
12 $ok++ if (&is_under_directory($d, $in{'file'}));
14 $ok++ if ($config{'custom_dir'} &&
15 &is_under_directory($config{'custom_dir'}, $in{'file'}));
16 $ok || &error($text{'doc_epath'});
17 if (!-r $in{'file'}) {
18 if (-r "$in{'file'}.gz") {
19 $in{'file'} = "$in{'file'}.gz";
22 &error($text{'doc_epath'});
26 # Just output if this is an image
27 $mt = &guess_mime_type($in{'file'});
28 if ($mt =~ /^image\//) {
29 print "Content-type: $mt\r\n\r\n";
30 print &read_file_contents($in{'file'});
34 &ui_print_header(undef, $text{'doc_title'}, "");
36 # Work out compression format
37 open(FILE, $in{'file'});
39 $qm = quotemeta($in{'file'});
40 if ($two eq "\037\213") {
42 &open_execute_command(FILE, "gunzip -c $qm", 1, 1);
44 elsif ($two eq "BZ") {
46 &open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
51 if ($in{'file'} =~ /\.htm/i) {
52 # Display HTML documentation
53 ($dir = $in{'file'}) =~ s/\/[^\/]+$//;
54 while($line = <FILE>) {
55 $line =~ s/(href|src)="([^"#][^"]*)"/$1="view_doc.cgi?file=$dir\/$2"/ig;
56 $line =~ s/(href|src)='([^'#][^']*)'/$1='view_doc.cgi?file=$dir\/$2'/ig;
57 $line =~ s/(href|src)=([^'"\s#][^'"\s>]*)/$1='view_doc.cgi?file=$dir\/$2'/ig;
64 @for = split(/\s+/, $in{'for'});
65 while($line = <FILE>) {
67 $line = &html_escape($line);
69 $line =~ s/($f)/<b>$1<\/b>/ig;
76 &show_view_table(&text('doc_header', $in{'file'}), $out);
78 &ui_print_footer("", $text{'index_return'});