| 35 | | function ast_with_dahdi() { |
|---|
| 36 | | global $astman; |
|---|
| 37 | | global $amp_conf; |
|---|
| 38 | | |
|---|
| 39 | | if (!$amp_conf['ZAP2DAHDICOMPAT']) { |
|---|
| 40 | | return false; |
|---|
| 41 | | } |
|---|
| 42 | | |
|---|
| 43 | | $engine_info = engine_getinfo(); |
|---|
| 44 | | $version = $engine_info['version']; |
|---|
| 45 | | |
|---|
| 46 | | if (version_compare($version, '1.4', 'ge') && $amp_conf['AMPENGINE'] == 'asterisk') { |
|---|
| 47 | | if (isset($astman) && $astman->connected()) { |
|---|
| 48 | | $response = $astman->send_request('Command', array('Command' => 'module show like chan_dahdi')); |
|---|
| 49 | | if (preg_match('/1 modules loaded/', $response['data'])) { |
|---|
| 50 | | return true; |
|---|
| 51 | | } |
|---|
| 52 | | } |
|---|
| 53 | | } |
|---|
| 54 | | return false; |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | function engine_getinfo() { |
|---|
| 58 | | global $amp_conf; |
|---|
| 59 | | global $astman; |
|---|
| 60 | | |
|---|
| 61 | | switch ($amp_conf['AMPENGINE']) { |
|---|
| 62 | | case 'asterisk': |
|---|
| 63 | | if (isset($astman) && $astman->connected()) { |
|---|
| 64 | | //get version (1.4) |
|---|
| 65 | | $response = $astman->send_request('Command', array('Command'=>'core show version')); |
|---|
| 66 | | if (preg_match('/No such command/',$response['data'])) { |
|---|
| 67 | | // get version (1.2) |
|---|
| 68 | | $response = $astman->send_request('Command', array('Command'=>'show version')); |
|---|
| 69 | | } |
|---|
| 70 | | $verinfo = $response['data']; |
|---|
| 71 | | } else { |
|---|
| 72 | | // could not connect to asterisk manager, try console |
|---|
| 73 | | $verinfo = exec('asterisk -V'); |
|---|
| 74 | | } |
|---|
| 75 | | |
|---|
| 76 | | if (preg_match('/Asterisk (\d+(\.\d+)*)(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 77 | | return array('engine'=>'asterisk', 'version' => $matches[1], 'additional' => $matches[4], 'raw' => $verinfo); |
|---|
| 78 | | } elseif (preg_match('/Asterisk SVN-(\d+(\.\d+)*)(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 79 | | return array('engine'=>'asterisk', 'version' => $matches[1], 'additional' => $matches[4], 'raw' => $verinfo); |
|---|
| 80 | | } elseif (preg_match('/Asterisk SVN-branch-(\d+(\.\d+)*)-r(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 81 | | return array('engine'=>'asterisk', 'version' => $matches[1].'.'.$matches[4], 'additional' => $matches[4], 'raw' => $verinfo); |
|---|
| 82 | | } elseif (preg_match('/Asterisk SVN-trunk-r(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 83 | | return array('engine'=>'asterisk', 'version' => '1.6', 'additional' => $matches[1], 'raw' => $verinfo); |
|---|
| 84 | | } elseif (preg_match('/Asterisk SVN-.+-(\d+(\.\d+)*)-r(-?(\S*))-(.+)/', $verinfo, $matches)) { |
|---|
| 85 | | return array('engine'=>'asterisk', 'version' => $matches[1], 'additional' => $matches[3], 'raw' => $verinfo); |
|---|
| 86 | | } elseif (preg_match('/Asterisk [B].(\d+(\.\d+)*)(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 87 | | return array('engine'=>'asterisk', 'version' => '1.2', 'additional' => $matches[3], 'raw' => $verinfo); |
|---|
| 88 | | } elseif (preg_match('/Asterisk [C].(\d+(\.\d+)*)(-?(\S*))/', $verinfo, $matches)) { |
|---|
| 89 | | return array('engine'=>'asterisk', 'version' => '1.4', 'additional' => $matches[3], 'raw' => $verinfo); |
|---|
| 90 | | } |
|---|
| 91 | | |
|---|
| 92 | | return array('engine'=>'ERROR-UNABLE-TO-PARSE', 'version'=>'0', 'additional' => '0', 'raw' => $verinfo); |
|---|
| 93 | | break; |
|---|
| 94 | | } |
|---|
| 95 | | return array('engine'=>'ERROR-UNSUPPORTED-ENGINE-'.$amp_conf['AMPENGINE'], 'version'=>'0', 'additional' => '0', 'raw' => $verinfo); |
|---|
| 96 | | } |
|---|