From a986f97f900b54b509776d366cd2834aca73f489 Mon Sep 17 00:00:00 2001 From: gnhb Date: Sat, 8 May 2010 11:12:52 +0700 Subject: Working on PPPoE periodic reset. Writing out pppoe_restart_XXX file still needs work. --- usr/local/www/interfaces_ppps_edit.php | 277 ++++++++++----------- .../javascript/interfaces_ppps_edit/ppps_edit.js | 13 + 2 files changed, 150 insertions(+), 140 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/interfaces_ppps_edit.php b/usr/local/www/interfaces_ppps_edit.php index 9bfa2c4..47c2901 100644 --- a/usr/local/www/interfaces_ppps_edit.php +++ b/usr/local/www/interfaces_ppps_edit.php @@ -43,7 +43,7 @@ require("guiconfig.inc"); -define("CRON_PPPOE_CMD_FILE", "/conf/pppoe{$if}restart"); +define("CRON_PPPOE_CMD_FILE", "{$g['varetc_path']}/ppp_restart_"); define("CRON_MONTHLY_PATTERN", "0 0 1 * *"); define("CRON_WEEKLY_PATTERN", "0 0 * * 0"); define("CRON_DAILY_PATTERN", "0 0 * * *"); @@ -61,7 +61,7 @@ function getMPDCRONSettings() { 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.$_POST['ptpid']) !== false) { return array("ID" => $i, "ITEM" => $item); } } @@ -133,8 +133,9 @@ if (isset($id) && $a_ppps[$id]) { /* ================================================ */ if (isset($a_ppps[$id]['pppoe-reset-type'])) { + $pconfig['pppoe-reset-type'] = $a_ppps[$id]['pppoe-reset-type']; + $resetTime = getMPDResetTimeFromConfig(); - $pconfig['pppoe_preset'] = true; if ($a_ppps[$id]['pppoe-reset-type'] == "custom") { $resetTime_a = split(" ", $resetTime); $pconfig['pppoe_pr_custom'] = true; @@ -178,8 +179,8 @@ if ($_POST) { * data validation procedure below, may trigger a false error * message. */ - if (empty($_POST['pppoe_preset'])) { - unset($_POST['pppoe_pr_type']); + if (empty($_POST['pppoe-reset-type'])) { + //unset($_POST['pppoe-reset-type']); unset($_POST['pppoe_resethour']); unset($_POST['pppoe_resetminute']); unset($_POST['pppoe_resetdate']); @@ -225,14 +226,23 @@ if ($_POST) { $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_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && + 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_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) && + 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_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) + 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!"); + } if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) $input_errors[] = "A valid PPTP local IP address must be specified."; if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) @@ -320,6 +330,10 @@ if ($_POST) { $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']); handle_pppoe_reset(); break; case "pptp": @@ -332,7 +346,7 @@ if ($_POST) { } /* 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(); $item = $itemhash['ITEM']; @@ -380,24 +394,23 @@ if ($_POST) { } // end if($_POST) function handle_pppoe_reset() { - global $_POST, $config, $g, $ppp, $if; + global $_POST, $config, $g; /* perform a periodic reset? */ - if(!isset($_POST['pppoe_preset'])) { - setup_pppoe_reset_file($if, false); + if(empty($_POST['pppoe-reset-type'])) { + setup_pppoe_reset_file($_POST['ptpid'], false); return; } + if (!is_array($config['cron']['item'])) $config['cron']['item'] = array(); $itemhash = getMPDCRONSettings(); $item = $itemhash['ITEM']; if (empty($item)) $item = array(); - if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") { - $ppp['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) { + if (isset($_POST['pppoe_resetdate']) && $_POST['pppoe_resetdate'] <> "") { $date = explode("/", $_POST['pppoe_resetdate']); $item['mday'] = $date[1]; $item['month'] = $date[0]; @@ -407,10 +420,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") { - $ppp['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"; @@ -419,7 +430,7 @@ function handle_pppoe_reset() { $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE; + $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "weekly": $item['minute'] = "0"; @@ -428,7 +439,7 @@ function handle_pppoe_reset() { $item['month'] = "*"; $item['wday'] = "0"; $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE; + $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "daily": $item['minute'] = "0"; @@ -437,7 +448,7 @@ function handle_pppoe_reset() { $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE; + $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; case "hourly": $item['minute'] = "0"; @@ -446,32 +457,28 @@ function handle_pppoe_reset() { $item['month'] = "*"; $item['wday'] = "*"; $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE; + $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; break; } // end switch - } // end if + }// end if if (isset($itemhash['ID'])) $config['cron']['item'][$itemhash['ID']] = $item; else $config['cron']['item'][] = $item; - /* finally install the pppoerestart file */ - if (isset($_POST['pppoe_preset'])) { - setup_pppoe_reset_file($if, true); - //$ppp['pppoe_reset'] = true; - $ppp['pppoe_preset'] = true; + + // finally install the pppoerestart file + if (isset($_POST['pppoe-reset-type'])) { + setup_pppoe_reset_file($_POST['ptpid'], true); sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP"); - } else { - //unset($ppp['pppoe_reset']); - unset($ppp['pppoe_preset']); - setup_pppoe_reset_file($if, false); - } + } else + setup_pppoe_reset_file($_POST['ptpid'], false); } $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", "ng" => "Netgraph" */ ); +$types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP", "l2tp" => "L2TP"/*, "tcp" => "TCP", "udp" => "UDP"*/ ); ?>