IPSC proxy basically working with one client

testing
Simon 3 years ago
parent 2562e75eb9
commit 6312699d07

@ -25,6 +25,7 @@ import ipaddress
import os import os
from setproctitle import setproctitle from setproctitle import setproctitle
from datetime import datetime from datetime import datetime
#from ipsc_const import *
# Does anybody read this stuff? There's a PEP somewhere that says I should do this. # Does anybody read this stuff? There's a PEP somewhere that says I should do this.
__author__ = 'Simon Adlem - G7RZU' __author__ = 'Simon Adlem - G7RZU'
@ -68,7 +69,7 @@ class Proxy(DatagramProtocol):
def reaper(self,_peer_id): def reaper(self,_peer_id):
if self.debug: if self.debug:
print("dead",_peer_id) print("dead",_peer_id)
if self.clientinfo and _peer_id != b'\xff\xff\xff\xff': if self.clientinfo:
print(f"{datetime.now().replace(microsecond=0)} Client: ID:{str(int_id(_peer_id)).rjust(9)} IP:{self.peerTrack[_peer_id]['shost'].rjust(15)} Port:{self.peerTrack[_peer_id]['sport']} Removed.") print(f"{datetime.now().replace(microsecond=0)} Client: ID:{str(int_id(_peer_id)).rjust(9)} IP:{self.peerTrack[_peer_id]['shost'].rjust(15)} Port:{self.peerTrack[_peer_id]['sport']} Removed.")
self.connTrack[self.peerTrack[_peer_id]['dport']] = False self.connTrack[self.peerTrack[_peer_id]['dport']] = False
del self.peerTrack[_peer_id] del self.peerTrack[_peer_id]
@ -89,24 +90,20 @@ class Proxy(DatagramProtocol):
#If the packet comes from the master #If the packet comes from the master
if host == self.master: if host == self.master:
#fill this in _command = data[0:1]
_peer_id = data[0:0] _peer_id = data[1:5]
if self.debug: if self.debug:
print(data) print(data)
if _peer_id in self.peerTrack: if _peer_id in self.peerTrack:
self.transport.write(data,(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) self.transport.write(data,(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport']))
# Remove the client after send a MSTN or MSTC packet
if _command in (MSTN,MSTC):
# Give time to the client for a reply to prevent port reassignment
self.peerTrack[_peer_id]['timer'].reset(15)
return return
else: else:
#fill this in _command = data[0:1]
_peer_id = data[0:0] _peer_id = data[1:5]
if _peer_id in self.peerTrack: if _peer_id in self.peerTrack:
_dport = self.peerTrack[_peer_id]['dport'] _dport = self.peerTrack[_peer_id]['dport']
@ -175,17 +172,17 @@ if __name__ == '__main__':
try: try:
Master = config.get('PROXY','Master') Master = config.get('IPSC_PROXY','Master')
ListenPort = config.getint('PROXY','ListenPort') ListenPort = config.getint('IPSC_PROXY','ListenPort')
ListenIP = config.get('PROXY','ListenIP') ListenIP = config.get('IPSC_PROXY','ListenIP')
DestportStart = config.getint('PROXY','DestportStart') DestportStart = config.getint('IPSC_PROXY','DestportStart')
DestPortEnd = config.getint('PROXY','DestPortEnd') DestPortEnd = config.getint('IPSC_PROXY','DestPortEnd')
Timeout = config.getint('PROXY','Timeout') Timeout = config.getint('IPSC_PROXY','Timeout')
Stats = config.getboolean('PROXY','Stats') Stats = config.getboolean('IPSC_PROXY','Stats')
Debug = config.getboolean('PROXY','Debug') Debug = config.getboolean('IPSC_PROXY','Debug')
ClientInfo = config.getboolean('PROXY','ClientInfo') ClientInfo = config.getboolean('IPSC_PROXY','ClientInfo')
BlackList = json.loads(config.get('PROXY','BlackList')) BlackList = json.loads(config.get('IPSC_PROXY','BlackList'))
IPBlackList = json.loads(config.get('PROXY','IPBlackList')) IPBlackList = json.loads(config.get('IPSC_PROXY','IPBlackList'))
except configparser.Error as err: except configparser.Error as err:
print('Error processing configuration file -- {}'.format(err)) print('Error processing configuration file -- {}'.format(err))
@ -194,15 +191,15 @@ if __name__ == '__main__':
#*** CONFIG HERE *** #*** CONFIG HERE ***
Master = "127.0.0.1" Master = "127.0.0.1"
ListenPort = 62031 ListenPort = 55005
#'' = all IPv4, '::' = all IPv4 and IPv6 (Dual Stack) #'' = all IPv4, '::' = all IPv4 and IPv6 (Dual Stack)
ListenIP = '' ListenIP = ''
DestportStart = 50000 DestportStart = 59000
DestPortEnd = 50002 DestPortEnd = 59001
Timeout = 30 Timeout = 30
Stats = False Stats = True
Debug = False Debug = True
ClientInfo = False ClientInfo = True
BlackList = [1234567] BlackList = [1234567]
#e.g. {10.0.0.1: 0, 10.0.0.2: 0} #e.g. {10.0.0.1: 0, 10.0.0.2: 0}
IPBlackList = {} IPBlackList = {}
@ -214,7 +211,7 @@ if __name__ == '__main__':
# Set up the signal handler # Set up the signal handler
def sig_handler(_signal, _frame): def sig_handler(_signal, _frame):
print('(GLOBAL) SHUTDOWN: PROXY IS TERMINATING WITH SIGNAL {}'.format(str(_signal))) print('(GLOBAL) SHUTDOWN: IPSC_PROXY IS TERMINATING WITH SIGNAL {}'.format(str(_signal)))
reactor.stop() reactor.stop()
# Set signal handers so that we can gracefully exit if need be # Set signal handers so that we can gracefully exit if need be
@ -222,14 +219,14 @@ if __name__ == '__main__':
signal.signal(sig, sig_handler) signal.signal(sig, sig_handler)
#Override static config from Environment #Override static config from Environment
if 'FDPROXY_STATS' in os.environ: if 'FDIPSC_PROXY_STATS' in os.environ:
Stats = bool(os.environ['FDPROXY_STATS']) Stats = bool(os.environ['FDIPSC_PROXY_STATS'])
#if 'FDPROXY_DEBUG' in os.environ: #if 'FDIPSC_PROXY_DEBUG' in os.environ:
# Debug = bool(os.environ['FDPROXY_DEBUG']) # Debug = bool(os.environ['FDIPSC_PROXY_DEBUG'])
if 'FDPROXY_CLIENTINFO' in os.environ: if 'FDIPSC_PROXY_CLIENTINFO' in os.environ:
ClientInfo = bool(os.environ['FDPROXY_CLIENTINFO']) ClientInfo = bool(os.environ['FDIPSC_PROXY_CLIENTINFO'])
if 'FDPROXY_LISTENPORT' in os.environ: if 'FDIPSC_PROXY_LISTENPORT' in os.environ:
ListenPort = int(os.environ['FDPROXY_LISTENPORT']) ListenPort = int(os.environ['FDIPSC_PROXY_LISTENPORT'])
for port in range(DestportStart,DestPortEnd+1,1): for port in range(DestportStart,DestPortEnd+1,1):
CONNTRACK[port] = False CONNTRACK[port] = False

Loading…
Cancel
Save

Powered by TurnKey Linux.