diff --git a/src/www/interfaces_ppps_edit.php b/src/www/interfaces_ppps_edit.php index fd0763fac..921bc7f4f 100644 --- a/src/www/interfaces_ppps_edit.php +++ b/src/www/interfaces_ppps_edit.php @@ -1,826 +1,919 @@ . - Copyright (C) 2010 Gabriel B. . - All rights reserved. + Copyright (C) 2014-2015 Deciso B.V. + Copyright (C) 2003-2004 Manuel Kasper . + Copyright (C) 2010 Gabriel B. . + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - 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 - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + 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 + POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("services.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_ppps.php'); - -define("CRON_MONTHLY_PATTERN", "0 0 1 * *"); -define("CRON_WEEKLY_PATTERN", "0 0 * * 0"); -define("CRON_DAILY_PATTERN", "0 0 * * *"); -define("CRON_HOURLY_PATTERN", "0 * * * *"); - if (!isset($config['ppps'])) { - $config['ppps'] = array(); + $config['ppps'] = array(); } - if (!isset($config['ppps']['ppp'])) { - $config['ppps']['ppp'] = array(); + $config['ppps']['ppp'] = array(); } - $a_ppps = &$config['ppps']['ppp']; -$iflist = get_configured_interface_with_descr(); -$portlist = get_interface_list(); -$portlist = array_merge($portlist, $iflist); -if (isset($config['vlans']['vlan'])) { - foreach ($config['vlans']['vlan'] as $vlan) { - $portlist[$vlan['vlanif']] = $vlan; - } +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + $pconfig = array(); + if (isset($_GET['id']) && !empty($a_ppps[$_GET['id']])) { + $id = $_GET['id']; + } + $copy_fields = array('ptpid', 'type', 'username', 'idletimeout', 'uptime', 'descr', 'simpin', 'pin-wait', + 'apn', 'apnum', 'phone', 'connect-timeout', 'provider', 'pppoe-reset-type'); + foreach ($copy_fields as $fieldname) { + if (isset($a_ppps[$id][$fieldname])) { + $pconfig[$fieldname] = $a_ppps[$id][$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } + $explode_fields = array('mtu', 'mru', 'mrru', 'bandwidth', 'localip', 'gateway', 'localip', 'subnet', 'ports'); + foreach ($explode_fields as $fieldname) { + if (isset($a_ppps[$id][$fieldname])) { + $pconfig[$fieldname] = explode(",", $a_ppps[$id][$fieldname]); + } else { + $pconfig[$fieldname] = array(); + } + } + + $bool_fields = array('ondemand', 'shortseq', 'acfcomp', 'protocomp', 'vjcomp', 'tcpmssfix'); + foreach ($bool_fields as $fieldname) { + $pconfig[$fieldname] = isset($a_ppps[$id][$fieldname]); + } + $pconfig['password'] = isset($a_ppps[$id]['password']) ? base64_decode($a_ppps[$id]['password']) : null; + $pconfig['initstr'] = isset($a_ppps[$id]['initstr']) ? base64_decode($a_ppps[$id]['initstr']) : null; + $pconfig['null_service'] = (isset($a_ppps[$id]['provider']) && empty($a_ppps[$id]['provider'])); + + if (!empty($a_ppps[$id]['pppoe-reset-type'])) { + $itemhash = getMPDCRONSettings($a_ppps[$id]['if']); + if (!empty($itemhash)) { + $cronitem = $itemhash['ITEM']; + $pconfig['pppoe_resetminute'] = $cronitem['minute']; + $pconfig['pppoe_resethour'] = $cronitem['hour']; + $pconfig['pppoe_resetmday'] = $cronitem['mday']; + $pconfig['pppoe_resetmonth'] = $cronitem['month']; + $pconfig['pppoe_resetwday'] = $cronitem['wday']; + } + } + if (empty($pconfig['ptpid'])) { + $pconfig['ptpid'] = interfaces_ptpid_next(); + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['id']) && !empty($a_ppps[$_POST['id']])) { + $id = $_POST['id']; + } + $input_errors = array(); + $pconfig = $_POST; + + /* input validation */ + switch($pconfig['type']) { + case "ppp": + $reqdfields = explode(" ", "ports phone"); + $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Phone Number")); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + break; + case "pppoe": + if ($_POST['ondemand']) { + $reqdfields = explode(" ", "ports username password ondemand idletimeout"); + $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Dial on demand"),gettext("Idle timeout value")); + } else { + $reqdfields = explode(" ", "ports username password"); + $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password")); + } + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + break; + case "l2tp": + case "pptp": + if ($pconfig['ondemand']) { + $reqdfields = explode(" ", "ports username password localip subnet gateway ondemand idletimeout"); + $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Local IP address"),gettext("Subnet"),gettext("Remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value")); + } else { + $reqdfields = explode(" ", "ports username password localip subnet gateway"); + $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Local IP address"),gettext("Subnet"),gettext("Remote IP address")); + } + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + break; + default: + $input_errors[] = gettext("Please choose a Link Type."); + break; + } + if ($pconfig['type'] == "ppp" && count($pconfig['ports']) > 1) { + $input_errors[] = gettext("Multilink connections (MLPPP) using the PPP link type is not currently supported. Please select only one Link Interface."); + } + if (!empty($pconfig['provider']) && !is_domain($pconfig['provider'])) { + $input_errors[] = gettext("The Service name contains invalid characters."); + } + if (!empty($pconfig['provider']) && !empty($pconfig['null_service'])) { + $input_errors[] = gettext("Do not specify both a Service name and a NULL Service name."); + } + if (($pconfig['idletimeout'] != "") && !is_numericint($pconfig['idletimeout'])) { + $input_errors[] = gettext("The idle timeout value must be an integer."); + } + + if (!empty($pconfig['pppoe-reset-type'])) { + if (!empty($pconfig['pppoe_resethour']) && (!is_numericint($pconfig['pppoe_resethour']) || $pconfig['pppoe_resethour'] < 0 || $pconfig['pppoe_resethour'] > 23)) { + $input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23)."); + } + if (!empty($pconfig['pppoe_resetminute']) && (!is_numericint($pconfig['pppoe_resetminute']) || $pconfig['pppoe_resetminute'] < 0 || $pconfig['pppoe_resetminute'] > 59)) { + $input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59)."); + } + if (!empty($pconfig['pppoe_resetdate']) && !is_numeric(str_replace("/", "", $pconfig['pppoe_resetdate']))) { + $input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy)."); + } + } + + + foreach($pconfig['ports'] as $iface_idx => $iface){ + if (!empty($pconfig['localip'][$iface_idx]) && !is_ipaddr($pconfig['localip'][$iface_idx])) { + $input_errors[] = sprintf(gettext("A valid local IP address must be specified for %s."),$iface); + } + if (!empty($pconfig['gateway'][$iface_idx]) && !is_ipaddr($pconfig['gateway'][$iface_idx]) && !is_hostname($pconfig['gateway'][$iface_idx])) { + $input_errors[] = sprintf(gettext("A valid gateway IP address OR hostname must be specified for %s."),$iface); + } + if (!empty($pconfig['bandwidth'][$iface_idx]) && !is_numericint($pconfig['bandwidth'][$iface_idx])) { + $input_errors[] = sprintf(gettext("The bandwidth value for %s must be an integer."),$iface); + } + + if (!empty($pconfig['mtu'][$iface_idx]) && ($pconfig['mtu'][$iface_idx] < 576)) { + $input_errors[] = sprintf(gettext("The MTU for %s must be greater than 576 bytes."),$iface); + } + if (!empty($pconfig['mru'][$iface_idx]) && ($pconfig['mru'][$iface_idx] < 576)) { + $input_errors[] = sprintf(gettext("The MRU for %s must be greater than 576 bytes."),$iface); + } + } + + if (count($input_errors) == 0) { + $ppp = array(); + $ppp['ptpid'] = $pconfig['ptpid']; + $ppp['type'] = $pconfig['type']; + $ppp['if'] = $ppp['type'].$ppp['ptpid']; + $ppp['ports'] = implode(',',$pconfig['ports']); + $ppp['username'] = $pconfig['username']; + $ppp['password'] = base64_encode($pconfig['password']); + $ppp['ondemand'] = !empty($pconfig['ondemand']); + if (!empty($pconfig['idletimeout'])) { + $ppp['idletimeout'] = $pconfig['idletimeout']; + } + $ppp['uptime'] = !empty($pconfig['uptime']); + if (!empty($pconfig['descr'])) { + $ppp['descr'] = $pconfig['descr']; + } + + // Loop through fields associated with a individual link/port and make an array of the data + $port_fields = array("localip", "gateway", "subnet", "bandwidth", "mtu", "mru", "mrru"); + $port_data = array(); + foreach($pconfig['ports'] as $iface_idx => $iface){ + $port_data[$field_label] = array(); + foreach($port_fields as $field_label){ + if (isset($pconfig[$field_label][$iface_idx])) { + $port_data[$field_label][] = $pconfig[$field_label][$iface_idx]; + } + } + } + switch($pconfig['type']) { + case "ppp": + if (!empty($pconfig['initstr'])) { + $ppp['initstr'] = base64_encode($pconfig['initstr']); + } + if (!empty($pconfig['simpin'])) { + $ppp['simpin'] = $pconfig['simpin']; + $ppp['pin-wait'] = $pconfig['pin-wait']; + } + if (!empty($pconfig['apn'])){ + $ppp['apn'] = $pconfig['apn']; + $ppp['apnum'] = $pconfig['apnum']; + } + $ppp['phone'] = $pconfig['phone']; + $ppp['localip'] = implode(',',$port_data['localip']); + $ppp['gateway'] = implode(',',$port_data['gateway']); + if (!empty($pconfig['connect-timeout'])) { + $ppp['connect-timeout'] = $pconfig['connect-timeout']; + } + break; + case "pppoe": + if (!empty($pconfig['provider'])) { + $ppp['provider'] = $pconfig['provider']; + } else { + $ppp['provider'] = !empty($pconfig['null_service']); + } + if (!empty($pconfig['pppoe-reset-type'])) { + $ppp['pppoe-reset-type'] = $pconfig['pppoe-reset-type']; + } + break; + case "pptp": + case "l2tp": + $ppp['localip'] = implode(',',$port_data['localip']); + $ppp['subnet'] = implode(',',$port_data['subnet']); + $ppp['gateway'] = implode(',',$port_data['gateway']); + break; + default: + break; + } + + $ppp['shortseq'] = !empty($pconfig['shortseq']); + $ppp['acfcomp'] = !empty($pconfig['acfcomp']); + $ppp['protocomp'] = !empty($pconfig['protocomp']); + $ppp['vjcomp'] = !empty($pconfig['vjcomp']); + $ppp['tcpmssfix'] = !empty($pconfig['tcpmssfix']); + $ppp['bandwidth'] = implode(',', $port_data['bandwidth']); + $ppp['mtu'] = implode(',', $port_data['mtu']); + $ppp['mru'] = implode(',', $port_data['mru']); + $ppp['mrru'] = implode(',', $port_data['mrru']); + + // XXX this was already in here, but is probably not the correct place to create this + if (!is_dir('/var/spool/lock')) { + mwexec('/bin/mkdir -p /var/spool/lock'); + } + /* handle_pppoe_reset is called here because if user changes Link Type from PPPoE to another type we + must be able to clear the config data in the section of config.xml if it exists + */ + // yak... room for improvement here.... (see interfaces.php as well) + handle_pppoe_reset($pconfig); + + if (isset($id)) { + $a_ppps[$id] = $ppp; + } else { + $a_ppps[] = $ppp; + } + + write_config(); + configure_cron(); + $iflist = get_configured_interface_with_descr(); + foreach ($iflist as $pppif => $ifdescr) { + if ($config['interfaces'][$pppif]['if'] == $ppp['if']) + interface_ppps_configure($pppif); + } + header("Location: interfaces_ppps.php"); + exit; + } } -if (is_numericint($_GET['id'])) - $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) - $id = $_POST['id']; - -if (isset($id) && $a_ppps[$id]) { - $pconfig['ptpid'] = $a_ppps[$id]['ptpid']; - $pconfig['type'] = $a_ppps[$id]['type']; - //$pconfig['if'] = $a_ppps[$id]['if']; - $pconfig['interfaces'] = $a_ppps[$id]['ports']; - $pconfig['username'] = $a_ppps[$id]['username']; - $pconfig['password'] = base64_decode($a_ppps[$id]['password']); - if (isset($a_ppps[$id]['ondemand'])) - $pconfig['ondemand'] = true; - $pconfig['idletimeout'] = $a_ppps[$id]['idletimeout']; - $pconfig['uptime'] = $a_ppps[$id]['uptime']; - $pconfig['descr'] = $a_ppps[$id]['descr']; - $pconfig['bandwidth'] = explode(",",$a_ppps[$id]['bandwidth']); - $pconfig['mtu'] = explode(",",$a_ppps[$id]['mtu']); - $pconfig['mru'] = explode(",",$a_ppps[$id]['mru']); - $pconfig['mrru'] = explode(",",$a_ppps[$id]['mrru']); - if (isset($a_ppps[$id]['shortseq'])) - $pconfig['shortseq'] = true; - if (isset($a_ppps[$id]['acfcomp'])) - $pconfig['acfcomp'] = true; - if (isset($a_ppps[$id]['protocomp'])) - $pconfig['protocomp'] = true; - if (isset($a_ppps[$id]['vjcomp'])) - $pconfig['vjcomp'] = true; - if (isset($a_ppps[$id]['tcpmssfix'])) - $pconfig['tcpmssfix'] = true; - switch($a_ppps[$id]['type']) { - case "ppp": - $pconfig['initstr'] = base64_decode($a_ppps[$id]['initstr']); - $pconfig['simpin'] = $a_ppps[$id]['simpin']; - $pconfig['pin-wait'] = $a_ppps[$id]['pin-wait']; - $pconfig['apn'] = $a_ppps[$id]['apn']; - $pconfig['apnum'] = $a_ppps[$id]['apnum']; - $pconfig['phone'] = $a_ppps[$id]['phone']; - $pconfig['connect-timeout'] = $a_ppps[$id]['connect-timeout']; - $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); - $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); - break; - case "l2tp": - case "pptp": - $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); - $pconfig['subnet'] = explode(",",$a_ppps[$id]['subnet']); - $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); - case "pppoe": - $pconfig['provider'] = $a_ppps[$id]['provider']; - if (isset($a_ppps[$id]['provider']) and empty($a_ppps[$id]['provider'])) - $pconfig['null_service'] = true; - /* ================================================ */ - /* = force a connection reset at a specific time? = */ - /* ================================================ */ - - if (isset($a_ppps[$id]['pppoe-reset-type'])) { - $pconfig['pppoe-reset-type'] = $a_ppps[$id]['pppoe-reset-type']; - $itemhash = getMPDCRONSettings($a_ppps[$id]['if']); - $cronitem = $itemhash['ITEM']; - if (isset($cronitem)) { - $resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; - } else { - $resetTime = NULL; - } - - if ($a_ppps[$id]['pppoe-reset-type'] == "custom") { - $resetTime_a = explode(" ", $resetTime); - $pconfig['pppoe_pr_custom'] = true; - $pconfig['pppoe_resetminute'] = $resetTime_a[0]; - $pconfig['pppoe_resethour'] = $resetTime_a[1]; - /* just initialize $pconfig['pppoe_resetdate'] if the - * coresponding item contains appropriate numeric values. - */ - if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") - $pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y"); - } else if ($a_ppps[$id]['pppoe-reset-type'] == "preset") { - $pconfig['pppoe_pr_preset'] = true; - switch ($resetTime) { - case CRON_MONTHLY_PATTERN: - $pconfig['pppoe_monthly'] = true; - break; - case CRON_WEEKLY_PATTERN: - $pconfig['pppoe_weekly'] = true; - break; - case CRON_DAILY_PATTERN: - $pconfig['pppoe_daily'] = true; - break; - case CRON_HOURLY_PATTERN: - $pconfig['pppoe_hourly'] = true; - break; - } - } - } - break; - } - -} else { - $pconfig['ptpid'] = interfaces_ptpid_next(); -} - -if ($_POST) { - - unset($input_errors); - - /* okay first of all, cause we are just hiding 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-reset-type'])) { - unset($_POST['pppoe_resethour']); - unset($_POST['pppoe_resetminute']); - unset($_POST['pppoe_resetdate']); - unset($_POST['pppoe_pr_preset_val']); - } - - if (!isset($_POST['interfaces'])) { - $_POST['interfaces'] = array(); - } - - $pconfig = $_POST; - - /* input validation */ - switch($_POST['type']) { - case "ppp": - $reqdfields = explode(" ", "interfaces phone"); - $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Phone Number")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - break; - case "pppoe": - if ($_POST['ondemand']) { - $reqdfields = explode(" ", "interfaces username password ondemand idletimeout"); - $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Dial on demand"),gettext("Idle timeout value")); - } else { - $reqdfields = explode(" ", "interfaces username password"); - $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password")); - } - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - break; - case "l2tp": - case "pptp": - if ($_POST['ondemand']) { - $reqdfields = explode(" ", "interfaces username password localip subnet gateway ondemand idletimeout"); - $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Local IP address"),gettext("Subnet"),gettext("Remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value")); - } else { - $reqdfields = explode(" ", "interfaces username password localip subnet gateway"); - $reqdfieldsn = array(gettext("Link Interface(s)"),gettext("Username"),gettext("Password"),gettext("Local IP address"),gettext("Subnet"),gettext("Remote IP address")); - } - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - break; - default: - $input_errors[] = gettext("Please choose a Link Type."); - break; - } - if ($_POST['type'] == "ppp" && count($_POST['interfaces']) > 1) - $input_errors[] = gettext("Multilink connections (MLPPP) using the PPP link type is not currently supported. Please select only one Link Interface."); - if ($_POST['provider'] && !is_domain($_POST['provider'])) - $input_errors[] = gettext("The Service name contains invalid characters."); - if ($_POST['provider'] && $_POST['null_service']) - $input_errors[] = gettext("Do not specify both a Service name and a NULL Service name."); - if (($_POST['idletimeout'] != "") && !is_numericint($_POST['idletimeout'])) - $input_errors[] = gettext("The idle timeout value must be an integer."); - if ($_POST['pppoe-reset-type'] == "custom" && $_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-reset-type'] == "custom" && $_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-reset-type'] == "custom" && $_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['pppoe-reset-type'] == "custom" && $_POST['pppoe_resetdate'] <> "" && is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))){ - $date_nums = explode("/",$_POST['pppoe_resetdate']); - if ($date_nums[0] < 1 || $date_nums[0] > 12) - $input_errors[] = gettext("A valid PPPoE reset month must be specified (1-12) in the Custom PPPoE Periodic reset fields."); - if ($date_nums[1] < 1 || $date_nums[1] > 31) - $input_errors[] = gettext("A valid PPPoE reset day of month must be specified (1-31) in the Custom PPPoE Periodic reset fields. No checks are done on valid # of days per month"); - if ($date_nums[2] < date("Y")) - $input_errors[] = gettext("A valid PPPoE reset year must be specified. Don't select a year in the past!"); - } - - foreach($_POST['interfaces'] as $iface){ - if ($_POST['localip'][$iface] && !is_ipaddr($_POST['localip'][$iface])) - $input_errors[] = sprintf(gettext("A valid local IP address must be specified for %s."),$iface); - if ($_POST['gateway'][$iface] && !is_ipaddr($_POST['gateway'][$iface]) && !is_hostname($_POST['gateway'][$iface])) - $input_errors[] = sprintf(gettext("A valid gateway IP address OR hostname must be specified for %s."),$iface); - if ($_POST['bandwidth'][$iface] && !is_numericint($_POST['bandwidth'][$iface])) - $input_errors[] = sprintf(gettext("The bandwidth value for %s must be an integer."),$iface); - if ($_POST['mtu'][$iface] && ($_POST['mtu'][$iface] < 576)) - $input_errors[] = sprintf(gettext("The MTU for %s must be greater than 576 bytes."),$iface); - if ($_POST['mru'][$iface] && ($_POST['mru'][$iface] < 576)) - $input_errors[] = sprintf(gettext("The MRU for %s must be greater than 576 bytes."),$iface); - } - -/* - foreach ($a_ppps as $ppp) { - if (isset($id) && ($a_ppps[$id]) && ($a_ppps[$id] === $ppp)) - continue; - - if ($ppp['serialport'] == $_POST['serialport']) { - $input_errors[] = gettext("Serial port is in use"); - break; - } - } -*/ - - if (!$input_errors) { - $ppp = array(); - $ppp['ptpid'] = $_POST['ptpid']; - $ppp['type'] = $_POST['type']; - $ppp['if'] = $ppp['type'].$ppp['ptpid']; - $ppp['ports'] = implode(',',$_POST['interfaces']); - $ppp['username'] = $_POST['username']; - $ppp['password'] = base64_encode($_POST['password']); - $ppp['ondemand'] = $_POST['ondemand'] ? true : false; - if (!empty($_POST['idletimeout'])) - $ppp['idletimeout'] = $_POST['idletimeout']; - else - unset($ppp['idletimeout']); - $ppp['uptime'] = $_POST['uptime'] ? true : false; - if (!empty($_POST['descr'])) - $ppp['descr'] = $_POST['descr']; - else - unset($ppp['descr']); - - // Loop through fields associated with a individual link/port and make an array of the data - $port_fields = array("localip", "gateway", "subnet", "bandwidth", "mtu", "mru", "mrru"); - foreach($_POST['interfaces'] as $iface){ - foreach($port_fields as $field_label){ - if (isset($_POST[$field_label][$iface])) - $port_data[$field_label][] = $_POST[$field_label][$iface]; - } - } - - switch($_POST['type']) { - case "ppp": - if (!empty($_POST['initstr'])) - $ppp['initstr'] = base64_encode($_POST['initstr']); - else - unset($ppp['initstr']); - if (!empty($_POST['simpin'])) { - $ppp['simpin'] = $_POST['simpin']; - $ppp['pin-wait'] = $_POST['pin-wait']; - } else { - unset($ppp['simpin']); - unset($ppp['pin-wait']); - } - - if (!empty($_POST['apn'])){ - $ppp['apn'] = $_POST['apn']; - $ppp['apnum'] = $_POST['apnum']; - } else { - unset($ppp['apn']); - unset($ppp['apnum']); - } - $ppp['phone'] = $_POST['phone']; - $ppp['localip'] = implode(',',$port_data['localip']); - $ppp['gateway'] = implode(',',$port_data['gateway']); - if (!empty($_POST['connect-timeout'])) - $ppp['connect-timeout'] = $_POST['connect-timeout']; - else - unset($ppp['connect-timeout']); - break; - case "pppoe": - if (!empty($_POST['provider'])) - $ppp['provider'] = $_POST['provider']; - else{ - unset($ppp['provider']); - $ppp['provider'] = $_POST['null_service'] ? true : false; - } - if (!empty($_POST['pppoe-reset-type'])) - $ppp['pppoe-reset-type'] = $_POST['pppoe-reset-type']; - else - unset($ppp['pppoe-reset-type']); - - break; - case "pptp": - case "l2tp": - $ppp['localip'] = implode(',',$port_data['localip']); - $ppp['subnet'] = implode(',',$port_data['subnet']); - $ppp['gateway'] = implode(',',$port_data['gateway']); - break; - default: - break; - - } - - $ppp['shortseq'] = $_POST['shortseq'] ? true : false; - $ppp['acfcomp'] = $_POST['acfcomp'] ? true : false; - $ppp['protocomp'] = $_POST['protocomp'] ? true : false; - $ppp['vjcomp'] = $_POST['vjcomp'] ? true : false; - $ppp['tcpmssfix'] = $_POST['tcpmssfix'] ? true : false; - $ppp['bandwidth'] = implode(',', $port_data['bandwidth']); - if (is_array($port_data['mtu'])) - $ppp['mtu'] = implode(',', $port_data['mtu']); - if (is_array($port_data['mru'])) - $ppp['mru'] = implode(',', $port_data['mru']); - if (is_array($port_data['mrru'])) - $ppp['mrru'] = implode(',', $port_data['mrru']); - - /* handle_pppoe_reset is called here because if user changes Link Type from PPPoE to another type we - must be able to clear the config data in the section of config.xml if it exists - */ - handle_pppoe_reset($_POST); - - if (isset($id) && $a_ppps[$id]) - $a_ppps[$id] = $ppp; - else - $a_ppps[] = $ppp; - - write_config(); - configure_cron(); - - foreach ($iflist as $pppif => $ifdescr) { - if ($config['interfaces'][$pppif]['if'] == $ppp['if']) - interface_ppps_configure($pppif); - } - header("Location: interfaces_ppps.php"); - exit; - } -} // end if($_POST) - +legacy_html_escape_form_data($pconfig); $closehead = false; include("head.inc"); - -$types = array("select" => gettext("Select"), "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP", "l2tp" => "L2TP"/*, "tcp" => "TCP", "udp" => "UDP"*/ ); - ?> - - - - - + +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +   +
+ +
+ + +
+ + +
+ + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + + + + + + + + + + + +
+
- 0) print_input_errors($input_errors); ?> -
+ +
+
+ + + + + + + +
  + " class="btn btn-default btn-xs"/> +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
  + " /> + " onclick="window.location.href=''" /> + + + + +
+
+
+ +
+
+
+
+