From: Michael Tremer Date: Sat, 23 Mar 2024 17:42:13 +0000 (+0100) Subject: web: Create a function to show the service status X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b19c1312e08f998a9eea87bd66a7ac367a724f1;p=people%2Fms%2Fipfire-2.x.git web: Create a function to show the service status Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 0a9ab6b70..98c8b9e36 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -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 () { + 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 () { + # Open the status file + open(STATUS, "<${status}"); + + # Read the status file + while () { + # 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 () { + 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{$_}++, @_ } diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index 184b214bc..df03cb462 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -856,4 +856,92 @@ sub _read_manualpage_hash() { close($file); } +sub ServiceStatus() { + my $services = shift; + my %services = %{ $services }; + + # Write the table header + print < + + + +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 < + + $service + +EOF + + # Running? + if (scalar @pids) { + # Format memory + $mem = &General::formatBytes($mem); + + print < + $Lang::tr{'running'} + + + + ${mem} + +EOF + + # Not Running + } else { + print < + $Lang::tr{'stopped'} + +EOF + } + + print < +EOF + + } + + print < + +EOF +} + 1; # End of package "Header" diff --git a/doc/language_issues.de b/doc/language_issues.de index 02e283c9e..a69b73d8b 100644 --- a/doc/language_issues.de +++ b/doc/language_issues.de @@ -960,6 +960,7 @@ WARNING: untranslated string: ovpn ciphers = Ciphers WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn unsupported cipher selected = Unknown cipher selected WARNING: untranslated string: pakfire invalid tree = Invalid repository selected diff --git a/doc/language_issues.en b/doc/language_issues.en index 01b7cf9b1..8c086d041 100644 --- a/doc/language_issues.en +++ b/doc/language_issues.en @@ -1467,6 +1467,7 @@ WARNING: untranslated string: ovpn mgmt in root range = A port number of 1024 or WARNING: untranslated string: ovpn no cipher selected = No cipher selected 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 roadwarrior settings = Roadwarrior Settings 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 diff --git a/doc/language_issues.es b/doc/language_issues.es index 3b8195a68..0fb54957b 100644 --- a/doc/language_issues.es +++ b/doc/language_issues.es @@ -1022,6 +1022,7 @@ WARNING: untranslated string: ovpn ciphers = Ciphers WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn unsupported cipher selected = Unknown cipher selected WARNING: untranslated string: pakfire ago = ago. diff --git a/doc/language_issues.fr b/doc/language_issues.fr index 91d6348d5..eb29151ee 100644 --- a/doc/language_issues.fr +++ b/doc/language_issues.fr @@ -966,6 +966,7 @@ WARNING: untranslated string: ovpn ciphers = Ciphers WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn unsupported cipher selected = Unknown cipher selected WARNING: untranslated string: pakfire ago = ago. diff --git a/doc/language_issues.it b/doc/language_issues.it index 92185385e..969144ebd 100644 --- a/doc/language_issues.it +++ b/doc/language_issues.it @@ -1210,6 +1210,7 @@ WARNING: untranslated string: ovpn connection name = Connection Name WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log WARNING: untranslated string: ovpn tls auth = TLS Channel Protection: diff --git a/doc/language_issues.nl b/doc/language_issues.nl index e3a643150..73e5b8ecb 100644 --- a/doc/language_issues.nl +++ b/doc/language_issues.nl @@ -1234,6 +1234,7 @@ WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn ha = Hash algorithm WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log WARNING: untranslated string: ovpn tls auth = TLS Channel Protection: diff --git a/doc/language_issues.pl b/doc/language_issues.pl index 72e4c131d..de67bac79 100644 --- a/doc/language_issues.pl +++ b/doc/language_issues.pl @@ -1400,6 +1400,7 @@ WARNING: untranslated string: ovpn mgmt in root range = A port number of 1024 or WARNING: untranslated string: ovpn no cipher selected = No cipher selected 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 roadwarrior settings = Roadwarrior Settings 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 diff --git a/doc/language_issues.ru b/doc/language_issues.ru index 8abbcc84c..e342fe4b4 100644 --- a/doc/language_issues.ru +++ b/doc/language_issues.ru @@ -1397,6 +1397,7 @@ WARNING: untranslated string: ovpn mgmt in root range = A port number of 1024 or WARNING: untranslated string: ovpn no cipher selected = No cipher selected 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 roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log WARNING: untranslated string: ovpn tls auth = TLS Channel Protection: diff --git a/doc/language_issues.tr b/doc/language_issues.tr index e546944a5..dde29568e 100644 --- a/doc/language_issues.tr +++ b/doc/language_issues.tr @@ -1124,6 +1124,7 @@ WARNING: untranslated string: ovpn connection name = Connection Name WARNING: untranslated string: ovpn fallback cipher = Fallback Cipher WARNING: untranslated string: ovpn fallback cipher help = This cipher is being used by clients that do not support cipher negotiation. WARNING: untranslated string: ovpn no cipher selected = No cipher selected +WARNING: untranslated string: ovpn roadwarrior server = OpenVPN Roadwarrior Server WARNING: untranslated string: ovpn roadwarrior settings = Roadwarrior Settings WARNING: untranslated string: ovpn rw connection log = OpenVPN Roadwarrior Connections Log WARNING: untranslated string: ovpn tls auth = TLS Channel Protection: diff --git a/doc/language_missings b/doc/language_missings index 090cbecec..795adc693 100644 --- a/doc/language_missings +++ b/doc/language_missings @@ -85,6 +85,7 @@ < ovpn fallback cipher < ovpn fallback cipher help < ovpn no cipher selected +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn unsupported cipher selected < quick control @@ -148,6 +149,7 @@ < ovpn fallback cipher < ovpn fallback cipher help < ovpn no cipher selected +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn unsupported cipher selected < regenerate host certificate @@ -179,6 +181,7 @@ < ovpn fallback cipher < ovpn fallback cipher help < ovpn no cipher selected +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn unsupported cipher selected < system time @@ -554,6 +557,7 @@ < ovpn fallback cipher < ovpn fallback cipher help < ovpn no cipher selected +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn rw connection log < ovpn tls auth @@ -1114,6 +1118,7 @@ < ovpn ha < ovpn no cipher selected < ovpn reneg sec +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn rw connection log < ovpn tls auth @@ -2001,6 +2006,7 @@ < ovpn no connections < ovpn port in root range < ovpn reneg sec +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn routes push < ovpn routes push options @@ -3012,6 +3018,7 @@ < ovpn no connections < ovpn port in root range < ovpn reneg sec +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn rw connection log < ovpn tls auth @@ -3512,6 +3519,7 @@ < ovpn fallback cipher < ovpn fallback cipher help < ovpn no cipher selected +< ovpn roadwarrior server < ovpn roadwarrior settings < ovpn rw connection log < ovpn tls auth diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi index 3186da006..ccd02f2b7 100755 --- a/html/cgi-bin/ovpnmain.cgi +++ b/html/cgi-bin/ovpnmain.cgi @@ -5213,6 +5213,15 @@ END $activeonrun = "disabled='disabled'"; } &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn roadwarrior settings'}); + + # Show the service status + &Header::ServiceStatus({ + $Lang::tr{'ovpn roadwarrior server'} => { + "process" => "openvpn", + "pidfile" => "/var/run/openvpn.pid", + } + }); + print <
diff --git a/html/html/themes/ipfire/include/css/style.css b/html/html/themes/ipfire/include/css/style.css index 1bf2eba5b..51c30b73e 100644 --- a/html/html/themes/ipfire/include/css/style.css +++ b/html/html/themes/ipfire/include/css/style.css @@ -1,3 +1,9 @@ +:root { + --color-green : #339933; + --color-green-invert : #ffffff; + --color-red : #993333; + --color-red-invert : #ffffff; +} /* This controls the width of the fixed width layouts */ @@ -122,6 +128,22 @@ iframe { float: right !important; } +/* + Text Alignment +*/ + +.text-left { + text-align: left; +} + +.text-center { + text-align: center; +} + +.text-right { + text-align: right; +} + /* Header */ #header { @@ -284,6 +306,10 @@ table { border-spacing: 0; } +.tbl { + width: 100%; +} + .tbl th { color: #ffffff; border-top: 1px solid #363636; @@ -293,6 +319,10 @@ table { padding-right: 0.5em; } +.tbl th[scope=row] { + text-align: left; +} + .tbl th:first-child { border-left: 1px solid #363636; border-top: 1px solid #363636; @@ -341,6 +371,23 @@ table { border-bottom: 1px solid #363636; } +.tbl .status { + text-align: center; + font-weight: bold; +} + +.tbl .status.is-running { + background-color: var(--color-green); + color: var(--color-green-invert); +} + +.tbl .status.is-stopped { + background-color: var(--color-red); + color: var(--color-red-invert); + + width: 33%; +} + table.fw-nat tbody tr td { height: 2.25em; } diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index f091d36e8..70c56cdfb 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -2049,6 +2049,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 roadwarrior settings' => 'Roadwarrior Settings', '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',