mirror of
https://github.com/opnsense/plugins.git
synced 2025-12-10 19:52:23 -06:00
net/redis: add Redis Server (#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
This commit is contained in:
parent
d5f0ddbd05
commit
b8ca2c76d1
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ PAGER?= less
|
|||||||
all:
|
all:
|
||||||
@cat ${.CURDIR}/README.md | ${PAGER}
|
@cat ${.CURDIR}/README.md | ${PAGER}
|
||||||
|
|
||||||
CATEGORIES= devel dns net-mgmt net mail security sysutils www
|
CATEGORIES= databases devel dns net-mgmt net mail security sysutils www
|
||||||
|
|
||||||
.for CATEGORY in ${CATEGORIES}
|
.for CATEGORY in ${CATEGORIES}
|
||||||
_${CATEGORY}!= ls -1d ${CATEGORY}/*
|
_${CATEGORY}!= ls -1d ${CATEGORY}/*
|
||||||
|
|||||||
@ -28,6 +28,7 @@ A list of currently available plugins
|
|||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
```
|
```
|
||||||
|
databases/redis -- Redis DB
|
||||||
devel/debug -- Debugging Tools
|
devel/debug -- Debugging Tools
|
||||||
devel/helloworld -- A sample framework application
|
devel/helloworld -- A sample framework application
|
||||||
dns/dyndns -- Dynamic DNS Support
|
dns/dyndns -- Dynamic DNS Support
|
||||||
|
|||||||
7
databases/redis/Makefile
Normal file
7
databases/redis/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
PLUGIN_NAME= redis
|
||||||
|
PLUGIN_VERSION= 0.0.1
|
||||||
|
PLUGIN_COMMENT= Redis DB
|
||||||
|
PLUGIN_DEPENDS= redis
|
||||||
|
PLUGIN_MAINTAINER= franz.fabian.94@gmail.com
|
||||||
|
|
||||||
|
.include "../../Mk/plugins.mk"
|
||||||
19
databases/redis/pkg-descr
Normal file
19
databases/redis/pkg-descr
Normal file
@ -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/
|
||||||
56
databases/redis/src/etc/inc/plugins.inc.d/redis.inc
Normal file
56
databases/redis/src/etc/inc/plugins.inc.d/redis.inc
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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';
|
||||||
|
}
|
||||||
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
<form>
|
||||||
|
<tab id="redis-general" description="General Settings">
|
||||||
|
<subtab id="redis-general-settings" description="General Redis Settings">
|
||||||
|
<field>
|
||||||
|
<id>redis.general.enabled</id>
|
||||||
|
<label>Enable Redis</label>
|
||||||
|
<type>checkbox</type>
|
||||||
|
<help>Enable or disable the Redis service.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.listen</id>
|
||||||
|
<label>Listen Interfaces</label>
|
||||||
|
<type>select_multiple</type>
|
||||||
|
<style>selectpicker</style>
|
||||||
|
<help>Let the Redis server listen on non localhost interfaces.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.protected_mode</id>
|
||||||
|
<label>Enable Protected Mode</label>
|
||||||
|
<type>checkbox</type>
|
||||||
|
<help>Reject Connections from other IP addresses than ::1 and 127.0.0.1.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.port</id>
|
||||||
|
<label>TCP Listen Port</label>
|
||||||
|
<type>text</type>
|
||||||
|
<help>Enter a valid TCP port or 0 to disable the TCP port.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.log_level</id>
|
||||||
|
<label>Log Level</label>
|
||||||
|
<type>dropdown</type>
|
||||||
|
<help>Select how detailed the logs should be debug is the most verbose setting.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.syslog_enabled</id>
|
||||||
|
<label>Enable Syslog</label>
|
||||||
|
<type>checkbox</type>
|
||||||
|
<help>Enable Syslog logging.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.syslog_facility</id>
|
||||||
|
<label>Syslog Facility</label>
|
||||||
|
<type>dropdown</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.general.databases</id>
|
||||||
|
<label>Database Count</label>
|
||||||
|
<type>text</type>
|
||||||
|
<help>The number of databases you would like to have.</help>
|
||||||
|
</field>
|
||||||
|
</subtab>
|
||||||
|
</tab>
|
||||||
|
<tab id="redis-restrictions" description="Restrictions">
|
||||||
|
<subtab id="redis-restrictions-security" description="Security Settings">
|
||||||
|
<field>
|
||||||
|
<id>redis.security.password</id>
|
||||||
|
<label>Server Password</label>
|
||||||
|
<type>text</type>
|
||||||
|
<help>Choose a secure value. It is recommended that you generate this password.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.security.disable_commands</id>
|
||||||
|
<label>Disable Commands</label>
|
||||||
|
<type>select_multiple</type>
|
||||||
|
<style>tokenize</style>
|
||||||
|
<allownew>true</allownew>
|
||||||
|
<help>The commands here will be disabled and cannot be used anymore.</help>
|
||||||
|
</field>
|
||||||
|
</subtab>
|
||||||
|
<subtab id="redis-restrictions-limits" description="Limits">
|
||||||
|
<field>
|
||||||
|
<id>redis.limits.maxclients</id>
|
||||||
|
<label>Maximum Clients</label>
|
||||||
|
<type>text</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.limits.maxmemory</id>
|
||||||
|
<label>Maximum Memory</label>
|
||||||
|
<type>text</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.limits.maxmemory_policy</id>
|
||||||
|
<label>Maximum Memory Policy</label>
|
||||||
|
<type>dropdown</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.limits.maxmemory_samples</id>
|
||||||
|
<label>Maximum Memory Samples</label>
|
||||||
|
<type>text</type>
|
||||||
|
</field>
|
||||||
|
</subtab>
|
||||||
|
</tab>
|
||||||
|
<tab id="redis-performance" description="Performance and Monitoring">
|
||||||
|
<subtab id="redis-performance-slow-transactions" description="Slow Transactions">
|
||||||
|
<field>
|
||||||
|
<id>redis.slowlog.slower_than</id>
|
||||||
|
<label>Log Transactions Slower Than (µS)</label>
|
||||||
|
<type>text</type>
|
||||||
|
<help>0: Log everything, Positive Value: Log events that take longer than specified, Negative Value: Log nothing.</help>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<id>redis.slowlog.max_len</id>
|
||||||
|
<label>Maximum Length</label>
|
||||||
|
<type>text</type>
|
||||||
|
</field>
|
||||||
|
</subtab>
|
||||||
|
</tab>
|
||||||
|
|
||||||
|
<activetab>redis-general-settings</activetab>
|
||||||
|
</form>
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<acl>
|
||||||
|
<page-Redis>
|
||||||
|
<name>redis</name>
|
||||||
|
<patterns>
|
||||||
|
<pattern>ui/redis/*</pattern>
|
||||||
|
<pattern>api/redis/*</pattern>
|
||||||
|
</patterns>
|
||||||
|
</page-Redis>
|
||||||
|
</acl>
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
<menu>
|
||||||
|
<Services>
|
||||||
|
<redis VisibleName="Redis Database" cssClass="fa fa-database fa-fw" url="/ui/redis/" />
|
||||||
|
</Services>
|
||||||
|
</menu>
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use OPNsense\Base\BaseModel;
|
||||||
|
|
||||||
|
class Redis extends BaseModel
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,109 @@
|
|||||||
|
<model>
|
||||||
|
<mount>//OPNsense/redis</mount>
|
||||||
|
<description>Redis DB</description>
|
||||||
|
<items>
|
||||||
|
<general>
|
||||||
|
<enabled type="BooleanField">
|
||||||
|
<default>0</default>
|
||||||
|
<Required>Y</Required>
|
||||||
|
</enabled>
|
||||||
|
<listen type="InterfaceField">
|
||||||
|
<default>1</default>
|
||||||
|
<Required>N</Required>
|
||||||
|
<multiple>Y</multiple>
|
||||||
|
</listen>
|
||||||
|
<protected_mode type="BooleanField">
|
||||||
|
<default>1</default>
|
||||||
|
<Required>Y</Required>
|
||||||
|
</protected_mode>
|
||||||
|
<port type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<MaximumValue>65536</MaximumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
<default>6379</default>
|
||||||
|
<ValidationMessage>This must be a valid port number or 0.</ValidationMessage>
|
||||||
|
</port>
|
||||||
|
<log_level type="OptionField">
|
||||||
|
<Required>Y</Required>
|
||||||
|
<default>warning</default>
|
||||||
|
<OptionValues>
|
||||||
|
<debug>Debug</debug>
|
||||||
|
<verbose>Verbose</verbose>
|
||||||
|
<notice>Notice</notice>
|
||||||
|
<warning>Warning</warning>
|
||||||
|
</OptionValues>
|
||||||
|
</log_level>
|
||||||
|
<syslog_enabled type="BooleanField">
|
||||||
|
<default>0</default>
|
||||||
|
<Required>Y</Required>
|
||||||
|
</syslog_enabled>
|
||||||
|
<syslog_facility type="OptionField">
|
||||||
|
<Required>Y</Required>
|
||||||
|
<default>LOCAL0</default>
|
||||||
|
<OptionValues>
|
||||||
|
<USER>USER</USER>
|
||||||
|
<LOCAL0>LOCAL0</LOCAL0>
|
||||||
|
<LOCAL1>LOCAL1</LOCAL1>
|
||||||
|
<LOCAL2>LOCAL2</LOCAL2>
|
||||||
|
<LOCAL3>LOCAL3</LOCAL3>
|
||||||
|
<LOCAL4>LOCAL4</LOCAL4>
|
||||||
|
<LOCAL5>LOCAL5</LOCAL5>
|
||||||
|
<LOCAL6>LOCAL6</LOCAL6>
|
||||||
|
<LOCAL7>LOCAL7</LOCAL7>
|
||||||
|
</OptionValues>
|
||||||
|
</syslog_facility>
|
||||||
|
<databases type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>Y</Required>
|
||||||
|
<default>16</default>
|
||||||
|
</databases>
|
||||||
|
</general>
|
||||||
|
<security>
|
||||||
|
<password type="TextField">
|
||||||
|
<Required>N</Required>
|
||||||
|
</password>
|
||||||
|
<disable_commands type="CSVListField">
|
||||||
|
</disable_commands>
|
||||||
|
</security>
|
||||||
|
<limits>
|
||||||
|
<maxclients type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
<default>10000</default>
|
||||||
|
</maxclients>
|
||||||
|
<maxmemory type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
</maxmemory>
|
||||||
|
<maxmemory_policy type="OptionField">
|
||||||
|
<Required>Y</Required>
|
||||||
|
<default>noeviction</default>
|
||||||
|
<OptionValues>
|
||||||
|
<noeviction>noeviction</noeviction>
|
||||||
|
<volatile-ttl>volatile-ttl</volatile-ttl>
|
||||||
|
<allkeys-random>allkeys-random</allkeys-random>
|
||||||
|
<volatile-random>volatile-random</volatile-random>
|
||||||
|
<allkeys-lru>allkeys-lru</allkeys-lru>
|
||||||
|
<volatile-lru>volatile-lru</volatile-lru>
|
||||||
|
</OptionValues>
|
||||||
|
</maxmemory_policy>
|
||||||
|
<maxmemory_samples type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
<default>5</default>
|
||||||
|
</maxmemory_samples>
|
||||||
|
</limits>
|
||||||
|
<slowlog>
|
||||||
|
<slower_than type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
<default>10000</default>
|
||||||
|
</slower_than>
|
||||||
|
<max_len type="IntegerField">
|
||||||
|
<MinimumValue>0</MinimumValue>
|
||||||
|
<Required>N</Required>
|
||||||
|
<default>128</default>
|
||||||
|
</max_len>
|
||||||
|
</slowlog>
|
||||||
|
</items>
|
||||||
|
</model>
|
||||||
@ -0,0 +1,148 @@
|
|||||||
|
{#
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
#}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$( 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 {
|
||||||
|
// request service status after successful save and update status box (wait a few seconds before update)
|
||||||
|
setTimeout(function(){
|
||||||
|
ajaxCall(url="/api/redis/service/status", sendData={}, callback=function(data,status) {
|
||||||
|
updateServiceStatusUI(data['status']);
|
||||||
|
});
|
||||||
|
},3000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs" role="tablist" id="maintabs">
|
||||||
|
{% for tab in settings['tabs']|default([]) %}
|
||||||
|
{% if tab['subtabs']|default(false) %}
|
||||||
|
{# Tab with dropdown #}
|
||||||
|
|
||||||
|
{# Find active subtab #}
|
||||||
|
{% set active_subtab="" %}
|
||||||
|
{% for subtab in tab['subtabs']|default({}) %}
|
||||||
|
{% if subtab[0]==settings['activetab']|default("") %}
|
||||||
|
{% set active_subtab=subtab[0] %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<li role="presentation" class="dropdown {% if settings['activetab']|default("") == active_subtab %}active{% endif %}">
|
||||||
|
<a data-toggle="dropdown" href="#" class="dropdown-toggle pull-right visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" role="button" style="border-left: 1px dashed lightgray;">
|
||||||
|
<b><span class="caret"></span></b>
|
||||||
|
</a>
|
||||||
|
<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>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
{# Standard Tab #}
|
||||||
|
<li {% if settings['activetab']|default("") == tab[0] %} class="active" {% endif %}>
|
||||||
|
<a data-toggle="tab" href="#tab_{{ tab[0] }}">
|
||||||
|
<b>{{ tab[1] }}</b>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="content-box tab-content">
|
||||||
|
{% for tab in settings['tabs']|default([]) %}
|
||||||
|
{% if tab['subtabs']|default(false) %}
|
||||||
|
{# Tab with dropdown #}
|
||||||
|
{% for subtab in tab['subtabs']|default({})%}
|
||||||
|
<div id="subtab_{{subtab[0]}}" class="tab-pane fade{% if settings['activetab']|default("") == subtab[0] %} in active {% endif %}">
|
||||||
|
{{ partial("layout_partials/base_form",['fields':subtab[2],'id':'frm_'~subtab[0],'data_title':subtab[1],'apply_btn_id':'save_'~subtab[0]]) }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if tab['subtabs']|default(false)==false %}
|
||||||
|
<div id="tab_{{tab[0]}}" class="tab-pane fade{% if settings['activetab']|default("") == tab[0] %} in active {% endif %}">
|
||||||
|
{{ partial("layout_partials/base_form",['fields':tab[2],'id':'frm_'~tab[0],'apply_btn_id':'save_'~tab[0]]) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
10
databases/redis/src/opnsense/scripts/redis/setup.sh
Executable file
10
databases/redis/src/opnsense/scripts/redis/setup.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
for redis_dir in /var/db/redis /var/log/redis /var/run/redis
|
||||||
|
do
|
||||||
|
mkdir -p $redis_dir
|
||||||
|
chown redis:redis $redis_dir
|
||||||
|
done
|
||||||
|
|
||||||
|
touch /var/log/redis/redis.log
|
||||||
|
chown redis:redis /var/log/redis/redis.log
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
[start]
|
||||||
|
command:/usr/local/opnsense/scripts/redis/setup.sh;/usr/local/etc/rc.d/redis start
|
||||||
|
parameters:
|
||||||
|
type:script
|
||||||
|
message:starting redis
|
||||||
|
|
||||||
|
[stop]
|
||||||
|
command:/usr/local/etc/rc.d/redis onestop
|
||||||
|
parameters:
|
||||||
|
type:script
|
||||||
|
message:stopping redis
|
||||||
|
|
||||||
|
[restart]
|
||||||
|
command:/usr/local/opnsense/scripts/redis/setup.sh;/usr/local/etc/rc.d/redis restart
|
||||||
|
parameters:
|
||||||
|
type:script
|
||||||
|
message:restarting redis
|
||||||
|
|
||||||
|
[status]
|
||||||
|
command:/usr/local/etc/rc.d/redis status;exit 0
|
||||||
|
parameters:
|
||||||
|
type:script_output
|
||||||
|
message:request redis status
|
||||||
|
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
redis.conf:/usr/local/etc/redis.conf
|
||||||
|
redis:/etc/rc.conf.d/redis
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{% if helpers.exists('OPNsense.redis.general.enabled') and OPNsense.redis.general.enabled == '1' %}
|
||||||
|
redis_enable="YES"
|
||||||
|
redis_opnsense_bootup_run="/usr/local/opnsense/scripts/redis/setup.sh"
|
||||||
|
{% else %}
|
||||||
|
redis_enable="NO"
|
||||||
|
{% endif %}
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user