summaryrefslogtreecommitdiffstats
path: root/usr/local/www/firewall_aliases_edit.php
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-05-11 11:52:39 +0545
committerPhil Davis <phil.davis@inf.org>2015-05-11 11:52:39 +0545
commit95a40ac01b2f3dd9a48a46430fc520413ba60d92 (patch)
tree1a4c5124855bd145a9f9e437cf50cc95007f91d5 /usr/local/www/firewall_aliases_edit.php
parentd0c28e66a81bb06183b09514c6d1aa87e9c4deb0 (diff)
downloadpfsense-95a40ac01b2f3dd9a48a46430fc520413ba60d92.zip
pfsense-95a40ac01b2f3dd9a48a46430fc520413ba60d92.tar.gz
Code style firewall_aliases
Diffstat (limited to 'usr/local/www/firewall_aliases_edit.php')
-rwxr-xr-xusr/local/www/firewall_aliases_edit.php160
1 files changed, 95 insertions, 65 deletions
diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php
index 1ae4e77..f6a54d7 100755
--- a/usr/local/www/firewall_aliases_edit.php
+++ b/usr/local/www/firewall_aliases_edit.php
@@ -58,26 +58,31 @@ $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firew
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
// Add all Load balance names to reserved_keywords
-if (is_array($config['load_balancer']['lbpool']))
- foreach ($config['load_balancer']['lbpool'] as $lbpool)
+if (is_array($config['load_balancer']['lbpool'])) {
+ foreach ($config['load_balancer']['lbpool'] as $lbpool) {
$reserved_keywords[] = $lbpool['name'];
+ }
+}
$reserved_ifs = get_configured_interface_list(false, true);
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
$max_alias_addresses = 5000;
-if (!is_array($config['aliases']['alias']))
+if (!is_array($config['aliases']['alias'])) {
$config['aliases']['alias'] = array();
+}
$a_aliases = &$config['aliases']['alias'];
$tab = $_REQUEST['tab'];
-if($_POST)
+if ($_POST) {
$origname = $_POST['origname'];
+}
// Debugging
-if($debug)
+if ($debug) {
unlink_if_exists("{$g['tmp_path']}/alias_rename_log.txt");
+}
function alias_same_type($name, $type) {
global $config;
@@ -85,21 +90,25 @@ function alias_same_type($name, $type) {
foreach ($config['aliases']['alias'] as $alias) {
if ($name == $alias['name']) {
if (in_array($type, array("host", "network")) &&
- in_array($alias['type'], array("host", "network")))
+ in_array($alias['type'], array("host", "network"))) {
return true;
- if ($type == $alias['type'])
+ }
+ if ($type == $alias['type']) {
return true;
- else
+ } else {
return false;
+ }
}
}
return true;
}
-if (is_numericint($_GET['id']))
+if (is_numericint($_GET['id'])) {
$id = $_GET['id'];
-if (isset($_POST['id']) && is_numericint($_POST['id']))
+}
+if (isset($_POST['id']) && is_numericint($_POST['id'])) {
$id = $_POST['id'];
+}
if (isset($id) && $a_aliases[$id]) {
$original_alias_name = $a_aliases[$id]['name'];
@@ -109,15 +118,16 @@ if (isset($id) && $a_aliases[$id]) {
$pconfig['type'] = $a_aliases[$id]['type'];
$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
- if(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
+ if (preg_match("/urltable/i", $a_aliases[$id]['type'])) {
$pconfig['address'] = $a_aliases[$id]['url'];
$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
}
- if($a_aliases[$id]['aliasurl'] <> "") {
- if(is_array($a_aliases[$id]['aliasurl']))
+ if ($a_aliases[$id]['aliasurl'] <> "") {
+ if (is_array($a_aliases[$id]['aliasurl'])) {
$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
- else
+ } else {
$pconfig['address'] = $a_aliases[$id]['aliasurl'];
+ }
}
}
@@ -138,8 +148,9 @@ if ($_POST) {
} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
$input_errors[] = gettext("Reserved word used for alias name.");
} else {
- if (is_validaliasname($_POST['name']) == false)
+ if (is_validaliasname($_POST['name']) == false) {
$input_errors[] = gettext("The alias name must be less than 32 characters long, may not consist of only numbers, and may only contain the following characters") . " a-z, A-Z, 0-9, _.";
+ }
}
/* check for name conflicts */
if (empty($a_aliases[$id])) {
@@ -152,13 +163,15 @@ if ($_POST) {
}
/* Check for reserved keyword names */
- foreach($reserved_keywords as $rk)
- if($rk == $_POST['name'])
+ foreach ($reserved_keywords as $rk) {
+ if ($rk == $_POST['name']) {
$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk);
+ }
+ }
/* check for name interface description conflicts */
- foreach($config['interfaces'] as $interface) {
- if($interface['descr'] == $_POST['name']) {
+ foreach ($config['interfaces'] as $interface) {
+ if ($interface['descr'] == $_POST['name']) {
$input_errors[] = gettext("An interface description with this name already exists.");
break;
}
@@ -193,16 +206,17 @@ if ($_POST) {
$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail0"], "|"));
$input_errors[] = $vertical_bar_err_text;
}
- } else
+ } else {
$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
+ }
}
} else if ($_POST['type'] == "url" || $_POST['type'] == "url_ports") {
$desc_fmt_err_found = false;
/* item is a url type */
- for($x=0; $x<$max_alias_addresses-1; $x++) {
+ for ($x=0; $x<$max_alias_addresses-1; $x++) {
$_POST['address' . $x] = trim($_POST['address' . $x]);
- if($_POST['address' . $x]) {
+ if ($_POST['address' . $x]) {
/* fetch down and add in */
$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
unlink_if_exists($temp_filename);
@@ -211,13 +225,15 @@ if ($_POST) {
download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl);
/* if the item is tar gzipped then extract */
- if(stristr($_POST['address' . $x], ".tgz"))
+ if (stristr($_POST['address' . $x], ".tgz")) {
process_alias_tgz($temp_filename);
- else if(stristr($_POST['address' . $x], ".zip"))
+ } else if (stristr($_POST['address' . $x], ".zip")) {
process_alias_unzip($temp_filename);
+ }
- if (!isset($alias['aliasurl']))
+ if (!isset($alias['aliasurl'])) {
$alias['aliasurl'] = array();
+ }
$alias['aliasurl'][] = $_POST['address' . $x];
if ($_POST["detail{$x}"] <> "") {
@@ -232,12 +248,13 @@ if ($_POST) {
$desc_fmt_err_found = true;
}
}
- } else
+ } else {
$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
+ }
- if(file_exists("{$temp_filename}/aliases")) {
+ if (file_exists("{$temp_filename}/aliases")) {
$address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 3000);
- if($address == null) {
+ if ($address == null) {
/* nothing was found */
$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
}
@@ -248,20 +265,21 @@ if ($_POST) {
}
}
unset($desc_fmt_err_found);
- if ($_POST['type'] == "url_ports")
+ if ($_POST['type'] == "url_ports") {
$address = group_ports($address);
+ }
} else {
/* item is a normal alias type */
$wrongaliases = "";
$desc_fmt_err_found = false;
$alias_address_count = 0;
- // First trim and expand the input data.
+ // First trim and expand the input data.
// Users can paste strings like "10.1.2.0/24 10.3.0.0/16 9.10.11.0/24" into an address box.
// They can also put an IP range.
// This loop expands out that stuff so it can easily be validated.
- for($x=0; $x<($max_alias_addresses-1); $x++) {
- if($_POST["address{$x}"] <> "") {
+ for ($x=0; $x<($max_alias_addresses-1); $x++) {
+ if ($_POST["address{$x}"] <> "") {
if ($_POST["detail{$x}"] <> "") {
if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
$detail_text = $_POST["detail{$x}"];
@@ -377,33 +395,39 @@ if ($_POST) {
}
// Validate the input data expanded above.
- foreach($input_addresses as $idx => $input_address) {
+ foreach ($input_addresses as $idx => $input_address) {
if (is_alias($input_address)) {
- if (!alias_same_type($input_address, $_POST['type']))
+ if (!alias_same_type($input_address, $_POST['type'])) {
// But alias type network can include alias type urltable. Feature#1603.
if (!($_POST['type'] == 'network' &&
- preg_match("/urltable/i", alias_get_type($input_address))))
+ preg_match("/urltable/i", alias_get_type($input_address)))) {
$wrongaliases .= " " . $input_address;
+ }
+ }
} else if ($_POST['type'] == "port") {
- if (!is_port($input_address) && !is_portrange($input_address))
+ if (!is_port($input_address) && !is_portrange($input_address)) {
$input_errors[] = $input_address . " " . gettext("is not a valid port or alias.");
+ }
} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
- if (is_subnet($input_address) ||
- (!is_ipaddr($input_address) && !is_hostname($input_address)))
+ if (is_subnet($input_address) ||
+ (!is_ipaddr($input_address) && !is_hostname($input_address))) {
$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s address, FQDN or alias.'), $input_address, $_POST['type']);
+ }
}
$tmpaddress = $input_address;
if ($_POST['type'] != "host" && is_ipaddr($input_address) && $input_address_subnet[$idx] <> "") {
- if (!is_subnet($input_address . "/" . $input_address_subnet[$idx]))
+ if (!is_subnet($input_address . "/" . $input_address_subnet[$idx])) {
$input_errors[] = sprintf(gettext('%s/%s is not a valid subnet.'), $input_address, $input_address_subnet[$idx]);
- else
+ } else {
$tmpaddress .= "/" . $input_address_subnet[$idx];
+ }
}
$address[] = $tmpaddress;
}
unset($desc_fmt_err_found);
- if ($wrongaliases <> "")
+ if ($wrongaliases <> "") {
$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
+ }
}
unset($vertical_bar_err_text);
@@ -461,36 +485,39 @@ if ($_POST) {
$tmpdirty = true;
}
}
- if ($tmpdirty == true)
+ if ($tmpdirty == true) {
$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
+ }
}
}
}
$a_aliases[$id] = $alias;
- } else
+ } else {
$a_aliases[] = $alias;
+ }
// Sort list
$a_aliases = msort($a_aliases, "name");
- if (write_config())
+ if (write_config()) {
mark_subsystem_dirty('aliases');
+ }
- if(!empty($tab))
+ if (!empty($tab)) {
header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
- else
+ } else {
header("Location: firewall_aliases.php");
+ }
exit;
- }
- //we received input errors, copy data to prevent retype
- else
- {
+ } else {
+ //we received input errors, copy data to prevent retype
$pconfig['name'] = $_POST['name'];
$pconfig['descr'] = $_POST['descr'];
- if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports'))
+ if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports')) {
$pconfig['address'] = implode(" ", $alias['aliasurl']);
- else
+ } else {
$pconfig['address'] = implode(" ", $address);
+ }
$pconfig['type'] = $_POST['type'];
$pconfig['detail'] = implode("||", $final_address_details);
}
@@ -536,8 +563,9 @@ function typesel_change() {
}
jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
- if (set_value == true)
+ if (set_value == true) {
jQuery("select[id^='address_subnet']").prop("value", field_value);
+ }
}
function add_alias_control() {
@@ -581,7 +609,7 @@ $jscriptstr .= <<<EOD
function update_box_type() {
var indexNum = document.forms[0].type.selectedIndex;
var selected = document.forms[0].type.options[indexNum].text;
- if(selected == '{$networks_str}') {
+ if (selected == '{$networks_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
@@ -589,7 +617,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$hosts_str}') {
+ } else if (selected == '{$hosts_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
document.getElementById ("twocolumn").firstChild.data = "";
@@ -597,7 +625,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$ports_str}') {
+ } else if (selected == '{$ports_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
document.getElementById ("twocolumn").firstChild.data = "";
@@ -605,7 +633,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$url_str}') {
+ } else if (selected == '{$url_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
document.getElementById ("twocolumn").firstChild.data = "";
@@ -613,7 +641,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$url_ports_str}') {
+ } else if (selected == '{$url_ports_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
document.getElementById ("twocolumn").firstChild.data = "";
@@ -621,7 +649,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$openvpn_user_str}') {
+ } else if (selected == '{$openvpn_user_str}') {
document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
@@ -629,7 +657,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'block';
document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
document.getElementById ("addrowbutton").style.display = 'block';
- } else if(selected == '{$urltable_str}') {
+ } else if (selected == '{$urltable_str}') {
if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
addRowTo('maintable', 'formfldalias');
typesel_change();
@@ -642,7 +670,7 @@ function update_box_type() {
document.getElementById ("threecolumn").style.display = 'none';
document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
document.getElementById ("addrowbutton").style.display = 'none';
- } else if(selected == '{$urltable_ports_str}') {
+ } else if (selected == '{$urltable_ports_str}') {
if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
addRowTo('maintable', 'formfldalias');
typesel_change();
@@ -701,12 +729,13 @@ EOD;
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
<?php
if (empty($tab)) {
- if (preg_match("/url/i", $pconfig['type']))
+ if (preg_match("/url/i", $pconfig['type'])) {
$tab = 'url';
- else if ($pconfig['type'] == 'host')
+ } else if ($pconfig['type'] == 'host') {
$tab = 'ip';
- else
+ } else {
$tab = $pconfig['type'];
+ }
}
?>
<input name="tab" type="hidden" id="tab" value="<?=htmlspecialchars($tab);?>" />
@@ -840,8 +869,9 @@ if (empty($tab)) {
function createAutoSuggest() {
<?php
- for ($jv = 0; $jv < $counter; $jv++)
+ for ($jv = 0; $jv < $counter; $jv++) {
echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
+ }
?>
}
OpenPOWER on IntegriCloud