Minor tweaks
This commit is contained in:
parent
10cc4c8442
commit
d84aa07def
2 changed files with 38 additions and 55 deletions
40
README.md
40
README.md
|
|
@ -1,21 +1,35 @@
|
|||
The new and improved python3 version is here!
|
||||
Because as we all know, python2 is the work of the devil, a major contributor to global warming
|
||||
and is probably responsible for the death of Jesus.
|
||||
Because as we all know, python2 is the work of the devil, a major contributor
|
||||
to global warming and is probably responsible for the death of Jesus.
|
||||
|
||||
Installing.
|
||||
|
||||
Find a nice place to put the file 'sipproxy', preferrably in a directory of its own.
|
||||
cd to that directory in a terminal/console/xterm and invoke the program by typing ./sipproxy
|
||||
It is purposely verbose, and will display a running commentary on what is happening.
|
||||
During this first run, the config file will be created as conf/config.conf and the phone book
|
||||
will be created as conf/addressbook.conf; (Both of these files require editing, and a great
|
||||
deal of effort has been put into using the right number words to enable the user to understand
|
||||
what is required, without competing with 'War & Peace').
|
||||
Find a nice place to put the file 'sipproxy', preferrably in a directory of
|
||||
its own. cd to that directory in a terminal/console/xterm and invoke the
|
||||
program by typing ./sipproxy (see Note below.)
|
||||
|
||||
It is purposely verbose, and will display a running commentary on what is
|
||||
happening. During this first run, the config file will be created as
|
||||
conf/config.conf and the phone book will be created as conf/addressbook.conf;
|
||||
(Both of these files require editing, and a great deal of effort has been put
|
||||
into using the right number words to enable the user to understand what is
|
||||
required, without competing with 'War & Peace'). sipproxy will then exit.
|
||||
After the configuration file, 'config.conf' has been modified to your needs
|
||||
and your VOIP telephone has been similarly setup with the correct settings,
|
||||
you are then ready to run sipproxy for real.
|
||||
|
||||
Note:
|
||||
|
||||
Microsoft Windows users will need to affix a '.py' file extension on to 'sipproxy', because
|
||||
Windows uses the file extension to determine the action required to use the file. Linux does
|
||||
not require a file extension, relying instead on file execute permissions and the shebang line
|
||||
(#!/usr/bin/python or #!/usr/bin/env python).
|
||||
Microsoft Windows users will need to affix a '.py' file extension on to
|
||||
'sipproxy', because Windows uses the file extension to determine the action
|
||||
required to use the file. Linux does not require a file extension, relying
|
||||
instead on file execute permissions and the shebang line, (#!/usr/bin/python
|
||||
or #!/usr/bin/env python or #!/usr/bin/python3 or #!/usr/bin/env python3).
|
||||
BSD is pretty similar but requires '#!/usr/bin/env python', and macOS requires
|
||||
'#!/usr/bin/python'. Basicly, you need to edit the first line in sipproxy to
|
||||
match your OS, because there is no 'one_size_fits_all' setting.
|
||||
|
||||
You can however, launch sipproxy as an argument to python, 'python sipproxy'
|
||||
or 'python ./siproxy', or 'python /home/me/sipthing/sipproxy', etc..
|
||||
|
||||
|
||||
|
|
|
|||
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