From 40d8ef483b16861e9f87500d5362c4e1cd43eb83 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 May 2019 08:42:00 +0200 Subject: [PATCH] databases/redis: add reset db button (#1348) (cherry picked from commit 784f372aa63d4239cdfe985b1187ddcb4be13830) (cherry picked from commit 610131d2c839fd55c9f7a6dfba2cc57e994c2670) --- databases/redis/Makefile | 2 +- databases/redis/pkg-descr | 17 +++++++++++++++++ .../OPNsense/Redis/Api/ServiceController.php | 13 +++++++++++++ .../mvc/app/views/OPNsense/Redis/index.volt | 19 ++++++++++++++++++- .../service/conf/actions.d/actions_redis.conf | 6 ++++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/databases/redis/Makefile b/databases/redis/Makefile index 8d9f84a68..35faf0478 100644 --- a/databases/redis/Makefile +++ b/databases/redis/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= redis -PLUGIN_VERSION= 1.0 +PLUGIN_VERSION= 1.1 PLUGIN_COMMENT= Redis DB PLUGIN_DEPENDS= redis PLUGIN_MAINTAINER= franz.fabian.94@gmail.com diff --git a/databases/redis/pkg-descr b/databases/redis/pkg-descr index e034aa372..3bc510cbc 100644 --- a/databases/redis/pkg-descr +++ b/databases/redis/pkg-descr @@ -16,4 +16,21 @@ Redis also supports trivial-to-setup master-slave replication, with very fast non-blocking first synchronization, auto-reconnection on net split and so forth. + +Plugin Changelog +---------------- + +1.1 + +* Add a button to reset all databases (contributed by Michael Muenz) + +1.0 + +* Allow interface and port selection +* Syslog or file-based logging +* Allow password protection +* Connection limits +* Performance monitoring of slow connections + + WWW: http://redis.io/ 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 059389c76..931a27f45 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 @@ -2,6 +2,7 @@ /* * Copyright (C) 2017 Fabian Franz + * Copyright (C) 2019 Michael Muenz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,6 +30,7 @@ namespace OPNsense\Redis\Api; use OPNsense\Base\ApiMutableServiceControllerBase; +use OPNsense\Core\Backend; class ServiceController extends ApiMutableServiceControllerBase { @@ -36,4 +38,15 @@ class ServiceController extends ApiMutableServiceControllerBase protected static $internalServiceTemplate = 'OPNsense/Redis'; protected static $internalServiceEnabled = 'general.enabled'; protected static $internalServiceName = 'redis'; + + /** + * remove database folder + * @return array + */ + public function resetdbAction() + { + $backend = new Backend(); + $response = $backend->configdRun("redis resetdb"); + return array("response" => $response); + } } 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 05a219f73..bf0bc4d96 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,11 +1,12 @@ {# # Copyright (C) 2017 Fabian Franz # Copyright (C) 2014-2015 Deciso B.V. + # Copyright (C) 2019 Michael Muenz # 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. # @@ -47,6 +48,8 @@ $( document ).ready(function() { history.pushState(null, null, e.target.hash); }); + $('#save_redis-general-settings').after(''); + // form save event handlers for all defined forms $('[id*="save_"]').each(function(){ $(this).click(function() { @@ -78,6 +81,20 @@ $( document ).ready(function() { }); }); }); + $("#resetdbAct").click(function () { + stdDialogConfirm( + '{{ lang._('Confirm database reset') }}', + '{{ lang._('Do you want to reset the database?') }}', + '{{ lang._('Yes') }}', '{{ lang._('Cancel') }}', function () { + $("#resetdbAct_progress").addClass("fa fa-spinner fa-pulse"); + ajaxCall(url="/api/redis/service/resetdb", sendData={}, callback=function(data,status) { + ajaxCall(url="/api/redis/service/reconfigure", sendData={}, callback=function(data,status) { + updateServiceControlUI('redis'); + $("#resetdbAct_progress").removeClass("fa fa-spinner fa-pulse"); + }); + }); + }); + }); }); diff --git a/databases/redis/src/opnsense/service/conf/actions.d/actions_redis.conf b/databases/redis/src/opnsense/service/conf/actions.d/actions_redis.conf index 96b9655c0..f9183fec7 100644 --- a/databases/redis/src/opnsense/service/conf/actions.d/actions_redis.conf +++ b/databases/redis/src/opnsense/service/conf/actions.d/actions_redis.conf @@ -21,3 +21,9 @@ command:/usr/local/etc/rc.d/redis status;exit 0 parameters: type:script_output message:request redis status + +[resetdb] +command:/usr/local/etc/rc.d/redis stop;rm -rf /var/db/redis +parameters: +type:script +message:remove all databases