forked from opnsense/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/redis: add Redis Server (opnsense#371)
* add redis * add general to model * temlate: add slowlog etc. * form seem ok * improve menu style * add service controller * select picker: bootstrap style * copy pkg-descr from ports tree * mv redis to db * add category databases and update readme
- Loading branch information
Showing
19 changed files
with
1,830 additions
and
1 deletion.
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
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
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,7 @@ | ||
PLUGIN_NAME= redis | ||
PLUGIN_VERSION= 0.0.1 | ||
PLUGIN_COMMENT= Redis DB | ||
PLUGIN_DEPENDS= redis | ||
PLUGIN_MAINTAINER= [email protected] | ||
|
||
.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,19 @@ | ||
Redis is an open source, advanced key-value store. It is often referred | ||
to as a data structure server since keys can contain strings, hashes, | ||
lists, sets and sorted sets. | ||
|
||
You can run atomic operations on these types, like appending to a string; | ||
incrementing the value in a hash; pushing to a list; computing set | ||
intersection, union and difference; or getting the member with highest | ||
ranking in a sorted set. | ||
|
||
In order to achieve its outstanding performance, Redis works with an | ||
in-memory dataset. Depending on your use case, you can persist it either | ||
by dumping the dataset to disk every once in a while, or by appending each | ||
command to a log. | ||
|
||
Redis also supports trivial-to-setup master-slave replication, with very | ||
fast non-blocking first synchronization, auto-reconnection on net split | ||
and so forth. | ||
|
||
WWW: http://redis.io/ |
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,56 @@ | ||
<?php | ||
|
||
/* | ||
Copyright (C) 2017 Fabian Franz | ||
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. | ||
*/ | ||
|
||
function redis_enabled() | ||
{ | ||
$model = new \OPNsense\Redis\Redis(); | ||
if ((string)$model->general->enabled == '1') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function redis_services() | ||
{ | ||
$services = array(); | ||
|
||
if (redis_enabled()) { | ||
$services[] = array( | ||
'description' => gettext('Redis DB'), | ||
'configd' => array( | ||
'restart' => array('redis restart'), | ||
'start' => array('redis start'), | ||
'stop' => array('redis stop'), | ||
), | ||
'name' => 'redis', | ||
'pidfile' => '/var/run/redis/redis.pid' | ||
); | ||
} | ||
return $services; | ||
} |
139 changes: 139 additions & 0 deletions
139
databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/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,139 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2017 Fabian Franz | ||
* | ||
* 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\Redis\Api; | ||
|
||
use \OPNsense\Base\ApiControllerBase; | ||
use \OPNsense\Core\Backend; | ||
use \OPNsense\Redis\Redis; | ||
|
||
class ServiceController extends ApiControllerBase | ||
{ | ||
|
||
/** | ||
* restart redis service | ||
* @return array | ||
*/ | ||
public function restartAction() | ||
{ | ||
if ($this->request->isPost()) { | ||
$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()) { | ||
$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()) { | ||
$backend = new Backend(); | ||
$response = $backend->configdRun('redis start'); | ||
return array('response' => $response); | ||
} else { | ||
return array('response' => array()); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/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,38 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2017 Fabian Franz | ||
* | ||
* 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\Redis\Api; | ||
|
||
use \OPNsense\Base\ApiMutableModelControllerBase; | ||
|
||
class SettingsController extends ApiMutableModelControllerBase | ||
{ | ||
static protected $internalModelClass = '\OPNsense\Redis\Redis'; | ||
static protected $internalModelName = 'redis'; | ||
} |
46 changes: 46 additions & 0 deletions
46
databases/redis/src/opnsense/mvc/app/controllers/OPNsense/Redis/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,46 @@ | ||
<?php | ||
/* | ||
Copyright (C) 2017 Fabian Franz | ||
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\Redis; | ||
|
||
/** | ||
* Class IndexController | ||
* @package OPNsense/Redis | ||
*/ | ||
class IndexController extends \OPNsense\Base\IndexController | ||
{ | ||
public function indexAction() | ||
{ | ||
$this->view->title = gettext("Redis"); | ||
$this->view->settings = $this->getForm("settings"); | ||
$this->view->pick('OPNsense/Redis/index'); | ||
} | ||
} |
Oops, something went wrong.