From 3db32b8cfa97bafa0eeaf9d9afe211f0e9b3c9e0 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Tue, 6 Apr 2021 18:34:11 +0300 Subject: [PATCH 1/4] Add ability to override module's info https://github.com/webmin/webmin/issues/1421#issuecomment-772137324 https://github.com/virtualmin/virtualmin-gpl/issues/275 --- mysql/module.overrides | 1 + mysql/mysql-lib.pl | 15 +++++++++++++++ web-lib-funcs.pl | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 mysql/module.overrides diff --git a/mysql/module.overrides b/mysql/module.overrides new file mode 100644 index 000000000..4c8c5c7c4 --- /dev/null +++ b/mysql/module.overrides @@ -0,0 +1 @@ +funcs=override_check_variant \ No newline at end of file diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index 951d4cf58..aa6ac9920 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1879,5 +1879,20 @@ if ($err) { &error_setup($text{'login_err'}); } +# Override function to substitute module's name +sub override_check_variant +{ +my ($rv) = @_; +my $mysql_version; +chop($mysql_version = &read_file_contents( + "$module_config_directory/version")); +$mysql_version ||= &get_mysql_version(); +if ($mysql_version =~ /mariadb/i) { + foreach my $t (keys %{$rv}) { + $rv->{$t} =~ s/MySQL/MariaDB/g; + } + } +} + 1; diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 783a678c8..be7356fe1 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -5619,9 +5619,43 @@ if (defined(&theme_get_module_info)) { %rv = &theme_get_module_info(\%rv, $_[0], $_[1], $_[2]); } +# Apply module overrides +&get_module_overrides($_[0], \%rv); + return %rv; } +=head2 get_module_overrides($mod, \data) + +Checks for module specific overrides if exist in +module.overrides file and executes defined subs + +=cut +sub get_module_overrides +{ +my ($mod, $data) = @_; +return if (!$mod); + +my $mdir = &module_root_directory($mod); + +# Call module specific overrides +if (-r "$mdir/module.overrides" && !$main::get_module_overrides_done++) { + my %overrides; + &read_file_cached("$mdir/module.overrides", \%overrides); + my $funcs = $overrides{'funcs'}; + if ($funcs) { + eval { + local $main::error_must_die = 1; + my @funcs = split(/\s+/, $funcs); + &foreign_require($mod); + foreach my $func (@funcs) { + &foreign_call($mod, $func, \%{$data}); + }; + } + } + } +} + =head2 get_all_module_infos(cachemode) Returns a list contains the information on all modules in this webmin From 575a801c6d1981a84f2f1babc7305d99fe1e47dc Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Tue, 6 Apr 2021 22:19:11 +0300 Subject: [PATCH 2/4] Fix to prevent endless loop on lib auto-detection; force define to -lib.pl file Call module override prior theme overrides --- mysql/mysql-lib.pl | 2 +- web-lib-funcs.pl | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index aa6ac9920..4a52436db 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1881,7 +1881,7 @@ if ($err) { # Override function to substitute module's name sub override_check_variant -{ +{ my ($rv) = @_; my $mysql_version; chop($mysql_version = &read_file_contents( diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index be7356fe1..901ccc614 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -5614,14 +5614,14 @@ if ($rv{'longdesc'}) { $rv{'index_link'} = 'index.cgi'; } +# Apply module overrides +&get_module_overrides($_[0], \%rv); + # Call theme-specific override function if (defined(&theme_get_module_info)) { %rv = &theme_get_module_info(\%rv, $_[0], $_[1], $_[2]); } -# Apply module overrides -&get_module_overrides($_[0], \%rv); - return %rv; } @@ -5639,7 +5639,7 @@ return if (!$mod); my $mdir = &module_root_directory($mod); # Call module specific overrides -if (-r "$mdir/module.overrides" && !$main::get_module_overrides_done++) { +if (-r "$mdir/module.overrides") { my %overrides; &read_file_cached("$mdir/module.overrides", \%overrides); my $funcs = $overrides{'funcs'}; @@ -5647,11 +5647,11 @@ if (-r "$mdir/module.overrides" && !$main::get_module_overrides_done++) { eval { local $main::error_must_die = 1; my @funcs = split(/\s+/, $funcs); - &foreign_require($mod); + &foreign_require($mod, "$mod-lib.pl"); foreach my $func (@funcs) { &foreign_call($mod, $func, \%{$data}); - }; - } + } + }; } } } From f358fa2a98a33bc57575b484cbdf750c3bde02b3 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Fri, 9 Apr 2021 18:58:16 +0300 Subject: [PATCH 3/4] Simplify https://github.com/webmin/webmin/pull/1470#issuecomment-816270694 --- mysql/module.overrides | 1 - mysql/module_overrides.pl | 19 +++++++++++++++++++ mysql/mysql-lib.pl | 15 --------------- web-lib-funcs.pl | 21 +++++++-------------- 4 files changed, 26 insertions(+), 30 deletions(-) delete mode 100644 mysql/module.overrides create mode 100644 mysql/module_overrides.pl diff --git a/mysql/module.overrides b/mysql/module.overrides deleted file mode 100644 index 4c8c5c7c4..000000000 --- a/mysql/module.overrides +++ /dev/null @@ -1 +0,0 @@ -funcs=override_check_variant \ No newline at end of file diff --git a/mysql/module_overrides.pl b/mysql/module_overrides.pl new file mode 100644 index 000000000..8717dcb67 --- /dev/null +++ b/mysql/module_overrides.pl @@ -0,0 +1,19 @@ + +do 'mysql-lib.pl'; + +# Override function to substitute module's name +sub module_overrides +{ +my ($rv) = @_; +my $mysql_version; +chop($mysql_version = &read_file_contents( + "$module_config_directory/version")); +$mysql_version ||= &get_mysql_version(); +if ($mysql_version =~ /mariadb/i) { + foreach my $t (keys %{$rv}) { + $rv->{$t} =~ s/MySQL/MariaDB/g; + } + } +} + +1; \ No newline at end of file diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index 4a52436db..951d4cf58 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1879,20 +1879,5 @@ if ($err) { &error_setup($text{'login_err'}); } -# Override function to substitute module's name -sub override_check_variant -{ -my ($rv) = @_; -my $mysql_version; -chop($mysql_version = &read_file_contents( - "$module_config_directory/version")); -$mysql_version ||= &get_mysql_version(); -if ($mysql_version =~ /mariadb/i) { - foreach my $t (keys %{$rv}) { - $rv->{$t} =~ s/MySQL/MariaDB/g; - } - } -} - 1; diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 901ccc614..6c3b5fde2 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -5639,20 +5639,13 @@ return if (!$mod); my $mdir = &module_root_directory($mod); # Call module specific overrides -if (-r "$mdir/module.overrides") { - my %overrides; - &read_file_cached("$mdir/module.overrides", \%overrides); - my $funcs = $overrides{'funcs'}; - if ($funcs) { - eval { - local $main::error_must_die = 1; - my @funcs = split(/\s+/, $funcs); - &foreign_require($mod, "$mod-lib.pl"); - foreach my $func (@funcs) { - &foreign_call($mod, $func, \%{$data}); - } - }; - } +my $call = 'module_overrides'; +if (-r "$mdir/$call.pl") { + eval { + local $main::error_must_die = 1; + &foreign_require($mod, "$call.pl"); + &foreign_call($mod, $call, \%{$data}); + }; } } From fc638f5d9000b2bf9e12313b5bab212833e8e440 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Sun, 11 Apr 2021 14:28:26 +0300 Subject: [PATCH 4/4] Fix to use already existing hashref --- web-lib-funcs.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 6c3b5fde2..a57bfa520 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -5644,7 +5644,7 @@ if (-r "$mdir/$call.pl") { eval { local $main::error_must_die = 1; &foreign_require($mod, "$call.pl"); - &foreign_call($mod, $call, \%{$data}); + &foreign_call($mod, $call, $data); }; } }