Archive

Archive for the ‘FreeSWITCH’ Category

IVR Application in Lua for Freeswitch

August 31st, 2010 admin No comments

1. Create a New file name 01_Custom.xml and add the following new extension:

<extension name=”Read Back Entered Digits”>
<condition field=”destination_number” expression=”^(9910)$”>
<action application=”lua” data=”test1.lua”/>
</condition>
</extension>

2. Save the file. Launch fs_cli and issue reload_xml, or press F6.

Our Dialplan is now ready to call the Lua script named test1.lua. Create this new script as follows:

1. Using your text editor, create test1.lua in the freeswitch/scripts/ directory and add the following lines:

– test1.lua
– Answer call, play a prompt, hangup

– Set the path separator
pathsep = ‘/’ — Windows users do this instead:
– pathsep = ‘\’

–Answer the call
session:answer()

–Create a string with path and filename of a sound file
prompt = “ivr” .. pathsep .. “ivr-welcome_to_freeswitch.wav”

– Print a log message
freeswitch.consoleLog(“INFO”,”Prompt file is ‘” .. prompt .. “‘\
n”)

–Play the prompt
session:streamFile(prompt)

– Hangup
session:hangup()

2. Save the file.

Now dialer 9910 and you will get IVR.

Categories: FreeSWITCH, Lua Tags:

Lua Tutorial for Freeswitch

August 31st, 2010 admin 1 comment

Lua is very lightweight programing language.Lua has a simple syntax that is easy both to learn and to read. Following is a
simple script:

— This is a sample Lua script
— Single line comments begin with two dashes

–[[
This is a multi-line comment.
Everything between the double square brackets
is part of the comment block.
]]

— Lua is loosely typed
var = 1 — This is a comment
var = �alpha� — Another comment
var = �A1� — You get the idea…

–[[
When the Lua script is called from the dialplan
you have a few magic objects. A handy one is
the 'freeswitch' object which lets you do things
like this:
freeswitch.consoleLog(�INFO�,�This is a log line\n�)

Another important one is the 'session' object which
Lets you manipulate the call:
session:answer()
session:hangup()
]]

— Lua makes extensive use of tables
— Tables are a hybrid of arrays and associative arrays
my_table = {
key1 = val1,
key2 = val2,
�index 1�,
�index 2�
}
freeswitch.consoleLog(�my_table key1 is ‘� .. my_table[key1] .. �’\n�)
freeswitch.consoleLog(�my_table index 1 is ‘� .. my_table[1] .. �’\n�)

— Access arguments passed in
arg1 = argv[1] — First argument
arg2 = argv[2] — Second argument

— Simple if/then
if ( var == �A1� ) then
freeswitch.consoleLog(�INFO�,�var is ‘A1′\n�)
end

— Simple if/then/else
if ( var == �A1� ) then
freeswitch.consoleLog(�INFO�,�var is ‘A1′\n�)
else
freeswitch.consoleLog(�INFO�,�var is not ‘A1′!\n�)
end

— String concatenation uses ..
var = �This � .. � and � .. �that�
freeswitch.consoleLog(�INFO�,�var contains ‘� .. var .. �’\n�)

— The end

Every Lua script that is executed from the Dialplan receives the session object,
which represents the call leg that is being processed. The session object is the
primary means of manipulating the call, and is used extensively in Lua scripting.

Categories: FreeSWITCH, Lua Tags:

Getting started with Lua in FreeSWITCH

August 31st, 2010 admin No comments

Enabling Lua (via mod_lua) is very easier process.It is done in the
following way:

1. Open modules.conf in the FreeSWITCH source directory and locate the
following line:

#languages/mod_lua

Remove the # and save the file.

2. Open modules.conf.xml in the conf/autoload_configs directory and
locate the following line:

tags and save the file.

3. Build and compile mod_lua from the FreeSWITCH source directory:

make mod_lua-install

4. Wait for the installation to finish, and then restart FreeSWITCH. Launch
fs_cli and type show application. If Lua loaded successfully, then you
will see that lua is now available as a Dialplan application as follows:

lua,Launch LUA ivr,

Categories: FreeSWITCH, Lua Tags:

Block DDoS attack on SIP Server

June 16th, 2010 emran No comments

Sometimes SIP Server attacked by hacker with huge number of SIP Registration.Which make mad the SIP Server.Full service can be get down. It can be blocked easily by IPTables. IPTables will work as Session Border Controller(SBC) for SIP Server. This script will work only with SIP.it will not work for TLS or SIPS.

#!/bin/sh
#
# INVITE rate, per host. Remember a successful (authenticated) call requires 2 INVITEs-
# Initial INVITE, 407 auth required (w/ nonce), INVITE with nonce and authentication.
IRATE=4/minute

# REGISTER rate, per host.
RRATE=2/minute

# All other SIP methods rate, per host. Be careful with SUBSCRIBEs, OPTIONS, CANCELs, etc.
ORATE=10/minute

# Methods for this script to ignore. These SIP methods are always allowed.
IGMETH=”OPTIONS”

# Burst
BURST=1

# Interface(s) to protect on INPUT. Seperate multiple interfaces with spaces.
# This will protect SIP services on THIS HOST.
IFACE=”eth0″

# Reject/drop action – usually something like DROP or REJECT.
# Use ACCEPT to use this script to not filter traffic but still collect statistics.
DACTION=DROP

# Protocol(s) to filter – can be either tcp or udp or both. Seperate multiples with spaces.
PROTOCOLS=”udp tcp”

# Enable logging.
#LOG=YES

# Block tel: URIs completely?
# P.S. – tel: sucks!
BLOCKTEL=yes

# Interface(s) to protect on FORWARD. Seperate multiple interfaces with spaces.
# The same hashtable will protect the entire network from the same host(s).
# Destination IP is NOT taken into consideration.
# This will protect any SIP services running on the network that uses this machine
# as a router (as long as you get the interfaces right).
#FIFACE=”eth0″

# Location of iptables binary.
IPTABLES=`which iptables`

# Search packet to this location. A larger offset looks further into the packet
# and takes more time but could catch more attacks (and false alarms).
# Remember, the method to match on is always in the beginning of the packet.
OFFSET=65

# SIP port
SPORT=5060

if [ ! "$1" ]
then
echo “SIP DoS/DDoS mitigation script for iptables
See top of script for configuration

Usage:
$0 [start|stop|status]”
exit 1
fi

if [ "$1" = "status" ]
then
$IPTABLES -L -v -n
exit
fi

# Setup iptables
$IPTABLES -F sipdos 2> /dev/null
$IPTABLES -X sipdos 2> /dev/null
$IPTABLES -N sipdos 2> /dev/null

if [ "$1" = "stop" ]
then
echo “Clearing iptables rules…”
if [ "$FIFACE" ]
then
$IPTABLES -F FORWARD 2> /dev/null
fi
$IPTABLES -F INPUT 2> /dev/null
exit
fi

# Send the right traffic through our chain
for i in $IFACE
do
for l in $PROTOCOLS
do
$IPTABLES -A INPUT -i $i -m $l -p $l –dport $SPORT -j sipdos
done
done

# Send the right forwarded traffic through our chain
if [ "$FIFACE" ]
then
for j in $FIFACE
do
for l in $PROTOCOLS
do
$IPTABLES -A FORWARD -i $j -m $l -p $l –dport $SPORT -j sipdos
done
done
fi

# “Handle” tel: URIs
if [ "$BLOCKTEL" ]
then
$IPTABLES -A sipdos -m string –string “tel:” –algo bm –to $OFFSET -j $DACTION
fi

# Ignore certain (configured) methods
if [ "$IGMETH" ]
then
for k in $IGMETH
do
$IPTABLES -A sipdos -m string –string “$k sip:” –algo bm –to $OFFSET -j ACCEPT
done
fi

# Finally set some limits…

# INVITE limit
$IPTABLES -A sipdos -m string –string “INVITE sip:” –algo bm –to $OFFSET \
-m hashlimit –hashlimit $IRATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_i_limit -j ACCEPT

# REGISTER limit
$IPTABLES -A sipdos -m string –string “REGISTER sip:” –algo bm –to $OFFSET \
-m hashlimit –hashlimit $RRATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_r_limit -j ACCEPT

# All other SIP packets…
$IPTABLES -A sipdos -m hashlimit –hashlimit $ORATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_o_limit -j ACCEPT

# Take action on everything else
if [ $LOG ]
then
$IPTABLES -A sipdos -j LOG
fi

$IPTABLES -A sipdos -j $DACTION

VoIP on Symbian Mobile

June 7th, 2010 emran No comments

Now a days it is very hot topics about voip on symbian mobile. To Call Over the internet from Mobile phone helps peoples life easier.There are few commercial and free voip mobile dialer for symbian and android.

One of them is Fring.You can make voip sip calls from fring.You can also use MSN, yahoo and Google.It supports many devices such as Nokia N73,n71,n75,E65 etc. It also support Other platform like iphone. It supports g711,GSM codec only.

SIPDialer is a product of E-SOFT BILLING PTE LTD. They provide commercial service. Their SIPDialer supports Symbian s60 3rd ed and android phone. You can send a demo request  from their website www.e-softbilling.com. They provide 5 days demo to run own sip proxy. SIPDialer supports G729,AMR,GSM and g711 codec. SIPDialre has balance display, realtime call duration, incoming call, DTMF, phone book features.Proxy IP can be changed on the fly.

SIPDroid is another opensource application for android phone.you can make audio and video calls from SIPDroid.It is based on mjsip.It has gsm, g711,ilbc and speex codecs.

H323Plus on FreeSWITCH

March 10th, 2010 emran No comments

First you have to download & install ptlib:

In your home, create a directory e.g. h323
mkdir -p ~/h323
cd ~/h323
wget http://www.h323plus.org/source/download/ptlib-2.4.5.tar.bz2
bunzip2 ptlib-2.4.5.tar.bz2
tar -xvf ptlib-2.4.5.tar.bz2
mv ptlib-2.4.5 ptlib-trunk
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/lib
cd ptlib-trunk
./configure
make
sudo make install
cd ..

Now, install h323plus

cd ~/h323

http://www.h323plus.org/source/download/h323plus-v1_21_0.tar.gz

export PTLIBDIR=~/h323/ptlib-trunk

tar -xzvf h323plus-v1_21_0.tar.gz
cd h323plus
./configure
make
make install

Now install mod_h323 on Freeswitch.

assuming you have FS source in your home
cd ~/freeswitch-trunk

make mod_h323-clean
make mod_h323
sudo make mod_h323-install

Now configure h323.conf.xml. It is similiar like mod_opal.

<configuration name=”h323.conf” description=”H323 Endpoints”>
  <settings>
    <param name=”trace-level” value=”4″/>
    <param name=”context” value=”public”/>
    <param name=”dialplan” value=”XML”/>
    <param name=”codec-prefs” value=”PCMU,PCMU,G729,GSM”/>
  </settings>
  <listeners>
    <listener name=”myH323_listener”>
      <param name=”h323-ip” value=”$${local_ip_v4}”/>
      <param name=”h323-port” value=”1720″/>
    </listener>
  </listeners>
</configuration>

 

   

Incoming Call Limit in FreeSWITCH

September 29th, 2009 emran No comments

Incoming call-limit can be controlled in FreeSWITCH from user directory for example:

<document type=”freeswitch/xml”>
  <section name=”directory”>
    <domain name=”192.168.0.2″>
      <user id=”some_user”>
        <params>
          <param name=”password” value=”some_password”/>
        </params>
        <variables>
                       <variable name=”accountcode” value=”315″/>
                       <variable name=”user_context” value=”default”/>
                       <variable name=”vm_extension” value=”315″/>
                       <variable name=”max_calls” value=”1″/>
          </variables>
      </user>
    </domain>
  </section>
</document>

Categories: FreeSWITCH Tags:

Using mod_limit with an outbound gateway in FreeSWITCH

September 29th, 2009 emran No comments

The following channel variables are set when mod_limit is called.

  • “limit_realm”
  • “limit_id”
  • “limit_max”

These channel variables are used at hang up to remove the record. More specifically, the delete is limited by uuid, hostname, realm and id.

<extension name=”Outbound Limit”>
        <condition field=”destination_number” expression=”^00″/>
         <action application=”limit” data=”$${domain} gw_PROVIDER PROVIDER_CHANNEL_LIMIT nextgw1″/>
                <action application=”bridge” data=”sofia/gateway/PROVIDER/1$1″/>
                <action application=”transfer” data=”nextgw1″/>
        </condition>
</extension>

Categories: FreeSWITCH Tags:

FollowMe in FreeSWITCH

September 29th, 2009 emran No comments

The following example shows how a DID can bridge to multiple extensions or gateways sequentially in a hunt pattern. In Asterisk, this feature is called FollowMe. If none of the bridges are successful the caller is sent to voicemail for example.

<extension name=”12531234567″>
  <condition field=”destination_number” expression=”12531234567″>
   <action application=”set” data=”hangup_after_bridge=true”/>
   <action application=”set” data=”continue_on_fail=true”/>
   <action application=”set” data=”ignore_early_media=true”/>
   <action application=”set” data=”call_timeout=10″/>
   <action application=”bridge” data=”sofia/$${domain}/1001″/>
     <action application=”set” data=”call_timeout=13″/>
   <action application=”bridge” data=”sofia/gateway/isoftswitch/123456789″ />
   <!– No answer, transfer to voicemail –>
   <action application=”answer”/>
   <action application=”sleep” data=”1000″/>
   <action application=”voicemail” data=”default $${domain} 1001″/>
  </condition>
</extension>

Multiple Route Dialing in FreeSWITCH simultaneously

September 29th, 2009 emran No comments

Forked dial is when you want to attempt to ring 2 destinations at the same time. Freeswitch will attempt to call both bridge options simultaneously. The first bridge leg that replies with a 183 (session progress) message will win the call, and the other bridge leg is dropped. This only will work if you enable inbound-late-negotiation in the profile this recipe is executing under ( not in the bridged-to profile ).

an example is:

 <extension name="dialoutpstn">
     <condition field="destination_number" expression="^((00).*)$">
       <action application="set" data="hangup_after_bridge=true"/>
       <action application="set" data="ignore_early_media=true"/>
       <action application="bridge" data="sofia/gateway/gatewayA/$1@1.2.3.4,sofia/gateway/gatewayB/$1@4.5.6.7"/>
       </condition>
 </extension>

Categories: FreeSWITCH Tags:
6 visitors online right now
6 guests, 0 members
Max visitors today: 6 at 12:02 am UTC
This month: 8 at 09-03-2010 11:34 pm UTC
This year: 43 at 06-10-2010 04:02 pm UTC
All time: 43 at 06-10-2010 04:02 pm UTC