5 * Asterisk manager interface for access to asterisk api (astdb)
9 * Asterisk Manager Interface
11 class AsteriskManagerInterface {
18 function AsteriskManagerInterface() {
22 * Reloads Asterisk Configuration
25 * asterisk manager interface username
27 * asterisk manager interface password
29 function connect($host,$username,$password) {
32 $fp = fsockopen($host, 5038, $errno, $errstr, 10);
38 if(version_compare(phpversion(), '4.3', '>=')) {
39 stream_set_timeout($fp, 5);
42 socket_set_timeout($fp, 5);
45 if (!preg_match('/Asterisk Call Manager/i', $buffer)) {
46 $_SESSION['ari_error'] = _("Asterisk Call Manager not responding") . "<br />\n";
50 $out="Action: Login\r\nUsername: ".$username."\r\nSecret: ".$password."\r\n\r\n";
53 if ($buffer!="Response: Success\r\n") {
54 $_SESSION['ari_error'] = _("Asterisk authentication failed:") . "<br />" . $buffer . "<br />\n";
58 $buffers=fgets($fp); // get rid of Message: Authentication accepted
69 * Reloads Asterisk Configuration
71 function disconnect() {
74 fclose($this->socket);
79 * Reloads Asterisk Configuration
82 * Command to be sent to the asterisk manager interface
84 * response from asterisk manager interface
86 function command($command) {
90 fwrite($this->socket,$command);
93 while (($buffer = fgets($this->socket)) && (!preg_match('/Response: Follows/i', $buffer))) {
96 $_SESSION['ari_error'] = _("Asterisk command not understood") . "<br />" . $buffer . "<br />\n";
103 while (($buffer = fgets($this->socket)) && (!preg_match('/END COMMAND/i', $buffer))) {
105 if (preg_match('/Value/',$buffer)) {
106 $parts = split(' ',trim($buffer));
107 $response = $parts[1];
111 $_SESSION['ari_error'] = _("Asterisk command not understood") . "<br />" . $buffer . "<br />\n";
120 function command2($command) {
124 fwrite($this->socket,$command);
127 while (($buffer = fgets($this->socket)) && (!preg_match('/Response: Follows/i', $buffer))) {
130 $_SESSION['ari_error'] = _("Asterisk command not understood") . "<br />" . $buffer . "<br />\n";
137 while (($buffer = fgets($this->socket)) && (!preg_match('/END COMMAND/i', $buffer))) {
139 if (preg_match('/Value:/',$buffer)) {
140 $parts = split('Value:',trim($buffer));
141 $response = $parts[1];
144 $_SESSION['ari_error'] = _("Asterisk command not understood") . "<br />" . $buffer . "<br />\n";