Tikejhya: Ashish Nepal

Knowledgebase

Category: Asterisk (Page 1 of 2)

Script: Asterisk, FreePBX and Centos

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

This script might need some tweaking as per your environment. This script help’s you install Asterisk and freepbx on centos/redhat boxes with necessary dependency.

Bottom of the page will be updated which shall give you potential problem and solution.
#!/bin/bash

# Get ready
function getReady() {
yum -y update
yum groupinstall core
yum groupinstall base

yum install gcc gcc-c++ bison mysql-devel mysql-server php php-mysql php-pear php-mbstring tftp-server httpd make ncurses-devel libtermcap-devel sendmail sendmail-cf caching-nameserver sox newt-devel libxml2-devel libtiff-devel audiofile-devel gtk2-devel subversion kernel-devel git subversion kernel-devel

pear install db
}

# Download Files
# You may want to check and replace download source with latest version.
function downloadRequired() {
cd /usr/local/src/
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
wget https://iksemel.googlecode.com/files/iksemel-1.4.tar.gz

}

# Install iksemel
function compileIksemel() {
cd /usr/local/src/
tar xf iksemel-1.4.tar.gz
cd /usr/local/src/iksemel-1.4/
./configure && make && make install

}

# Install LIBPRI
function compileLibpri() {

cd /usr/local/src/
tar xf libpri-1.4-current.tar.gz
cd /usr/local/src/libpri-1.4.14/
./configure && contrib/scripts/get_mp3_source.sh
make menuselect && make && make install && make config
}

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

# Compile and install Asterisk
function compileAsterisk() {
cd /usr/local/src/
tar xvfz asterisk-11-current.tar.gz
cd /usr/local/src/asterisk-11.1.0
./configure
contrib/scripts/get_mp3_source.sh
make menuselect

#### You Will have to select mysql_cdr options on the very first make menuselect screen, Select all 5 option to enable asteriskcdr function.

make
make install
make config
}

# Extra Sounds
function extraSounds() {

cd /var/lib/asterisk/sounds
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-gsm-current.tar.gz
tar xfz asterisk-extra-sounds-en-gsm-current.tar.gz
rm -f asterisk-extra-sounds-en-gsm-current.tar.gz

}

# Download and extract FreePBX
function extractFreepbx() {
export VER_FREEPBX=2.11
cd /usr/local/src/
svn co http://www.freepbx.org/v2/svn/freepbx/branches/${VER_FREEPBX} freepbx
cd freepbx
}

function getApacheReady() {
adduser asterisk -M -c "Asterisk User"
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib/asterisk
mkdir /var/www/html
chown -R asterisk. /var/www/

sed -i 's/(^upload_max_filesize = ).*/120M/' /etc/php.ini
sed -i 's/^(User|Group).*/1 asterisk/' /etc/httpd/conf/httpd.conf

service httpd restart
}

function createDb() {
export ASTERISK_DB_PW=a2c0In
mysqladmin -u root create asterisk
mysqladmin -u root create asteriskcdrdb
mysql -u root asterisk < SQL/newinstall.sql mysql -u root asteriskcdrdb < SQL/cdr_mysql_table.sql mysql -u root -e "GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY '${ASTERISK_DB_PW}';" mysql -u root -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY '${ASTERISK_DB_PW}';" mysql -u root -e "flush privileges;" } compileIksemel compileLibpri compileAsterisk extractFreepbx getApacheReady createDb ##### Finalize ################### ./start_asterisk start ./install_amp amportal a ma installall amportal a reload ##################################

Asterisk Active Call

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

watch -n 1 “sudo asterisk -vvvvvrx ‘core show channels’ | grep call”

Asterisk g729 support

How to install right codec (e.g. g729 support)
identify

cat /proc/cpuinfo/
cat /etc/redhat-release

check your cpu and release download required code.so.

asterisk -rx “module load codec_g729.so”
1017 asterisk -rvvvvvv
1018 asterisk -rx “core show translations” | grep -i g729
1019 asterisk -rx “core show translation” | grep -i g729

[root@server ashish.nepal]# asterisk -rx “core show translation” | grep -i g729
g723 gsm ulaw alaw g726aal2 adpcm slin lpc10 g729 speex ilbc g726 g722 siren7 siren14 slin16 g719 speex16 testlaw
g729 – 2000 1001 1001 3000 1001 1000 2000 – – 7999 2999 2000 – – 3000 – – 1001

ref: http://asterisk.hosting.lv/

Asterisk If Else extension.conf

Asterisk Log, Asterisk If Else then conditions, Asterisk System command

//Setting Callerid To Caller Name
//This will work if we have entires in Asterisk DB
//can be found under *CLI> database show cidname
exten=> _.,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})

// If else with extension “Asterisk”
exten=> _.,n,Set(foo=${IF($[ ${CALLERID(dnid)} = 44111111111]?customer_a:${IF($[ ${CALLERID(dnid)} = 4422222222]?Customer_b:Customer_c)})})

//This can also be achieved by noop
//Logging or Echo Variable
exten=> _.,n,Log(NOTICE, “Callerid TO: ${CALLERID(to)}”)

//Running Command from dialplan Asterisk (Bash)
exten=> _.,n,System(/etc/asterisk/my_script.sh)

Sample:

Pre-Routing: conditional messaging.

[context]

exten=> _.,1,NoOp(Incoming Call)

exten=> _.,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})

exten=> _.,n,Set(foo=${IF($[ ${CALLERID(dnid)} = 012345678]?Client1:${IF($[ ${CALLERID(dnid)} = 234567]?Client2:Client3)})})
exten=> _.,n,Set(bar=${IF($[ ${CALLERID(dnid)} = 45464554645]?SomeOne:${IF($[ ${CALLERID(dnid)} = 4654758]?SomeTwo:SomeThree)})})

exten=> _.,n,Log(NOTICE, “Callerid TO: ${CALLERID(to)}”)

exten=> _.,n,System(/etc/asterisk/sendim.sh ${bar} ‘There is an Incoming call From ${CALLERID(name)} Caller Id: ${CALLERID(num)} n Customer try
ing to reach ${foo}’)

exten=> _.,n,NoOp(Sending to PSTN Now)
exten=> _.,n,goto(from-pstn,${EXTEN},1)

secure asterisk server with iptables

Secure Asterisk Server

iptables -A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT
# This has to be port open on rtp.conf

iptables -A INPUT -p udp -m udp --dport 5060 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 5038 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 1720 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

And reject all

Securing Asterisk Server (Simple tips)

Securing Asterisk Server (Simple tips)

Change Admin: User: Done

Use Monitoring such as Ossec for any suspecious alerts.

Change root password if its simple

vi /var/www/html/recordings/includes/main.conf
Console= disabled

Extension passwords to be complicated (Auto generated)

Iptables

-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#Open for Web UI,SSH and SSL
-A INPUT -p tcp -m multiport --dport 80,443,22 -j ACCEPT

# IP to allow SIP Port
-A INPUT -p udp -m udp -s x.x.x.x/32 --dport 5060 -j ACCEPT

# DDI Providers IP All range
-A INPUT -p udp -m udp -s xx.xx.Xxx.x/25 --dport 5060 -j ACCEPT

# RTP PORT as mentioned in rtp conf file
-A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT


#Block Everything Else
-A INPUT -j REJECT --reject-with icmp-host-prohibited

From Freepbx web or conf

For each Extension:

deny = 0.0.0.0/0.0.0.0 (All)
Permit = XX.XX.XX.XX/255.255.255.255 (Only My IP)

How to make Asterisk accept HTTPS

How to make Asterisk accept HTTPS

yum install mod_ssl

Change your ssl.conf setting with required certificate file and document dir

And

# Redirect all requests to port 80 to port 443 SSL via mod_rewrite

# make sure the module is loaded and switched on


LoadModule rewrite_module /usr/lib/httpd/modules/mod_rewrite.so


RewriteEngine on

# The line below sets the rewrite condition for mod_rewrite.so.
# That is, if the server port does not equal 443, then this condition is true

ReWriteCond %{SERVER_PORT} !^443$

# redirect rule

RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

pre-routing calls before it reaches freepbx

How to pre-route calls before it reaches freepbx.

[I have situation where i am executing script before call is connected.]

[notification]

exten=> _.,1,NoOp(Incoming Call)
exten=> _.,n,GotoIf($["${CALLERID(dnid)}" != "44xxxxxxxxxx"]?final)
exten=> _.,n,System(/path/to/script/ CS 'There is an Incoming call From ${CALLERID(name)} ${CALLERID(all)} n Customer trying to reach ${CALLERID(dnid)}')
exten=> _.,n,NoOp(Sending to PSTN Now)
exten=> _.,n,goto(from-pstn,${EXTEN},1)

You are using the default Asterisk Manager password that is widely known

You are using the default Asterisk Manager password that is widely known, you should set a secure password

Setting ¬ Advance Setting ¬ Asterisk Manager Password
(Change password and Apply configuration)

How to get rid of annoying asterisk pre-greeting message

How to get rid of annoying asterisk pre-greeting message “Extension 111 is unavailable”

Solution:
Record pre-greeting messages
*97 and follow menu

Page 1 of 2

Powered by WordPress & Theme by Anders Norén