Add support for template variables to help pages

This commit is contained in:
Jamie Cameron
2025-03-20 20:02:47 -07:00
parent 4021b6d8bb
commit e60be7133b
3 changed files with 30 additions and 13 deletions

View File

@@ -10,24 +10,41 @@ use WebminCore;
$ENV{'PATH_INFO'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
&error($text{'help_epath'});
$ENV{'PATH_INFO'} =~ /^\/(\S+)\/(\S+)$/ || &error($text{'help_epath'});
$module = $1; $file = $2;
my $module = $1;
my $file = $2;
&ReadParse();
# if it ends with .gif assume it is a direct URL
if ($file =~ /\.(gif|jpg|jpeg|png)$/i) {
&redirect("$module/$file");
exit;
}
return;
}
# read the help file
$help = &read_help_file($module, $file);
my $help = &read_help_file($module, $file);
$help || &helperror(&text('help_efile3',
&html_escape($file), &html_escape($module)));
my %hash;
# Modify help file based on module
if (&foreign_exists($module) &&
&foreign_require($module) &&
&foreign_defined($module, 'help_pre_load')) {
$help = &foreign_call($module, "help_pre_load", $help);
&foreign_require($module)) {
if (&foreign_defined($module, 'help_pre_load')) {
$help = &foreign_call($module, "help_pre_load", $help);
}
if (&foreign_defined($module, 'help_template')) {
%hash = &foreign_call($module, "help_template");
}
}
# if any template variables were given as URL params, substitute them into the file
foreach my $k (keys %in) {
if ($k =~ /^tmpl_(\S+)$/i) {
$hash{$1} = $in{$k};
}
}
if (%hash) {
$help = &substitute_template($help, \%hash);
}
# find and replace the <header> section