mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
databases/redis: use new mutable service controller
This commit is contained in:
+6
-110
@@ -28,116 +28,12 @@
|
||||
|
||||
namespace OPNsense\Redis\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\Core\Backend;
|
||||
use \OPNsense\Redis\Redis;
|
||||
use OPNsense\Base\ApiMutableServiceControllerBase;
|
||||
|
||||
class ServiceController extends ApiControllerBase
|
||||
class ServiceController extends ApiMutableServiceControllerBase
|
||||
{
|
||||
/**
|
||||
* restart redis service
|
||||
* @return array
|
||||
*/
|
||||
public function restartAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun('redis restart');
|
||||
return array('response' => $response);
|
||||
} else {
|
||||
return array('response' => array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve status of redis
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function statusAction()
|
||||
{
|
||||
$backend = new Backend();
|
||||
$redis = new Redis();
|
||||
$response = $backend->configdRun('redis status');
|
||||
|
||||
if (strpos($response, 'not running') > 0) {
|
||||
if ((string)$redis->general->enabled == 1) {
|
||||
$status = 'stopped';
|
||||
} else {
|
||||
$status = 'disabled';
|
||||
}
|
||||
} elseif (strpos($response, 'is running') > 0) {
|
||||
$status = 'running';
|
||||
} elseif ((string)$redis->general->enabled == 0) {
|
||||
$status = 'disabled';
|
||||
} else {
|
||||
$status = 'unknown';
|
||||
}
|
||||
|
||||
|
||||
return array('status' => $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* reconfigure redis, generate config and reload
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
|
||||
$redis = new Redis();
|
||||
$backend = new Backend();
|
||||
|
||||
$this->stopAction();
|
||||
|
||||
// generate template
|
||||
$backend->configdRun('template reload OPNsense/Redis');
|
||||
|
||||
// (re)start daemon
|
||||
if ((string)$redis->general->enabled == '1') {
|
||||
$this->startAction();
|
||||
}
|
||||
|
||||
return array('status' => 'ok');
|
||||
} else {
|
||||
return array('status' => 'failed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* stop redis service
|
||||
* @return array
|
||||
*/
|
||||
public function stopAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun('redis stop');
|
||||
return array('response' => $response);
|
||||
} else {
|
||||
return array('response' => array());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* start redis service
|
||||
* @return array
|
||||
*/
|
||||
public function startAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun('redis start');
|
||||
return array('response' => $response);
|
||||
} else {
|
||||
return array('response' => array());
|
||||
}
|
||||
}
|
||||
static protected $internalServiceClass = '\OPNsense\Redis\Redis';
|
||||
static protected $internalServiceTemplate = 'OPNsense/Redis';
|
||||
static protected $internalServiceEnabled = 'general.enabled';
|
||||
static protected $internalServiceName = 'redis';
|
||||
}
|
||||
|
||||
+22
-23
@@ -1,35 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2017 Fabian Franz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\Redis\Api;
|
||||
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class SettingsController extends ApiMutableModelControllerBase
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<menu>
|
||||
<Services>
|
||||
<Redis VisibleName="Redis Database" cssClass="fa fa-database fa-fw" url="/ui/redis/" />
|
||||
</Services>
|
||||
<Services>
|
||||
<Redis cssClass="fa fa-database fa-fw" url="/ui/redis/" />
|
||||
</Services>
|
||||
</menu>
|
||||
|
||||
@@ -1,94 +1,86 @@
|
||||
{#
|
||||
# Copyright (C) 2017 Fabian Franz
|
||||
# Copyright (C) 2014-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:
|
||||
|
||||
Copyright (C) 2017 Fabian Franz
|
||||
OPNsense® is Copyright © 2014 – 2015 by 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.
|
||||
|
||||
|
||||
#}
|
||||
# 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.
|
||||
#}
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
var data_get_map = {'frm_redis':'/api/redis/settings/get'};
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
var data_get_map = {'frm_redis':'/api/redis/settings/get'};
|
||||
|
||||
// load initial data
|
||||
mapDataToFormUI(data_get_map).done(function(){
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
// request service status on load and update status box
|
||||
ajaxCall(url="/api/redis/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
});
|
||||
|
||||
// update history on tab state and implement navigation
|
||||
if(window.location.hash != "") {
|
||||
$('a[href="' + window.location.hash + '"]').click()
|
||||
}
|
||||
$('.nav-tabs a').on('shown.bs.tab', function (e) {
|
||||
history.pushState(null, null, e.target.hash);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// form save event handlers for all defined forms
|
||||
$('[id*="save_"]').each(function(){
|
||||
$(this).click(function() {
|
||||
var frm_id = $(this).closest("form").attr("id");
|
||||
var frm_title = $(this).closest("form").attr("data-title");
|
||||
// save data for General TAB
|
||||
saveFormToEndpoint(url="/api/redis/settings/set", formid=frm_id, callback_ok=function(){
|
||||
// on correct save, perform reconfigure. set progress animation when reloading
|
||||
$("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse");
|
||||
|
||||
ajaxCall(url="/api/redis/service/reconfigure", sendData={}, callback=function(data,status){
|
||||
// when done, disable progress animation.
|
||||
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
|
||||
if (status != "success" || data['status'] != 'ok' ) {
|
||||
// fix error handling
|
||||
BootstrapDialog.show({
|
||||
type:BootstrapDialog.TYPE_WARNING,
|
||||
title: frm_title,
|
||||
message: JSON.stringify(data),
|
||||
draggable: true
|
||||
});
|
||||
} else {
|
||||
ajaxCall(url="/api/redis/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// load initial data
|
||||
mapDataToFormUI(data_get_map).done(function(){
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
// request service status on load and update status box
|
||||
ajaxCall(url="/api/redis/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
});
|
||||
|
||||
// update history on tab state and implement navigation
|
||||
if(window.location.hash != "") {
|
||||
$('a[href="' + window.location.hash + '"]').click()
|
||||
}
|
||||
$('.nav-tabs a').on('shown.bs.tab', function (e) {
|
||||
history.pushState(null, null, e.target.hash);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// form save event handlers for all defined forms
|
||||
$('[id*="save_"]').each(function(){
|
||||
$(this).click(function() {
|
||||
var frm_id = $(this).closest("form").attr("id");
|
||||
var frm_title = $(this).closest("form").attr("data-title");
|
||||
// save data for General TAB
|
||||
saveFormToEndpoint(url="/api/redis/settings/set", formid=frm_id, callback_ok=function(){
|
||||
// on correct save, perform reconfigure. set progress animation when reloading
|
||||
$("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse");
|
||||
|
||||
ajaxCall(url="/api/redis/service/reconfigure", sendData={}, callback=function(data,status){
|
||||
// when done, disable progress animation.
|
||||
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
|
||||
if (status != "success" || data['status'] != 'ok' ) {
|
||||
// fix error handling
|
||||
BootstrapDialog.show({
|
||||
type:BootstrapDialog.TYPE_WARNING,
|
||||
title: frm_title,
|
||||
message: JSON.stringify(data),
|
||||
draggable: true
|
||||
});
|
||||
} else {
|
||||
ajaxCall(url="/api/redis/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist" id="maintabs">
|
||||
@@ -111,7 +103,7 @@
|
||||
<a data-toggle="tab" href="#subtab_{{ tab['subtabs'][0][0] }}" class="visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" style="border-right:0px;"><b>{{ tab[1] }}</b></a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
{% for subtab in tab['subtabs']|default({}) %}
|
||||
<li class="{% if settings['activetab']|default("") == subtab[0] %}active{% endif %}"><a data-toggle="tab" href="#subtab_{{subtab[0]}}"><i class="fa fa-check-square"></i> {{ subtab[1] }}</a></li>
|
||||
<li class="{% if settings['activetab']|default("") == subtab[0] %}active{% endif %}"><a data-toggle="tab" href="#subtab_{{subtab[0]}}">{{ subtab[1] }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user