Remove manual HTML
[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 # find and replace the <footer> section
38 $help =~ s/<footer>/<p><hr>/i;
39
40 # find and replace <include> directives
41 $help =~ s/<include\s+(\S+)>/inchelp($1)/ige;
42
43 # find and replace <if><else> directives
44 $help =~ s/<if\s+([^>]*)>([\000-\177]*?)<else>([\000-\177]*?)<\/if>/ifhelp($1, $2, $3)/ige;
45
46 # find and replace <if> directives
47 $help =~ s/<if\s+([^>]*)>([\000-\177]*?)<\/if>/ifhelp($1, $2)/ige;
48
49 # find and replace <exec> directives
50 $help =~ s/<exec\s+([^>]*)>/exechelp($1)/ige;
51
52 # output the HTML
53 print $help;
54 &popup_footer();
55
56 # inchelp(path)
57 sub inchelp
58 {
59 if ($_[0] =~ /^\/(\S+)\/(\S+)$/) {
60         # including something from another module..
61         }
62 else {
63         # including from this module
64         local $ipath = &help_file($module, $_[0]);
65         @st = stat($ipath);
66         open(INC, $ipath) ||
67                 return "<i>".&text('help_einclude', $_[0])."</i><br>\n";
68         read(INC, $inc, $st[7]);
69         close(INC);
70         return $inc;
71         }
72 }
73
74 # ifhelp(perl, text, [elsetext])
75 sub ifhelp
76 {
77 local $rv = eval $_[0];
78 if ($@) { return "<i>".&text('help_eif', $_[0], $@)."</i><br>\n"; }
79 elsif ($rv) { return $_[1]; }
80 else { return $_[2]; }
81 }
82
83 # exechelp(perl)
84 sub exechelp
85 {
86 local $rv = eval $_[0];
87 if ($@) { return "<i>".&text('help_eexec', $_[0], $@)."</i><br>\n"; }
88 else { return $rv; }
89 }
90
91 sub helperror
92 {
93 &header($text{'error'});
94 print "<center><h2>$text{'error'}</h2></center>\n";
95 print "<hr><p><b>",@_,"</b><p><hr>\n";
96 exit;
97 }
98