Asterisk + FreeSwitch + Skype. Detailed guide



Good day to the residents of Habr!

Having experience in installing voip-servers based on Asterisk, I decided to offer my detailed guide on installing a call-center based on Asterisk in conjunction with Skype. In view of the popularization of Skype, this network began to be used for call centers of many companies. Using its official client greatly limits our possibilities. This assembly allows you to increase the number of simultaneous calls from Skype-network.

1. Updating the server

Install all the necessary packages and updates. In the console, enter the commands:
apt-get update
apt-get upgrade
apt-get install build-essential mc automake autoconf bison flex libtool libncurses5-dev libssl-dev dahdi-source subversion x11vnc yate-qt4 yate-mysql yum op-panel
apt-get -f install
apt-get install yate-qt4 yate-mysql yum op-panel


2. Safety Notes

Almost always, immediately after installing the server, the selection of passwords begins using the standard port (22) of the ssh protocol to your server. If God forbid, you will set a standard password known to the "sorters", your server will be captured and all important data will be deleted. The easiest way is to change the port number:

nano  /etc/ssh/sshd_config

Find the line (almost at the very beginning): Port 22 . Change the number 22 to whatever you like, ad infinitum (preferably not more than 65535). Restart ssh:

/etc/init.d/ssh restart

3. Install Asterisk

3.1. Everything is installed from repositories.

apt-get install asterisk asterisk-mp3 asterisk-mysql asterisk-ooh323c asterisk-h323 asterisk-sounds-main asterisk-moh-opsound-g722 asterisk-moh-opsound-gsm asterisk-moh-opsound-wav

3.2. Installing the Web GUI:

mkdir -p /root/asterisk/asterisk-gui
cd /root/downloads/asterisk-gui/
svn checkout http://svn.digium.com/svn/asterisk-gui/trunk asterisk-gui
svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0/
cd /root/downloads/asterisk-gui/2.0/
./configure
make
make install # (Устанавливается в /var/lib/asterisk/)
cp -r /etc/asterisk /etc/asterisk.backup
chown -R asterisk:asterisk /var/lib/asterisk/

3.3. Add the login information to the manager.conf file:

nano /etc/asterisk/manager.conf
enabled = yes
webenabled = yes
port = 5038
bindaddr = 127.0.0.1
[root]
secret = toor
read = system,call,log,verbose,command,agent,user,config
write = system,call,log,verbose,command,agent,user,config

Where “root” is the server administrator and “toor” is the administrator password.
Editing http.conf:

nano /etc/asterisk/http.conf


enabled=yes 
enablestatic=yes
bindaddr = 127.0.01
redirect = / /static/config/cfgbasic.html
[post_mappings]
backups = /var/lib/asterisk/gui_backups

3.4. We take the necessary steps to complete

cd /root/downloads/asterisk-gui/2.0/
make checkconfig

Delete the folder / usr / share / asterisk / static-http / before creating a symbolic link:

ln -s /var/lib/asterisk/static-http/ /usr/share/asterisk/
mk dir /usr/share/asterisk/static-http/config
chmod 777 /usr/share/asterisk/static-http/config
/etc/init.d/asterisk restart

Check:

In Ubuntu, the root directory of the Asterisk web server is located in / usr / share / asterisk / static-http / ,
and the GUI is installed in / var / lib / asterisk / static-http , so you need to delete the empty folder:

rmdir /usr/share/asterisk/static-http/

And create a link:

ln -s /var/lib/asterisk/static-http/ /usr/share/asterisk/
cd ~/asterisk-gui/
sudo make checkconfig

3.5. Starting and stopping Asterisk

If you installed Asterisk, you can start it with the command:

/usr/src/asterisk -vvvgc

You can stop Asterisk from the CLI with the “stop now” command.
With no arguments, Asterisk starts as a daemon.

/usr/sbin/asterisk 

It can be connected to the command interface (CLI) using the argument 'r'.

/usr/sbin/asterisk -r или просто asterisc -r

Rebooting configuration files without a full reboot:

asterisk -rx reload

If the GUI hangs on the “Checking write permission for gui folder”, then:
First you need to replace the line in the file /var/lib/asterisk/static-http/config/js/astman.js

timeout : '60000' 

On the
timeout : '6'


If this does not help, then reset all rights:

chown -R asterisk:asterisk /var/lib/asterisk/
chmod -R 777 /var/lib/asterisk/
chown -R asterisk:asterisk /etc/asterisk/
chmod -R 777 /etc/asterisk/

3.6. Create Asterisk Group and User

/usr/sbin/groupadd asterisk 
/usr/sbin/useradd -d /var/lib/asterisk -g asterisk asterisk 

3.7. Change permissions

Change the permissions to use the following files:

chown --recursive asterisk:asterisk /var/lib/asterisk
chown --recursive asterisk:asterisk /var/log/asterisk
chown --recursive asterisk:asterisk /var/run/asterisk
chown --recursive asterisk:asterisk /var/spool/asterisk
chown --recursive asterisk:asterisk /usr/lib/asterisk
chown --recursive asterisk:asterisk /etc/asterisk/

## If you are using Zaptel:

chown --recursive asterisk:asterisk /dev/zap

## If you are using DAHDI

chown --recursive asterisk:asterisk /dev/dahdi

# ------------------------------------------------- ---

chmod --recursive u=rwX,g=rX,o= /var/lib/asterisk
chmod --recursive u=rwX,g=rX,o= /var/log/asterisk
chmod --recursive u=rwX,g=rX,o= /var/run/asterisk
chmod --recursive u=rwX,g=rX,o= /var/spool/asterisk
chmod --recursive u=rwX,g=rX,o= /usr/lib/asterisk

## If you are using Zaptel

chmod --recursive u=rwX,g=rX,o= /dev/zap

## If you are using DAHDI

chmod --recursive u=rwX,g=rX,o= /dev/dahdi

# ------------------------------------------------- ---

chown --recursive asterisk:asterisk /etc/asterisk
chmod --recursive u=rwX,g=rX,o= /etc/asterisk 

3.8. Asterisk

/ usr / lib / asterisk / modules directories : Contains binary files (modules, codecs).
/ var / lib / asterisk: Contains variable data (sounds, scripts, etc.).
/ var / spool / asterisk: Files created during operation (voice messages, outgoing calls, etc.).
/ var / log / asterisk: Logs, call information.
/ etc / asterisk: Asterisk configuration files.

Configurations:
musiconhold.conf - Setting the "music on hold" MusicOnHold.
cdr_mysql.conf - Setting up the storage of call records in MySQL.
manager.conf - Configuring the Manager interface.
meetme.conf - Configure conferences (meetme).
mgcp.conf - Configure MGCP device settings.
parking.conf - Parameters of “parking” calls “Call parking”.
voicemail.conf - Voice Mail Settings (VoiceMail).
agents.conf - Asterisk Agents.
extensions.conf - Asterisk license plate.
iax.conf - Configuring IAX devices.
modem.conf - Configure ISDN using ISDN4Linux.
vpb.conf - Configuring Voicetronix hardware.
alsa.conf - ALSA sound driver settings for the console user.
festival.conf - Parameters for working with the festival speech synthesizer.
modules.conf - Configuring Asterisk modules.
zapata.conf - Setting up analog digium telephony devices.
asterisk.conf - Locating Asterisk directories.
indications.conf - Setting the parameters of analog automatic telephone exchanges of different countries.
rpt.conf - rtp protocol parameters.
logger.conf - Asterisk logging options.

The Asterisk Web GUI control panel will be available at: host : 8088, where host is the address of the server on which Asterisk is located.

3.9 Configuring Asterisk via the

Trunks Web GUI . Voip trunks:
Provider Name: SIBNET
Hostname: sibnet.ru
Username: user123
Password: pass123
CallerID: user
FromDomain: sibnet.ru
FromUser: user123 Outgoing

Calling Rules:
Calling Rule Name: World
Pattern: _XXXXXXXXXXX
Caller ID: Admin
Destination: 6001
Use Trunk: SIBNET

DialPlans:
DialPlan Name: user
Include Outgoing Calling Rules: World
Include Local Contexts: default parkedcalls conferences ringgroups voicemenus queues voicemailgroups directory pagegroups page_an_extension

Incoming Calling Rules:
Pattern: _XXXXXXXXXXXX
Destination: 6001

4. We proceed to the installation of Skype

4.1. Create the file /etc/yum.repos.d/skype.repo and add to it:

[skype]
name=Skype Repository
baseurl=http://download.skype.com/linux/repos/fedora/updates/i586/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-skype

Install by command:
yum --nogpgcheck install skype

Or from packages:

wget www.skype.com/go/getskype-linux-deb
apt-get -f install
dpkg -i skype-debian_2.0.0.72-1_i386.deb или dpkg -i getskype-linux-deb
aptitude install skype

4.2. Installation of additional packages

On rpm.pbone.net we search, download and install qt4, qt4-x11 packages.
Also:

yum install x11vnc или apt-get install x11vnc

4.3. Setup

We get the user under whom Skype will work:

adduser --home /home/skype --ingroup audio --disabled-password skype

Create a directory from which Skype will read its config:

mkdir -p /home/skype/multi/interface01
chown -R skype.audio /home/skype/multi

If skype will turn off, then you can try this method:
nano or vim / usr / local / bin / skype_start with the following contents:
Spoiler
#!/bin/sh
SKYPE_SYSTEM_USER=skype
SKYPE_HOME=/home/skype/multi
SKYPE_USER=username
SKYPE_PASSWORD=userpass
SKYPE_INSTANCES=N
XVFB=/usr/bin/Xvfb
module_reload() {
  rmmod snd-dummy
  modprobe snd-dummy
}
skype_start() {
  for i in $(seq 1 $SKYPE_INSTANCES); do
    i=`printf "%02d" $i`
    $XVFB :1$i -ac >> /dev/null 2>&1 &
    sleep 3
    su $SKYPE_SYSTEM_USER -c "/bin/echo '$SKYPE_USER $SKYPE_PASSWORD'| DISPLAY=:1$i  /usr/bin/skype \
    --dbpath=$SKYPE_HOME/interface$i --pipelogin >> /dev/null 2>&1 &"
    echo "Skype $i started"
  done
}
skype_stop() {
kill -TERM `ps -u $SKYPE_SYSTEM_USER -o pid=` >> /dev/null 2>&1
sleep 3
kill -TERM `ps -C Xvfb -o pid=` >> /dev/null 2>&1
}
case "$1" in
  start)
        module_reload
        sleep 3
        skype_start
        ;;
  stop)
        skype_stop
        ;;
  restart)
        skype_stop
        sleep 3
        skype_start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac


We make it executable:

chmod +x /usr/local/bin/skype_start

4.4. Launch

Launch the VNC server

aptitude install x11vnc
/usr/bin/Xvfb :101 -ac &
x11vnc -display :101

Create a file where the password for authorization will be stored:

mcedit /home/passwd

Create a password:

x11vnc -storepasswd 123456 /home/passwd

Rights:

chmod 777 /home/passwd
chown rr /home/passwd

Process stop:

ps ax | grep vnc
kill 22062 # (номер процесса)

Before starting Skype, you need to run these modules:

rmmod snd-dummy
modprobe snd-dummy
echo "snd_dummy" >> /etc/modules

Launch Skype:

su skype -c "/bin/echo 'username userpass'| DISPLAY=:101 /usr/bin/skype --dbpath=/home/skype/multi/interface01 --pipelogin &"
kill skype # остановка Skype
ps aux # проверка

By connecting via vnc to the server, you can see the Skype launched in the previous step, in the settings of which you need to remove all unnecessary things (disable events, automatically change status, etc.) and select the dummy driver as all sound devices (Dummy-HW 2.0) .

5. Installing FreeSwitch

5.1. Installing the necessary libraries:

apt-get -y install build-essential subversion automake autoconf wget libtool libncurses5-dev xvfb libx11-dev libasound2-dev xfs xfonts-100dpi xfonts-75dpi xfonts-scalable
apt-get install autoconf automake g++ git-core libjpeg62-dev libncurses5-dev libtool make python-dev gawk pkg-config gnutls-bin
apt-get install libcurl4-openssl-dev libexpat1-dev libgnutls-dev libtiff4-dev libx11-dev unixodbc-dev libssl-dev python2.6-dev zlib1g-dev libzrtpcpp-dev libasound2-dev libogg-dev libvorbis-dev libperl-dev libgdbm-dev libdb-dev python-dev uuid-dev bison
yum install expat-devel gnutls-devel libtiff-devel libX11-devel unixODBC-devel libssl-devel python-devel  zlib-devel libzrtpcpp-devel alsa-lib-devel libogg-devel libvorbis-devel perl-libs gdbm-devel libdb-devel uuid-devel @development-tools

5.2. Download FreeSwitch:

cd /usr/local/src
git clone git://git.freeswitch.org/freeswitch.git
cd freeswitch
./bootstrap.sh

5.3. Editing modules.conf:

nano /usr/local/src/freeswitch/modules.conf

We check and add all the missing:

applications/mod_limit
codecs/mod_voipcodecs
endpoints/mod_skypopen
mod_say_ru
formats/mod_file_string

5.4. Assembly and installation

cd /usr/local/src/freeswitch
./configure
make
make install all cd-sounds-install cd-moh-install uhd-sounds-install uhd-moh-install hd-sounds-install hd-moh-install sounds-install moh-install

5.5. Copy the mod_skypopen configuration and init script to run FreeSwitch:

cp /usr/src/freeswitch/src/mod/endpoints/mod_skypopen/configs/skypopen.conf.xml /usr/local/freeswitch/conf/autoload_configs/
cp /usr/src/freeswitch/debian/freeswitch.init /etc/init.d/freeswitch
cp debian/freeswitch.default /etc/default/freeswitch
sed -i 's/opt/usr\/local/g' /etc/init.d/freeswitch
sed -i 's/false/true/g' /etc/default/freeswitch

5.6. Getting a user for FreeSwitch

adduser --disabled-password --quiet --system --home /usr/local/freeswitch --gecos "FreeSwitch Voice Platform" --ingroup daemon freeswitch
adduser freeswitch audio
chown -R freeswitch.daemon /usr/local/freeswitch
chmod -R o-rwx /usr/local/freeswitch/

5.7. Launch and other FreeSwitch commands

load mod_skypiax # загрузка модуля 			
sk list # проверка загруженности модуля 
console loglevel 9 # поднимаем уровень логирования
shutdown # остановка работы FreeSwitch
/usr/local/freeswitch/bin/freeswitch # запуск FreeSwitch

5.8. Mod Skypopen

Now let's move on to the most important setting - the Public API. Here you need to allow mod_skypopen to contact Skype.
Skype itself allows you to add programs to the “Allowed programs” list only after they contact Skype, but only to make such settings it is not advisable to run FreeSwitch and mod_skypopen, so the creators of mod_skypiax have written a small utility that simulates mod_skypopen calling Skype. It is located in the FreeSwitch source tree and needs to be compiled separately:

cd /usr/local/src/freeswitch/src/mod/endpoints/mod_skypopen/configs/old-stuff
gcc -Wall -ggdb skypopen_auth.c -o skypopen_auth -lX11

You should definitely have a VNC screen open right now.

Launch skypopen:
./skypopen_auth :101

Return to the vnc connection window - in the dialog that appears, you need to enable Skype to connect to the skypopen API. You can also do this in the file /home/skype/multi/interface01/username/config.xml. Having given this view:

skypopen202


6. Configuration settings

An important point is that skype clients must be launched before loading the mod_skypopen module, i.e. before starting FreeSwitch. Also, stopping already used mod_skypopen copies of Skype will cause FreeSwitch to crash.

6.1. Mod_skypopen

nano /usr/local/freeswitch/conf/autoload_configs/skypopen.conf.xml

Editing something like this:



Here:
5000 - extension to which the incoming Skype call will be routed;
: 101 - display of the X-server;
skype_user is the name of the Skype account .

6.2. Add Skypopen to autoload.

Add mod_skypopen to the list of modules loading at the start of FreeSwitch.
To do this, in the /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml file, uncomment or add the line:


6.3. Extension 5000 configuration

As you probably remember, incoming Skype calls will be routed to extension 5000, which still needs to be created. To do this, in the directory / usr / local / freeswitch / conf / dialplan / default, create the file 02_skype.xml with the following contents:


Where:
asterisk - the name of the gateway the call will go to (PBX based on Asterisk);
6001 - extension in Asterisk, which will receive a call;
- the extension is indicated here, which will be processed in asterisk when a call arrives, in this case 6001.

In the same directory are examples of other extensions that will need to be commented out so that the extension we need is not processed elsewhere. The same operation must be done in the file /usr/local/freeswitch/conf/dialplan/default.xml.

Create the file 01_skypopen.xml:

nano /usr/local/freeswitch/conf/dialplan/public/01_skypopen.xml

With content:


6.4. Configuring sip_profiles

On the server with FreeSwitch, in the directory / usr / local / freeswitch / conf / sip_profiles / external, create an asterisk.xml file with the following contents:


Where:
asterisk - gateway name (must match the one specified in the previous step);
127.0.0.1 - host with Asterisk;
freeswitch - username for access to the gateway;
pass123 is his password.

6.5. Configuring sip.conf

On the server with Asterisk, add the following to /etc/asterisk/sip.conf:
Spoiler
[freeswitch]
type=friend
host=dynamic		
username=freeswitch
port=5080
secret=pass123
[6001]
fullname=Skype
registersip=no
callgroup=1
transfer=yes
callcounter=yes
context=default
cid_number=6001
hassip=yes
hasiax=no
nat=no
insecure=no
autoprov=yes
disallow=all
alow=ulaw,ulaw,gsm,g726,g729
dtmfmode=rfc2833
host=dynamic
username=60001
port=5080
fromdomain=1.1.1.1
secret=supersecret



Where:
6001 - extension from previous steps
1.1.1.1 - server address with FreeSwitch
pass123 - password from Extensions 6001 It

remains to re-read sip.conf:

rasterisk -x 'sip reload'

6.6. Users.conf configuration

Spoiler
[freeswitch]
type=friend
host=dynamic		
username=freeswitch
port=5080
secret=pass123
[6001]
fullname=Skype
registersip=no
callgroup=1
transfer=yes
callcounter=yes
context=default
cid_number=6001
hassip=yes
hasiax=no
nat=no
insecure=no
autoprov=yes
disallow=all
alow=ulaw,ulaw,gsm,g726,g729
dtmfmode=inband
host=dynamic
username=6001
port=5080
fromdomain=1.1.1.1
secret=pass123
hasvoicemail=yes
vmsecret=secret
call-limit=100
macaddres=6001
label=6001
linekeys=1



Where:
secret - password for voicemail.
100 - maximum lines.
nat = yes - means that the client can be located behind the NAT-th and for opening the media channel when this user calls, broadcasting headers is required.
host = dynamic - no binding to the client's host address.
username = 6001 - username. This login is then used in the settings of the SIP client.
dtmfmode = rfc2833 - method for transmitting dtmf dialing tones. There is also the info method (it must match the settings in the SIP client).
disallow = all - disable all codecs.
allow = ulaw - allow ulaw codec. The codec must be one that is supported by the client.
context = default - the context describes which section of the Dailplan client calls will go through.

In extentions.conf, add the following:

[default]
exten => 6000,1,Dial(SIP/6000)
exten => 6001,1,Dial(SIP/6001)


7. Launch order

After installation, you should possibly reboot the system. Asterisk will start at boot. The softphone must already be active before rebooting.
Priority:

/usr/bin/Xvfb :101 -ac &
x11vnc -display :101
su skype -c "/bin/echo 'username userpass'| DISPLAY=:101 /usr/bin/skype --dbpath=/home/skype/multi/interface01 --pipelogin &" 
/usr/local/freeswitch/bin/freeswitch

If the log is not displayed in the FreeSwitch console during an incoming call from the Skype network or the client does not appear when connecting to Vnc Viewer, you must manually restart the Skype client and re-check the client settings.

Resources used: wiki.exp-it.ru, wiki.freeswitch.ru, asterisk-pbx.ru + asterisk books.

Also popular now: