#!/usr/bin/perl
# index.cgi
# Display current iptables firewall configuration from save file
# unified for IPV4 and IPV6
require './firewall-lib.pl';
&ReadParse();
# Load the correct library
$ipvx_version = &get_ipvx_version();
if ($ipvx_version == 6) {
require './firewall6-lib.pl';
}
else {
require './firewall4-lib.pl';
}
if ($ipvx_save) {
$desc = &text('index_editing', "$ipvx_save");
}
&ui_print_header($text{"index_title_v${ipvx}"}, $text{'index_title'}, undef,
"intro", 1, 1, 0,
&help_search_link("ip${ipvx}tables", "man", "doc"));
# Firewall protocol selector
my @vlinks;
push(@vlinks, $ipvx_version == 4 ? "$text{'index_ipvx4'}" :
&ui_link($ipv4_link, $text{'index_ipvx4'}));
push(@vlinks, $ipvx_version == 6 ? "$text{'index_ipvx6'}" :
&ui_link($ipv6_link, $text{'index_ipvx6'}));
print "";
print "$text{'index_ipvxmode'}\n",
&ui_links_row(\@vlinks),"\n";
print "
$desc
";
# Check for iptables and iptables-restore commands
if ($c = &missing_firewall_commands()) {
print "
",&text('index_ecommand', "$c"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } # Check if the kernel supports iptables $out = &backquote_command("ip${ipvx}tables -n -t filter -L OUTPUT 2>&1"); if ($?) { print "
",&text('index_ekernel', "
$out"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } # Check if the distro supports iptables if (!$config{"direct${ipvx}"} && defined(&check_iptables) && ($err = &check_iptables())) { print "
$err
\n"; &ui_print_footer("/", $text{'index'}); exit; } # Check if firewall is being started at boot if (!$config{"direct${ipvx}"} && &foreign_check("init")) { $init_support++; if (defined(&started_at_boot)) { $atboot = &started_at_boot(); } else { &foreign_require("init", "init-lib.pl"); $atboot = &init::action_status("webmin-ip${ipvx}tables") == 2; } } # Check if the save file exists. If not, check for any existing firewall # rules, and offer to create a save file from them @livetables = &get_iptables_save("ip${ipvx}tables-save 2>/dev/null |"); # Display warnings about active external firewalls! &external_firewall_message(\@livetables); if (!$config{"direct${ipvx}"} && $in{'reset'} && $access{'setup'}) { @tables = @livetables; foreach $t (@tables) { $rules++ if (@{$t->{'rules'}}); foreach $c (keys %{$t->{'defaults'}}) { $chains++ if ($t->{'defaults'}->{$c} ne 'ACCEPT'); } $hastable{$t->{'name'}}++; } foreach $t (@known_tables) { system("ip${ipvx}tables -t $t -n -L >/dev/null") if (!$hastable{$t}); } if (!$in{'reset'} && ($rules || $chains)) { # Offer to save the current rules print &ui_confirmation_form("convert.cgi", &text('index_existing', $rules, "$ipvx_save"), ( ['version'], [${ipvx_arg}] ), [ [ undef, $text{'index_saveex'} ] ], $init_support && !$atboot ? &ui_checkbox("atboot", 1, $text{'index_atboot'}, 0) : "", ); print &ui_table_start($text{'index_headerex'}, "width=100%", 2); $out = &backquote_command("ip${ipvx}tables-save 2>/dev/null"); print &ui_table_row(undef, "".&html_escape($out)."", 2); print &ui_table_end(); } else { # Offer to set up a firewall print &text($in{'reset'} ? 'index_rsetup' : 'index_setup', "$ipvx_save"),"
\n"; print &ui_form_start("setup${ipvx}.cgi"); print &ui_hidden("version", ${ipvx_arg}); print &ui_hidden("reset", $in{'reset'}); print "
| \n";
print &ui_oneradio("auto", 0, $text{'index_auto0'}, 1)," \n"; foreach $a (1 .. 5) { print &ui_oneradio("auto", $a, $text{'index_auto'.$a}, 0)." "; print &interface_choice("iface".$a)," \n"; } print " |
\n"; if ($init_support && !$atboot) { print &ui_checkbox("atboot", 1, $text{'index_atboot'}, 0); } print "
\n"; } } # Work out the default table if (!defined($in{'table'})) { foreach $t (@tables) { if (@{$t->{'rules'}} && &can_edit_table($t->{'name'})) { $in{'table'} = $t->{'index'}; last; } } } if (!defined($in{'table'})) { foreach $t (@tables) { if (&can_edit_table($t->{'name'})) { $in{'table'} = $t->{'index'}; last; } } } $table = $tables[$in{'table'}]; # Allow selection of a table print "
| \n"; print "\n"; print " | \n"; $form++; if ($access{'newchain'}) { # Show form to create a chain print "\n"; print "\n"; print " | \n"; $form++; } print "
\n"; } # alert about the detected firewall modules foreach my $word (split ' ', $fwname) { print ui_alert_box(&text("index_$word", "$gconfig{'webprefix'}/$word/", $fwconfig), 'warn'); } }