mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
VPN/IPsec - add enable toggle to connection page
This commit is contained in:
parent
ec06c3cc49
commit
fe65dded8d
@ -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'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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 @@
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-10">
|
||||
<button class="btn btn-primary" id="reconfigureAct"
|
||||
data-endpoint="/api/ipsec/service/reconfigure"
|
||||
data-label="{{ lang._('Apply') }}"
|
||||
@ -159,6 +175,13 @@
|
||||
></button>
|
||||
<br/><br/>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="pull-right">
|
||||
<input name="enable" class="pending" type="checkbox" id="enable"/>
|
||||
<strong>{{ lang._('Enable IPsec') }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="edit_connection" class="tab-pane fade in">
|
||||
<div class="section_header">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user