Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from xivo_auth_client import Client as Auth
- from xivo_confd_client import Client as Confd
- # Please add a web service user with acl confd.#
- # To use ./add-webrtc-line
- username = "sylvain" # Fill with your username
- password = "sylvain" # Fill with your password
- ################ Do no modify ##############
- data = {}
- error = None
- def get_token(username, password):
- token_data = auth.token.new('xivo_service', expiration=60)
- return token_data['token']
- def create_line(line):
- try:
- l = confd.lines.create(line)
- return l['id']
- except Exception as e:
- print 'There is an error to create extension :', e
- delete_on_error(data)
- def create_endpoint_sip(endpoint):
- try:
- sip = confd.endpoints_sip.create(endpoint)
- return sip['id']
- except Exception as e:
- print 'There is an error to create endpoint SIP :', e
- delete_on_error(data)
- def associate_user(data):
- confd.endpoints_sip.relations(data['id_endpoint_sip']).associate_line(data['id_line'])
- #confd.users.relations(data['uuid']).add_line(data['id_line'])
- #confd.extensions.relations(data['id_exten']).add_line(data['id_line'])
- def delete_on_error(data):
- global error
- error = 1
- try:
- confd.line.delete(data['id_line'])
- confd.endpoints_sip.delete(data['id_endpoint_sip'])
- except:
- pass
- auth = Auth('127.0.0.1', username=username, password=password, verify_certificate=False)
- token = get_token(username, password)
- confd = Confd('localhost', verify_certificate=False, token=token)
- endpoint = {
- 'type': 'friend',
- 'host': 'dynamic',
- 'options': [
- ('transport', 'wss'),
- ('directmedia', 'no'),
- ('encryption', 'yes'),
- ('dtlsenable', 'yes'),
- ('dtlsverify', 'yes'),
- ('dtlscertfile', '/usr/share/xivo-certs/server.crt'),
- ('dtlsprivatekey', '/usr/share/xivo-certs/server.key'),
- ('dtlssetup', 'actpass'),
- ('force_avp', 'yes'),
- ('avpf', 'yes'),
- ('icesupport', 'yes')
- ]
- }
- data['id_endpoint_sip'] = create_endpoint_sip(endpoint)
- line = {
- 'context': 'default'
- }
- data['id_line'] = create_line(line)
- if data and error != 1:
- associate_user(data)
- print data
- auth.token.revoke(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement