From d173230c708d56ee9857dfff84779be36194d05d Mon Sep 17 00:00:00 2001 From: Seth Mos Date: Fri, 19 Oct 2007 19:10:16 +0000 Subject: Add prelimenary Routing page. Allow multiple gateways on one (static) interface --- usr/local/www/fbegin.inc | 2 +- usr/local/www/interfaces.php | 54 ++++---- usr/local/www/interfaces_opt.php | 56 ++++----- usr/local/www/interfaces_wan.php | 54 ++++---- usr/local/www/system_gateways.php | 176 ++++++++++++++++++++++++++ usr/local/www/system_gateways_edit.php | 223 +++++++++++++++++++++++++++++++++ usr/local/www/system_routes.php | 43 ++++--- usr/local/www/system_routes_edit.php | 53 ++++---- 8 files changed, 533 insertions(+), 128 deletions(-) create mode 100755 usr/local/www/system_gateways.php create mode 100755 usr/local/www/system_gateways_edit.php (limited to 'usr/local/www') diff --git a/usr/local/www/fbegin.inc b/usr/local/www/fbegin.inc index 450c3ec..a0f2a18 100755 --- a/usr/local/www/fbegin.inc +++ b/usr/local/www/fbegin.inc @@ -127,7 +127,7 @@ require_once("notices.inc");
  • Packages
  • Setup wizard
  • -
  • Static routes
  • +
  • Routing
  • Tunables
  • User Manager
  • diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index d4dc2d1..7dcfefa 100755 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -68,6 +68,10 @@ function getMPDResetTimeFromConfig() { require("guiconfig.inc"); +if (!is_array($config['gateways']['gateway_item'])) + $config['gateways']['gateway_item'] = array(); +$a_gateways = &$config['gateways']['gateway_item']; + $wancfg = &$config['interfaces']['wan']; $optcfg = &$config['interfaces']['wan']; @@ -136,7 +140,6 @@ $pconfig['bigpond_minheartbeatinterval'] = $config['bigpond']['minheartbeatinter $pconfig['dhcphostname'] = $wancfg['dhcphostname']; $pconfig['alias-address'] = $wancfg['alias-address']; $pconfig['alias-subnet'] = $wancfg['alias-subnet']; -$pconfig['use_rrd_gateway'] = $wancfg['use_rrd_gateway']; if ($wancfg['ipaddr'] == "dhcp") { $pconfig['type'] = "DHCP"; @@ -252,8 +255,15 @@ if ($_POST) { if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) { $input_errors[] = "A valid alias subnet bit count must be specified."; } - if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) { - $input_errors[] = "A valid gateway must be specified."; + if ($_POST['gateway']) { + $match = false; + foreach($a_gateways as $gateway) { + if(in_array($_POST['gateway'], $gateway)) { + $match = true; + } + } + if(!$match) + $input_errors[] = "A valid gateway must be specified."; } if (($_POST['pointtopoint'] && !is_ipaddr($_POST['pointtopoint']))) { $input_errors[] = "A valid point-to-point IP address must be specified."; @@ -264,9 +274,6 @@ if ($_POST) { if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) { $input_errors[] = "The idle timeout value must be an integer."; } - if (($_POST['use_rrd_gateway'] && !is_ipaddr($_POST['use_rrd_gateway']))) { - $input_errors[] = "A valid monitor IP address must be specified."; - } if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) { $input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23)."); @@ -358,11 +365,6 @@ if ($_POST) { system_start_ftp_helpers(); } - /* per interface rrd gateway monitor helper */ - if($_POST['use_rrd_gateway'] <> "") { - $wancfg['use_rrd_gateway'] = $_POST['use_rrd_gateway']; - } - if ($_POST['type'] == "Static") { $wancfg['ipaddr'] = $_POST['ipaddr']; $wancfg['subnet'] = $_POST['subnet']; @@ -788,7 +790,19 @@ function show_mon_config() { Gateway - +
    @@ -1009,22 +1023,6 @@ seconds
    If no qualifying outgoing packets are transmitted for the specified n
    - - Monitor IP - -
    - - Show Monitor IP configuration -
    - - - "" && !is_ipaddr($_POST['gateway'])) { - $input_errors[] = "A valid gateway must be specified."; + if ($_POST['gateway']) { + $match = false; + foreach($a_gateways as $gateway) { + if(in_array($_POST['gateway'], $gateway)) { + $match = true; + } + } + if(!$match) + $input_errors[] = "A valid gateway must be specified."; } } } @@ -217,11 +227,6 @@ if ($_POST) { $optcfg['bridge'] = $_POST['bridge']; $optcfg['enable'] = $_POST['enable'] ? true : false; - /* per interface rrd gateway monitor helper */ - if($_POST['use_rrd_gateway'] <> "") { - $optcfg['use_rrd_gateway'] = $_POST['use_rrd_gateway']; - } - if ($_POST['type'] == "Static") { $optcfg['ipaddr'] = $_POST['ipaddr']; $optcfg['subnet'] = $_POST['subnet']; @@ -400,11 +405,20 @@ function show_mon_config() { - Gateway - - -
    - If you have multiple WAN connections, enter the next hop gateway (router) IP address here. Otherwise, leave this option blank. + Gateway +
    @@ -421,22 +435,6 @@ function show_mon_config() {
    - - Monitor IP - -
    - - Show Monitor IP configuration -
    - - - "" && !is_numericint($_POST['pppoe_resethour']) && $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) { $input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23)."); @@ -358,11 +365,6 @@ if ($_POST) { system_start_ftp_helpers(); } - /* per interface rrd gateway monitor helper */ - if($_POST['use_rrd_gateway'] <> "") { - $wancfg['use_rrd_gateway'] = $_POST['use_rrd_gateway']; - } - if ($_POST['type'] == "Static") { $wancfg['ipaddr'] = $_POST['ipaddr']; $wancfg['subnet'] = $_POST['subnet']; @@ -788,7 +790,19 @@ function show_mon_config() { Gateway - +
    @@ -1009,22 +1023,6 @@ seconds
    If no qualifying outgoing packets are transmitted for the specified n
    - - Monitor IP - -
    - - Show Monitor IP configuration -
    - - - . + All rights reserved. + + 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. + + 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. +*/ + +require("guiconfig.inc"); + +if (!is_array($config['gateways']['gateway_item'])) + $config['gateways']['gateway_item'] = array(); + +$a_gateways = &$config['gateways']['gateway_item']; +$changedesc = "Gateways: "; + +if ($_POST) { + + $pconfig = $_POST; + + if ($_POST['apply']) { + + $retval = 0; + + $retval = system_routing_configure(); + $retval |= filter_configure(); + + $savemsg = get_std_save_message($retval); + if ($retval == 0) { + if (file_exists($d_staticroutesdirty_path)) { + config_lock(); + unlink($d_staticroutesdirty_path); + config_unlock(); + } + } + } +} + +if ($_GET['act'] == "del") { + if ($a_gateways[$_GET['id']]) { + $changedesc .= "removed gateway {$_GET['id']}"; + unset($a_gateways[$_GET['id']]); + write_config($changedesc); + touch($d_staticroutesdirty_path); + header("Location: system_gateways.php"); + exit; + } +} + +$pgtitle = "System: Gateways"; +include("head.inc"); + +?> + + + +

    +
    + + +

    +You must apply the changes in order for them to take +effect.");?>
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    NameInterfaceGatewayMonitor IPDescription + + + + + +
    +
    + (default)"; + } + ?> + + + 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) + $iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + echo htmlspecialchars($iflabels[$gateway['interface']]); ?> + + + +   + +   + + + + + + + + + +
    +
    + +
    + + + + + +
    +
    +

    + + + diff --git a/usr/local/www/system_gateways_edit.php b/usr/local/www/system_gateways_edit.php new file mode 100755 index 0000000..1ccd2d5 --- /dev/null +++ b/usr/local/www/system_gateways_edit.php @@ -0,0 +1,223 @@ +. + All rights reserved. + + 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. + + 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. +*/ + +require("guiconfig.inc"); + +if (!is_array($config['gateways']['gateway_item'])) + $config['gateways']['gateway_item'] = array(); + +$a_gateways = &$config['gateways']['gateway_item']; + +$id = $_GET['id']; +if (isset($_POST['id'])) + $id = $_POST['id']; + +if (isset($_GET['dup'])) { + $id = $_GET['dup']; +} + +if (isset($id) && $a_gateways[$id]) { + $pconfig['name'] = $a_gateways[$id]['name']; + $pconfig['interface'] = $a_gateways[$id]['interface']; + $pconfig['gateway'] = $a_gateways[$id]['gateway']; + $pconfig['defaultgw'] = $a_gateways[$id]['defaultgw']; + $pconfig['monitor'] = $a_gateways[$id]['monitor']; + $pconfig['descr'] = $a_gateways[$id]['descr']; +} + +if (isset($_GET['dup'])) + unset($id); + +if ($_POST) { + + unset($input_errors); + $pconfig = $_POST; + + /* input validation */ + $reqdfields = explode(" ", "interface name gateway"); + $reqdfieldsn = explode(",", "Interface,Name,Gateway"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if (! isset($_POST['name'])) { + $input_errors[] = "A valid gateway name must be specified."; + } + if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) { + $input_errors[] = "A valid gateway IP address must be specified."; + } + if (($_POST['monitor'] && !is_ipaddr($_POST['monitor']))) { + $input_errors[] = "A valid monitor IP address must be specified."; + } + + if ($_POST['defaultgw'] == "yes") { + $i=0; + foreach ($a_gateways as $gateway) { + if($id != $i) { + unset($config['gateways']['gateway_item'][$i]['defaultgw']); + } else { + $config['gateways']['gateway_item'][$i]['defaultgw'] = true; + } + $i++; + } + } else { + $i=0; + foreach ($a_gateways as $gateway) { + if($id == $i) { + unset($config['gateways']['gateway_item'][$i]['defaultgw']); + } + $i++; + } + } + + /* check for overlaps */ + foreach ($a_gateways as $gateway) { + if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) + continue; + + if ($gateway['name'] == $_POST['name']) { + $input_errors[] = "A gateway with this name \"{$_POST['name']}\" already exists."; + break; + } + if ($gateway['gateway'] == $_POST['gateway']) { + $input_errors[] = "A gateway with the IP address \"{$_POST['gateway']}\" already exists."; + break; + } + if ($gateway['monitor'] == $_POST['monitor']) { + $input_errors[] = "A monitor with the IP address \"{$_POST['monitor']}\" already exists."; + break; + } + } + + if (!$input_errors) { + $gateway = array(); + $gateway['interface'] = $_POST['interface']; + $gateway['name'] = $_POST['name']; + $gateway['gateway'] = $_POST['gateway']; + $gateway['defaultgw'] = $_POST['defaultgw']; + $gateway['monitor'] = $_POST['monitor']; + $gateway['descr'] = $_POST['descr']; + + if (isset($id) && $a_gateways[$id]) + $a_gateways[$id] = $gateway; + else + $a_gateways[] = $gateway; + + touch($d_staticroutesdirty_path); + + write_config(); + + header("Location: system_gateways.php"); + exit; + } +} + +$pgtitle = "System: Gateways: Edit gateway"; +include("head.inc"); + +?> + + + +

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Interface +
    + Choose which interface this gateway applies to.
    Name + +
    Gateway name
    Gateway + +
    Gateway IP address
    Default Gateway + onclick="enable_change(false)" /> + Default Gateway
    + This will select the above gateway as the default gateway +
    Monitor IP + + Alternative monitor IP
    + Enter a alternative address here to be used to monitor the link. This is used for the + quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond + to icmp requests. +
    +
    Description + +
    You may enter a description here + for your reference (not parsed).
      + + + + +
    +
    + + + + diff --git a/usr/local/www/system_routes.php b/usr/local/www/system_routes.php index a53e5c8..8bd3acd 100755 --- a/usr/local/www/system_routes.php +++ b/usr/local/www/system_routes.php @@ -34,8 +34,12 @@ require("guiconfig.inc"); if (!is_array($config['staticroutes']['route'])) $config['staticroutes']['route'] = array(); +if (!is_array($config['gateways']['gateway_item'])) + $config['gateways']['gateway_item'] = array(); + staticroutes_sort(); $a_routes = &$config['staticroutes']['route']; +$a_gateways = &$config['gateways']['gateway_item']; $changedesc = "Static Routes: "; if ($_POST) { @@ -112,10 +116,20 @@ include("head.inc"); + + + - + - +
    + +
    Interface Network GatewayInterface Description @@ -126,26 +140,25 @@ include("head.inc");
    - 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP'); - for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) - $iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; - echo htmlspecialchars($iflabels[$route['interface']]); ?> + - + - + } + + ?>   @@ -161,7 +174,7 @@ include("head.inc");
    - + diff --git a/usr/local/www/system_routes_edit.php b/usr/local/www/system_routes_edit.php index da09d99..18e27e6 100755 --- a/usr/local/www/system_routes_edit.php +++ b/usr/local/www/system_routes_edit.php @@ -33,9 +33,12 @@ require("guiconfig.inc"); if (!is_array($config['staticroutes']['route'])) $config['staticroutes']['route'] = array(); +if (!is_array($config['gateways']['gateway_item'])) + $config['gateways']['gateway_item'] = array(); staticroutes_sort(); $a_routes = &$config['staticroutes']['route']; +$a_gateways = &$config['gateways']['gateway_item']; $id = $_GET['id']; if (isset($_POST['id'])) @@ -46,7 +49,6 @@ if (isset($_GET['dup'])) { } if (isset($id) && $a_routes[$id]) { - $pconfig['interface'] = $a_routes[$id]['interface']; list($pconfig['network'],$pconfig['network_subnet']) = explode('/', $a_routes[$id]['network']); $pconfig['gateway'] = $a_routes[$id]['gateway']; @@ -62,8 +64,8 @@ if ($_POST) { $pconfig = $_POST; /* input validation */ - $reqdfields = explode(" ", "interface network network_subnet gateway"); - $reqdfieldsn = explode(",", "Interface,Destination network,Destination network bit count,Gateway"); + $reqdfields = explode(" ", "network network_subnet gateway"); + $reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); @@ -73,8 +75,15 @@ if ($_POST) { if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) { $input_errors[] = "A valid destination network bit count must be specified."; } - if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) { - $input_errors[] = "A valid gateway IP address must be specified."; + if ($_POST['gateway']) { + $match = false; + foreach($a_gateways as $gateway) { + if(in_array($_POST['gateway'], $gateway)) { + $match = true; + } + } + if(!$match) + $input_errors[] = "A valid gateway must be specified."; } /* check for overlaps */ @@ -91,7 +100,6 @@ if ($_POST) { if (!$input_errors) { $route = array(); - $route['interface'] = $_POST['interface']; $route['network'] = $osn; $route['gateway'] = $_POST['gateway']; $route['descr'] = $_POST['descr']; @@ -121,22 +129,6 @@ include("head.inc");
    - - - - - + - + - +
    Interface -
    - Choose which interface this route applies to.
    Destination network @@ -151,13 +143,20 @@ include("head.inc");
    Destination network for this static route
    Gateway - -
    Gateway to be used to reach the destination network
    +
    + Choose which gateway this route applies to.
    Description -- cgit v1.1