From 9a2311e88f26016844be9bf50d3197f2a4974ece Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Mon, 4 Mar 2024 22:50:25 +0200 Subject: [PATCH 1/3] Add support for enabling module in postinstall once --- postinstall.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 postinstall.pl diff --git a/postinstall.pl b/postinstall.pl new file mode 100755 index 0000000..0a22734 --- /dev/null +++ b/postinstall.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +our ($module_name, %gconfig); + +do 'virtualmin-htpasswd-lib.pl'; + +sub module_install +{ +# Enable virtualmin-htpasswd module once +if (&virtual_server::plugin_defined("virtualmin-nginx", "start_nginx")) { + if ($virtual_server::config{'plugins'} !~ /$module_name/ && + $virtual_server::config{'plugins_postinstall_enabled'} !~ /$module_name/) { + &virtual_server::lock_file($virtual_server::module_config_file); + $virtual_server::config{'plugins'} .= " $module_name"; + $virtual_server::config{'plugins'} =~ s/^\s+|\s+$//g; + $virtual_server::config{'plugins_postinstall_enabled'} .= " $module_name"; + $virtual_server::config{'plugins_postinstall_enabled'} =~ s/^\s+|\s+$//g; + &virtual_server::save_module_config(\%virtual_server::config, 'virtual-server'); + &virtual_server::unlock_file($virtual_server::module_config_file); + } + } +} + From 16c5b0299a276abd1608126b589871dcf104cc56 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 5 Mar 2024 11:17:51 +0200 Subject: [PATCH 2/3] Fix to just check if plugin is there --- postinstall.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postinstall.pl b/postinstall.pl index 0a22734..0a6b32d 100755 --- a/postinstall.pl +++ b/postinstall.pl @@ -7,7 +7,7 @@ sub module_install { # Enable virtualmin-htpasswd module once -if (&virtual_server::plugin_defined("virtualmin-nginx", "start_nginx")) { +if (&indexof('virtualmin-nginx', @virtual_server::plugins) >= 0) { if ($virtual_server::config{'plugins'} !~ /$module_name/ && $virtual_server::config{'plugins_postinstall_enabled'} !~ /$module_name/) { &virtual_server::lock_file($virtual_server::module_config_file); From d9ff2568e82070c56c3b45a03689112d87a7da87 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Fri, 8 Mar 2024 17:39:54 +0200 Subject: [PATCH 3/3] Fix to use split and join when reading config values --- postinstall.pl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/postinstall.pl b/postinstall.pl index 0a6b32d..c3a2bfa 100755 --- a/postinstall.pl +++ b/postinstall.pl @@ -7,17 +7,18 @@ sub module_install { # Enable virtualmin-htpasswd module once -if (&indexof('virtualmin-nginx', @virtual_server::plugins) >= 0) { - if ($virtual_server::config{'plugins'} !~ /$module_name/ && - $virtual_server::config{'plugins_postinstall_enabled'} !~ /$module_name/) { - &virtual_server::lock_file($virtual_server::module_config_file); - $virtual_server::config{'plugins'} .= " $module_name"; - $virtual_server::config{'plugins'} =~ s/^\s+|\s+$//g; - $virtual_server::config{'plugins_postinstall_enabled'} .= " $module_name"; - $virtual_server::config{'plugins_postinstall_enabled'} =~ s/^\s+|\s+$//g; - &virtual_server::save_module_config(\%virtual_server::config, 'virtual-server'); - &virtual_server::unlock_file($virtual_server::module_config_file); - } +my @p = split(/\s+/, $virtual_server::config{'plugins'}); +my @ppe = split(/\s+/, $virtual_server::config{'plugins_postinstall_enabled'}); +if (&indexof('virtualmin-nginx', @virtual_server::plugins) > -1 && + &indexof($module_name, @p) == -1 && + &indexof($module_name, @ppe) == -1) { + &virtual_server::lock_file($virtual_server::module_config_file); + push(@p, $module_name); + push(@ppe, $module_name); + $virtual_server::config{'plugins'} = join(" ", @p); + $virtual_server::config{'plugins_postinstall_enabled'} = join(" ", @ppe); + &virtual_server::save_module_config(\%virtual_server::config, 'virtual-server'); + &virtual_server::unlock_file($virtual_server::module_config_file); } }