SIP Trunx Dial Rules not matching (fixlocalprefix)


Have a dual-SIM GSM gateway set up as two separate trunks (one for each SIM).

Created an outbound_cellphone route for cellphone numbers which matches 9 (for the outbound lines), then the prefix for all cellphone numbers (6). The route tries SIM1, SIM2, then tries a ISDN gateway, finally a POTS gateway.

What I want to do is to prefix the caller-ID hide code #31# before the number: this must be done only for the two GSM trunks.

Also, I would like–again, only in the GSM trunks–to prepend the #31# for all calls, but to omit for a dozen cellphone numbers. So, friends and family (in the list) see who is calling them, but everybody else get CID hiding.

The obvious place to do this is in the SIP Trunk | Dial Rules. This way, I can keep everything nice and clean, and don’t have to do any messy customizations, nor worry if I decide to change the trunk sequence in my outbound_cellphone route.

First step is to add a rule like #31#+.

But it doesn’t work.

I tried a little debugging in …/agi-bin/fixlocalprefix, adding an $agi->verbose here and there.
Turns out that the # character isn’t recognized. So:

0000123450000+. -> works, prepends 0000123450000 to the $EXTEN
0000#123450000+. -> partially works, prepends 0000 to the $EXTEN
#31#0000012345+. -> doesn’t work at all, fixlocalprefix exits with 0

Probably (can’t understand PHP) it’s these lines:
if (isset($conf[“trunk-$trunk”])) {
foreach ($conf[“trunk-$trunk”] as $key=>$rule) {
// extract all ruleXX keys
//$agi->conlog("$key = $rule");
if (preg_match("/^rule\d+$/",$key)) { <====== probable offending line
// $rule is a dial rule

		if (($newnum = fixNumber($rule, $number, $agi)) !== false) {

Any ideas? Thanks in advance!

go ahead and file a bug and provide a diff or patch of the change that you did.

We can use that to have a look at what needs to be done in the new dialplan version of the manipulation code and to determine if the fix needs to be pushed back to 2.7 as well (which still uses this script).

as far as the other bug, yeah I guess it is suppose to say “read only” and not “write only” :slight_smile: - feel free to add that to the ticket.

Fixed. I poked at the parse_conf function and fixed it like so:

function parse_conf($filename, &$conf, &$section) {
if (is_null($conf)) {
$conf = array();
if (is_null($section)) {
$section = “general”;

if (file_exists($filename)) {
	$fd = fopen($filename, "r");
	while ($line = fgets($fd, 1024)) {

MODIFIED ===>>> if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=\s*(.?)?$/",$line,$matches)) {
// name = value
// option line
$conf[$section][ $matches[1] ] = $matches[2];
} else if (preg_match("/^\s
[(.+)]/",$line,$matches)) {

There is also another bug:

/* --------WARNING---------

  • This script is auto-copied from an included module and will get overwritten.
  • If you modify it, you must change it to write only, in the agi-bin directory,
  • to keep it from getting changed.

No, it must be changed to read only, I guess. At least, that’s what I did.

Shall I open a bug?

Thanks in advance

P.S.: Forgot - Running on FreePBX + PIAF + Asterisk

my guess (as you indicated) is that ‘#’ is probably not a ‘valid’ dial digit currently.

If you have confirmed that you may want to open up a bug so we remember to have a look at it. Keep in mind though that the script has bone away in 2.8 and beyond (fixlocalprefix is all done in dialplan). So … if it gets fixed, it probably won’t be something usable pre-2.8.