-
-
Save benasse/2840a577543f79469b3730f7eee4d7e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from wazo_auth_client import Client as Auth | |
from wazo_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('wazo_user', expiration=60) | |
return token_data['token'] | |
def create_line(line_data): | |
try: | |
line = confd.lines.create(line_data) | |
return line['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'), | |
('dtls_auto_generate_cert', 'yes'), | |
('allow', '!all,opus,g722,ulaw,alaw,vp9,vp8,h264'), | |
('webrtc', 'yes') | |
] | |
} | |
data['id_endpoint_sip'] = create_endpoint_sip(endpoint) | |
line = { | |
'context': 'default' # Use the good context | |
} | |
data['id_line'] = create_line(line) | |
if data and error != 1: | |
associate_user(data) | |
print(data) | |
auth.token.revoke(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment