Allow editing of automatically added gateways.

Input validation needs work.
Some fields may need to be hidden?
This commit is contained in:
Seth Mos 2008-11-13 18:23:37 +00:00
parent 8c30876c29
commit d7dfd5f8f4

View File

@ -39,10 +39,7 @@
require("guiconfig.inc");
if (!is_array($config['gateways']['gateway_item']))
$config['gateways']['gateway_item'] = array();
$a_gateways = &$config['gateways']['gateway_item'];
$a_gateways = return_gateways_array();
$id = $_GET['id'];
if (isset($_POST['id']))
@ -59,6 +56,7 @@ if (isset($id) && $a_gateways[$id]) {
$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
$pconfig['monitor'] = $a_gateways[$id]['monitor'];
$pconfig['descr'] = $a_gateways[$id]['descr'];
$pconfig['attribute'] = $a_gateways[$id]['attribute'];
}
if (isset($_GET['dup']))
@ -66,6 +64,8 @@ if (isset($_GET['dup']))
if ($_POST) {
$post = print_r($_POST, true);
log_error("$post");
unset($input_errors);
$pconfig = $_POST;
@ -78,33 +78,14 @@ if ($_POST) {
if (! isset($_POST['name'])) {
$input_errors[] = "A valid gateway name must be specified.";
}
if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
/* skip system gateways which have been automatically added */
if ($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system")) {
$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))
@ -125,28 +106,44 @@ if ($_POST) {
}
if (!$input_errors) {
$gateway = array();
$gateway['interface'] = $_POST['interface'];
$gateway['name'] = $_POST['name'];
$gateway['gateway'] = $_POST['gateway'];
$gateway['monitor'] = $_POST['monitor'];
$gateway['descr'] = $_POST['descr'];
if($_POST['defaultgw'] == "yes") {
$i = 0;
foreach($a_gateways as $gw) {
unset($config['gateways'][$i]['defaultgw']);
$i++;
}
$gateway['defaultgw'] = true;
} else {
unset($gateway['defaultgw']);
/* if we are processing a system gateway only save the monitorip */
if($pconfig['attribute'] == "system") {
$config['interfaces'][$_POST['interface']]['monitorip'] = $_POST['monitor'];
}
if (isset($id) && $a_gateways[$id])
$a_gateways[$id] = $gateway;
else
$a_gateways[] = $gateway;
/* Manual gateways are handled differently */
/* rebuild the array with the manual entries only */
if (!is_array($config['gateways']['gateway_item']))
$config['gateways']['gateway_item'] = array();
$a_gateways = &$config['gateways']['gateway_item'];
if ((is_numeric($pconfig['attribute'])) && ($pconfig['attribute'] != "system")) {
$gateway = array();
$gateway['interface'] = $_POST['interface'];
$gateway['name'] = $_POST['name'];
$gateway['gateway'] = $_POST['gateway'];
$gateway['descr'] = $_POST['descr'];
if ($_POST['defaultgw'] == "yes") {
$i = 0;
foreach($a_gateways as $gw) {
unset($config['gateways'][$i]['defaultgw']);
$i++;
}
$gateway['defaultgw'] = true;
} else {
unset($gateway['defaultgw']);
}
/* when saving the manual gateway we use the attribute which has the corresponding id */
$id = $pconfig['attribute'];
if (isset($id) && $a_gateways[$id]) {
$a_gateways[$id] = $gateway;
} else {
$a_gateways[] = $gateway;
}
}
touch($d_staticroutesdirty_path);
@ -166,6 +163,12 @@ include("head.inc");
<?php include("fbegin.inc"); ?>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<form action="system_gateways_edit.php" method="post" name="iform" id="iform">
<?php
/* If this is a automatically added system gateway we need this var */
if($pconfig['attribute'] == "system") {
echo "<input type='hidden' name='attribute' id='attribute' value='{$pconfig['attribute']}' >\n";
}
?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td colspan="2" valign="top" class="listtopic">Edit gateway</td>