Commit 63d31921 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor system_routes_edit.php

parent 84ba6a49
<?php <?php
/* /*
Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
Copyright (C) 2010 Scott Ullrich Copyright (C) 2010 Scott Ullrich
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("guiconfig.inc"); require_once("guiconfig.inc");
...@@ -35,44 +35,45 @@ require_once("pfsense-utils.inc"); ...@@ -35,44 +35,45 @@ require_once("pfsense-utils.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_routes.php'); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_routes.php');
if (!is_array($config['staticroutes'])) { if (!isset($config['staticroutes']) || !is_array($config['staticroutes'])) {
$config['staticroutes'] = array(); $config['staticroutes'] = array();
} }
if (!is_array($config['staticroutes']['route'])) { if (!isset($config['staticroutes']['route']) || !is_array($config['staticroutes']['route'])) {
$config['staticroutes']['route'] = array(); $config['staticroutes']['route'] = array();
} }
$a_routes = &$config['staticroutes']['route']; $a_routes = &$config['staticroutes']['route'];
$a_gateways = return_gateways_array(true, true); $a_gateways = return_gateways_array(true, true);
if (is_numericint($_GET['id'])) { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$id = $_GET['id']; if (isset($_GET['id']) && isset($a_routes[$_GET['id']])) {
} $id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id'])) { $configId = $id;
$id = $_POST['id']; } elseif (isset($_GET['dup']) && isset($a_routes[$_GET['dup']])) {
} $configId = $_GET['dup'];
}
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { $pconfig = array();
$id = $_GET['dup'];
} if (isset($configId)) {
list($pconfig['network'],$pconfig['network_subnet']) =
if (isset($id) && $a_routes[$id]) { explode('/', $a_routes[$configId]['network']);
list($pconfig['network'],$pconfig['network_subnet']) = $pconfig['gateway'] = $a_routes[$configId]['gateway'];
explode('/', $a_routes[$id]['network']); $pconfig['descr'] = $a_routes[$configId]['descr'];
$pconfig['gateway'] = $a_routes[$id]['gateway']; $pconfig['disabled'] = isset($a_routes[$configId]['disabled']);
$pconfig['descr'] = $a_routes[$id]['descr']; } else {
$pconfig['disabled'] = isset($a_routes[$id]['disabled']); $pconfig['network'] = null;
} $pconfig['network_subnet'] = null;
$pconfig['gateway'] = null;
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { $pconfig['disabled'] = false;
unset($id); }
} } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && isset($a_routes[$_POST['id']])) {
if ($_POST) { $id = $_POST['id'];
}
global $aliastable; global $aliastable;
unset($input_errors); $input_errors = array();
$pconfig = $_POST; $pconfig = $_POST;
/* input validation */ /* input validation */
...@@ -84,39 +85,39 @@ if ($_POST) { ...@@ -84,39 +85,39 @@ if ($_POST) {
gettext("Gateway") gettext("Gateway")
); );
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
if (($_POST['network'] && !is_ipaddr($_POST['network']) && !is_alias($_POST['network']))) { if (($pconfig['network'] && !is_ipaddr($pconfig['network']) && !is_alias($pconfig['network']))) {
$input_errors[] = gettext("A valid IPv4 or IPv6 destination network must be specified."); $input_errors[] = gettext("A valid IPv4 or IPv6 destination network must be specified.");
} }
if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) { if (($_POST['network_subnet'] && !is_numeric($pconfig['network_subnet']))) {
$input_errors[] = gettext("A valid destination network bit count must be specified."); $input_errors[] = gettext("A valid destination network bit count must be specified.");
} }
if (($_POST['gateway']) && is_ipaddr($_POST['network'])) { if (($_POST['gateway']) && is_ipaddr($pconfig['network'])) {
if (!isset($a_gateways[$_POST['gateway']])) { if (!isset($a_gateways[$pconfig['gateway']])) {
$input_errors[] = gettext("A valid gateway must be specified."); $input_errors[] = gettext("A valid gateway must be specified.");
} }
if (!validate_address_family($_POST['network'], lookup_gateway_ip_by_name($_POST['gateway']))) { if (!validate_address_family($pconfig['network'], lookup_gateway_ip_by_name($pconfig['gateway']))) {
$input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family as network '{$_POST['network']}'."); $input_errors[] = gettext("The gateway '{$a_gateways[$pconfig['gateway']]['gateway']}' is a different Address Family as network '{$pconfig['network']}'.");
} }
} }
/* check for overlaps */ /* check for overlaps */
$current_targets = get_staticroutes(true); $current_targets = get_staticroutes(true);
$new_targets = array(); $new_targets = array();
if (is_ipaddrv6($_POST['network'])) { if (is_ipaddrv6($pconfig['network'])) {
$osn = gen_subnetv6($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; $osn = gen_subnetv6($pconfig['network'], $pconfig['network_subnet']) . "/" . $pconfig['network_subnet'];
$new_targets[] = $osn; $new_targets[] = $osn;
} }
if (is_ipaddrv4($_POST['network'])) { if (is_ipaddrv4($pconfig['network'])) {
if ($_POST['network_subnet'] > 32) { if ($pconfig['network_subnet'] > 32) {
$input_errors[] = gettext("A IPv4 subnet can not be over 32 bits."); $input_errors[] = gettext("A IPv4 subnet can not be over 32 bits.");
} else { } else {
$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; $osn = gen_subnet($pconfig['network'], $pconfig['network_subnet']) . "/" . $pconfig['network_subnet'];
$new_targets[] = $osn; $new_targets[] = $osn;
} }
} elseif (is_alias($_POST['network'])) { } elseif (is_alias($pconfig['network'])) {
$osn = $_POST['network']; $osn = $pconfig['network'];
foreach (preg_split('/\s+/', $aliastable[$osn]) as $tgt) { foreach (preg_split('/\s+/', $aliastable[$osn]) as $tgt) {
if (is_ipaddrv4($tgt)) { if (is_ipaddrv4($tgt)) {
$tgt .= "/32"; $tgt .= "/32";
...@@ -164,28 +165,28 @@ if ($_POST) { ...@@ -164,28 +165,28 @@ if ($_POST) {
if (is_array($config['interfaces'])) { if (is_array($config['interfaces'])) {
foreach ($config['interfaces'] as $if) { foreach ($config['interfaces'] as $if) {
if (is_ipaddrv4($_POST['network']) if (is_ipaddrv4($pconfig['network'])
&& isset($if['ipaddr']) && isset($if['subnet']) && isset($if['ipaddr']) && isset($if['subnet'])
&& is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet']) && is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet'])
&& ($_POST['network_subnet'] == $if['subnet']) && ($_POST['network_subnet'] == $if['subnet'])
&& (gen_subnet($_POST['network'], $_POST['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet']))) { && (gen_subnet($pconfig['network'], $pconfig['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet']))) {
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']); $input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
} elseif (is_ipaddrv6($_POST['network']) } elseif (is_ipaddrv6($pconfig['network'])
&& isset($if['ipaddrv6']) && isset($if['subnetv6']) && isset($if['ipaddrv6']) && isset($if['subnetv6'])
&& is_ipaddrv6($if['ipaddrv6']) && is_numeric($if['subnetv6']) && is_ipaddrv6($if['ipaddrv6']) && is_numeric($if['subnetv6'])
&& ($_POST['network_subnet'] == $if['subnetv6']) && ($_POST['network_subnet'] == $if['subnetv6'])
&& (gen_subnetv6($_POST['network'], $_POST['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6']))) { && (gen_subnetv6($pconfig['network'], $pconfig['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6']))) {
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']); $input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
} }
} }
} }
if (!$input_errors) { if (count($input_errors) == 0){
$route = array(); $route = array();
$route['network'] = $osn; $route['network'] = $osn;
$route['gateway'] = $_POST['gateway']; $route['gateway'] = $pconfig['gateway'];
$route['descr'] = $_POST['descr']; $route['descr'] = $pconfig['descr'];
if ($_POST['disabled']) { if (!empty($pconfig['disabled'])) {
$route['disabled'] = true; $route['disabled'] = true;
} else { } else {
unset($route['disabled']); unset($route['disabled']);
...@@ -210,9 +211,7 @@ if ($_POST) { ...@@ -210,9 +211,7 @@ if ($_POST) {
} }
} }
file_put_contents('/tmp/.system_routes.apply', serialize($toapplylist)); file_put_contents('/tmp/.system_routes.apply', serialize($toapplylist));
mark_subsystem_dirty('staticroutes'); mark_subsystem_dirty('staticroutes');
write_config(); write_config();
header("Location: system_routes.php"); header("Location: system_routes.php");
...@@ -220,247 +219,116 @@ if ($_POST) { ...@@ -220,247 +219,116 @@ if ($_POST) {
} }
} }
$pgtitle = array(gettext('System'), gettext('Routes'), gettext('Edit')); $pgtitle = array(gettext('System'), gettext('Routes'), gettext('Edit'));
$shortcut_section = "routing"; $shortcut_section = "routing";
legacy_html_escape_form_data($a_gateways);
legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body>
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
<script type="text/javascript" src="/javascript/suggestions.js"></script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid"> <body>
<script type="text/javascript">
<div class="row"> $( document ).ready(function() {
<?php if (isset($input_errors) && count($input_errors) > 0) { // hook in, ipv4/ipv6 selector events
print_input_errors($input_errors); hook_ipv4v6('ipv4v6net', 'network-id');
});
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors);
} ?> } ?>
<section class="col-xs-12">
<section class="col-xs-12"> <div class="content-box">
<form action="system_routes_edit.php" method="post" name="iform" id="iform">
<div class="content-box"> <div class="table-responsive">
<table class="table table-striped">
<form action="system_routes_edit.php" method="post" name="iform" id="iform"> <tr>
<td width="22%"></td>
<div class="table-responsive"> <td width="78%" align="right">
<table class="table table-striped table-sort"> <small><?=gettext("full help"); ?> </small>
<tr> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i></a>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit route entry"); ?></td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination network"); ?></td> <td><a id="help_for_network" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination network"); ?></td>
<td width="78%" class="vtable"> <td>
<table> <input name="network" type="text" id="network" value="<?=$pconfig['network'];?>" />
<tr> /
<td width="348px"> <select name="network_subnet" data-network-id="network" class="ipv4v6net" id="network_netbits">
<input name="network" type="text" class="formfldalias ipv4v6" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>" /> <?php for ($i = 128; $i >= 0; $i--) :
</td> ?>
<td> <option value="<?=$i;?>" <?= isset($pconfig['network_subnet']) && $i == $pconfig['network_subnet'] ? "selected=\"selected\"" : "";?>>
<select name="network_subnet" class="selectpicker ipv4v6" id="network_subnet" data-width="auto"> <?=$i;?>
<?php for ($i = 128; $i >= 1; $i--) : </option>
?> <?php
<option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) { endfor; ?>
echo "selected=\"selected\""; </select>
} ?>> <div class="hidden" for="help_for_network">
<?=$i;?> <?=gettext("Destination network for this static route"); ?>
</option> </div>
<?php </td>
endfor; ?> </tr>
</select> <tr>
</td> <td><a id="help_for_gateway" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Gateway"); ?></td>
</tr> <td>
</table> <select name="gateway" id="gateway" class="selectpicker">
<br /><span class="vexpl"><?=gettext("Destination network for this static route"); ?></span> <?php
</td> foreach ($a_gateways as $gateway):?>
</tr> <option value="<?=$gateway['name'];?>" <?=$gateway['name'] == $pconfig['gateway'] ? "selected=\"selected\"" : "";?>>
<tr> <?=$gateway['name'] . " - " . $gateway['gateway'];?>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td> </option>
<td width="78%" class="vtable"> <?php
<select name="gateway" id="gateway" class="selectpicker"> endforeach;?>
<?php </select>
foreach ($a_gateways as $gateway) { <div class="hidden" for="help_for_gateway">
?> <?=gettext("Choose which gateway this route applies to or");?>
<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) { <a href="/system_gateways_edit.php"><?=gettext("add a new one.");?></a>
echo "selected=\"selected\""; </div>
} ?>> </td>
<?=htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']);?> </tr>
</option> <tr>
<?php <td><a id="help_for_disabled" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disabled");?></td>
} <td width="78%" class="vtable">
?> <input name="disabled" type="checkbox" value="yes" <?= !empty($pconfig['disabled']) ? "checked=\"checked\"" : "";?>/>
</select> <br /> <div class="hidden" for="help_for_disabled">
<div id='addgwbox'> <strong><?=gettext("Disable this static route");?></strong><br/>
<?=gettext("Choose which gateway this route applies to or"); <?=gettext("Set this option to disable this static route without removing it from the list.");?>
?> <a onclick="show_add_gateway();" href="#"><?=gettext("add a new one.");?></a> </div>
</div> </td>
<div id='notebox'> </tr>
</div> <tr>
<div style="display:none" id="status"> <td><a id="help_for_descr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td>
</div> <td>
<div style="display:none" id="addgateway"> <input name="descr" type="text" value="<?=$pconfig['descr'];?>" />
<table class="table table-striped" summary="addgateway"> <div for="help_for_descr" class="hidden">
<tbody> <?=gettext("You may enter a description here for your reference (not parsed)."); ?>
<tr> </div>
<td colspan="2" valign="top" class="listtopic"><b><?=gettext("Add new gateway:"); ?></b></td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%"><?=gettext("Default gateway:"); ?></td><td with="78%"><input class="form-control" type="checkbox" id="defaultgw" name="defaultgw" /></td> <td></td>
</tr> <td>
<tr> <input id="save" name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
<td width="22%"><?=gettext("Interface:"); ?></td> <input id="cancel" type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
<td with="78%"> <?php
<select name="addinterfacegw" id="addinterfacegw" class="selectpicker"> if (isset($id) && $a_routes[$id]) :?>
<?php $gwifs = get_configured_interface_with_descr(); <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
foreach ($gwifs as $fif => $dif) { <?php
echo "<option value=\"{$fif}\">{$dif}</option>\n"; endif; ?>
} </td>
?> </tr>
</select> </table>
</td> </div>
</tr> </form>
<tr> </div>
<td with="22%"><?=gettext("Gateway Name:"); ?></td><td with="78%"><input class="form-control" id="name" name="name" value="GW" /></td> </section>
</tr> </div>
<tr> </div>
<td with="22%"><?=gettext("Gateway IP:"); ?></td><td with="78%"><input class="form-control" id="gatewayip" name="gatewayip" /></td> </section>
</tr>
<tr>
<td with="22%"><?=gettext("Description:"); ?></td><td with="78%"><input class="form-control" id="gatewaydescr" name="gatewaydescr" /></td>
</tr>
<tr>
<td with="22%"></td>
<td with="78%">
<div id='savebuttondiv'>
<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
<input class="btn btn-primary" id="gwsave" type="button" value="<?=gettext("Save Gateway"); ?>" onclick='hide_add_gatewaysave();' />
<input class="btn btn-default" id="gwcancel" type="button" value="<?=gettext("Cancel"); ?>" onclick='hide_add_gateway();' />
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Disabled");?></td>
<td width="78%" class="vtable">
<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) {
echo "checked=\"checked\"";
} ?> />
<strong><?=gettext("Disable this static route");?></strong><br />
<span class="vexpl"><?=gettext("Set this option to disable this static route without removing it from the list.");?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
<br /><span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)."); ?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input id="save" name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
<input id="cancel" type="button" class="btn btn-default" value="<?=gettext("Cancel");
?>" onclick="window.location.href='<?=$referer;?>'" />
<?php if (isset($id) && $a_routes[$id]) :
?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php
endif; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<script type="text/javascript">
//<![CDATA[
var gatewayip;
var name;
function show_add_gateway() {
document.getElementById("addgateway").style.display = '';
document.getElementById("addgwbox").style.display = 'none';
//document.getElementById("gateway").style.display = 'none';
jQuery('#gateway').selectpicker('hide');
document.getElementById("save").style.display = 'none';
document.getElementById("cancel").style.display = 'none';
document.getElementById("gwsave").style.display = '';
document.getElementById("gwcancel").style.display = '';
//jQuery('.selectpicker').selectpicker('refresh');
jQuery('#notebox').html("");
}
function hide_add_gateway() {
document.getElementById("addgateway").style.display = 'none';
document.getElementById("addgwbox").style.display = '';
//document.getElementById("gateway").style.display = '';
jQuery('#gateway').selectpicker('show');
document.getElementById("save").style.display = '';
document.getElementById("cancel").style.display = '';
document.getElementById("gwsave").style.display = '';
document.getElementById("gwcancel").style.display = '';
//jQuery('.selectpicker').selectpicker('refresh');
}
function hide_add_gatewaysave() {
document.getElementById("addgateway").style.display = 'none';
var iface = jQuery('#addinterfacegw').val();
name = jQuery('#name').val();
var descr = jQuery('#gatewaydescr').val();
gatewayip = jQuery('#gatewayip').val();
addrtype = jQuery('#addrtype').val();
var defaultgw = '';
if (jQuery('#defaultgw').checked)
defaultgw = 'yes';
var url = "system_gateways_edit.php";
var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
jQuery.ajax(
url,
{
type: 'post',
data: pars,
error: report_failure,
success: save_callback
});
}
function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.append(optn);
selectbox.prop('selectedIndex',selectbox.children('option').length-1);
jQuery('#notebox').html("<p><strong><?=gettext("NOTE:");?><\/strong> <?php printf(gettext("You can manage Gateways %shere%s."), "<a target='_blank' href='system_gateways.php'>", "<\/a>");?> <\/strong><\/p>");
jQuery('.selectpicker').selectpicker('refresh');
}
function report_failure() {
alert("<?=gettext("Sorry, we could not create your gateway at this time."); ?>");
hide_add_gateway();
}
function save_callback(response) {
if (response) {
document.getElementById("addgateway").style.display = 'none';
hide_add_gateway();
var gwtext = escape(name) + " - " + gatewayip;
addOption(jQuery('#gateway'), gwtext, name);
jQuery('.selectpicker').selectpicker('refresh');
} else {
report_failure();
}
}
var addressarray = <?= json_encode(get_alias_list(array("host", "network"))) ?>;
var oTextbox1 = new AutoSuggestControl(document.getElementById("network"), new StateSuggestions(addressarray));
//]]>
</script>
<?php include("foot.inc"); <?php include("foot.inc");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment