Add ability to hide services table if dedicated module is avail

This commit is contained in:
Ilia Ross
2026-06-13 00:52:47 +02:00
parent 8f8199a4bf
commit 8dd06e3c34
4 changed files with 90 additions and 55 deletions
+1
View File
@@ -1,6 +1,7 @@
line1=Configurable options,11
expert=Allow selection of individual runlevels?,1,1-Yes,0-No
desc=Display actions with descriptions,1,2-Yes, and show all runlevels,1-Yes,0-No
systemd_dedicated=Hide systemd services table?,1,-No,1-Yes
order=Show boot order of actions?,1,1-Yes,0-No
status_check=Show current status of actions,1,2-On index and action pages,1-On action page only,0-No
sort_mode=Sort actions by,1,1-Boot order,0-Name
+66 -54
View File
@@ -329,61 +329,74 @@ elsif ($init_mode eq "upstart" && $access{'bootup'}) {
}
elsif ($init_mode eq "systemd" && $access{'bootup'}) {
# Show systemd actions
print &ui_form_start("mass_systemd.cgi", "post");
@links = ( &select_all_link("d"),
&select_invert_link("d"),
&ui_link("edit_systemd.cgi?new=1", $text{'index_sadd'}) );
print &ui_links_row(\@links);
print &ui_columns_start([ "", $text{'systemd_name'},
$config{'desc'} ? $text{'systemd_desc'} : (),
$text{'systemd_status'},
$text{'systemd_boot'},
$text{'index_ustatus'} ]);
foreach $u (&list_systemd_services()) {
if ($u->{'legacy'}) {
$l = "edit_action.cgi?0+".&urlize($u->{'name'});
}
else {
$l = "edit_systemd.cgi?name=".&urlize($u->{'name'});
}
my $sname = $u->{'name'};
$sname =~ s/\.service$//;
my $title = ($u->{'boot'} == -1 ?
&html_escape($sname) :
&ui_link($l, &html_escape($sname)));
my $desc = $config{'desc'} ? &html_escape($u->{'desc'}) : undef;
print &ui_columns_row([
&ui_checkbox("d", $u->{'name'}, undef),
$title,
$desc // (),
$u->{'fullstatus'} || "<i>$text{'index_unknown'}</i>",
$u->{'boot'} == 1 ?
&ui_text_color("$text{'yes'}", 'success') :
$u->{'boot'} == 2 ?
&ui_text_color("$text{'index_sboot6'}", 'success') :
$u->{'boot'} == -1 ?
&ui_text_color("$text{'index_sboot5'}", 'warn') :
&ui_text_color("$text{'no'}", 'warn'),
$u->{'status'} == 1 ? &ui_text_color("$text{'yes'}", 'success') :
$u->{'status'} == 0 ?
&ui_text_color("$text{'no'}", 'warn') :
"<i>$text{'index_unknown'}</i>",
]);
if (!&init_show_systemd_services()) {
my $systemd_link = &ui_tag('a',
$text{'index_systemd_module'},
{ 'href' => '../systemd/' });
print &ui_alert_box(
&text('index_systemd_dedicated', $systemd_link),
'info', undef, undef, ""),"\n";
}
print &ui_columns_end();
print &ui_links_row(\@links);
print &ui_form_end([ [ "start", $text{'index_start'} ],
[ "stop", $text{'index_stop'} ],
[ "restart", $text{'index_restart'} ],
undef,
[ "addboot", $text{'index_addboot'} ],
[ "delboot", $text{'index_delboot'} ],
undef,
[ "addboot_start", $text{'index_addboot_start'} ],
[ "delboot_stop", $text{'index_delboot_stop'} ],
]);
else {
# Show systemd actions
print &ui_form_start("mass_systemd.cgi", "post");
@links = ( &select_all_link("d"),
&select_invert_link("d"),
&ui_link("edit_systemd.cgi?new=1",
$text{'index_sadd'}) );
print &ui_links_row(\@links);
print &ui_columns_start([ "", $text{'systemd_name'},
$config{'desc'} ?
$text{'systemd_desc'} : (),
$text{'systemd_status'},
$text{'systemd_boot'},
$text{'index_ustatus'} ]);
foreach $u (&list_systemd_services()) {
if ($u->{'legacy'}) {
$l = "edit_action.cgi?0+".&urlize($u->{'name'});
}
else {
$l = "edit_systemd.cgi?name=".&urlize($u->{'name'});
}
my $sname = $u->{'name'};
$sname =~ s/\.service$//;
my $title = ($u->{'boot'} == -1 ?
&html_escape($sname) :
&ui_link($l, &html_escape($sname)));
my $desc = $config{'desc'} ?
&html_escape($u->{'desc'}) : undef;
print &ui_columns_row([
&ui_checkbox("d", $u->{'name'}, undef),
$title,
$desc // (),
$u->{'fullstatus'} || "<i>$text{'index_unknown'}</i>",
$u->{'boot'} == 1 ?
&ui_text_color("$text{'yes'}", 'success') :
$u->{'boot'} == 2 ?
&ui_text_color("$text{'index_sboot6'}", 'success') :
$u->{'boot'} == -1 ?
&ui_text_color("$text{'index_sboot5'}", 'warn') :
&ui_text_color("$text{'no'}", 'warn'),
$u->{'status'} == 1 ? &ui_text_color("$text{'yes'}", 'success') :
$u->{'status'} == 0 ?
&ui_text_color("$text{'no'}", 'warn') :
"<i>$text{'index_unknown'}</i>",
]);
}
print &ui_columns_end();
print &ui_links_row(\@links);
print &ui_form_end([ [ "start", $text{'index_start'} ],
[ "stop", $text{'index_stop'} ],
[ "restart", $text{'index_restart'} ],
undef,
[ "addboot", $text{'index_addboot'} ],
[ "delboot", $text{'index_delboot'} ],
undef,
[ "addboot_start", $text{'index_addboot_start'} ],
[ "delboot_stop", $text{'index_delboot_stop'} ],
]);
}
}
elsif ($init_mode eq "launchd" && $access{'bootup'}) {
# Show launchd agents
@@ -440,4 +453,3 @@ if ($access{'shutdown'}) {
print &ui_buttons_end();
&ui_print_footer("/", $text{'index'});
+21 -1
View File
@@ -3168,8 +3168,11 @@ my @display = ( 'expert', 'desc', 'order', 'status_check', 'sort_mode' );
my @common = ( 'init_mode', 'reboot_command', 'shutdown_command' );
my @sysv = ( @common, 'init_base', 'init_dir', 'order_digits',
'boot_levels', 'local_script', 'local_down', 'inittab_id' );
my @systemd_display = ( 'desc' );
push(@systemd_display, 'systemd_dedicated')
if (&init_dedicated_systemd_module_available());
return ( 'line1', 'desc', 'line2', @common )
return ( 'line1', @systemd_display, 'line2', @common )
if ($mode eq 'systemd');
return ( 'line1', @display, 'line2', @sysv )
if ($mode eq 'init' || $mode eq 'upstart' || $mode eq 'openrc');
@@ -3204,4 +3207,21 @@ if (ref($modconf_order) eq 'ARRAY') {
}
}
# init_dedicated_systemd_module_available()
# Returns 1 if the standalone Systemd module can be used by this Webmin user.
sub init_dedicated_systemd_module_available
{
return &foreign_available("systemd") && &foreign_installed("systemd");
}
# init_show_systemd_services()
# Returns 1 if this module should show its legacy systemd service table.
sub init_show_systemd_services
{
return 1 if (!&init_dedicated_systemd_module_available());
return 0 if ($config{'systemd_dedicated'} &&
$config{'systemd_dedicated'} eq '1');
return 1;
}
1;
+2
View File
@@ -247,6 +247,8 @@ systemd_edesc=Missing unit description
systemd_return=systemd unit
systemd_econf=No systemd unit configuration entered
systemd_estart=Missing commands to run on startup
index_systemd_module=Systemd Services and Units
index_systemd_dedicated=Use the dedicated $1 module to manage systemd services and units. This page now shows only system reboot and shutdown controls.
launchd_title1=Create Launchd Agent
launchd_title2=Edit Launchd Agent