diff --git a/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/ConnectionsController.php b/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/ConnectionsController.php index 95045af09..bb1864744 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/ConnectionsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/ConnectionsController.php @@ -29,6 +29,7 @@ namespace OPNsense\IPsec\Api; use OPNsense\Base\ApiMutableModelControllerBase; +use OPNsense\Core\Config; /** * Class ConnectionsController @@ -274,4 +275,41 @@ class ConnectionsController extends ApiMutableModelControllerBase { return $this->delBase('children.child', $uuid); } + + /** + * is IPsec enabled + */ + public function isEnabledAction() + { + $this->sessionClose(); + return [ + 'enabled' => isset(Config::getInstance()->object()->ipsec->enable) + ]; + } + + /** + * toggle if IPsec is enabled + */ + public function toggleAction($enabled = null) + { + if ($this->request->isPost()) { + $this->sessionClose(); + Config::getInstance()->lock(); + $config = Config::getInstance()->object(); + if ($enabled == "0" || $enabled == "1") { + $new_status = $enabled == "1"; + } else { + $new_status = !isset($config->ipsec->enable); + } + if ($new_status) { + $config->ipsec->enable = true; + } elseif (isset($config->ipsec->enable)) { + unset($config->ipsec->enable); + } + Config::getInstance()->save(); + return ['status' => 'ok']; + } + return ['status' => 'failed']; + } + } diff --git a/src/opnsense/mvc/app/views/OPNsense/IPsec/connections.volt b/src/opnsense/mvc/app/views/OPNsense/IPsec/connections.volt index f19d28b9a..317e387cd 100644 --- a/src/opnsense/mvc/app/views/OPNsense/IPsec/connections.volt +++ b/src/opnsense/mvc/app/views/OPNsense/IPsec/connections.volt @@ -93,6 +93,22 @@ $("#frm_ConnectionDialog").append($("#frm_DialogConnection").detach()); updateServiceControlUI('ipsec'); + $("#enable").click(function(){ + if (!$(this).hasClass("pending")) { + $(this).addClass("pending"); + let enabled = $("#enable").prop('checked') ? '1' : '0'; + ajaxCall('/api/ipsec/connections/toggle/' + enabled, {}, function (data, status) { + $("#enable").removeClass("pending"); + }); + } + }); + ajaxGet('/api/ipsec/connections/is_enabled', {}, function (data, status) { + if (data.enabled === true) { + $("#enable").prop('checked', data.enabled); + } + $("#enable").removeClass("pending"); + }); + /** * reconfigure */ @@ -150,7 +166,7 @@
-
+


+
+
+ + {{ lang._('Enable IPsec') }} +
+
+