| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
* phpagi.php : PHP AGI Functions for Asterisk |
|---|
| 5 |
* Website: http://phpagi.sourceforge.net/ |
|---|
| 6 |
* |
|---|
| 7 |
* $Id$ |
|---|
| 8 |
* |
|---|
| 9 |
* Copyright (c) 2003, 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us> |
|---|
| 10 |
* All Rights Reserved. |
|---|
| 11 |
* |
|---|
| 12 |
* This software is released under the terms of the GNU Lesser General Public License v2.1 |
|---|
| 13 |
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html |
|---|
| 14 |
* |
|---|
| 15 |
* We would be happy to list your phpagi based application on the phpagi |
|---|
| 16 |
* website. Drop me an Email if you'd like us to list your program. |
|---|
| 17 |
* |
|---|
| 18 |
* |
|---|
| 19 |
* Written for PHP 4.3.4, should work with older PHP 4.x versions. |
|---|
| 20 |
* |
|---|
| 21 |
* Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ |
|---|
| 22 |
* Gracias. :) |
|---|
| 23 |
* |
|---|
| 24 |
* |
|---|
| 25 |
* @package phpAGI |
|---|
| 26 |
* @version 2.0 |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
/** |
|---|
| 30 |
*/ |
|---|
| 31 |
|
|---|
| 32 |
if(!class_exists('AGI_AsteriskManager')) |
|---|
| 33 |
{ |
|---|
| 34 |
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi-asmanager.php'); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
define('AST_CONFIG_DIR', '/etc/asterisk/'); |
|---|
| 38 |
define('AST_SPOOL_DIR', '/var/spool/asterisk/'); |
|---|
| 39 |
define('AST_TMP_DIR', AST_SPOOL_DIR . '/tmp/'); |
|---|
| 40 |
define('DEFAULT_PHPAGI_CONFIG', AST_CONFIG_DIR . '/phpagi.conf'); |
|---|
| 41 |
|
|---|
| 42 |
define('AST_DIGIT_ANY', '0123456789#*'); |
|---|
| 43 |
|
|---|
| 44 |
define('AGIRES_OK', 200); |
|---|
| 45 |
|
|---|
| 46 |
define('AST_STATE_DOWN', 0); |
|---|
| 47 |
define('AST_STATE_RESERVED', 1); |
|---|
| 48 |
define('AST_STATE_OFFHOOK', 2); |
|---|
| 49 |
define('AST_STATE_DIALING', 3); |
|---|
| 50 |
define('AST_STATE_RING', 4); |
|---|
| 51 |
define('AST_STATE_RINGING', 5); |
|---|
| 52 |
define('AST_STATE_UP', 6); |
|---|
| 53 |
define('AST_STATE_BUSY', 7); |
|---|
| 54 |
define('AST_STATE_DIALING_OFFHOOK', 8); |
|---|
| 55 |
define('AST_STATE_PRERING', 9); |
|---|
| 56 |
|
|---|
| 57 |
define('AUDIO_FILENO', 3); |
|---|
| 58 |
|
|---|
| 59 |
/** |
|---|
| 60 |
* AGI class |
|---|
| 61 |
* |
|---|
| 62 |
* @package phpAGI |
|---|
| 63 |
* @link http://www.voip-info.org/wiki-Asterisk+agi |
|---|
| 64 |
* @example examples/dtmf.php Get DTMF tones from the user and say the digits |
|---|
| 65 |
* @example examples/input.php Get text input from the user and say it back |
|---|
| 66 |
* @example examples/ping.php Ping an IP address |
|---|
| 67 |
*/ |
|---|
| 68 |
class AGI |
|---|
| 69 |
{ |
|---|
| 70 |
|
|---|
| 71 |
* Request variables read in on initialization. |
|---|
| 72 |
* |
|---|
| 73 |
* Often contains any/all of the following: |
|---|
| 74 |
* agi_request - name of agi script |
|---|
| 75 |
* agi_channel - current channel |
|---|
| 76 |
* agi_language - current language |
|---|
| 77 |
* agi_type - channel type (SIP, ZAP, IAX, ...) |
|---|
| 78 |
* agi_uniqueid - unique id based on unix time |
|---|
| 79 |
* agi_callerid - callerID string |
|---|
| 80 |
* agi_dnid - dialed number id |
|---|
| 81 |
* agi_rdnis - referring DNIS number |
|---|
| 82 |
* agi_context - current context |
|---|
| 83 |
* agi_extension - extension dialed |
|---|
| 84 |
* agi_priority - current priority |
|---|
| 85 |
* agi_enhanced - value is 1.0 if started as an EAGI script |
|---|
| 86 |
* agi_accountcode - set by SetAccount in the dialplan |
|---|
| 87 |
* agi_network - value is yes if this is a fastagi |
|---|
| 88 |
* agi_network_script - name of the script to execute |
|---|
| 89 |
* |
|---|
| 90 |
* NOTE: program arguments are still in $_SERVER['argv']. |
|---|
| 91 |
* |
|---|
| 92 |
* @var array |
|---|
| 93 |
* @access public |
|---|
| 94 |
*/ |
|---|
| 95 |
var $request; |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
* Config variables |
|---|
| 99 |
* |
|---|
| 100 |
* @var array |
|---|
| 101 |
* @access public |
|---|
| 102 |
*/ |
|---|
| 103 |
var $config; |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
* Asterisk Manager |
|---|
| 107 |
* |
|---|
| 108 |
* @var AGI_AsteriskManager |
|---|
| 109 |
* @access public |
|---|
| 110 |
*/ |
|---|
| 111 |
var $asmanager; |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* Input Stream |
|---|
| 115 |
* |
|---|
| 116 |
* @access private |
|---|
| 117 |
*/ |
|---|
| 118 |
var $in = NULL; |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
* Output Stream |
|---|
| 122 |
* |
|---|
| 123 |
* @access private |
|---|
| 124 |
*/ |
|---|
| 125 |
var $out = NULL; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
* FastAGI socket |
|---|
| 129 |
* |
|---|
| 130 |
* @access private |
|---|
| 131 |
*/ |
|---|
| 132 |
var $socket = NULL; |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
* Audio Stream |
|---|
| 136 |
* |
|---|
| 137 |
* @access public |
|---|
| 138 |
*/ |
|---|
| 139 |
var $audio = NULL; |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
* Constructor |
|---|
| 143 |
* |
|---|
| 144 |
* @param string $config is the name of the config file to parse |
|---|
| 145 |
* @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['phpagi'] |
|---|
| 146 |
*/ |
|---|
| 147 |
function AGI($config=NULL, $optconfig=array(), $socket=NULL) |
|---|
| 148 |
{ |
|---|
| 149 |
|
|---|
| 150 |
if(!is_null($config) && file_exists($config)) |
|---|
| 151 |
$this->config = parse_ini_file($config, true); |
|---|
| 152 |
elseif(file_exists(DEFAULT_PHPAGI_CONFIG)) |
|---|
| 153 |
$this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true); |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
foreach($optconfig as $var=>$val) |
|---|
| 157 |
$this->config['phpagi'][$var] = $val; |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
if(!isset($this->config['phpagi']['error_handler'])) $this->config['phpagi']['error_handler'] = true; |
|---|
| 161 |
if(!isset($this->config['phpagi']['debug'])) $this->config['phpagi']['debug'] = false; |
|---|
| 162 |
if(!isset($this->config['phpagi']['admin'])) $this->config['phpagi']['admin'] = NULL; |
|---|
| 163 |
if(!isset($this->config['phpagi']['tempdir'])) $this->config['phpagi']['tempdir'] = AST_TMP_DIR; |
|---|
| 164 |
|
|---|
| 165 |
ob_implicit_flush(true); |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
if(is_null($socket)) |
|---|
| 169 |
{ |
|---|
| 170 |
$this->in = defined('STDIN') ? STDIN : fopen('php://stdin', 'r'); |
|---|
| 171 |
$this->out = defined('STDOUT') ? STDOUT : fopen('php://stdout', 'w'); |
|---|
| 172 |
} |
|---|
| 173 |
else |
|---|
| 174 |
$this->socket = $socket; |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
if($this->config['phpagi']['error_handler'] == true) |
|---|
| 178 |
{ |
|---|
| 179 |
set_error_handler('phpagi_error_handler'); |
|---|
| 180 |
global $phpagi_error_handler_email; |
|---|
| 181 |
$phpagi_error_handler_email = $this->config['phpagi']['admin']; |
|---|
| 182 |
error_reporting(E_ALL); |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
$this->make_folder($this->config['phpagi']['tempdir']); |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
$str = is_null($this->socket) ? fgets($this->in) : socket_read($this->socket, 4096, PHP_NORMAL_READ); |
|---|
| 190 |
while($str != "\n") |
|---|
| 191 |
{ |
|---|
| 192 |
$this->request[substr($str, 0, strpos($str, ':'))] = trim(substr($str, strpos($str, ':') + 1)); |
|---|
| 193 |
$str = is_null($this->socket) ? fgets($this->in) : socket_read($this->socket, 4096, PHP_NORMAL_READ); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
if($this->request['agi_enhanced'] == '1.0') |
|---|
| 198 |
{ |
|---|
| 199 |
if(file_exists('/proc/' . getmypid() . '/fd/3')) |
|---|
| 200 |
{ |
|---|
| 201 |
|
|---|
| 202 |
$this->audio = fopen('/proc/' . getmypid() . '/fd/3', 'r'); |
|---|
| 203 |
} |
|---|
| 204 |
elseif(file_exists('/dev/fd/3')) |
|---|
| 205 |
{ |
|---|
| 206 |
|
|---|
| 207 |
$this->audio = fopen('/dev/fd/3', 'r'); |
|---|
| 208 |
} |
|---|
| 209 |
else |
|---|
| 210 |
$this->conlog('Unable to open audio stream'); |
|---|
| 211 |
|
|---|
| 212 |
if($this->audio) stream_set_blocking($this->audio, 0); |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
$this->conlog('PHPAGI internal configuration:'); |
|---|
| 216 |
$this->conlog(print_r($this->config, true)); |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
function answer() |
|---|
| 237 |
|
|---|
| 238 |
$this->evaluate('ANSWER'); |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
function channel_status($channel='') |
|---|
| 249 |
|
|---|
| 250 |
$ret = $this->evaluate("CHANNEL STATUS $channel"); |
|---|
| 251 |
$ret['result']) |
|---|
| 252 |
|
|---|
| 253 |
1: $ret['data'] = trim("There is no channel that matches $channel"); break; |
|---|
| 254 |
AST_STATE_DOWN: $ret['data'] = 'Channel is down and available'; break; |
|---|
| 255 |
AST_STATE_RESERVED: $ret['data'] = 'Channel is down, but reserved'; break; |
|---|
| 256 |
AST_STATE_OFFHOOK: $ret['data'] = 'Channel is off hook'; break; |
|---|
| 257 |
AST_STATE_DIALING: $ret['data'] = 'Digits (or equivalent) have been dialed'; break; |
|---|
| 258 |
AST_STATE_RING: $ret['data'] = 'Line is ringing'; break; |
|---|
| 259 |
AST_STATE_RINGING: $ret['data'] = 'Remote end is ringing'; break; |
|---|
| 260 |
AST_STATE_UP: $ret['data'] = 'Line is up'; break; |
|---|
| 261 |
AST_STATE_BUSY: $ret['data'] = 'Line is busy'; break; |
|---|
| 262 |
AST_STATE_DIALING_OFFHOOK: $ret['data'] = 'Digits (or equivalent) have been dialed while offhook'; break; |
|---|
| 263 |
AST_STATE_PRERING: $ret['data'] = 'Channel has detected an incoming call and is waiting for ring'; break; |
|---|
| 264 |
$ret['data'] = "Unknown ({$ret['result']})"; break; |
|---|
| 265 |
|
|---|
| 266 |
$ret; |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
function database_del($family, $key) |
|---|
| 278 |
|
|---|
| 279 |
$this->evaluate("DATABASE DEL \"$family\" \"$key\""); |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
function database_deltree($family, $keytree='') |
|---|
| 291 |
|
|---|
| 292 |
$cmd = "DATABASE DELTREE \"$family\""; |
|---|
| 293 |
$keytree != '') $cmd .= " \"$keytree\""; |
|---|
| 294 |
$this->evaluate($cmd); |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
function database_get($family, $key) |
|---|
| 306 |
|
|---|
| 307 |
$this->evaluate("DATABASE GET \"$family\" \"$key\""); |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
function database_put($family, $key, $value) |
|---|
| 319 |
|
|---|
| 320 |
$value = str_replace("\n", '\n', addslashes($value)); |
|---|
| 321 |
$this->evaluate("DATABASE PUT \"$family\" \"$key\" \"$value\""); |
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
function exec($application, $options) |
|---|
| 334 |
|
|---|
| 335 |
is_array($options)) $options = join('|', $options); |
|---|
| 336 |
$this->evaluate("EXEC $application $options"); |
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
function get_data($filename, $timeout=NULL, $max_digits=NULL) |
|---|
| 377 |
|
|---|
| 378 |
$this->evaluate(rtrim("GET DATA $filename $timeout $max_digits")); |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
function get_variable($variable) |
|---|
| 392 |
|
|---|
| 393 |
$this->evaluate("GET VARIABLE $variable"); |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
function hangup($channel='') |
|---|
| 411 |
|
|---|
| 412 |
$this->evaluate("HANGUP $channel"); |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
function noop() |
|---|
| 422 |
|
|---|
| 423 |
$this->evaluate('NOOP'); |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
function receive_char($timeout=-1) |
|---|
| 436 |
|
|---|
| 437 |
$this->evaluate("RECEIVE CHAR $timeout"); |
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
function record_file($file, $format, $escape_digits='', $timeout=-1, $offset=NULL, $beep=false, $silence=NULL) |
|---|
| 457 |
|
|---|
| 458 |
$cmd = trim("RECORD FILE $file $format \"$escape_digits\" $timeout $offset"); |
|---|
| 459 |
$beep) $cmd .= ' BEEP'; |
|---|
| 460 |
is_null($silence)) $cmd .= " s=$silence"; |
|---|
| 461 |
$this->evaluate($cmd); |
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
function say_digits($digits, $escape_digits='') |
|---|
| 474 |
|
|---|
| 475 |
$this->evaluate("SAY DIGITS $digits \"$escape_digits\""); |
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
function say_number($number, $escape_digits='') |
|---|
| 488 |
|
|---|
| 489 |
$this->evaluate("SAY NUMBER $number \"$escape_digits\""); |
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
function say_phonetic($text, $escape_digits='') |
|---|
| 502 |
|
|---|
| 503 |
$this->evaluate("SAY PHONETIC $text \"$escape_digits\""); |
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
function say_time($time=NULL, $escape_digits='') |
|---|
| 516 |
|
|---|
| 517 |
is_null($time)) $time = time(); |
|---|
| 518 |
$this->evaluate("SAY TIME $time \"$escape_digits\""); |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
function send_image($image) |
|---|
| 532 |
|
|---|
| 533 |
$this->evaluate("SEND IMAGE $image"); |
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
function send_text($text) |
|---|
| 547 |
|
|---|
| 548 |
$this->evaluate("SEND TEXT \"$text\""); |
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
function set_autohangup($time=0) |
|---|
| 562 |
|
|---|
| 563 |
$this->evaluate("SET AUTOHANGUP $time"); |
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
function set_callerid($cid) |
|---|
| 579 |
|
|---|
| 580 |
$this->evaluate("SET CALLERID $cid"); |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
function set_context($context) |
|---|
| 597 |
|
|---|
| 598 |
$this->evaluate("SET CONTEXT $context"); |
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
function set_extension($extension) |
|---|
| 615 |
|
|---|
| 616 |
$this->evaluate("SET EXTENSION $extension"); |
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
function set_music($enabled=true, $class='') |
|---|
| 628 |
|
|---|
| 629 |
$enabled = ($enabled) ? 'ON' : 'OFF'; |
|---|
| 630 |
$this->evaluate("SET MUSIC $enabled $class"); |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
function set_priority($priority) |
|---|
| 644 |
|
|---|
| 645 |
$this->evaluate("SET PRIORITY $priority"); |
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
function set_variable($variable, $value) |
|---|
| 662 |
|
|---|
| 663 |
$value = str_replace("\n", '\n', addslashes($value)); |
|---|
| 664 |
$this->evaluate("SET VARIABLE $variable \"$value\""); |
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
|
|---|
| 681 |
function stream_file($filename, $escape_digits='', $offset=0) |
|---|
| 682 |
|
|---|
| 683 |
$this->evaluate("STREAM FILE $filename \"$escape_digits\" $offset"); |
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
function tdd_mode($setting) |
|---|
| 694 |
|
|---|
| 695 |
$this->evaluate("TDD MODE $setting"); |
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 |
function verbose($message, $level=1) |
|---|
| 714 |
|
|---|
| 715 |
explode("\n", str_replace("\r\n", "\n", print_r($message, true))) as $msg) |
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
|
|---|
| 719 |
$ret = $this->evaluate("VERBOSE \"$msg\" $level"); |
|---|
| 720 |
|
|---|
| 721 |
$ret; |
|---|
| 722 |
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 |
function wait_for_digit($timeout=-1) |
|---|
| 733 |
|
|---|
| 734 |
$this->evaluate("WAIT FOR DIGIT $timeout"); |
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
function exec_absolutetimeout($seconds=0) |
|---|
| 756 |
|
|---|
| 757 |
$this->exec('AbsoluteTimeout', $seconds); |
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
function exec_agi($command, $args) |
|---|
| 769 |
|
|---|
| 770 |
$this->exec("AGI $command", $args); |
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
function exec_setaccountcode($accountcode) |
|---|
| 782 |
|
|---|
| 783 |
$this->exec('SetAccount', $accountcode); |
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 |
|
|---|
| 791 |
|
|---|
| 792 |
function exec_setlanguage($language='en') |
|---|
| 793 |
|
|---|
| 794 |
$this->exec('SetLanguage', $language); |
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
function exec_sipaddheader($header, $value) |
|---|
| 805 |
|
|---|
| 806 |
$this->exec('SIPAddHeader', '"'.$header.":".$value.'"'); |
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 |
function set_alertinfo($value) |
|---|
| 816 |
|
|---|
| 817 |
$this->exec_sipaddheader('Alert-Info',$value); |
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
|
|---|
| 822 |
|
|---|
| 823 |
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 |
|
|---|
| 828 |
|
|---|
| 829 |
function exec_enumlookup($exten) |
|---|
| 830 |
|
|---|
| 831 |
$this->exec('EnumLookup', $exten); |
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
|
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 |
function exec_dial($type, $identifier, $timeout=NULL, $options=NULL, $url=NULL) |
|---|
| 851 |
|
|---|
| 852 |
$this->exec('Dial', trim("$type/$identifier|$timeout|$options|$url", '|')); |
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 |
|
|---|
| 864 |
|
|---|
| 865 |
|
|---|
| 866 |
function exec_goto($a, $b=NULL, $c=NULL) |
|---|
| 867 |
|
|---|
| 868 |
$this->exec('Goto', trim("$a|$b|$c", '|')); |
|---|
| 869 |
|
|---|
| 870 |
|
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 |
|
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 |
|
|---|
| 885 |
|
|---|
| 886 |
|
|---|
| 887 |
function fastpass_say_digits(&$buffer, $digits, $escape_digits='') |
|---|
| 888 |
|
|---|
| 889 |
$proceed = false; |
|---|
| 890 |
$escape_digits != '' && $buffer != '') |
|---|
| 891 |
|
|---|
| 892 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 893 |
$proceed = true; |
|---|
| 894 |
|
|---|
| 895 |
$buffer == '' || $proceed) |
|---|
| 896 |
|
|---|
| 897 |
$res = $this->say_digits($digits, $escape_digits); |
|---|
| 898 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 899 |
$buffer .= chr($res['result']); |
|---|
| 900 |
$res; |
|---|
| 901 |
|
|---|
| 902 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); |
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
|
|---|
| 911 |
|
|---|
| 912 |
|
|---|
| 913 |
|
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
function fastpass_say_number(&$buffer, $number, $escape_digits='') |
|---|
| 917 |
|
|---|
| 918 |
$proceed = false; |
|---|
| 919 |
$escape_digits != '' && $buffer != '') |
|---|
| 920 |
|
|---|
| 921 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 922 |
$proceed = true; |
|---|
| 923 |
|
|---|
| 924 |
$buffer == '' || $proceed) |
|---|
| 925 |
|
|---|
| 926 |
$res = $this->say_number($number, $escape_digits); |
|---|
| 927 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 928 |
$buffer .= chr($res['result']); |
|---|
| 929 |
$res; |
|---|
| 930 |
|
|---|
| 931 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); |
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 |
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
function fastpass_say_phonetic(&$buffer, $text, $escape_digits='') |
|---|
| 946 |
|
|---|
| 947 |
$proceed = false; |
|---|
| 948 |
$escape_digits != '' && $buffer != '') |
|---|
| 949 |
|
|---|
| 950 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 951 |
$proceed = true; |
|---|
| 952 |
|
|---|
| 953 |
$buffer == '' || $proceed) |
|---|
| 954 |
|
|---|
| 955 |
$res = $this->say_phonetic($text, $escape_digits); |
|---|
| 956 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 957 |
$buffer .= chr($res['result']); |
|---|
| 958 |
$res; |
|---|
| 959 |
|
|---|
| 960 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); |
|---|
| 961 |
|
|---|
| 962 |
|
|---|
| 963 |
|
|---|
| 964 |
|
|---|
| 965 |
|
|---|
| 966 |
|
|---|
| 967 |
|
|---|
| 968 |
|
|---|
| 969 |
|
|---|
| 970 |
|
|---|
| 971 |
|
|---|
| 972 |
|
|---|
| 973 |
|
|---|
| 974 |
function fastpass_say_time(&$buffer, $time=NULL, $escape_digits='') |
|---|
| 975 |
|
|---|
| 976 |
$proceed = false; |
|---|
| 977 |
$escape_digits != '' && $buffer != '') |
|---|
| 978 |
|
|---|
| 979 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 980 |
$proceed = true; |
|---|
| 981 |
|
|---|
| 982 |
$buffer == '' || $proceed) |
|---|
| 983 |
|
|---|
| 984 |
$res = $this->say_time($time, $escape_digits); |
|---|
| 985 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 986 |
$buffer .= chr($res['result']); |
|---|
| 987 |
$res; |
|---|
| 988 |
|
|---|
| 989 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); |
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 |
|
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
|
|---|
| 996 |
|
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
|
|---|
| 1000 |
|
|---|
| 1001 |
|
|---|
| 1002 |
|
|---|
| 1003 |
|
|---|
| 1004 |
|
|---|
| 1005 |
|
|---|
| 1006 |
function fastpass_stream_file(&$buffer, $filename, $escape_digits='', $offset=0) |
|---|
| 1007 |
|
|---|
| 1008 |
$proceed = false; |
|---|
| 1009 |
$escape_digits != '' && $buffer != '') |
|---|
| 1010 |
|
|---|
| 1011 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 1012 |
$proceed = true; |
|---|
| 1013 |
|
|---|
| 1014 |
$buffer == '' || $proceed) |
|---|
| 1015 |
|
|---|
| 1016 |
$res = $this->stream_file($filename, $escape_digits, $offset); |
|---|
| 1017 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 1018 |
$buffer .= chr($res['result']); |
|---|
| 1019 |
$res; |
|---|
| 1020 |
|
|---|
| 1021 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); |
|---|
| 1022 |
|
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 |
|
|---|
| 1026 |
|
|---|
| 1027 |
|
|---|
| 1028 |
|
|---|
| 1029 |
|
|---|
| 1030 |
|
|---|
| 1031 |
|
|---|
| 1032 |
|
|---|
| 1033 |
|
|---|
| 1034 |
|
|---|
| 1035 |
function fastpass_text2wav(&$buffer, $text, $escape_digits='', $frequency=8000) |
|---|
| 1036 |
|
|---|
| 1037 |
$proceed = false; |
|---|
| 1038 |
$escape_digits != '' && $buffer != '') |
|---|
| 1039 |
|
|---|
| 1040 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 1041 |
$proceed = true; |
|---|
| 1042 |
|
|---|
| 1043 |
$buffer == '' || $proceed) |
|---|
| 1044 |
|
|---|
| 1045 |
$res = $this->text2wav($text, $escape_digits, $frequency); |
|---|
| 1046 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 1047 |
$buffer .= chr($res['result']); |
|---|
| 1048 |
$res; |
|---|
| 1049 |
|
|---|
| 1050 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); |
|---|
| 1051 |
|
|---|
| 1052 |
|
|---|
| 1053 |
|
|---|
| 1054 |
|
|---|
| 1055 |
|
|---|
| 1056 |
|
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
|
|---|
| 1060 |
|
|---|
| 1061 |
|
|---|
| 1062 |
|
|---|
| 1063 |
|
|---|
| 1064 |
function fastpass_swift(&$buffer, $text, $escape_digits='', $frequency=8000, $voice=NULL) |
|---|
| 1065 |
|
|---|
| 1066 |
$proceed = false; |
|---|
| 1067 |
$escape_digits != '' && $buffer != '') |
|---|
| 1068 |
|
|---|
| 1069 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 1070 |
$proceed = true; |
|---|
| 1071 |
|
|---|
| 1072 |
$buffer == '' || $proceed) |
|---|
| 1073 |
|
|---|
| 1074 |
$res = $this->swift($text, $escape_digits, $frequency, $voice); |
|---|
| 1075 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 1076 |
$buffer .= chr($res['result']); |
|---|
| 1077 |
$res; |
|---|
| 1078 |
|
|---|
| 1079 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); |
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
|
|---|
| 1083 |
|
|---|
| 1084 |
|
|---|
| 1085 |
|
|---|
| 1086 |
|
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
|
|---|
| 1092 |
function fastpass_say_punctuation(&$buffer, $text, $escape_digits='', $frequency=8000) |
|---|
| 1093 |
|
|---|
| 1094 |
$proceed = false; |
|---|
| 1095 |
$escape_digits != '' && $buffer != '') |
|---|
| 1096 |
|
|---|
| 1097 |
strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) |
|---|
| 1098 |
$proceed = true; |
|---|
| 1099 |
|
|---|
| 1100 |
$buffer == '' || $proceed) |
|---|
| 1101 |
|
|---|
| 1102 |
$res = $this->say_punctuation($text, $escape_digits, $frequency); |
|---|
| 1103 |
$res['code'] == AGIRES_OK && $res['result'] > 0) |
|---|
| 1104 |
$buffer .= chr($res['result']); |
|---|
| 1105 |
$res; |
|---|
| 1106 |
|
|---|
| 1107 |
'code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); |
|---|
| 1108 |
|
|---|
| 1109 |
|
|---|
| 1110 |
|
|---|
| 1111 |
|
|---|
| 1112 |
|
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 |
|
|---|
| 1119 |
|
|---|
| 1120 |
|
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
|
|---|
| 1128 |
|
|---|
| 1129 |
|
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 |
|
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 |
|
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
|
|---|
| 1146 |
|
|---|
| 1147 |
function fastpass_get_data(&$buffer, $filename, $timeout=NULL, $max_digits=NULL) |
|---|
| 1148 |
|
|---|
| 1149 |
is_null($max_digits) || strlen($buffer) < $max_digits) |
|---|
| 1150 |
|
|---|
| 1151 |
$buffer == '') |
|---|
| 1152 |
|
|---|
| 1153 |
$res = $this->get_data($filename, $timeout, $max_digits); |
|---|
| 1154 |
$res['code'] == AGIRES_OK) |
|---|
| 1155 |
$buffer .= $res['result']; |
|---|
| 1156 |
$res; |
|---|
| 1157 |
|
|---|
| 1158 |
|
|---|
| 1159 |
|
|---|
| 1160 |
is_null($max_digits) || strlen($buffer) < $max_digits) |
|---|
| 1161 |
|
|---|
| 1162 |
$res = $this->wait_for_digit(); |
|---|
| 1163 |
$res['code'] != AGIRES_OK) return $res; |
|---|
| 1164 |
$res['result'] == ord('#')) break; |
|---|
| 1165 |
$buffer .= chr($res['result']); |
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 |
|
|---|
| 1169 |
'code'=>AGIRES_OK, 'result'=>$buffer); |
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 |
|
|---|
| 1173 |
|
|---|
| 1174 |
|
|---|
| 1175 |
|
|---|
| 1176 |
|
|---|
| 1177 |
|
|---|
| 1178 |
|
|---|
| 1179 |
|
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
|
|---|
| 1183 |
|
|---|
| 1184 |
|
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 |
function menu($choices, $timeout=2000) |
|---|
| 1188 |
|
|---|
| 1189 |
$keys = join('', array_keys($choices)); |
|---|
| 1190 |
$choice = NULL; |
|---|
| 1191 |
is_null($choice)) |
|---|
| 1192 |
|
|---|
| 1193 |
$choices as $prompt) |
|---|
| 1194 |
|
|---|
| 1195 |
$prompt{0} == '*') |
|---|
| 1196 |
$ret = $this->text2wav(substr($prompt, 1), $keys); |
|---|
| 1197 |
|
|---|
| 1198 |
$ret = $this->stream_file($prompt, $keys); |
|---|
| 1199 |
|
|---|
| 1200 |
$ret['code'] != AGIRES_OK || $ret['result'] == -1) |
|---|
| 1201 |
|
|---|
| 1202 |
$choice = -1; |
|---|
| 1203 |
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 |
$ret['result'] != 0) |
|---|
| 1207 |
|
|---|
| 1208 |
$choice = chr($ret['result']); |
|---|
| 1209 |
|
|---|
| 1210 |
|
|---|
| 1211 |
|
|---|
| 1212 |
|
|---|
| 1213 |
is_null($choice)) |
|---|
| 1214 |
|
|---|
| 1215 |
$ret = $this->get_data('beep', $timeout, 1); |
|---|
| 1216 |
$ret['code'] != AGIRES_OK || $ret['result'] == -1) |
|---|
| 1217 |
$choice = -1; |
|---|
| 1218 |
$ret['result'] != '' && strpos(' '.$keys, $ret['result'])) |
|---|
| 1219 |
$choice = $ret['result']; |
|---|
| 1220 |
|
|---|
| 1221 |
|
|---|
| 1222 |
$choice; |
|---|
| 1223 |
|
|---|
| 1224 |
|
|---|
| 1225 |
|
|---|
| 1226 |
|
|---|
| 1227 |
|
|---|
| 1228 |
|
|---|
| 1229 |
|
|---|
| 1230 |
|
|---|
| 1231 |
|
|---|
| 1232 |
function goto($context, $extension='s', $priority=1) |
|---|
| 1233 |
|
|---|
| 1234 |
$this->set_context($context); |
|---|
| 1235 |
$this->set_extension($extension); |
|---|
| 1236 |
$this->set_priority($priority); |
|---|
| 1237 |
|
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 |
|
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|
| 1246 |
|
|---|
| 1247 |
|
|---|
| 1248 |
|
|---|
| 1249 |
|
|---|
| 1250 |
function parse_callerid($callerid=NULL) |
|---|
| 1251 |
|
|---|
| 1252 |
is_null($callerid)) |
|---|
| 1253 |
$callerid = $this->request['agi_callerid']; |
|---|
| 1254 |
|
|---|
| 1255 |
$ret = array('name'=>'', 'protocol'=>'', 'username'=>'', 'host'=>'', 'port'=>''); |
|---|
| 1256 |
$callerid = trim($callerid); |
|---|
| 1257 |
|
|---|
| 1258 |
$callerid{0} == '"' || $callerid{0} == "'") |
|---|
| 1259 |
|
|---|
| 1260 |
$d = $callerid{0}; |
|---|
| 1261 |
$callerid = explode($d, substr($callerid, 1)); |
|---|
| 1262 |
$ret['name'] = array_shift($callerid); |
|---|
| 1263 |
$callerid = join($d, $callerid); |
|---|
| 1264 |
|
|---|
| 1265 |
|
|---|
| 1266 |
$callerid = explode('@', trim($callerid, '<> ')); |
|---|
| 1267 |
$username = explode(':', array_shift($callerid)); |
|---|
| 1268 |
count($username) == 1) |
|---|
| 1269 |
$ret['username'] = $username[0]; |
|---|
| 1270 |
|
|---|
| 1271 |
|
|---|
| 1272 |
$ret['protocol'] = array_shift($username); |
|---|
| 1273 |
$ret['username'] = join(':', $username); |
|---|
| 1274 |
|
|---|
| 1275 |
|
|---|
| 1276 |
$callerid = join('@', $callerid); |
|---|
| 1277 |
$host = explode(':', $callerid); |
|---|
| 1278 |
count($host) == 1) |
|---|
| 1279 |
$ret['host'] = $host[0]; |
|---|
| 1280 |
|
|---|
| 1281 |
|
|---|
| 1282 |
$ret['host'] = array_shift($host); |
|---|
| 1283 |
$ret['port'] = join(':', $host); |
|---|
| 1284 |
|
|---|
| 1285 |
|
|---|
| 1286 |
$ret; |
|---|
| 1287 |
|
|---|
| 1288 |
|
|---|
| 1289 |
|
|---|
| 1290 |
|
|---|
| 1291 |
|
|---|
| 1292 |
|
|---|
| 1293 |
|
|---|
| 1294 |
|
|---|
| 1295 |
|
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 |
|
|---|
| 1299 |
|
|---|
| 1300 |
|
|---|
| 1301 |
|
|---|
| 1302 |
function text2wav($text, $escape_digits='', $frequency=8000) |
|---|
| 1303 |
|
|---|
| 1304 |
|
|---|
| 1305 |
if(!isset($this->config['festival']['text2wave'])) $this->config['festival']['text2wave'] = $this->which('text2wave'); |
|---|
| 1306 |
|
|---|
| 1307 |
$text = trim($text); |
|---|
| 1308 |
$text == '') return true; |
|---|
| 1309 |
|
|---|
| 1310 |
$hash = md5($text); |
|---|
| 1311 |
$fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR; |
|---|
| 1312 |
$fname .= 'text2wav_' . $hash; |
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
if(!file_exists("$fname.wav")) |
|---|
| 1316 |
|
|---|
| 1317 |
|
|---|
| 1318 |
if(!file_exists("$fname.txt")) |
|---|
| 1319 |
|
|---|
| 1320 |
$fp = fopen("$fname.txt", 'w'); |
|---|
| 1321 |
fputs($fp, $text); |
|---|
| 1322 |
fclose($fp); |
|---|
| 1323 |
|
|---|
| 1324 |
|
|---|
| 1325 |
shell_exec("{$this->config['festival']['text2wave']} -F $frequency -o $fname.wav $fname.txt"); |
|---|
| 1326 |
|
|---|
| 1327 |
|
|---|
| 1328 |
|
|---|
| 1329 |
touch("$fname.txt"); |
|---|
| 1330 |
touch("$fname.wav"); |
|---|
| 1331 |
|
|---|
| 1332 |
|
|---|
| 1333 |
|
|---|
| 1334 |
$ret = $this->stream_file($fname, $escape_digits); |
|---|
| 1335 |
|
|---|
| 1336 |
|
|---|
| 1337 |
$delete = time() - 2592000; |
|---|
| 1338 |
foreach(glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'text2wav_*') as $file) |
|---|
| 1339 |
filemtime($file) < $delete) |
|---|
| 1340 |
unlink($file); |
|---|
| 1341 |
|
|---|
| 1342 |
$ret; |
|---|
| 1343 |
|
|---|
| 1344 |
|
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
|
|---|
| 1348 |
|
|---|
| 1349 |
|
|---|
| 1350 |
|
|---|
| 1351 |
|
|---|
| 1352 |
|
|---|
| 1353 |
|
|---|
| 1354 |
function swift($text, $escape_digits='', $frequency=8000, $voice=NULL) |
|---|
| 1355 |
|
|---|
| 1356 |
|
|---|
| 1357 |
if(!isset($this->config['cepstral']['swift'])) $this->config['cepstral']['swift'] = $this->which('swift'); |
|---|
| 1358 |
|
|---|
| 1359 |
is_null($voice)) |
|---|
| 1360 |
$voice = "-n $voice"; |
|---|
| 1361 |
$this->config['cepstral']['voice'])) |
|---|
| 1362 |
$voice = "-n {$this->config['cepstral']['voice']}"; |
|---|
| 1363 |
|
|---|
| 1364 |
$text = trim($text); |
|---|
| 1365 |
$text == '') return true; |
|---|
| 1366 |
|
|---|
| 1367 |
$hash = md5($text); |
|---|
| 1368 |
$fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR; |
|---|
| 1369 |
$fname .= 'swift_' . $hash; |
|---|
| 1370 |
|
|---|
| 1371 |
|
|---|
| 1372 |
if(!file_exists("$fname.wav")) |
|---|
| 1373 |
|
|---|
| 1374 |
|
|---|
| 1375 |
if(!file_exists("$fname.txt")) |
|---|
| 1376 |
|
|---|
| 1377 |
$fp = fopen("$fname.txt", 'w'); |
|---|
| 1378 |
fputs($fp, $text); |
|---|
| 1379 |
fclose($fp); |
|---|
| 1380 |
|
|---|
| 1381 |
|
|---|
| 1382 |
shell_exec("{$this->config['cepstral']['swift']} -p audio/channels=1,audio/sampling-rate=$frequency $voice -o $fname.wav -f $fname.txt"); |
|---|
| 1383 |
|
|---|
| 1384 |
|
|---|
| 1385 |
|
|---|
| 1386 |
$ret = $this->stream_file($fname, $escape_digits); |
|---|
| 1387 |
|
|---|
| 1388 |
|
|---|
| 1389 |
$delete = time() - 2592000; |
|---|
| 1390 |
foreach(glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'swift_*') as $file) |
|---|
| 1391 |
filemtime($file) < $delete) |
|---|
| 1392 |
unlink($file); |
|---|
| 1393 |
|
|---|
| 1394 |
$ret; |
|---|
| 1395 |
|
|---|
| 1396 |
|
|---|
| 1397 |
|
|---|
| 1398 |
|
|---|
| 1399 |
|
|---|
| 1400 |
|
|---|
| 1401 |
|
|---|
| 1402 |
|
|---|
| 1403 |
|
|---|
| 1404 |
|
|---|
| 1405 |
|
|---|
| 1406 |
|
|---|
| 1407 |
|
|---|
| 1408 |
|
|---|
| 1409 |
|
|---|
| 1410 |
|
|---|
| 1411 |
function text_input($mode='NUMERIC') |
|---|
| 1412 |
|
|---|
| 1413 |
$alpha = array( 'k0'=>' ', 'k00'=>',', 'k000'=>'.', 'k0000'=>'?', 'k00000'=>'0', |
|---|
| 1414 |
'k1'=>'!', 'k11'=>':', 'k111'=>';', 'k1111'=>'#', 'k11111'=>'1', |
|---|
| 1415 |
'k2'=>'A', 'k22'=>'B', 'k222'=>'C', 'k2222'=>'2', |
|---|
| 1416 |
'k3'=>'D', 'k33'=>'E', 'k333'=>'F', 'k3333'=>'3', |
|---|
| 1417 |
'k4'=>'G', 'k44'=>'H', 'k444'=>'I', 'k4444'=>'4', |
|---|
| 1418 |
'k5'=>'J', 'k55'=>'K', 'k555'=>'L', 'k5555'=>'5', |
|---|
| 1419 |
'k6'=>'M', 'k66'=>'N', 'k666'=>'O', 'k6666'=>'6', |
|---|
| 1420 |
'k7'=>'P', 'k77'=>'Q', 'k777'=>'R', 'k7777'=>'S', 'k77777'=>'7', |
|---|
| 1421 |
'k8'=>'T', 'k88'=>'U', 'k888'=>'V', 'k8888'=>'8', |
|---|
| 1422 |
'k9'=>'W', 'k99'=>'X', 'k999'=>'Y', 'k9999'=>'Z', 'k99999'=>'9'); |
|---|
| 1423 |
$symbol = array('k0'=>'=', |
|---|
| 1424 |
'k1'=>'<', 'k11'=>'(', 'k111'=>'[', 'k1111'=>'{', 'k11111'=>'1', |
|---|
| 1425 |
'k2'=>'@', 'k22'=>'$', 'k222'=>'&', 'k2222'=>'%', 'k22222'=>'2', |
|---|
| 1426 |
'k3'=>'>', 'k33'=>')', 'k333'=>']', 'k3333'=>'}', 'k33333'=>'3', |
|---|
| 1427 |
'k4'=>'+', 'k44'=>'-', 'k444'=>'*', 'k4444'=>'/', 'k44444'=>'4', |
|---|
| 1428 |
'k5'=>"'", 'k55'=>'`', 'k555'=>'5', |
|---|
| 1429 |
'k6'=>'"', 'k66'=>'6', |
|---|
| 1430 |
'k7'=>'^', 'k77'=>'7', |
|---|
| 1431 |
'k8'=>"\\",'k88'=>'|', 'k888'=>'8', |
|---|
| 1432 |
'k9'=>'_', 'k99'=>'~', 'k999'=>'9'); |
|---|
| 1433 |
$text = ''; |
|---|
| 1434 |
|
|---|
| 1435 |
|
|---|
| 1436 |
$command = false; |
|---|
| 1437 |
$result = $this->get_data('beep'); |
|---|
| 1438 |
explode('*', $result['result']) as $code) |
|---|
| 1439 |
|
|---|
| 1440 |
$command) |
|---|
| 1441 |
|
|---|
| 1442 |
$code{0}) |
|---|
| 1443 |
|
|---|
| 1444 |
'2': $text = substr($text, 0, strlen($text) - 1); break; |
|---|
| 1445 |
case '5': $mode = 'LOWERCASE'; break; |
|---|
| 1446 |
'6': $mode = 'NUMERIC'; break; |
|---|
| 1447 |
'7': $mode = 'SYMBOL'; break; |
|---|
| 1448 |
'8': $mode = 'UPPERCASE'; break; |
|---|
| 1449 |
'9': $text = explode(' ', $text); unset($text[count($text)-1]); $text = join(' ', $text); break; |
|---|
| 1450 |
} |
|---|
| 1451 |
$code = substr($code, 1); |
|---|
| 1452 |
$command = false; |
|---|
| 1453 |
|
|---|
| 1454 |
$code == '') |
|---|
| 1455 |
$command = true; |
|---|
| 1456 |
$mode == 'NUMERIC') |
|---|
| 1457 |
$text .= $code; |
|---|
| 1458 |
$mode == 'UPPERCASE' && isset($alpha['k'.$code])) |
|---|
| 1459 |
$text .= $alpha['k'.$code]; |
|---|
| 1460 |
$mode == 'LOWERCASE' && isset($alpha['k'.$code])) |
|---|
| 1461 |
$text .= strtolower($alpha['k'.$code]); |
|---|
| 1462 |
$mode == 'SYMBOL' && isset($symbol['k'.$code])) |
|---|
| 1463 |
$text .= $symbol['k'.$code]; |
|---|
| 1464 |
|
|---|
| 1465 |
$this->say_punctuation($text); |
|---|
| 1466 |
substr($result['result'], -2) == '**'); |
|---|
| 1467 |
$text; |
|---|
| 1468 |
|
|---|
| 1469 |
|
|---|
| 1470 |
|
|---|
| 1471 |
|
|---|
| 1472 |
|
|---|
| 1473 |
|
|---|
| 1474 |
|
|---|
| 1475 |
|
|---|
| 1476 |
|
|---|
| 1477 |
|
|---|
| 1478 |
function say_punctuation($text, $escape_digits='', $frequency=8000) |
|---|
| 1479 |
|
|---|
| 1480 |
$i = 0; $i < strlen($text); $i++) |
|---|
| 1481 |
|
|---|
| 1482 |
$text{$i}) |
|---|
| 1483 |
|
|---|
| 1484 |
' ': $ret .= 'SPACE '; |
|---|
| 1485 |
',': $ret .= 'COMMA '; break; |
|---|
| 1486 |
'.': $ret .= 'PERIOD '; break; |
|---|
| 1487 |
'?': $ret .= 'QUESTION MARK '; break; |
|---|
| 1488 |
'!': $ret .= 'EXPLANATION POINT '; break; |
|---|
| 1489 |
':': $ret .= 'COLON '; break; |
|---|
| 1490 |
';': $ret .= 'SEMICOLON '; break; |
|---|
| 1491 |
'#': $ret .= 'POUND '; break; |
|---|
| 1492 |
'=': $ret .= 'EQUALS '; break; |
|---|
| 1493 |
'<': $ret .= 'LESS THAN '; break; |
|---|
| 1494 |
'(': $ret .= 'LEFT PARENTHESIS '; break; |
|---|
| 1495 |
'[': $ret .= 'LEFT BRACKET '; break; |
|---|
| 1496 |
'{': $ret .= 'LEFT BRACE '; break; |
|---|
| 1497 |
'@': $ret .= 'AT '; break; |
|---|
| 1498 |
'$': $ret .= 'DOLLAR SIGN '; break; |
|---|
| 1499 |
'&': $ret .= 'AMPERSAND '; break; |
|---|
| 1500 |
'%': $ret .= 'PERCENT '; break; |
|---|
| 1501 |
'>': $ret .= 'GREATER THAN '; break; |
|---|
| 1502 |
')': $ret .= 'RIGHT PARENTHESIS '; break; |
|---|
| 1503 |
']': $ret .= 'RIGHT BRACKET '; break; |
|---|
| 1504 |
'}': $ret .= 'RIGHT BRACE '; break; |
|---|
| 1505 |
'+': $ret .= 'PLUS '; break; |
|---|
| 1506 |
'-': $ret .= 'MINUS '; break; |
|---|
| 1507 |
'*': $ret .= 'ASTERISK '; break; |
|---|
| 1508 |
'/': $ret .= 'SLASH '; break; |
|---|
| 1509 |
"'": $ret .= 'SINGLE QUOTE '; break; |
|---|
| 1510 |
'`': $ret .= 'BACK TICK '; break; |
|---|
| 1511 |
'"': $ret .= 'QUOTE '; break; |
|---|
| 1512 |
'^': $ret .= 'CAROT '; break; |
|---|
| 1513 |
"\\": $ret .= 'BACK SLASH '; break; |
|---|
| 1514 |
'|': $ret .= 'BAR '; break; |
|---|
| 1515 |
'_': $ret .= 'UNDERSCORE '; break; |
|---|
| 1516 |
'~': $ret .= 'TILDE '; break; |
|---|
| 1517 |
$ret .= $text{$i} . ' '; break; |
|---|
| 1518 |
|
|---|
| 1519 |
|
|---|
| 1520 |
$this->text2wav($ret, $escape_digits, $frequency); |
|---|
| 1521 |
|
|---|
| 1522 |
|
|---|
| 1523 |
|
|---|
| 1524 |
|
|---|
| 1525 |
|
|---|
| 1526 |
function &new_AsteriskManager() |
|---|
| 1527 |
|
|---|
| 1528 |
$this->asm = new AGI_AsteriskManager(NULL, $this->config); |
|---|
| 1529 |
$this->asm->pagi =& $this; |
|---|
| 1530 |
$this->config =& $this->asm->config; |
|---|
| 1531 |
$this->asm; |
|---|
| 1532 |
|
|---|
| 1533 |
|
|---|
| 1534 |
|
|---|
| 1535 |
|
|---|
| 1536 |
|
|---|
| 1537 |
|
|---|
| 1538 |
|
|---|
| 1539 |
|
|---|
| 1540 |
|
|---|
| 1541 |
|
|---|
| 1542 |
|
|---|
| 1543 |
|
|---|
| 1544 |
|
|---|
| 1545 |
|
|---|
| 1546 |
function evaluate($command) |
|---|
| 1547 |
|
|---|
| 1548 |
$broken = array('code'=>500, 'result'=>-1, 'data'=>''); |
|---|
| 1549 |
|
|---|
| 1550 |
|
|---|
| 1551 |
if(is_null($this->socket)) |
|---|
| 1552 |
|
|---|
| 1553 |
fwrite($this->out, trim($command) . "\n")) return $broken; |
|---|
| 1554 |
fflush($this->out); |
|---|
| 1555 |
|
|---|
| 1556 |
socket_write($this->socket, trim($command) . "\n") === false) return $broken; |
|---|
| 1557 |
|
|---|
| 1558 |
|
|---|
| 1559 |
|
|---|
| 1560 |
|
|---|
| 1561 |
|
|---|
| 1562 |
|
|---|
| 1563 |
$count = 0; |
|---|
| 1564 |
|
|---|
| 1565 |
|
|---|
| 1566 |
$str = is_null($this->socket) ? @fgets($this->in, 4096) : @socket_read($this->socket, 4096, PHP_NORMAL_READ); |
|---|
| 1567 |
$str == '' && $count++ < 5); |
|---|
| 1568 |
|
|---|
| 1569 |
$count >= 5) |
|---|
| 1570 |
|
|---|
| 1571 |
|
|---|
| 1572 |
return $broken; |
|---|
| 1573 |
|
|---|
| 1574 |
|
|---|
| 1575 |
|
|---|
| 1576 |
$ret['code'] = substr($str, 0, 3); |
|---|
| 1577 |
$str = trim(substr($str, 3)); |
|---|
| 1578 |
|
|---|
| 1579 |
$str{0} == '-') |
|---|
| 1580 |
{ |
|---|
| 1581 |
$count = 0; |
|---|
| 1582 |
$str = substr($str, 1) . "\n"; |
|---|
| 1583 |
|
|---|
| 1584 |
$line = is_null($this->socket) ? @fgets($this->in, 4096) : @socket_read($this->socket, 4096, PHP_NORMAL_READ); |
|---|
| 1585 |
substr($line, 0, 3) != $ret['code'] && $count < 5) |
|---|
| 1586 |
|
|---|
| 1587 |
$str .= $line; |
|---|
| 1588 |
$line = is_null($this->socket) ? @fgets($this->in, 4096) : @socket_read($this->socket, 4096, PHP_NORMAL_READ); |
|---|
| 1589 |
$count = (trim($line) == '') ? $count + 1 : 0; |
|---|
| 1590 |
|
|---|
| 1591 |
$count >= 5) |
|---|
| 1592 |
|
|---|
| 1593 |
|
|---|
| 1594 |
return $broken; |
|---|
| 1595 |
|
|---|
| 1596 |
|
|---|
| 1597 |
|
|---|
| 1598 |
$ret['result'] = NULL; |
|---|
| 1599 |
$ret['data'] = ''; |
|---|
| 1600 |
$ret['code'] != AGIRES_OK) |
|---|
| 1601 |
{ |
|---|
| 1602 |
$ret['data'] = $str; |
|---|
| 1603 |
$this->conlog(print_r($ret, true)); |
|---|
| 1604 |
|
|---|
| 1605 |
|
|---|
| 1606 |
{ |
|---|
| 1607 |
$parse = explode(' ', trim($str)); |
|---|
| 1608 |
$in_token = false; |
|---|
| 1609 |
$parse as $token) |
|---|
| 1610 |
|
|---|
| 1611 |
$in_token) |
|---|
| 1612 |
{ |
|---|
| 1613 |
$tmp = trim($token); |
|---|
| 1614 |
$tmp = $tmp{0} == '(' ? substr($tmp,1):$tmp; |
|---|
| 1615 |
$tmp = substr($tmp,-1) == ')' ? substr($tmp,0,strlen($tmp)-1):$tmp; |
|---|
| 1616 |
$ret['data'] .= ' ' . trim($tmp); |
|---|
| 1617 |
$token{strlen($token)-1} == ')') $in_token = false; |
|---|
| 1618 |
|
|---|
| 1619 |
$token{0} == '(') |
|---|
| 1620 |
|
|---|
| 1621 |
$token{strlen($token)-1} != ')') $in_token = true; |
|---|
| 1622 |
$tmp = trim(substr($token,1)); |
|---|
| 1623 |
$tmp = $in_token ? $tmp : substr($tmp,0,strlen($tmp)-1); |
|---|
| 1624 |
$ret['data'] .= ' ' . trim($tmp); |
|---|
| 1625 |
|
|---|
| 1626 |
strpos($token, '=')) |
|---|
| 1627 |
|
|---|
| 1628 |
$token = explode('=', $token); |
|---|
| 1629 |
$ret[$token[0]] = $token[1]; |
|---|
| 1630 |
|
|---|
| 1631 |
$token != '') |
|---|
| 1632 |
$ret['data'] .= ' ' . $token; |
|---|
| 1633 |
|
|---|
| 1634 |
$ret['data'] = trim($ret['data']); |
|---|
| 1635 |
|
|---|
| 1636 |
|
|---|
| 1637 |
|
|---|
| 1638 |
if($ret['result'] < 0) |
|---|
| 1639 |
$this->conlog("$command returned {$ret['result']}"); |
|---|
| 1640 |
|
|---|
| 1641 |
$ret; |
|---|
| 1642 |
|
|---|
| 1643 |
|
|---|
| 1644 |
|
|---|
| 1645 |
|
|---|
| 1646 |
|
|---|
| 1647 |
|
|---|
| 1648 |
|
|---|
| 1649 |
|
|---|
| 1650 |
|
|---|
| 1651 |
|
|---|
| 1652 |
function conlog($str, $vbl=1) |
|---|
| 1653 |
|
|---|
| 1654 |
$busy = false; |
|---|
| 1655 |
|
|---|
| 1656 |
$this->config['phpagi']['debug'] != false) |
|---|
| 1657 |
|
|---|
| 1658 |
$busy) |
|---|
| 1659 |
{ |
|---|
| 1660 |
$busy = true; |
|---|
| 1661 |
$this->verbose($str, $vbl); |
|---|
| 1662 |
$busy = false; |
|---|
| 1663 |
|
|---|
| 1664 |
|
|---|
| 1665 |
|
|---|
| 1666 |
|
|---|
| 1667 |
|
|---|
| 1668 |
|
|---|
| 1669 |
|
|---|
| 1670 |
|
|---|
| 1671 |
|
|---|
| 1672 |
|
|---|
| 1673 |
|
|---|
| 1674 |
|
|---|
| 1675 |
function which($cmd, $checkpath=NULL) |
|---|
| 1676 |
|
|---|
| 1677 |
$_ENV; |
|---|
| 1678 |
$chpath = is_null($checkpath) ? $_ENV['PATH'] : $checkpath; |
|---|
| 1679 |
|
|---|
| 1680 |
explode(PATH_SEPERATOR, $chpath) as $path) |
|---|
| 1681 |
function_exists('is_executable') || is_executable($path . DIRECTORY_SEPERATOR . $cmd)) |
|---|
| 1682 |
$path . DIRECTORY_SEPERATOR . $cmd; |
|---|
| 1683 |
|
|---|
| 1684 |
is_null($checkpath)) |
|---|
| 1685 |
|
|---|
| 1686 |
substr(strtoupper(PHP_OS, 0, 3)) != 'WIN') |
|---|
| 1687 |
$this->which($cmd, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:'. |
|---|
| 1688 |
'/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/mysql/bin'); |
|---|
| 1689 |
|
|---|
| 1690 |
false; |
|---|
| 1691 |
|
|---|
| 1692 |
|
|---|
| 1693 |
|
|---|
| 1694 |
|
|---|
| 1695 |
|
|---|
| 1696 |
|
|---|
| 1697 |
|
|---|
| 1698 |
|
|---|
| 1699 |
|
|---|
| 1700 |
function make_folder($folder, $perms=0755) |
|---|
| 1701 |
|
|---|
| 1702 |
$f = explode(DIRECTORY_SEPARATOR, $folder); |
|---|
| 1703 |
$base = ''; |
|---|
| 1704 |
$i = 0; $i < count($f); $i++) |
|---|
| 1705 |
|
|---|
| 1706 |
$base .= $f[$i]; |
|---|
| 1707 |
$f[$i] != '' && !file_exists($base)) |
|---|
| 1708 |
mkdir($base, $perms); |
|---|
| 1709 |
$base .= DIRECTORY_SEPARATOR; |
|---|
| 1710 |
|
|---|
| 1711 |
|
|---|
| 1712 |
|
|---|
| 1713 |
|
|---|
| 1714 |
|
|---|
| 1715 |
|
|---|
| 1716 |
|
|---|
| 1717 |
|
|---|
| 1718 |
|
|---|
| 1719 |
|
|---|
| 1720 |
|
|---|
| 1721 |
|
|---|
| 1722 |
|
|---|
| 1723 |
function phpagi_error_handler($level, $message, $file, $line, $context) |
|---|
| 1724 |
|
|---|
| 1725 |
ini_get('error_reporting') == 0) return; |
|---|
| 1726 |
|
|---|
| 1727 |
@syslog(LOG_WARNING, $file . '[' . $line . ']: ' . $message); |
|---|
| 1728 |
|
|---|
| 1729 |
$phpagi_error_handler_email; |
|---|
| 1730 |
function_exists('mail') && !is_null($phpagi_error_handler_email)) |
|---|
| 1731 |
{ |
|---|
| 1732 |
|
|---|
| 1733 |
switch($level) |
|---|
| 1734 |
|
|---|
| 1735 |
E_WARNING: |
|---|
| 1736 |
E_USER_WARNING: |
|---|
| 1737 |
$level = "Warning"; |
|---|
| 1738 |
|
|---|
| 1739 |
E_NOTICE: |
|---|
| 1740 |
E_USER_NOTICE: |
|---|
| 1741 |
$level = "Notice"; |
|---|
| 1742 |
|
|---|
| 1743 |
E_USER_ERROR: |
|---|
| 1744 |
$level = "Error"; |
|---|
| 1745 |
|
|---|
| 1746 |
|
|---|
| 1747 |
|
|---|
| 1748 |
|
|---|
| 1749 |
$basefile = basename($file); |
|---|
| 1750 |
$subject = "$basefile/$line/$level: $message"; |
|---|
| 1751 |
$message = "$level: $message in $file on line $line\n\n"; |
|---|
| 1752 |
|
|---|
| 1753 |
function_exists('mysql_errno') && strpos(' '.strtolower($message), 'mysql')) |
|---|
| 1754 |
$message .= 'MySQL error ' . mysql_errno() . ": " . mysql_error() . "\n\n"; |
|---|
| 1755 |
|
|---|
| 1756 |
|
|---|
| 1757 |
if(function_exists('socket_create')) |
|---|
| 1758 |
|
|---|
| 1759 |
$addr = NULL; |
|---|
| 1760 |
$port = 80; |
|---|
| 1761 |
$socket = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); |
|---|
| 1762 |
socket_connect($socket, '64.0.0.0', $port); |
|---|
| 1763 |
socket_getsockname($socket, $addr, $port); |
|---|
| 1764 |
socket_close($socket); |
|---|
| 1765 |
$message .= "\n\nIP Address: $addr\n"; |
|---|
| 1766 |
|
|---|
| 1767 |
|
|---|
| 1768 |
|
|---|
| 1769 |
$message .= "\n\nContext:\n" . print_r($context, true); |
|---|
| 1770 |
$message .= "\n\nGLOBALS:\n" . print_r($GLOBALS, true); |
|---|
| 1771 |
$message .= "\n\nBacktrace:\n" . print_r(debug_backtrace(), true); |
|---|
| 1772 |
|
|---|
| 1773 |
|
|---|
| 1774 |
if(file_exists($file)) |
|---|
| 1775 |
|
|---|
| 1776 |
$message .= "\n\n$file:\n"; |
|---|
| 1777 |
$code = @file($file); |
|---|
| 1778 |
$i = max(0, $line - 10); $i < min($line + 10, count($code)); $i++) |
|---|
| 1779 |
$message .= ($i + 1)."\t$code[$i]"; |
|---|
| 1780 |
|
|---|
| 1781 |
|
|---|
| 1782 |
|
|---|
| 1783 |
$ret = ''; |
|---|
| 1784 |
$i = 0; $i < strlen($message); $i++) |
|---|
| 1785 |
|
|---|
| 1786 |
$c = ord($message{$i}); |
|---|
| 1787 |
$c == 10 || $c == 13 || $c == 9) |
|---|
| 1788 |
$ret .= $message{$i}; |
|---|
| 1789 |
$c < 16) |
|---|
| 1790 |
$ret .= '\x0' . dechex($c); |
|---|
| 1791 |
$c < 32 || $c > 127) |
|---|
| 1792 |
$ret .= '\x' . dechex($c); |
|---|
| 1793 |
|
|---|
| 1794 |
$ret .= $message{$i}; |
|---|
| 1795 |
|
|---|
| 1796 |
$message = $ret; |
|---|
| 1797 |
|
|---|
| 1798 |
|
|---|
| 1799 |
static $mailcount = 0; |
|---|
| 1800 |
$mailcount < 5) |
|---|
| 1801 |
mail($phpagi_error_handler_email, $subject, $message); |
|---|
| 1802 |
$mailcount++; |
|---|
| 1803 |
|
|---|
| 1804 |
|
|---|
| 1805 |
$phpagi_error_handler_email = NULL; |
|---|
| 1806 |
?> |
|---|
| 1807 |
|
|---|