mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 14:13:29 +00:00
Add cat_systemd sub to parse systemd unit config
This commit is contained in:
@@ -2550,6 +2550,44 @@ if ($init_mode eq "systemd") {
|
||||
return wantarray ? (-1, undef) : 0;
|
||||
}
|
||||
|
||||
=head2 cat_systemd(unit)
|
||||
|
||||
List given systemd unit file contents
|
||||
|
||||
=cut
|
||||
|
||||
sub cat_systemd
|
||||
{
|
||||
my ($unit) = @_;
|
||||
my @config;
|
||||
my $current_section;
|
||||
my $current_file;
|
||||
|
||||
# Execute and parse the system command
|
||||
&open_execute_command(*CAT, "systemctl cat ".quotemeta($unit), 1, 1);
|
||||
while (<CAT>) {
|
||||
s/\r|\n//g;
|
||||
next if /^$/;
|
||||
if (/^#\s+(\/.*)$/) {
|
||||
# File name line, e.g., # /usr/lib/systemd/system/ssh.socket
|
||||
$current_file = $1;
|
||||
push @config, { file => $current_file, sections => {} };
|
||||
}
|
||||
elsif (/^\[(.+?)\]$/) {
|
||||
# Section header, e.g., [Unit]
|
||||
$current_section = $1;
|
||||
$config[-1]{'sections'}{$current_section} ||= {};
|
||||
}
|
||||
elsif (/^([^=]+)=(.*)$/ && $current_section) {
|
||||
# Key-value pair, e.g., ListenStream=0.0.0.0:22
|
||||
my ($key, $value) = ($1, $2);
|
||||
push @{ $config[-1]{'sections'}{$current_section}{$key} }, $value;
|
||||
}
|
||||
}
|
||||
close(CAT);
|
||||
return \@config;
|
||||
}
|
||||
|
||||
=head2 reboot_system
|
||||
|
||||
Immediately reboots the system.
|
||||
|
||||
Reference in New Issue
Block a user