Pwning Your Phone with Adhearsion and Asterisk
-
Upload
jicksta -
Category
Economy & Finance
-
view
8.234 -
download
4
description
Transcript of Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone
Pwning Your Phone
with Adhearsion and Asteriskwith Adhearsion and Asterisk
Past & TodayPast & TodayStarted January of 2005 at an ITSP
I got into Rails. Started rewrite last summer
Launched last Christmas
Spoke at O’Reilly Emerging Telephony 2007
4 page article in Linux Journal last March
Section in next O’Reilly Asterisk book
Adhearsion in a Nutshell
Adhearsion in a Nutshell
Build very complex phone systems with Ruby
Open source (LGPL) framework
Builds atop Asterisk without losing anything
More of a “collaboration framework” than an “Asterisk development framework”
Adhearsion = “adhesion” you can “hear”
Not Rails. For the VoIP domain specifically!
Why VoIP RocksWhy VoIP Rocks
(why the lucky stiff???)
VoIP skills are awesome for hackers
VoIP can dramatically cut a business’ expenses
VoIP skills look good on a resume
Builds skills in CS, SE, EE, UX,BA, and all kinds of other acronyms
Plus, now you can use Ruby!
Fun VoIP ProjectsFun VoIP ProjectsUnlock apartment door with your cell phone
Control your hacked Xbox Media Center
Rarely ever pay for a phone call
Make your own crazy reminder system
Control anything with voice commands
Phone controlled Roomba
Dave Troy’s Asterisk-Powered Roomba
Dave Troy’s Asterisk-Powered Roomba
Dave’s also writing “Telephony with Ruby”.
Will be published by The Prags in November
What is ?What is ?
Open source phone call manager (PBX)
Sponsored and developed by Digium, Inc.
Revolutionized the telecom world forever
Makes hackers really happy
Makes cash flow statements really happy
Does everything you could want with a phone
Existing Control Grammars Suck At...
Existing Control Grammars Suck At...
Conditional looping & branching
Variables
Complex data structures
Database/LDAP integration
Use of third-party libraries
Extending the language
Error handling
Date & time handling
Pattern matching...to name just a few things!
Old Dialplan Example
Old Dialplan Example
[macro-dial-iax]exten => s,1,SetGlobalVar(FOUNDME=ANSWER) exten => s,2,GotoIf($[${LEN(${ARG1})} = 10]?2:4) exten => s,3,SetVar(NumToDial=1${ARG1}) exten => s,4,Goto(s,6) exten => s,5,SetVar(NumToDial=${ARG1})
...
From extensions.conf
Why Use Adhearsion?
Why Use Adhearsion?
Asterisk rocks but its barrier to entry sucks
Grammar feels like assembler or Excel
Adds many new features to your PBX
Adhearsion does dramatically improve Asterisk
Database integration with ActiveRecord
Last but not least, integrate VoIP and Rails!
BeforeAdhearsion.
BeforeAdhearsion.
AfterAdhearsion.
Other Aspects of Adhearsion
Other Aspects of Adhearsion
Helper system for extending the framework
One of the first times VoIP code can be traded
Integrates with on-phone micro-browsers
Use other collaboration technologies together
Instant messaging, growl, weather, reverse number lookup, etc...
Getting StartedGetting Started
Asterisk?! Isn’t that hard to install?
Asterisk?! Isn’t that hard to install?
No! Use Digium’s AsteriskNOW distro
Available as install or live CD, VMWare & Xen
Asterisk installed and running when booted
Asterisk v1.4 now has a web GUI
Many good resources exist to get you started
Not to mention it now has ADHEARSION
Installing AdhearsionInstalling Adhearsion
gem install adhearsion
[asterisk-context]exten => _.,1,AGI(agi://127.0.0.1)
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal {internal {
}}
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal {internal { play ‘hello-world’play ‘hello-world’}}
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal {internal { loop { play ‘tt-monkeys’ }loop { play ‘tt-monkeys’ }}}
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal {internal { +foo+foo}}
foo {foo { record {record { dial SIP/:out_trunk/1234dial SIP/:out_trunk/1234}}}}
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal {internal { play %w”a-connect-charge-ofplay %w”a-connect-charge-of 16 cents-per-minute16 cents-per-minute will-apply”will-apply”}}
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
internal { case extension when 10...100 dial SIP/extension when 6000...6020, 7000..7030 join extension when _'21XX' if Time.now.hour.between? 2, 10 dial SIP/"berlin-office"/extension[2..4] else speak "It is not business hours now in Germany." end ...
Writing Adhearsion Dialplans
Writing Adhearsion Dialplans
... when US_NUMBER dial SIP/'us-trunk-out'/extension when /^\d{11,}$/ dial IAX/'intl-trunk-out'/extension else play %w'sorry invalid extension please-try-again' end}
Database-DrivenDialplans
Database-DrivenDialplans
service { customer = Account.find_by_phone_number callerid usage = customer.usage_this_month if usage >= 100.hours then +beyond_limit else customer.usage_this_month += time do dial IAX2/'main-trunk'/extension end end}
beyond_limit { play %w"sorry your-limit-of 100 hours has-been-reached"}
How Does Adhearsion Talk to
Asterisk?
How Does Adhearsion Talk to
Asterisk?Asterisk receives a call normally
Asterisk establishes a socket to Adhearsion, sending all call-related information
Adhearsion evaluates its own dial plan and sends commands over one at a time using AGI
Asterisk evals commands one at a time, sending a result after each
Dialog continues until call ends
Things you can do from Rails
Things you can do from Rails
Invoke virtually any PBX event with Adhearsion’s sexy syntaxes
Start calls, view live channels, record channel
Share Adhearsion’s ActiveRecord models
Manage users, groups, anything...
Manage a DB-driven dial plan
Use your imagination!
HelpersHelpers
What’s a Helper?What’s a Helper?
Code loaded when Adhearsion boots
Introduces a technology to the framework
Can be virtually anything
Can be written in Ruby, C, Java (JRuby)
HelpersHelpersrequire "hpricot"require "open-uri"
def lookup number hash = {} url = "http://www.whitepages.com/9901/search/ReversePhone?phone=#{number}" doc = Hpricot open(url)
# This div contains all the information we need, unless it's an unlisted number if (results = doc.at "#results_single_listing") then # This div's h3 contains the name of the caller hash[:first_name], hash[:last_name] = results.at('h3').inner_html.split(/,\s*/).reverse
# Now we just need the rest of the information contained in p's. meta = results/'p' meta.pop # Discard the useless p element
hash[:number] = meta.pop.inner_html city_info = meta.pop.inner_html city_info = city_info.match /(.+), ([A-Za-z]{2}) (\d{5})/ hash[:city] = city_info[1] hash[:state] = city_info[2] hash[:zip] = city_info[3]
hash[:address] = meta.map(&:inner_html) * " " elsif (results = doc.at "#results_single_phone_info") then meta = results/'span' hash[:location] = (meta.pop.inner_html.match /Location: (.*)/)[1] end if hash[:first_name] or hash[:last_name] then hash[:composite] = "#{hash[:first_name]} #{hash[:last_name]}" else hash[:composite] = hash[:location] end hashend
Helpers(in C)
Helpers(in C)
int fast_factorial(int input) { int prod = 1, count = 1; while(count <= input) { prod *= count++; } return sum;}
MicromenusMicromenus
MicromenusMicromenus
Many modern IP phones have micro-browsers
Use custom XML schema over HTTP
Uses a Ruby DSL to generate
Mini-web app framework
Also viewable in a web browser!
MicromenusMicromenusitem 'Adhearsion Server Statistics' do item 'View Registered SIP Users' do PBX.sip_users.each do |u| item "SIP user '#{u.username}' on IP #{u.ip}" end end item 'View System Uptime' do item `uptime` end item 'Network' do heading 'Network Interface Info' `ifconfig eth1`.each_line do |line| item line end endend
MicromenusMicromenus
item 'Call an Employee' do item 'Select an employee below.' User.find(:all).each do |user| call user.extension, user.name endend
call 'Join main conference' do play 'welcome' join 5555end
Where Adhearsionis Headed
Where Adhearsionis Headed
Rails GUI to Adhearsion
Built-in TFTP server serving dynamic configs
Adhearsion CLI
High-level Queue and Agent abstractions
ORM for Asterisk configs (ActiveAsterisk)
RSpec testing... for a PBX
Get Involved!Get Involved!I’m always looking for Adhearsion hackers!
Share your ideas on our mailing list!
Build your own awesome PBX on a weekend
For corporate needs, I offer Adhearsion consulting
Contact me at [email protected]
Adhearsion’s website: http://adhearsion.com