]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
web: Create a function to show the service status
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Mar 2024 17:42:13 +0000 (18:42 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Mar 2024 17:42:13 +0000 (18:42 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
15 files changed:
config/cfgroot/general-functions.pl
config/cfgroot/header.pl
doc/language_issues.de
doc/language_issues.en
doc/language_issues.es
doc/language_issues.fr
doc/language_issues.it
doc/language_issues.nl
doc/language_issues.pl
doc/language_issues.ru
doc/language_issues.tr
doc/language_missings
html/cgi-bin/ovpnmain.cgi
html/html/themes/ipfire/include/css/style.css
langs/en/cgi-bin/en.pl

index 0a9ab6b7021d96f8348fdd4b404bf2c891b823a0..98c8b9e3699ce1b91968d83ce9068f6da4a8663b 100644 (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{$_}++, @_ }
 
index 184b214bc4bd6a883efcccba1a4b7db96ac7848a..df03cb462e22f8f0d4cf0860b69cf8845cfabda5 100644 (file)
@@ -856,4 +856,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"
index 02e283c9e6e944c4f32ef0953addf6ed5c8586e3..a69b73d8b4805209efa3b031496beff1b766b4e9 100644 (file)
@@ -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
index 01b7cf9b1783b9bcd1ad708c9faeb59aa5c26b5d..8c086d041a181bfd25c8f75746f9193c435c23c4 100644 (file)
@@ -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
index 3b8195a68256b660cd1ac44d934db5f44304b4c0..0fb54957b8bc5376975de36cc5fabe283a6d914c 100644 (file)
@@ -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.
index 91d6348d569a4941138ef38876eb5ceec579302a..eb29151ee6e3f7a57878a816f61e9a957c0ef022 100644 (file)
@@ -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.
index 92185385e457bdddc7bd6667dc57c2d34ebe1173..969144ebdb8e2546d20decfab4c71e4a7e73a1d2 100644 (file)
@@ -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:
index e3a643150d3c843ee5106ff118856ca2df30ee42..73e5b8ecbac4dd5fcfa43536ae16e59f0a90ac1e 100644 (file)
@@ -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:
index 72e4c131d4519181b6f58131f951b9438c853ba4..de67bac798af0b0c8327c99c97bb1b2806c6ab9a 100644 (file)
@@ -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
index 8abbcc84c2c947d9f155403cf838229ea8a8e5ab..e342fe4b472046dce8f80e6062c1c573ea7275b4 100644 (file)
@@ -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:
index e546944a5f7f1cb34b87e3d6050ea99c5be9f9c8..dde29568ed82787e72d5d2767b420364a418a2e1 100644 (file)
@@ -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:
index 090cbecec0b2d1ec90938f8a373c9596e6302a32..795adc693782a0c1dfa5f8df1789fd84f96be436 100644 (file)
@@ -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
 < ovpn fallback cipher
 < ovpn fallback cipher help
 < ovpn no cipher selected
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn unsupported cipher selected
 < regenerate host certificate
 < ovpn fallback cipher
 < ovpn fallback cipher help
 < ovpn no cipher selected
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn unsupported cipher selected
 < system time
 < ovpn fallback cipher
 < ovpn fallback cipher help
 < ovpn no cipher selected
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn rw connection log
 < ovpn tls auth
 < ovpn ha
 < ovpn no cipher selected
 < ovpn reneg sec
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn rw connection log
 < ovpn tls auth
 < ovpn no connections
 < ovpn port in root range
 < ovpn reneg sec
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn routes push
 < ovpn routes push options
 < ovpn no connections
 < ovpn port in root range
 < ovpn reneg sec
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn rw connection log
 < ovpn tls auth
 < ovpn fallback cipher
 < ovpn fallback cipher help
 < ovpn no cipher selected
+< ovpn roadwarrior server
 < ovpn roadwarrior settings
 < ovpn rw connection log
 < ovpn tls auth
index 3186da006cb20cca64d2cc9cd41cdc9b666859bf..ccd02f2b7e34f8968a5884f4186fe60dd64f5735 100755 (executable)
@@ -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 <<END;
     <table width='100%' border='0'>
     <form method='post'>
index 1bf2eba5b246875de52de43e4bbbf739e2ed7031..51c30b73e1435df3ec87d45baf0d34316bc222fb 100644 (file)
@@ -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;
 }
index f091d36e828dae7861121ad088b88bd9bfc98a98..70c56cdfb48fafab6e9a147f08310e15005f77ea 100644 (file)
 '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',