From: Kyle Willmon <kylewillmon@gmail.com>
Date: Mon, 26 Dec 2011 01:57:17 -0600
Subject: Add SYNC_PROXY_SERVER configuration option

Patch submitted by Corey Smith
---
 DenyHosts/sync.py |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

--- a/DenyHosts/sync.py
+++ b/DenyHosts/sync.py
@@ -1,7 +1,8 @@
 import logging
 import os
 import time
-from xmlrpclib import ServerProxy
+from xmlrpclib import ServerProxy, Transport
+from httplib import HTTP
 
 from constants import SYNC_TIMESTAMP, SYNC_HOSTS, SYNC_HOSTS_TMP, SYNC_RECEIVED_HOSTS
 
@@ -14,6 +15,21 @@
     else:
         return ""
 
+class ProxiedTransport(Transport):
+    def set_proxy(self, proxy):
+        self.proxy = proxy
+
+    def make_connection(self, host):
+        self.realhost = host
+        h = HTTP(self.proxy)
+        return h
+
+    def send_request(self, connection, handler, request_body):
+        connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
+
+    def send_host(self, connection, host):
+        connection.putheader('Host', self.realhost)
+
 class Sync(object):
     def __init__(self, prefs):
         self.__prefs = prefs
@@ -23,7 +39,13 @@
 
     def xmlrpc_connect(self):
         try:
-            self.__server = ServerProxy(self.__prefs.get('SYNC_SERVER'))
+            proxy_server = self.__prefs.get('SYNC_PROXY_SERVER')
+            if proxy_server is None:
+                self.__server = ServerProxy(self.__prefs.get('SYNC_SERVER'))
+            else:
+                p = ProxiedTransport()
+                p.set_proxy(proxy_server)
+                self.__server = ServerProxy(self.__prefs.get('SYNC_SERVER'), transport=p)
             self.__connected = True
         except Exception, e:
             error(str(e))
--- a/DenyHosts/prefs.py
+++ b/DenyHosts/prefs.py
@@ -59,6 +59,7 @@
                        'SYNC_DOWNLOAD': "yes",
                        'SYNC_DOWNLOAD_THRESHOLD': 3,
                        'SYNC_DOWNLOAD_RESILIENCY': '5h',
+                       'SYNC_PROXY_SERVER': None,
                        'PURGE_THRESHOLD': 0,
                        'ALLOWED_HOSTS_HOSTNAME_LOOKUP': 'no',
                        'ETC_DIR': '/etc'}
--- a/denyhosts.conf
+++ b/denyhosts.conf
@@ -608,6 +608,18 @@
 
 #######################################################################
 #
+# SYNC_PROXY_SERVER: HTTP proxy to use when connecting to the
+# SYNC-SERVER
+#
+# To disable using a proxy (the default), do nothing.
+#
+# To enable an HTTP proxy, you must uncomment and edit the following line:
+#SYNC_PROXY_SERVER = http://my.web.proxy:3128
+#
+#######################################################################
+
+#######################################################################
+#
 # SYNC_INTERVAL: the interval of time to perform synchronizations if
 # SYNC_SERVER has been uncommented.  The default is 1 hour.
 # 
