diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index 2164233e63..a24765a879 100755 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -59,18 +59,18 @@ if ($_REQUEST['if']) { $if = "wan"; } -define("CRON_PPPOE_CMD_FILE", "/conf/pppoe{$if}restart"); +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() { +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) !== false) { + if (strpos($item['command'], CRON_PPPOE_CMD_FILE.$ptpid_) !== false) { return array("ID" => $i, "ITEM" => $item); } } @@ -78,15 +78,10 @@ function getMPDCRONSettings() { return NULL; } -function getMPDResetTimeFromConfig() { - $itemhash = getMPDCRONSettings(); - $cronitem = $itemhash['ITEM']; - if (isset($cronitem)) { - return "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; - } else { - return NULL; - } -} +if (!is_array($config['ppps']['ppp'])) + $config['ppps']['ppp'] = array(); + +$a_ppps = &$config['ppps']['ppp']; function remove_bad_chars($string) { return preg_replace('/[^a-z|_|0-9]/i','',$string); @@ -99,56 +94,77 @@ $a_gateways = &$config['gateways']['gateway_item']; $wancfg = &$config['interfaces'][$if]; -$pconfig['pppoe_username'] = $wancfg['pppoe_username']; -$pconfig['pppoe_password'] = $wancfg['pppoe_password']; -$pconfig['provider'] = $wancfg['provider']; -$pconfig['pppoe_dialondemand'] = isset($wancfg['ondemand']); -$pconfig['pppoe_idletimeout'] = $wancfg['timeout']; - -/* ================================================ */ -/* = force a connection reset at a specific time? = */ -/* ================================================ */ - -if (isset($wancfg['pppoe']['pppoe-reset-type'])) { - $resetTime = getMPDResetTimeFromConfig(); - $pconfig['pppoe_preset'] = true; - if ($wancfg['pppoe']['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 ($wancfg['pppoe']['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; +if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { + foreach ($a_ppps as $pppid => $ppp) { + if ($wancfg['ptpid'] == $ppp['ptpid']) break; } } +if ($wancfg['ptpid'] == $ppp['ptpid']) { + $pconfig['interfaces'] = $a_ppps[$pppid]['ports']; + + if (isset($a_ppps[$pppid]['defaultgw'])) + $pconfig['defaultgw'] = true; + + if ($a_ppps[$pppid]['type'] == "pppoe"){ + $pconfig['pppoe_username'] = $a_ppps[$pppid]['username']; + $pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']); + $pconfig['provider'] = $a_ppps[$pppid]['provider']; + $pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']); + $pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout']; + + /* ================================================ */ + /* = force a connection reset at a specific time? = */ + /* ================================================ */ + + if (isset($a_ppps[$pppid]['pppoe-reset-type'])) { + $pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type']; + $itemhash = getMPDCRONSettings($a_ppps[$pppid]['ptpid']); + $cronitem = $itemhash['ITEM']; + if (isset($cronitem)) { + $resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; + } else { + $resetTime = NULL; + } + if ($a_ppps[$pppid]['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[$pppid]['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; + } + } + }// End force pppoe reset at specific time + }// End if type == pppoe + if ($a_ppps[$pppid]['type'] == "pptp"){ + $pconfig['pptp_username'] = $a_ppps[$pppid]['username']; + $pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']); + $pconfig['pptp_local'] = $a_ppps[$pppid]['localip']; + $pconfig['pptp_subnet'] = $a_ppps[$pppid]['subnet']; + $pconfig['pptp_remote'] = $a_ppps[$pppid]['gateway']; + $pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']); + $pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout']; + } } - -$pconfig['pptp_username'] = $wancfg['pptp_username']; -$pconfig['pptp_password'] = $wancfg['pptp_password']; -$pconfig['pptp_local'] = $wancfg['local']; -$pconfig['pptp_subnet'] = $wancfg['subnet']; -$pconfig['pptp_remote'] = $wancfg['remote']; -$pconfig['pptp_dialondemand'] = isset($wancfg['ondemand']); -$pconfig['pptp_idletimeout'] = $wancfg['timeout']; - $pconfig['dhcphostname'] = $wancfg['dhcphostname']; $pconfig['alias-address'] = $wancfg['alias-address']; $pconfig['alias-subnet'] = $wancfg['alias-subnet']; @@ -180,13 +196,9 @@ switch($wancfg['ipaddr']) { $pconfig['ipaddr'] = ""; break; case "pppoe": - $pconfig['type'] = "pppoe"; - break; case "pptp": - $pconfig['type'] = "pptp"; - break; case "ppp": - $pconfig['type'] = "ppp"; + $pconfig['type'] = $wancfg['ipaddr']; break; default: if(is_ipaddr($wancfg['ipaddr'])) { @@ -467,6 +479,7 @@ if ($_POST) { } } if (!$input_errors) { + $ppp = array(); if ($wancfg['ipaddr'] != "ppp") unset($wancfg['ipaddr']); unset($wancfg['subnet']); @@ -509,7 +522,13 @@ if ($_POST) { unset($gateway_item); } } - + + // Here code assumes only that strings of form "opt#" will be passed. + if ($if == "wan") + $if_num = "0"; + else + $if_num = substr($interface, 3); + switch($_POST['type']) { case "static": $wancfg['ipaddr'] = $_POST['ipaddr']; @@ -537,25 +556,57 @@ if ($_POST) { } break; case "pppoe": - $wancfg['ipaddr'] = "pppoe"; - $wancfg['pppoe_username'] = $_POST['pppoe_username']; - $wancfg['pppoe_password'] = $_POST['pppoe_password']; - $wancfg['provider'] = $_POST['provider']; - $wancfg['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false; - $wancfg['timeout'] = $_POST['pppoe_idletimeout']; + $ppp['ptpid'] = $_POST['ptpid']; + $ppp['type'] = $_POST['type']; + if (isset($_POST['ppp_port'])) + $ppp['ports'] = $_POST['ppp_port']; + else + $ppp['ports'] = $wancfg['if']; + $ppp['username'] = $_POST['pppoe_username']; + $ppp['password'] = base64_encode($_POST['pppoe_password']); + if (!empty($_POST['provider'])) + $ppp['provider'] = $_POST['provider']; + else + unset($ppp['provider']); + $ppp['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false; + if (!empty($_POST['idletimeout'])) + $ppp['idletimeout'] = $_POST['pppoe_idletimeout']; + else + unset($ppp['idletimeout']); + + if (!empty($_POST['pppoe-reset-type'])) + $ppp['pppoe-reset-type'] = $_POST['pppoe-reset-type']; + else + unset($ppp['pppoe-reset-type']); + $wancfg['if'] = $_POST['type'] . $if_num; + $wancfg['ptpid'] = $_POST['ptpid']; + $wancfg['ipaddr'] = $_POST['type']; if($gateway_item) { $a_gateways[] = $gateway_item; } + break; case "pptp": - $wancfg['ipaddr'] = "pptp"; - $wancfg['pptp_username'] = $_POST['pptp_username']; - $wancfg['pptp_password'] = $_POST['pptp_password']; - $wancfg['local'] = $_POST['pptp_local']; - $wancfg['subnet'] = $_POST['pptp_subnet']; - $wancfg['remote'] = $_POST['pptp_remote']; - $wancfg['ondemand'] = $_POST['pptp_dialondemand'] ? true : false; - $wancfg['timeout'] = $_POST['pptp_idletimeout']; + $ppp['ptpid'] = $_POST['ptpid']; + $ppp['type'] = $_POST['type']; + if (isset($_POST['ppp_port'])) + $ppp['ports'] = $_POST['ppp_port']; + else + $ppp['ports'] = $wancfg['if']; + $ppp['username'] = $_POST['pptp_username']; + $ppp['password'] = base64_encode($_POST['pptp_password']); + $ppp['localip'] = $_POST['pptp_local']; + $ppp['subnet'] = $_POST['pptp_subnet']; + $ppp['gateway'] = $_POST['pptp_remote']; + $ppp['ondemand'] = $_POST['pptp_dialondemand'] ? true : false; + if (!empty($_POST['idletimeout'])) + $ppp['idletimeout'] = $_POST['pptp_idletimeout']; + else + unset($ppp['idletimeout']); + + $wancfg['if'] = $_POST['type'] . $if_num; + $wancfg['ptpid'] = $_POST['ptpid']; + $wancfg['ipaddr'] = $_POST['type']; if($gateway_item) { $a_gateways[] = $gateway_item; } @@ -563,9 +614,9 @@ if ($_POST) { } handle_pppoe_reset(); /* reset cron items if necessary */ - if (empty($_POST['pppoe_preset'])) { + if (empty($_POST['pppoe-reset-type'])) { /* test whether a cron item exists and unset() it if necessary */ - $itemhash = getMPDCRONSettings(); + $itemhash = getMPDCRONSettings($_POST['ptpid']); $item = $itemhash['ITEM']; if (isset($item)) unset($config['cron']['item'][$itemhash['ID']]); @@ -597,13 +648,19 @@ if ($_POST) { header("Location: interfaces.php?if={$if}"); exit; } + + if (isset($_POST['pppid']) && $a_ppps[$pppid]) + $a_ppps[$pppid] = $ppp; + else + $a_ppps[] = $ppp; + } // end if($_POST) function handle_pppoe_reset() { global $_POST, $config, $g, $wancfg, $if; /* perform a periodic reset? */ if(!isset($_POST['pppoe_preset'])) { - setup_pppoe_reset_file($if, false); + setup_pppoe_reset_file($_POST['ptpid'], $_POST['if']); return; } if (!is_array($config['cron']['item'])) @@ -612,9 +669,7 @@ function handle_pppoe_reset() { $item = $itemhash['ITEM']; if (empty($item)) $item = array(); - if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") { - $wancfg['pppoe']['pppoe-reset-type'] = "custom"; - $pconfig['pppoe_pr_custom'] = true; + 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'] <> "" && strlen($_POST['pppoe_resetdate']) == 10) { @@ -627,10 +682,8 @@ function handle_pppoe_reset() { } $item['wday'] = "*"; $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE; - } else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") { - $wancfg['pppoe']['pppoe-reset-type'] = "preset"; - $pconfig['pppoe_pr_preset'] = true; + $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"; @@ -675,15 +728,15 @@ function handle_pppoe_reset() { else $config['cron']['item'][] = $item; /* finally install the pppoerestart file */ - if (isset($_POST['pppoe_preset'])) { - setup_pppoe_reset_file($if, true); - $wancfg['pppoe_reset'] = true; - $wancfg['pppoe_preset'] = true; + if (isset($_POST['pppoe-reset-type']) { + setup_pppoe_reset_file($_POST['ptpid'], $if); +// $wancfg['pppoe_reset'] = true; +// $wancfg['pppoe_preset'] = true; sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP"); } else { - unset($wancfg['pppoe_reset']); - unset($wancfg['pppoe_preset']); - setup_pppoe_reset_file($if, false); +// unset($wancfg['pppoe_reset']); +// unset($wancfg['pppoe_preset']); + setup_pppoe_reset_file($_POST['ptpid']); } } @@ -872,7 +925,19 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" else $('presetwrap').hide(); } - + function show_reset_settings(reset_type) { + if (reset_type == 'preset') { + Effect.Appear('pppoepresetwrap', { duration: 0.0 }); + Effect.Fade('pppoecustomwrap', { duration: 0.0 }); + } + else if (reset_type == 'custom') { + Effect.Appear('pppoecustomwrap', { duration: 0.0 }); + Effect.Fade('pppoepresetwrap', { duration: 0.0 }); + } else { + Effect.Fade('pppoecustomwrap', { duration: 0.0 }); + Effect.Fade('pppoepresetwrap', { duration: 0.0 }); + } + } function show_mon_config() { document.getElementById("showmonbox").innerHTML=''; aodiv = document.getElementById('showmon'); @@ -1034,7 +1099,7 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe"
| @@ -1690,6 +1747,17 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" + + + + + + |