From 3f32516c59a2b39f1ea2010e88ac3ad42ec5d312 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 25 Dec 2017 16:55:05 +0100 Subject: [PATCH] databases/redis: use new mutable service controller --- .../OPNsense/Redis/Api/ServiceController.php | 116 +------------ .../OPNsense/Redis/Api/SettingsController.php | 45 +++-- .../app/models/OPNsense/Redis/Menu/Menu.xml | 6 +- .../mvc/app/views/OPNsense/Redis/index.volt | 156 +++++++++--------- 4 files changed, 105 insertions(+), 218 deletions(-) diff --git a/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/ServiceController.php b/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/ServiceController.php index d0e8da63f..fbc7e6219 100644 --- a/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/ServiceController.php +++ b/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/ServiceController.php @@ -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'; } diff --git a/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/SettingsController.php b/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/SettingsController.php index 02338d507..9a76825c3 100644 --- a/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/SettingsController.php +++ b/databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/Api/SettingsController.php @@ -1,35 +1,34 @@ - - - + + + diff --git a/databases/redis/src/opnsense/mvc/app/views/OPNsense/Redis/index.volt b/databases/redis/src/opnsense/mvc/app/views/OPNsense/Redis/index.volt index 93c77a716..96d80e251 100644 --- a/databases/redis/src/opnsense/mvc/app/views/OPNsense/Redis/index.volt +++ b/databases/redis/src/opnsense/mvc/app/views/OPNsense/Redis/index.volt @@ -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. + #}