Copyright (C) 2003-2004 Manuel Kasper All rights reserved. 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. 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. */ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("services.inc"); if (!isset($config['ppps'])) { $config['ppps'] = array(); } if (!isset($config['ppps']['ppp'])) { $config['ppps']['ppp'] = array(); } $a_ppps = &$config['ppps']['ppp']; if ($_SERVER['REQUEST_METHOD'] === 'GET') { // read form data $pconfig = array(); if (isset($_GET['id']) && !empty($a_ppps[$_GET['id']])) { $id = $_GET['id']; } // plain 1-on-1 copy $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; } } // fields containing array data (comma seperated) $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(); } } // boolean fields $bool_fields = array('ondemand', 'shortseq', 'acfcomp', 'protocomp', 'vjcomp', 'tcpmssfix'); foreach ($bool_fields as $fieldname) { $pconfig[$fieldname] = isset($a_ppps[$id][$fieldname]); } // special cases $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'])); // init resetpppoe_reset vars $pconfig['pppoe_resetminute'] = null; $pconfig['pppoe_resethour'] = null; $pconfig['pppoe_resetmday'] = null; $pconfig['pppoe_resetmonth'] = null; $pconfig['pppoe_resetwday'] = null; // read resetpppoe_reset vars 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 ($pconfig['ptpid'] == null) { $pconfig['ptpid'] = interfaces_ptpid_next(); } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { // save form data 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 (!empty($pconfig['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 (!empty($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 (!isset($pconfig['ports'])) { $pconfig = array(); } 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){ foreach($port_fields as $field_label){ if (!isset($port_data[$field_label])) { $port_data[$field_label] = array(); } 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; } } legacy_html_escape_form_data($pconfig); include("head.inc"); ?>
0) print_input_errors($input_errors); ?>
 
  " class="btn btn-default btn-xs"/>
  " /> " onclick="window.location.href=''" />