-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.inc.php
179 lines (140 loc) · 6.36 KB
/
functions.inc.php
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
global $amp_conf;
function motif_get_config($engine) {
global $ext;
switch($engine) {
case "asterisk":
FreePBX::create()->Sipsettings->setConfig('icesupport', 'yes');
$accounts = FreePBX::Motif()->getAllAccounts();
foreach($accounts as $list) {
$settings = $list['settings'];
$context = $list['context']; //Remove special characters for use in contexts. There still might be a char limit though
$incontext = "im-".$context;
$address = 's'; //Joshua Colp @ Digium: 'It will only accept from the s context'
$ext->add($incontext, $address, '1', new ext_noop('Receiving GoogleVoice on DID: '.$list['phonenum']));
$ext->add($incontext, $address, '', new ext_noop('${EXTEN}'));
$ext->add($incontext, $address, '', new ext_gotoif('$["${REGEX("!" ${CALLERID(name)})}" = "1"]', 'ex'));
$ext->add($incontext, $address, 'at', new ext_setvar('CALLERID(name)', '${CUT(CALLERID(name),@,1)}'));
$ext->add($incontext, $address, '', new ext_goto("int"));
$ext->add($incontext, $address, 'ex', new ext_setvar('CALLERID(name)', '${CUT(CALLERID(name),!,1)}'));
$ext->add($incontext, $address, '', new ext_goto("int"));
$ext->add($incontext, $address, 'int', new ext_gotoif('$["${CALLERID(name):0:2}" != "+1"]', 'nextstop'));
$ext->add($incontext, $address, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):2}'));
$ext->add($incontext, $address, 'nextstop', new ext_gotoif('$["${CALLERID(name):0:1}" != "+"]', 'notrim'));
$ext->add($incontext, $address, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):1}'));
$ext->add($incontext, $address, '', new ext_setvar('CDR(did)', $list['phonenum']));
$ext->add($incontext, $address, 'notrim', new ext_setvar('CALLERID(number)', '${CALLERID(name)}'));
if(isset($settings['gvm']) && $settings['gvm']) {
$ext->add($incontext, $address, '', new ext_setvar('DIAL_OPTIONS', '${DIAL_OPTIONS}aD(:1)'));
if(isset($settings['greeting']) && $settings['greeting']) {
$ext->add($incontext, $address, '', new ext_answer(''));
$ext->add($incontext, $address, '', new ext_playback('hello') );
$ext->add($incontext, $address, '', new ext_senddtmf('1'));
}
} else {
$ext->add($incontext, $address, '', new ext_wait('1'));
$ext->add($incontext, $address, '', new ext_answer(''));
$ext->add($incontext, $address, '', new ext_senddtmf('1'));
}
$ext->add($incontext, $address, '', new ext_goto('1', $list['phonenum'], 'from-trunk'));
$ext->add($incontext, 'h', '', new ext_hangup(''));
}
break;
}
}
class motif_conf {
//Tell freepbx which files we want to 'control'
function get_filename() {
$files = array(
'motif.conf',
'xmpp.conf'
);
return $files;
}
//This function is called for every file defined in 'get_filename()' function above
function generateConf($file) {
global $version,$amp_conf,$astman;
//Create all custom files
if(!file_exists($amp_conf['ASTETCDIR'] . '/xmpp_general_custom.conf')) {
touch($amp_conf['ASTETCDIR'] . '/xmpp_general_custom.conf');
}
if(!file_exists($amp_conf['ASTETCDIR'] . '/motif_custom.conf')) {
touch($amp_conf['ASTETCDIR'] . '/motif_custom.conf');
}
if(!file_exists($amp_conf['ASTETCDIR'] . '/xmpp_custom.conf')) {
touch($amp_conf['ASTETCDIR'] . '/xmpp_custom.conf');
}
//Backup all old xmpp & motif.conf files
if(file_exists($amp_conf['ASTETCDIR'] . '/xmpp.conf') && !file_exists($amp_conf['ASTETCDIR'] . '/xmpp.conf.bak')) {
copy($amp_conf['ASTETCDIR'] . '/xmpp.conf', $amp_conf['ASTETCDIR'] . '/xmpp.conf.bak');
}
if(file_exists($amp_conf['ASTETCDIR'] . '/motif.conf') && !file_exists($amp_conf['ASTETCDIR'] . '/motif.conf.bak')) {
copy($amp_conf['ASTETCDIR'] . '/motif.conf', $amp_conf['ASTETCDIR'] . '/motif.conf.bak');
}
//Disable gtalk and jabber
if(file_exists($amp_conf['ASTETCDIR'] . '/jabber.conf') && !file_exists($amp_conf['ASTETCDIR'] . '/jabber.conf.old')) {
rename($amp_conf['ASTETCDIR'] . '/jabber.conf', $amp_conf['ASTETCDIR'] . '/jabber.conf.old');
}
if($astman->mod_loaded('jabber')) {
$astman->send_request('Command', array('Command' => 'module unload res_jabber.so'));
}
if(file_exists($amp_conf['ASTETCDIR'] . '/gtalk.conf') && !file_exists($amp_conf['ASTETCDIR'] . '/gtalk.conf.old')) {
rename($amp_conf['ASTETCDIR'] . '/gtalk.conf', $amp_conf['ASTETCDIR'] . '/gtalk.conf.old');
}
if($astman->mod_loaded('gtalk')) {
$astman->send_request('Command', array('Command' => 'module unload chan_gtalk.so'));
}
//Setup specific file matching
switch ($file) {
case 'motif.conf':
return $this->generate_motif_conf($version);
break;
case 'xmpp.conf':
return $this->generate_xmpp_conf($version);
break;
}
}
function generate_motif_conf($ast_version) {
$accounts = FreePBX::Motif()->getAllAccounts();
//Clear output for motif file
$output = '';
foreach($accounts as $list) {
$context = $list['context']; //Remove special characters for use in contexts. There still might be a char limit though
$output .= "[g".$context."]\n"; //Add contexts for each 'line'
$output .= "context=im-".$context."\n";
$output .= "disallow=all\n";
$output .= "allow=ulaw\n";
$output .= "connection=g".$context."\n\n";
}
$output .= "#include motif_custom.conf\n";
return $output;
}
function generate_xmpp_conf($ast_version) {
$accounts = FreePBX::Motif()->getAllAccounts();
$output = "[general]\n\n";
$output .= "#include xmpp_general_custom.conf\n\n";
foreach($accounts as $list) {
$context = $list['context']; //Remove special characters for use in contexts. There still might be a char limit though
$output .= "[g".$context."]\n";
$output .= "type=client\n";
$output .= "serverhost=talk.google.com\n";
$output .= "username=".$list['username']."\n";
if($list['authmode'] == 'plaintext') {
$output .= "secret=".$list['password']."\n";
} else {
$output .= "refresh_token=".$list['refresh_token']."\n";
$output .= "oauth_clientid=".$list['oauth_clientid']."\n";
$output .= "oauth_secret=".$list['oauth_secret']."\n";
}
$output .= "port=5222\n";
$output .= "usetls=yes\n";
$output .= "usesasl=yes\n";
$output .= "status=available\n";
$output .= "statusmessage=\"".$list['statusmessage']."\"\n";
$output .= "timeout=5\n";
$output .= "priority=".$list['priority']."\n\n";
}
$output .= "#include xmpp_custom.conf\n";
return $output;
}
}