<commit_before><?php

/*
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2010 <NAME>. <<EMAIL>>
    Copyright (C) 2003-2004 <NAME> <<EMAIL>>
    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');
    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']));

    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"));<commit_msg>remove idletimeout requirement for ondemand connections<commit_after><?php

/*
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2010 <NAME>. <<EMAIL>>
    Copyright (C) 2003-2004 <NAME> <<EMAIL>>
    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');
    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']));

    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"));
{'fraction_non_alphanumeric': 0.16052141527001862, 'fraction_numerical': 0.005400372439478585, 'mean_word_length': 3.407468198604842, 'pattern_counts': {'":': 8, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797794', 'n_tokens_mistral': 3303, 'n_tokens_neox': 3139, 'n_words': 839}