Asterisk --> Mysql --> Web Interface

hi guys,

i am stuck with some problems … and i am very new in this field :blush:

i am trying to have a interface that will interect with asterisk using Mysql database … example.

user is able to login to change the promotion message on the dialplan without having to access the asterisk CLI.

i had tried using asterisk database but no avail.

the website part is alright but i just cant seem to get it interfaced with asterisk.

experts here, please advise.

also … i have configured a dial plan of the follow flow…

  1. user called in ( asterisk IVR response “hallo”)

  2. User choose the following. 1. pre recorded message of locations, 2. the items on sale today, 3. operator help.

i wonder if it is possible to record what ever the user choose and record it in a database?? thanks

The existing capability of a programming language to connect to database
can be used to produce a dynamic IVR using Asterisk AGi scripting.

refer the link below for more details:
voip-info.org/wiki-Asterisk+AGI

hi … thanks for the speedy reply…

sorry i still dont get it. yes i know about phpagi and had experiment it with the dialplans…

but i still dont get how to interface the phpagi to a database hence providing a dynamic IVR

can you quote me examples?

if you can afford the extra processor cycles in your dialplan, why not just have a db lookup either from the dialplan using the MYSQL application, or via an AGI, that looks up the current message number and then plays that ?

then you can create your web interface elsewhere and in the language of your choice.

i do something similar for a client of mine that wants to be able to set assorted “modes” during the day/week/month/year. in this case they do the actual setting via an extension number, but it modifies a MySQL db table that displays the current status on a webpage that all the speeddials and click-2-dial numbers are displayed.

in this case you are trying to tell me to use the MYsql function in the dial plan ?

example

exten => _X.,1,MYSQL(Connect connid localhost asterisk dbpass asterisk)
exten => _X.,2,MYSQL(Query resultid ${connid} SELECT\ scriptname\ from\ mac2pin\ where\ userid=${CALLERIDNAME})
exten => _X.,3,MYSQL(Fetch fetchid ${resultid} AGIScript)
exten => _X.,4,MYSQL(Clear ${resultid})
exten => _X.,5,MYSQL(Disconnect ${connid})
exten => _X.,6,GotoIf(${fetchid}?7:9)
exten => _X.,7,AGI(${DefaultAGIScript},${EXTEN})
exten => _X.,8,Hangup
exten => _X.,9,AGI(${AGIScript},${EXTEN})
exten => _X.,10,Hangup

then thru a AGI script that refresh the supposed greeting msg which is then controlled by the website tat i am scripting?

but the point is. in this dial plan there is no way i am able to write data into the sql server.

is there a way i can write data into the sql server using a agi or dialplan?

i tried exten=> 1,1,Set(DB(data/test)=${EXTEN})

which will write the supposed extension into the asterisk db. but when i want it to be writen to the sql database. !! how do i go about doing it?

even when i try to interface using the asterisk database … it turn out to a disaster…

the array cannot display the intended …

below are my codes… can tell me what is wrong with it ? thanks

<?php import_request_variables("GP"); ?> <? if ($mode == "put"){ echo '';} ?> <? // ----------------------------------------------------------------------- begin ast db show if(!isset($mode)|| $mode == 'show') { echo 'Asterisk Database Maintenance

New Entry - Or edit existing below

';

$man_name = “myasterisk”;
$man_pword = “mycode”;

$socket = fsockopen(“127.0.0.1”,“5038”, $errno, $errstr, $timeout); // open a connection to the manager interface

fputs($socket, “Action: Login\r\n”); // login
fputs($socket, “UserName: $man_name\r\n”); // send username
fputs($socket, “Secret: $man_pword\r\n\r\n”); // send password

fputs($socket, “Action: Command\r\n”); // tell it a command is coming
fputs($socket, “Command: database show\r\n\r\n”); // ask for the contents of the database
fputs($socket, “Action: Logoff\r\n\r\n”); // logoff

while (!feof($socket)) {
$dbentries .= fread($socket, 5038); // read the entire output into $dbentries

}
fclose($socket); // close the socket

$array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); // split $dbentries on newline characters and store in $array
//$array = preg_split("/\n/",$dbentries, -1);
for ($i = 1; $i < 7; $i++) {
array_shift($array); // get rid of 7 lines of useless garbage (need a test for this)
}
$bgcolor=‘white’; // set a background color for the table
$color_state=true; // use it when $color_state = true
?>

<? foreach($array as $value) { if (strncmp($value, '--END COMMAND', 13) == 0) { // look for the end of the output break; // stop showing records at this point } preg_match("/^\/(.*)\/(\w*)\s*:\s*(\w\.:@*)/", $value, $temp); // isolate Family, Key and Value into $temp[] array_shift($temp); // shift off the matched portion $querystring = 'mode=form&family='.urlencode($temp0).'&key='.urlencode($temp1).'&value='.urlencode($temp2); // build some of the URI for this value ?> > <? $color_state = !$color_state; // flip the color state if ($color_state) { $bgcolor = 'white'; // if true use white; } else { $bgcolor = 'blue'; // else use grey } } } //------------------------------------------------------------------------ end ast db show

// ------------------------------------------------------------------------- begin ast db form

if ($mode == “form”) {
?>

" METHOD="POST">
Family Key Value <? echo($array); ?> <? echo ($dbentries); ?>
<? echo ''.$temp0.'';?> <? echo($temp1); ?>123 <? echo($temp2); ?>123 <? echo($dbentries); ?>
Family

Key

Value

<? } // ------------------------------------------------------------------------- end ast db form // --------------------------------------------------------------------------- begin ast db put if ($mode == "put") { if ($verb == "Submit") { $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: myasterisk\r\n"); fputs($socket, "Secret: mycode\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: database put $family $key $value\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { $response .= fread($socket, 8192); // read the entire output into $response } fclose($socket); // close the socket if (strpos($response, 'Updated database successfully')) { print("Your data has been INSERTED.\r\n"); } else print("INSERT Error...."); } if ($verb == "DELETE") { $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: myasterisk\r\n"); fputs($socket, "Secret: mycode\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: database del $family $key\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { $response .= fread($socket, 8192); // read the entire output into $response } fclose($socket); // close the socket if (strpos($response, 'Database entry removed')) { print("Your data has been DELETED.\r\n"); } else print("Delete Error...."); } } // ------------------------------------------------------------------------ end ast db put ?>

make your mind up. do you want to use MySQL or ASTDB ? and how do you want your PBX admin to access the interface to modify the IVR message.

if you look at the MYSQL example you posted, there is a QUERY involved. simply modify this from a SELECT query to an UPDATE one to update a record.

i would like to use MYSQL … but the asterisk database is just to test out.

i dont understand. when i connect to the database with mysql there is an error

Nov 20 18:37:58 WARNING[29537]: app_addon_sql_mysql.c:115 find_identifier: Ident ifier 0, identifier_type 1 not found in identifier list
Nov 20 18:37:58 WARNING[29537]: app_addon_sql_mysql.c:279 aMYSQL_query: aMYSQL_q uery: Invalid connection identifier 0 passed in aMYSQL_query

also because this database is just to capture all data that the user entered, i cannot simply use the update function rite?

any advise ?

What is the exact extensions.conf extry that is triggering that error?

sounds like you are not passing the connectionid variables properly

[quote=“sky_Dew”]i would like to use MYSQL … but the asterisk database is just to test out.

i dont understand. when i connect to the database with mysql there is an error

Nov 20 18:37:58 WARNING[29537]: app_addon_sql_mysql.c:115 find_identifier: Ident ifier 0, identifier_type 1 not found in identifier list
Nov 20 18:37:58 WARNING[29537]: app_addon_sql_mysql.c:279 aMYSQL_query: aMYSQL_q uery: Invalid connection identifier 0 passed in aMYSQL_query

also because this database is just to capture all data that the user entered, i cannot simply use the update function rite?

any advise ?[/quote]

dear brother, i wrote this script to pass value into the database.

#!/usr/bin/php -q

<?php ob_implicit_flush(true); set_time_limit(6); $in = fopen("php://stdin","r"); $stdlog = fopen("/var/log/asterisk/agitest.log", "w"); function read() { global $in; $input = str_replace("\n","",fgets($in,4096)); return $input; } // parse agi headers into array while ($env=read()) { $s = split(": ",$env); $agi[str_replace("agi_","",$s[0])] = trim($s[1]); if (($env == "") || ($env == "\n")) { break; } } $argv=$_SERVER['argv']; $u_choice=$argv[1]; //fputs($stdlog, "First variable $u_choice\n"); below are the argument that you paased to agi and you can manipulate them in any way now $arg1=$argv[2]; //arg1 is the first argument $arg2=$argv[3]; //arg2 is the second argument and so on $arg3=$argv[4]; $arg4=$argv[5]; $arg5=$argv[6]; $db_username = "root"; $db_password = "123456"; $db_hostname = "localhost"; $db_connect = mysql_connect($db_hostname, $db_username, $db_password)or die("Unable to connect to MySQL"); $db_select = mysql_select_db("testing", $db_connect)or die("Unable to select test"); mysql_query("insert into telephone (telephone,provider) values ($arg1,$arg2);"); //values are your recieved variables mysql_close($db_connect); ?>

some how i cant seem to pass it to the database

the table name is called telephone
the database name is testing

username is root
password is 123456

did i do aynthing wrong ? please advise

ok people … my bad … i solve the problem … hahhahaha my mistake

Could you post what the problem is?