| 1 |
<?php |
|---|
| 2 |
//Copyright (C) 2008 Astrogen LLC (philippe at freepbx dot org) |
|---|
| 3 |
//This program is free software; you can redistribute it and/or |
|---|
| 4 |
//modify it under the terms of the GNU General Public License |
|---|
| 5 |
//as published by the Free Software Foundation; either version 2 |
|---|
| 6 |
//of the License, or (at your option) any later version. |
|---|
| 7 |
// |
|---|
| 8 |
//This program is distributed in the hope that it will be useful, |
|---|
| 9 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 |
//GNU General Public License for more details. |
|---|
| 12 |
|
|---|
| 13 |
function dundicheck_check_extensions($exten=true) { |
|---|
| 14 |
global $active_modules; |
|---|
| 15 |
global $astman; |
|---|
| 16 |
|
|---|
| 17 |
$extenlist = array(); |
|---|
| 18 |
if ((is_array($exten) && empty($exten)) || $exten === true) { |
|---|
| 19 |
return $extenlist; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
if ($astman) { |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
// |
|---|
| 26 |
$dundimap = array(); |
|---|
| 27 |
|
|---|
| 28 |
$trunklist = core_trunks_list(true); |
|---|
| 29 |
if (is_array($trunklist)) { |
|---|
| 30 |
foreach ($trunklist as $trunkprops) { |
|---|
| 31 |
if (trim($trunkprops['value']) == 'on') { |
|---|
| 32 |
|
|---|
| 33 |
continue; |
|---|
| 34 |
} |
|---|
| 35 |
switch ($trunkprops['tech']) { |
|---|
| 36 |
case 'DUNDI': |
|---|
| 37 |
$dundimap[] = $trunkprops['name']; |
|---|
| 38 |
break; |
|---|
| 39 |
default: |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
} |
|---|
| 43 |
if (empty($dundimap)) { |
|---|
| 44 |
return array(); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
// |
|---|
| 49 |
$results = array(); |
|---|
| 50 |
foreach ($exten as $num) { |
|---|
| 51 |
$foundone = dundicheck_lookup($num, $dundimap); |
|---|
| 52 |
if (!empty($foundone)) { |
|---|
| 53 |
$results[] = array('exten' => $num, |
|---|
| 54 |
'description' => $foundone |
|---|
| 55 |
); |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$type = isset($active_modules['customappsreg']['type'])?$active_modules['customappsreg']['type']:'tool'; |
|---|
| 60 |
|
|---|
| 61 |
foreach ($results as $result) { |
|---|
| 62 |
$thisexten = $result['exten']; |
|---|
| 63 |
$extenlist[$thisexten]['description'] = _("DUNDi: ").$result['description']; |
|---|
| 64 |
$extenlist[$thisexten]['status'] = 'INUSE'; |
|---|
| 65 |
$extenlist[$thisexten]['edit_url'] = 'config.php?display=dundicheck&dundiconflict=true&extdisplay='.urlencode($thisexten); |
|---|
| 66 |
} |
|---|
| 67 |
return $extenlist; |
|---|
| 68 |
} else { |
|---|
| 69 |
return array(); |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
function dundicheck_lookup($num, $map) { |
|---|
| 74 |
global $astman; |
|---|
| 75 |
if ($astman) { |
|---|
| 76 |
foreach ($map as $lookup) { |
|---|
| 77 |
$response = $astman->send_request('Command',array('Command'=>"dundi lookup $num@$lookup")); |
|---|
| 78 |
if (strstr($response['data'],$num.' (EXISTS)')) { |
|---|
| 79 |
$parser = explode("@",$response['data']); |
|---|
| 80 |
$parser = explode("\n",$parser[1]); |
|---|
| 81 |
return $parser[0]; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
return null; |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
function dundicheck_lookup_all($num) { |
|---|
| 90 |
global $astman; |
|---|
| 91 |
|
|---|
| 92 |
$dundimap = array(); |
|---|
| 93 |
|
|---|
| 94 |
$trunklist = core_trunks_list(true); |
|---|
| 95 |
if (is_array($trunklist)) { |
|---|
| 96 |
foreach ($trunklist as $trunkprops) { |
|---|
| 97 |
if (trim($trunkprops['value']) == 'on') { |
|---|
| 98 |
|
|---|
| 99 |
continue; |
|---|
| 100 |
} |
|---|
| 101 |
switch ($trunkprops['tech']) { |
|---|
| 102 |
case 'DUNDI': |
|---|
| 103 |
$dundimap[] = $trunkprops['name']; |
|---|
| 104 |
break; |
|---|
| 105 |
default: |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
$results = array(); |
|---|
| 111 |
if ($astman) { |
|---|
| 112 |
foreach ($dundimap as $lookup) { |
|---|
| 113 |
$response = $astman->send_request('Command',array('Command'=>"dundi lookup $num@$lookup")); |
|---|
| 114 |
if (strstr($response['data'],$num.' (EXISTS)')) { |
|---|
| 115 |
$results[$lookup] = $response['data']; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
return $results; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
?> |
|---|
| 124 |
|
|---|