Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from xivo_auth_client import Client as Auth
  4. from xivo_confd_client import Client as Confd
  5.  
  6. # Please add a web service user with acl confd.#
  7. # To use ./add-webrtc-line
  8.  
  9. username = "sylvain" # Fill with your username
  10. password = "sylvain" # Fill with your password
  11.  
  12. ################ Do no modify ##############
  13.  
  14. data = {}
  15. error = None
  16.  
  17. def get_token(username, password):
  18. token_data = auth.token.new('xivo_service', expiration=60)
  19. return token_data['token']
  20.  
  21. def create_line(line):
  22. try:
  23. l = confd.lines.create(line)
  24. return l['id']
  25. except Exception as e:
  26. print 'There is an error to create extension :', e
  27. delete_on_error(data)
  28.  
  29. def create_endpoint_sip(endpoint):
  30. try:
  31. sip = confd.endpoints_sip.create(endpoint)
  32. return sip['id']
  33. except Exception as e:
  34. print 'There is an error to create endpoint SIP :', e
  35. delete_on_error(data)
  36.  
  37. def associate_user(data):
  38. confd.endpoints_sip.relations(data['id_endpoint_sip']).associate_line(data['id_line'])
  39. #confd.users.relations(data['uuid']).add_line(data['id_line'])
  40. #confd.extensions.relations(data['id_exten']).add_line(data['id_line'])
  41.  
  42. def delete_on_error(data):
  43. global error
  44. error = 1
  45. try:
  46. confd.line.delete(data['id_line'])
  47. confd.endpoints_sip.delete(data['id_endpoint_sip'])
  48. except:
  49. pass
  50.  
  51. auth = Auth('127.0.0.1', username=username, password=password, verify_certificate=False)
  52. token = get_token(username, password)
  53. confd = Confd('localhost', verify_certificate=False, token=token)
  54.  
  55. endpoint = {
  56. 'type': 'friend',
  57. 'host': 'dynamic',
  58. 'options': [
  59. ('transport', 'wss'),
  60. ('directmedia', 'no'),
  61. ('encryption', 'yes'),
  62. ('dtlsenable', 'yes'),
  63. ('dtlsverify', 'yes'),
  64. ('dtlscertfile', '/usr/share/xivo-certs/server.crt'),
  65. ('dtlsprivatekey', '/usr/share/xivo-certs/server.key'),
  66. ('dtlssetup', 'actpass'),
  67. ('force_avp', 'yes'),
  68. ('avpf', 'yes'),
  69. ('icesupport', 'yes')
  70. ]
  71. }
  72.  
  73. data['id_endpoint_sip'] = create_endpoint_sip(endpoint)
  74.  
  75. line = {
  76. 'context': 'default'
  77. }
  78.  
  79. data['id_line'] = create_line(line)
  80.  
  81. if data and error != 1:
  82. associate_user(data)
  83. print data
  84.  
  85. auth.token.revoke(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement