Skip to content

Commit

Permalink
support listen on ip
Browse files Browse the repository at this point in the history
  • Loading branch information
rexdf committed Nov 4, 2015
1 parent 5c26ad0 commit ba44003
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,15 @@ class Proxy:
"""
def __init__(self, config):
self.config = config
self.http_server = ThreadedHTTPServer(('',
self.http_server = ThreadedHTTPServer((self.config.listen_ip_address,
self.config.http_listen_port),
ProxyHandler)
self.http_server.config = config
self.http_server.timeout = config.client_timeout
self.http_server.open_logs()

if self.config.https_certificate:
self.https_server = ThreadedHTTPServer(('',
self.https_server = ThreadedHTTPServer((self.config.listen_ip_address,
self.config.https_listen_port),
ProxySSLHandler)
self.https_server.socket = ssl.wrap_socket(self.https_server.socket,
Expand Down Expand Up @@ -803,6 +803,7 @@ def __init__(self):
self.http_endpoint = '/'
self.https_endpoint = '/'
self.rewrites=[]
self.listen_ip_address = ''
self.http_listen_port = 0
self.https_listen_port = 0
self.https_certificate = None
Expand Down Expand Up @@ -850,6 +851,11 @@ def validConfig(self):
"""
if not self.hostname:
return False
if self.listen_ip_address and self.listen_ip_address != 'localhost':
try:
socket.inet_aton(self.listen_ip_address)
except socket.error:
return False
if self.http_listen_port < 1 or self.http_listen_port > 65535 \
or self.https_listen_port < 1 or self.https_listen_port > 65535:
return False
Expand All @@ -867,6 +873,7 @@ def parseConfig(self, fn):
conf.read(fn)
self.conf = conf
self.hostname = conf.get('global', 'hostname').lower()
self.listen_ip_address = conf.get('global', 'listen_ip_address')
self.http_listen_port = conf.getint('global', 'http_listen_port')
self.https_listen_port = conf.getint('global', 'https_listen_port')
self.http_port = conf.getint('global', 'http_port')
Expand Down
3 changes: 3 additions & 0 deletions proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
;; The DNS-address your proxy resides on.
hostname=proxy.example.org

;; The ip to listen on. Normal ipv4 address or empty for all (*), localhost for 127.0.0.1
listen_ip_address=

;; The port to listen on for HTTP. This is the port your users connect
;; to. If you are using a reverse proxy, this is the port your HTTPD
;; should proxy to.
Expand Down

0 comments on commit ba44003

Please sign in to comment.