mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 16:50:24 +00:00
Config file editing
This commit is contained in:
0
fail2ban/edit_config.cgi
Normal file → Executable file
0
fail2ban/edit_config.cgi
Normal file → Executable file
34
fail2ban/edit_manual.cgi
Executable file
34
fail2ban/edit_manual.cgi
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/local/bin/perl
|
||||
# Allow manual editing of all config files
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
require './fail2ban-lib.pl';
|
||||
our (%in, %text);
|
||||
&ReadParse();
|
||||
|
||||
&ui_print_header(undef, $text{'manual_title'}, "");
|
||||
|
||||
# Show file selector
|
||||
my @files = &list_all_config_files();
|
||||
$in{'file'} ||= $files[0];
|
||||
&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
|
||||
print &ui_form_start("edit_manual.cgi");
|
||||
print "<b>$text{'manual_desc'}</b>\n";
|
||||
print &ui_select("file", $in{'file'}, \@files, 1, 0, 0, 0,
|
||||
"onchange='form.submit()'");
|
||||
print &ui_submit($text{'manual_ok'});
|
||||
print &ui_form_end();
|
||||
print "<p>\n";
|
||||
|
||||
# Show editing form
|
||||
my $data = &read_file_contents($in{'file'});
|
||||
print &ui_form_start("save_manual.cgi", "form-data");
|
||||
print &ui_hidden("file", $in{'file'});
|
||||
print &ui_table_start("<tt>".&html_escape($in{'file'})."</tt>", undef, 2);
|
||||
print &ui_table_row(undef,
|
||||
&ui_textarea("manual", $data, 40, 80), 2);
|
||||
print &ui_table_end();
|
||||
print &ui_form_end([ [ undef, $text{'save'} ] ]);
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
@@ -3,8 +3,8 @@
|
||||
# XXX include in makedist.pl
|
||||
# XXX main help page
|
||||
# XXX help page for filters with description of <HOST> / etc
|
||||
# XXX filter defaults
|
||||
# XXX deleting a directive removes too many lines?
|
||||
# XXX config files for distros
|
||||
|
||||
BEGIN { push(@INC, ".."); };
|
||||
use strict;
|
||||
@@ -393,4 +393,16 @@ my $out = &backquote_logged("$config{'client_cmd'} reload 2>&1 </dev/null");
|
||||
return $? ? $out : undef;
|
||||
}
|
||||
|
||||
# list_all_config_files()
|
||||
# Returns a list of all Fail2Ban config files
|
||||
sub list_all_config_files
|
||||
{
|
||||
my @rv;
|
||||
push(@rv, "$config{'config_dir'}/fail2ban.conf");
|
||||
push(@rv, glob("$config{'config_dir'}/filter.d/*.conf"));
|
||||
push(@rv, glob("$config{'config_dir'}/action.d/*.conf"));
|
||||
push(@rv, "$config{'config_dir'}/jail.conf");
|
||||
return @rv;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
BIN
fail2ban/images/manual.gif
Normal file
BIN
fail2ban/images/manual.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
@@ -133,6 +133,7 @@ log_start=Started Fail2Ban server
|
||||
log_restart=Re-started Fail2Ban server
|
||||
log_atboot=Enabled Fail2Ban at boot time
|
||||
log_delboot=Disabled Fail2Ban at boot time
|
||||
log_manual=Edited configuration file $1
|
||||
|
||||
config_title=Global Configuration
|
||||
config_edef=No Definition section found in config file!
|
||||
@@ -147,6 +148,13 @@ config_err=Failed to save global configuration
|
||||
config_elogtarget=File to write logs to must be an absolute path
|
||||
config_esocket=Socket file must be an absolute path
|
||||
|
||||
manual_title=Edit Config Files
|
||||
manual_desc=File to edit:
|
||||
manual_ok=OK
|
||||
manual_efile=Selected file is not part of the Fail2Ban configuration!
|
||||
manual_err=Failed to edit config file
|
||||
manual_edata=No config file contents entered
|
||||
|
||||
syslog_logtarget=Fail2Ban action log
|
||||
|
||||
__norefs=1
|
||||
|
||||
24
fail2ban/save_manual.cgi
Normal file
24
fail2ban/save_manual.cgi
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/local/bin/perl
|
||||
# Save one config file
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
require './fail2ban-lib.pl';
|
||||
our (%in, %text);
|
||||
&ReadParseMime();
|
||||
&error_setup($text{'manual_err'});
|
||||
|
||||
# Validate inputs
|
||||
my @files = &list_all_config_files();
|
||||
&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
|
||||
$in{'manual'} =~ s/\r//g;
|
||||
$in{'manual'} =~ /\S/ || &error($text{'manual_edata'});
|
||||
|
||||
# Write it out
|
||||
my $fh = "FILE";
|
||||
&open_lock_tempfile($fh, ">$in{'file'}");
|
||||
&print_tempfile($fh, $in{'manual'});
|
||||
&close_tempfile($fh);
|
||||
|
||||
&webmin_log("manual", undef, $in{'file'});
|
||||
&redirect("");
|
||||
Reference in New Issue
Block a user