From 14f90afb89b6aba2c09ae0389be8609ba4f5d041 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sun, 7 Jun 2026 16:55:20 +0200 Subject: [PATCH] Fix to cache init mode for menu title selection --- init/index.cgi | 9 ++++- init/init-lib.pl | 97 +++++++++++++++++++++++++++++++-------------- init/lang/en | 1 + init/module.info | 3 +- init/postinstall.pl | 6 +++ 5 files changed, 84 insertions(+), 32 deletions(-) create mode 100755 init/postinstall.pl diff --git a/init/index.cgi b/init/index.cgi index cc2c42d98..27fb89c37 100755 --- a/init/index.cgi +++ b/init/index.cgi @@ -6,8 +6,15 @@ require './init-lib.pl'; require './hostconfig-lib.pl'; &ReadParse(); + +# Save detected mode before rendering, so module.info can use mode-specific desc +&save_init_mode() + if (!-r $init_mode_file && !&is_readonly_mode()); + +# Show the page title with the detected boot system name &ui_print_header(&text('index_mode', &index_boot_system_title()), - $text{'index_title'}, "", undef, 1, 1); + $text{"index_title_$init_mode"} || $text{'index_title'}, + "", undef, 1, 1); if ($init_mode eq "osx" && $access{'bootup'}) { # This hostconfig if block written by Michael A Peters diff --git a/init/init-lib.pl b/init/init-lib.pl index ec4ea71d0..bbfb077f3 100644 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -24,6 +24,9 @@ use WebminCore; 'stop' ); %access = &get_module_acl(); +# File read by module.info alternate description selection +$init_mode_file = "$module_config_directory/mode"; + =head2 init_mode This variable is set based on the bootup system in use. Possible values are : @@ -45,36 +48,7 @@ This variable is set based on the bootup system in use. Possible values are : =item systemd - SystemD, seen on Fedora 16 =cut -if ($config{'init_mode'}) { - $init_mode = $config{'init_mode'}; - } -elsif (&has_command("launchd")) { - $init_mode = "launchd"; - } -elsif ($config{'hostconfig'}) { - $init_mode = "osx"; - } -elsif ($config{'rc_dir'}) { - $init_mode = "rc"; - } -elsif ($config{'init_base'} && -d "/etc/init" && - &has_command("initctl") && - &execute_command("/sbin/init --version") == 0) { - $init_mode = "upstart"; - } -elsif (-d "/etc/systemd" && &has_command("systemctl") && - &execute_command("systemctl list-units") == 0) { - $init_mode = "systemd"; - } -elsif ($config{'init_base'}) { - $init_mode = "init"; - } -elsif ($config{'local_script'}) { - $init_mode = "local"; - } -elsif ($gconfig{'os_type'} eq 'windows') { - $init_mode = "win32"; - } +$init_mode = &detect_init_mode(); # Do init scripts support start and stop custom messages? if ($init_mode eq "init" && $gconfig{'os_type'} =~ /^(osf1|hpux)$/) { @@ -4098,4 +4072,67 @@ if (ref($modconf_order) eq 'ARRAY') { } } +# detect_init_mode([&config]) +# Returns the boot system mode to use for a module config. +sub detect_init_mode +{ +my ($conf) = @_; +$conf ||= \%config; + +if ($conf->{'init_mode'}) { + return $conf->{'init_mode'}; + } +elsif (&has_command("launchd")) { + return "launchd"; + } +elsif ($conf->{'hostconfig'}) { + return "osx"; + } +elsif ($conf->{'rc_dir'}) { + return "rc"; + } +elsif ($conf->{'init_base'} && -d "/etc/init" && + &has_command("initctl") && + &execute_command("/sbin/init --version") == 0) { + return "upstart"; + } +elsif (-d "/etc/systemd" && &has_command("systemctl") && + &execute_command("systemctl list-units") == 0) { + return "systemd"; + } +elsif ($conf->{'init_base'}) { + return "init"; + } +elsif ($conf->{'local_script'}) { + return "local"; + } +elsif ($gconfig{'os_type'} eq 'windows') { + return "win32"; + } +return undef; +} + +# save_init_mode([&config]) +# Save detected init mode for module.info description selection. +sub save_init_mode +{ +my ($conf) = @_; +my %mode; +my $mode = $conf ? &detect_init_mode($conf) : $init_mode; +$mode{'mode'} = $mode if ($mode); +&lock_file($init_mode_file); +&write_file($init_mode_file, \%mode); +&unlock_file($init_mode_file); +unlink("$config_directory/module.infos.cache"); +unlink("$var_directory/module.infos.cache"); +} + +# config_post_save(&new-config, &old-config) +# Called after the module's configuration has been saved. +sub config_post_save +{ +my ($newconfig, $oldconfig) = @_; +&save_init_mode($newconfig); +} + 1; diff --git a/init/lang/en b/init/lang/en index 64d45bd64..11a58fdad 100644 --- a/init/lang/en +++ b/init/lang/en @@ -1,4 +1,5 @@ index_title=Boot and Shutdown Services +index_title_systemd=Systemd Services and Units index_mode=Boot system : $1 index_add=Create a new bootup and shutdown action. index_reboot=Reboot System diff --git a/init/module.info b/init/module.info index 9a4f819d6..6b86e2b98 100644 --- a/init/module.info +++ b/init/module.info @@ -1,7 +1,8 @@ name=Boot Manager category=system os_support=solaris *-linux hpux freebsd unixware openserver openbsd osf1 irix aix macos netbsd windows -desc=Boot and Shutdown Services +desc=Bootup and Shutdown +desc+systemd=Systemd Services and Units depends=proc inittab longdesc=Manage services, scripts and systemd units that start at boot time or stop during shutdown. readonly=1 diff --git a/init/postinstall.pl b/init/postinstall.pl new file mode 100755 index 000000000..f90720964 --- /dev/null +++ b/init/postinstall.pl @@ -0,0 +1,6 @@ +require 'init-lib.pl'; + +sub module_install +{ +&save_init_mode(); +}