| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
global $db; |
|---|
| 10 |
global $amp_conf; |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
function __core_routing_trunk_del($trunknum) { |
|---|
| 16 |
global $db; |
|---|
| 17 |
|
|---|
| 18 |
$sql = "DELETE FROM `extensions` WHERE `application` = 'Macro' AND `context` LIKE 'outrt-%' AND `args` LIKE 'dialout-%,$trunknum,%'"; |
|---|
| 19 |
$result = $db->query($sql); |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
outn(_("Checking routes for trunks..")); |
|---|
| 35 |
$sql = "SELECT DISTINCT `args` FROM `extensions` WHERE `context` LIKE 'outrt-%' AND `application` = 'Macro' AND `args` LIKE 'dialout-%'"; |
|---|
| 36 |
$results = $db->getCol($sql); |
|---|
| 37 |
if(DB::IsError($results)) { |
|---|
| 38 |
$results = array(); |
|---|
| 39 |
out(_("ok")); |
|---|
| 40 |
} else { |
|---|
| 41 |
$trunks = array(); |
|---|
| 42 |
$trunks_hash = array(); |
|---|
| 43 |
foreach ($results as $trunk_call) { |
|---|
| 44 |
if (preg_match('/^dialout-(?:trunk|enum|dundi),([\d]+),.*$/',$trunk_call,$match) != 1) { |
|---|
| 45 |
out(_("error detected")); |
|---|
| 46 |
out(sprintf(_("an erroneous entry, %s, was found in extensions table that should not be there"),$trunk_call)); |
|---|
| 47 |
} else { |
|---|
| 48 |
$trunks_hash[$match[1]] = "OUT_".$match[1]; |
|---|
| 49 |
} |
|---|
| 50 |
} |
|---|
| 51 |
$num_trunks = count($trunks_hash); |
|---|
| 52 |
out(sprintf(_("found %s"),$num_trunks)); |
|---|
| 53 |
|
|---|
| 54 |
outn(_("checking for phantoms..")); |
|---|
| 55 |
|
|---|
| 56 |
require_once($amp_conf['AMPWEBROOT'].'/admin/modules/core/functions.inc.php'); |
|---|
| 57 |
$trunks = core_trunks_list(true); |
|---|
| 58 |
|
|---|
| 59 |
$bad_trunks = array(); |
|---|
| 60 |
$cnt = 0; |
|---|
| 61 |
foreach ($trunks_hash as $trunknum => $globalvar) { |
|---|
| 62 |
$bad = true; |
|---|
| 63 |
foreach ($trunks as $trunk) { |
|---|
| 64 |
if ($trunk['globalvar'] == $globalvar) { |
|---|
| 65 |
$bad = false; |
|---|
| 66 |
break; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
if ($bad) { |
|---|
| 70 |
$cnt++; |
|---|
| 71 |
outn("$trunknum.."); |
|---|
| 72 |
__core_routing_trunk_del($trunknum); |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
if ($cnt) { |
|---|
| 76 |
out(sprintf(_("removed %s phantoms"),$cnt)); |
|---|
| 77 |
} else { |
|---|
| 78 |
out(_("none")); |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
?> |
|---|
| 82 |
|
|---|