Commit d5654b79 authored by Franco Fichtner's avatar Franco Fichtner

interfaces: remove pppoe reset cron handling... #911

... Ad already annotated a few spots, the whole thing is beyond
repair and I dread extending it to PPP and others which has been
asked for a few times now.  We will have to find another way.

To paraphrase Star Trek: He's dead, Jim.

The upside is that the cron config items are flushed by default
now, later we can remove this as we don't care what is in that
unused config section anyway.
parent 8d10efac
......@@ -1408,108 +1408,6 @@ function interfaces_ptpid_next()
return $ptpid;
}
function getMPDCRONSettings($pppif)
{
global $config;
$cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}";
if (isset($config['cron']['item'])) {
foreach ($config['cron']['item'] as $i => $item) {
if (stripos($item['command'], $cron_cmd_file) !== false) {
return array("ID" => $i, "ITEM" => $item);
}
}
}
return null;
}
function handle_pppoe_reset($post_array)
{
global $config;
$pppif = "{$post_array['type']}{$post_array['ptpid']}";
$cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}";
if (!isset($config['cron']['item']) || !is_array($config['cron']['item'])) {
$config['cron']['item'] = array();
}
$itemhash = getMPDCRONSettings($pppif);
// reset cron items if necessary and return
if (empty($post_array['pppoe-reset-type'])) {
if (isset($itemhash)) {
unset($config['cron']['item'][$itemhash['ID']]);
}
killbypid('/var/run/cron.pid', 'HUP');
return;
}
if (empty($itemhash)) {
$itemhash = array();
}
$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_cmd_file;
} elseif (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'] = "*";
break;
case "weekly":
$item['minute'] = "0";
$item['hour'] = "0";
$item['mday'] = "*";
$item['month'] = "*";
$item['wday'] = "0";
break;
case "daily":
$item['minute'] = "0";
$item['hour'] = "0";
$item['mday'] = "*";
$item['month'] = "*";
$item['wday'] = "*";
break;
case "hourly":
$item['minute'] = "0";
$item['hour'] = "*";
$item['mday'] = "*";
$item['month'] = "*";
$item['wday'] = "*";
break;
} // end switch
$item['who'] = "root";
$item['command'] = $cron_cmd_file;
}
if (empty($item)) {
return;
}
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.
......@@ -1839,14 +1737,6 @@ EOD;
mwexec("/usr/local/sbin/mpd5 -b -k -d /var/etc -f mpd_{$interface}.conf -p /var/run/" .
escapeshellarg($ppp['type']) . "_{$interface}.pid -s ppp " . escapeshellarg($ppp['type']) . "client");
// Check for PPPoE periodic reset request
if ($ppp['type'] == "pppoe") {
if (!empty($ppp['pppoe-reset-type'])) {
interface_setup_pppoe_reset_file($ppp['if'], $interface);
} else {
interface_setup_pppoe_reset_file($ppp['if']);
}
}
/* wait for up to 10 seconds for the interface to appear (ppp(oe)) */
$i = 0;
while ($i < 10) {
......@@ -4965,26 +4855,6 @@ function is_jumbo_capable($iface)
}
}
function interface_setup_pppoe_reset_file($pppif, $iface = '')
{
$cron_file = "/var/etc/pppoe_restart_{$pppif}";
if (!empty($iface) && !empty($pppif)) {
$cron_cmd = <<<EOD
#!/bin/sh
/usr/local/opnsense/service/configd_ctl.py interface reconfigure {$iface}
/usr/bin/logger -t {$pppif} "PPPoE periodic reset executed on {$iface}"
EOD;
@file_put_contents($cron_file, $cron_cmd);
chmod($cron_file, 0755);
killbypid('/var/run/cron.pid', 'HUP');
} else {
@unlink($cron_file);
}
}
function get_vip_descr($ipaddress)
{
global $config;
......
......@@ -2344,25 +2344,8 @@ function configure_cron()
{
global $config;
$obsoletes = array(
'/usr/local/etc/rc.backup_dhcpleases',
'/usr/local/etc/rc.backup_netflow',
'/usr/local/etc/rc.backup_rrd',
'/usr/local/etc/rc.filter_configure_sync',
'/usr/local/etc/rc.dyndns.update',
'/usr/local/etc/rc.update_bogons',
'/usr/local/etc/rc.update_urltables',
'/usr/local/opnsense/scripts/remote_backup.php',
'/usr/local/sbin/expiretable -v -t 3600 sshlockout',
'/usr/local/sbin/expiretable -v -t 3600 virusprot',
'adjkerntz -a',
/* old config migration for extra care: */
'checkreload.sh',
'newsyslog',
);
/*
* Strip old cron jobs that we no longer save explicitly.
* Strip the cron jobs that we no longer save explicitly.
* This can be safely removed on our final road to 17.1.
*/
if (isset($config['cron']['item'])) {
......@@ -2372,11 +2355,9 @@ function configure_cron()
/* PHP retains the index, can iterate all and unset */
foreach ($config['cron']['item'] as $item) {
foreach ($obsoletes as $obsolete) {
if ($item['command'] === $obsolete) {
unset($config['cron']['item'][$index]);
$flush = true;
}
}
$index++;
}
......@@ -2457,10 +2438,6 @@ function configure_cron()
$crontab_contents .= '# auto-generated at ' . date('F j, Y, g:i a') . "\n";
$crontab_contents .= "#\n";
if (isset($config['cron']['item'])) {
$autocron = array_merge($config['cron']['item'], $autocron);
}
foreach ($autocron as $item) {
$crontab_contents .= "{$item['minute']}\t";
$crontab_contents .= "{$item['hour']}\t";
......
......@@ -2287,16 +2287,6 @@ function upgrade_063_to_064() {
$ppp['ondemand'] = true;
if (isset($ifinfo['timeout']))
$ppp['idletimeout'] = $ifinfo['timeout'];
if (isset($ifinfo['pppoe']['pppoe-reset-type'])){
$ppp['pppoe-reset-type'] = $ifinfo['pppoe']['pppoe-reset-type'];
if (is_array($config['cron']['item'])) {
for ($i = 0; $i < count($config['cron']['item']); $i++) {
$item = $config['cron']['item'][$i];
if (strpos($item['command'], "/conf/pppoe{$ifname}restart") !== false)
$config['cron']['item'][$i]['command'] = "/var/etc/pppoe_restart_" . $ppp['if'];
}
}
}
if (isset($ifinfo['local']))
$ppp['localip'] = $ifinfo['local'];
if (isset($ifinfo['subnet']))
......@@ -2312,8 +2302,6 @@ function upgrade_063_to_064() {
unset($ifcfg[$ifname]['provider']);
unset($ifcfg[$ifname]['ondemand']);
unset($ifcfg[$ifname]['timeout']);
unset($ifcfg[$ifname]['pppoe_reset']);
unset($ifcfg[$ifname]['pppoe_preset']);
unset($ifcfg[$ifname]['pppoe']);
unset($ifcfg[$ifname]['pptp_username']);
unset($ifcfg[$ifname]['pptp_password']);
......
This diff is collapsed.
......@@ -57,8 +57,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (ppp_inuse($a_ppps[$id]['if'])) {
$input_errors[] = gettext("This point-to-point link cannot be deleted because it is still being used as an interface.");
} else {
unset($a_ppps[$id]['pppoe-reset-type']);
handle_pppoe_reset($a_ppps[$id]);
unset($a_ppps[$id]);
write_config();
header("Location: interfaces_ppps.php");
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment