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:
Franco Fichtner 2026-06-01 07:55:13 +02:00
parent cd2e12ed9f
commit ae08b03b53
3 changed files with 28 additions and 3 deletions

View file

@ -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'];
}
/**

View file

@ -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]

View file

@ -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