Remove explicit <hr> from help pages
[webmin.git] / help.cgi
1 #!/usr/local/bin/perl
2 # help.cgi
3 # Displays help HTML for some module, with substitutions
4
5 $trust_unknown_referers = 1;
6 require './web-lib.pl';
7 &init_config();
8 require './ui-lib.pl';
9 &error_setup($text{'help_err'});
10 $ENV{'PATH_INFO'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
11         &error($text{'help_epath'});
12 $ENV{'PATH_INFO'} =~ /^\/(\S+)\/(\S+)$/ || &error($text{'help_epath'});
13 $module = $1; $file = $2;
14
15 # if it ends with .gif assume it is a direct URL
16 if ($file =~ /\.(gif|jpg|jpeg|png)$/i) {
17         &redirect("$module/$file");
18         exit;
19 }
20
21 # read the help file
22 $path = &help_file($module, $file);
23 @st = stat($path);
24 open(HELP, $path) || &helperror(&text('help_efile', $path));
25 read(HELP, $help, $st[7]);
26 close(HELP);
27
28 # find and replace the <header> section
29 if ($help =~ s/<header>([^<]+)<\/header>//i) {
30         &popup_header($1);
31         print &ui_subheading($1);
32         }
33 else {
34         &helperror($text{'help_eheader'});
35         }
36
37 # replace any explicit use of <hr> with the ui-lib function
38 $uihr = &ui_hr();
39 $help =~ s/<hr>/$uihr/ig;
40
41 # find and replace the <footer> section
42 $help =~ s/<footer>/<p>/i;
43
44 # find and replace <include> directives
45 $help =~ s/<include\s+(\S+)>/inchelp($1)/ige;
46
47 # find and replace <if><else> directives
48 $help =~ s/<if\s+([^>]*)>([\000-\177]*?)<else>([\000-\177]*?)<\/if>/ifhelp($1, $2, $3)/ige;
49
50 # find and replace <if> directives
51 $help =~ s/<if\s+([^>]*)>([\000-\177]*?)<\/if>/ifhelp($1, $2)/ige;
52
53 # find and replace <exec> directives
54 $help =~ s/<exec\s+([^>]*)>/exechelp($1)/ige;
55
56 # output the HTML
57 print $help;
58 &popup_footer();
59
60 # inchelp(path)
61 sub inchelp
62 {
63 if ($_[0] =~ /^\/(\S+)\/(\S+)$/) {
64         # including something from another module..
65         }
66 else {
67         # including from this module
68         local $ipath = &help_file($module, $_[0]);
69         @st = stat($ipath);
70         open(INC, $ipath) ||
71                 return "<i>".&text('help_einclude', $_[0])."</i><br>\n";
72         read(INC, $inc, $st[7]);
73         close(INC);
74         return $inc;
75         }
76 }
77
78 # ifhelp(perl, text, [elsetext])
79 sub ifhelp
80 {
81 local $rv = eval $_[0];
82 if ($@) { return "<i>".&text('help_eif', $_[0], $@)."</i><br>\n"; }
83 elsif ($rv) { return $_[1]; }
84 else { return $_[2]; }
85 }
86
87 # exechelp(perl)
88 sub exechelp
89 {
90 local $rv = eval $_[0];
91 if ($@) { return "<i>".&text('help_eexec', $_[0], $@)."</i><br>\n"; }
92 else { return $rv; }
93 }
94
95 sub helperror
96 {
97 &header($text{'error'});
98 print "<center><h2>$text{'error'}</h2></center>\n";
99 print "<hr><p><b>",@_,"</b><p><hr>\n";
100 exit;
101 }
102