-
Notifications
You must be signed in to change notification settings - Fork 17
/
provision.js
102 lines (91 loc) · 2.99 KB
/
provision.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var client = require('ari-client');
var url = "http://192.168.1.140:8088"
var username = "asterisk"
var password = "asterisk"
var sip_user = '100'
var sip_password = '100'
function provision(sip_user, sip_password){
client.connect(url, username, password)
.then(function (ari){
ari.asterisk.updateObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'auth',
fields : [
{ attribute: 'auth_type', value: 'userpass' },
{ attribute: 'username', value: sip_user },
{ attribute: 'password', value: sip_password }
]
})
.then (function (configTuples){
console.log(configTuples)
ari.asterisk.updateObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'aor',
fields : [
{ attribute: 'support_path', value: "yes" },
{ attribute: 'remove_existing', value: "yes" },
{ attribute: 'max_contacts', value: "1" }
]
})
.then (function (configTuples){
console.log(configTuples)
ari.asterisk.updateObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'endpoint',
fields : [
{ attribute: 'from_user', value: sip_user },
{ attribute: 'allow', value: "!all,g722,ulaw,alaw" },
{ attribute: 'ice_support', value: "yes" },
{ attribute: 'force_rport', value: "yes" },
{ attribute: 'rewrite_contact', value: "yes" },
{ attribute: 'rtp_symmetric', value: "yes" },
{ attribute: 'context', value: "applications" },
{ attribute: 'auth', value: sip_user },
{ attribute: 'aors', value: sip_user }
]
})
.then (function (configTuples){
console.log(configTuples)
})
})
})
})
.catch(function (err) {
console.log(err)
});
}
function deprovision(sip_user){
client.connect(url, username, password)
.then(function (ari){
ari.asterisk.deleteObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'endpoint'
})
.then (function (configTuples){
console.log(configTuples)
ari.asterisk.deleteObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'aor'
})
.then (function (configTuples){
console.log(configTuples)
ari.asterisk.deleteObject({
configClass: 'res_pjsip',
id: sip_user,
objectType: 'auth'
})
.then (function (configTuples){
console.log(configTuples)
})
})
})
})
.catch(function (err) {
console.log(err)
});
}