Skip to content

Instantly share code, notes, and snippets.

@jesusprubio
Created February 17, 2013 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesusprubio/4972679 to your computer and use it in GitHub Desktop.
Save jesusprubio/4972679 to your computer and use it in GitHub Desktop.
Apache Ruby script to interop between FreeSWITCH and Kamailio. (xmlcurl_sample.rb)
#!/usr/bin/env ruby
#
# 2012-03-2012 -- jesus.perez _at_ quobis _dot_ com
#
# Apache Ruby script to interop between FreeSWITCH and Kamailio.
# It uses Siremis database schema:
#
# mysql> use openser;
# Database changed
# mysql> desc subscriber;
# +---------------+------------------+------+-----+---------+----------------+
# | Field | Type | Null | Key | Default | Extra |
# +---------------+------------------+------+-----+---------+----------------+
# | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
# | username | varchar(64) | NO | MUL | | |
# | domain | varchar(64) | NO | | | |
# | password | varchar(25) | NO | | | |
# | email_address | varchar(64) | NO | | | |
# | ha1 | varchar(64) | NO | | | |
# | ha1b | varchar(64) | NO | | | |
# | rpid | varchar(64) | YES | | NULL | |
# | mac | varchar(64) | YES | | NULL | |
# +---------------+------------------+------+-----+---------+----------------+
# 9 rows in set (0.00 sec)
require "cgi"
require "mysql"
DBHOST = "localhost"
DBNAME = "openser"
DBUSER = "siremis"
DBPASS = "siremisrw"
def printheader
puts "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
puts "<document type=\"freeswitch/xml\">"
puts "<section name=\"directory\" description=\"User Directory\">"
end
def printfooter
puts "</section>"
puts "</document>"
end
dbh = Mysql.real_connect(DBHOST, DBUSER, DBPASS, DBNAME)
cgi = CGI.new
params = cgi.params
puts "Content-type: text/plain\r\n\r\n"
domain = params['domain'].to_s
username = params['user'].to_s
if (domain == "") or (username == "")
exit
end
result = dbh.query("SELECT password,vmpass
FROM subscriber
WHERE domain = '#{domain}'
AND username = '#{username}'
LIMIT 1")
if result.num_rows != 0
result.each do |row|
password = row[0]
vmpass = row[1]
printheader
puts "<domain name=\"#{domain}\">"
puts " <user id=\"#{username}\">"
puts " <params>"
puts " <param name=\"password\" value=\"#{password}\" />"
puts " <param name=\"vm-password\" value=\"#{vmpass}\" />"
puts " </params>"
puts " </user>"
puts "</domain>"
printfooter
end
end
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment