Package: denyhosts
Version: 2.3-3
Severity: wishlist
Tags: patch, upstream

denyhosts currently lacks the ability to run in a 'debugging' or
'foreground' mode.  The attached patch adds a --foreground switch to
achieve this.

-- 
Robert Edmonds
[EMAIL PROTECTED]
diff -ru DenyHosts-2.3/DenyHosts/deny_hosts.py 
denyhosts-2.3.foreground/DenyHosts/deny_hosts.py
--- DenyHosts-2.3/DenyHosts/deny_hosts.py       2006-03-30 14:18:47.000000000 
-0500
+++ denyhosts-2.3.foreground/DenyHosts/deny_hosts.py    2006-06-24 
21:08:26.000000000 -0400
@@ -40,7 +40,7 @@
 class DenyHosts:
     def __init__(self, logfile, prefs, lock_file,
                  ignore_offset=0, first_time=0,
-                 noemail=0, daemon=0):
+                 noemail=0, daemon=0, foreground=0):
         self.__denied_hosts = {}
         self.__prefs = prefs
         self.__lock_file = lock_file
@@ -48,6 +48,7 @@
         self.__noemail = noemail
         self.__report = Report(prefs.get("HOSTNAME_LOOKUP"))
         self.__daemon = daemon
+        self.__foreground = foreground
         self.__sync_server = prefs.get('SYNC_SERVER')
         self.__sync_upload = is_true(prefs.get("SYNC_UPLOAD"))
         self.__sync_download = is_true(prefs.get("SYNC_DOWNLOAD"))
@@ -85,7 +86,7 @@
             info("Log file size has not changed.  Nothing to do.")
 
             
-        if daemon:
+        if daemon and not foreground:
             info("launching DenyHosts daemon (version %s)..." % VERSION)
             #logging.getLogger().setLevel(logging.WARN)
 
@@ -99,6 +100,10 @@
                 self.runDaemon(logfile, last_offset)
             else:
                 die("Error creating daemon: %s (%d)" % (retCode[1], 
retCode[0]))
+        elif foreground:
+            info("launching DenyHosts (version %s)..." % VERSION)
+            self.__lock_file.remove()
+            self.runDaemon(logfile, last_offset)
 
 
     def killDaemon(self, signum, frame):
diff -ru DenyHosts-2.3/denyhosts.py denyhosts-2.3.foreground/denyhosts.py
--- DenyHosts-2.3/denyhosts.py  2006-03-11 09:45:51.000000000 -0500
+++ denyhosts-2.3.foreground/denyhosts.py       2006-06-24 21:32:09.000000000 
-0400
@@ -33,6 +33,7 @@
     print " --migrate: migrate your HOSTS_DENY file so that it is suitable for 
--purge"
     print " --purge: expire entries older than your PURGE_DENY setting"
     print " --daemon: run DenyHosts in daemon mode"
+    print " --foreground: run DenyHosts in foreground mode"
     print " --sync: run DenyHosts synchronization mode"
     print " --version: Prints the version of DenyHosts and exits"
     
@@ -62,6 +63,7 @@
     purge = 0
     sync_mode = 0
     daemon = 0
+    foreground = 0
     enable_debug = 0
     upgrade099 = 0
     args = sys.argv[1:]
@@ -69,8 +71,8 @@
         (opts, getopts) = getopt.getopt(args, 'f:c:dinuvps?hV',
                                         ["file=", "ignore", "verbose", 
"debug", 
                                          "help", "noemail", "config=", 
"version",
-                                         "migrate", "purge", "daemon", "sync",
-                                         "upgrade099"])
+                                         "migrate", "purge", "daemon", 
"foreground",
+                                         "sync", "upgrade099"])
     except:
         print "\nInvalid command line option detected."
         usage()
@@ -100,6 +102,8 @@
             sync_mode = 1
         if opt == '--daemon':
             daemon = 1
+        if opt == '--foreground':
+            foreground = 1
         if opt == '--upgrade099':
             upgrade099 = 1
         if opt == '--version':
@@ -130,21 +134,21 @@
 
     lock_file.create()
 
-    if upgrade099 and not daemon:
+    if upgrade099 and not (daemon or foreground):
         if not prefs.get('PURGE_DENY'):
             lock_file.remove()
             die("You have supplied the --upgrade099 flag, however you have not 
set PURGE_DENY in your configuration file")
         else:
             u = UpgradeTo099(prefs.get("HOSTS_DENY"))
 
-    if migrate and not daemon:
+    if migrate and not (daemon or foreground):
         if not prefs.get('PURGE_DENY'):
             lock_file.remove()
             die("You have supplied the --migrate flag however you have not set 
PURGE_DENY in your configuration file.")
         else:
             m = Migrate(prefs.get("HOSTS_DENY"))
 
-    if purge and not daemon:
+    if purge and not (daemon or foreground):
         purge_time = prefs.get('PURGE_DENY')
         if not purge_time:
             lock_file.remove()
@@ -161,7 +165,9 @@
     try:
         for f in logfiles:
             dh = DenyHosts(f, prefs, lock_file, ignore_offset,
-                           first_time, noemail, daemon)
+                           first_time, noemail, daemon, foreground)
+    except KeyboardInterrupt:
+        pass
     except SystemExit, e:
         pass
     except Exception, e:
@@ -169,7 +175,7 @@
         print "\nDenyHosts exited abnormally"
 
 
-    if sync_mode and not daemon:
+    if sync_mode and not (daemon or foreground):
         if not prefs.get('SYNC_SERVER'):
             lock_file.remove()
             die("You have provided the --sync flag however your configuration 
file is missing a value for SYNC_SERVER.")

Attachment: signature.asc
Description: Digital signature

Reply via email to