PHP Script to Automate adding Inbound route and "Apply Configuration Changes"

Hi,

I need to automate the process of adding an Inbound Route.
Can someone help here ?

What I have understood thus far is I need to fire the following mysql query:

INSERT INTO `incoming` VALUES ('','123123123','timeconditions,11,1','disabled','',0,0,0,'','','default','Test','',0,'');

Need help in understanding what happens when the user presses the “Apply Configuration Changes” button and how can I do this using a script (automation)

Thank you in advance.

Best regards,
Vai

this is open source, it is written in PHP, so you could try just reading the code.

I tried but could not figure out, hence I posted. Not a pro at PHP.

I have shared what I could understand; the SQL command.

Thx
Vai

it’s always a bit ‘dangerous’ to just enter something into SQL. You are also ignoring possible hooks by other modules that might need to know about the new route. Lastly, the specific insert is not even listing the fields but dependent on table order which could always change with future updates. You would be better off trying to include and use the function that FreePBX uses from core.

As far as doing the equivalent of the Apply Configuration Changes button, see the module_admin script supplied by FreePBX (the CLI version), it has a “reload” option that can be called that does this.

Thx Philippe, appreciate your inputs.

Is there any other non-manual way to add Inbound Route to FreePBX ?

Thx again.

Best regards,
Vai

ah! you did suggest You would be better off trying to include and use the function that FreePBX uses from core.

Can you send me additional pointer / file / code area which I can explore.

Thx
Vai

core_did_add() and core_did_edit()

Thx Philippe!!

function core_did_add($incoming,$target=false){
        global $db;
        foreach ($incoming as $key => $val) { ${$key} = $db->escapeSimple($val); } // create variables from request

        // Check to make sure the did is not being used elsewhere
        //
        $existing=core_did_get($extension,$cidnum);

        if (empty($existing)) {
                $destination= ($target) ? $target : ${$goto0.'0'};
                $sql="INSERT INTO incoming (cidnum,extension,destination,faxexten,faxemail,answer,wait,privacyman,alertinfo, ringing, mohclass, description, grppre, delay_answer, pricid) values ('$cidnum','$extension','$destination','$faxexten','$faxemail','$answer','$wait','$privacyman','$alertinfo', '$ringing', '$mohclass', '$description', '$grppre', '$delay_answer', '$pricid')";
                sql($sql);
                return true;
        } else {
                echo "<script>javascript:alert('"._("A route for this DID/CID already exists!")." => ".$existing['extension']."/".$existing['cidnum']."')</script>";
                return false;
        }
}

I believe calling this function should do the trick.
I will make an external routine to ensure that the DID is not used previously.

I will post back how this works for me.

Thx
Vai

Hi,
I tried this command:

[trixbox1 admin]# /var/lib/asterisk/bin/module_admin reload

PHP Notice:  Undefined variable: conf in /var/www/html/admin/functions.inc.php on line 834
Successfully reloaded
[trixbox1 admin]#

Is this good ? Should I be concerned about the PHP Notice, thou its just a notice.

Thx
Vai

it’s unlikely an issue and very possibly already fixed. The error is fairly meaningless though without know what line 834 is on your specific version of that functions.inc.php file.