Handle hostnames with upper-case letters
[webmin.git] / man / view_kernel.cgi
1 #!/usr/local/bin/perl
2 # view_kernel.cgi
3 # View some kernel doc file
4
5 require './man-lib.pl';
6 &ReadParse();
7
8 $in{'file'} = &simplify_path($in{'file'});
9 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
10         &error($text{'kernel_epath'});
11 foreach $h (split(/\s+/, $config{'kernel_dir'})) {
12         $ok++ if (&is_under_directory($config{'kernel_dir'}, $in{'file'}));
13         }
14 $ok || &error($text{'kernel_epath'});
15 -r $in{'file'} || &error($text{'kernel_epath'});
16
17 &ui_print_header(undef, $text{'kernel_title'}, "");
18
19 # Work out compression format
20 open(FILE, $in{'file'});
21 read(FILE, $two, 2);
22 $qm = quotemeta($in{'file'});
23 if ($two eq "\037\213") {
24         close(FILE);
25         &open_execute_command(FILE, "gunzip -c $qm", 1, 1);
26         }
27 elsif ($two eq "BZ") {
28         close(FILE);
29         &open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
30         }
31 seek(FILE, 0, 0);
32
33 $out = "";
34 if ($in{'file'} =~ /\.htm/i) {
35         # Display HTML documentation
36         ($dir = $in{'file'}) =~ s/\/[^\/]+$//;
37         while($line = <FILE>) {
38                 $line =~ s/href="([^"]+)"/href="view_doc.cgi?file=$dir\/$1"/ig;
39                 $line =~ s/href='([^']+)'/href='view_doc.cgi?file=$dir\/$1'/ig;
40                 $line =~ s/href=([^'"\s>]+)/href='view_doc.cgi?file=$dir\/$1'/ig;
41                 $out .= $line;
42                 }
43         }
44 else {
45         # Display text file
46         $out .= "<pre>";
47         @for = split(/\s+/, $in{'for'});
48         while($line = <FILE>) {
49                 $line = &html_escape($line);
50                 foreach $f (@for) {
51                         $line =~ s/($f)/<b>$1<\/b>/ig;
52                         }
53                 $out .= $line;
54                 }
55         $out .= "</pre>";
56         }
57 close(FILE);
58 &show_view_table(&text('kernel_header', $in{'file'}), $out);
59
60 &ui_print_footer("", $text{'index_return'});
61