From: Stefan Schantl Date: Sun, 5 Aug 2018 12:24:20 +0000 (+0200) Subject: ids.cgi: Display if the IDS is running X-Git-Tag: v2.23-core131~117^2~173^2~20 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=8766096429b7d19a78d632e96a84b32f058f8e80 ids.cgi: Display if the IDS is running Signed-off-by: Stefan Schantl --- diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index 0dce9e994d..0a814f1a11 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -347,8 +347,63 @@ if ($errormessage) { &Header::closebox(); } +# 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'} + + + +
br> +END +} +&Header::closebox(); + +# Draw elements for IDS configuration. +&Header::openbox('100%', 'center', $Lang::tr{'settings'}); + my $rulesdate; # Check if a ruleset allready has been downloaded. @@ -667,3 +722,33 @@ 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 statm file for the given process-id on the pseudo + # file system proc. + if (open(FILE, "/proc/$pid/statm")) { + # Read file content. + my $temp = ; + + # Splitt file content and store in an array. + my @memory = split(/ /,$temp); + + # Close file handle. + close(FILE); + + # Calculate memory usage. + $memory+=$memory[0]; + + # Return memory usage. + return $memory; + } + + # If the file could not be open, return nothing. + return; +} +