Minor tweaks
This commit is contained in:
parent
10cc4c8442
commit
d84aa07def
2 changed files with 38 additions and 55 deletions
53
sipproxy
53
sipproxy
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/python
|
||||
#import sys first so that if we bale in the following try we can still exit clean.
|
||||
import sys
|
||||
|
||||
|
|
@ -15,12 +15,13 @@ try:
|
|||
import socket
|
||||
import syslog
|
||||
import time
|
||||
except ImportError:
|
||||
print("Some modules missing: requires Twisted among others.\n")
|
||||
except ImportError as e:
|
||||
print(e)
|
||||
print("Required module missing.\n")
|
||||
sys.exit(1)
|
||||
|
||||
##################################################################
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
BaseDir = os.getcwd()
|
||||
CRLF = "\r\n"
|
||||
confdir = "conf"
|
||||
|
|
@ -171,9 +172,7 @@ Remote_Audio_Port = "61110"
|
|||
Local_Audio_IP = "127.0.0.1"
|
||||
Local_Audio_Port = "61110"
|
||||
register_regex = 'CSeq: (.+?) REGISTER'
|
||||
inviteSD_regex = 'INVITE sip:(.+?)@sipdiscount.com SIP/2'
|
||||
register_pattern=re.compile(register_regex, flags=re.IGNORECASE)
|
||||
inviteSD_pattern=re.compile(inviteSD_regex, flags=re.IGNORECASE)
|
||||
##################################################################
|
||||
class Sip(DatagramProtocol):
|
||||
def datagramReceived(self, data, addr):
|
||||
|
|
@ -217,7 +216,6 @@ class Sip(DatagramProtocol):
|
|||
print(tdata)
|
||||
else:
|
||||
if (addr[0] != LocalPhoneIP):
|
||||
Logit(Time + " From ip: " + addr[0] + " " + data)
|
||||
if (UserID in data):
|
||||
Destination = addr[0]
|
||||
reg = re.findall(register_pattern,tdata)
|
||||
|
|
@ -225,6 +223,7 @@ class Sip(DatagramProtocol):
|
|||
self.transport.write(tdata.encode(), (LocalPhoneIP, 5060))
|
||||
print(tdata[:12])
|
||||
else:
|
||||
Logit(Time + " From ip: " + addr[0] + " " + data)
|
||||
syslog.syslog("To " + LocalPhoneIP)
|
||||
syslog.syslog(tdata)
|
||||
print(Time, "To:", LocalPhoneIP)
|
||||
|
|
@ -232,7 +231,7 @@ class Sip(DatagramProtocol):
|
|||
print(tdata)
|
||||
|
||||
else:
|
||||
Logit(Time + " Spam From ip: " + addr[0] + " " + tdata)
|
||||
Logit(Time + " Spam From ip: " + addr[0] + " " + data)
|
||||
|
||||
##################################################################
|
||||
|
||||
|
|
@ -249,8 +248,6 @@ def Proxy(data, addr):
|
|||
##################################################################
|
||||
|
||||
def FromRemote(data, addr):
|
||||
global Remote_Audio_IP # spurious, probably unneeded
|
||||
|
||||
data = data.replace(PublicIP, LocalPhoneIP)
|
||||
data = data.replace(addr[0], ThisBoxIP)
|
||||
data = Remote_SDP_Edit(data)
|
||||
|
|
@ -261,35 +258,8 @@ def FromRemote(data, addr):
|
|||
def FromLocal(data, addr):
|
||||
global Destination
|
||||
data = FoneBook(data)
|
||||
# Too many bugs, needs thinking about.
|
||||
# reg = re.findall(register_pattern,data)
|
||||
# if reg:
|
||||
# Destination = ITSP
|
||||
# print("Destination is " + Destination)
|
||||
# data = data.replace(addr[0], PublicIP)
|
||||
# data = Local_SDP_Edit(data)
|
||||
# return data
|
||||
#
|
||||
# sd = re.findall(inviteSD_pattern,data)
|
||||
# if sd:
|
||||
# Destination = ITSP
|
||||
# print("Destination is " + Destination)
|
||||
# else:
|
||||
# if ("INVITE sip:" in data):
|
||||
# begin = data.find("@")
|
||||
# begin = begin + 1
|
||||
# nigeb = data.find(" ", begin)
|
||||
# Destination = data[begin:nigeb]
|
||||
# Destination = Destination.split(':')[0]
|
||||
# print("Destination is " + Destination)
|
||||
#
|
||||
# if isip(Destination) == False:
|
||||
# Destination = socket.gethostbyname(Destination)
|
||||
#
|
||||
# print("Destination is " + Destination)
|
||||
data = data.replace(addr[0], PublicIP)
|
||||
data = Local_SDP_Edit(data)
|
||||
# print(data)
|
||||
return data
|
||||
|
||||
##################################################################
|
||||
|
|
@ -370,16 +340,14 @@ def signal_handler(sig, frame):
|
|||
Time = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(Time, "Shutting down")
|
||||
reactor.stop()
|
||||
print('reactor stopped')
|
||||
syslog.syslog("SIGINT - Shutting Down!")
|
||||
os._exit(0)
|
||||
syslog.syslog("Not Visible in syslog.")
|
||||
quit()
|
||||
|
||||
|
||||
##################################################################
|
||||
def MkFoneBook():
|
||||
Blurb001 = "# This fonebook is crude, the error checking is minimal, so if you screw it up, then it wont work.\n"
|
||||
Blurb000 = "# This fonebook is crude, the error checking is minimal, so if you screw it up, then it wont work.\n"
|
||||
Blurb001 = "# It is based on a UK telephone exchange and dialling codes. It also assumes you are using sipdiscount as your ITSP.\n"
|
||||
Blurb002 = "# However, if you delete the screwed up copy, the basic file will be recreated by SipProxy.\n\n"
|
||||
Blurb003 = "# Lines beginning with # are ignored, as are lines consisting solely of whitespace and blank lines.\n#\n"
|
||||
Blurb004 = "#Replace=With\n"
|
||||
|
|
@ -463,6 +431,7 @@ def MkFoneBook():
|
|||
|
||||
try:
|
||||
fh = codecs.open(phonebookfile, 'w', encoding='utf-8')
|
||||
fh.write(Blurb000)
|
||||
fh.write(Blurb001)
|
||||
fh.write(Blurb002)
|
||||
fh.write(Blurb003)
|
||||
|
|
@ -602,7 +571,7 @@ else:
|
|||
signal.signal(signal.SIGINT, signal_handler)
|
||||
Time = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(Time, "Everything started up")
|
||||
Logit(Time + "Started up OK")
|
||||
Logit(Time + " Started up OK")
|
||||
syslog.syslog("Everything started up")
|
||||
reactor.listenUDP(5060, Sip())
|
||||
reactor.listenUDP(11110, OutRTP())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue