diff options
-rw-r--r-- | etc/inc/interfaces.inc | 235 | ||||
-rwxr-xr-x | usr/local/www/interfaces.php | 179 | ||||
-rw-r--r-- | usr/local/www/interfaces_ppps_edit.php | 13 |
3 files changed, 316 insertions, 111 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 700edbe..f01c288 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -867,36 +867,93 @@ function interface_bring_down($interface = "wan", $destroy = false) { function interface_ppps_configure($interface) { global $config, $g; - $intcfg = &$config['interfaces'][$interface]; + // mpd5 requires a /var/spool/lock directory for PPP modem links. + if(!is_dir("/var/spool/lock")) { + exec("/bin/mkdir -p /var/spool/lock"); + exec("/bin/chmod a+rw /var/spool/lock/."); + } + // mpd5 modem chat script expected in the same directory as the mpd_xxx.conf files + if (!file_exists("{$g['varetc_path']}/mpd.script")) + mwexec("/bin/ln -s /usr/local/sbin/mpd.script {$g['varetc_path']}/."); + + $ifcfg = &$config['interfaces'][$interface]; if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { foreach ($config['ppps']['ppp'] as $pppid => $ppp) { - if ($intcfg['ptpid'] == $ppp['ptpid']) + if ($ifcfg['ptpid'] == $ppp['ptpid']) break; } } - if (!$ppp || $intcfg['ptpid'] != $ppp['ptpid']){ - log_error("PPP configuration error in interface_ppps_configure()."); - return; + if (!$ppp || $ifcfg['ptpid'] != $ppp['ptpid']){ + log_error("Can't find PPP config with ptpid {$ifcfg['ptpid']} in interface_ppps_configure()."); + return 0; } - $pppif = $intcfg['if']; + $pppif = $ifcfg['if']; if ($ppp['type'] == "ppp") $type = "modem"; else $type = $ppp['type']; - $upper_type = strtoupper($ppp['type']); + $upper_type = strtoupper($ppp['type']); - // mpd5 requires a /var/spool/lock directory for PPP modem links. - if(!is_dir("/var/spool/lock")) { - exec("/bin/mkdir -p /var/spool/lock"); - exec("/bin/chmod a+rw /var/spool/lock/."); - } - // mpd5 modem chat script expected in the same directory as the mpd_xxx.conf files - if (!file_exists("{$g['varetc_path']}/mpd.script")) - mwexec("/bin/ln -s /usr/local/sbin/mpd.script {$g['varetc_path']}/."); - - if($g['booting']) + if($g['booting']) { echo " configuring {$upper_type} on {$pppif} interface...\n"; + // Do not re-configure the interface if we are booting and it's already been started + if(file_exists("{$g['varrun_path']}/{$ppp['type']}_{$interface}.pid")) + return 0; + } + + $ports = explode(',',$ppp['ports']); + $localips = explode(',',$ppp['localip']); + $gateways = explode(',',$ppp['gateway']); + $subnets = explode(',',$ppp['subnet']); + + /* We bring up the parent interface first because if DHCP is configured on the parent we need + to obtain an address first so we can write it in the mpd .conf file for PPtP and L2tP configs + */ + foreach($ports as $pid => $port){ + switch ($ppp['type']) { + case "pppoe": + /* Bring the parent interface up */ + interfaces_bring_up($port); + break; + case "pptp": + case "l2tp": + /* configure interface */ + if ($localips[$pid] == "dhcp") { + // configure DHCP on the $port interface + interface_dhcp_configure($port); + // Wait for the IP address before proceeding. + for ($count = 0; $count < 15; $count++) { + $localips[$pid] = find_interface_ip($port); + if(!empty($localips[$pid])) + break; + sleep(1); + } + log_error("Could not get PPtP/L2tP Local IP address for {$port} using DHCP in interfaces_ppps_configure"); + return 0; + } else { + // Manually configure interface IP/subnet + mwexec("/sbin/ifconfig " . escapeshellarg($port) . " " . + escapeshellarg($localips[$pid] . "/" . $subnets[$pid]) . " up"); + } + /* configure the gateway (remote IP ) */ + if (!empty($gateways[$pid]) && is_hostname($gateways[$pid]) && !is_ipaddr($gateways[$pid])) { + // do a DNS lookup for the gateway IP and store it in $gateways[$pid] + $gateways[$pid] = gethostbyname($gateways[$pid]); + } + if (0) // Logic for this? + log_error("Could not bring up interface {$port} for {$interface} {$ppp['type']} link in interface_ppps_configure()."); + break; + case "ppp": + if (!file_exists("{$port}")) { + log_error("Device {$port} does not exist. PPP link cannot start without the modem device."); + return 1; + } + break; + default: + break; + } + } /* generate mpd.conf */ $fd = fopen("{$g['varetc_path']}/mpd_{$interface}.conf", "w"); @@ -904,7 +961,6 @@ function interface_ppps_configure($interface) { log_error("Error: cannot open mpd_{$interface}.conf in interface_ppps_configure().\n"); return 1; } - $ports = explode(',',$ppp['ports']); if (is_array($ports) && count($ports) > 1) $multilink = "enable"; @@ -922,13 +978,12 @@ function interface_ppps_configure($interface) { else $gateway = "10.6.6.{$pppid}"; $ranges = "{$localip}/0 {$gateway}/0"; + + if (empty($ppp['apnum'])) + $ppp['apnum'] = 1; } else $ranges = "0.0.0.0/0 0.0.0.0/0"; - - $localips = explode(',',$ppp['localip']); - $gateways = explode(',',$ppp['gateway']); - $subnets = explode(',',$ppp['subnet']); if (isset($ppp['ondemand'])) $ondemand = "enable"; @@ -950,7 +1005,7 @@ function interface_ppps_configure($interface) { $mtus = explode(',',$ppp['mtu']); $mrus = explode(',',$ppp['mru']); - if (!isset($ppp['idletimeout'])) + if (isset($ppp['idletimeout'])) $mrrus = explode(',',$ppp['mrru']); // Construct the mpd.conf file $mpdconf = <<<EOD @@ -1028,7 +1083,7 @@ EOD; EOD; /* - if (!isset($intcfg['dnsnosec']) && isset($config['system']['dnsallowoverride'])) + if (!isset($ifcfg['dnsnosec']) && isset($config['system']['dnsallowoverride'])) $mpdconf .= <<<EOD set ipcp enable req-sec-dns @@ -1174,6 +1229,10 @@ EOD; conf_mount_ro(); } } + + /* fire up mpd */ + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/{$ppp['type']}_{$interface}.pid -s ppp {$ppp['type']}client"); + // Check for PPPoE periodic reset request if ($type == "pppoe") if (isset($ppp['pppoe-reset-type'])) @@ -1181,42 +1240,6 @@ EOD; else setup_pppoe_reset_file($ppp['ptpid']); - if(file_exists("{$g['varrun_path']}/{$ppp['type']}_{$interface}.pid") and $g['booting']) { - /* if we are booting and mpd has already been started then don't start again. */ - } else { - foreach($ports as $pid => $port){ - switch ($ppp['type']) { - case "pppoe": - /* Bring the parent interface up */ - if($port) - interfaces_bring_up($port); - else - log_error("Could not bring up interface {$port} for {$interface} {$ppp['type']} link in interface_ppps_configure()."); - break; - case "pptp": - case "l2tp": - /* configure interface */ - if($port) - mwexec("/sbin/ifconfig " . escapeshellarg($port) . " " . - escapeshellarg($localips[$pid] . "/" . $subnets[$pid]) . " up"); - else - log_error("Could not bring up interface {$port} for {$interface} {$ppp['type']} link in interface_ppps_configure()."); - break; - case "ppp": - if (!file_exists("{$port}")) { - log_error("Device {$port} does not exist. PPP link cannot start without the modem device."); - return 1; - } - break; - default: - break; - } - } - - /* fire up mpd */ - mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/{$ppp['type']}_{$interface}.pid -s ppp {$ppp['type']}client"); - } - /* sleep until wan is up - or 30 seconds, whichever comes first */ for ($count = 0; $count < 12; $count++) { if(file_exists("{$g['tmp_path']}/{$pppif}up")) { @@ -2258,7 +2281,12 @@ function interface_dhcp_configure($interface = "wan") { } $wanif = get_real_interface($interface); - + if (isset($wancfg['ptpid'])) + $wanif = get_real_interface($interface, true); + if (stristr($wanif,',')) { + log_error("Invalid interface \"{$wanif}\" in interface_dhcp_configure()"); + return 1; + } $dhclientconf = ""; $dhclientconf .= <<<EOD @@ -2287,13 +2315,11 @@ EOD; fwrite($fd, $dhclientconf); fclose($fd); - $realwanif = $wancfg['if']; - /* bring wan interface up before starting dhclient */ - if($realwanif) - interfaces_bring_up($realwanif); + if($wanif) + interfaces_bring_up($wanif); else - log_error("Could not bring realwanif up in interface_dhcp_configure()"); + log_error("Could not bring up {$wanif} interface in interface_dhcp_configure()"); /* fire up dhclient */ mwexec("/sbin/dhclient -c {$g['varetc_path']}/dhclient_{$interface}.conf {$wanif} > {$g['tmp_path']}/{$wanif}_output > {$g['tmp_path']}/{$wanif}_error_output"); @@ -2647,7 +2673,7 @@ function convert_real_interface_to_friendly_interface_name($interface = "wan") { return "opt{$index}"; else return "wan"; - } else if (stristr($interface, "vip")) { + } else if (stristr($interface, "vip")) { $index = substr($interface, 3); $counter = 0; foreach ($config['virtualip']['vip'] as $vip) { @@ -2771,7 +2797,7 @@ function interface_get_wireless_clone($wlif) { } } -function get_real_interface($interface = "wan") { +function get_real_interface($interface = "wan", $get_parent = false) { global $config; $wanif = NULL; @@ -2813,45 +2839,50 @@ function get_real_interface($interface = "wan") { if ($interface == $if || $interface == $ifdesc) { - $cfg = $config['interfaces'][$if]; - - // Wireless cloned NIC support (FreeBSD 8+) - // interface name format: $parentnic_wlanparentnic# - // example: ath0_wlan0 - if(is_interface_wireless($cfg['if'])) { - $wanif = interface_get_wireless_clone($cfg['if']); - break; - } - - if (empty($cfg['ipaddr'])) { - $wanif = $cfg['if']; - break; - } - - switch ($cfg['ipaddr']) { - case "carpdev-dhcp": - $viparr = &$config['virtualip']['vip']; - $counter = 0; - if(is_array($viparr)) - foreach ($viparr as $vip) { - if ($vip['mode'] == "carpdev-dhcp") { - if($vip['interface'] == $if) { - $wanif = "carp{$counter}"; - break; - } - $counter++; - } else if ($vip['mode'] = "carp") - $counter++; - } + $cfg = $config['interfaces'][$if]; + + // Wireless cloned NIC support (FreeBSD 8+) + // interface name format: $parentnic_wlanparentnic# + // example: ath0_wlan0 + if(is_interface_wireless($cfg['if'])) { + $wanif = interface_get_wireless_clone($cfg['if']); break; - default: + } + + if (empty($cfg['ipaddr'])) { $wanif = $cfg['if']; break; } - - break; + + switch ($cfg['ipaddr']) { + case "carpdev-dhcp": + $viparr = &$config['virtualip']['vip']; + $counter = 0; + if(is_array($viparr)) + foreach ($viparr as $vip) { + if ($vip['mode'] == "carpdev-dhcp") { + if($vip['interface'] == $if) { + $wanif = "carp{$counter}"; + break; + } + $counter++; + } else if ($vip['mode'] = "carp") + $counter++; + } + break; + default: + $wanif = $cfg['if']; + if ($get_parent && isset($cfg['ptpid'])) + foreach ($config['ppps']['ppp'] as $ppp) { + if ($ppp['ptpid'] == $cfg['ptpid']) + $wanif = $ppp['ports']; + } + break; + } + + break; + } } - } break; } diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index d01008c..33a2b7d 100755 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -103,6 +103,15 @@ if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { if ($wancfg['ptpid'] == $a_ppps[$pppid]['ptpid']) { $pconfig['pppid'] = $pppid; + + if ($a_ppps[$pppid]['type'] == "ppp"){ + $pconfig['username'] = $a_ppps[$pppid]['username']; + $pconfig['password'] = base64_decode($a_ppps[$pppid]['password']); + $pconfig['port'] = $a_ppps[$pppid]['ports']; + $pconfig['phone'] = $a_ppps[$pppid]['phone']; + $pconfig['apn'] = $a_ppps[$pppid]['apn']; + } + if ($a_ppps[$pppid]['type'] == "pppoe"){ $pconfig['pppoe_username'] = $a_ppps[$pppid]['username']; $pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']); @@ -553,6 +562,15 @@ if ($_POST) { $a_gateways[] = $gateway_item; } break; + case "ppp": + $a_ppps[$pppid]['ptpid'] = $_POST['ptpid']; + $a_ppps[$pppid]['type'] = $_POST['type']; + $a_ppps[$pppid]['ports'] = $_POST['port']; + $a_ppps[$pppid]['username'] = $_POST['username']; + $a_ppps[$pppid]['password'] = base64_encode($_POST['password']); + $a_ppps[$pppid]['apn'] = $_POST['apn']; + break; + case "pppoe": $a_ppps[$pppid]['ptpid'] = $_POST['ptpid']; $a_ppps[$pppid]['type'] = $_POST['type']; @@ -899,6 +917,7 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "ppp" = } case "ppp": { $('none','static','dhcp','pptp', 'pppoe').invoke('hide'); + country_list(); break; } case "pppoe": { @@ -946,6 +965,90 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "ppp" = else return true; } + function country_list() { + $('country').childElements().each(function(node) { node.remove(); }); + $('provider').childElements().each(function(node) { node.remove(); }); + $('providerplan').childElements().each(function(node) { node.remove(); }); + new Ajax.Request("getserviceproviders.php",{ + onSuccess: function(response) { + var responseTextArr = response.responseText.split("\n"); + responseTextArr.sort(); + responseTextArr.each( function(value) { + var option = new Element('option'); + country = value.split(":"); + option.text = country[0]; + option.value = country[1]; + $('country').insert({ bottom : option }); + }); + } + }); + $('trcountry').setStyle({display : "table-row"}); + } + + function providers_list() { + $('provider').childElements().each(function(node) { node.remove(); }); + $('providerplan').childElements().each(function(node) { node.remove(); }); + new Ajax.Request("getserviceproviders.php",{ + parameters: {country : $F('country')}, + onSuccess: function(response) { + var responseTextArr = response.responseText.split("\n"); + responseTextArr.sort(); + responseTextArr.each( function(value) { + var option = new Element('option'); + option.text = value; + option.value = value; + $('provider').insert({ bottom : option }); + }); + } + }); + $('trprovider').setStyle({display : "table-row"}); + $('trproviderplan').setStyle({display : "none"}); + } + + function providerplan_list() { + $('providerplan').childElements().each(function(node) { node.remove(); }); + $('providerplan').insert( new Element('option') ); + new Ajax.Request("getserviceproviders.php",{ + parameters: {country : $F('country'), provider : $F('provider')}, + onSuccess: function(response) { + var responseTextArr = response.responseText.split("\n"); + responseTextArr.sort(); + responseTextArr.each( function(value) { + if(value != "") { + providerplan = value.split(":"); + + var option = new Element('option'); + option.text = providerplan[0] + " - " + providerplan[1]; + option.value = providerplan[1]; + $('providerplan').insert({ bottom : option }); + } + }); + } + }); + $('trproviderplan').setStyle({display : "table-row"}); + } + + function prefill_provider() { + new Ajax.Request("getserviceproviders.php",{ + parameters: {country : $F('country'), provider : $F('provider'), plan : $F('providerplan')}, + onSuccess: function(response) { + var xmldoc = response.responseXML; + var provider = xmldoc.getElementsByTagName('connection')[0]; + $('username').setValue(''); + $('password').setValue(''); + if(provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") { + $('phone').setValue('*777'); + $('apn').setValue(''); + } else { + $('phone').setValue('*99#'); + $('apn').setValue(provider.getElementsByTagName('apn')[0].firstChild.data); + } + $('username').setValue(provider.getElementsByTagName('username')[0].firstChild.data); + $('password').setValue(provider.getElementsByTagName('password')[0].firstChild.data); + } + }); + } + </script> </head> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> @@ -1181,8 +1284,82 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "ppp" = <tr> <td colspan="2" valign="top" class="listtopic">PPP configuration</td> </tr> + <tr name="ppp_provider" id="ppp_provider"> + <td width="22%" valign="top" class="vncell"><?= gettext("Service Provider"); ?></td> + <td width="78%" class="vtable"> + <table border="0" cellpadding="0" cellspacing="0"> + <tr id="trcountry"> + <td><?= gettext("Country"); ?> : </td> + <td> + <select class="formselect" name="country" id="country" onChange="providers_list()"> + <option></option> + </select> + </td> + </tr> + <tr id="trprovider" style="display:none"> + <td><?= gettext("Provider"); ?> : </td> + <td> + <select class="formselect" name="provider" id="provider" onChange="providerplan_list()"> + <option></option> + </select> + </td> + </tr> + <tr id="trproviderplan" style="display:none"> + <td><?= gettext("Plan"); ?> : </td> + <td> + <select class="formselect" name="providerplan" id="providerplan" onChange="prefill_provider()"> + <option></option> + </select> + </td> + </tr> + </table> + <br/><span class="vexpl"><?= gettext("Select to fill in data for your service provider."); ?></span> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?= gettext("Username"); ?></td> + <td width="78%" class="vtable"> + <input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>"> + </td> + </tr> <tr> - <td width="22%" valign="top" class="vncell">PPP</td> + <td width="22%" valign="top" class="vncell"><?= gettext("Password"); ?></td> + <td width="78%" class="vtable"> + <input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>"> + </td> + </tr> + <tr name="phone_num" id="phone_num"> + <td width="22%" valign="top" class="vncellreq"><?= gettext("Phone Number"); ?></td> + <td width="78%" class="vtable"> + <input name="phone" type="text" class="formfld unknown" id="phone" size="12" value="<?=htmlspecialchars($pconfig['phone']);?>"> + </td> + </tr> + <tr name="apn_" id="apn_"> + <td width="22%" valign="top" class="vncell"><?= gettext("Access Point Name (APN)"); ?></td> + <td width="78%" class="vtable"> + <input name="apn" type="text" class="formfld unknown" id="apn" size="40" value="<?=htmlspecialchars($pconfig['apn']);?>"> + </td> + </tr> + <tr name="interface" id="interface" > + <td width="22%" valign="top" class="vncellreq"><?= gettext("Modem Port"); ?></td> + <td width="78%" class="vtable"> + <select name="port" id="port" class="formselect"> + <?php + $portlist = glob("/dev/cua*"); + $modems = glob("/dev/modem*"); + $portlist = array_merge($portlist, $modems); + foreach ($portlist as $port) { + if(preg_match("/\.(lock|init)$/", $port)) + continue; + echo "<option value=\"".trim($port)."\""; + if ($pconfig['port'] == $port) + echo "selected"; + echo ">{$port}</option>"; + }?> + </select> + </td> + </tr> + <td width="22%" valign="top" class="vncell"><?= gettext("Advanced PPP"); ?></td> <?php if (isset($pconfig['pppid'])): ?> <td width="78%" class="vtable"> <a href="/interfaces_ppps_edit.php?id=<?=htmlspecialchars($pconfig['pppid']);?>" class="navlnk">Click here</a> diff --git a/usr/local/www/interfaces_ppps_edit.php b/usr/local/www/interfaces_ppps_edit.php index 4254fde..694b54a 100644 --- a/usr/local/www/interfaces_ppps_edit.php +++ b/usr/local/www/interfaces_ppps_edit.php @@ -314,10 +314,7 @@ if ($_POST) { if (!empty($_POST['apn'])){ $ppp['apn'] = $_POST['apn']; - if (!empty($_POST['apnum'])) - $ppp['apnum'] = $_POST['apnum']; - else - $ppp['apnum'] = "1"; + $ppp['apnum'] = $_POST['apnum']; } else { unset($ppp['apn']); unset($ppp['apnum']); @@ -509,7 +506,7 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" echo " value=\"{$key}\" >" . htmlspecialchars($opt) . "</option>"; } ?> - </select> + </select> </td> </tr> <tr name="interface" id="interface" > @@ -685,7 +682,7 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" <br/> <span class="vexpl"><?= gettext("Hint: this field can usually be left empty"); ?></span> </td> </tr> - <tr> + <tr style="display:none" id="advanced_<?=$k;?>" name="advanced_<?=$k;$k++;?>"> <td width="22%" valign="top" class="vncell"><?=gettext("Periodic reset");?></td> <td width="78%" class="vtable"> <table id="presetwrap" cellspacing="0" cellpadding="0" width="100%"> @@ -850,14 +847,14 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" <td width="22%" id="mtulabel<?=$i;?>" valign="top" class="vncell"> MTU</td> <td width="78%" class="vtable"> <input name="mtu[]" id="mtu<?=$i;?>" type="text" class="formfld unknown" size="6" value="<?=htmlspecialchars($pconfig['mtu'][$i]);?>"> - <br> <span class="vexpl">Set MTU for each link if links have different bandwidths, otherwise, mtu will default to 1492.</span> + <br> <span class="vexpl">MTU will default to 1492.</span> </td> </tr> <tr> <td width="22%" id="mrulabel<?=$i;?>" valign="top" class="vncell"> MRU</td> <td width="78%" class="vtable"> <input name="mru[]" id="mru<?=$i;?>" type="text" class="formfld unknown" size="6" value="<?=htmlspecialchars($pconfig['mru'][$i]);?>"> - <br> <span class="vexpl">Set MRU for each link if links have different bandwidths, otherwise, mru will default to 1492.</span> + <br> <span class="vexpl">MRU will default to 1492.</span> </td> </tr> </table |