| 1 |
#!/usr/bin/env php |
|---|
| 2 |
<? |
|---|
| 3 |
// No use outputting anything, as env forces php headers to appear. Sigh. |
|---|
| 4 |
|
|---|
| 5 |
global $argv; |
|---|
| 6 |
require_once("php-asmanager.php"); |
|---|
| 7 |
|
|---|
| 8 |
function getconf($filename) { |
|---|
| 9 |
$file = file($filename); |
|---|
| 10 |
foreach ($file as $line) { |
|---|
| 11 |
if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\%-]*)\"?\s*([;#].*)?/",$line,$matches)) { |
|---|
| 12 |
$conf[ $matches[1] ] = $matches[2]; |
|---|
| 13 |
} |
|---|
| 14 |
} |
|---|
| 15 |
return $conf; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
$amp_conf = getconf(AMP_CONF); |
|---|
| 19 |
|
|---|
| 20 |
$astman = new AGI_AsteriskManager(); |
|---|
| 21 |
if (! $res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { |
|---|
| 22 |
unset( $astman ); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
if (!$argv[1] || strstr($argv[1], "/") || strstr($argv[1], "..")) { |
|---|
| 26 |
// You must supply a single filename, which will be written to /tmp |
|---|
| 27 |
exit; |
|---|
| 28 |
} |
|---|
| 29 |
$dump = file_get_contents("/tmp/ampbackups.$argv[1]/astdb.dump"); |
|---|
| 30 |
$arr = explode("\n", $dump); |
|---|
| 31 |
foreach ($arr as $line) { |
|---|
| 32 |
$result = preg_match("/\[(.+)\] \[(.+)\]/", $line, $matches); |
|---|
| 33 |
// Now, the bad ones we know about are the ones that start with //, anything starting with SIP or IAX, |
|---|
| 34 |
// and RG (which are only temporary anyway). |
|---|
| 35 |
if (!isset($matches[1]) || $matches[1] == "") { continue; } |
|---|
| 36 |
$pattern = "/(^\/\/)|(^\/IAX)|(^\/SIP)|(^\/RG)|(^\/BLKVM)|(^\/FM)/"; |
|---|
| 37 |
if (preg_match($pattern, $matches[1])) { continue; } |
|---|
| 38 |
preg_match("/(.+)\/(.+)$/", $matches[1], $famkey); |
|---|
| 39 |
$famkey[1]=trim($famkey[1], '/'); |
|---|
| 40 |
$astman->database_put($famkey[1], $famkey[2], $matches[2]); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
?> |
|---|