
| Current Path : /home/ift/51_iftlib/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/ift/51_iftlib/extensions.py |
import sys,re,os,random
phone_numbers = []
phone_numbers.append( ["499112878343", "widor124", "1234"] )
phone_numbers.append( ["499112878376", "widor124", "1234"] )
phone_numbers.append( ["4991130006130", "widor124", "1234"] )
host_intern = "fritz.box"
host_extern = "10.2.2.1"
etc_a = '''
[---NR---]
exten => ---NR---,1,Dial(SIP/---NRX---)
exten => _0[1-9].,1,Dial(SIP/${EXTEN}@---NR---)
exten => _0043[1-9].,1,Dial(SIP/${EXTEN}@---NR---)
'''
sip_a = "register => ---NR---:---PASSWORD---@---HOST---/---NR---"
sip_x = "register => ---NRX---:---PWX---@---HOSTX---/---NRX---"
sip_b = '''
[---NRX---]
type=friend
secret=---PWX---
host=dynamic
context=---NR---
[---NR---]
host=---HOST---
fromdomain=---HOST---
username=---NR---
fromuser=---NR---
secret=---PASSWORD---
context=---NR---
type=peer
insecure=port,invite
'''
#-------------------------
etc_x = etc_a.replace("-NRX-","-NREND-")
etc_x = etc_x.replace("-NR-","-NRX-")
sip_y = sip_b.replace("-NRX-","-NREND-")
sip_y = sip_y.replace("-PWX-","-SE-")
sip_y = sip_y.replace("-NR-","-NRX-")
sip_y = sip_y.replace("-HOST-","-HOSTX-")
sip_y = sip_y.replace("-PASSWORD-","-PWX-")
extensions = '''
[general]
port=5060
bind=0.0.0.0
'''
sip1 = '''
[general]
context=public
'''
sip2 = ""
exten_x = extensions
sip5 = sip1
sip6 = sip2
for nrdata in phone_numbers:
nr = "10" + nrdata[0]
nrx = "09" + nrdata[0]
nrend = "00" + nrdata[0]
pw = nrdata[1]
pwx = str(random.randint(100000000009,999999999990))
se = nrdata[2]
extensions = extensions + etc_a
extensions = extensions.replace("---NR---",nr)
extensions = extensions.replace("---NRX---",nrx)
sip1 = sip1 + sip_a + "\n"
sip1 = sip1.replace("---NR---",nr)
sip1 = sip1.replace("---PASSWORD---",pw)
sip1 = sip1.replace("---HOST---",host_intern)
sip2 = sip2 + sip_b
sip2 = sip2.replace("---NR---",nr)
sip2 = sip2.replace("---NRX---",nrx)
sip2 = sip2.replace("---PASSWORD---",pw)
sip2 = sip2.replace("---PWX---",pwx)
sip2 = sip2.replace("---HOST---",host_intern)
exten_x = exten_x + etc_x
exten_x = exten_x.replace("---NRX---",nrx)
exten_x = exten_x.replace("---NREND---",nrend)
sip5 = sip5 + sip_x + "\n"
sip5 = sip5.replace("---NRX---",nrx)
sip5 = sip5.replace("---PWX---",pwx)
sip5 = sip5.replace("---HOSTX---",host_extern)
sip6 = sip6 + sip_y
sip6 = sip6.replace("---NREND---",nrend)
sip6 = sip6.replace("---NRX---",nrx)
sip6 = sip6.replace("---PWX---",pwx)
sip6 = sip6.replace("---SE---",se)
sip6 = sip6.replace("---HOSTX---",host_extern)
open("extensions.conf","w").write(extensions)
open("sip.conf","w").write(sip1+sip2)
open("extensions."+host_extern.replace(".","_"),"w").write(exten_x)
open("sip."+host_extern.replace(".","_"),"w").write(sip5+sip6)