From d7eb312d0ff6be1dcb1ca98f76233db71709981f Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 21 Aug 2024 16:14:40 +0200 Subject: [PATCH] guardian.cgi: Use the new service widget Signed-off-by: Michael Tremer --- html/cgi-bin/guardian.cgi | 115 +++++--------------------------------- 1 file changed, 15 insertions(+), 100 deletions(-) diff --git a/html/cgi-bin/guardian.cgi b/html/cgi-bin/guardian.cgi index 8ffe57f11..9441ac53b 100644 --- a/html/cgi-bin/guardian.cgi +++ b/html/cgi-bin/guardian.cgi @@ -93,10 +93,6 @@ my $errormessage = ''; # Get GUI values. &Header::getcgihash(\%settings); -# Check if guardian is running and grab some stats. -&daemonstats(); -my $pid = $pid[0]; - ## Perform input checks and save settings. # if ($settings{'ACTION'} eq $Lang::tr{'save'}) { @@ -191,11 +187,8 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) { &GenerateIgnoreFile(); } - # Check if guardian is running. - if ($pid > 0) { - # Send reload command through socket connection. - &Guardian::Socket::Client("reload-ignore-list"); - } + # Send reload command through socket connection. + &Guardian::Socket::Client("reload-ignore-list"); ## Toggle Enabled/Disabled for an existing entry on the ignore list. # @@ -233,11 +226,8 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) { # Regenerate the ignore file. &GenerateIgnoreFile(); - # Check if guardian is running. - if ($pid > 0) { - # Send reload command through socket connection. - &Guardian::Socket::Client("reload-ignore-list"); - } + # Send reload command through socket connection. + &Guardian::Socket::Client("reload-ignore-list"); } ## Remove entry from ignore list. @@ -260,11 +250,8 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) { # Regenerate the ignore file. &GenerateIgnoreFile(); - # Check if guardian is running. - if ($pid > 0) { - # Send reload command through socket connection. - &Guardian::Socket::Client("reload-ignore-list"); - } + # Send reload command through socket connection. + &Guardian::Socket::Client("reload-ignore-list"); ## Block a user given address or subnet. # @@ -355,11 +342,7 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) { # Call functions to generate whole page. &showMainBox(); &showIgnoreBox(); - -# Display area only if guardian is running. -if ( ($memory != 0) && ($pid > 0) ) { - &showBlockedBox(); -} +&showBlockedBox(); # Function to display the status of guardian and allow base configuration. sub showMainBox() { @@ -437,54 +420,15 @@ sub showMainBox() { END + &Header::opensection(); + &Header::ServiceStatus({ + $Lang::tr{'guardian service'} => { + "process" => "guardian", + } + }); - # Draw current guardian state. - &Header::openbox('100%', 'center', $Lang::tr{'guardian'}); - - # Get current status of guardian. - &daemonstats(); - $pid = $pid[0]; - - # Display some useful information related to guardian, if daemon is running. - if ( ($memory != 0) && ($pid > 0) ){ - print < - - $Lang::tr{'guardian service'} - - - $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{'guardian service'} - - - $Lang::tr{'guardian daemon'} - $Lang::tr{'stopped'} - - -END - } - - &Header::closebox(); + &Header::closesection(); # Draw elements for guardian configuration. &Header::openbox('100%', 'center', $Lang::tr{'guardian configuration'}); @@ -801,29 +745,6 @@ END &Header::closebigbox(); &Header::closepage(); -# Function to check if guardian has been started. -# Grab process id and consumed memory if the daemon is running. -sub daemonstats() { - $memory = 0; - # for pid and memory - open(FILE, '/usr/local/bin/addonctrl guardian status | '); - @guardian = ; - close(FILE); - $string = join("", @guardian); - $string =~ s/[a-z_]//gi; - $string =~ s/\[[0-1]\;[0-9]+//gi; - $string =~ s/[\(\)\.]//gi; - $string =~ s/ //gi; - $string =~ s/\e//gi; - @pid = split(/\s/,$string); - if (open(FILE, "/proc/$pid[0]/statm")){ - my $temp = ; - @memory = split(/ /,$temp); - close(FILE); - } - $memory+=$memory[0]; -} - sub GetBlockedHosts() { # Create new, empty array. my @hosts; @@ -935,13 +856,7 @@ sub BuildConfiguration() { # Check if guardian should be started or stopped. if($settings{'GUARDIAN_ENABLED'} eq 'on') { - if($pid > 0) { - # Send reload command through socket connection. - &Guardian::Socket::Client("reload"); - } else { - # Launch guardian. - &General::system("/usr/local/bin/addonctrl", "guardian", "start"); - } + &General::system("/usr/local/bin/addonctrl", "guardian", "restart"); } else { # Stop the daemon. &General::system("/usr/local/bin/addonctrl", "guardian", "stop"); -- 2.39.5