Reload New PINs via PHP script

I wrote a PHP script to manage PIN codes for making outgoing calls. I designed the script in such a way that I can maintain these PINs and know who owns a particular PIN by storing them in the database.

I had successfully populated the appropriate PIN sets in the asterisk but as soon as I add a new PIN, I still have to go to the Asterisk Admin Page to reload the settings to have the new PIN works.


QUESTION:
Is there a way I can initiate the REALOADing of the new settings without logging into the Asterisk Admin page? Is there a PHP file that I can call or include to do this?

Thanks!

Hi,
I dont know how you load the PIN in the Asterisk, but I would suggest to work with AGI, then you can send the call to the AGI script which can check the pin and start the call if there is a valid PIN:

extensions.conf:

exten => _Z.,1,AGI(pin.php)

pin.php:

[code]#!/usr/bin/php -q

<?php set_time_limit(0); $in=fopen("php://stdin","r"); while ($env=read()) { $s = split(": ",$env); $agi[str_replace("agi_","",$s[0])] = trim($s[1]); if (($env == "") || ($env == "\n")) { break; } } function retrievevar($varname) { echo "get variable ".$varname."\n"; $ret=read(); if(trim($ret)!="200 result=0") { $ret=str_replace(")","",$ret); list($tmp,$value)=split("\(",$ret,2); return(trim($value)); } else { return false; } } //database connection $link=mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname,$link); // Answer the call echo "exec Answer\n"; read(); // start voicefile and receive pin echo "exec Read PIN|voicefile_tellmepin\n"; read(); $pin = retrievevar("PIN"); //check if pin is inside database $ret=mysql_query("SELECT * from pin WHERE pin='".$pin."'",$link); if(mysql_num_rows($ret)>0) { //if pin is in database ask for number to dial echo "exec Read NUMBER|voicefile_enter_the_number_to_dial\n"; read(); $dial_number = retrievevar("NUMBER"); //go to outbound context and start call with the received number echo "exec Goto outbound|".$dial_number."|1|n\n"; read(); } else { // pin is not in database, hangup the call echo "exec Hangup\n"; read(); } ?>[/code]

I did not test the script, hope it help
good luck,
Alfred
take a look to our Switchboard

Hi Alfred,

Thanks for the reply.

There is no problem with adding a new PIN to the database but the newly added PINs can’t be used without logging into the TrixBox admin page then click the red box at the top page that says: “Reload New Settings”.

I need to know if there is a way wherein I can reload the PIN sets from a PHP script (equivalent to clicking the red box at the top of the admin page in TrixBox)?

Hi,
I have no experience with TrixBox, never have installed such a system.
But you can reload the Asterisk within a script via the Manager Interface:

OR you change in /etc/asterisk/asterisk.conf the asctlgroup to the www user like:[quote]
[files]
astctlpermissions = 0660
astctlowner = root
astctlgroup = www-data
astctl = asterisk.ctl
[/quote]
then you can reload the asterisk inside php with [quote]"exec(“asterisk -rx “reload””);[/quote] with an http request or whatever you like.

Regards,
Alfred
please do a look to our Switchboard