]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
guardian.cgi: Reload guardian if config or the ignorelist changes.
authorStefan Schantl <stefan.schantl@ipfire.org>
Tue, 21 Oct 2014 19:55:07 +0000 (21:55 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 29 Jul 2016 11:17:55 +0000 (13:17 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
html/cgi-bin/guardian.cgi

index 9337e82cb9b8aa2c72f42ed6a8e343934d4fe76d..aacdfca990869cb25259c7cf9f7b0733215b787d 100644 (file)
@@ -72,6 +72,10 @@ 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'}) {
@@ -131,6 +135,12 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
                close(FILE);
        }
 
+       # Check if guardian is running.
+       if ($pid > 0) {
+               # Call guardianctrl to perform a reload.
+               system("/usr/local/bin/guardianctrl reload &>/dev/null");
+       }
+
 ## Remove entry from ignore list.
 #
 } elsif ($settings{'ACTION'} eq $Lang::tr{'remove'}) {
@@ -155,6 +165,12 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
        }
        close(FILE);
 
+       # Check if guardian is running.
+       if ($pid > 0) {
+               # Call guardianctrl to perform a reload.
+               system("/usr/local/bin/guardianctrl reload &>/dev/null");
+       }
+
 ## Block a user given address or subnet.
 #
 } elsif ($settings{'ACTION'} eq $Lang::tr{'block'}) {
@@ -221,7 +237,7 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
 &showIgnoreBox();
 
 # Display area only if guardian is running.
-if ( ($memory != 0) && (@pid[0] ne "///") ) {
+if ( ($memory != 0) && ($pid > 0) ) {
        &showBlockedBox();
 }
 
@@ -259,11 +275,12 @@ sub showMainBox() {
        # Draw current guardian state.
        &Header::openbox('100%', 'center', $Lang::tr{'guardian'});
 
-       # Check if guardian is running and grab some stats.
+       # 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] ne "///") ){
+       if ( ($memory != 0) && ($pid > 0) ){
                print <<END;
                        <table width='95%' cellspacing='0' class='tbl'>
                                <tr>
@@ -620,10 +637,17 @@ sub BuildConfiguration() {
 
        close(FILE);
 
-       # Restart the service.
-       if ($settings{'GUARDIAN_ENABLED'} eq 'on') {
-               system("/usr/local/bin/guardianctrl restart &>/dev/null");
+       # Check if guardian should be started or stopped.
+       if($settings{'GUARDIAN_ENABLED'} eq 'on') {
+               if($pid > 0) {
+                       # Call guardianctl to perform a reload.
+                       system("/usr/local/bin/guardianctrl reload &>/dev/null");
+               } else {
+                       # Launch guardian.
+                       system("/usr/local/bin/guardianctrl start &>/dev/null");
+               }
        } else {
+               # Stop the daemon.
                system("/usr/local/bin/guardianctrl stop &>/dev/null");
        }
 }