| 1 |
<?php |
<?php |
| 2 |
// $Id: asterisk_common.inc,v 1.10 2006/09/18 14:40:24 thehunmonkgroup Exp $ |
// $Id: asterisk_common.inc,v 1.11 2008/05/31 23:06:48 thehunmonkgroup Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 21 |
if (convert_sound_file($tempname, $file['filemime'], $filename, $user) == 0) { |
if (convert_sound_file($tempname, $file['filemime'], $filename, $user) == 0) { |
| 22 |
$return = TRUE; |
$return = TRUE; |
| 23 |
} |
} |
| 24 |
|
else { |
| 25 |
|
$return['error'] = "Sox unable to convert file $tempname to $filename"; |
| 26 |
|
} |
| 27 |
|
} |
| 28 |
|
else { |
| 29 |
|
$return['error'] = "Can't write temporary playback file $tempname."; |
| 30 |
} |
} |
| 31 |
unlink($tempname); |
unlink($tempname); |
| 32 |
} |
} |
| 33 |
|
else { |
| 34 |
|
$return['error'] = "Can't create temporary file"; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
return $return; |
return $return; |
| 38 |
} |
} |
| 76 |
// Scan the clients directory for the user. |
// Scan the clients directory for the user. |
| 77 |
if (is_dir(DRUPAL_ACCOUNTS_DIR)) { |
if (is_dir(DRUPAL_ACCOUNTS_DIR)) { |
| 78 |
if ($dh = opendir(DRUPAL_ACCOUNTS_DIR)) { |
if ($dh = opendir(DRUPAL_ACCOUNTS_DIR)) { |
| 79 |
|
// Assume invalid username until we're proven wrong. |
| 80 |
|
$return['error'] = 'Invalid username.'; |
| 81 |
while (($dir = readdir($dh)) !== false) { |
while (($dir = readdir($dh)) !== false) { |
| 82 |
if (is_dir(DRUPAL_ACCOUNTS_DIR . DIRECTORY_SEPARATOR . $dir) && $user == trim($dir) && $dir != 'www.example.com') { |
if (is_dir(DRUPAL_ACCOUNTS_DIR . DIRECTORY_SEPARATOR . $dir) && $user == trim($dir) && $dir != 'www.example.com') { |
| 83 |
$ini_file = DRUPAL_ACCOUNTS_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR .'account.conf'; |
$ini_file = DRUPAL_ACCOUNTS_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR .'account.conf'; |
| 86 |
$ini_array = parse_ini_file($ini_file, TRUE); |
$ini_array = parse_ini_file($ini_file, TRUE); |
| 87 |
// Validate the user's password. |
// Validate the user's password. |
| 88 |
if (trim($ini_array['general']['pass']) == $pass) { |
if (trim($ini_array['general']['pass']) == $pass) { |
| 89 |
|
// Don't check any more accounts, and clear any previously marked errors. |
| 90 |
$return['success'] = TRUE; |
$return['success'] = TRUE; |
| 91 |
|
unset($return['error']); |
| 92 |
|
break; |
| 93 |
} |
} |
| 94 |
else { |
else { |
| 95 |
$return['error'] = 'Invalid password'; |
$return['error'] = 'Invalid password'; |
| 101 |
break; |
break; |
| 102 |
} |
} |
| 103 |
} |
} |
|
$return['error'] = 'Invalid username.'; |
|
| 104 |
closedir($dh); |
closedir($dh); |
| 105 |
} |
} |
| 106 |
else { |
else { |
| 162 |
// Write the information to a temporary file. |
// Write the information to a temporary file. |
| 163 |
$tmpfname = tempnam($tempdir, 'drupal-record'); |
$tmpfname = tempnam($tempdir, 'drupal-record'); |
| 164 |
|
|
| 165 |
if (asterisk_write_file($callfile, $tmpfname)) { |
$result = asterisk_write_file($callfile, $tmpfname); |
| 166 |
|
if ($result === TRUE) { |
| 167 |
chmod($tmpfname, 0644); |
chmod($tmpfname, 0644); |
| 168 |
$outgoing = CALL_SPOOL_DIR . DIRECTORY_SEPARATOR . basename($tmpfname); |
$outgoing = CALL_SPOOL_DIR . DIRECTORY_SEPARATOR . basename($tmpfname); |
| 169 |
// Move (NOT copy or create in) to outgoing spool. |
// Move (NOT copy or create in) to outgoing spool. |
| 171 |
$return = TRUE; |
$return = TRUE; |
| 172 |
} |
} |
| 173 |
else { |
else { |
| 174 |
$return['error'] = "Can't move call file to spool $outgoing."; |
$return['error'] = "Can't move call file to spool: $outgoing."; |
| 175 |
unlink($tmpfname); |
unlink($tmpfname); |
| 176 |
} |
} |
| 177 |
} |
} |
| 191 |
$fh = fopen($location, 'w'); |
$fh = fopen($location, 'w'); |
| 192 |
$ret = fwrite($fh, $contents); |
$ret = fwrite($fh, $contents); |
| 193 |
fclose($fh); |
fclose($fh); |
| 194 |
return $ret; |
return $ret ? TRUE : FALSE; |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
/** |
/** |
| 397 |
*/ |
*/ |
| 398 |
function asterisk_process_new_calls($user, $pass, $calls) { |
function asterisk_process_new_calls($user, $pass, $calls) { |
| 399 |
|
|
| 400 |
$return = asterisk_validate_host($user, $pass); |
$return['callfile'] = array(); |
| 401 |
|
$return['playback_file'] = array(); |
| 402 |
|
|
| 403 |
if (isset($return['success'])) { |
$result = asterisk_validate_host($user, $pass); |
| 404 |
$return = asterisk_validate_user_directories($user); |
|
| 405 |
if ($return === TRUE) { |
if (isset($result['success'])) { |
| 406 |
|
$result = asterisk_validate_user_directories($user); |
| 407 |
|
if ($result === TRUE) { |
| 408 |
foreach ($calls as $type => $files) { |
foreach ($calls as $type => $files) { |
| 409 |
switch ($type) { |
switch ($type) { |
| 410 |
case 'playback_file': |
case 'playback_file': |
| 414 |
$return['playback_file'][$key] = TRUE; |
$return['playback_file'][$key] = TRUE; |
| 415 |
} |
} |
| 416 |
else { |
else { |
| 417 |
$return = $result; |
$return['playback_file'][$key] = $result; |
| 418 |
} |
} |
| 419 |
} |
} |
|
|
|
| 420 |
break; |
break; |
| 421 |
case 'callfile'; |
case 'callfile'; |
| 422 |
foreach ($files as $key => $file) { |
foreach ($files as $key => $file) { |
| 425 |
$return['callfile'][$key] = TRUE; |
$return['callfile'][$key] = TRUE; |
| 426 |
} |
} |
| 427 |
else { |
else { |
| 428 |
$return = $result; |
$return['callfile'][$key] = $result; |
| 429 |
} |
} |
| 430 |
} |
} |
|
|
|
| 431 |
break; |
break; |
| 432 |
} |
} |
| 433 |
} |
} |
| 434 |
} |
} |
| 435 |
|
else { |
| 436 |
|
$return = $result; |
| 437 |
|
} |
| 438 |
|
} |
| 439 |
|
else { |
| 440 |
|
$return = $result; |
| 441 |
} |
} |
| 442 |
|
|
| 443 |
return $return; |
return $return; |
| 515 |
); |
); |
| 516 |
} |
} |
| 517 |
|
|
| 518 |
|
function asterisk_debug_to_file($contents, $op = 'a') { |
| 519 |
|
$fh = fopen('/tmp/asterisk.debug', $op); |
| 520 |
|
$ret = fwrite($fh, $contents); |
| 521 |
|
fclose($fh); |
| 522 |
|
return $ret; |
| 523 |
|
} |
| 524 |
|
|
| 525 |
/** |
/** |
| 526 |
* Functions listed below are not working. In the future, they may be added as features |
* Functions listed below are not working. In the future, they may be added as features |
| 527 |
* or removed altogether. |
* or removed altogether. |