| 1 |
<?php |
|---|
| 2 |
/* $Id */ |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
// This is the hook for 'destinations' |
|---|
| 6 |
function disa_destinations() { |
|---|
| 7 |
$results = disa_list(); |
|---|
| 8 |
// return an associative array with destination and description |
|---|
| 9 |
if (isset($results)) { |
|---|
| 10 |
foreach($results as $result){ |
|---|
| 11 |
$extens[] = array('destination' => 'disa,'.$result['disa_id'].',1', 'description' => $result['displayname']); |
|---|
| 12 |
} |
|---|
| 13 |
return $extens; |
|---|
| 14 |
} else { |
|---|
| 15 |
return null; |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
// This actually generates the dialplan |
|---|
| 20 |
function disa_get_config($engine) { |
|---|
| 21 |
global $ext; |
|---|
| 22 |
switch($engine) { |
|---|
| 23 |
case "asterisk": |
|---|
| 24 |
$disalist = disa_list(); |
|---|
| 25 |
if(is_array($disalist)) { |
|---|
| 26 |
foreach($disalist as $item) { |
|---|
| 27 |
$nopass = false; |
|---|
| 28 |
|
|---|
| 29 |
if (isset($item['pin']) && !empty($item['pin']) && (strtolower($item['pin']) != 'no-password')) { |
|---|
| 30 |
// Create the disa-$id.conf file |
|---|
| 31 |
$filename = "/etc/asterisk/disa-".$item['disa_id'].".conf"; |
|---|
| 32 |
$fh = fopen($filename, "w+"); |
|---|
| 33 |
$pinarr = explode(',' , $item['pin'] ); |
|---|
| 34 |
foreach($pinarr as $pin) { |
|---|
| 35 |
|
|---|
| 36 |
// Don't support remote MWI, too easy for users to break. |
|---|
| 37 |
fwrite($fh, "$pin|".$item['context']."|".$item['cid']."\n"); |
|---|
| 38 |
} |
|---|
| 39 |
fclose($fh); |
|---|
| 40 |
chmod($filename, 0660); |
|---|
| 41 |
} else { |
|---|
| 42 |
$nopass = true; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
$thisitem = disa_get(ltrim($item['disa_id'])); |
|---|
| 46 |
// add dialplan |
|---|
| 47 |
|
|---|
| 48 |
if ($thisitem['needconf'] == 'CHECKED') { |
|---|
| 49 |
$ext->add('disa', $item['disa_id'], '', new ext_setvar('RESCOUNT', '1')); |
|---|
| 50 |
$ext->add('disa', $item['disa_id'], 'loop', new ext_gotoif('$[ ${RESCOUNT} > 5]', 'end')); |
|---|
| 51 |
$ext->add('disa', $item['disa_id'], '', new ext_read('RRES', 'press-1', '1', ',1,3')); |
|---|
| 52 |
$ext->add('disa', $item['disa_id'], '', new ext_setvar('RESCOUNT', '$[${RESCOUNT}+1]')); |
|---|
| 53 |
$ext->add('disa', $item['disa_id'], '', new ext_gotoif('$["x${RRES}"="x"]', 'loop')); |
|---|
| 54 |
} |
|---|
| 55 |
$ext->add('disa', $item['disa_id'], '', new ext_setvar('TIMEOUT(digit)', $thisitem['digittimeout'])); |
|---|
| 56 |
$ext->add('disa', $item['disa_id'], '', new ext_setvar('TIMEOUT(response)', $thisitem['resptimeout'])); |
|---|
| 57 |
|
|---|
| 58 |
if ($nopass) { |
|---|
| 59 |
if ($item['cid']) { |
|---|
| 60 |
$ext->add('disa', $item['disa_id'], '', new ext_setvar('CALLERID(all)', $item['cid'])); |
|---|
| 61 |
} |
|---|
| 62 |
$ext->add('disa', $item['disa_id'], '', new ext_disa('no-password,'.$item['context'])); |
|---|
| 63 |
} else { |
|---|
| 64 |
$ext->add('disa', $item['disa_id'], '', new ext_playback('enter-password')); |
|---|
| 65 |
$ext->add('disa', $item['disa_id'], '', new ext_disa('/etc/asterisk/disa-'.$item['disa_id'].'.conf')); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$ext->add('disa', $item['disa_id'], 'end', new ext_hangup('')); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
break; |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
function disa_list() { |
|---|
| 77 |
$results = sql("SELECT * FROM disa","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 78 |
if(is_array($results)){ |
|---|
| 79 |
foreach($results as $result){ |
|---|
| 80 |
// check to see if we have a dept match for the current AMP User. |
|---|
| 81 |
if (!isset($results['deptname']) || checkDept($result['deptname'])){ |
|---|
| 82 |
// return this item's dialplan destination, and the description |
|---|
| 83 |
$allowed[] = $result; |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
if (isset($allowed)) { |
|---|
| 88 |
return $allowed; |
|---|
| 89 |
} else { |
|---|
| 90 |
return null; |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
function disa_get($id){ |
|---|
| 95 |
//get all the variables for the meetme |
|---|
| 96 |
$results = sql("SELECT * FROM disa WHERE disa_id = '$id'","getRow",DB_FETCHMODE_ASSOC); |
|---|
| 97 |
return $results; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
function disa_chk($post) { |
|---|
| 101 |
return true; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
function disa_add($post) { |
|---|
| 105 |
if(!disa_chk($post)) |
|---|
| 106 |
return null; |
|---|
| 107 |
extract($post); |
|---|
| 108 |
if (!isset($needconf)) |
|---|
| 109 |
$needconf = ''; |
|---|
| 110 |
if(empty($displayname)) $displayname = "unnamed"; |
|---|
| 111 |
$results = sql("INSERT INTO disa (displayname,pin,cid,context,resptimeout,digittimeout,needconf) values (\"".str_replace("\"", "\"\"",$displayname)."\",\"".$pin."\",\"".str_replace("\"", "\"\"", $cid)."\",\"".$context."\", \"$resptimeout\", \"$digittimeout\", \"$needconf\")"); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
function disa_del($id) { |
|---|
| 115 |
$results = sql("DELETE FROM disa WHERE disa_id = \"$id\"","query"); |
|---|
| 116 |
unlink("/etc/asterisk/disa-{$id}.conf"); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
function disa_edit($id, $post) { |
|---|
| 120 |
if (!disa_chk($post)) |
|---|
| 121 |
return null; |
|---|
| 122 |
extract($post); |
|---|
| 123 |
if (!isset($needconf)) |
|---|
| 124 |
$needconf = ''; |
|---|
| 125 |
if(empty($displayname)) $displayname = "unnamed"; |
|---|
| 126 |
$results = sql("UPDATE disa set displayname = \"".str_replace("\"", "\"\"",$displayname)."\", pin = \"$pin\", cid = \"".str_replace("\"", "\"\"",$cid)."\", context = \"$context\", resptimeout = \"$resptimeout\", digittimeout = \"$digittimeout\", needconf = \"$needconf\" where disa_id = \"$id\""); |
|---|
| 127 |
} |
|---|
| 128 |
?> |
|---|