我有一个旧版本的freePBX (超过5000个扩展,数百个IVR),我必须记录下来才能迁移到新版本。我必须映射哪些IVR使用哪些中继。为此,我必须将所拨打的号码与出站路由的拨号模式进行匹配。
带有我必须匹配的模式的表的'extensions‘列如下所示
19328555
_13XXXX
_1933370[0-2]
_2805XX
_28[3-7]XXX
_331XXX
_848XXX
_85XXXXX
_879XXX例如,我必须找出哪个‘扩展名’模式与数字8481234匹配,然后才能从另一列中抓取主干。
我知道一定有一个嵌入在Asterisk中的函数,它的工作原理如下
$number='8481234';
$pattern='_879XXX';
if (asterisk_pattern_match($number,$pattern)) {
#get trunk column from that row
}它可以是SQL、Perl或PHP。我可以写它,但我相信我会重新发明轮子。有没有人知道像这样的函数可能在哪里?我已经用谷歌搜索了我能想到的所有方法,但所有的结果都是关于在星号拨号方案中使用MySQL,这对我来说没有任何价值。
谢谢!
发布于 2015-08-14 02:04:55
谢谢大家。我找到了我要找的程序
https://gist.github.com/lgaetz/8695182
它被称为match_pattern.php,由Lorne Gaetz修改并发布在git上。
描述:两个PHP函数,match_pattern和match_pattern_all,用于将数字字符串与星号拨号模式(或模式数组)进行比较,并返回修改后的数字字符串。
发布于 2015-08-07 08:02:05
您可以使用以下脚本查找匹配项,结合在Asterisk CLI上运行的dialplan show extension@context的结果,这将向您显示执行匹配项的顺序。
#!/usr/bin/env perl
use strict;
use warnings;
my $numbers = [
"8481234", "8581234", "1283123"
];
my $patterns = [
"19328555" , "_13XXXX" , "_1933370[0-2]" ,
"_2805XX" , "_28[3-7]XXX" , "_331XXX" ,
"_848XXX" , "_85XXXXX" , "_879XXX" ,
];
# Lets turn partterns into usable regex, based on the reference:
# https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching
foreach my $r (@$patterns)
{
$r =~ s/_/^/; # Proper regex starts with
$r =~ s/X|x/\\d/g; # Replace X with any digit
$r =~ s/Z|z/[1-9]/g; # Replace Z with 1-9 as per spec
$r =~ s/N|m/[2-9]/g; # Replace N with 2-9 as per spec
my @matches = grep(/$r/i, @$numbers);
print "Matching numbers for: ", $r, " are: ", join(', ', @matches), "\n";
}https://stackoverflow.com/questions/31862530
复制相似问题