web: Create a function to show the service status

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2024-03-23 18:42:13 +01:00
parent b5e6a2c56f
commit 0b16963484
15 changed files with 217 additions and 3 deletions

View File

@@ -97,6 +97,82 @@ sub system($) {
return $rc;
}
sub read_pids($) {
my $pidfile = shift;
# Open the PID file
open(PIDFILE, "<${pidfile}");
# Store all PIDs here
my @pids = ();
# Read all PIDs
while (<PIDFILE>) {
chomp $_;
if (-d "/proc/$_") {
push(@pids, $_);
}
}
# Close the PID file
close(PIDFILE);
return @pids;
}
sub find_pids($) {
my $process = shift;
# Store all PIDs here
my @pids = ();
foreach my $status (</proc/*/status>) {
# Open the status file
open(STATUS, "<${status}");
# Read the status file
while (<STATUS>) {
# If the name does not match, we break the loop immediately
if ($_ =~ m/^Name:\s+(.*)$/) {
last if ($process ne $1);
# Push the PID onto the list
} elsif ($_ =~ m/^Pid:\s+(\d+)$/) {
push(@pids, $1);
# Once we got here, we are done
last;
}
}
# Close the status file
close(STATUS);
}
return @pids;
}
sub get_memory_consumption() {
my $memory = 0;
foreach my $pid (@_) {
# Open the status file or skip on error
open(STATUS, "/proc/${pid}/status") or next;
while (<STATUS>) {
if ($_ =~ m/^VmRSS:\s+(\d+) kB/) {
$memory += $1 * 1024;
last;
}
}
close(STATUS);
}
return $memory;
}
# Function to remove duplicates from an array
sub uniq { my %seen; grep !$seen{$_}++, @_ }

View File

@@ -896,4 +896,92 @@ sub _read_manualpage_hash() {
close($file);
}
sub ServiceStatus() {
my $services = shift;
my %services = %{ $services };
# Write the table header
print <<EOF;
<table class="tbl">
<!-- <thead>
<tr>
<th>
$Lang::tr{'service'}
</th>
<th>
$Lang::tr{'status'}
</th>
<th>
$Lang::tr{'memory'}
</th>
</tr>
</thead> -->
<tbody>
EOF
foreach my $service (sort keys %services) {
my %config = %{ $services{$service} };
my $pidfile = $config{"pidfile"};
my $process = $config{"process"};
# Collect all pids
my @pids = ();
# Read the PID file or go search...
if (defined $pidfile) {
@pids = &General::read_pids("${pidfile}");
} else {
@pids = &General::find_pids("${process}");
}
# Get memory consumption
my $mem = &General::get_memory_consumption(@pids);
print <<EOF;
<tr>
<th scope="row">
$service
</th>
EOF
# Running?
if (scalar @pids) {
# Format memory
$mem = &General::formatBytes($mem);
print <<EOF;
<td class="status is-running">
$Lang::tr{'running'}
</td>
<td class="text-right">
${mem}
</td>
EOF
# Not Running
} else {
print <<EOF;
<td class="status is-stopped" colspan="2">
$Lang::tr{'stopped'}
</td>
EOF
}
print <<EOF;
</tr>
EOF
}
print <<EOF;
</tbody>
</table>
EOF
}
1; # End of package "Header"

View File

@@ -415,7 +415,6 @@ WARNING: translation string unused: installed updates
WARNING: translation string unused: interfaces
WARNING: translation string unused: intrusion detection system log viewer
WARNING: translation string unused: intrusion detection system2
WARNING: translation string unused: intrusion prevention system
WARNING: translation string unused: invalid cache size
WARNING: translation string unused: invalid date entered
WARNING: translation string unused: invalid downlink speed
@@ -960,6 +959,7 @@ WARNING: untranslated string: log drop hostile out = Log dropped packets TO host
WARNING: untranslated string: netbios nameserver daemon = NetBIOS Nameserver Daemon
WARNING: untranslated string: no entries = No entries at the moment.
WARNING: untranslated string: optional = Optional
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: pakfire invalid tree = Invalid repository selected
WARNING: untranslated string: reg_file_data_sampling = Register File Data Sampling (RFDS)
WARNING: untranslated string: regenerate host certificate = Renew Host Certificate

View File

@@ -1103,6 +1103,7 @@ WARNING: untranslated string: internet = INTERNET
WARNING: untranslated string: intrusion detection = Intrusion Prevention
WARNING: untranslated string: intrusion detection system = Intrusion Prevention System
WARNING: untranslated string: intrusion detection system rules = Ruleset
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid broadcast ip = Invalid broadcast IP
WARNING: untranslated string: invalid characters found in pre-shared key = Invalid characters found in pre-shared key.
WARNING: untranslated string: invalid default lease time = Invalid default lease time.
@@ -1455,6 +1456,7 @@ WARNING: untranslated string: ovpn on blue = OpenVPN on BLUE:
WARNING: untranslated string: ovpn on orange = OpenVPN on ORANGE:
WARNING: untranslated string: ovpn on red = OpenVPN on RED:
WARNING: untranslated string: ovpn port in root range = A port number of 1024 or higher is required.
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn routes push = Routes (one per line) e.g. 192.168.10.0/255.255.255.0 192.168.20.0/24
WARNING: untranslated string: ovpn routes push options = Route push options
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log

View File

@@ -460,7 +460,6 @@ WARNING: translation string unused: installed updates
WARNING: translation string unused: interfaces
WARNING: translation string unused: intrusion detection system log viewer
WARNING: translation string unused: intrusion detection system2
WARNING: translation string unused: intrusion prevention system
WARNING: translation string unused: invalid cache size
WARNING: translation string unused: invalid date entered
WARNING: translation string unused: invalid downlink speed
@@ -1022,6 +1021,7 @@ WARNING: untranslated string: log drop hostile out = Log dropped packets TO host
WARNING: untranslated string: no data = unknown string
WARNING: untranslated string: openvpn cert expires soon = Expires Soon
WARNING: untranslated string: openvpn cert has expired = Expired
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: pakfire ago = ago.
WARNING: untranslated string: processors = Processors
WARNING: untranslated string: reg_file_data_sampling = Register File Data Sampling (RFDS)

View File

@@ -443,7 +443,6 @@ WARNING: translation string unused: installed updates
WARNING: translation string unused: interfaces
WARNING: translation string unused: intrusion detection system log viewer
WARNING: translation string unused: intrusion detection system2
WARNING: translation string unused: intrusion prevention system
WARNING: translation string unused: invalid cache size
WARNING: translation string unused: invalid date entered
WARNING: translation string unused: invalid downlink speed
@@ -966,6 +965,7 @@ WARNING: untranslated string: guardian service = unknown string
WARNING: untranslated string: hostile networks total = Total Hostile Networks
WARNING: untranslated string: ids provider eol = (EOL)
WARNING: untranslated string: load average = Load Average
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: pakfire ago = ago.
WARNING: untranslated string: processors = Processors
WARNING: untranslated string: reg_file_data_sampling = Register File Data Sampling (RFDS)

View File

@@ -1131,6 +1131,7 @@ WARNING: untranslated string: incoming overhead in bytes per second = Incoming O
WARNING: untranslated string: info messages = unknown string
WARNING: untranslated string: inodes = Index-Nodes
WARNING: untranslated string: interface mode = Interface
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid input for inactivity timeout = Invalid input for Inactivity Timeout
WARNING: untranslated string: invalid input for interface address = Invalid input for interface address
WARNING: untranslated string: invalid input for interface mode = Invalid input for interface mode
@@ -1216,6 +1217,7 @@ WARNING: untranslated string: outgoing overhead in bytes per second = Outgoing O
WARNING: untranslated string: ovpn add conf = Additional configuration
WARNING: untranslated string: ovpn connection name = Connection Name
WARNING: untranslated string: ovpn error md5 = You host certificate uses MD5 for the signature which is not accepted anymore. <br>Please update to the latest IPFire version and generate a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log
WARNING: untranslated string: ovpn tls auth = TLS Channel Protection:
WARNING: untranslated string: ovpn warning rfc3280 = Your host certificate is not RFC3280 compliant. <br>Please update to the latest IPFire version and generate as soon as possible a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>

View File

@@ -1139,6 +1139,7 @@ WARNING: untranslated string: incoming overhead in bytes per second = Incoming O
WARNING: untranslated string: info messages = unknown string
WARNING: untranslated string: inodes = Index-Nodes
WARNING: untranslated string: interface mode = Interface
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid input for inactivity timeout = Invalid input for Inactivity Timeout
WARNING: untranslated string: invalid input for interface address = Invalid input for interface address
WARNING: untranslated string: invalid input for interface mode = Invalid input for interface mode
@@ -1242,6 +1243,7 @@ WARNING: untranslated string: ovpn connection name = Connection Name
WARNING: untranslated string: ovpn crypt options = Cryptographic options
WARNING: untranslated string: ovpn error md5 = You host certificate uses MD5 for the signature which is not accepted anymore. <br>Please update to the latest IPFire version and generate a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>
WARNING: untranslated string: ovpn ha = Hash algorithm
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log
WARNING: untranslated string: ovpn tls auth = TLS Channel Protection:
WARNING: untranslated string: ovpn warning rfc3280 = Your host certificate is not RFC3280 compliant. <br>Please update to the latest IPFire version and generate as soon as possible a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>

View File

@@ -1280,6 +1280,7 @@ WARNING: untranslated string: info messages = unknown string
WARNING: untranslated string: inodes = Index-Nodes
WARNING: untranslated string: integrity = Integrity:
WARNING: untranslated string: interface mode = Interface
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid input for dpd delay = Invalid input for DPD delay
WARNING: untranslated string: invalid input for dpd timeout = Invalid input for DPD timeout
WARNING: untranslated string: invalid input for inactivity timeout = Invalid input for Inactivity Timeout
@@ -1411,6 +1412,7 @@ WARNING: untranslated string: ovpn ha = Hash algorithm
WARNING: untranslated string: ovpn mgmt in root range = A port number of 1024 or higher is required.
WARNING: untranslated string: ovpn no connections = No active OpenVPN connections
WARNING: untranslated string: ovpn port in root range = A port number of 1024 or higher is required.
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn routes push = Routes (one per line) e.g. 192.168.10.0/255.255.255.0 192.168.20.0/24
WARNING: untranslated string: ovpn routes push options = Route push options
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log

View File

@@ -1276,6 +1276,7 @@ WARNING: untranslated string: info messages = unknown string
WARNING: untranslated string: inodes = Index-Nodes
WARNING: untranslated string: integrity = Integrity:
WARNING: untranslated string: interface mode = Interface
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid input for dpd delay = Invalid input for DPD delay
WARNING: untranslated string: invalid input for dpd timeout = Invalid input for DPD timeout
WARNING: untranslated string: invalid input for inactivity timeout = Invalid input for Inactivity Timeout
@@ -1406,6 +1407,7 @@ WARNING: untranslated string: ovpn ha = Hash algorithm
WARNING: untranslated string: ovpn mgmt in root range = A port number of 1024 or higher is required.
WARNING: untranslated string: ovpn no connections = No active OpenVPN connections
WARNING: untranslated string: ovpn port in root range = A port number of 1024 or higher is required.
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log
WARNING: untranslated string: ovpn tls auth = TLS Channel Protection:
WARNING: untranslated string: ovpn warning rfc3280 = Your host certificate is not RFC3280 compliant. <br>Please update to the latest IPFire version and generate as soon as possible a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>

View File

@@ -1071,6 +1071,7 @@ WARNING: untranslated string: ids working = Changes are being applied. Please wa
WARNING: untranslated string: info messages = unknown string
WARNING: untranslated string: inodes = Index-Nodes
WARNING: untranslated string: interface mode = Interface
WARNING: untranslated string: intrusion prevention system = Intrusion Prevention System
WARNING: untranslated string: invalid input for interface address = Invalid input for interface address
WARNING: untranslated string: invalid input for interface mode = Invalid input for interface mode
WARNING: untranslated string: invalid input for interface mtu = Invalid input to interface MTU
@@ -1130,6 +1131,7 @@ WARNING: untranslated string: optional = Optional
WARNING: untranslated string: otp qrcode = OTP QRCode
WARNING: untranslated string: ovpn connection name = Connection Name
WARNING: untranslated string: ovpn error md5 = You host certificate uses MD5 for the signature which is not accepted anymore. <br>Please update to the latest IPFire version and generate a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>
WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server
WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log
WARNING: untranslated string: ovpn tls auth = TLS Channel Protection:
WARNING: untranslated string: ovpn warning rfc3280 = Your host certificate is not RFC3280 compliant. <br>Please update to the latest IPFire version and generate as soon as possible a new root and host certificate.</br><br>All OpenVPN clients needs then to be renewed!</br>

View File

@@ -78,6 +78,7 @@
< notes
< okay
< optional
< ovpn roadwarrior server
< quick control
< random number generator daemon
< regenerate host certificate
@@ -135,6 +136,7 @@
< log drop hostile out
< openvpn cert expires soon
< openvpn cert has expired
< ovpn roadwarrior server
< processors
< regenerate host certificate
< reg_file_data_sampling
@@ -161,6 +163,7 @@
< ids provider eol
< ids unsupported provider
< load average
< ovpn roadwarrior server
< processors
< reg_file_data_sampling
< system time
@@ -531,6 +534,7 @@
< ovpn add conf
< ovpn connection name
< ovpn error md5
< ovpn roadwarrior server
< ovpn rw connection log
< ovpn tls auth
< ovpn warning rfc3280
@@ -1086,6 +1090,7 @@
< ovpn generating the root and host certificates
< ovpn ha
< ovpn reneg sec
< ovpn roadwarrior server
< ovpn rw connection log
< ovpn tls auth
< ovpn warning rfc3280
@@ -1968,6 +1973,7 @@
< ovpn no connections
< ovpn port in root range
< ovpn reneg sec
< ovpn roadwarrior server
< ovpn routes push
< ovpn routes push options
< ovpn rw connection log
@@ -2974,6 +2980,7 @@
< ovpn no connections
< ovpn port in root range
< ovpn reneg sec
< ovpn roadwarrior server
< ovpn rw connection log
< ovpn tls auth
< ovpn warning rfc3280
@@ -3469,6 +3476,7 @@
< otp qrcode
< ovpn connection name
< ovpn error md5
< ovpn roadwarrior server
< ovpn rw connection log
< ovpn tls auth
< ovpn warning rfc3280

View File

@@ -5247,6 +5247,15 @@ END
$activeonrun = "disabled='disabled'";
}
&Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'});
# Show the service status
&Header::ServiceStatus({
$Lang::tr{'ovpn roadwarrior server'} => {
"process" => "openvpn",
"pidfile" => "/var/run/openvpn.pid",
}
});
print <<END;
<table width='100%' border='0'>
<form method='post'>

View File

@@ -133,6 +133,22 @@ iframe {
float: right !important;
}
/*
Text Alignment
*/
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
/* Header */
#header {
@@ -296,6 +312,10 @@ table {
border-spacing: 0;
}
.tbl {
width: 100%;
}
.tbl th {
color: #ffffff;
border-top: 1px solid #363636;

View File

@@ -2044,6 +2044,7 @@
'ovpn on red' => 'OpenVPN on RED:',
'ovpn port in root range' => 'A port number of 1024 or higher is required.',
'ovpn reneg sec' => 'Session key lifetime:',
'ovpn roadwarrior server' => 'OpenVPN Roadwarrior Server',
'ovpn routes push' => 'Routes (one per line) e.g. 192.168.10.0/255.255.255.0 192.168.20.0/24',
'ovpn routes push options' => 'Route push options',
'ovpn rw connection log' => 'OpenVPN Roadwarrior Connections Log',