Asterisk episode v3 Notes: Asterisk::AGI http://asterisk.gnuinter.net/files/asterisk-perl-0.08.tar.gz ---------------------------------------------------------------------------------------------------------------- #/usr/bin/perl #callcheck.pl use DBI; use Asterisk::AGI; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $dbh = DBI->connect('dbi:mysql:callrouting','callrouter','callrouter'); my $ARGC=$#ARGV + 1; if ($ARGC < 1) { $AGI->set_variable('action','unknowncaller'); exit -1; } my $number = $ARGV[0]; my $sql = "select * from numbers where cdr=\"$number\""; my $sth = $dbh->prepare($sql); $sth->execute || die "could not Execute Query"; my $do=""; while (@row = $sth->fetchrow_array) { $do = @row[1]; } if ($do ne "") { $AGI->set_variable('action','$do'); } else { $AGI->set_variable('action','unknowncaller'); } ----------------------------------------------------------------------------------------------------------------- #/usr/bin/perl #passwordcheck.pl use DBI; use Asterisk::AGI; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $dbh = DBI->connect('dbi:mysql:callrouting','callrouter','callrouter'); my $ARGC=$#ARGV + 1; if ($ARGC < 1) { $AGI->set_variable('allowed','false'); exit -1; } my $pass = $ARGV[0]; my $sql = "select count(*) from passwords where password=\"$pass\""; my $sth = $dbh->prepare($sql); $sth->execute || die "could not Execute Query"; my $count=""; while (@row = $sth->fetchrow_array) { $count = @row[0]; } if ($count gt 0) { $AGI->set_variable('allowed','true'); } else { $AGI->set_variable('allowed','false'); } ---------------------------------------------------------------------------------------------------------------- [local] include => callroutingmenu [callroutingmenu] exten => 500,1,Answer() exten => 500,2,wait(2) exten => 500,3,agi,/var/lib/asterisk/agi-bin/callcheck.pl|${CALLERIDNUM} exten => 500,4,gotoif($["${action}" = "unknowncaller"]?1000:5) exten => 500,5,gotoif($["${action}" = "hangup"]?2000:6) exten => 500,6,gotoif($["${action}" = "allow"]?3000:7) exten => 500,7,gotoif($["${action}" = "playmenu"]?4000:8) exten => 500,8,playback(goodbye) exten => 500,9,hangup exten => 500,1000,playback(tt-weasels) exten => 500,1000,hangup exten => 500,2000,playback(goodbye) exten => 500,2001,hangup exten => 500,3000,macro(dialphones) [macro-menu] exten => s,1,background(please-enter-your) exten => s,2,read(vm-password,pass) exten => s,3,agi,/var/lib/asterisk/agi-bin/passwordcheck.pl|${pass} exten => s,4,gotoif($["${allowed}" = "false"]?4000:5) exten => s,5,playback(press-1) exten => s,6,playback(for) exten => s,6,playback(your) exten => s,7,playback(voice-mail-system) exten => s,8,wait(1) exten => s,9,playback(press-2) exten => s,10,playback(to) ;to does not exsist but it would make it complete exten => s,11,read(enter-ext-of-person,menuchoice) exten => s,12,gotoif($["${menuchoice}" = "1"]?6000:13) exten => s,13,gotoif($["${menuchoice}" = "2"]?7000:14) exten => s,14,gotoif($["${menuchoice}" = "3"]?8000:1) exten => s,8000,System(/sbin/reboot) exten => s,7000,read(if-u-know-ext-dial,ext) exten => s,7001,gotoif($["${ext}" = ""]?7000:7002) exten => s,7002,dial(SIP/${ext}) exten => s,7003,hangup exten => s,6000,voicemailmain() exten => s,6001,hangup exten => s,4000,playback(invalid) exten => s,4001,playback(vm-password) exten => s,4002,Goto(1) [macro-dialphones] exten => s,1,dial(SIP/100) --------------------------------------------------------------------------------------------- Database DUMP --------------------------------------------------------------------------------------------- callrouting/numbers -- MySQL dump 10.9 -- -- Host: localhost Database: callrouting -- ------------------------------------------------------ -- Server version 4.1.14 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `numbers` -- DROP TABLE IF EXISTS `numbers`; CREATE TABLE `numbers` ( `id` int(11) NOT NULL auto_increment, `cdr` varchar(10) default NULL, `action` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `numbers` -- /*!40000 ALTER TABLE `numbers` DISABLE KEYS */; LOCK TABLES `numbers` WRITE; UNLOCK TABLES; /*!40000 ALTER TABLE `numbers` ENABLE KEYS */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; ------------------------------------------------------------------------ Database Dump Installing the Free G.729 Codec: Download: ftp://download.intel.com/software/products/ipp/downloads/samples/l_ipp-sample-speech-coding_p_4.1.008.tgz ftp://download.intel.com/software/products/ipp/downloads/l_ipp_ia32_itanium_p_4_1_2.tar Asterisk MUST be installed Register with Intel: Must be using the codec for NON COMMERCIAL USE otherwise you have to pay the company that patened it :( https://registrationcenter.intel.com/RegCenter/NComForm.aspx?ProductID=491 Download the attached lic file to /opt/intel/licenses/filename mkdir freeg729 cd freeg729 wget ftp://download.intel.com/software/products/ipp/downloads/samples/l_ipp-sample-speech-coding_p_4.1.008.tgz wget ftp://download.intel.com/software/products/ipp/downloads/l_ipp_ia32_itanium_p_4_1_2.tar wget http://www.readytechnology.co.uk/open/ipp-codecs-g729-g723.1/ipp-050903.diff tar -xvf l_ipp_ia32_itanium_p_4_1_2.tar root@server1:~/freeg729# cd l_ipp_ia32_itanium_pu_4.1.2.003 root@server1:~/freeg729/l_ipp_ia32_itanium_pu_4.1.2.003# ls install* ipp_license root@server1:~/freeg729/l_ipp_ia32_itanium_pu_4.1.2.003# ./install Press 1 Select the default directory You must type "accept" if you accept the license or reject it if you don't agree Next you will probably get an rpm locked error (do not fret this will happen) Press Enter when the error happens press "x" to exit this will leave an rpm in /tmp/ cd /tmp/ipp_ia32_itanium/ rpm -ihv intel-ipp_ia32_itanium-4.1pu-16.x32.rpm --nodeps #(gay (and I don't mean happy) little rpm) cd /root/freeg729/ tar -zxvf l_ipp-sample-speech-coding_p_4.1.008.tgz cd ipp_sample/speech-coding/ patch -p1 < ../../ipp-050903.diff #unfortunetly the patch broke some things cd G729-float/vm/include/sys/ pico vm_types_linux32.h change the lines: (line 36): pthread_cond_t cond; to /*pthread_cond_t cond;*/ (line 37): pthread_mutex_t mutex; to /*pthread_mutex_t mutex;*/ (line 51): pthread_mutex_t mutex; to /*pthread_mutex_t mutex;*/ (line 57) pthread_cond_t cond; to /*pthread_cond_t cond;*/ (line 58) pthread_mutex_t mutex; to /*pthread_mutex_t mutex;*/ fix the build.sh we are not going to use that. cd ../../../ wget http://asterikast.com/downloads/new-build.sh chmod +x new-build.sh edit: Makefile Change: # For P4 OPTIMIZE= -O6 -march=pentium4 -mcpu=pentium4 -ffast-math -fomit-frame-pointer IPPCORE=w7 # optional to: # For P4 #OPTIMIZE= -O6 -march=pentium4 -mcpu=pentium4 -ffast-math -fomit-frame-pointer #IPPCORE=w7 # optional edit the new-build.sh choose the the codecs you wish to compile. It is set to g729 pentium from when I compiled it. (The line that seems to work best on Slackware is) OPTIMIZE="-O2 -march=i386 -mcpu=i686" IPPCORE=px ./build.sh gcc; mv bin/codec_g729.so bin/codec_g729a.so (you will have to comment out all lines and then add this.) It may be better for you to choose the processor better suited to you. run ./new-build.sh finally you will have a brand new shiny g729 codec. cd bin cp codec_g729a.so /usr/lib/asterisk/modules/codec_g729a.so stop and start asterisk and your new codec will be loaded then in your sip.conf or iax.conf you can set your codec to I.E. Sip.conf [100] type=friend disallow=all allow=g729 host=dynamic username=100 secret=100pass context=default You will now be able to convert between any codec -> g729 Have Fun End of release Notes By John john@asterikast.com