From 0b7773ded862105d228abda21bd37007e26094eb Mon Sep 17 00:00:00 2001 From: sluther Date: Thu, 26 Aug 2010 21:02:26 -0700 Subject: [PATCH] Added support for Asterisk 1.6 --- avscripts/install1.6.sh | 48 +++++ .../scripts1.6/agilevoice-export-extensions | 16 ++ .../agilevoice-export-extensions.pl | 59 ++++++ avscripts/scripts1.6/agilevoice-export-iax | 17 ++ avscripts/scripts1.6/agilevoice-export-sip | 17 ++ avscripts/scripts1.6/agilevoice-export-vm | 89 +++++++++ .../agilevoice-pro-export-extensions | 16 ++ .../agilevoice-pro-export-extensions.pl | 181 ++++++++++++++++++ avscripts/scripts1.6/cdr_import_agilevoice | 101 ++++++++++ .../retrieve_iax_conf_from_mysql.pl | 105 ++++++++++ .../retrieve_sip_conf_from_mysql.pl | 115 +++++++++++ 11 files changed, 764 insertions(+) create mode 100644 avscripts/install1.6.sh create mode 100755 avscripts/scripts1.6/agilevoice-export-extensions create mode 100755 avscripts/scripts1.6/agilevoice-export-extensions.pl create mode 100755 avscripts/scripts1.6/agilevoice-export-iax create mode 100755 avscripts/scripts1.6/agilevoice-export-sip create mode 100755 avscripts/scripts1.6/agilevoice-export-vm create mode 100755 avscripts/scripts1.6/agilevoice-pro-export-extensions create mode 100755 avscripts/scripts1.6/agilevoice-pro-export-extensions.pl create mode 100755 avscripts/scripts1.6/cdr_import_agilevoice create mode 100755 avscripts/scripts1.6/retrieve_iax_conf_from_mysql.pl create mode 100755 avscripts/scripts1.6/retrieve_sip_conf_from_mysql.pl diff --git a/avscripts/install1.6.sh b/avscripts/install1.6.sh new file mode 100644 index 00000000..cb7b9115 --- /dev/null +++ b/avscripts/install1.6.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +doinstall() { + perl -pe "s|%%AGILE_DB_HOST%%|${db_host}|g" $1 | \ + perl -pe "s|%%AGILE_DB_DATABASE%%|${db_name}|g" | \ + perl -pe "s|%%AGILE_DB_USERNAME%%|${db_user}|g" | \ + perl -pe "s|%%AGILE_DB_PASSWORD%%|${db_pass}|g" > $2 + echo "Installing to: $2" +} + +echo -n "Enter the database IP address: " +read db_host +echo -n "Enter the database name: " +read db_name +echo -n "Enter the database username: " +read db_user +echo -n "Enter the database password: " +read db_pass +# echo +# echo "Installing templated Asterisk configuration files..." + +# cd conf +# for FILE in *; do +# doinstall ${FILE} /etc/asterisk/${FILE} +# done +# cd .. +cd scripts1.6 +for FILE in *; do + doinstall ${FILE} /usr/sbin/${FILE} + chmod 755 /usr/sbin/${FILE} +done +cd .. + +echo "Installing Cron entries..." +echo "*/15 * * * * asterisk /usr/sbin/agilevoice-export-extensions" >>/etc/crontab +echo "*/15 * * * * asterisk /usr/sbin/agilevoice-export-sip" >>/etc/crontab +echo "*/15 * * * * asterisk /usr/sbin/agilevoice-export-iax" >>/etc/crontab +echo "*/15 * * * * asterisk /usr/sbin/agilevoice-export-vm" >>/etc/crontab +echo "*/30 * * * * asterisk /usr/sbin/cdr_import_agilevoice" >>/etc/crontab + +perl -MCPAN -e "install Text::CSV" + +echo "Installing MySQL tables..." +echo "Installing av-tables.sql" +mysql -u ${db_user} -p${db_pass} ${db_name} < av-tables.sql + + +echo "Complete." \ No newline at end of file diff --git a/avscripts/scripts1.6/agilevoice-export-extensions b/avscripts/scripts1.6/agilevoice-export-extensions new file mode 100755 index 00000000..ab37473b --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-export-extensions @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import sys +import posix +import os + +posix.system('/usr/sbin/agilevoice-export-extensions.pl') +a = posix.system('diff -q /etc/asterisk/extensions_agilevoice.conf.tmp /etc/asterisk/extensions_agilevoice.conf >/dev/null 2>&1') +if a: + try: + os.unlink('/etc/asterisk/extensions_agilevoice.conf') + except OSError: + pass + posix.system('mv -f /etc/asterisk/extensions_agilevoice.conf.tmp /etc/asterisk/extensions_agilevoice.conf') + posix.system('asterisk -rx "extensions reload" >/dev/null 2>&1') + diff --git a/avscripts/scripts1.6/agilevoice-export-extensions.pl b/avscripts/scripts1.6/agilevoice-export-extensions.pl new file mode 100755 index 00000000..501e1cba --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-export-extensions.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl -T +# Retrieves the extensions entries from the database + +use DBI; +################### BEGIN OF CONFIGURATION #################### + +# the name of the extensions table +$table_name = "ab_voip_did"; +# the path to the extensions.conf file +# WARNING: this file will be substituted by the output of this program +$ext_conf = "/etc/asterisk/extensions_agilevoice.conf.tmp"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; + +################### END OF CONFIGURATION ####################### + +my $dial = ""; +my $dialarg = ""; + +open EXTEN, ">$ext_conf" or die "Cannot create/overwrite file: $ext_conf\n"; + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); + + +$statement = "SELECT did, channel, channelarg from $table_name WHERE active=1 ORDER BY did"; +my $result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +my @resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + $dial = $result[1]; + $dialarg = $result[2]; + if (0 == length($dialarg)) { + $dialarg = $result[0]; + } + if ($dial =~ /IAX/) { + $dial = "IAX2/".$dialarg."/".$result[1]; + } else { + $dial = "SIP/".$dialarg; + } + print EXTEN "exten => ".$result[0].",1,Dial(".$dial.")\n"; + print EXTEN "exten => ".$result[0].",2,Macro(exten-vm,".$result[0].",".$dial.")\n"; + print EXTEN "exten => ".$result[0].",3,Hangup\n"; + } +} +exit 0; \ No newline at end of file diff --git a/avscripts/scripts1.6/agilevoice-export-iax b/avscripts/scripts1.6/agilevoice-export-iax new file mode 100755 index 00000000..81a9e1b5 --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-export-iax @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import sys +import posix +import os + +posix.system('/usr/sbin/retrieve_iax_conf_from_mysql.pl') +a = posix.system('diff -q /etc/asterisk/iax_agilevoice.conf.tmp /etc/asterisk/iax_agilevoice.conf >/dev/null 2>&1') +if a: + try: + os.unlink('/etc/asterisk/iax_agilevoice.conf') + except OSError: + pass + posix.system('mv -f /etc/asterisk/iax_agilevoice.conf.tmp /etc/asterisk/iax_agilevoice.conf') + posix.system('asterisk -rx "reload chan_iax2.so" >/dev/null 2>&1') + posix.system('asterisk -rx "reload app_voicemail.so" >/dev/null 2>&1') + diff --git a/avscripts/scripts1.6/agilevoice-export-sip b/avscripts/scripts1.6/agilevoice-export-sip new file mode 100755 index 00000000..e5678096 --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-export-sip @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import sys +import posix +import os + +posix.system('/usr/sbin/retrieve_sip_conf_from_mysql.pl') +a = posix.system('diff -q /etc/asterisk/sip_agilevoice.conf.tmp /etc/asterisk/sip_agilevoice.conf >/dev/null 2>&1') +if a: + try: + os.unlink('/etc/asterisk/sip_agilevoice.conf') + except OSError: + pass + posix.system('mv -f /etc/asterisk/sip_agilevoice.conf.tmp /etc/asterisk/sip_agilevoice.conf') + posix.system('asterisk -rx "sip reload" >/dev/null 2>&1') + posix.system('asterisk -rx "reload app_voicemail.so" >/dev/null 2>&1') + diff --git a/avscripts/scripts1.6/agilevoice-export-vm b/avscripts/scripts1.6/agilevoice-export-vm new file mode 100755 index 00000000..93005db3 --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-export-vm @@ -0,0 +1,89 @@ +#!/usr/bin/perl -Tw +# Retrieves the voicemail entries from the database + +use DBI; +################### BEGIN OF CONFIGURATION #################### + +# the name of the extensions table +$table_name = "ab_voip_vm"; +# the path to the extensions.conf file +# WARNING: this file will be substituted by the output of this program +$vm_conf = "/etc/asterisk/voicemai.conf"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; + +################### END OF CONFIGURATION ####################### + +open EXTEN, ">$vm_conf" or die "Cannot create/overwrite file: $vm_conf\n"; + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); + +# Get the possible contexts available +$statement = "SELECT DISTINCT context FROM $table_name"; +my $cresult = $dbh->selectall_arrayref($statement); +unless ($cresult) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} + +# Global Voicemail configuration options +print EXTEN "[general]\n\n"; +print EXTEN "format=wav49|wav\n"; +print EXTEN "operator=yes\n"; +print EXTEN "review=yes\n"; +print EXTEN "serveremail=AgileVoice\n"; +print EXTEN "attach=yes\n"; +print EXTEN "maxmessage=300\n"; +print EXTEN "minmessage=3\n"; +print EXTEN "maxsilence=5\n"; +print EXTEN "pbxskip=yes\n"; +print EXTEN "fromstring=AgileVoice\n"; +print EXTEN 'emailsubject=New voicemail from ${VM_CALLERID}'; print EXTEN "\n"; +print EXTEN 'emailbody=Dear ${VM_NAME}:\n\n\tJust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE} so you might\nwant to check it when you get a chance. Thanks!\n'; print EXTEN "\n"; +print EXTEN "mailcmd=/usr/sbin/sendmail -t\n"; + +print EXTEN "\n[zonemessages]\n"; +print EXTEN "eastern=America/New_York|'vm-received' Q 'digits/at' IMp\n"; +print EXTEN "central=America/Chicago|'vm-received' Q 'digits/at' IMp\n"; +print EXTEN "central24=America/Chicago|'vm-received' q 'digits/at' H 'digits/hundred' M 'hours'\n"; print EXTEN "\n"; + + + +my @cresultSet = @{$cresult}; +if ( $#cresultSet > -1 ) { + foreach $crow (@{ $cresult }) { + my @cresult = @{ $crow }; + + # Print the context out + print EXTEN "[".$cresult[0]."]\n"; + + $statement = "SELECT context, mailbox, password, fullname, email, pager, options from $table_name WHERE context='".$cresult[0]."'"; + my $result = $dbh->selectall_arrayref($statement); + unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; + } + my @resultSet = @{$result}; + if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + print EXTEN $result[1]." => ".$result[2].",".$result[3].",".$result[4]."\n"; + } + } + } +} + +exit 0; + diff --git a/avscripts/scripts1.6/agilevoice-pro-export-extensions b/avscripts/scripts1.6/agilevoice-pro-export-extensions new file mode 100755 index 00000000..8eb80061 --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-pro-export-extensions @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import sys +import posix +import os + +posix.system('/usr/sbin/agilevoice-pro-export-extensions.pl') +a = posix.system('diff -q /etc/asterisk/extensions_agilevoice.conf.tmp /etc/asterisk/extensions_agilevoice.conf >/dev/null 2>&1') +if a: + try: + os.unlink('/etc/asterisk/extensions_agilevoice.conf') + except OSError: + pass + posix.system('mv -f /etc/asterisk/extensions_agilevoice.conf.tmp /etc/asterisk/extensions_agilevoice.conf') + posix.system('asterisk -rx "extensions reload" >/dev/null 2>&1') + diff --git a/avscripts/scripts1.6/agilevoice-pro-export-extensions.pl b/avscripts/scripts1.6/agilevoice-pro-export-extensions.pl new file mode 100755 index 00000000..6bdc402e --- /dev/null +++ b/avscripts/scripts1.6/agilevoice-pro-export-extensions.pl @@ -0,0 +1,181 @@ +#!/usr/bin/perl -T +# Retrieves the voicemail entries from the database + +use DBI; +################### BEGIN OF CONFIGURATION #################### + +# the name of the extensions table +$table_name = "ab_voip_did"; +# the name of the blacklist table +$btable_name = "ab_voip_blacklist"; +# the path to the extensions.conf file +# WARNING: this file will be substituted by the output of this program +$ext_conf = "/etc/asterisk/extensions_agilevoice.conf.tmp"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; + +################### END OF CONFIGURATION ####################### + +my $dial = ""; +my $dialarg = ""; + +open EXTEN, ">$ext_conf" or die "Cannot create/overwrite file: $ext_conf\n"; + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); + + +$statement = "SELECT did, channel, channelarg, cnam, callforwardingenabled, busycallforwardingenabled, voicemailafter, cfringfor, cfnumber, bcfnumber, rxfax, conf, failover, failovernumber, remotecallforward, remotecallforwardnumber, blacklist, active, id from $table_name ORDER BY did"; +my $result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +my @resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + + $did = $result[0]; + $dial = $result[1]; + $dialarg = $result[2]; + $cnam = $result[3]; # ME + $cfe = $result[4]; + $bcfe = $result[5]; + $timelimit = $result[6]; + $cfringfor = $result[7]; + $cfnumber = $result[8]; + $bcfnumber = $result[9]; + $rxfax = $result[10]; + $conf = $result[11]; + $failover = $result[12]; + $failovernumber = $result[13]; + $rcf = $result[14]; + $rcfnumber = $result[15]; + $blacklist = $result[16]; #ME + $active = $result[17]; + $did_id = $result[18]; + + if (0 == length($dialarg)) { + $dialarg = $result[0]; + } + if ($dial =~ /IAX/) { + $dial = "IAX2/".$dialarg."/".$did; + } else { + $dial = "SIP/".$dialarg; + } + + if ($active == 0) { + gen_out_of_service($did); + } else { + if ($rxfax == 1) { + gen_fax($did); + } elsif ($conf == 1) { + gen_conf($did); + } elsif ($rcf == 1) { + gen_rcf($did, $rcfnumber); + } else { + $d = "Macro(agilevoice,"; + $d = $d.$dial.","; + $d = $d.$did.","; + if ($cfe == 1) { + $d = $d.$cfnumber.","; + } else { + $d = $d.","; + } + $d = $d.$cfringfor.","; + $d = $d.$timelimit.","; + if ($bcfe == 1) { + $d = $d.$bcfnumber.","; + } else { + $d = $d.","; + } + if ($failover == 1) { + $d = $d.$failovernumber.","; + } + $d = $d.")"; + $pri = 1; + if ($cnam == 1) { + print EXTEN "exten => ".$did.",".$pri.",AGI(cnam)\n"; + $pri++; + } + print EXTEN "exten => ".$did.",".$pri.",".$d."\n"; + print EXTEN "exten => ".$result[0].",".($pri + 1).",Hangup\n"; + if ($blacklist == 1) { + gen_blacklist($did_id,$did); + } + } + } + } +} + +exit 0; + +sub gen_blacklist +{ + my ($did_id, $did) = @_; + + $statement = "SELECT src, dst from $btable_name WHERE voip_did_id=$did_id ORDER BY src"; + my $result = $dbh->selectall_arrayref($statement); + unless ($result) { + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; + } + my @resultset = @{$result}; + if ($#resultset > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + + $src = $result[0]; + $dst = $result[1]; + $dst =~ s/ /(/; + $dst =~ s/$/)/; + print EXTEN "exten => ".$did."/".$src.",1,".$dst."\n"; + print EXTEN "exten => ".$did."/".$src.",2,Hangup\n"; + } + } +} + +sub gen_fax +{ + my ($did) = @_; + + print EXTEN "exten => ".$did.",1,SetVar(LOCALSTATIONID=\${CALLERIDNUM})\n"; + print EXTEN "exten => ".$did.",2,RxFax(/tmp/fax-%d.tif)\n"; + print EXTEN "exten => ".$did.",3,Hangup\n"; +} + +sub gen_conf +{ + my ($did) = @_; + + print EXTEN "exten => ".$did.",1,Meetme(".$did."|q)\n"; + print EXTEN "exten => ".$did.",2,Hangup\n"; +} + +sub gen_rcf +{ + my ($did, $rcfnumber) = @_; + + print EXTEN "exten => ".$did.",1,Dial(Local/".$rcfnumber."\@international/n)\n"; + print EXTEN "exten => ".$did.",2,Hangup\n"; +} + +sub gen_out_of_service +{ + my ($did) = @_; + + print EXTEN "exten => ".$did.",1,Playback(discon-or-out-of-service)\n"; + print EXTEN "exten => ".$did.",2,Hangup\n"; +} + diff --git a/avscripts/scripts1.6/cdr_import_agilevoice b/avscripts/scripts1.6/cdr_import_agilevoice new file mode 100755 index 00000000..4971e7a7 --- /dev/null +++ b/avscripts/scripts1.6/cdr_import_agilevoice @@ -0,0 +1,101 @@ +#!/usr/bin/perl -Tw +# +# Verify that all Asterisk native CSV records are stored in an AgileVoice CDR table +# +# Copyright (C) 2003-2005 Agileco LLC in association with Thralling Penguin LLC +# +# + +use DBI; +use Text::CSV; + +################### BEGIN OF CONFIGURATION #################### + +# the name of the cdr table +$table_name = "ab_voip_cdr"; +# the path to the Master.csv file +$csv_master = "/var/log/asterisk/cdr-csv/Master.csv"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; +# debugging mode? +$debug = 0; +################### END OF CONFIGURATION ####################### + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); + +sub get_id +{ + my ($table) = @_; + + $statement = "UPDATE ".$table."_id set id=LAST_INSERT_ID(id+1)"; + if ($debug) { + print $statement, "\n"; + } + $sth = $dbh->prepare($statement); + $sth->execute; + $id = $dbh->{mysql_insertid}; + $sth->finish; + return $id; +} + +sub verify +{ + my (@field) = @_; + my $count = 0; + + $statement = "SELECT COUNT(*) FROM $table_name WHERE date_orig=UNIX_TIMESTAMP(".$dbh->quote($field[9]).") and channel=".$dbh->quote($field[5])." and dstchannel=".$dbh->quote($field[6]); + if ($debug) { + print $statement, "\n"; + } + $sth = $dbh->prepare($statement); + $sth->execute; + my @result = $sth->fetchrow_array; + $count = $result[0]; + $sth->finish; + return $count; +} + +sub insert_cdr +{ + my (@field) = @_; + $id = get_id($table_name); + $statement = "INSERT INTO $table_name (id,site_id,date_orig,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode) VALUES ($id,1,UNIX_TIMESTAMP(".$dbh->quote($field[9])."),".$dbh->quote($field[4]).",".$dbh->quote($field[1]).",".$dbh->quote($field[2]).",".$dbh->quote($field[3]).",".$dbh->quote($field[5]).",".$dbh->quote($field[6]).",".$dbh->quote($field[7]).",".$dbh->quote($field[8]).",".$dbh->quote($field[12]).",".$dbh->quote($field[13]).",".$dbh->quote($field[14]).",".$dbh->quote($field[15]).",".$dbh->quote($field[0]).")"; + if ($debug) { + print $statement, "\n"; + } + $dbh->do($statement); +} + +my $csv = Text::CSV->new; +my $icount = 0; +my $ecount = 0; + +open CSV, "<$csv_master" or exit; +while ( ($line = ) ) { + chomp $line; + if ($csv->parse($line)) { + my @field = $csv->fields; + if (!verify(@field)) { + insert_cdr(@field); + $icount = $icount + 1; + } else { + #print "Record exists.\n"; + $ecount = $ecount + 1; + } + } else { + my $err = $csv->error_input; + print "parse() failed on argument: ", $err, "\n"; + } +} +close CSV; + +print "There were ".$icount." records inserted.\n"; +print "There were ".$ecount." records already in the database.\n"; +exit 0; + diff --git a/avscripts/scripts1.6/retrieve_iax_conf_from_mysql.pl b/avscripts/scripts1.6/retrieve_iax_conf_from_mysql.pl new file mode 100755 index 00000000..45a2d35c --- /dev/null +++ b/avscripts/scripts1.6/retrieve_iax_conf_from_mysql.pl @@ -0,0 +1,105 @@ +#!/usr/bin/perl -Tw +# Retrieves the iax user/peer entries from the database + +use DBI; +################### BEGIN OF CONFIGURATION #################### + +# the name of the extensions table +$table_name = "ab_voip_iax"; +# the path to the extensions.conf file +# WARNING: this file will be substituted by the output of this program +$iax_conf = "/etc/asterisk/iax_agilevoice.conf.tmp"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; + +################### END OF CONFIGURATION ####################### + +$additional = ""; + +open EXTEN, ">$iax_conf" or die "Cannot create/overwrite extensions file: $iax_conf\n"; + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); +$statement = "SELECT keyword,data from $table_name where iax='0' and keyword <> 'account' and (flags <> 1 or flags is null)"; +my $result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +my @resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + $additional .= $result[0]."=".$result[1]."\n"; + } +} + +# items with id like 9999999% get put at the top of the file +$statement = "SELECT keyword,data from $table_name where iax LIKE '9999999%' and keyword <> 'account' and (flags <> 1 or flags is null)"; +$result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +@resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + $top .= $result[0]."=".$result[1]."\n"; + } + print EXTEN "$top\n"; +} + +$statement = "SELECT data,iax from $table_name where keyword='account' and (flags <> 1 or flags is null) group by data"; +$result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; +} + +@resultSet = @{$result}; +if ( $#resultSet == -1 ) { + exit; +} + +foreach my $row ( @{ $result } ) { + my $account = @{ $row }[0]; + my $id = @{ $row }[1]; + print EXTEN "[$account]\n"; + $statement = "SELECT keyword,data from $table_name where iax='$id' and keyword <> 'account' and (flags <> 1 or flags is null) order by keyword DESC"; + my $result = $dbh->selectall_arrayref($statement); + unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; + } + + my @resSet = @{$result}; + if ( $#resSet == -1 ) { + print "no results\n"; + exit; + } + foreach my $row ( @{ $result } ) { + my @result = @{ $row }; + print EXTEN "$result[0]=$result[1]\n"; + } + print EXTEN "$additional\n"; +} + +exit 0; + diff --git a/avscripts/scripts1.6/retrieve_sip_conf_from_mysql.pl b/avscripts/scripts1.6/retrieve_sip_conf_from_mysql.pl new file mode 100755 index 00000000..072aaff6 --- /dev/null +++ b/avscripts/scripts1.6/retrieve_sip_conf_from_mysql.pl @@ -0,0 +1,115 @@ +#!/usr/bin/perl -Tw +# Retrieves the sip user/peer entries from the database +# Use these commands to create the appropriate tables in MySQL +# +#CREATE TABLE sip (id INT(11) DEFAULT -1 NOT NULL,keyword VARCHAR(20) NOT NULL,data VARCHAR(50) NOT NULL, flags INT(1) DEFAULT 0 NOT NULL,PRIMARY KEY (id,keyword)); +# +# if flags = 1 then the records are not included in the output file + +use DBI; +################### BEGIN OF CONFIGURATION #################### + +# the name of the extensions table +$table_name = "ab_voip_sip"; +# the path to the extensions.conf file +# WARNING: this file will be substituted by the output of this program +$sip_conf = "/etc/asterisk/sip_agilevoice.conf.tmp"; +# the name of the box the MySQL database is running on +$hostname = "%%AGILE_DB_HOST%%"; +# the name of the database our tables are kept +$database = "%%AGILE_DB_DATABASE%%"; +# username to connect to the database +$username = "%%AGILE_DB_USERNAME%%"; +# password to connect to the database +$password = "%%AGILE_DB_PASSWORD%%"; +# if slashes should always be striped from the generated file +$stripslashes = 0; + +################### END OF CONFIGURATION ####################### + +$additional = ""; + +open EXTEN, ">$sip_conf" or die "Cannot create/overwrite extensions file: $sip_conf\n"; + +$dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); +$statement = "SELECT keyword,data from $table_name where sip='0' and keyword <> 'account' and (flags <> 1 or flags is null)"; +my $result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +my @resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + $additional .= $result[0]."=".$result[1]."\n"; + } +} + +# items with id like 9999999% get put at the top of the file +$statement = "SELECT keyword,data from $table_name where sip LIKE '9999999%' and keyword <> 'account' and (flags <> 1 or flags is null)"; +$result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; +} +@resultSet = @{$result}; +if ( $#resultSet > -1 ) { + foreach $row (@{ $result }) { + my @result = @{ $row }; + $top .= $result[0]."=".$result[1]."\n"; + } + print EXTEN "$top\n"; +} + +$statement = "SELECT data,sip from $table_name where keyword='account' and (flags <> 1 or flags is null) group by data"; +$result = $dbh->selectall_arrayref($statement); +unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; +} + +@resultSet = @{$result}; +if ( $#resultSet == -1 ) { + exit; +} + +foreach my $row ( @{ $result } ) { + my $account = @{ $row }[0]; + my $id = @{ $row }[1]; + print EXTEN "[$account]\n"; + $statement = "SELECT keyword,data from $table_name where sip='$id' and keyword <> 'account' and (flags <> 1 or flags is null) order by keyword DESC"; + my $result = $dbh->selectall_arrayref($statement); + unless ($result) { + # check for errors after every single database call + print "dbh->selectall_arrayref($statement) failed!\n"; + print "DBI::err=[$DBI::err]\n"; + print "DBI::errstr=[$DBI::errstr]\n"; + exit; + } + + my @resSet = @{$result}; + if ( $#resSet == -1 ) { + print "no results\n"; + exit; + } + foreach my $row ( @{ $result } ) { + my @result = @{ $row }; + if ( $stripslashes ) { + $result[1] =~ s/\\//g; + } + print EXTEN "$result[0]=$result[1]\n"; + } + print EXTEN "$additional\n"; +} + +exit 0; +