From 3301e1a2c923ff298189f10156f32cca61d52cdc Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 30 Nov 2015 10:23:27 +0000 Subject: [PATCH] (legacy) refactor system_gateway_groups_edit.php --- src/www/system_gateway_groups_edit.php | 508 +++++++++++-------------- 1 file changed, 218 insertions(+), 290 deletions(-) diff --git a/src/www/system_gateway_groups_edit.php b/src/www/system_gateway_groups_edit.php index c34810ba9..cd9f482e0 100644 --- a/src/www/system_gateway_groups_edit.php +++ b/src/www/system_gateway_groups_edit.php @@ -1,38 +1,36 @@ . - All rights reserved. + Copyright (C) 2014-2015 Deciso B.V. + Copyright (C) 2010 Seth Mos . + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("vpn.inc"); require_once("interfaces.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateway_groups.php'); - if (!is_array($config['gateways'])) { $config['gateways'] = array(); } @@ -40,68 +38,61 @@ if (!is_array($config['gateways'])) { if (!is_array($config['gateways']['gateway_group'])) { $config['gateways']['gateway_group'] = array(); } - $a_gateway_groups = &$config['gateways']['gateway_group']; $a_gateways = return_gateways_array(); -$carplist = get_configured_carp_interface_list(); -$categories = array('down' => gettext("Member Down"), - 'downloss' => gettext("Packet Loss"), - 'downlatency' => gettext("High Latency"), - 'downlosslatency' => gettext("Packet Loss or High Latency")); - -if (is_numericint($_GET['id'])) { - $id = $_GET['id']; -} -if (isset($_POST['id']) && is_numericint($_POST['id'])) { - $id = $_POST['id']; -} - -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { - $id = $_GET['dup']; -} - -if (isset($id) && $a_gateway_groups[$id]) { - $pconfig['name'] = $a_gateway_groups[$id]['name']; - $pconfig['item'] = &$a_gateway_groups[$id]['item']; - $pconfig['descr'] = $a_gateway_groups[$id]['descr']; - $pconfig['trigger'] = $a_gateway_groups[$id]['trigger']; -} - -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { - unset($id); -} - -if ($_POST) { - unset($input_errors); +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && isset($a_gateway_groups[$_GET['id']])) { + $id = $_GET['id']; + $configId = $id; + } elseif (isset($_GET['dup']) && isset($a_gateway_groups[$_GET['dup']])) { + $configId = $_GET['dup']; + } + $pconfig=array(); + if (isset($configId)) { + $pconfig['name'] = $a_gateway_groups[$configId]['name']; + $pconfig['item'] = &$a_gateway_groups[$configId]['item']; + $pconfig['descr'] = $a_gateway_groups[$configId]['descr']; + $pconfig['trigger'] = $a_gateway_groups[$configId]['trigger']; + } else { + $pconfig['name'] = null; + $pconfig['descr'] = null; + $pconfig['trigger'] = null; + $pconfig['item'] = array(); + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $pconfig = $_POST; + if (isset($_POST['id']) && isset($a_gateway_groups[$_POST['id']])) { + $id = $_POST['id']; + } + $input_errors = array(); /* input validation */ $reqdfields = explode(" ", "name"); $reqdfieldsn = explode(",", "Name"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - if (! isset($_POST['name'])) { + if (empty($pconfig['name'])) { $input_errors[] = gettext("A valid gateway group name must be specified."); } - if (! is_validaliasname($_POST['name'])) { + if (!is_validaliasname($pconfig['name'])) { $input_errors[] = gettext("The gateway name must not contain invalid characters."); } - if (isset($_POST['name'])) { + if (!empty($pconfig['name'])) { /* check for overlaps */ if (is_array($a_gateway_groups)) { foreach ($a_gateway_groups as $gateway_group) { if (isset($id) && ($a_gateway_groups[$id]) && ($a_gateway_groups[$id] === $gateway_group)) { - if ($gateway_group['name'] != $_POST['name']) { + if ($gateway_group['name'] != $pconfig['name']) { $input_errors[] = gettext("Changing name on a gateway group is not allowed."); } continue; } - if ($gateway_group['name'] == $_POST['name']) { - $input_errors[] = sprintf(gettext('A gateway group with this name "%s" already exists.'), $_POST['name']); + if ($gateway_group['name'] == $pconfig['name']) { + $input_errors[] = sprintf(gettext('A gateway group with this name "%s" already exists.'), $pconfig['name']); break; } } @@ -111,14 +102,14 @@ if ($_POST) { /* Build list of items in group with priority */ $pconfig['item'] = array(); foreach ($a_gateways as $gwname => $gateway) { - if ($_POST[$gwname] > 0) { + if (isset($pconfig[$gwname]) && $pconfig[$gwname] > 0) { $vipname = "{$gwname}_vip"; /* we have a priority above 0 (disabled), add item to list */ - $pconfig['item'][] = "{$gwname}|{$_POST[$gwname]}|{$_POST[$vipname]}"; + $pconfig['item'][] = "{$gwname}|{$pconfig[$gwname]}|{$pconfig[$vipname]}"; } /* check for overlaps */ - if ($_POST['name'] == $gwname) { - $input_errors[] = sprintf(gettext('A gateway group cannot have the same name with a gateway "%s" please choose another name.'), $_POST['name']); + if ($pconfig['name'] == $gwname) { + $input_errors[] = sprintf(gettext('A gateway group cannot have the same name with a gateway "%s" please choose another name.'), $pconfig['name']); } } @@ -126,14 +117,14 @@ if ($_POST) { $input_errors[] = gettext("No gateway(s) have been selected to be used in this group"); } - if (!$input_errors) { + if (count($input_errors) == 0) { $gateway_group = array(); - $gateway_group['name'] = $_POST['name']; + $gateway_group['name'] = $pconfig['name']; $gateway_group['item'] = $pconfig['item']; - $gateway_group['trigger'] = $_POST['trigger']; - $gateway_group['descr'] = $_POST['descr']; + $gateway_group['trigger'] = $pconfig['trigger']; + $gateway_group['descr'] = $pconfig['descr']; - if (isset($id) && $a_gateway_groups[$id]) { + if (isset($id)) { $a_gateway_groups[$id] = $gateway_group; } else { $a_gateway_groups[] = $gateway_group; @@ -152,233 +143,170 @@ if ($_POST) { $pgtitle = array(gettext('System'),gettext('Gateways'), gettext('Edit Group')); $shortcut_section = "gateway-groups"; -function build_gateway_protocol_map (&$a_gateways) -{ - $result = array(); - foreach ($a_gateways as $gwname => $gateway) { - $result[$gwname] = $gateway['ipprotocol']; - } - return $result; -} - +legacy_html_escape_form_data($a_gateways); +legacy_html_escape_form_data($pconfig); include("head.inc"); - ?> - - -
-
-
- 0) { - print_input_errors($input_errors); +
+
+
+ 0) { + print_input_errors($input_errors); } ?> -
-
- -
-
-

-
-
- -
- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + +
- -
- - - - - - - - $gateway) { - if (!empty($pconfig['item'])) { - $af = explode("|", $pconfig['item'][0]); - $family = $a_gateways[$af[0]]['ipprotocol']; - if ($gateway['ipprotocol'] != $family) { - continue; - } - } - $interface = $gateway['friendlyiface']; - $selected = array(); - foreach ((array)$pconfig['item'] as $item) { - $itemsplit = explode("|", $item); - if ($itemsplit[0] == $gwname) { - $selected[$itemsplit[1]] = "selected=\"selected\""; - break; - } else { - $selected[0] = "selected=\"selected\""; - } - } - $tr_id = $gwname . "_row"; - echo "\n"; - echo ""; - - $selected = array(); - foreach ((array)$pconfig['item'] as $item) { - $itemsplit = explode("|", $item); - if ($itemsplit[0] == $gwname) { - $selected[$itemsplit[2]] = "selected=\"selected\""; - break; - } else { - $selected['address'] = "selected=\"selected\""; - } - } - echo ""; - echo ""; - } - ?> -
"; - echo "{$gateway['name']} "; - echo ""; - echo "\n"; - echo ""; - echo "{$gateway['descr']} "; - echo "
-
-
- -
-
- -

-
- -
-
- -
-
  - " /> - " onclick="window.location.href=''" /> - +
+
+ + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ + + + + + + + $gateway): + if (!empty($pconfig['item'])) { + $af = explode("|", $pconfig['item'][0]); + $family = $a_gateways[$af[0]]['ipprotocol']; + if ($gateway['ipprotocol'] != $family) { + continue; + } + } ?> - - - - -
- - - - - - - +
+ + + +
+ +
+ + +
+ + +
+ " /> + " onclick="window.location.href=''" /> + + + +
+ +
+
+
+
+
+
- -