From: Michael Tremer Date: Sat, 23 Mar 2024 18:16:48 +0000 (+0100) Subject: ids.cgi: Use new services function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fb09506ae1682adc2e12bd4ffe5ad438197da2d;p=people%2Fmfischer%2Fipfire-2.x.git ids.cgi: Use new services function Signed-off-by: Michael Tremer --- diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index 8ace30b02..d44ce1788 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -1005,53 +1005,11 @@ sub show_mainpage() { # Draw current state of the IDS &Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'}); - # Check if the IDS is running and obtain the process-id. - my $pid = &IDS::ids_is_running(); - - # Display some useful information, if suricata daemon is running. - if ($pid) { - # Gather used memory. - my $memory = &get_memory_usage($pid); - - print < - - $Lang::tr{'intrusion detection'} - - - - $Lang::tr{'guardian daemon'} - $Lang::tr{'running'} - - - - - PID - $Lang::tr{'memory'} - - - - - $pid - $memory KB - - -END - } else { - # Otherwise display a hint that the service is not launched. - print < - - $Lang::tr{'intrusion detection'} - - - - $Lang::tr{'guardian daemon'} - $Lang::tr{'stopped'} - - -END - } + &Header::ServiceStatus({ + $Lang::tr{'intrusion prevention system'} => { + "process" => "suricata", + }, + }); # Only show this area, if at least one ruleset provider is configured. if (%used_providers) { @@ -1998,45 +1956,6 @@ sub readrulesfile ($) { } } -# -## Function to get the used memory of a given process-id. -# -sub get_memory_usage($) { - my ($pid) = @_; - - my $memory = 0; - - # Try to open the status file for the given process-id on the pseudo - # file system proc. - if (open(FILE, "/proc/$pid/status")) { - # Loop through the entire file. - while () { - # Splitt current line content and store them into variables. - my ($key, $value) = split(":", $_, 2); - - # Check if the current key is the one which contains the memory usage. - # The wanted one is VmRSS which contains the Real-memory (resident set) - # of the entire process. - if ($key eq "VmRSS") { - # Found the memory usage add it to the memory variable. - $memory += $value; - - # Break the loop. - last; - } - } - - # Close file handle. - close(FILE); - - # Return memory usage. - return $memory; - } - - # If the file could not be open, return nothing. - return; -} - # ## Function to get the provider handle by a given ID. #