Ticket #2695: functions.inc.php

File functions.inc.php, 221.0 kB (added by robmac, 9 months ago)
Line 
1 <?php
2
3 class core_conf {
4         var $_sip_general    = array();
5         var $_iax_general    = array();
6         var $_h323_general    = array();
7         var $_mgcp_general    = array();
8         var $_skinny_general    = array();
9         var $_featuregeneral = array();
10         var $_featuremap     = array();
11         var $_applicationmap = array();
12         // return an array of filenames to write
13         function get_filename() {
14                 $files = array(
15                         'zapata_additional.conf',
16                         'sip_additional.conf',
17                         'sip_registrations.conf',
18                         'sip_general_additional.conf',
19                         'iax_additional.conf',
20                         'iax_registrations.conf',
21                         'iax_general_additional.conf',
22                         'ooh323_additional.conf',
23                         'ooh323_registrations.conf',
24                         'ooh323_general_additional.conf',
25                         'mgcp_additional.conf',
26                         'mgcp_registrations.conf',
27                         'mgcp_general_additional.conf',
28                         'skinny_additional.conf',
29                         'skinny_registrations.conf',
30                         'skinny_general_additional.conf',
31                         'features_general_additional.conf',
32                         'features_applicationmap_additional.conf',
33                         'features_featuremap_additional.conf',
34                         );
35                 return $files;
36         }
37        
38         // return the output that goes in each of the files
39         function generateConf($file) {
40                 global $version;
41
42                 switch ($file) {
43                         case 'sip_general_additional.conf':
44                                 return $this->generate_sip_general_additional($version);
45                                 break;
46                         case 'sip_additional.conf':
47                                 return $this->generate_sip_additional($version);
48                                 break;
49                         case 'sip_registrations.conf':
50                                 return $this->generate_sip_registrations($version);
51                                 break;
52                         case 'iax_general_additional.conf':
53                                 return $this->generate_iax_general_additional($version);
54                                 break;
55                         case 'iax_additional.conf':
56                                 return $this->generate_iax_additional($version);
57                                 break;
58                         case 'iax_registrations.conf':
59                                 return $this->generate_iax_registrations($version);
60                                 break;
61                         case 'ooh323_general_additional.conf':
62                                 return $this->generate_h323_general_additional($version);
63                                 break;
64                         case 'ooh323_additional.conf':
65                                 return $this->generate_h323_additional($version);
66                                 break;
67                         case 'ooh323_registrations.conf':
68                                 return $this->generate_h323_registrations($version);
69                                 break;
70                         case 'mgcp_general_additional.conf':
71                                 return $this->generate_mgcp_general_additional($version);
72                                 break;
73                         case 'mgcp_additional.conf':
74                                 return $this->generate_mgcp_additional($version);
75                                 break;
76                         case 'mgcp_registrations.conf':
77                                 return $this->generate_mgcp_registrations($version);
78                                 break;
79                         case 'skinny_general_additional.conf':
80                                 return $this->generate_skinny_general_additional($version);
81                                 break;
82                         case 'skinny_additional.conf':
83                                 return $this->generate_skinny_additional($version);
84                                 break;
85                         case 'skinny_registrations.conf':
86                                 return $this->generate_skinny_registrations($version);
87                                 break;
88                         case 'zapata_additional.conf':
89                                 return $this->generate_zapata_additional($version);
90                                 break;
91                         case 'features_general_additional.conf':
92                                 return $this->generate_featuregeneral_additional($version);
93                                 break;
94                         case 'features_applicationmap_additional.conf':
95                                 return $this->generate_applicationmap_additional($version);
96                                 break;
97                         case 'features_featuremap_additional.conf':
98                                 return $this->generate_featuremap_additional($version);
99                                 break;
100                 }
101         }
102
103         function addSipGeneral($key, $value) {
104                 $this->_sip_general[] = array('key' => $key, 'value' => $value);
105         }
106
107         function generate_sip_general_additional($ast_version) {
108                 $output = '';
109
110                 if (isset($this->_sip_general) && is_array($this->_sip_general)) {
111                         foreach ($this->_sip_general as $values) {
112                                 $output .= $values['key']."=".$values['value']."\n";
113                         }
114                 }
115                 return $output;
116         }
117
118         function addIaxGeneral($key, $value) {
119                 $this->_iax_general[] = array('key' => $key, 'value' => $value);
120         }
121
122         function generate_iax_general_additional($ast_version) {
123                 $output = '';
124
125                 if (isset($this->_iax_general) && is_array($this->_iax_general)) {
126                         foreach ($this->_iax_general as $values) {
127                                 $output .= $values['key']."=".$values['value']."\n";
128                         }
129                 }
130                 return $output;
131         }
132
133         function addH323General($key, $value) {
134                 $this->_h323_general[] = array('key' => $key, 'value' => $value);
135         }
136
137         function generate_h323_general_additional($ast_version) {
138                 $output = '';
139
140                 if (isset($this->_h323_general) && is_array($this->_h323_general)) {
141                         foreach ($this->_h323_general as $values) {
142                                 $output .= $values['key']."=".$values['value']."\n";
143                         }
144                 }
145                 return $output;
146         }
147
148         function addMgcpGeneral($key, $value) {
149                 $this->_mgcp_general[] = array('key' => $key, 'value' => $value);
150         }
151
152         function generate_mgcp_general_additional($ast_version) {
153                 $output = '';
154
155                 if (isset($this->_mgcp_general) && is_array($this->_mgcp_general)) {
156                         foreach ($this->_mgcp_general as $values) {
157                                 $output .= $values['key']."=".$values['value']."\n";
158                         }
159                 }
160                 return $output;
161         }
162
163         function addSkinnyGeneral($key, $value) {
164                 $this->_skinny_general[] = array('key' => $key, 'value' => $value);
165         }
166
167         function generate_skinny_general_additional($ast_version) {
168                 $output = '';
169
170                 if (isset($this->_skinny_general) && is_array($this->_skinny_general)) {
171                         foreach ($this->_skinny_general as $values) {
172                                 $output .= $values['key']."=".$values['value']."\n";
173                         }
174                 }
175                 return $output;
176         }
177
178         function addFeatureGeneral($key, $value) {
179                 $this->_featuregeneral[] = array('key' => $key, 'value' => $value);
180         }
181
182         function generate_featuregeneral_additional($ast_version) {
183                 $output = '';
184
185                 if (isset($this->_featuregeneral) && is_array($this->_featuregeneral)) {
186                         foreach ($this->_featuregeneral as $values) {
187                                 $output .= $values['key']."=".$values['value']."\n";
188                         }
189                 }
190                 return $output;
191         }
192
193         function addFeatureMap($key, $value) {
194                 $this->_featuremap[] = array('key' => $key, 'value' => $value);
195         }
196
197         function generate_featuremap_additional($ast_version) {
198                 $output = '';
199
200                 if (isset($this->_featuremap) && is_array($this->_featuremap)) {
201                         foreach ($this->_featuremap as $values) {
202                                 $output .= $values['key']."=".$values['value']."\n";
203                         }
204                 }
205                 return $output;
206         }
207
208         function addApplicationMap($key, $value) {
209                 $this->_applicationmap[] = array('key' => $key, 'value' => $value);
210         }
211
212         function generate_applicationmap_additional($ast_version) {
213                 $output = '';
214
215                 if (isset($this->_applicationmap) && is_array($this->_applicationmap)) {
216                         foreach ($this->_applicationmap as $values) {
217                                 $output .= $values['key']."=".$values['value']."\n";
218                         }
219                 }
220                 return $output;
221         }
222
223         function generate_sip_additional($ast_version) {
224                 global $db;
225
226                 $table_name = "sip";
227                 $additional = "";
228                 $output = "";
229
230                 // Asterisk 1.4 requires call-limit be set for hints to work properly
231                 //
232                 if (version_compare($ast_version, "1.4", "ge")) {
233                         $call_limit = "call-limit=50\n";
234                         $ver12 = false;
235                 } else {
236                         $call_limit = "";
237                         $ver12 = true;
238                 }
239
240                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
241                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
242                 if(DB::IsError($results)) {
243                 die($results->getMessage());
244                 }
245                 foreach ($results as $result) {
246                         if ($ver12) {
247                                 $additional .= $result['keyword']."=".$result['data']."\n";
248                         } else {
249                                 $option = $result['data'];
250                                 switch ($result['keyword']) {
251                                         case 'allow':
252                                         case 'disallow':
253                                                 if ($option != '')
254                                                         $additional .= $result['keyword']."=$option\n";
255                                                 break;
256                                         default:
257                                                 $additional .= $result['keyword']."=$option\n";
258                                 }
259                         }
260                 }
261
262                 $sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
263                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
264                 if(DB::IsError($results)) {
265                 die($results->getMessage());
266                 }
267
268                 foreach ($results as $result) {
269                         $account = $result['data'];
270                         $id = $result['id'];
271                         $output .= "[$account]\n";
272        
273                         $sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
274                         $results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
275                         if(DB::IsError($results2)) {
276                         die($results2->getMessage());
277                         }
278                         foreach ($results2 as $result2) {
279                                 $options = explode("&", $result2['data']);
280                                 if ($ver12) {
281                                         foreach ($options as $option) {
282                                                 $output .= $result2['keyword']."=$option\n";
283                                         }
284                                 } else {
285                                         foreach ($options as $option) {
286                                                 switch ($result2['keyword']) {
287                                                         case 'allow':
288                                                         case 'disallow':
289                                                                 if ($option != '')
290                                                                         $output .= $result2['keyword']."=$option\n";
291                                                                 break;
292                                                         default:
293                                                                 $output .= $result2['keyword']."=$option\n";
294                                                 }
295                                         }
296                                 }
297                         }
298                         if ($call_limit && (substr($id,0,4) != "9999" | $id < 99990)) {
299
300                                 $output .= $call_limit;
301                         }
302                         $output .= $additional."\n";
303                 }
304                 return $output;
305         }
306
307         function generate_sip_registrations($ast_version) {
308                 global $db;
309
310                 $table_name = "sip";
311                 $output = "";
312
313                 // items with id like 9999999% get put in registrations file
314                 //
315                 $sql = "SELECT keyword,data from $table_name where id LIKE '9999999%' and keyword <> 'account' and flags <> 1";
316                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
317                 if(DB::IsError($results)) {
318                 die($results->getMessage());
319                 }
320
321                 foreach ($results as $result) {
322                         $output .= $result['keyword']."=".$result['data']."\n";
323                 }
324
325                 return $output;
326         }
327
328         function generate_iax_additional($ast_version) {
329                 global $db;
330
331                 $table_name = "iax";
332                 $additional = "";
333                 $output = "";
334
335                 $ver12 = version_compare($ast_version, '1.4', 'lt');
336
337                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
338                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
339                 if(DB::IsError($results)) {
340                 die($results->getMessage());
341                 }
342                 foreach ($results as $result) {
343                         if ($ver12) {
344                                 $additional .= $result['keyword']."=".$result['data']."\n";
345                         } else {
346                                 $option = $result['data'];
347                                 switch ($result['keyword']) {
348                                         case 'notransfer':
349                                                 if (strtolower($option) == 'yes') {
350                                                         $additional .= "transfer=no\n";
351                                                 } else if (strtolower($option) == 'no') {
352                                                         $additional .= "transfer=yes\n";
353                                                 } else if (strtolower($option) == 'mediaonly') {
354                                                         $additional .= "transfer=mediaonly\n";
355                                                 } else {
356                                                         $additional .= $result['keyword']."=$option\n";
357                                                 }
358                                                 break;
359                                         case 'allow':
360                                         case 'disallow':
361                                                 if ($option != '')
362                                                         $additional .= $result['keyword']."=$option\n";
363                                                 break;
364                                         default:
365                                                 $additional .= $result['keyword']."=$option\n";
366                                 }
367                         }
368                 }
369
370                 $sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
371                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
372                 if(DB::IsError($results)) {
373                 die($results->getMessage());
374                 }
375                
376                 foreach ($results as $result) {
377                         $account = $result['data'];
378                         $id = $result['id'];
379                         $output .= "[$account]\n";
380        
381                         $sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
382                         $results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
383                         if(DB::IsError($results2)) {
384                         die($results2->getMessage());
385                         }       
386                         foreach ($results2 as $result2) {
387                                 $options = explode("&", $result2['data']);
388                                 if ($ver12) {
389                                         foreach ($options as $option) {
390                                                 $output .= $result2['keyword']."=$option\n";
391                                         }
392                                 } else {
393                                         foreach ($options as $option) {
394                                                 switch ($result2['keyword']) {
395                                                         case 'notransfer':
396                                                                 if (strtolower($option) == 'yes') {
397                                                                         $output .= "transfer=no\n";
398                                                                 } else if (strtolower($option) == 'no') {
399                                                                         $output .= "transfer=yes\n";
400                                                                 } else if (strtolower($option) == 'mediaonly') {
401                                                                         $output .= "transfer=mediaonly\n";
402                                                                 } else {
403                                                                         $output .= $result2['keyword']."=$option\n";
404                                                                 }
405                                                                 break;
406                                                         case 'allow':
407                                                         case 'disallow':
408                                                                 if ($option != '')
409                                                                         $output .= $result2['keyword']."=$option\n";
410                                                                 break;
411                                                         default:
412                                                                 $output .= $result2['keyword']."=$option\n";
413                                                 }
414                                         }
415                                 }
416                         }
417                         $output .= $additional."\n";
418                 }
419                 return $output;
420         }
421
422         function generate_iax_registrations($ast_version) {
423                 global $db;
424
425                 $table_name = "iax";
426                 $output = "";
427
428                 // items with id like 9999999% get put in the registration file
429                 //
430                 $sql = "SELECT keyword,data from $table_name where id LIKE '9999999%' and keyword <> 'account' and flags <> 1";
431                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
432                 if(DB::IsError($results)) {
433                 die($results->getMessage());
434                 }
435
436                 foreach ($results as $result) {
437                         $output .= $result['keyword']."=".$result['data']."\n";
438                 }
439
440                 return $output;
441         }
442
443         function generate_h323_additional($ast_version) {
444                 global $db;
445
446                 $table_name = "h323";
447                 $additional = "";
448                 $output = "";
449
450                 $ver12 = version_compare($ast_version, '1.4', 'lt');
451
452                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
453                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
454                 if(DB::IsError($results)) {
455                 die($results->getMessage());