--- backup-stock-image-20100320/inc/interfaces.inc 2010-03-23 13:42:51.000000000 +0700 +++ interfaces.inc 2010-03-24 14:41:27.000000000 +0700 @@ -687,7 +687,7 @@ interfaces_qinq_configure(); /* Set up PPP interfaces */ - interfaces_ppp_configure(); + //interfaces_ppp_configure(); $iflist = get_configured_interface_with_descr(); $delayed_list = array(); @@ -824,8 +824,6 @@ unlink_if_exists("{$g['tmp_path']}/{$realif}up"); unlink_if_exists("{$g['vardb_path']}/{$interface}ip"); unlink_if_exists("{$g['tmp_path']}/{$realif}_router"); - - interface_ppp_bring_down($realif); switch ($ifcfg['ipaddr']) { case "pppoe": @@ -857,6 +855,10 @@ mwexec("/usr/sbin/arp -d -i {$realif} -a"); } break; + case "ppp": + killbypid("{$g['varrun_path']}/{$realif}.pid"); + sleep(2); + break; default: if(does_interface_exist("$realif")) { mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); @@ -873,7 +875,9 @@ return; } - +/* Now PPP functions are integrated into the structure of other functions better we don't need this + i.e. interface_ppp_configure is called by interface_configure, interface_bring_down, etc. + function interfaces_ppp_configure($write_config=true) { global $config, $g; if(!$g['booting']) @@ -882,8 +886,8 @@ echo "Configuring PPP interfaces..."; if($config['ppps']['ppp']) { foreach($config['ppps']['ppp'] as $ppp) { - $dev = substr($ppp['port'], 5); - interface_ppp_configure($dev,$write_config); + $id = $ppp['id']; + interface_ppp_configure($id,$write_config); } } if(!$g['booting']) @@ -891,110 +895,224 @@ if($g['booting']) echo "done.\n"; } +*/ -function interface_ppp_configure($ifcfg,$edit=false) { +function interface_ppp_configure($ppp_int,$edit=false) { global $config, $g; - /* Remove the /dev/ from the device name. */ - $orig_dev = $ifcfg; - - // ppp (userland) requires a /var/spool/lock directory + $serial_device = 0; + if ($ppp_int <> -1) + if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { + foreach ($config['ppps']['ppp'] as $ppp) { + if ($ppp_int == "ppp".$ppp['pppid']) + $serial_device = $ppp['port']; + } + } + + // mpd5 requires a /var/spool/lock directory if(!is_dir("/var/spool/lock")) { - exec("mkdir -p /var/spool/lock"); - exec("chmod a+rw /var/spool/lock/."); + exec("/bin/mkdir -p /var/spool/lock"); + exec("/bin/chmod a+rw /var/spool/lock/."); } - if ($edit){ - // Construct the ppp.conf file - $peerfile .= "default:\n"; - $peerfile .= " set log Phase Chat LCP IPCP CCP tun command\n"; - $peerfile .= " ident user-ppp VERSION (built COMPILATIONDATE)\n"; - $peerfile .= " set dial \"ABORT BUSY ABORT NO\\\sCARRIER TIMEOUT 5 \\\n"; - $peerfile .= " \\\"\\\" AT OK-AT-OK ATE1Q0 OK \\\dATDT\\\T TIMEOUT 40 CONNECT\"\n"; - $peerfile .= " enable dns\n"; - $peerfile .= " nat enable yes\n"; - $peerfile .= " set reconnect {$ifcfg['connect-max-attempts']} 5\n"; - $peerfile .= " allow users root\n\n"; - - // Loop variables - $i = 0; - $startingip = 1; - - // Start ppp.linkup file - $rclinkup = "default:\n"; - // Start ppp.linkdown file - $rclinkdown = "default:\n"; + if (!file_exists("{$g['varetc_path']}/mpd.script")) + if($g['booting']) + // Maybe make a symlink instead? + mwexec("/bin/cp /etc/ppp/mpd.script {$g['varetc_path']}/mpd.script"); + + if ($edit || $g['booting']){ + if($g['booting']) + echo " configuring PPP on {$ppp_int} interface...\n"; + /* generate mpd.conf */ + $fd = fopen("{$g['varetc_path']}/mpd-ppp.conf", "w"); + if (!$fd) { + printf("Error: cannot open mpd-ppp.conf in interface_ppp_configure().\n"); + return 1; + } + /* generate mpd.secret */ + $fds = fopen("{$g['varetc_path']}/mpd.secret", "w"); + if (!$fds) { + printf("Error: cannot open mpd.secret in interface_ppp_configure().\n"); + return 1; + } + $fdlnkdn = fopen("{$g['varetc_path']}/ppp.linkdn", "w"); + if (!$fdlnkdn) { + printf("Error: cannot open ppp.linkdn in interface_ppp_configure().\n"); + return 1; + } + // Create mpd.secret file + + $secret = <<> /conf/ppp-up.{$dev}.log\"\n"; - $rclinkup .= " ! sh -c \"/sbin/ppp-script HISADDR INTERFACE DNS0 DNS1\"\n"; - $rclinkup .= " ! sh -c \"/etc/rc.linkup INTERFACE start\"\n"; - $rclinkup .= " ! sh -c \"/etc/rc.conf_mount_ro\"\n"; - $rclinkup.= " ! sh -c \"/etc/rc.filter_configure_sync\"\n"; - // Link down file - $rclinkdown .= "{$dev}:\n"; - $rclinkdown .= " ! sh -c \"/etc/rc.conf_mount_rw\"\n"; - $rclinkdown .= " ! sh -c \"/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` UPTIME >> /conf/ppp-up.{$dev}.log\"\n"; - $rclinkdown .= " ! sh -c \"/etc/rc.conf_mount_ro\"\n"; - $rclinkdown .= " ! sh -c \"/bin/rm -f /var/run/{$dev}.if\"\n"; - } - } + $ranges = "set ipcp ranges 10.0.0.{$ip}/0 10.0.0.{$endingip}/0"; + if ($ppp['username'] <> ""){ + $user = "{$ppp['username']}"; + } else { + $user = "Mylogin"; + } + + $mpdconf .= <<> /conf/$1.log +#/etc/rc.conf_mount_ro + +EOD; + + if ($ppp['username'] <> ""){ + $secret .= << accomplished by starting mpd with the -k flag*/ + /* fire up mpd */ + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd-ppp.conf -p {$g['varrun_path']}/{$ppp_int}.pid -s ppp {$ppp_int}"); + sleep(2); + -function interface_ppp_bring_down($if) { - if(file_exists("/var/run/{$if}.pid")) { - $pid = trim(file_get_contents("/var/run/{$if}.pid")); - mwexec("kill -QUIT {$pid}"); } } @@ -1904,7 +2022,9 @@ case 'pptp': interface_pptp_configure($interface); break; - + case 'ppp': + interface_ppp_configure($realif); + break; default: if ($wancfg['ipaddr'] <> "" && $wancfg['subnet'] <> "") { if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) { @@ -1929,9 +2049,6 @@ if (!$g['booting']) interface_reload_carps($realif); - if($wancfg['serialport']) - interface_ppp_configure($wancfg['serialport']); - if (!$g['booting']) { if (link_interface_to_gre($interface)) { foreach ($config['gres']['gre'] as $gre) @@ -2391,7 +2508,7 @@ */ function convert_real_interface_to_friendly_interface_name($interface = "wan") { global $config; - + if (stristr($interface, "pppoe")) { $index = substr($interface, 5); if (intval($index) > 0) @@ -2404,7 +2521,7 @@ 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) { @@ -2446,7 +2563,7 @@ /* attempt to resolve interface to friendly descr */ function convert_friendly_interface_to_friendly_descr($interface) { - global $config; + global $config; switch ($interface) { case "l2tp": @@ -2570,17 +2687,6 @@ if ($interface == $if || $interface == $ifdesc) { - // PPP Support - if($config['interfaces'][$if]['serialport']) { - $dev = $config['interfaces'][$if]['serialport']; - if(file_exists("/var/run/{$dev}.if")) { - $wanif = trim(file_get_contents("/var/run/{$dev}.if")); - } else - $wanif = "Not connected"; - - break; - } - $cfg = $config['interfaces'][$if]; // Wireless cloned NIC support (FreeBSD 8+) @@ -2624,6 +2730,9 @@ else $wanif = "pptp" . substr($if, 3); break; + case "ppp": + $wanif = $cfg['if']; + break; default: $wanif = $cfg['if']; break; @@ -2923,16 +3032,14 @@ /* loop interfaces, check config for outbound */ foreach($config['interfaces'] as $ifdescr => $ifname) { - if($ifname['serialport']) { - $ints[] = $ifdescr; - continue; - } + switch ($ifname['ipaddr']) { case "dhcp": case "carpdev-dhcp": case "pppoe": case "pptp": - $ints[] = $ifdescr; + case "ppp"; + $ints[] = $ifdescr; break; default: if ($ifname['pointtopoint'])