* 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"); function interfaces_ptpid_used($ptpid) { global $config; if (isset($config['ppps']['ppp'])) { foreach ($config['ppps']['ppp'] as & $settings) { if ($ptpid == $settings['ptpid']) { return true; } } } return false; } function interfaces_ptpid_next() { $ptpid = 0; while (interfaces_ptpid_used($ptpid)) { $ptpid++; } return $ptpid; } function serial_devices() { // collect 3g/4g modems $dmesg = array(); exec('/sbin/sysctl -a', $dmesg); $modems = array(); foreach ($dmesg as $line) { if (strpos($line, 'dev.u3g.') === 0) { $portnum = explode('.', $line)[2]; if (is_numeric($portnum)) { if (!isset($modems[$portnum])) { $modems[$portnum] = array(); } if (strpos($line, '%desc:') !== false) { $modems[$portnum]['descr'] = explode('%desc:', $line)[1]; } elseif (strpos($line, '%pnpinfo:') !== false) { foreach (explode(' ', explode('%pnpinfo:', $line)[1]) as $prop) { $tmp = explode('=', $prop); if (count($tmp) == 2) { $modems[$portnum][$tmp[0]] = $tmp[1]; } } } } } } $serialports = array(); foreach (glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE) as $device) { $serialports[$device] = array('descr' => ''); $tty = explode('.', explode('cua', $device)[1])[0]; foreach ($modems as $modem) { if (isset($modem['ttyname']) && $modem['ttyname'] == $tty) { $serialports[$device] = $modem; } } } return $serialports; } $a_ppps = &config_read_array('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', 'hostuniq'); 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-separated) $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; 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"); $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['ports'] = 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 (($pconfig['idletimeout'] != "") && !is_numericint($pconfig['idletimeout'])) { $input_errors[] = gettext("The idle timeout value must be an integer."); } 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])) { $input_errors[] = sprintf(gettext("A valid gateway IP address 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": $ppp['provider'] = $pconfig['provider']; if (!empty($pconfig['hostuniq'])) { $ppp['hostuniq'] = $pconfig['hostuniq']; } 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']); if (isset($id)) { $a_ppps[$id] = $ppp; } else { $a_ppps[] = $ppp; } write_config(); $iflist = get_configured_interface_with_descr(); foreach ($iflist as $pppif => $ifdescr) { if ($config['interfaces'][$pppif]['if'] == $ppp['if']) { interface_ppps_configure($pppif); } } header(url_safe('Location: /interfaces_ppps.php')); exit; } } legacy_html_escape_form_data($pconfig); include("head.inc"); ?>
0) print_input_errors($input_errors); ?>