. 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_PPPOE_CMD_FILE", "{$g['varetc_path']}/pppoe_restart_"); 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 * * * *"); function getMPDCRONSettings($ptpid_) { global $config; if (is_array($config['cron']['item'])) { for ($i = 0; $i < count($config['cron']['item']); $i++) { $item = $config['cron']['item'][$i]; if (strpos($item['command'], CRON_PPPOE_CMD_FILE.$ptpid_) !== false) { return array("ID" => $i, "ITEM" => $item); } } } return NULL; } if (!is_array($config['ppps']['ppp'])) $config['ppps']['ppp'] = array(); $a_ppps = &$config['ppps']['ppp']; $portlist = get_interface_list(); $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; if (isset($id) && $a_ppps[$id]) { $pconfig['type'] = $a_ppps[$id]['type']; $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'] = $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 "pptp": $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); $pconfig['subnet'] = explode(",",$a_ppps[$id]['subnet']); $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); if (isset($a_ppps[$id]['dhcp'])) $pconfig['pptp_dhcp'] = true; break; case "pppoe": $pconfig['provider'] = $a_ppps[$id]['provider']; /* ================================================ */ /* = 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]['ptpid']); $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; } } 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 = explode(",", "Link Interface(s),Phone Number"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); break; case "pppoe": if ($_POST['ondemand']) { $reqdfields = explode(" ", "interfaces username password ondemand idletimeout"); $reqdfieldsn = explode(",", "Link Interface(s),Username,Password,Dial on demand,Idle timeout value"); } else { $reqdfields = explode(" ", "interfaces username password"); $reqdfieldsn = explode(",", "Link Interface(s),Username,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 = explode(",", "Link Interface(s),Username,Password,Local IP address,Subnet,Remote IP address,Dial on demand,Idle timeout value"); } else { $reqdfields = explode(" ", "interfaces username password localip subnet gateway"); $reqdfieldsn = explode(",", "Link Interface(s),Username,Password,Local IP address,Subnet,Remote IP address"); } do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); break; default: $input_errors[] = "Please choose a Link Type."; break; } if ($_POST['type'] == "ppp" && count($_POST['interfaces']) > 1) $input_errors[] = "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[] = "The service name contains invalid characters."; if (($_POST['idletimeout'] != "") && !is_numericint($_POST['idletimeout'])) $input_errors[] = "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[] = "A valid local IP address must be specified for {$iface}."; if ($_POST['gateway'][$iface] && !is_ipaddr($_POST['gateway'][$iface]) && !is_hostname($_POST['gateway'][$iface])) $input_errors[] = "A valid gateway IP address OR hostname must be specified for {$iface}."; if ($_POST['bandwidth'][$iface] && !is_numericint($_POST['bandwidth'][$iface])) $input_errors[] = "The bandwidth value for {$iface} must be an integer."; if ($_POST['mtu'][$iface] && ($_POST['mtu'][$iface] < 576)) $input_errors[] = "The MTU for {$iface} must be greater than 576 bytes."; if ($_POST['mru'][$iface] && ($_POST['mru'][$iface] < 576)) $input_errors[] = "The MRU for {$iface} must be greater than 576 bytes."; } /* 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['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']); 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']; if (!empty($_POST['apnum'])) $ppp['apnum'] = $_POST['apnum']; else $ppp['apnum'] = "1"; } else { unset($ppp['apn']); unset($ppp['apnum']); } $ppp['phone'] = $_POST['phone']; foreach($_POST['interfaces'] as $iface){ if (isset($_POST['localip'][$iface])) $localip_array[] = $_POST['localip'][$iface]; if (isset($_POST['gateway'][$iface])) $gateway_array[] = $_POST['gateway'][$iface]; } if (count($localip_array)) $ppp['localip'] = implode(',',$localip_array); else unset($ppp['localip']); if (count($gateway_array)) $ppp['gateway'] = implode(',',$gateway_array); else unset($ppp['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']); 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": foreach($_POST['interfaces'] as $iface){ if (isset($_POST['localip'][$iface])) $localip_array[] = $_POST['localip'][$iface]; if (isset($_POST['gateway'][$iface])) $gateway_array[] = $_POST['gateway'][$iface]; if (isset($_POST['subnet'][$iface])) $subnet_array[] = $_POST['subnet'][$iface]; } $ppp['dhcp'] = $_POST['pptp_dhcp'] ? true : false; if (count($localip_array)) $ppp['localip'] = implode(',',$localip_array); else unset($ppp['localip']); if (count($gateway_array)) $ppp['gateway'] = implode(',',$gateway_array); else unset($ppp['gateway']); if (count($subnet_array)) $ppp['subnet'] = implode(',',$subnet_array); else unset($ppp['subnet']); 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; foreach($_POST['interfaces'] as $iface){ if (isset($_POST['bandwidth'][$iface])) $bw_array[] = $_POST['bandwidth'][$iface]; if (isset($_POST['mtu'][$iface])) $mtu_array[] = $_POST['mtu'][$iface]; if (isset($_POST['mru'][$iface])) $mru_array[] = $_POST['mru'][$iface]; if (isset($_POST['mrru'][$iface])) $mrru_array[] = $_POST['mrru'][$iface]; } if (count($bw_array)) $ppp['bandwidth'] = implode(',', $bw_array); else unset($ppp['bandwidth']); if (count($mtu_array)) $ppp['mtu'] = implode(',', $mtu_array); else unset($ppp['mtu']); if (count($mru_array)) $ppp['mru'] = implode(',', $mru_array); else unset($ppp['mru']); /* 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(); $iflist = get_configured_interface_list(); foreach ($iflist as $if) { if ($config['interfaces'][$if]['ptpid'] == $_POST['ptpid']){ $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) function handle_pppoe_reset() { global $_POST, $config, $g; if (!is_array($config['cron']['item'])) $config['cron']['item'] = array(); $itemhash = getMPDCRONSettings($_POST['ptpid']); $item = $itemhash['ITEM']; /* reset cron items if necessary and return*/ if (empty($_POST['pppoe-reset-type'])) { if (isset($item)) unset($config['cron']['item'][$itemhash['ID']]); sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP"); return; } if (empty($item)) $item = array(); if (isset($_POST['pppoe-reset-type']) && $_POST['pppoe-reset-type'] == "custom") { $item['minute'] = $_POST['pppoe_resetminute']; $item['hour'] = $_POST['pppoe_resethour']; if (isset($_POST['pppoe_resetdate']) && $_POST['pppoe_resetdate'] <> "") { $date = explode("/", $_POST['pppoe_resetdate']); $item['mday'] = $date[1]; $item['month'] = $date[0]; } else { $item['mday'] = "*"; $item['month'] = "*"; } $item['wday'] = "*"; $item['who'] = "root"; $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; } else if (isset($_POST['pppoe-reset-type']) && $_POST['pppoe-reset-type'] == "preset") { switch ($_POST['pppoe_pr_preset_val']) { case "monthly": $item['minute'] = "0"; $item['hour'] = "0"; $item['mday'] = "1"; $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "weekly": $item['minute'] = "0"; $item['hour'] = "0"; $item['mday'] = "*"; $item['month'] = "*"; $item['wday'] = "0"; $item['who'] = "root"; $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "daily": $item['minute'] = "0"; $item['hour'] = "0"; $item['mday'] = "*"; $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "hourly": $item['minute'] = "0"; $item['hour'] = "*"; $item['mday'] = "*"; $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; } // end switch }// end if if (isset($itemhash['ID'])) $config['cron']['item'][$itemhash['ID']] = $item; else $config['cron']['item'][] = $item; } $closehead = false; $pgtitle = array("Interfaces","PPPs","Edit"); include("head.inc"); $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP", "l2tp" => "L2TP"/*, "tcp" => "TCP", "udp" => "UDP"*/ ); ?>

>

When the idle timeout occurs, if the dial-on-demand option is enabled, mpd goes back into dial-on-demand mode. Otherwise, the interface is brought down and all associated routes removed."); ?>
>


This option enables Van Jacobson TCP header compression, which saves several bytes per TCP data packet. You almost always want this option. This compression ineffective for TCP connections with enabled modern extensions like time stamping or SACK, which modify TCP options between sequential packets.

This option causes mpd to adjust incoming and outgoing TCP SYN segments so that the requested maximum segment size is not greater than the amount allowed by the interface MTU. This is necessary in many setups to avoid problems caused by routers that drop ICMP Datagram Too Big messages. Without these messages, the originating machine sends data, it passes the rogue router then hits a machine that has an MTU that is not big enough for the data. Because the IP Don't Fragment option is set, this machine sends an ICMP Datagram Too Big message back to the originator and drops the packet. The rogue router drops the ICMP message and the originator never gets to discover that it must reduce the fragment size or drop the IP Don't Fragment option from its outgoing data.
ShortSeq
ACFComp
ProtoComp