diff --git a/admin/class-nginx-helper-admin.php b/admin/class-nginx-helper-admin.php index 5ecd8bf0..a3987140 100644 --- a/admin/class-nginx-helper-admin.php +++ b/admin/class-nginx-helper-admin.php @@ -281,9 +281,15 @@ public function nginx_helper_default_settings() { 'purge_feeds' => 1, 'redis_hostname' => '127.0.0.1', 'redis_port' => '6379', - 'redis_prefix' => 'nginx-cache:', + 'redis_prefix' => 'nginx-cache:', + 'redis_unix_socket' => '', + 'redis_database' => 0, + 'redis_username' => '', + 'redis_password' => '', 'purge_url' => '', 'redis_enabled_by_constant' => 0, + 'redis_socket_enabled_by_constant' => 0, + 'redis_acl_enabled_by_constant' => 0, 'preload_cache' => 0, 'is_cache_preloaded' => 0 ); @@ -325,6 +331,7 @@ public function nginx_helper_settings() { 'redis_hostname' => '127.0.0.1', 'redis_port' => '6379', 'redis_prefix' => 'nginx-cache:', + 'redis_database' => 0, ) ); @@ -339,17 +346,24 @@ public function nginx_helper_settings() { defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) ); + $data['redis_acl_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_USERNAME') && defined('RT_WP_NGINX_HELPER_REDIS_PASSWORD'); + $data['redis_socket_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET'); + $data['redis_unix_socket'] = $data['redis_socket_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET : $data['redis_unix_socket']; + $data['redis_username'] = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_USERNAME : $data['redis_username']; + $data['redis_password'] = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_PASSWORD : $data['redis_password']; + if ( ! $is_redis_enabled ) { return $data; } - - $data['redis_enabled_by_constant'] = $is_redis_enabled; - $data['enable_purge'] = $is_redis_enabled; - $data['cache_method'] = 'enable_redis'; - $data['redis_hostname'] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; - $data['redis_port'] = RT_WP_NGINX_HELPER_REDIS_PORT; - $data['redis_prefix'] = RT_WP_NGINX_HELPER_REDIS_PREFIX; - + + $data['redis_enabled_by_constant'] = $is_redis_enabled; + $data['enable_purge'] = $is_redis_enabled; + $data['cache_method'] = 'enable_redis'; + $data['redis_hostname'] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; + $data['redis_port'] = RT_WP_NGINX_HELPER_REDIS_PORT; + $data['redis_prefix'] = RT_WP_NGINX_HELPER_REDIS_PREFIX; + $data['redis_database'] = defined('RT_WP_NGINX_HELPER_REDIS_DATABASE') ? RT_WP_NGINX_HELPER_REDIS_DATABASE : 0; + return $data; } diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 10a84831..d4b0f955 100644 --- a/admin/class-phpredis-purger.php +++ b/admin/class-phpredis-purger.php @@ -39,11 +39,32 @@ public function __construct() { try { $this->redis_object = new Redis(); + + $redis_acl = array(); + + $username = $nginx_helper_admin->options['redis_username']; + $password = $nginx_helper_admin->options['redis_password']; + + if( $username && $password ) { + $redis_acl['auth'] = array( $username, $password ); + } + + $hostname = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_hostname'] : $nginx_helper_admin->options['redis_unix_socket']; + $port = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_port'] : 0; + $this->redis_object->connect( - $nginx_helper_admin->options['redis_hostname'], - $nginx_helper_admin->options['redis_port'], - 5 + $hostname, + $port, + 5, + null, + 0, + 0, + $redis_acl ); + + if( $nginx_helper_admin->options['redis_database'] !== 0 ) { + $this->redis_object->select($nginx_helper_admin->options['redis_database']); + } } catch ( Exception $e ) { $this->log( $e->getMessage(), 'ERROR' ); diff --git a/admin/class-predis-purger.php b/admin/class-predis-purger.php index 1290a0de..7f007b49 100644 --- a/admin/class-predis-purger.php +++ b/admin/class-predis-purger.php @@ -37,19 +37,36 @@ public function __construct() { } Predis\Autoloader::register(); - + + $predis_args = array(); + + $username = $nginx_helper_admin->options['redis_username']; + $password = $nginx_helper_admin->options['redis_password']; + + if( empty( $nginx_helper_admin->options['redis_unix_socket'] ) ) { + $predis_args['path'] = $nginx_helper_admin->options['redis_unix_socket']; + } else { + $predis_args['host'] = $nginx_helper_admin->options['redis_hostname'];; + $predis_args['port'] = $nginx_helper_admin->options['redis_port']; + } + + if ( $username && $password ) { + $predis_args['username'] = $username; + $predis_args['password'] = $password; + } + // redis server parameter. - $this->redis_object = new Predis\Client( - array( - 'host' => $nginx_helper_admin->options['redis_hostname'], - 'port' => $nginx_helper_admin->options['redis_port'], - ) - ); + $this->redis_object = new Predis\Client( $predis_args ); try { $this->redis_object->connect(); } catch ( Exception $e ) { $this->log( $e->getMessage(), 'ERROR' ); + return; + } + + if( $nginx_helper_admin->options['redis_database'] !== 0 ) { + $this->redis_object->select($nginx_helper_admin->options['redis_database']); } } diff --git a/admin/css/nginx-helper-admin.css b/admin/css/nginx-helper-admin.css index 0a8856ba..ddf47ce4 100644 --- a/admin/css/nginx-helper-admin.css +++ b/admin/css/nginx-helper-admin.css @@ -4,7 +4,7 @@ */ .clearfix { - *zoom: 1; + zoom: 1; } .clearfix:before, .clearfix:after { @@ -103,3 +103,18 @@ form#purgeall .button-primary:focus { font-size: 13px; margin-left: 23px; } + +.password-input { + padding-right: 40px; +} + +.password-show-hide-btn { + background-color: transparent; + border: 0; + cursor: pointer; + display: inline-block; +} + +.password-wrapper { + display: flex; +} diff --git a/admin/js/nginx-helper-admin.js b/admin/js/nginx-helper-admin.js index 4b3aa006..748ac703 100644 --- a/admin/js/nginx-helper-admin.js +++ b/admin/js/nginx-helper-admin.js @@ -75,6 +75,19 @@ } ); + jQuery('.password-show-hide-btn').on('click', function() { + var passwordInput = $(this).siblings('.password-input'); + var icon = $(this).find('.password-input-icon'); + + if (passwordInput.attr('type') === 'password') { + passwordInput.attr('type', 'text'); + icon.removeClass('dashicons-hidden').addClass('dashicons-visibility'); + } else { + passwordInput.attr('type', 'password'); + icon.removeClass('dashicons-visibility').addClass('dashicons-hidden'); + } + }); + /** * Show OR Hide options on option checkbox * diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index 02eb2229..c3794ea9 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -22,6 +22,12 @@ 'redis_hostname', 'redis_port', 'redis_prefix', + 'redis_database', + 'redis_username', + 'redis_password', + 'redis_unix_socket', + 'redis_socket_enabled_by_constant', + 'redis_acl_enabled_by_constant', 'purge_homepage_on_edit', 'purge_homepage_on_del', 'purge_url', @@ -253,7 +259,7 @@ - /> + /> + '; + esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' ); + echo '

'; + } + ?> - /> + /> + '; + esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' ); + echo '

'; + + } + ?> + + + + + + /> + '; + esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); + echo '

'; + + } + ?> @@ -295,6 +332,55 @@ ?> + + + + /> + '; + esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); + echo '

'; + + } + ?> + + + + + + + /> + '; + esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); + echo '

'; + + } + ?> + + + + + + +
+ /> + +
+ '; + esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); + echo '

'; + + } + ?> + +