diff options
-rw-r--r-- | etc/inc/interfaces.inc | 112 | ||||
-rw-r--r-- | usr/local/www/interfaces_ppps.php | 2 | ||||
-rw-r--r-- | usr/local/www/interfaces_ppps_edit.php | 114 |
3 files changed, 123 insertions, 105 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index a985ff8..dc82a94 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -860,6 +860,118 @@ function interface_bring_down($interface = "wan", $destroy = false) { return; } +function interfaces_ptpid_used($ptpid) { + global $config; + + if (is_array($config['ppps']['ppp'])) + foreach ($config['ppps']['ppp'] as & $settings) + if ($ptpid == $settings['ptpid']) + return true; + + return false; +} + +function interfaces_ptpid_next() { + + $ptpid = 0; + while(interfaces_ptpid_used($ptpid)) + $ptpid++; + + return $ptpid; +} + +function getMPDCRONSettings($pppif_) { + 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.$pppif_) !== false) { + return array("ID" => $i, "ITEM" => $item); + } + } + } + return NULL; +} + +function handle_pppoe_reset($post_array) { + global $config, $g; + + $pppif = $post_array['type'].$post_array['ptpid']; + if (!is_array($config['cron']['item'])) + $config['cron']['item'] = array(); + $itemhash = getMPDCRONSettings($pppif); + $item = $itemhash['ITEM']; + + // reset cron items if necessary and return + if (empty($post_array['pppoe-reset-type'])) { + if (isset($item)) + unset($config['cron']['item'][$itemhash['ID']]); + sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP"); + return; + } + + if (empty($item)) + $item = array(); + if (isset($post_array['pppoe-reset-type']) && $post_array['pppoe-reset-type'] == "custom") { + $item['minute'] = $post_array['pppoe_resetminute']; + $item['hour'] = $post_array['pppoe_resethour']; + if (isset($post_array['pppoe_resetdate']) && $post_array['pppoe_resetdate'] <> "") { + $date = explode("/", $post_array['pppoe_resetdate']); + $item['mday'] = $date[1]; + $item['month'] = $date[0]; + } else { + $item['mday'] = "*"; + $item['month'] = "*"; + } + $item['wday'] = "*"; + $item['who'] = "root"; + $item['command'] = CRON_PPPOE_CMD_FILE.$pppif; + } else if (isset($post_array['pppoe-reset-type']) && $post_array['pppoe-reset-type'] == "preset") { + switch ($post_array['pppoe_pr_preset_val']) { + case "monthly": + $item['minute'] = "0"; + $item['hour'] = "0"; + $item['mday'] = "1"; + $item['month'] = "*"; + $item['wday'] = "*"; + $item['who'] = "root"; + $item['command'] = CRON_PPPOE_CMD_FILE.$pppif; + break; + case "weekly": + $item['minute'] = "0"; + $item['hour'] = "0"; + $item['mday'] = "*"; + $item['month'] = "*"; + $item['wday'] = "0"; + $item['who'] = "root"; + $item['command'] = CRON_PPPOE_CMD_FILE.$pppif; + break; + case "daily": + $item['minute'] = "0"; + $item['hour'] = "0"; + $item['mday'] = "*"; + $item['month'] = "*"; + $item['wday'] = "*"; + $item['who'] = "root"; + $item['command'] = CRON_PPPOE_CMD_FILE.$pppif; + break; + case "hourly": + $item['minute'] = "0"; + $item['hour'] = "*"; + $item['mday'] = "*"; + $item['month'] = "*"; + $item['wday'] = "*"; + $item['who'] = "root"; + $item['command'] = CRON_PPPOE_CMD_FILE.$pppif; + break; + } // end switch + }// end if + if (isset($itemhash['ID'])) + $config['cron']['item'][$itemhash['ID']] = $item; + else + $config['cron']['item'][] = $item; +} + /* This function can configure PPPoE, MLPPP (PPPoE), PPtP. * It writes the mpd config file to /var/etc every time the link is opened. */ diff --git a/usr/local/www/interfaces_ppps.php b/usr/local/www/interfaces_ppps.php index fc598b6..63287b6 100644 --- a/usr/local/www/interfaces_ppps.php +++ b/usr/local/www/interfaces_ppps.php @@ -107,7 +107,7 @@ include("head.inc"); <?php $i = 0; foreach ($a_ppps as $id => $ppp): ?> <tr ondblclick="document.location='interfaces_ppps_edit.php?id=<?=$i;?>'"> <td class="listr"> - <?=htmlspecialchars($ppp['type']);?> + <?=htmlspecialchars($ppp['if']);?> </td> <td class="listr"> <?=htmlspecialchars($ppp['ports']);?> diff --git a/usr/local/www/interfaces_ppps_edit.php b/usr/local/www/interfaces_ppps_edit.php index 694b54a..402868e 100644 --- a/usr/local/www/interfaces_ppps_edit.php +++ b/usr/local/www/interfaces_ppps_edit.php @@ -50,19 +50,6 @@ define("CRON_WEEKLY_PATTERN", "0 0 * * 0"); define("CRON_DAILY_PATTERN", "0 0 * * *"); define("CRON_HOURLY_PATTERN", "0 * * * *"); -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.$ptpid_) !== false) { - return array("ID" => $i, "ITEM" => $item); - } - } - } - return NULL; -} - if (!is_array($config['ppps']['ppp'])) $config['ppps']['ppp'] = array(); @@ -73,10 +60,11 @@ $portlist = get_interface_list(); $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; - - + if (isset($id) && $a_ppps[$id]) { + $pconfig['ptpid'] = $a_ppps[$id]['ptpid']; $pconfig['type'] = $a_ppps[$id]['type']; + //$pconfig['if'] = $a_ppps[$id]['if']; $pconfig['interfaces'] = $a_ppps[$id]['ports']; $pconfig['username'] = $a_ppps[$id]['username']; $pconfig['password'] = base64_decode($a_ppps[$id]['password']); @@ -131,7 +119,7 @@ if (isset($id) && $a_ppps[$id]) { if (isset($a_ppps[$id]['pppoe-reset-type'])) { $pconfig['pppoe-reset-type'] = $a_ppps[$id]['pppoe-reset-type']; - $itemhash = getMPDCRONSettings($a_ppps[$id]['ptpid']); + $itemhash = getMPDCRONSettings($a_ppps[$id]['if']); $cronitem = $itemhash['ITEM']; if (isset($cronitem)) { $resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; @@ -170,7 +158,8 @@ if (isset($id) && $a_ppps[$id]) { break; } -} +} else + $pconfig['ptpid'] = interfaces_ptpid_next(); if ($_POST) { @@ -275,6 +264,7 @@ if ($_POST) { $ppp = array(); $ppp['ptpid'] = $_POST['ptpid']; $ppp['type'] = $_POST['type']; + $ppp['if'] = $ppp['type'].$ppp['ptpid']; $ppp['ports'] = implode(',',$_POST['interfaces']); $ppp['username'] = $_POST['username']; $ppp['password'] = base64_encode($_POST['password']); @@ -368,11 +358,11 @@ if ($_POST) { /* handle_pppoe_reset is called here because if user changes Link Type from PPPoE to another type we must be able to clear the config data in the <cron> section of config.xml if it exists */ - handle_pppoe_reset(); + handle_pppoe_reset($_POST); $iflist = get_configured_interface_list(); foreach ($iflist as $if) { - if ($config['interfaces'][$if]['ptpid'] == $_POST['ptpid']){ + if ($config['interfaces'][$if]['if'] == $ppp['if']){ $thisif = $if; break; } @@ -393,84 +383,6 @@ if ($_POST) { } } // end if($_POST) -function handle_pppoe_reset() { - global $_POST, $config, $g; - - if (!is_array($config['cron']['item'])) - $config['cron']['item'] = array(); - $itemhash = getMPDCRONSettings($_POST['ptpid']); - $item = $itemhash['ITEM']; - - /* reset cron items if necessary and return*/ - if (empty($_POST['pppoe-reset-type'])) { - if (isset($item)) - unset($config['cron']['item'][$itemhash['ID']]); - sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP"); - return; - } - - if (empty($item)) - $item = array(); - 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'] <> "") { - $date = explode("/", $_POST['pppoe_resetdate']); - $item['mday'] = $date[1]; - $item['month'] = $date[0]; - } else { - $item['mday'] = "*"; - $item['month'] = "*"; - } - $item['wday'] = "*"; - $item['who'] = "root"; - $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"; - $item['hour'] = "0"; - $item['mday'] = "1"; - $item['month'] = "*"; - $item['wday'] = "*"; - $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; - break; - case "weekly": - $item['minute'] = "0"; - $item['hour'] = "0"; - $item['mday'] = "*"; - $item['month'] = "*"; - $item['wday'] = "0"; - $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; - break; - case "daily": - $item['minute'] = "0"; - $item['hour'] = "0"; - $item['mday'] = "*"; - $item['month'] = "*"; - $item['wday'] = "*"; - $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; - break; - case "hourly": - $item['minute'] = "0"; - $item['hour'] = "*"; - $item['mday'] = "*"; - $item['month'] = "*"; - $item['wday'] = "*"; - $item['who'] = "root"; - $item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid']; - break; - } // end switch - }// end if - if (isset($itemhash['ID'])) - $config['cron']['item'][$itemhash['ID']] = $item; - else - $config['cron']['item'][] = $item; -} - $closehead = false; $pgtitle = array("Interfaces","PPPs","Edit"); include("head.inc"); @@ -865,13 +777,7 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()"> - <?php - if (isset($a_ppps[$id]['ptpid'])) - $ptpid = $a_ppps[$id]['ptpid']; - else - $ptpid = uniqid('', true); - ?> - <input name="ptpid" type="hidden" value="<?=$ptpid;?>"> + <input name="ptpid" type="hidden" value="<?=htmlspecialchars($pconfig['ptpid']);?>"> <?php if (isset($id) && $a_ppps[$id]): ?> <input name="id" type="hidden" value="<?=$id;?>"> <?php endif; ?> |