1 post / 0 new
cbbs70a's picture
Joined: 2008/04/10
Points: 0

This is a little script I wrote that will retrieve the MySQL login and password to be used in the dialplan. This way, that info does not have to be hard coded. Example included.


# get_mysql_params.agi - Get the MySQL login and passwd
# so they do not have to be hardcoded in the dialplan. Reads
# /etc/asterisk/res_mysql.conf. Needs PERL module Config::Std
# and Asterisk::AGI. Dialplan example:
# exten => s,1,AGI(get_mysql_params.agi)
# exten => s,2,MYSQL(Connect connid ${DBHOST} ${DBUSER} ${DBPASS} ${DBNAME})
# By FSD. fsd@voipbusiness.us

use strict;
use Config::Std;
use Config::Std { def_sep => '=' };
use Asterisk::AGI;

our $AGI = new Asterisk::AGI;

my $configfile = "/etc/asterisk/res_mysql.conf";
read_config "$configfile" => my %config;
my $dbhost = $config{general}{'dbhost'};
my $dbname = $config{general}{'dbname'};
my $dbuser = $config{general}{'dbuser'};
my $dbpass = $config{general}{'dbpass'};
my $dbport = $config{general}{'dbport'};