summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2017-04-18 00:27:54 +0545
committerPhil Davis <phil.davis@inf.org>2017-04-18 00:27:54 +0545
commitf1bb5c7f1bd1919ab7a2d3689e6b2f6a7922c308 (patch)
tree1a9ca8834504ff2c085fa555540c40917b856a30 /src
parentdfafd8c283959a2499ba596b6e0194e5dcd94697 (diff)
downloadpfsense-f1bb5c7f1bd1919ab7a2d3689e6b2f6a7922c308.zip
pfsense-f1bb5c7f1bd1919ab7a2d3689e6b2f6a7922c308.tar.gz
Validate gateway and interface together
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/gwlb.inc31
-rwxr-xr-xsrc/usr/local/www/interfaces.php162
2 files changed, 85 insertions, 108 deletions
diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc
index d61c9a8..4f67351 100644
--- a/src/etc/inc/gwlb.inc
+++ b/src/etc/inc/gwlb.inc
@@ -1337,13 +1337,18 @@ function gateway_is_gwgroup_member($name) {
return $members;
}
-
-// Check the proposed gateway settings to see if they are valid.
-// $gateway_settings - the proposed array of proposed gateway settings
-// $id - the index of the gateway proposed to be modified (otherwise "" if adding a new gateway)
-// Return completed $input_errors array if there is any problem.
-// Otherwise return an empty $input_errors array
-function validate_gateway($gateway_settings, $id = "") {
+/*
+ Check the proposed gateway settings to see if they are valid.
+ $gateway_settings - the proposed array of proposed gateway settings
+ $id - the index of the gateway proposed to be modified (otherwise "" if adding a new gateway)
+ $parent_ip - the IP (v4 or v6) address about to be set on the corresponding interface (if any)
+ $parent_sn - the subnet about to be set on the corresponding interface (if any)
+ (Note: the above 2 parameters allow gateway parameters to be validated concurrently with saving
+ an interface, before the new interface parameters are actually saved in the config.)
+ Return completed $input_errors array if there is any problem.
+ Otherwise return an empty $input_errors array
+*/
+function validate_gateway($gateway_settings, $id = "", $parent_ip = "", $parent_sn = "") {
global $config;
$a_gateways = return_gateways_array(true, false, true, true);
@@ -1393,8 +1398,10 @@ function validate_gateway($gateway_settings, $id = "") {
if ($gateway_settings['gateway'] && (is_ipaddr($gateway_settings['gateway'])) && !$gateway_settings['isAjax']) {
if (is_ipaddrv4($gateway_settings['gateway'])) {
- $parent_ip = get_interface_ip($gateway_settings['interface']);
- $parent_sn = get_interface_subnet($gateway_settings['interface']);
+ if ($parent_ip == '') {
+ $parent_ip = get_interface_ip($gateway_settings['interface']);
+ $parent_sn = get_interface_subnet($gateway_settings['interface']);
+ }
if (empty($parent_ip) || empty($parent_sn)) {
$input_errors[] = gettext("Cannot add IPv4 Gateway Address because no IPv4 address could be found on the interface.");
} elseif (!isset($gateway_settings["nonlocalgateway"])) {
@@ -1424,8 +1431,10 @@ function validate_gateway($gateway_settings, $id = "") {
} else if (is_ipaddrv6($gateway_settings['gateway'])) {
/* do not do a subnet match on a link local address, it's valid */
if (!is_linklocal($gateway_settings['gateway'])) {
- $parent_ip = get_interface_ipv6($gateway_settings['interface']);
- $parent_sn = get_interface_subnetv6($gateway_settings['interface']);
+ if ($parent_ip == '') {
+ $parent_ip = get_interface_ipv6($gateway_settings['interface']);
+ $parent_sn = get_interface_subnetv6($gateway_settings['interface']);
+ }
if (empty($parent_ip) || empty($parent_sn)) {
$input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface.");
} elseif (!isset($gateway_settings["nonlocalgateway"])) {
diff --git a/src/usr/local/www/interfaces.php b/src/usr/local/www/interfaces.php
index 5929ae5..d623194 100755
--- a/src/usr/local/www/interfaces.php
+++ b/src/usr/local/www/interfaces.php
@@ -767,20 +767,29 @@ if ($_POST['apply']) {
if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
}
- if (($_POST['gateway'] != "none") || ($_POST['gatewayv6'] != "none")) {
+
+ // Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
+ if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
$match = false;
foreach ($a_gateways as $gateway) {
if (in_array($_POST['gateway'], $gateway)) {
$match = true;
}
}
+ if (!$match) {
+ $input_errors[] = gettext("A valid IPv4 gateway must be specified.");
+ }
+ }
+ // Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
+ if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
+ $match = false;
foreach ($a_gateways as $gateway) {
if (in_array($_POST['gatewayv6'], $gateway)) {
$match = true;
}
}
if (!$match) {
- $input_errors[] = gettext("A valid gateway must be specified.");
+ $input_errors[] = gettext("A valid IPv6 gateway must be specified.");
}
}
if (($_POST['provider'] && !is_domain($_POST['provider']))) {
@@ -972,6 +981,36 @@ if ($_POST['apply']) {
$input_errors[] = gettext("PTPP Password and confirmed password must match!");
}
+ if ($_POST['gatewayip4']) {
+ // The user wants to add an IPv4 gateway - validate the settings
+ $gateway_settings4 = array();
+
+ $gateway_settings4['name'] = $_POST['gatewayname4'];
+ $gateway_settings4['interface'] = $_POST['if'];
+ $gateway_settings4['gateway'] = $_POST['gatewayip4'];
+ $gateway_settings4['descr'] = $_POST['gatewaydescr4'];
+ $gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
+ $gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
+ foreach ($gw_input_errors as $input_error_text) {
+ $input_errors[] = $input_error_text;
+ }
+ }
+
+ if ($_POST['gatewayip6']) {
+ // The user wants to add an IPv6 gateway - validate the settings
+ $gateway_settings6 = array();
+
+ $gateway_settings6['name'] = $_POST['gatewayname6'];
+ $gateway_settings6['interface'] = $_POST['if'];
+ $gateway_settings6['gateway'] = $_POST['gatewayip6'];
+ $gateway_settings6['descr'] = $_POST['gatewaydescr6'];
+ $gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
+ $gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
+ foreach ($gw_input_errors as $input_error_text) {
+ $input_errors[] = $input_error_text;
+ }
+ }
+
if (!$input_errors) {
// These 3 fields can be a list of multiple data items when used for MLPPP.
// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
@@ -1430,6 +1469,14 @@ if ($_POST['apply']) {
write_config();
+ if ($_POST['gatewayip4']) {
+ save_gateway($gateway_settings4);
+ }
+
+ if ($_POST['gatewayip6']) {
+ save_gateway($gateway_settings6);
+ }
+
if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
} else {
@@ -1660,6 +1707,8 @@ $types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"),
$ip = $_SERVER['REMOTE_ADDR'];
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
$mymac = str_replace("\n", "", $mymac);
+$defgatewayname4 = $wancfg['descr'] . "GW";
+$defgatewayname6 = $wancfg['descr'] . "GWv6";
function build_mediaopts_list() {
global $mediaopts_list;
@@ -1882,7 +1931,7 @@ $modal->addInput(new Form_Input(
'gatewayname6',
'Gateway name',
'text',
- $wancfg['descr'] . "GWv6"
+ $defgatewayname6
));
$modal->addInput(new Form_IpAddress(
@@ -3206,7 +3255,7 @@ $modal->addInput(new Form_Input(
'gatewayname4',
'Gateway name',
'text',
- $wancfg['descr'] . "GW"
+ $defgatewayname4
));
$modal->addInput(new Form_IpAddress(
@@ -3364,52 +3413,6 @@ events.push(function() {
$('#track6-prefix-id-range').html(track6_prefix_ids);
}
- // Create the new gateway from the data entered in the modal pop-up
- function hide_add_gatewaysave_v4() {
- var iface = $('#if').val();
- name = $('#gatewayname4').val();
- var descr = $('#gatewaydescr4').val();
- gatewayip = $('#gatewayip4').val();
-
- var defaultgw = '';
- if ($('#defaultgw4').is(':checked')) {
- defaultgw = '&defaultgw=on';
- }
-
- var url = "system_gateways_edit.php";
- var pars = 'isAjax=true&save=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
- $.ajax(
- url,
- {
- type: 'post',
- data: pars,
- error: report_failure_v4,
- complete: save_callback_v4
- });
- }
-
- function save_callback_v4(response_v4) {
- if (response_v4) {
- var gwtext_v4 = escape(name) + " - " + gatewayip;
- addOption_v4($('#gateway'), gwtext_v4, name);
- } else {
- report_failure_v4();
- }
-
- $("#newgateway4").modal('hide');
- }
-
- function report_failure_v4(request, textStatus, errorThrown) {
- contenttype = ";"+request.getResponseHeader("Content-Type")+";";
- if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
- alert(request.responseText);
- } else {
- alert("The IPv4 gateway could not be created.");
- }
-
- $("#newgateway4").modal('hide');
- }
-
function addOption_v4(selectbox, text, value) {
var optn = document.createElement("OPTION");
optn.text = text;
@@ -3418,29 +3421,6 @@ events.push(function() {
selectbox.prop('selectedIndex', selectbox.children().length - 1);
}
- function hide_add_gatewaysave_v6() {
-
- var iface = $('#if').val();
- name = $('#gatewayname6').val();
- var descr = $('#gatewaydescr6').val();
- gatewayip = $('#gatewayip6').val();
- var defaultgw = '';
- if ($('#defaultgw6').is(':checked')) {
- defaultgw = '&defaultgw=on';
- }
- var url_v6 = "system_gateways_edit.php";
- var pars_v6 = 'isAjax=true&save=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
- $.ajax(
- url_v6,
- {
- type: 'post',
- data: pars_v6,
- error: report_failure_v6,
- success: save_callback_v6
- });
- }
-
-
function addOption_v6(selectbox, text, value) {
var optn = document.createElement("OPTION");
optn.text = text;
@@ -3449,28 +3429,6 @@ events.push(function() {
selectbox.prop('selectedIndex', selectbox.children().length - 1);
}
- function report_failure_v6(request, textStatus, errorThrown) {
- if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
- alert(request.responseText);
- } else {
- alert("The IPv6 gateway could not be created.");
- }
-
- $("#newgateway6").modal('hide');
- }
-
- function save_callback_v6(response_v6) {
- if (response_v6) {
-
- var gwtext_v6 = escape(name) + " - " + gatewayip;
- addOption_v6($('#gatewayv6'), gwtext_v6, name);
- } else {
- report_failure_v6();
- }
-
- $("#newgateway6").modal('hide');
- }
-
function country_list() {
$('#country').children().remove();
$('#provider_list').children().remove();
@@ -3664,18 +3622,28 @@ events.push(function() {
});
$("#add4").click(function() {
- hide_add_gatewaysave_v4();
+ var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
+ addOption_v4($('#gateway'), gwtext_v4, $("#gatewayname4").val());
+ $("#newgateway4").modal('hide');
});
$("#cnx4").click(function() {
+ $("#gatewayname4").val('<?=$defgatewayname4;?>');
+ $("#gatewayip4").val('');
+ $("#gatewaydescr4").val('');
$("#newgateway4").modal('hide');
});
$("#add6").click(function() {
- hide_add_gatewaysave_v6();
+ var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
+ addOption_v6($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
+ $("#newgateway6").modal('hide');
});
$("#cnx6").click(function() {
+ $("#gatewayname6").val('<?=$defgatewayname6;?>');
+ $("#gatewayip6").val('');
+ $("#gatewaydescr6").val('');
$("#newgateway6").modal('hide');
});
OpenPOWER on IntegriCloud