Quick ruby one liner to reboot phones attached to freeswitch

Posted by Bougyman Tue, 15 Dec 2009 23:17:00 GMT

Needed this to reboot all my extensions from 1000-1009 every night. Adjust as needed.
irb(main):039:0> (Nokogiri(%x{fs_cli -x 'sofia xmlstatus profile internal'})/:registration).select{|x| (x/"sip-auth-user").text.to_i < 1010 }.map { |n| (n/"call-id").text }.each { |p| reboot(p) }
Sending reboot to 3c2671257674-tlf1pz01hu9g
Sending reboot to 3c26700e5573-7zw9k9793uer@snom320-0004132CC8C8

Freeswitcher 0.4.4 Released, and welcome Harry

Posted by Bougyman Sun, 06 Dec 2009 20:44:00 GMT

This is a fairly minor bugfix (thanks diegoviela) to fix the Playback app. The 0.4.4 should be available via gem.

Mostly i'm sorry this blog has been so idle, we've been working hard on FSR, FXC, and related components, but much of it on commercial or proprietary projects. In the coming months we'll be using this knowledge to release applications which enhance the functionality of open source telecom.

Thanks to all the new contributors, and welcome to the core team Harry Vandberg. He's pushed development along while we played end user for a few months, we're happy to have him.

FreeSWITCHeR 0.4.0 released. Now Ruby 1.9.1 compat! 1

Posted by JVaughn Wed, 03 Jun 2009 23:18:00 GMT

Release early and release often, right?

Well ok, then.
FreeSWITCHeR 0.4.0, The Ruby framework for FreeSWITCH, has been released!

This release includes many bug fixes, thanks to everyone for the emails and/or stopping by our IRC channel, #rubyists on Freenode.


Keep the bug reports and feature requests coming
Most importantly, this release introduces Ruby 1.9.1 compatibility with FreeSWITCHeR.

Enjoy!

More FreeSWITCH ruby love - FXC on the way 1

Posted by Bougyman Wed, 03 Jun 2009 01:36:00 GMT

With FSR well under way and being used both internally and in the wild for FreeSWITCH application development, the next logical step will be a Configurator for FreeSWITCH itself. FreeSWITCH has long lacked the standard Administrator/User configuration available via web or GUI, FXC is intended to allow web interfaces for configuration to be built easily with any Rack application utilizing the FreeSWITCH xml_curl interface. The first pass of FXC will include some Rack middleware which turns FreeSWITCH requests (to /) into easy to organize routes such as /directory/register/internal/1000, /dialplan/public/8885551212, /configuration/acl.conf. The goal is to eliminate the gruntwork of routing by POST variables, exposing clean Rack-app routes up the stack (for ramaze, sinatra, etc). The following is an example with ramaze.

middleware.rb

module FXC
  module Rack
    class Middleware
      def initialize(app)
        @app = app
      end

      def call(env)
        r = ::Rack::Request.new(env)
        return @app.call(env) unless r.params["section"]
        path = r.params["section"] + "/"
        path << case path
        when "dialplan/"
          dp_req(env, r)
        when "directory/"
          dir_req(env, r)
        when "configuration/"
          conf_req(env, r)
        end
        env["PATH_INFO"] << (env["PATH_INFO"].match(%r{/$}) ? path : "/#{path}")
        @app.call(env)
      end

      private
      def dp_req(env, r)
        s = [r.params["Caller-Context"]]
        s << r.params["Caller-Destination-Number"]
        s.join("/")
      end

      def dir_req(env, r)
        s = []
        if r.params["purpose"]
          s << r.params["purpose"].gsub("-","_")
          s << r.params["sip_profile"]
        elsif r.params["action"] and r.params["action"] == "sip_auth"
          s << "register"
          s << r.params["sip_profile"]
          s << r.params["sip_auth_username"]
        elsif r.params["user"]
          s << "voicemail"
          s << r.params["sip_profile"]
          s << r.params["user"]
        end
        s.join("/")
      end

      def conf_req(env, r)
        s = []
        if r.params["key_name"] == "name"
          s << r.params["key_value"]
        end
        s.join("/")
      end

    end
  end
end

controller/dialplan.rb

# Copyright (c) 2008-2009 The Rubyists, LLC (effortless systems) <rubyists@rubyists.com>
# Distributed under the terms of the MIT license.
# The full text can be found in the LICENSE file included with this software
#
module FXC
  class Dialplan < Controller
    map '/dialplan'
    layout :dialplan

    def index(*args)
      Ramaze::Log.info("Got unhandled dialplan request: " + request.inspect)
      not_found
    end

    def default(number)
      Ramaze::Log.info("got default dialplan request for #{number}")
      not_found
    end

    def public(number)
      @did = FXC::Did.first(:number.like /#{number.sub(/^1/,'1?')}/)
      if @did 
        @user = @did.user
        @targets = @did.targets
        Ramaze::Log.info("Routing #{@did.number} to #{@user.dialstring}")
        render_view(:index)
      else
        Ramaze::Log.info("Got public dialplan request for #{number}, but no DID matches: ")
        not_found
      end
    end
  end
end

In the FXC::Dialplan controller, each method represents a FreeSWICH dialplan context. Undefined contexts (in this ramaze controller) will fallthrough to the index method and be logged.

Finally, the FreeSWITCH configuration to send requests to above app becomes a single line/single url

conf/autoloadconfigs/xmlcurl.conf.xml


<configuration name="xml_curl.conf" description="cURL XML Gateway">
  <bindings>
    <binding name="fxc">
      <param name="gateway-url" value="http://127.0.0.1:9292/" bindings="configuration|directory|dialplan"/>
    </binding>
  </bindings>
</configuration>

Next step is completing all the methods available for each binding type (configuration, dialplan, directory). Once complete FreeSWITCH web config on Rack should follow rapidly. That will be the “Look Ma, No XML” FXC release (TBA).

Freeswitch ruby demos live

Posted by Bougyman Thu, 21 May 2009 00:59:00 GMT

The demos included with the FreeSWITCHeR (freeswitcher, FSR) ruby library for the FreeSWITCH event socket are being published publicly. The first is available at sip:8084@falcon.rubyists.com:5080. This is the outbound_event_demo.rb from examples/ .

Ruby loves FreeSWITCH! 2

Posted by Bougyman Tue, 19 May 2009 05:05:00 GMT

Ruby Freeswitch Application Programming Interface (ESL Alternative)

freeswitcher (FSR) is a ruby library for communicating with FreeSWITCH through its event socket interface. FreeSWITCH ruby integration in the core just doesn’t work with the thread models of either 1.8 or 1.9. On the other hand; FSR, built on ruby eventmachine, can manage more than one instance of FreeSWITCH at a time.

Using the freeswitcher gem, 2 minute tutorial

This program will play a smooth wav file and read the DTMF tones entered by the caller. It simply logs the received digits to the info facility (you should see it on stdout)

require "rubygems"
require "fsr"
require "fsr/outbound"
class GetDigits < FSR::Listener::Outbound
  def session_initiated
    exten = session.headers[:caller_caller_id]
    answer do
      read("/path/to/smooth.wav") do |read_var|
        FSR::Log.info("Received #{read_var} from #{exten}")
      end
    end
  end
end
FSR.start_oes! GetDigits, :port => 8084, :host => "127.0.0.1"

In order to use the above script, add the following in your FreeSWITCH dialplan. You can save it as 00sockettest.xml in conf/dialplan/default/ if you’re using the stock FreeSWITCH configuration.

<include>
  <extension name="8084">
    <condition field="destination_number" expression="^8084$">
      <action application="set" data="continue_on_fail=true" /> <!-- we still need this to continue if bridging times out -->
      <action application="set" data="call_timeout=5" />
      <action application="socket" data="127.0.0.1:8084 sync full"/>
    </condition>
  </extension>
</include>

Then reloadxml on FreeSWITCH, make sure the GetDigits listener is started, and call 8084 on a phone registered to FreeSWITCH.

This is only the Outbound Event Socket handler for FreeSWITCH in ruby. Other interfaces freeswitcher includes are the Inbound Event Socket handler and a CommandSocket, which allows any api or bgapi command. See the docs for the full scoop.