Wednesday, November 23, 2016

Quick'n'dirty answer on Asterisk "Who hung up"?

Really fast and dirty solution for answer "Who put handset first?" on Asterisk. Idea based on "g" option in Dial, that works in a case if callee hangs up and not, if caller.

exten => _X.,1,Dial(SIP/Trunk/${EXTEN},,g)
 same => n,Set(HANGUP_CALLEE=True)

exten => h,1,GoToIf($["x${HANGUP_CALLEE}"="xTrue"]?hangup-callee)
 same => n,Set(CDR(userfield)=HANGUP_CALLER)
 same => n,GoTo(end)
 same => n(hangup-callee),Set(CDR(userfield)=HANGUP_CALLEE)
 same => n(end),NoOp

And in CDR in userfield we will get who hung up first, caller or callee.

Monday, November 14, 2016

Friday, April 1, 2016

Installing SIP SIMPLE Client SDK on Debian 8

Few words, that missed from official wiki at AG Projects site about installing from repos.

You need also to add jessie-backports repos to your sources.list
deb http://ftp.debian.org/debian jessie-backports main
Than -
apt-get update
apt-get -t jessie-backports install python-otr
apt-get install python-sipsimple
apt-get install sipclients

That's it :) All thanks goes to Saúl Ibarra Corretgé from AG Project.

Monday, March 14, 2016

Telecom and VoIP for non-specialists. Part 1.

Hello to all!
One of mine friends suggests me to start a series of articles about telecom, PBXes and other stuff I work with. For a non-telecom boys and girls. So, why not?

And I’d like to start with a disclaimer. All you will read here is not «last and final truth». It’s just mine point of view on things I work with. I work mostly with SMB market, so if you come and ask something about large distributed call-centres with tons of queues and agents, and reports… I know basics of telecom and using this knowledge I can answer how to build this. But honestly - I like to be more close to ground. Reason - you speak to people more, than to machines. And all this «bloody enterprise» things make me feel like a hamster in a ball. Endless reports, numbers, conversions… Boring. Much more interesting to work with SMB. And easier, of course. And - no possible to work for something really heavy all alone. That’s may be the real reason. So, back to disclaimer, all here is my own opinion. Can be right, can be wrong, but based on experience. If you think I’m wrong somewhere - you’re welcome to comments :) Also, english - is not my native, so there would be errors, but hope, everybody can catch main idea.

Let’s start than with little dive-in.
History of telecom starts earlier, than history of computers and IT. And for many years computers and telecom industry was close, but really not the same, like nowadays. They have separate standards, separate networks, different ideology.
And ok, let’s narrow a bit our field of view and talk about PBX’es. What PBX is? Normally you see a phone on your work desk or home. You know, if you dial a number, you can talk to person you’ve dialed. But how your phone is connected to other’s? It’s done via PBX.
First PBX’es was actually alive girls who manually switches wires from one jack to another. Actually, «jack» connector is from these times. Later girls were replaced by electrical mechanics. If you are old enough or live in some god’s forgotten place with telephone, you can remember disk phones or when you push buttons on your phones, you can hear «ticks» depends on digit dialed. That is actually commands to PBX mechanism.
Next big era is fully digital. You may heard ISDN abbreviation. That’s it. Still alive and well. But, modern system use 10-20% of this standard. ISDN was designed not only a voice carrying network, but data also. But, for data it was really expensive and data was moved to other networks. That’s why sometimes ISDN is decoded as It Still Does Nothing ;)

That’s it for now. Muse had left me. In next part we will talk about nowadays.

Monday, January 25, 2016

FusionPBX(Freeswitch) HA sync gateways across servers

There was a little task to do.
Assume, we have several FusionPBX in HA (shared database incl. runtime data is on). On "master managing" server we add a gateway to external profile. To add them on other servers we have to go to each server and push rescan on external profile. Eh... To lazy for this.
We will use script, that will subscribe to CUSTOM sofia::gateway_add and gateway_delete event and run sofia profile external rescan over other servers.
We will do this over xmlrpc, so no need to add ssh keys or so.

"Slave" servers:

  • Go to Advanced -> Modules and enable XML RPC module
  • Go to Advanced -> Settings on each "slave" server and put common data for XMLRPC connection, like username, pass and port
  • Restart mod_xml_rpc on each "slave" server
"Master" server
  • Create files /usr/local/freeswitch/scripts/app/gateway_states/resources/gateway_states_add.lua and /usr/local/freeswitch/scripts/app/gateway_states/resources/gateway_states_delete.lua
(I can't get add and delete event work from a single file)
  • gateway_states_add.lua
--description
--monitor custom sofia:gateway_* event and run sofia profile external rescan over other servers
--protect xmlrpc using a firewall on the server to limit access by ip address

--iptables
-- /sbin/iptables -I INPUT -j ACCEPT -p tcp --dport 8080 -s x.x.x.x/32

--define the servers running freeswitch do not include local
servers = {}
x = 0;
servers[x] = {}
servers[x]['username'] = "freeswitch";
servers[x]['password'] = "work";
servers[x]['hostname'] = "10.0.0.2";
servers[x]['port'] = "8080";
x = x + 1;
servers[x] = {}
servers[x]['username'] = "freeswitch";
servers[x]['password'] = "work";
servers[x]['hostname'] = "10.0.0.3";
servers[x]['port'] = "8080";
--x = x + 1;
--servers[x] = {}
--servers[x]['username'] = "ccc";
--servers[x]['password'] = "xxxxx";
--servers[x]['hostname'] = "127.0.0.3";
--servers[x]['port'] = "8080";

--subscribe to the events
--events = freeswitch.EventConsumer("all");
events = freeswitch.EventConsumer("CUSTOM", "sofia::gateway_add");
        -- events = freeswitch.EventConsumer("CUSTOM", "sofia::gateway_delete");
        -- Modify line above to get gateway_states_delete.lua
--prepare the api object
api = freeswitch.API();

--get the events
for event in (function() return events:pop(1) end) do
api_command_argument = "profile%20external%20rescan";
  -- event_gateway = event:getHeader("Gateway");
  -- api_command_argument = "profile%20external%20killgw%20"..event_gateway;
  -- Modify line above to get gateway_states_delete.lua
for key,row in pairs(servers) do
url = [[http://]]..row.username..[[:]]..row.password..[[@]]..row.hostname..[[:]]..row.port..[[/webapi/sofia?]]..api_command_argument;
response = api:execute("curl", url);
freeswitch.consoleLog("INFO", "[notice] ".. url .. " "..response.."\n");
end
end



  • Modify /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml

    <param name="startup-script" value="app/gateway_states/resources/gateway_states_add.lua"/>
    <param name="startup-script" value="app/gateway_states/resources/gateway_states_delete.lua"/>


  • Restart "master" server. At this point, every gateway add or delete will trigger an event, that will go across all our servers and command them pull new config from common database.

This script was modified from memcache.lua, that flushes memcaches over all Fusion servers.

Tuesday, January 12, 2016

Sngrep. I'm happy to found it.

Really best tool to analyze SIP traffic in console.

Also, not to forget about sipgrep.
Yep, very short post, but really - no more complex tshark or pcap with downloading :)