From ae08b03b53c8d24358bd7ecbfb6f8e349ac8ba8e Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 1 Jun 2026 07:55:13 +0200 Subject: [PATCH] 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. --- .../OPNsense/Cron/Api/SettingsController.php | 17 ++++++++++++++--- .../service/conf/actions.d/actions_configd.conf | 6 ++++++ src/opnsense/service/modules/actions/inline.py | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php index 30d88213b2..8670e859db 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php @@ -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']; } /** diff --git a/src/opnsense/service/conf/actions.d/actions_configd.conf b/src/opnsense/service/conf/actions.d/actions_configd.conf index ab78ac5e70..c280e094d5 100644 --- a/src/opnsense/service/conf/actions.d/actions_configd.conf +++ b/src/opnsense/service/conf/actions.d/actions_configd.conf @@ -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] diff --git a/src/opnsense/service/modules/actions/inline.py b/src/opnsense/service/modules/actions/inline.py index 74a50fa919..325a7151c4 100644 --- a/src/opnsense/service/modules/actions/inline.py +++ b/src/opnsense/service/modules/actions/inline.py @@ -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