From 67c2baf157c50ae1b545f36bcf6afee6cdf6f67c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 14 Dec 2015 23:18:15 +0545 Subject: Coe style firewall * --- src/usr/local/www/firewall_aliases.php | 19 +- src/usr/local/www/firewall_aliases_edit.php | 27 +-- src/usr/local/www/firewall_aliases_import.php | 3 +- src/usr/local/www/firewall_nat.php | 22 +- src/usr/local/www/firewall_nat_1to1.php | 14 +- src/usr/local/www/firewall_nat_1to1_edit.php | 53 +++-- src/usr/local/www/firewall_nat_edit.php | 65 +++--- src/usr/local/www/firewall_nat_npt.php | 14 +- src/usr/local/www/firewall_nat_npt_edit.php | 27 ++- src/usr/local/www/firewall_nat_out.php | 85 ++++---- src/usr/local/www/firewall_nat_out_edit.php | 41 ++-- src/usr/local/www/firewall_rules.php | 77 +++---- src/usr/local/www/firewall_rules_edit.php | 152 +++++++------- src/usr/local/www/firewall_schedule.php | 25 ++- src/usr/local/www/firewall_schedule_edit.php | 249 ++++++++++------------- src/usr/local/www/firewall_shaper_queues.php | 24 ++- src/usr/local/www/firewall_shaper_vinterface.php | 14 +- src/usr/local/www/firewall_shaper_wizards.php | 9 +- src/usr/local/www/firewall_virtual_ip.php | 26 ++- src/usr/local/www/firewall_virtual_ip_edit.php | 50 ++--- 20 files changed, 551 insertions(+), 445 deletions(-) (limited to 'src/usr/local/www') diff --git a/src/usr/local/www/firewall_aliases.php b/src/usr/local/www/firewall_aliases.php index c5f6acc..6df3ad2 100644 --- a/src/usr/local/www/firewall_aliases.php +++ b/src/usr/local/www/firewall_aliases.php @@ -191,7 +191,7 @@ $tab_array[] = array(gettext("URLs"), ($tab == "url"? true : false), "/firewall $tab_array[] = array(gettext("All"), ($tab == "all"? true : false), "/firewall_aliases.php?tab=all"); foreach ($tab_array as $dtab) { - if($dtab[1] == true) { + if ($dtab[1] == true) { $bctab = $dtab[0]; break; } @@ -202,11 +202,13 @@ $shortcut_section = "aliases"; include("head.inc"); -if ($savemsg) +if ($savemsg) { print_info_box($savemsg, 'success'); +} -if (is_subsystem_dirty('aliases')) +if (is_subsystem_dirty('aliases')) { print_info_box_np(gettext("The alias list has been changed.") . "
" . gettext("You must apply the changes in order for them to take effect.")); +} display_top_tabs($tab_array); @@ -234,16 +236,19 @@ display_top_tabs($tab_array); case "ip": case "host": case "network": - if (preg_match("/(host|network)/", $alias["type"])) + if (preg_match("/(host|network)/", $alias["type"])) { $show_alias= true; + } break; case "url": - if (preg_match("/(url)/i", $alias["type"])) + if (preg_match("/(url)/i", $alias["type"])) { $show_alias= true; + } break; case "port": - if ($alias["type"] == "port") + if ($alias["type"] == "port") { $show_alias= true; + } break; } if ($show_alias): @@ -303,7 +308,7 @@ display_top_tabs($tab_array); That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
- ' . 'You can enter the name of an alias instead of the host, network or port where indicated. The alias will be resolved according to the list above.' . '
' . 'If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.'), info)?> diff --git a/src/usr/local/www/firewall_aliases_edit.php b/src/usr/local/www/firewall_aliases_edit.php index 4656541..b0625d3 100755 --- a/src/usr/local/www/firewall_aliases_edit.php +++ b/src/usr/local/www/firewall_aliases_edit.php @@ -116,7 +116,7 @@ function alias_same_type($name, $type) { foreach ($config['aliases']['alias'] as $alias) { if ($name == $alias['name']) { if (in_array($type, array("host", "network")) && - in_array($alias['type'], array("host", "network"))) { + in_array($alias['type'], array("host", "network"))) { return true; } @@ -426,7 +426,7 @@ if ($_POST) { if (!alias_same_type($input_address, $_POST['type'])) { // But alias type network can include alias type urltable. Feature#1603. if (!($_POST['type'] == 'network' && - preg_match("/urltable/i", alias_get_type($input_address)))) { + preg_match("/urltable/i", alias_get_type($input_address)))) { $wrongaliases .= " " . $input_address; } } @@ -436,7 +436,7 @@ if ($_POST) { } } else if ($_POST['type'] == "host" || $_POST['type'] == "network") { if (is_subnet($input_address) || - (!is_ipaddr($input_address) && !is_hostname($input_address))) { + (!is_ipaddr($input_address) && !is_hostname($input_address))) { $input_errors[] = sprintf(gettext('%1$s is not a valid %2$s address, FQDN or alias.'), $input_address, $_POST['type']); } } @@ -606,16 +606,18 @@ $types = array( ); if (empty($tab)) { - if (preg_match("/url/i", $pconfig['type'])) + if (preg_match("/url/i", $pconfig['type'])) { $tab = 'url'; - else if ($pconfig['type'] == 'host') + } else if ($pconfig['type'] == 'host') { $tab = 'ip'; - else + } else { $tab = $pconfig['type']; + } } -if ($input_errors) +if ($input_errors) { print_input_errors($input_errors); +} $form = new Form; @@ -640,8 +642,7 @@ $form->addGlobal(new Form_Input( $pconfig['name'] )); -if (isset($id) && $a_aliases[$id]) -{ +if (isset($id) && $a_aliases[$id]) { $form->addGlobal(new Form_Input( 'id', null, @@ -741,7 +742,7 @@ print $form; //; -events.push(function(){ +events.push(function() { var disable_subnets; @@ -771,7 +772,7 @@ events.push(function(){ hideRowsAfter(1, (tab == 'urltable') || (tab == 'urltable_ports')); // The add button and delete buttons must not show on URL Table IP or URL table ports - if((tab == 'urltable') || (tab == 'urltable_ports')) { + if ((tab == 'urltable') || (tab == 'urltable_ports')) { hideClass('addbtn', true); $('[id^=deleterow]').hide(); } else { @@ -785,7 +786,7 @@ events.push(function(){ var idx = 0; $('.repeatable').each(function(el) { - if ( idx >= row ) { + if (idx >= row) { hideRow(idx, hide); } @@ -815,7 +816,7 @@ events.push(function(){ // Autocomplete $('[id^=address]').each(function() { - if(this.id.substring(0, 8) != "address_") { + if (this.id.substring(0, 8) != "address_") { $(this).autocomplete({ source: addressarray }); diff --git a/src/usr/local/www/firewall_aliases_import.php b/src/usr/local/www/firewall_aliases_import.php index f44c92f..a263208 100755 --- a/src/usr/local/www/firewall_aliases_import.php +++ b/src/usr/local/www/firewall_aliases_import.php @@ -191,8 +191,9 @@ if ($_POST['aliasimport'] != "") { include("head.inc"); -if ($input_errors) +if ($input_errors) { print_input_errors($input_errors); +} $form = new Form; $section = new Form_Section('Alias details'); diff --git a/src/usr/local/www/firewall_nat.php b/src/usr/local/www/firewall_nat.php index e89e934..6c856a5 100644 --- a/src/usr/local/www/firewall_nat.php +++ b/src/usr/local/www/firewall_nat.php @@ -79,18 +79,20 @@ if (!is_array($config['nat']['rule'])) { $a_nat = &$config['nat']['rule']; /* update rule order, POST[rule] is an array of ordered IDs */ -if(array_key_exists('order-store', $_POST)) { +if (array_key_exists('order-store', $_POST)) { if (is_array($_POST['rule']) && !empty($_POST['rule'])) { $a_nat_new = array(); // if a rule is not in POST[rule], it has been deleted by the user - foreach ($_POST['rule'] as $id) + foreach ($_POST['rule'] as $id) { $a_nat_new[] = $a_nat[$id]; + } $a_nat = $a_nat_new; - if (write_config()) + if (write_config()) { mark_subsystem_dirty('filter'); + } header("Location: firewall_nat.php"); exit; @@ -171,12 +173,14 @@ $closehead = false; $pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward")); include("head.inc"); -if ($savemsg) +if ($savemsg) { print_info_box($savemsg, 'success'); +} -if (is_subsystem_dirty('natconf')) +if (is_subsystem_dirty('natconf')) { print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . gettext('You must apply the changes in order for them to take effect.') . '
'); +} $tab_array = array(); $tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php"); @@ -222,8 +226,9 @@ foreach ($a_nat as $natent): ); /* if user does not have access to edit an interface skip on to the next record */ - if (!have_natpfruleint_access($natent['interface'])) + if (!have_natpfruleint_access($natent['interface'])) { continue; + } ?> @@ -246,10 +251,11 @@ foreach ($a_nat as $natent): diff --git a/src/usr/local/www/firewall_nat_1to1.php b/src/usr/local/www/firewall_nat_1to1.php index a2213b8..0995cb8 100644 --- a/src/usr/local/www/firewall_nat_1to1.php +++ b/src/usr/local/www/firewall_nat_1to1.php @@ -78,18 +78,20 @@ if (!is_array($config['nat']['onetoone'])) { $a_1to1 = &$config['nat']['onetoone']; /* update rule order, POST[rule] is an array of ordered IDs */ -if($_POST['order-store']) { +if ($_POST['order-store']) { if (is_array($_POST['rule']) && !empty($_POST['rule'])) { $a_1to1_new = array(); // if a rule is not in POST[rule], it has been deleted by the user - foreach ($_POST['rule'] as $id) + foreach ($_POST['rule'] as $id) { $a_1to1_new[] = $a_1to1[$id]; + } $a_1to1 = $a_1to1_new; - if (write_config()) + if (write_config()) { mark_subsystem_dirty('natconf'); + } header("Location: firewall_nat_1to1.php"); exit; @@ -156,12 +158,14 @@ if (isset($_POST['del_x'])) { $pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("1:1")); include("head.inc"); -if ($savemsg) +if ($savemsg) { print_info_box($savemsg, 'success'); +} -if (is_subsystem_dirty('natconf')) +if (is_subsystem_dirty('natconf')) { print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . gettext('You must apply the changes in order for them to take effect.') . '
'); +} $tab_array = array(); $tab_array[] = array(gettext("Port Forward"), false, "firewall_nat.php"); diff --git a/src/usr/local/www/firewall_nat_1to1_edit.php b/src/usr/local/www/firewall_nat_1to1_edit.php index 8788280..c058a55 100644 --- a/src/usr/local/www/firewall_nat_1to1_edit.php +++ b/src/usr/local/www/firewall_nat_1to1_edit.php @@ -143,8 +143,9 @@ if ($_POST) { $temp = str_replace(">", "", $value); $newpost = htmlentities($temp); - if ($newpost != $temp) + if ($newpost != $temp) { $input_errors[] = sprintf(gettext("Invalid characters detected (%s). Please remove invalid characters and save again."), $temp); + } } /* input validation */ @@ -283,11 +284,13 @@ function build_srctype_list() { $sel = is_specialnet($pconfig['src']); - if (have_ruleint_access("pppoe")) + if (have_ruleint_access("pppoe")) { $list['pppoe'] = 'PPPoE clients'; + } - if (have_ruleint_access("l2tp")) + if (have_ruleint_access("l2tp")) { $list['l2tp'] = 'L2TP clients'; + } foreach ($ifdisp as $ifent => $ifdesc) { if (have_ruleint_access($ifent)) { @@ -305,8 +308,9 @@ function srctype_selected() { $sel = is_specialnet($pconfig['src']); if (!$sel) { - if (($pconfig['srcmask'] == 32) || (!isset($pconfig['srcmask']))) + if (($pconfig['srcmask'] == 32) || (!isset($pconfig['srcmask']))) { return('single'); + } return('network'); } @@ -320,11 +324,13 @@ function build_dsttype_list() { $sel = is_specialnet($pconfig['dst']); $list = array('any' => 'Any', 'single' => 'Single host or alias', 'network' => 'Network', '(self)' => 'This Firewall (self)'); - if (have_ruleint_access("pppoe")) + if (have_ruleint_access("pppoe")) { $list['pppoe'] = 'PPPoE clients'; + } - if (have_ruleint_access("l2tp")) + if (have_ruleint_access("l2tp")) { $list['l2tp'] = 'L2TP clients'; + } foreach ($ifdisp as $if => $ifdesc) { if (have_ruleint_access($if)) { @@ -335,8 +341,9 @@ function build_dsttype_list() { if (is_array($config['virtualip']['vip'])) { foreach ($config['virtualip']['vip'] as $sn) { - if (isset($sn['noexpand'])) + if (isset($sn['noexpand'])) { continue; + } if ($sn['mode'] == "proxyarp" && $sn['type'] == "network") { $start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits'])); @@ -362,12 +369,14 @@ function dsttype_selected() { $sel = is_specialnet($pconfig['dst']); - if (empty($pconfig['dst'] || $pconfig['dst'] == "any")) + if (empty($pconfig['dst'] || $pconfig['dst'] == "any")) { return('any'); + } if (!$sel) { - if ($pconfig['dstmask'] == 32) + if ($pconfig['dstmask'] == 32) { return('single'); + } return('network'); } @@ -375,8 +384,9 @@ function dsttype_selected() { return($pconfig['dst']); } -if ($input_errors) +if ($input_errors) { print_input_errors($input_errors); +} $form = new Form(new Form_Button( 'Submit', @@ -394,24 +404,31 @@ $section->addInput(new Form_Checkbox( $iflist = get_configured_interface_with_descr(false, true); -foreach ($iflist as $if => $ifdesc) - if (have_ruleint_access($if)) +foreach ($iflist as $if => $ifdesc) { + if (have_ruleint_access($if)) { $interfaces[$if] = $ifdesc; + } +} -if ($config['l2tp']['mode'] == "server") - if (have_ruleint_access("l2tp")) +if ($config['l2tp']['mode'] == "server") { + if (have_ruleint_access("l2tp")) { $interfaces['l2tp'] = "L2TP VPN"; + } +} -if (is_pppoe_server_enabled() && have_ruleint_access("pppoe")) +if (is_pppoe_server_enabled() && have_ruleint_access("pppoe")) { $interfaces['pppoe'] = "PPPoE Server"; +} /* add ipsec interfaces */ -if (ipsec_enabled() && have_ruleint_access("enc0")) +if (ipsec_enabled() && have_ruleint_access("enc0")) { $interfaces["enc0"] = "IPsec"; +} /* add openvpn/tun interfaces */ -if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) +if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) { $interfaces["openvpn"] = "OpenVPN"; +} $section->addInput(new Form_Select( 'interface', @@ -505,7 +522,7 @@ print($form); SetQname($pipe); - } else + } else { $input_errors[] = gettext("Could not create new queue/discipline!"); + } if ($q) { $sform = $q->build_form(); @@ -220,8 +221,9 @@ if ($_GET) { $queue->SetEnabled("on"); $sform = $queue->build_form(); $queue->wconfig(); - if (write_config()) + if (write_config()) { mark_subsystem_dirty('shaper'); + } } else { $input_errors[] = gettext("Queue not found!"); } @@ -231,8 +233,9 @@ if ($_GET) { $queue->SetEnabled(""); $sform = $queue->build_form(); $queue->wconfig(); - if (write_config()) + if (write_config()) { mark_subsystem_dirty('shaper'); + } } else { $input_errors[] = gettext("Queue not found!"); } @@ -351,8 +354,9 @@ if ($queue) { } if ($queue->CanHaveChildren()) { $can_add = true; - } else + } else { $can_add = false; + } } $tree = "
    "; @@ -469,7 +473,7 @@ if ($dfltmsg) {