Archive for the ‘Uncategorized’ Category

find

Thursday, March 6th, 2014

Find files older than 15 days and list them:

[root@staff /root]# find /var/squid/logs/ -mtime +15 -execdir ls -lh {} \;
-rw-r-----  1 squid  squid    91k Feb 16 20:46 /var/squid/logs/cache.log.17
-rw-r-----  1 squid  squid   108M Feb 17 00:00 /var/squid/logs/access.log.17
-rw-r-----  1 squid  squid   122M Feb 16 00:00 /var/squid/logs/access.log.18
-rw-r-----  1 squid  squid   355M Feb 19 00:00 /var/squid/logs/access.log.15
-rw-r-----  1 squid  squid   137k Feb 18 23:55 /var/squid/logs/cache.log.15
-rw-r-----  1 squid  squid   275M Feb 18 00:00 /var/squid/logs/access.log.16
-rw-r-----  1 squid  squid   145k Feb 17 21:49 /var/squid/logs/cache.log.16

List files modified during last 5 minutes:

find /some/path/ -type f -mmin -5 -execdir ls -l {} \;

Find files bigger than 2 kilobytes in .mc/ directory:

find .mc/ -type f -size +2000c
.mc/ini

or:

find .mc/ -type f -size +2k
.mc/ini

Find files smaller than 80 bytes in .mc/ directory:

vn ~ # find .mc/ -type f -size -80c
.mc/Tree
.mc/cedit/cooledit.clip

Handy one-liner for searching a file with wildcard, case-insensitive, in 2 directories simultaneously (assuming the file contains ‘Yutong’):

srv ~ # find /storage/sounds/{cars,ru/cars} -iname yut\*
/storage/sounds/cars/Yutong.wav
/storage/sounds/ru/cars/Yutong.wav

Find files with “+380” in their name which were created on October 13, 2015 and copy them to /home/lexus/:

find /storage/cluster/ready/ -name "*+380*" -type f -newermt 2015-10-13 ! -newermt 2015-10-14 -execdir cp {} /home/lexus/ \;

WordPress: disabling quotes convertion

Sunday, February 16th, 2014

You have to edit the file default-filters.php which is located here:
/your_WP_root_directory/wp-includes/default-filters.php

Comment out the line:
add_filter( 'the_content', 'wptexturize' );

Based on this topic: https://wordpress.org/support/topic/please-give-us-the-option-to-turn-of-smart-quotes .

awk

Sunday, February 16th, 2014

Print the first line:
cat somefile.txt | awk ‘{print $1}’

… and see the number of active calls on Asterisk PBX:

asterisk -rx 'core show calls' | head -n 1 | awk '{print $1}'

Print all but first 6 columns of the file:
cat somefile.txt | awk ‘{$1=$2=$3=$4=$5=$6=””; print $0}’

… and see who’s trying to connect to 5060/TCP and 22/TCP (some fields reduced):

root@vds:~# tail -n 2 /var/log/syslog | awk '{$1=$2=$3=$4=$5=$6=""; print $0}'
      iptables denied Asterisk IN=eth0 SRC=69.60.119.204 DST=XX.XX.YY.ZZ PROTO=UDP SPT=5072 DPT=5060
      iptables denied SSH IN=eth0 SRC=222.186.62.39 DST=XX.XX.YY.ZZ PROTO=TCP SPT=6000 DPT=22

By default, awk doesn’t separate columns. To do that, use comma:

root@vds:~# grep Aster /var/log/syslog | awk '{print $1,$2,$3,$9,$13}'
Feb 17 07:03:25 Asterisk SRC=74.118.193.77
Feb 17 07:13:23 Asterisk SRC=85.25.194.185
Feb 17 07:56:31 Asterisk SRC=188.138.34.254
Feb 17 08:12:02 Asterisk SRC=200.12.49.147

PS: all these IPs are bad guys. They’re trying to connect to my SSH and SIP ports. So, I do not hide their addresses :)

Update:

In case you’ve got an output like

“123456”
“234567”
“345678”

and want to get rid of first and last symbols:

rev input_file.txt | cut -c2- | rev | cut -c2-

In case your columns have some other delimiters than space, p.e. comma, specify it:

cat file.txt | awk -F',' '{print $3}'

Debian/Ubuntu: set default applications (both X11 and console)

Friday, February 7th, 2014

To set the default web browser type:

sudo update-alternatives --config x-www-browser

This will lead to:

lexus@lexus:~$ sudo update-alternatives --config x-www-browser
There are 3 choices for the alternative x-www-browser (providing /usr/bin/x-www-browser).

  Selection    Path                    Priority   Status
------------------------------------------------------------
  0            /usr/bin/google-chrome   200       auto mode
* 1            /usr/bin/firefox         40        manual mode
  2            /usr/bin/google-chrome   200       manual mode
  3            /usr/bin/opera           200       manual mode

Press enter to keep the current choice[*], or type selection number: 

To set default editor:

update-alternatives --config editor

To edit (or leave with defaults) all variants, use:

sudo update-alternatives --all

Asterisk: block inbound call by CALLERID(num) (AEL syntax)

Friday, January 31st, 2014

One number :

    73522123456 =>
    {
        if(${CALLERID(num)} = 74995008119)
            {
            Hangup;
            }
        Dial(IAX2/iaxpeer/somedevice);
    }

Several numbers:

    73522123456 =>
    {
    switch (${CALLERID(num)}) {

         case 74957805170:
            NoOp(Block call from Susan);
            Hangup();
            break;

        pattern [78]4957805174:
            NoOp(Block call from Anna);
            Hangup();
            break;

        pattern [78]4957805061:
            NoOp(Block call from Lily );
            Hangup();
            break;

        pattern [78]495780508X:
            NoOp(Block call from Samantha);
            Hangup();
            break;

        default:
            Set(CDR(accountcode)=some-accountcode);
            Dial(SIP/somepeer/tomsphone01,,r);
        }
    }

pattern – here you may use constructions like [167] and/or 123X.
case – is exact sequence of symbols.

https://wiki.asterisk.org/wiki/display/AST/AEL+Conditionals

FreeSWITCH installation

Friday, January 17th, 2014

Download latest stable release (January, 2014) http://files.freeswitch.org/freeswitch-1.2.17.tar.bz2 to /usr/src/.
I have the basic Debian 7.3 Wheezy installation.
I needed these dependences: apt-get install zlib zlib-dev zlib1g-dev libjpeg62 libjpeg62-dev libjpeg8-dev libcurses-perl libncurses5-dev libssl-dev

Then:

./configure

make install
make cd-sounds-ru-install
make cd-moh-ru-install
make cd-moh-install

Symlinks:
ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli
ln -s /usr/local/freeswitch/bin/freeswitch /usr/local/bin/freeswitch

Fire!:
fs_cli -l 5

FreeSWITCH: dial through VoIP provider

Thursday, January 16th, 2014

Register against megavoip.com sbc:
Add a file sip.megavoip.com.xml to /usr/local/freeswitch/conf/sip_profiles/external/ to dial through Megavoip.com:

fs-megavoip

Register against multifon.ru sbc:
Add a file multifon.xml to /usr/local/freeswitch/conf/sip_profiles/external/ to dial through multifon.ru:

fs-multifon

Now it’s time to check if the REGISTER is OK.
Execute in the FS CLI:

freeswitch@internal> sofia status
Name Type Data State
=================================================================================================
external profile sip:mod_sofia@10.145.13.21:5080 RUNNING (0)
external::example.com gateway sip:joeuser@example.com NOREG
external::sip.megavoip.com gateway sip:megavoip_username@sip.megavoip.com REGED
external::multifon gateway sip:79221234567@sbc.multifon.ru REGED
10.145.13.21 alias internal ALIASED
internal profile sip:mod_sofia@10.145.13.21:5060 RUNNING (0)
internal-ipv6 profile sip:mod_sofia@[::1]:5060 RUNNING (0)
=================================================================================================
3 profiles 1 alias

or:
freeswitch@internal> sofia status gateway
Profile::Gateway-Name Data State IB Calls(F/T) OB Calls(F/T)
=================================================================================================
external::example.com sip:joeuser@example.com NOREG 0/0 0/0
external::sip.megavoip.com sip:megavoip_username@sip.megavoip.com REGED 0/0 0/0
external::multifon sip:79221234567@sbc.multifon.ru REGED 0/1 0/0
=================================================================================================
3 gateways: Inbound(Failed/Total): 0/1,Outbound(Failed/Total):0/0

or with more info:
freeswitch@internal> sofia status gateway sip.megavoip.com
...

Dial through (let’s dial via megavoip.com):

Add to /usr/local/freeswitch/conf/dialplan/default.xml to the beginning of ‘default’ context:

fs-dial-through

FreeSWITCH and Asterisk: equivalent commands

Thursday, January 16th, 2014

fs_cli -l 5 = console loglevel 5

sofia global siptrace on|off = calls debug

console loglevel help
console loglevel [0-7] = core set verbose X

sofia profile default start

sofia status profile internal
sofia status profile internal reg = sip show peers. Show devices, registered against your FreeSWITCH
list_users = sip show peers. Show devices, registered against your FreeSWITCH

sofia profile internal rescan = sip reload (not sure! Command below is BETTER!)
sofia profile external restart reloadxml = equivalent of ‘sip reload’. Execute after editing /usr/local/freeswitch/conf/sip_profiles/external (or internal)

F6 = dialplan reload
reloadxml

xml_locate dialplan = dialplan show

reload mod_sofia

http://wiki.freeswitch.org/wiki/Rosetta_stone

FreeSWITCH unexpected behavior

Saturday, January 4th, 2014

FreeSWITCH is a new telephony engine for me, so I’m just learning it when I have free time.
Today I discovered a 'system' command in FS CLI and for the sake of curiosity typed 'system ping 8.8.8.8'. Nothing changed in the CLI.
Some time later I started to learn how to reload the SIP stack of FreeSWITCH ('reload mod_sofia'). And each time I saw an error:

...
2014-01-04 09:02:57.468709 [ERR] sofia.c:1501 Error Creating SIP UA for profile: internal
2014-01-04 09:02:57.468709 [ERR] sofia.c:1501 Error Creating SIP UA for profile: internal-ipv6
2014-01-04 09:02:57.468709 [ERR] sofia.c:1501 Error Creating SIP UA for profile: external
...

All of SIP-profiles failed when restarting them.

I started searching – who is listening on port 5060. That’s what I’ve discovered:
root@server:/opt/freeswitch/bin# netstat -tulpan | grep 5060
tcp 0 0 10.15.9.10:5060 0.0.0.0:* LISTEN 6887/ping
udp 124576 0 10.15.9.10:5060 0.0.0.0:* 6887/ping

My ping, that 'system' application. I killed it and restarted FreeSWITCH. After that everything works fine.

Cell phone as a queue member

Thursday, December 19th, 2013

From time to time I’m asked by my customers if it is possible to include a cellular phone as a queue member. Yes, it is easy to do. You may include any phone number, not only cell or SIP, which is registered on your Asterisk server. Asterisk must be compiled with the local channel support. Everything is done with its help.

queues.conf:

[queue_cell_and_sip]
strategy = ringall
servicelevel = 10
joinempty = yes
music = default

member => SIP/1301
member => Local/79221234567@your-context

extensions.ael:

...
        1810 =>
        {
                Answer;
                Queue(queue_cell_and_sip);
                Hangup;
        }
...