From 860c4e80bb62a525579d11b40711b4e2389fa12b Mon Sep 17 00:00:00 2001 From: Chris Buechler Date: Mon, 18 Feb 2008 01:33:06 +0000 Subject: [PATCH] Initial import of PPP for 3G and dial up modem support. Needs testing and likely some fixing, then porting to HEAD once verified working. --- etc/inc/filter.inc | 10 +- etc/inc/interfaces.inc | 86 +++++++++++++ etc/inc/pfsense-utils.inc | 6 + usr/local/www/interfaces_assign.php | 23 +++- usr/local/www/interfaces_opt.php | 32 ++++- usr/local/www/interfaces_ppp.php | 148 +++++++++++++++++++++++ usr/local/www/interfaces_ppp_edit.php | 166 ++++++++++++++++++++++++++ usr/local/www/interfaces_vlan.php | 1 + 8 files changed, 469 insertions(+), 3 deletions(-) create mode 100644 usr/local/www/interfaces_ppp.php create mode 100644 usr/local/www/interfaces_ppp_edit.php diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 98320d677c..dd44010586 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -394,7 +394,15 @@ function filter_generate_aliases() { if($opt_carp_ints) $aliases .= $opt_carp_ints; } - $aliases .= " }\"\n"; + $aliases .= " }\"\n"; + /* XXX TODO: below comment and subsequent two lines of code from + Adam Lebsack + I'm not sure what it means, marking this to look into. cmb@ + + add an alias, since much of the filter code is broken when it comes to + finding out the real interface */ + if(preg_match("/^ppp_(.+)$/", $config['interfaces'][$ifname]['if'], $matches)) + $aliases .= "{$config['interfaces'][$ifname]['if']} = \"ppp0\"\n"; } $aliases .= "# User Aliases \n"; /* Setup pf groups */ diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 4da901377c..81d8708a76 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -278,6 +278,10 @@ function interfaces_optional_configure_if($opti) { if (is_array($optcfg['wireless'])) interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']); + /* PPP configuration */ + if (isset($optcfg['pointtopoint'])) + interfaces_ppp_configure_if($optcfg); + /* MAC spoofing? */ if ($optcfg['spoofmac']) { mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . @@ -368,6 +372,74 @@ function interfaces_optional_configure_if($opti) { return 0; } +function interfaces_ppp_configure_if($ifcfg) { + global $config; + + if(file_exists("/var/run/ppp0.pid")) { + $pid = file_get_contents("/var/run/ppp0.pid"); + mwexec('kill $pid'); + } + + mwexec("/sbin/ifconfig ppp0 down destroy"); + + $peerfile = "lcp-echo-failure 0\n"; + $peerfile .= "lcp-echo-interval 0\n"; + $peerfile .= "connect /etc/ppp/peers/ppp0-connect-chat\n"; + //$peerfile .= "disconnect /etc/ppp/peers/ppp0-disconnect-chat\n"; + $peerfile .= "/dev/{$ifcfg['serialport']}\n"; + $peerfile .= "crtscts\n"; + $peerfile .= "local\n"; + $peerfile .= ":{$ifcfg['gateway']}\n"; + $peerfile .= "noipdefault\n"; + $peerfile .= "ipcp-accept-local\n"; + $peerfile .= "novj\n"; + $peerfile .= "nobsdcomp\n"; + $peerfile .= "novjccomp\n"; + $peerfile .= "nopcomp\n"; + $peerfile .= "noaccomp\n"; + $peerfile .= "noauth\n"; + $peerfile .= "persist\n"; + $peerfile .= "debug\n"; + // KD - test + //$peerfile .= "defaultroute\n"; + //$peerfile .= "nodetach\n"; + // KD - so I know where to look! + $peerfile .= "# created by /etc/inc/interfaces.inc\n"; + file_put_contents("/etc/ppp/peers/ppp0", $peerfile); + + // Added single quotes to some strings below: + // the \rAT is *always* going to need it + // and the phone number on a GSM connection ends in a # char + // Kevin Dawson, 22 Jan 2008 + // Refer Andrew Curtis + + $chatfile = "#!/bin/sh\n"; + $chatfile .= "exec chat \\\n"; + $chatfile .= "TIMEOUT 5 \\\n"; + $chatfile .= "ECHO ON \\\n"; + $chatfile .= "ABORT '\\nBUSY\\r' \\\n"; + $chatfile .= "ABORT '\\nERROR\\r' \\\n"; + $chatfile .= "ABORT '\\nNO ANSWER\\r' \\\n"; + $chatfile .= "ABORT '\\nNO CARRIER\\r' \\\n"; + $chatfile .= "ABORT '\\nNO DIALTONE\\r' \\\n"; + $chatfile .= "ABORT '\\nRINGING\\r\\n\\r\\nRINGING\\r' \\\n"; + // KD + $chatfile .= "'' '\\rAT' \\\n"; + $chatfile .= "TIMEOUT 12 \\\n"; + $chatfile .= "OK ATH \\\n"; + $chatfile .= "OK ATE1 \\\n"; + $chatfile .= "OK 'AT+CGDCONT=1,\"IP\",\"{$ifcfg['ap']}\"' \\\n"; + // KD + $chatfile .= "OK 'ATD{$ifcfg['phone']}' \\\n"; + $chatfile .= "TIMEOUT 22 \\\n"; + $chatfile .= "CONNECT \"\" \\\n"; + $chatfile .= "SAY \"\\nConnected.\"\n"; + file_put_contents("/etc/ppp/peers/ppp0-connect-chat", $chatfile); + chmod("/etc/ppp/peers/ppp0-connect-chat", 0755); + mwexec("/sbin/ifconfig ppp0 create"); + return 0; +} + function interfaces_carp_configure() { global $g, $config, $debugging; $balanacing = ""; @@ -1637,6 +1709,20 @@ function get_number_of_vlan_interfaces() { return "{$vlans_total}"; } +function get_number_of_ppp_interfaces() { + $ppps_total = 0; + $ppps = split("\n", `/sbin/ifconfig -a | /usr/bin/grep ppp | grep flags`); + foreach($ppps as $bridge) { + $match_array = ""; + preg_match_all("/ppp(.*):/",$bridge,$match_array); + if($match_array[1][0] <> "") { + if($match_array[1][0] > $ppps_total) + $ppps_total = $match_array[1][0]; + } + } + return "{$ppps_total}"; +} + function get_next_available_bridge_interface() { $bridges_total = get_number_of_bridged_interfaces(); $interfaces = `/sbin/ifconfig -l`; diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 5cae4d5224..d162854830 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1464,6 +1464,8 @@ function guess_interface_from_ip($ipaddress) { function filter_opt_interface_to_real($opt) { global $config; + if(isset($config['interfaces'][$opt]['pointtopoint'])) + return "ppp0"; return $config['interfaces'][$opt]['if']; } @@ -1509,6 +1511,8 @@ function find_ip_interface($ip) { */ function filter_translate_type_to_real_interface($interface) { global $config; + if(isset($config['interfaces'][$interface]['pointtopoint'])) + return "ppp0"; if($config['interfaces'][$interface]['if'] <> "") { return $config['interfaces'][$interface]['if']; } else { @@ -1780,6 +1784,8 @@ function convert_friendly_interface_to_real_interface_name($interface) { global $config; if($config['interfaces'][$interface]['ipaddr'] == "pppoe") return "ng0"; + if(isset($config['interfaces'][$interface]['pointtopoint'])) + return "ppp0"; $lc_interface = strtolower($interface); if($lc_interface == "lan") return $config['interfaces']['lan']['if']; diff --git a/usr/local/www/interfaces_assign.php b/usr/local/www/interfaces_assign.php index 908f9840da..d58fc36ffe 100755 --- a/usr/local/www/interfaces_assign.php +++ b/usr/local/www/interfaces_assign.php @@ -50,6 +50,17 @@ if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) { } } +/* add PPP interfaces */ +if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { + $i = 0; + foreach ($config['ppps']['ppp'] as $ppp) { + $portname = 'ppp_' . basename($ppp['port']); + $portlist[$portname] = $ppp; + $portlist[$portname]['isppp'] = true; + $i++; + } +} + if ($_POST) { unset($input_errors); @@ -92,7 +103,11 @@ if ($_POST) { if (!is_array($ifport)) { $config['interfaces'][$ifname]['if'] = $ifport; - + if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) { + $config['interfaces'][$ifname]['pointtopoint'] = true; + $config['interfaces'][$ifname]['serialport'] = $matches[1]; + } + /* check for wireless interfaces, set or clear ['wireless'] */ if (preg_match($g['wireless_regex'], $ifport)) { if (!is_array($config['interfaces'][$ifname]['wireless'])) @@ -235,6 +250,7 @@ if(file_exists("/var/run/interface_mismatch_reboot_needed")) $tab_array = array(); $tab_array[0] = array("Interface assignments", true, "interfaces_assign.php"); $tab_array[1] = array("VLANs", false, "interfaces_vlan.php"); + $tab_array[2] = array("PPP", false, "interfaces_ppp.php"); display_top_tabs($tab_array); ?> @@ -264,6 +280,11 @@ if(file_exists("/var/run/interface_mismatch_reboot_needed")) if ($portinfo['descr']) $descr .= " (" . $portinfo['descr'] . ")"; echo htmlspecialchars($descr); + } elseif ($portinfo['isppp']) { + $descr = "PPP {$portinfo['port']}"; + if ($portinfo['descr']) + $descr .= " (" . $portinfo['descr'] . ")"; + echo htmlspecialchars($descr); } else echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")"); ?> diff --git a/usr/local/www/interfaces_opt.php b/usr/local/www/interfaces_opt.php index 9a6de95899..f40d7c585f 100755 --- a/usr/local/www/interfaces_opt.php +++ b/usr/local/www/interfaces_opt.php @@ -84,6 +84,8 @@ if ($optcfg['ipaddr'] == "dhcp") { $pconfig['subnet'] = $optcfg['subnet']; $pconfig['gateway'] = $optcfg['gateway']; $pconfig['pointtopoint'] = $optcfg['pointtopoint']; + $pconfig['ap'] = $optcfg['ap']; + $pconfig['phone'] = $optcfg['phone']; } if ($_POST) { @@ -231,8 +233,11 @@ if ($_POST) { $optcfg['ipaddr'] = $_POST['ipaddr']; $optcfg['subnet'] = $_POST['subnet']; $optcfg['gateway'] = $_POST['gateway']; - if (isset($optcfg['ispointtopoint'])) + if (isset($optcfg['ispointtopoint'])) { $optcfg['pointtopoint'] = $_POST['pointtopoint']; + $optcfg['ap'] = $_POST['ap']; + $optcfg['phone'] = $_POST['phone']; + } } else if ($_POST['type'] == "DHCP") { $optcfg['ipaddr'] = "dhcp"; $optcfg['dhcphostname'] = $_POST['dhcphostname']; @@ -324,6 +329,30 @@ function show_mon_config() { General configuration + + + AP Hostname + + + + + + Phone Number + + + + + + Remote IP + + + + + + + + + Type Select a existing Gateway from the list or add one on the Gateways page
+ diff --git a/usr/local/www/interfaces_ppp.php b/usr/local/www/interfaces_ppp.php new file mode 100644 index 0000000000..2e05616965 --- /dev/null +++ b/usr/local/www/interfaces_ppp.php @@ -0,0 +1,148 @@ + + Changes by Chris Buechler + + Copyright (C) 2004-2008 BSD Perimeter LLC. + 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("guiconfig.inc"); + +if (!is_array($config['ppps']['ppp'])) + $config['ppps']['ppp'] = array(); + +$a_ppps = &$config['ppps']['ppp'] ; + +function ppp_inuse($num) { + global $config, $g; + + if ($config['interfaces']['lan']['if'] == "ppp{$num}") + return true; + if ($config['interfaces']['wan']['if'] == "ppp{$num}") + return true; + + for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) { + if ($config['interfaces']['opt' . $i]['if'] == "ppp{$num}") + return true; + } + + return false; +} + +function renumber_ppp($if, $delppp) { + if (!preg_match("/^ppp/", $if)) + return $if; + + $ppp = substr($if, 4); + if ($ppp > $delppp) + return "ppp" . ($ppp - 1); + else + return $if; +} + +if ($_GET['act'] == "del") { + /* check if still in use */ + if (ppp_inuse($_GET['id'])) { + $input_errors[] = "This PPP interface cannot be deleted because it is still being used as an interface."; + } else { + unset($a_ppps[$_GET['id']]); + + /* renumber all interfaces that use PPP */ + $config['interfaces']['lan']['if'] = renumber_ppp($config['interfaces']['lan']['if'], $_GET['id']); + $config['interfaces']['wan']['if'] = renumber_ppp($config['interfaces']['wan']['if'], $_GET['id']); + for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) + $config['interfaces']['opt' . $i]['if'] = renumber_ppp($config['interfaces']['opt' . $i]['if'], $_GET['id']); + + write_config(); + + interfaces_optional_configure(); + + header("Location: interfaces_ppp.php"); + exit; + } +} + + +$pgtitle = "Interfaces: PPP"; +include("head.inc"); + +?> + + + +

+ + + + + + +
+ +
+
+ + + + + + + + $ppp): ?> + + + + + + + + + + + +
InterfaceSerial PortDescription
+ ppp + + + + +   + + +  
 
+
+
+ + + diff --git a/usr/local/www/interfaces_ppp_edit.php b/usr/local/www/interfaces_ppp_edit.php new file mode 100644 index 0000000000..d6f7753530 --- /dev/null +++ b/usr/local/www/interfaces_ppp_edit.php @@ -0,0 +1,166 @@ + + Changes by Chris Buechler + + Copyright (C) 2004-2008 BSD Perimeter LLC. + 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("guiconfig.inc"); + +if (!is_array($config['ppps']['ppp'])) + $config['ppps']['ppp'] = array(); + +$a_ppps = &$config['ppps']['ppp']; + + +$id = $_GET['id']; +if (isset($_POST['id'])) + $id = $_POST['id']; + +if (isset($id) && $a_ppps[$id]) { + $pconfig['if'] = $a_ppps[$id]['if']; + $pconfig['initstr'] = $a_ppps[$id]['initstr']; + $pconfig['phone'] = $a_ppps[$id]['phone']; + $pconfig['linespeed'] = $a_ppps[$id]['linespeed']; + $pconfig['descr'] = $a_ppps[$id]['descr']; +} + +if ($_POST) { + + unset($input_errors); + $pconfig = $_POST; + + /* input validation */ + $reqdfields = explode(" ", "port"); + $reqdfieldsn = explode(",", "Serial Port"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + foreach ($a_ppps as $ppp) { + if (isset($id) && ($a_ppps[$id]) && ($a_ppps[$id] === $ppp)) + continue; + + if ($ppp['port'] == $_POST['port']) { + $input_errors[] = "Port is in use"; + break; + } + } + + if (!$input_errors) { + $ppp = array(); + $ppp['port'] = $_POST['port']; + $ppp['initstr'] = $_POST['initstr']; + $ppp['phone'] = $_POST['phone']; + $ppp['linespeed'] = $_POST['linespeed']; + $ppp['descr'] = $_POST['descr']; + + if (isset($id) && $a_ppps[$id]) + $a_ppps[$id] = $ppp; + else + $a_ppps[] = $ppp; + + write_config(); + + interfaces_optional_configure(); + + header("Location: interfaces_ppp.php"); + exit; + } +} + +$pgtitle = "Firewall: PPP: Edit"; +include("head.inc"); + +?> + + + +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Parent interface + +
Init String + +
Enter the modem initialization string here
Phone Number + +
Line Speed + +
Description + +
You may enter a description here + for your reference (not parsed).
  + + + + +
+
+ + + diff --git a/usr/local/www/interfaces_vlan.php b/usr/local/www/interfaces_vlan.php index c1d859a44b..0ed7ee6ef6 100755 --- a/usr/local/www/interfaces_vlan.php +++ b/usr/local/www/interfaces_vlan.php @@ -100,6 +100,7 @@ include("head.inc"); $tab_array = array(); $tab_array[0] = array("Interface assignments", false, "interfaces_assign.php"); $tab_array[1] = array("VLANs", true, "interfaces_vlan.php"); + $tab_array[2] = array("PPP", false, "interfaces_ppp.php"); display_top_tabs($tab_array); ?>