mirror of
https://github.com/opnsense/core.git
synced 2026-06-09 00:42:36 -04:00
cron: allow unregistered actions to be deleted
Also add a user exception so the users knows what's going on when not being able to delete.
This commit is contained in:
parent
cd2e12ed9f
commit
ae08b03b53
3 changed files with 28 additions and 3 deletions
|
|
@ -29,6 +29,8 @@
|
|||
namespace OPNsense\Cron\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use OPNsense\Base\UserException;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
/**
|
||||
* Class SettingsController Handles settings related API actions for the Cron
|
||||
|
|
@ -120,11 +122,20 @@ class SettingsController extends ApiMutableModelControllerBase
|
|||
{
|
||||
if ($uuid != null) {
|
||||
$node = $this->getModel()->getNodeByReference('jobs.job.' . $uuid);
|
||||
if ($node->origin == "cron") {
|
||||
return $this->delBase("jobs.job", $uuid);
|
||||
$may_delete = false;
|
||||
if ($node->origin == 'cron') {
|
||||
$may_delete = true;
|
||||
} else {
|
||||
$result = trim((new Backend())->configdpRun('configd lookup', [$node->command]));
|
||||
$may_delete = $result !== 'OK';
|
||||
}
|
||||
if ($may_delete) {
|
||||
return $this->delBase('jobs.job', $uuid);
|
||||
} else {
|
||||
throw new UserException(gettext('Cannot delete this automatically registered cron job.'));
|
||||
}
|
||||
}
|
||||
return array("result" => "failed");
|
||||
return ['result' => 'failed'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,3 +9,9 @@ command:env | sort
|
|||
parameters:
|
||||
type:script_output
|
||||
message:get configd environment
|
||||
|
||||
[lookup]
|
||||
command:configd.lookup
|
||||
parameters:%s
|
||||
type:inline
|
||||
message:check action registered [%s]
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ class Action(BaseAction):
|
|||
return 'OK'
|
||||
else:
|
||||
return 'ERR'
|
||||
elif self.command == 'configd.lookup':
|
||||
from ..processhandler import ActionHandler
|
||||
act_handler = ActionHandler()
|
||||
action_obj, *_ = act_handler.find_action(act_parameters.split())
|
||||
if action_obj is not None:
|
||||
return 'OK'
|
||||
else:
|
||||
return 'ERR'
|
||||
elif self.command == 'configd.actions':
|
||||
# list all available configd actions
|
||||
from ..processhandler import ActionHandler
|
||||
|
|
|
|||
Loading…
Reference in a new issue