-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysutils/auto-recovery: a new plugin, closes #2976
- Loading branch information
Showing
13 changed files
with
679 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PLUGIN_NAME= auto-recovery | ||
PLUGIN_VERSION= 1.0 | ||
PLUGIN_COMMENT= A configuration rollback functionality for OPNsense | ||
PLUGIN_MAINTAINER= opnsense@moov.de | ||
|
||
.include "../../Mk/plugins.mk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Set a timer to perform a rollback to a previous configuration state. | ||
It is a safety net when making critical configuration on a remote device. | ||
|
||
Plugin Changelog | ||
================ | ||
|
||
1.0 | ||
|
||
* initial release |
92 changes: 92 additions & 0 deletions
92
...recovery/src/opnsense/mvc/app/controllers/OPNsense/AutoRecovery/Api/ServiceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2023 Frank Wall | ||
* Copyright (C) 2015 Deciso B.V. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
namespace OPNsense\AutoRecovery\Api; | ||
|
||
use OPNsense\Base\ApiMutableServiceControllerBase; | ||
use OPNsense\Core\Backend; | ||
use OPNsense\AutoRecovery\AutoRecovery; | ||
|
||
/** | ||
* Class ServiceController | ||
* @package OPNsense\AutoRecovery | ||
*/ | ||
class ServiceController extends ApiMutableServiceControllerBase | ||
{ | ||
protected static $internalServiceClass = '\OPNsense\AutoRecovery\AutoRecovery'; | ||
protected static $internalServiceTemplate = 'OPNsense/AutoRecovery'; | ||
protected static $internalServiceEnabled = 'general.Enabled'; | ||
protected static $internalServiceName = 'autorecovery'; | ||
|
||
/** | ||
* start countdown | ||
* @return string | ||
*/ | ||
public function countdownAction() | ||
{ | ||
$model = new AutoRecovery(); | ||
$action = (string)$model->general->action; | ||
if (!empty((string)$model->general->configd_command)) { | ||
// Replace spaces with colons before passing the value to configdRun(). | ||
$configdcmd = str_replace(' ', ':',(string)$model->general->configd_command); | ||
} else { | ||
$configdcmd = 'not_found'; | ||
} | ||
// Convert minutes to seconds | ||
$countdown = 60 * (string)$model->general->countdown; | ||
|
||
$backend = new Backend(); | ||
$response = $backend->configdRun("autorecovery countdown ${action} ${configdcmd} ${countdown}"); | ||
return array("response" => $response); | ||
} | ||
|
||
/** | ||
* get remaining time for current countdown | ||
* @return string | ||
*/ | ||
public function timeAction() | ||
{ | ||
$backend = new Backend(); | ||
$response = $backend->configdRun("autorecovery status"); | ||
return array("response" => $response); | ||
} | ||
|
||
/** | ||
* abort countdown | ||
* @return string | ||
*/ | ||
public function abortAction() | ||
{ | ||
$backend = new Backend(); | ||
$response = $backend->configdRun("autorecovery abort"); | ||
return array("response" => $response); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ecovery/src/opnsense/mvc/app/controllers/OPNsense/AutoRecovery/Api/SettingsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2023 Frank Wall | ||
* Copyright (C) 2015-2019 Deciso B.V. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
namespace OPNsense\AutoRecovery\Api; | ||
|
||
use OPNsense\Base\ApiMutableModelControllerBase; | ||
use OPNsense\Core\Config; | ||
use OPNsense\AutoRecovery\AutoRecovery; | ||
|
||
/** | ||
* Class SettingsController Handles settings related API actions for the AutoRecovery module | ||
* @package OPNsense\AutoRecovery | ||
*/ | ||
class SettingsController extends ApiMutableModelControllerBase | ||
{ | ||
protected static $internalModelName = 'autorecovery'; | ||
protected static $internalModelClass = 'OPNsense\AutoRecovery\AutoRecovery'; | ||
} |
47 changes: 47 additions & 0 deletions
47
.../auto-recovery/src/opnsense/mvc/app/controllers/OPNsense/AutoRecovery/IndexController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2023 Frank Wall | ||
* Copyright (C) 2015 Deciso B.V. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
namespace OPNsense\AutoRecovery; | ||
|
||
/** | ||
* Class IndexController | ||
* @package OPNsense\AutoRecovery | ||
*/ | ||
class IndexController extends \OPNsense\Base\IndexController | ||
{ | ||
public function indexAction() | ||
{ | ||
// pick the template to serve to our users. | ||
$this->view->pick('OPNsense/AutoRecovery/index'); | ||
// fetch form data "general" in | ||
$this->view->generalForm = $this->getForm("general"); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ls/auto-recovery/src/opnsense/mvc/app/controllers/OPNsense/AutoRecovery/forms/general.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<form> | ||
<field> | ||
<label>Configuration</label> | ||
<type>header</type> | ||
</field> | ||
<field> | ||
<id>autorecovery.general.countdown</id> | ||
<label>Countdown in minutes</label> | ||
<type>text</type> | ||
<help>The number of minutes to wait before starting recovery procedures.</help> | ||
</field> | ||
<field> | ||
<id>autorecovery.general.action</id> | ||
<label>Recovery action</label> | ||
<type>dropdown</type> | ||
<help>The recovery action that should be performed.</help> | ||
</field> | ||
<field> | ||
<label>Required Parameters</label> | ||
<type>header</type> | ||
<style>table_configd</style> | ||
</field> | ||
<field> | ||
<id>autorecovery.general.configd_command</id> | ||
<label>System Command</label> | ||
<type>dropdown</type> | ||
<help>Select a pre-defined system command which should be run.</help> | ||
</field> | ||
</form> |
9 changes: 9 additions & 0 deletions
9
sysutils/auto-recovery/src/opnsense/mvc/app/models/OPNsense/AutoRecovery/ACL/ACL.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<acl> | ||
<page-user-autorecovery> | ||
<name>System: Auto Recovery</name> | ||
<patterns> | ||
<pattern>ui/autorecovery/*</pattern> | ||
<pattern>api/autorecovery/*</pattern> | ||
</patterns> | ||
</page-user-autorecovery> | ||
</acl> |
38 changes: 38 additions & 0 deletions
38
sysutils/auto-recovery/src/opnsense/mvc/app/models/OPNsense/AutoRecovery/AutoRecovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2023 Frank Wall | ||
* Copyright (C) 2015 Deciso B.V. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
namespace OPNsense\AutoRecovery; | ||
|
||
use OPNsense\Base\BaseModel; | ||
|
||
class AutoRecovery extends BaseModel | ||
{ | ||
} |
37 changes: 37 additions & 0 deletions
37
sysutils/auto-recovery/src/opnsense/mvc/app/models/OPNsense/AutoRecovery/AutoRecovery.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<model> | ||
<mount>//OPNsense/AutoRecovery</mount> | ||
<version>1.0.0</version> | ||
<description>A configuration rollback functionality for OPNsense</description> | ||
<items> | ||
<general> | ||
<countdown type="IntegerField"> | ||
<default>10</default> | ||
<MinimumValue>1</MinimumValue> | ||
<!-- max value is 7 days --> | ||
<MaximumValue>10080</MaximumValue> | ||
<ValidationMessage>Please specify a value between 1 and 10080 minutes.</ValidationMessage> | ||
<Required>Y</Required> | ||
</countdown> | ||
<action type="OptionField"> | ||
<Required>Y</Required> | ||
<default>restore_reboot</default> | ||
<OptionValues> | ||
<restore_reboot>Restore config and reboot [default]</restore_reboot> | ||
<restore_reload>Restore config and restart all services</restore_reload> | ||
<restore_configd>Restore config and run system command</restore_configd> | ||
<restore>Restore config</restore> | ||
<reboot>Reboot OPNsense</reboot> | ||
<configd>Run system command</configd> | ||
<noop>Do nothing (for testing purpose)</noop> | ||
</OptionValues> | ||
</action> | ||
<configd_command type="ConfigdActionsField"> | ||
<filters> | ||
<description>/(.){1,255}/</description> | ||
</filters> | ||
<ValidationMessage>Select a command from the list.</ValidationMessage> | ||
<Required>N</Required> | ||
</configd_command> | ||
</general> | ||
</items> | ||
</model> |
5 changes: 5 additions & 0 deletions
5
sysutils/auto-recovery/src/opnsense/mvc/app/models/OPNsense/AutoRecovery/Menu/Menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<menu> | ||
<System> | ||
<AutoRecovery VisibleName="Auto Recovery" cssClass="fa fa-history fa-fw" url="/ui/autorecovery"/> | ||
</System> | ||
</menu> |
Oops, something went wrong.