summaryrefslogtreecommitdiffstats
path: root/usr/local/www/interfaces.php
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2008-11-21 02:28:13 +0000
committerScott Ullrich <sullrich@pfsense.org>2008-11-21 02:28:13 +0000
commit270c4607dce6e73ac58b734109189b1c3f69410b (patch)
tree3c368063dd9295b4d9ea0d014b35b26a80405d36 /usr/local/www/interfaces.php
parentec164e2b01596825e19afe81568168898a55be69 (diff)
downloadpfsense-270c4607dce6e73ac58b734109189b1c3f69410b.zip
pfsense-270c4607dce6e73ac58b734109189b1c3f69410b.tar.gz
Cleanup 440 lines of code where the formatting is all shot and is completely
unreadable. Break a couple items into their own functions where we can.
Diffstat (limited to 'usr/local/www/interfaces.php')
-rwxr-xr-xusr/local/www/interfaces.php895
1 files changed, 438 insertions, 457 deletions
diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php
index c213acd..8e29ef7 100755
--- a/usr/local/www/interfaces.php
+++ b/usr/local/www/interfaces.php
@@ -87,6 +87,7 @@ function remove_bad_chars($string) {
if (!is_array($config['gateways']['gateway_item']))
$config['gateways']['gateway_item'] = array();
+
$a_gateways = &$config['gateways']['gateway_item'];
$wancfg = &$config['interfaces'][$if];
@@ -166,8 +167,7 @@ else
if (is_array($config['aliases']['alias']))
foreach($config['aliases']['alias'] as $alias)
if($alias['name'] == $wancfg['descr'])
- $input_errors[] = gettext("Sorry, an alias with the name {$wancfg['descr']} a
-lready exists.");
+ $input_errors[] = gettext("Sorry, an alias with the name {$wancfg['descr']} already exists.");
if ($wancfg['ipaddr'] == "dhcp") {
$pconfig['type'] = "dhcp";
@@ -229,17 +229,16 @@ if (isset($wancfg['wireless'])) {
$pconfig['wep_enable'] = isset($wancfg['wireless']['wep']['enable']);
$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
- if (is_array($wancfg['wireless']['wep']) &&
- is_array($wancfg['wireless']['wep']['key'])) {
- $i = 1;
- foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
- $pconfig['key' . $i] = $wepkey['value'];
- if (isset($wepkey['txkey']))
- $pconfig['txkey'] = $i;
- $i++;
- }
- if (!isset($wepkey['txkey']))
- $pconfig['txkey'] = 1;
+ if (is_array($wancfg['wireless']['wep']) && is_array($wancfg['wireless']['wep']['key'])) {
+ $i = 1;
+ foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
+ $pconfig['key' . $i] = $wepkey['value'];
+ if (isset($wepkey['txkey']))
+ $pconfig['txkey'] = $i;
+ $i++;
+ }
+ if (!isset($wepkey['txkey']))
+ $pconfig['txkey'] = 1;
}
}
@@ -249,20 +248,14 @@ if ($_POST['apply']) {
if (!file_exists($d_landirty_path))
$intput_errors[] = "You have already applied your settings!";
else {
- unlink_if_exists("{$g['tmp_path']}/config.cache");
+ unlink_if_exists("{$g['tmp_path']}/config.cache");
unlink_if_exists("{$d_landirty_path}");
- /* ermal -- do not think these are needed at all.
- ob_flush();
- flush();
- sleep(1);
- */
-
- interface_configure($if);
+ interface_configure($if);
system_start_ftp_helpers();
- reset_carp();
+ reset_carp();
if ($if == "lan") {
/* restart snmp so that it binds to correct address */
@@ -270,484 +263,472 @@ if ($_POST['apply']) {
$savemsg = "The changes have been applied. You may need to correct your web browser's IP address.";
}
- /* sync filter configuration */
+ /* sync filter configuration */
config_lock();
- filter_configure();
+ filter_configure();
config_unlock();
- /* set up static routes */
- system_routing_configure();
+ /* set up static routes */
+ system_routing_configure();
}
header("Location: interfaces.php?if={$if}");
exit;
-} else if ($_POST) {
+}
- unset($input_errors);
- $pconfig = $_POST;
-
- /* filter out spaces from descriptions */
- $_POST['descr'] = remove_bad_chars($_POST['descr']);
-
- /* okay first of all, cause we are just hidding the PPPoE HTML
- * fields releated to PPPoE resets, we are going to unset $_POST
- * vars, if the reset feature should not be used. Otherwise the
- * data validation procedure below, may trigger a false error
- * message.
- */
- if (empty($_POST['pppoe_preset'])) {
- unset($_POST['pppoe_pr_type']);
- unset($_POST['pppoe_resethour']);
- unset($_POST['pppoe_resetminute']);
- unset($_POST['pppoe_resetdate']);
- unset($_POST['pppoe_pr_preset_val']);
- unlink_if_exists(CRON_PPPOE_CMD_FILE);
- }
+if ($_POST && $_POST['enable'] == "no") {
+ unset($wancfg['enable']);
+ interface_bring_down($if);
+ write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
+ touch($d_landirty_path);
+ header("Location: interfaces.php?if={$if}");
+ exit;
+}
- if ($_POST['enable'] == "yes" || $if == "wan" || $if == "lan") {
- /* optional interface if list */
- $iflist = get_configured_interface_with_descr();
+if ($_POST) {
- /* description unique? */
- foreach ($iflist as $ifent => $ifdescr) {
- if ($if != $ifent && $ifdescr == $_POST['descr'])
- $input_errors[] = "An interface with the specified description already exists.";
+ unset($input_errors);
+ $pconfig = $_POST;
+
+ /* filter out spaces from descriptions */
+ $_POST['descr'] = remove_bad_chars($_POST['descr']);
+
+ /* okay first of all, cause we are just hidding the PPPoE HTML
+ * fields releated to PPPoE resets, we are going to unset $_POST
+ * vars, if the reset feature should not be used. Otherwise the
+ * data validation procedure below, may trigger a false error
+ * message.
+ */
+ if (empty($_POST['pppoe_preset'])) {
+ unset($_POST['pppoe_pr_type']);
+ unset($_POST['pppoe_resethour']);
+ unset($_POST['pppoe_resetminute']);
+ unset($_POST['pppoe_resetdate']);
+ unset($_POST['pppoe_pr_preset_val']);
+ unlink_if_exists(CRON_PPPOE_CMD_FILE);
+ }
- }
+ /* optional interface if list */
+ $iflist = get_configured_interface_with_descr();
- /* input validation */
- if ($_POST['type'] == "static") {
- $reqdfields = explode(" ", "ipaddr subnet gateway");
- $reqdfieldsn = explode(",", "IP address,Subnet bit count,Gateway");
- do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
- } else if ($_POST['type'] == "PPPoE") {
- if ($_POST['pppoe_dialondemand']) {
- $reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
- $reqdfieldsn = explode(",", "PPPoE username,PPPoE password,Dial on demand,Idle timeout value");
- } else {
- $reqdfields = explode(" ", "pppoe_username pppoe_password");
- $reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
- }
- do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
- } else if ($_POST['type'] == "PPTP") {
- if ($_POST['pptp_dialondemand']) {
- $reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
- $reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address,Dial on demand,Idle timeout value");
- } else {
- $reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
- $reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
+ /* description unique? */
+ foreach ($iflist as $ifent => $ifdescr) {
+ if ($if != $ifent && $ifdescr == $_POST['descr'])
+ $input_errors[] = "An interface with the specified description already exists.";
}
- do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
- }
-
- /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
- $_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
- if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
- $input_errors[] = "A valid IP address must be specified.";
- }
- if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
- $input_errors[] = "A valid subnet bit count must be specified.";
- }
- if (($_POST['alias-address'] && !is_ipaddr($_POST['alias-address']))) {
- $input_errors[] = "A valid alias IP address must be specified.";
- }
- if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
- $input_errors[] = "A valid alias subnet bit count must be specified.";
- }
- if ($_POST['gateway'] != "none") {
- $match = false;
- foreach($a_gateways as $gateway) {
- if(in_array($_POST['gateway'], $gateway)) {
- $match = true;
+ /* input validation */
+ if ($_POST['type'] == "static") {
+ $reqdfields = explode(" ", "ipaddr subnet gateway");
+ $reqdfieldsn = explode(",", "IP address,Subnet bit count,Gateway");
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+ } else if ($_POST['type'] == "PPPoE") {
+ if ($_POST['pppoe_dialondemand']) {
+ $reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
+ $reqdfieldsn = explode(",", "PPPoE username,PPPoE password,Dial on demand,Idle timeout value");
+ } else {
+ $reqdfields = explode(" ", "pppoe_username pppoe_password");
+ $reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
+ }
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+ } else if ($_POST['type'] == "PPTP") {
+ if ($_POST['pptp_dialondemand']) {
+ $reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
+ $reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address,Dial on demand,Idle timeout value");
+ } else {
+ $reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
+ $reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
}
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
}
- 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.";
- }
- if (($_POST['provider'] && !is_domain($_POST['provider']))) {
- $input_errors[] = "The service name contains invalid characters.";
- }
- if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
- $input_errors[] = "The idle timeout value must be an integer.";
- }
- 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).");
- }
- if ($_POST['pppoe_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) &&
- $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
- $input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
- }
- if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
- $input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
- }
- if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local']))) {
- $input_errors[] = "A valid PPTP local IP address must be specified.";
- }
- if (($_POST['pptp_subnet'] && !is_numeric($_POST['pptp_subnet']))) {
- $input_errors[] = "A valid PPTP subnet bit count must be specified.";
- }
- if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote']))) {
- $input_errors[] = "A valid PPTP remote IP address must be specified.";
- }
- if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
- $input_errors[] = "The idle timeout value must be an integer.";
- }
- if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
- $input_errors[] = "A valid MAC address must be specified.";
- }
- if ($_POST['mtu'] && ($_POST['mtu'] < 576)) {
- $input_errors[] = "The MTU must be greater than 576 bytes.";
- }
- /* Wireless interface? */
- if (isset($wancfg['wireless'])) {
- $reqdfields = explode(" ", "mode ssid");
- $reqdfieldsn = explode(",", "Mode,SSID");
- do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
-
- /* loop through keys and enforce size */
- for ($i = 1; $i <= 4; $i++) {
- if ($_POST['key' . $i]) {
- /* 64 bit */
- if (strlen($_POST['key' . $i]) == 5)
- continue;
- if (strlen($_POST['key' . $i]) == 10) {
- /* hex key */
- if (stristr($_POST['key' . $i], "0x") == false) {
- $_POST['key' . $i] = "0x" . $_POST['key' . $i];
- }
- continue;
+ /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
+ $_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
+
+ if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr'])))
+ $input_errors[] = "A valid IP address must be specified.";
+
+ if (($_POST['subnet'] && !is_numeric($_POST['subnet'])))
+ $input_errors[] = "A valid subnet bit count must be specified.";
+
+ if (($_POST['alias-address'] && !is_ipaddr($_POST['alias-address'])))
+ $input_errors[] = "A valid alias IP address must be specified.";
+
+ if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet'])))
+ $input_errors[] = "A valid alias subnet bit count must be specified.";
+
+ if ($_POST['gateway'] != "none") {
+ $match = false;
+ foreach($a_gateways as $gateway) {
+ if(in_array($_POST['gateway'], $gateway)) {
+ $match = true;
}
- if (strlen($_POST['key' . $i]) == 12) {
- /* hex key */
- if(stristr($_POST['key' . $i], "0x") == false) {
- $_POST['key' . $i] = "0x" . $_POST['key' . $i];
- }
- continue;
- }
- /* 128 bit */
- if (strlen($_POST['key' . $i]) == 13)
- continue;
- if (strlen($_POST['key' . $i]) == 26) {
- /* hex key */
- if (stristr($_POST['key' . $i], "0x") == false)
- $_POST['key' . $i] = "0x" . $_POST['key' . $i];
- continue;
- }
- if(strlen($_POST['key' . $i]) == 28)
- continue;
- $input_errors[] = "Invalid wep key size. Sizes should be 40 (64) bit keys or 104 (128) bit.";
- break;
}
+ 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.";
+ if (($_POST['provider'] && !is_domain($_POST['provider'])))
+ $input_errors[] = "The service name contains invalid characters.";
+ if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout']))
+ $input_errors[] = "The idle timeout value must be an integer.";
+ 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).");
+ if ($_POST['pppoe_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) &&
+ $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59)
+ $input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
+ if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate'])))
+ $input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
+ if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local'])))
+ $input_errors[] = "A valid PPTP local IP address must be specified.";
+ if (($_POST['pptp_subnet'] && !is_numeric($_POST['pptp_subnet'])))
+ $input_errors[] = "A valid PPTP subnet bit count must be specified.";
+ if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote'])))
+ $input_errors[] = "A valid PPTP remote IP address must be specified.";
+ if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout']))
+ $input_errors[] = "The idle timeout value must be an integer.";
+ if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac'])))
+ $input_errors[] = "A valid MAC address must be specified.";
+ if ($_POST['mtu'] && ($_POST['mtu'] < 576))
+ $input_errors[] = "The MTU must be greater than 576 bytes.";
- if (!$input_errors) {
-
- unset($wancfg['ipaddr']);
- unset($wancfg['subnet']);
- unset($wancfg['gateway']);
- unset($wancfg['pointtopoint']);
- unset($wancfg['dhcphostname']);
- unset($wancfg['pppoe_username']);
- unset($wancfg['pppoe_password']);
- unset($wancfg['pptp_username']);
- unset($wancfg['pptp_password']);
- unset($wancfg['provider']);
- unset($wancfg['ondemand']);
- unset($wancfg['timeout']);
- if ($wancfg['pppoe']['pppoe-reset-type'])
- unset($wancfg['pppoe']['pppoe-reset-type']);
- unset($wancfg['local']);
- unset($wancfg['subnet']);
- unset($wancfg['remote']);
- unset($wancfg['disableftpproxy']);
-
- /* per interface pftpx helper */
- if ($_POST['disableftpproxy'] == "yes")
- $wancfg['disableftpproxy'] = true;
-
- $wancfg['descr'] = remove_bad_chars($_POST['descr']);
- if ($if == "wan" || $if == "lan")
- $wancfg['enable'] = true;
- else
- $wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
+ /* Wireless interface? */
+ if (isset($wancfg['wireless'])) {
+ $reqdfields = explode(" ", "mode ssid");
+ $reqdfieldsn = explode(",", "Mode,SSID");
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
- if ($_POST['type'] == "static") {
- $wancfg['ipaddr'] = $_POST['ipaddr'];
- $wancfg['subnet'] = $_POST['subnet'];
- if ($_POST['gateway'] != "none")
- $wancfg['gateway'] = $_POST['gateway'];
- if (isset($wancfg['ispointtopoint']))
- $wancfg['pointtopoint'] = $_POST['pointtopoint'];
- } else if ($_POST['type'] == "dhcp") {
- $wancfg['ipaddr'] = "dhcp";
- $wancfg['dhcphostname'] = $_POST['dhcphostname'];
- $wancfg['alias-address'] = $_POST['alias-address'];
- $wancfg['alias-subnet'] = $_POST['alias-subnet'];
- } else if ($_POST['type'] == "carpdev-dhcp") {
- $wancfg['ipaddr'] = "carpdev-dhcp";
- $wancfg['dhcphostname'] = $_POST['dhcphostname'];
- $wancfg['alias-address'] = $_POST['alias-address'];
- $wancfg['alias-subnet'] = $_POST['alias-subnet'];
- } else if ($_POST['type'] == "pppoe") {
- $wancfg['ipaddr'] = "pppoe";
- $wancfg['pppoe_username'] = $_POST['pppoe_username'];
- $wancfg['pppoe_password'] = $_POST['pppoe_password'];
- $wancfg['provider'] = $_POST['provider'];
- $wancfg['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
- $wancfg['timeout'] = $_POST['pppoe_idletimeout'];
-
- /* perform a periodic reset? */
- if (isset($_POST['pppoe_preset'])) {
- if (! is_array($config['cron']['item']))
- $config['cron']['item'] = array();
-
- $itemhash = getMPDCRONSettings();
- $item = $itemhash['ITEM'];
-
- if (empty($item)) {
- $item = array();
+ /* loop through keys and enforce size */
+ for ($i = 1; $i <= 4; $i++) {
+ if ($_POST['key' . $i]) {
+ /* 64 bit */
+ if (strlen($_POST['key' . $i]) == 5)
+ continue;
+ if (strlen($_POST['key' . $i]) == 10) {
+ /* hex key */
+ if (stristr($_POST['key' . $i], "0x") == false) {
+ $_POST['key' . $i] = "0x" . $_POST['key' . $i];
+ }
+ continue;
}
-
- if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") {
- $wancfg['pppoe']['pppoe-reset-type'] = "custom";
- $pconfig['pppoe_pr_custom'] = true;
-
- $item['minute'] = $_POST['pppoe_resetminute'];
- $item['hour'] = $_POST['pppoe_resethour'];
-
- if (isset($_POST['pppoe_resetdate']) &&
- $_POST['pppoe_resetdate'] <> "" &&
- strlen($_POST['pppoe_resetdate']) == 10) {
- $date = explode("/", $_POST['pppoe_resetdate']);
- $item['mday'] = $date[1];
- $item['month'] = $date[0];
- } else {
- $item['mday'] = "*";
- $item['month'] = "*";
+ if (strlen($_POST['key' . $i]) == 12) {
+ /* hex key */
+ if(stristr($_POST['key' . $i], "0x") == false) {
+ $_POST['key' . $i] = "0x" . $_POST['key' . $i];
}
- $item['wday'] = "*";
- $item['who'] = "root";
- $item['command'] = CRON_PPPOE_CMD_FILE;
- } else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") {
- $wancfg['pppoe']['pppoe-reset-type'] = "preset";
- $pconfig['pppoe_pr_preset'] = true;
-
- switch ($_POST['pppoe_pr_preset_val']) {
- case "monthly":
- $item['minute'] = "0";
- $item['hour'] = "0";
- $item['mday'] = "1";
- $item['month'] = "*";
- $item['wday'] = "*";
- $item['who'] = "root";
- $item['command'] = CRON_PPPOE_CMD_FILE;
- break;
- case "weekly":
- $item['minute'] = "0";
- $item['hour'] = "0";
- $item['mday'] = "*";
- $item['month'] = "*";
- $item['wday'] = "0";
- $item['who'] = "root";
- $item['command'] = CRON_PPPOE_CMD_FILE;
- break;
- case "daily":
- $item['minute'] = "0";
- $item['hour'] = "0";
- $item['mday'] = "*";
- $item['month'] = "*";
- $item['wday'] = "*";
- $item['who'] = "root";
- $item['command'] = CRON_PPPOE_CMD_FILE;
- break;
- case "hourly":
- $item['minute'] = "0";
- $item['hour'] = "*";
- $item['mday'] = "*";
- $item['month'] = "*";
- $item['wday'] = "*";
- $item['who'] = "root";
- $item['command'] = CRON_PPPOE_CMD_FILE;
- break;
- } // end switch
- } // end if
- if (isset($itemhash['ID'])) {
- $config['cron']['item'][$itemhash['ID']] = $item;
- } else {
- $config['cron']['item'][] = $item;
+ continue;
+ }
+ /* 128 bit */
+ if (strlen($_POST['key' . $i]) == 13)
+ continue;
+ if (strlen($_POST['key' . $i]) == 26) {
+ /* hex key */
+ if (stristr($_POST['key' . $i], "0x") == false)
+ $_POST['key' . $i] = "0x" . $_POST['key' . $i];
+ continue;
+ }
+ if(strlen($_POST['key' . $i]) == 28)
+ continue;
+ $input_errors[] = "Invalid wep key size. Sizes should be 40 (64) bit keys or 104 (128) bit.";
+ break;
}
- } // end if
- } else if ($_POST['type'] == "pptp") {
- $wancfg['ipaddr'] = "pptp";
- $wancfg['pptp_username'] = $_POST['pptp_username'];
- $wancfg['pptp_password'] = $_POST['pptp_password'];
- $wancfg['local'] = $_POST['pptp_local'];
- $wancfg['subnet'] = $_POST['pptp_subnet'];
- $wancfg['remote'] = $_POST['pptp_remote'];
- $wancfg['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
- $wancfg['timeout'] = $_POST['pptp_idletimeout'];
+ }
}
+
+ if (!$input_errors) {
+
+ unset($wancfg['ipaddr']);
+ unset($wancfg['subnet']);
+ unset($wancfg['gateway']);
+ unset($wancfg['pointtopoint']);
+ unset($wancfg['dhcphostname']);
+ unset($wancfg['pppoe_username']);
+ unset($wancfg['pppoe_password']);
+ unset($wancfg['pptp_username']);
+ unset($wancfg['pptp_password']);
+ unset($wancfg['provider']);
+ unset($wancfg['ondemand']);
+ unset($wancfg['timeout']);
+ if ($wancfg['pppoe']['pppoe-reset-type'])
+ unset($wancfg['pppoe']['pppoe-reset-type']);
+ unset($wancfg['local']);
+ unset($wancfg['subnet']);
+ unset($wancfg['remote']);
+ unset($wancfg['disableftpproxy']);
+
+ /* per interface pftpx helper */
+ if ($_POST['disableftpproxy'] == "yes")
+ $wancfg['disableftpproxy'] = true;
+
+ $wancfg['descr'] = remove_bad_chars($_POST['descr']);
+ if ($if == "wan" || $if == "lan")
+ $wancfg['enable'] = true;
+ else
+ $wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
+
+ if ($_POST['type'] == "static") {
+ $wancfg['ipaddr'] = $_POST['ipaddr'];
+ $wancfg['subnet'] = $_POST['subnet'];
+ if ($_POST['gateway'] != "none")
+ $wancfg['gateway'] = $_POST['gateway'];
+ if (isset($wancfg['ispointtopoint']))
+ $wancfg['pointtopoint'] = $_POST['pointtopoint'];
+ } else if ($_POST['type'] == "dhcp") {
+ $wancfg['ipaddr'] = "dhcp";
+ $wancfg['dhcphostname'] = $_POST['dhcphostname'];
+ $wancfg['alias-address'] = $_POST['alias-address'];
+ $wancfg['alias-subnet'] = $_POST['alias-subnet'];
+ } else if ($_POST['type'] == "carpdev-dhcp") {
+ $wancfg['ipaddr'] = "carpdev-dhcp";
+ $wancfg['dhcphostname'] = $_POST['dhcphostname'];
+ $wancfg['alias-address'] = $_POST['alias-address'];
+ $wancfg['alias-subnet'] = $_POST['alias-subnet'];
+ } else if ($_POST['type'] == "pppoe") {
+ $wancfg['ipaddr'] = "pppoe";
+ $wancfg['pppoe_username'] = $_POST['pppoe_username'];
+ $wancfg['pppoe_password'] = $_POST['pppoe_password'];
+ $wancfg['provider'] = $_POST['provider'];
+ $wancfg['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
+ $wancfg['timeout'] = $_POST['pppoe_idletimeout'];
+ handle_pppoe_reset();
+ } else if ($_POST['type'] == "pptp") {
+ $wancfg['ipaddr'] = "pptp";
+ $wancfg['pptp_username'] = $_POST['pptp_username'];
+ $wancfg['pptp_password'] = $_POST['pptp_password'];
+ $wancfg['local'] = $_POST['pptp_local'];
+ $wancfg['subnet'] = $_POST['pptp_subnet'];
+ $wancfg['remote'] = $_POST['pptp_remote'];
+ $wancfg['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
+ $wancfg['timeout'] = $_POST['pptp_idletimeout'];
+ }
- /* reset cron items if necessary */
- if (empty($_POST['pppoe_preset'])) {
- /* test whether a cron item exists and unset() it if necessary */
- $itemhash = getMPDCRONSettings();
- $item = $itemhash['ITEM'];
- if (isset($item))
- unset($config['cron']['item'][$itemhash['ID']]);
- }
+ /* reset cron items if necessary */
+ if (empty($_POST['pppoe_preset'])) {
+ /* test whether a cron item exists and unset() it if necessary */
+ $itemhash = getMPDCRONSettings();
+ $item = $itemhash['ITEM'];
+ if (isset($item))
+ unset($config['cron']['item'][$itemhash['ID']]);
+ }
- if($_POST['blockpriv'] == "yes")
- $wancfg['blockpriv'] = true;
- else
- unset($wancfg['blockpriv']);
+ if($_POST['blockpriv'] == "yes")
+ $wancfg['blockpriv'] = true;
+ else
+ unset($wancfg['blockpriv']);
- if($_POST['blockbogons'] == "yes")
- $wancfg['blockbogons'] = true;
- else
- unset($wancfg['blockbogons']);
+ if($_POST['blockbogons'] == "yes")
+ $wancfg['blockbogons'] = true;
+ else
+ unset($wancfg['blockbogons']);
- $wancfg['spoofmac'] = $_POST['spoofmac'];
- $wancfg['mtu'] = $_POST['mtu'];
+ $wancfg['spoofmac'] = $_POST['spoofmac'];
+ $wancfg['mtu'] = $_POST['mtu'];
- if (isset($wancfg['wireless'])) {
- if (!is_array($wancfg['wireless']))
- $wancfg['wireless'] = array();
- $wancfg['wireless']['standard'] = $_POST['standard'];
- $wancfg['wireless']['mode'] = $_POST['mode'];
- $wancfg['wireless']['protmode'] = $_POST['protmode'];
- $wancfg['wireless']['ssid'] = $_POST['ssid'];
- $wancfg['wireless']['channel'] = $_POST['channel'];
- $wancfg['wireless']['authmode'] = $_POST['authmode'];
- $wancfg['wireless']['txpower'] = $_POST['txpower'];
- $wancfg['wireless']['distance'] = $_POST['distance'];
- if (!is_array($wancfg['wireless']['wpa']))
- $wancfg['wireless']['wpa'] = array();
- $wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
- $wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
- $wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
- $wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
- $wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
- $wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
- $wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
- $wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
- $wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
-
- if ($_POST['hidessid_enable'] == "yes")
- $wancfg['wireless']['hidessid']['enable'] = true;
- else if (isset($wancfg['wireless']['hidessid']['enable']))
- unset($wancfg['wireless']['hidessid']['enable']);
-
- if ($_POST['mac_acl_enable'] == "yes")
- $wancfg['wireless']['wpa']['mac_acl_enable'] = true;
- else if (isset($wancfg['wireless']['wpa']['mac_acl_enable']))
- unset($wancfg['wireless']['wpa']['mac_acl_enable']);
-
- if ($_POST['ieee8021x'] == "yes")
- $wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
- else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable']))
- unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
-
- if ($_POST['wpa_strict_rekey'] == "yes")
- $wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
- else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey']))
- unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
-
- if ($_POST['debug_mode'] == "yes")
- $wancfg['wireless']['wpa']['debug_mode'] = true;
- else if (isset($wancfg['wireless']['wpa']['debug_mode']))
- unset($wancfg['wireless']['wpa']['debug_mode']);
-
- if ($_POST['wpa_enable'] == "yes")
- $wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
- else if (isset($wancfg['wireless']['wpa']['enable']))
- unset($wancfg['wireless']['wpa']['enable']);
-
- if ($_POST['wep_enable'] == "yes") {
- if (!is_array($wancfg['wireless']['wep']))
- $wancfg['wireless']['wep'] = array();
- $wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
- } else if (isset($wancfg['wireless']['wep']))
- unset($wancfg['wireless']['wep']);
-
- if ($_POST['wme_enable'] == "yes") {
- if (!is_array($wancfg['wireless']['wme']))
- $wancfg['wireless']['wme'] = array();
- $wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
- } else if (isset($wancfg['wireless']['wme']['enable']))
- unset($wancfg['wireless']['wme']['enable']);
-
- if ($_POST['pureg_enable'] == "yes") {
- if (!is_array($wancfg['wireless']['pureg']))
- $wancfg['wireless']['pureg'] = array();
- $wancfg['wireless']['pureg']['enable'] = $_POST['pureg_enable'] = true;
- } else if (isset($wancfg['wireless']['pureg']['enable']))
- unset($wancfg['wireless']['pureg']['enable']);
-
- if ($_POST['apbridge_enable'] == "yes") {
- if (!is_array($wancfg['wireless']['apbridge']))
- $wancfg['wireless']['apbridge'] = array();
- $wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
- } else if (isset($wancfg['wireless']['apbridge']['enable']))
- unset($wancfg['wireless']['apbridge']['enable']);
-
- if ($_POST['standard'] == "11a Turbo") {
- if (!is_array($wancfg['wireless']['turbo']))
- $wancfg['wireless']['turbo'] = array();
- $wancfg['wireless']['turbo']['enable'] = true;
- } else if (isset($wancfg['wireless']['turbo']['enable']))
- unset($wancfg['wireless']['turbo']['enable']);
-
- $wancfg['wireless']['wep']['key'] = array();
+ if (isset($wancfg['wireless']))
+ handle_wireless_post($wancfg);
- for ($i = 1; $i <= 4; $i++) {
- if ($_POST['key' . $i]) {
- $newkey = array();
- $newkey['value'] = $_POST['key' . $i];
- if ($_POST['txkey'] == $i)
- $newkey['txkey'] = true;
- $wancfg['wireless']['wep']['key'][] = $newkey;
- }
- }
- }
-
- write_config();
+ write_config();
+ touch($d_landirty_path);
+
+ conf_mount_ro();
+
+ header("Location: interfaces.php?if={$if}");
+ exit;
+ }
+} // end if($_POST)
+
+function handle_pppoe_reset() {
+ global $_POST, $config, $g;
+ /* perform a periodic reset? */
+ if(!isset($_POST['pppoe_preset']))
+ return;
+ if (!is_array($config['cron']['item']))
+ $config['cron']['item'] = array();
+ $itemhash = getMPDCRONSettings();
+ $item = $itemhash['ITEM'];
+ if (empty($item))
+ $item = array();
+ if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") {
+ $wancfg['pppoe']['pppoe-reset-type'] = "custom";
+ $pconfig['pppoe_pr_custom'] = true;
+
+ $item['minute'] = $_POST['pppoe_resetminute'];
+ $item['hour'] = $_POST['pppoe_resethour'];
+
+ if (isset($_POST['pppoe_resetdate']) &&
+ $_POST['pppoe_resetdate'] <> "" &&
+ strlen($_POST['pppoe_resetdate']) == 10) {
+ $date = explode("/", $_POST['pppoe_resetdate']);
+ $item['mday'] = $date[1];
+ $item['month'] = $date[0];
+ } else {
+ $item['mday'] = "*";
+ $item['month'] = "*";
+ }
+ $item['wday'] = "*";
+ $item['who'] = "root";
+ $item['command'] = CRON_PPPOE_CMD_FILE;
+ } else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") {
+ $wancfg['pppoe']['pppoe-reset-type'] = "preset";
+ $pconfig['pppoe_pr_preset'] = true;
+
+ switch ($_POST['pppoe_pr_preset_val']) {
+ case "monthly":
+ $item['minute'] = "0";
+ $item['hour'] = "0";
+ $item['mday'] = "1";
+ $item['month'] = "*";
+ $item['wday'] = "*";
+ $item['who'] = "root";
+ $item['command'] = CRON_PPPOE_CMD_FILE;
+ break;
+ case "weekly":
+ $item['minute'] = "0";
+ $item['hour'] = "0";
+ $item['mday'] = "*";
+ $item['month'] = "*";
+ $item['wday'] = "0";
+ $item['who'] = "root";
+ $item['command'] = CRON_PPPOE_CMD_FILE;
+ break;
+ case "daily":
+ $item['minute'] = "0";
+ $item['hour'] = "0";
+ $item['mday'] = "*";
+ $item['month'] = "*";
+ $item['wday'] = "*";
+ $item['who'] = "root";
+ $item['command'] = CRON_PPPOE_CMD_FILE;
+ break;
+ case "hourly":
+ $item['minute'] = "0";
+ $item['hour'] = "*";
+ $item['mday'] = "*";
+ $item['month'] = "*";
+ $item['wday'] = "*";
+ $item['who'] = "root";
+ $item['command'] = CRON_PPPOE_CMD_FILE;
+ break;
+ } // end switch
+ } // end if
+ if (isset($itemhash['ID']))
+ $config['cron']['item'][$itemhash['ID']] = $item;
+ else
+ $config['cron']['item'][] = $item;
+
/* finally install the pppoerestart file */
if (isset($_POST['pppoe_preset'])) {
- config_lock();
- conf_mount_rw();
-
if (! file_exists(CRON_PPPOE_CMD_FILE)) {
file_put_contents(CRON_PPPOE_CMD_FILE, CRON_PPPOE_CMD);
chmod(CRON_PPPOE_CMD_FILE, 0700);
}
-
/* regenerate cron settings/crontab file */
configure_cron();
sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP");
-
- conf_mount_ro();
- config_unlock();
}
+}
- touch($d_landirty_path);
- header("Location: interfaces.php?if={$if}");
- exit;
- }
- } else {
- unset($wancfg['enable']);
- interface_bring_down($if);
- write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
- touch($d_landirty_path);
- header("Location: interfaces.php?if={$if}");
- exit;
+function handle_wireless_post(&$wancfg) {
+ global $_POST, $config, $g;
+ if (!is_array($wancfg['wireless']))
+ $wancfg['wireless'] = array();
+ $wancfg['wireless']['standard'] = $_POST['standard'];
+ $wancfg['wireless']['mode'] = $_POST['mode'];
+ $wancfg['wireless']['protmode'] = $_POST['protmode'];
+ $wancfg['wireless']['ssid'] = $_POST['ssid'];
+ $wancfg['wireless']['channel'] = $_POST['channel'];
+ $wancfg['wireless']['authmode'] = $_POST['authmode'];
+ $wancfg['wireless']['txpower'] = $_POST['txpower'];
+ $wancfg['wireless']['distance'] = $_POST['distance'];
+ if (!is_array($wancfg['wireless']['wpa']))
+ $wancfg['wireless']['wpa'] = array();
+ $wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
+ $wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
+ $wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
+ $wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
+ $wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
+ $wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
+ $wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
+ $wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
+ $wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
+
+ if ($_POST['hidessid_enable'] == "yes")
+ $wancfg['wireless']['hidessid']['enable'] = true;
+ else if (isset($wancfg['wireless']['hidessid']['enable']))
+ unset($wancfg['wireless']['hidessid']['enable']);
+
+ if ($_POST['mac_acl_enable'] == "yes")
+ $wancfg['wireless']['wpa']['mac_acl_enable'] = true;
+ else if (isset($wancfg['wireless']['wpa']['mac_acl_enable']))
+ unset($wancfg['wireless']['wpa']['mac_acl_enable']);
+
+ if ($_POST['ieee8021x'] == "yes")
+ $wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
+ else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable']))
+ unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
+
+ if ($_POST['wpa_strict_rekey'] == "yes")
+ $wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
+ else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey']))
+ unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
+
+ if ($_POST['debug_mode'] == "yes")
+ $wancfg['wireless']['wpa']['debug_mode'] = true;
+ else if (isset($wancfg['wireless']['wpa']['debug_mode']))
+ sunset($wancfg['wireless']['wpa']['debug_mode']);
+
+ if ($_POST['wpa_enable'] == "yes")
+ $wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
+ else if (isset($wancfg['wireless']['wpa']['enable']))
+ unset($wancfg['wireless']['wpa']['enable']);
+
+ if ($_POST['wep_enable'] == "yes") {
+ if (!is_array($wancfg['wireless']['wep']))
+ $wancfg['wireless']['wep'] = array();
+ $wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
+ } else if (isset($wancfg['wireless']['wep']))
+ unset($wancfg['wireless']['wep']);
+
+ if ($_POST['wme_enable'] == "yes") {
+ if (!is_array($wancfg['wireless']['wme']))
+ $wancfg['wireless']['wme'] = array();
+ $wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
+ } else if (isset($wancfg['wireless']['wme']['enable']))
+ unset($wancfg['wireless']['wme']['enable']);
+
+ if ($_POST['pureg_enable'] == "yes") {
+ if (!is_array($wancfg['wireless']['pureg']))
+ $wancfg['wireless']['pureg'] = array();
+ $wancfg['wireless']['pureg']['enable'] = $_POST['pureg_enable'] = true;
+ } else if (isset($wancfg['wireless']['pureg']['enable']))
+ unset($wancfg['wireless']['pureg']['enable']);
+
+ if ($_POST['apbridge_enable'] == "yes") {
+ if (!is_array($wancfg['wireless']['apbridge']))
+ $wancfg['wireless']['apbridge'] = array();
+ $wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
+ } else if (isset($wancfg['wireless']['apbridge']['enable']))
+ unset($wancfg['wireless']['apbridge']['enable']);
+
+ if ($_POST['standard'] == "11a Turbo") {
+ if (!is_array($wancfg['wireless']['turbo']))
+ $wancfg['wireless']['turbo'] = array();
+ $wancfg['wireless']['turbo']['enable'] = true;
+ } else if (isset($wancfg['wireless']['turbo']['enable']))
+ unset($wancfg['wireless']['turbo']['enable']);
+
+ $wancfg['wireless']['wep']['key'] = array();
+
+ for ($i = 1; $i <= 4; $i++) {
+ if ($_POST['key' . $i]) {
+ $newkey = array();
+ $newkey['value'] = $_POST['key' . $i];
+ if ($_POST['txkey'] == $i)
+ $newkey['txkey'] = true;
+ $wancfg['wireless']['wep']['key'][] = $newkey;
+ }
}
}
OpenPOWER on IntegriCloud