📜 ⬆️ ⬇️

Asterisk + FreeSwitch + Skype. Detailed guide



Good day, residents of Habr!

Having experience in the installation of Asterisk-based voip-servers, I decided to offer my detailed installation guide for the Asterisk-based call-center in conjunction with Skype. Due to the popularization of Skype, this network has been used for call centers of many companies. The use of her official client greatly limits our possibilities. This assembly allows you to increase the number of simultaneous calls from the Skype-network.

1. We update the server

Install all the necessary packages and updates. In the console, enter the command:
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 Notices

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 put a standard, well-known “pick-ups” password, your server will capture and delete all important data. 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 the 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. Install 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 login information to the file manager.conf:

 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 carry out the necessary actions to complete

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

Delete the / usr / share / asterisk / static-http / folder 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 run it with the command:

 /usr/src/asterisk -vvvgc 

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

 /usr/sbin/asterisk 

Connect to the command line interface (CLI) by using the 'r' argument.

 /usr/sbin/asterisk -r   asterisc -r 

Reloading 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 /var/lib/asterisk/static-http/config/js/astman.js file

 timeout : '60000' 

On
 timeout : '6' 


If it 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. Creating an Asterisk group and user

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

3.7. Change of rights

Change the rights 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 directories

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

Configurations:
musiconhold.conf - Set music on hold settings for MusicOnHold.
cdr_mysql.conf - Customize storage of call records in MySQL.
manager.conf - Configuring the Manager interface.
meetme.conf - Set up conferences (meetme).
mgcp.conf - Configure settings for MGCP devices.
parking.conf - Call parking parking options.
voicemail.conf - Voicemail settings (VoiceMail).
agents.conf - Asterisk agents.
extensions.conf - Asterisk Numbering Plan.
iax.conf - Configure IAX devices.
modem.conf - ISDN configuration using ISDN4Linux.
vpb.conf - Voicetronix hardware setup.
alsa.conf - ALSA sound driver settings for the console user.
festival.conf - Parameters for working with the festival speech synthesizer.
modules.conf - Configure Asterisk modules.
zapata.conf - Setup of analog digium telephony devices.
asterisk.conf - Locating Asterisk directories.
indications.conf - Setting parameters for analog PBXs of various countries.
rpt.conf - rtp protocol parameters.
logger.conf - Asterisk logging options.

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

3.9 Configuring Asterisk via Web GUI

Trunks. 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 ringgroups voicemenus queues voicemailgroups directory pagegroups page_an_extension

Incoming Calling Rules:
Pattern: _XXXXXXXXXXX
Destination: 6001

4. Go to install 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 with the 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. Installing 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. Customization

We get the user under which 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 is turned off, 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 


Making it executable:

 chmod +x /usr/local/bin/skype_start 

4.4. Launch

We start 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 

The rights:

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

Stop process:

 ps ax | grep vnc kill 22062 # ( ) 

Before launching Skype, you need to run these modules:

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

Skype launch:

 su skype -c "/bin/echo 'username userpass'| DISPLAY=:101 /usr/bin/skype --dbpath=/home/skype/multi/interface01 --pipelogin &" kill skype #  Skype ps aux #  

Having connected 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 (disable events, automatic status change, etc.) and select the dummy driver as all audio devices (Dummy-HW 2.0) .

5. Installing FreeSwitch

5.1. Install 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 

Check and add all 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 the init script to start 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. We get the user to 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. Run and other FreeSwitch commands

 load mod_skypiax #   sk list #    console loglevel 9 #    shutdown #   FreeSwitch /usr/local/freeswitch/bin/freeswitch #  FreeSwitch 

5.8. Mod skypopen

We now turn to the most important setting - Public API. Here you need to allow mod_skypopen to access Skype.
Skype itself allows you to add programs to the “Allowed programs” list only after they have accessed Skype, but it is impractical to launch FreeSwitch and mod_skypopen only to make such a setting, so the creators of mod_skypiax wrote a small utility that simulates the appeal of mod_skypopen to 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 must now have the VNC screen open.

Run skypopen:
 ./skypopen_auth :101 

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

 <UI> <API> <Authorizations>skypopen</Authorizations> <BlockedPrograms></BlockedPrograms> </API> <CaptureDevice>2</CaptureDevice> <Notifications> <Enable> <SkypeLogin>0</SkypeLogin> </Enable> </Notifications> <SoundDevice>2</SoundDevice> </UI> 


6. Configuring

The important point is that skype-clients should be launched before loading the mod_skypopen module, i.e. before starting freeSwitch. Also, stopping Skype’s already involved mod_skypopen copies will cause FreeSwitch to crash.

6.1. Mod_skypopen

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

Edit something like this:

 <configuration name="skypopen.conf" description="Skypopen Configuration"> <global_settings> <param name="debug" value="8"/> <param name="dialplan" value="XML"/> <param name="skype_user" value="username"/> <param name="report_incoming_chatmessages" value="false"/> <param name="write_silence_when_idle" value="false"/> <param name="silent_mode" value="false"/> <param name="setsockopt" value="true"/> <param name="codec-prefs" value="gsm,ulaw"/> <param name="hold-music" value="$${moh_uri}"/> </global_settings> <per_interface_settings> <interface id="1" name="skypopen1"> <param name="destination" value="5000"/> <param name="context" value="default"/> <param name="X11-display" value=":101"/> <param name="tcp_cli_port" value="15556"/> <param name="tcp_srv_port" value="15557"/> <param name="hold-music" value="$${moh_uri}"/> </interface> </per_interface_settings> </configuration> 


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

6.2. Add Skypopen to autoload

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

 <load module="mod_skypiax"/> 

6.3. Configuration extension 5000

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

 <include> <extension name="skype_incoming"> <condition field="destination_number" expression="^7770$"> <action application="set" data="hangup_after_bridge=true"/> <action application="set" data="effective_caller_id_name=6001"/> <action application="bridge" data="sofia/gateway/asterisk/6001"/> <action application="hangup"/> </condition> </extension> </include> 

Where:
asterisk - the name of the gateway to which the call will go (PBX based on Asterisk);
6001 - extension to Asterisk, which will receive a call;
<action application = "bridge" ...> - here is the extension that will be processed in asterisk when a call arrives, in this case 6001.

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

Create the 01_skypopen.xml file:

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

With content:

 <extension name="SKYPE#1"> <condition field="destination_number" expression="^8(\d{10})$"> <action application="set" data="continue_on_fail=true"/> <action application="set" data="hangup_after_bridge=true"/> <action application="bridge" data="skypopen/RR/+7$1"/> </condition> </extension> 

6.4. Sip_profiles configuration

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

 <include> <gateway name="asterisk"> <param name="username" value="freeswitch"/> <param name="realm" value="127.0.0.1"/> <param name="password" value="pass123"/> <param name="register" value="true"/> <param name="ping" value="25"/> </gateway> </include> 

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

6.5. Sip.conf configuration

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. Configuration users.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=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 - voicemail password.
100 - maximum lines.
nat = yes - indicates that the client can be located behind the NAT and to open the media channel when calling this user a header broadcast is required.
host = dynamic - there is no binding to the client's host address.
username = 6001 - username. This login is then used in the SIP client settings.
dtmfmode = rfc2833 - the method of transmitting dtmf-tones dialing. There is also an info method (must match the settings in the SIP client).
disallow = all - disable all codecs.
allow = ulaw - enable the ulaw codec. The codec must be one that is supported by the client.
context = default - the context describes the section of Dailplan that the client calls will go through.

In extentions.conf, we add the following:

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


7. Startup procedure

After installation, you need to reboot the system if possible. Asterisk will be launched at boot. The softtophone should 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 in the FreeSwitch console is not displayed when an incoming call from the Skype network or the client is not displayed when connecting from the 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 + books on asterisk.

Source: https://habr.com/ru/post/247981/


All Articles