. All rights reserved. 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: 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. */ /* pfSense_MODULE: interfaces */ ##|+PRIV ##|*IDENT=page-interfaces-ppps-edit ##|*NAME=Interfaces: PPPs: Edit page ##|*DESCR=Allow access to the 'Interfaces: PPPs: Edit' page. ##|*MATCH=interfaces_ppps_edit.php* ##|-PRIV require("guiconfig.inc"); require("functions.inc"); 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 (!is_array($config['ppps']['ppp'])) $config['ppps']['ppp'] = array(); $a_ppps = &$config['ppps']['ppp']; $portlist = get_interface_list(); $portlist = array_merge($portlist, get_configured_interface_with_descr()); $id = $_GET['id']; if (isset($_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 = split(" ", $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); $pconfig = $_POST; /* 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']); } /* 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[] = "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); $iflist = get_configured_interface_list(); foreach ($iflist as $if) { if ($config['interfaces'][$if]['if'] == $ppp['if']){ $thisif = $if; break; } } if (isset($id) && $a_ppps[$id]) $a_ppps[$id] = $ppp; else $a_ppps[] = $ppp; write_config(); configure_cron(); if (isset($thisif)){ interface_ppps_configure($thisif); } header("Location: interfaces_ppps.php"); exit; } } // end if($_POST) $closehead = false; $pgtitle = array(gettext("Interfaces"),gettext("PPPs"),gettext("Edit")); include("head.inc"); $types = array("select" => gettext("Select"), "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP", "l2tp" => "L2TP"/*, "tcp" => "TCP", "udp" => "UDP"*/ ); ?>


 

">

  "> " onclick="history.back()">