nokiasip/confGen

89 lines
3.3 KiB
Text
Raw Permalink Normal View History

2021-08-06 00:40:59 +01:00
#!/usr/bin/python3
# NOKIA SIP PROV GENERATOR
# Copyright (C) 2021 Dovi Cowan
# nokiasip@catch.dovicowan.email
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import subprocess
import argparse
print("NOKIA SIP PROV GENERATOR\nCopyright (C) 2021 Dovi Cowan\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions.")
devices = os.listdir('templates/')
2021-08-10 17:17:19 +01:00
devices = [i.split('.', 1)[0] for i in devices]
2021-08-06 00:40:59 +01:00
args = argparse.ArgumentParser('./confGen', description="Generate provisioning files for Nokia SIP")
args.add_argument('device', help="Device type", type=str, choices=devices)
args.add_argument('--provName', help="Name for provisioning profile (default 'Nokia SIP')", type=str)
args.add_argument('username', help="SIP Username", type=str)
args.add_argument('password', help="SIP Password", type=str)
args.add_argument('server', help="SIP Server", type=str)
args.add_argument('--port', help="SIP Port (default 5060)", type=int)
args.add_argument('--proxy', help="SIP Proxy", type=str)
args.add_argument('--proxyPort', help="SIP Proxy Port (default 5060)", type=str)
args.add_argument('--output', help="Output file (default config.prov)", type=str)
args.add_argument('--provURI', help=argparse.SUPPRESS)
args = args.parse_args()
args = vars(args)
with open('templates/'+args['device']+'.xml', 'r') as file:
data = file.read().replace('\n', '')
if args['provName'] is None:
2021-08-10 17:50:46 +01:00
data = data.replace("{NAME}",'Nokia SIP')
2021-08-06 00:40:59 +01:00
else:
2021-08-10 17:50:46 +01:00
data = data.replace("{NAME}",args['provName'])
2021-08-06 00:40:59 +01:00
if args['port'] is None:
2021-08-10 17:50:46 +01:00
data = data.replace("{PORT}",str(5060))
2021-08-06 00:40:59 +01:00
proxyport = 5060
else:
2021-08-10 17:50:46 +01:00
data = data.replace("{PORT}",args['port'])
2021-08-06 00:40:59 +01:00
proxyport = args['port']
if args['proxy'] is None:
2021-08-10 17:50:46 +01:00
data = data.replace("{REGISTRAR}",args['server'])
2021-08-06 00:40:59 +01:00
else:
2021-08-10 17:50:46 +01:00
data = data.replace("{REGISTRAR}",args['proxy'])
2021-08-06 00:40:59 +01:00
if args['proxyPort'] is None:
2021-08-10 17:50:46 +01:00
data = data.replace("{REGISTRAR_PORT}",str(proxyport))
2021-08-06 00:40:59 +01:00
else:
2021-08-10 17:50:46 +01:00
data = data.replace("{REGISTRAR_PORT}",args['proxyPort'])
2021-08-06 00:40:59 +01:00
# This will give an option for "Service Homepage" on the phone
if args['provURI'] is None:
2021-08-10 17:50:46 +01:00
data = data.replace("{PROV_URI}", 'http://projects.fnukhosting.net/nokiasip/prov.php?devicetype='+args['device'])
2021-08-06 00:40:59 +01:00
else:
2021-08-10 17:50:46 +01:00
data = data.replace("{PROV_URI}",args['provURI'])
2021-08-06 00:40:59 +01:00
2021-08-10 17:50:46 +01:00
data = data.replace("{DOMAIN}",args['server'])
data = data.replace("{USER}",args['username'])
data = data.replace("{PASSWORD}",args['password'])
2021-08-06 00:40:59 +01:00
# prov = wbxml.xml_to_wbxml(data)
data = data.encode(encoding='utf8')
if args['output'] is not None:
outputFile = args['output']
else:
outputFile = 'config.prov'
prov = subprocess.Popen(["./libwbxml/bin/xml2wbxml", "-o"+outputFile, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
2021-08-10 17:50:46 +01:00
prov = prov.communicate(input=bytes(data))[0]