Pwning Your Phone with Adhearsion and Asterisk
Past & Today Started 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 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” Ad hear sion = “adhesion” you can “hear” Not  Rails. For the VoIP domain specifically!
Why VoIP Rocks 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! (why the lucky stiff???)
Fun VoIP Projects Unlock 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’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... 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 [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? 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!
Before Adhearsion.
Before Adhearsion. After 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 Started
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 Adhearsion gem install adhearsion [asterisk-context] exten => _.,1,AGI(agi://127.0.0.1)
Writing Adhearsion Dialplans internal { }
Writing Adhearsion Dialplans internal { play ‘hello-world’ }
Writing Adhearsion Dialplans internal { loop { play ‘tt-monkeys’ } }
Writing Adhearsion Dialplans internal { +foo } foo { record { dial SIP/:out_trunk/1234 } }
Writing Adhearsion Dialplans internal { play %w”a-connect-charge-of 16 cents-per-minute will-apply” }
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 ... 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-Driven Dialplans Dialplans 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? 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 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!
Helpers
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)
Helpers require "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 hash end
Helpers (in C) (in C) int fast_factorial(int input) { int prod = 1, count = 1; while(count <= input) { prod *= count++; } return sum; }
Micromenus
Micromenus 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!
Micromenus item 'Adhearsion Server Statistics' do item 'View Registered SIP Users' do PBX.sip_users.each do |u| item &quot;SIP user '#{u.username}' on IP #{u.ip}&quot; 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 end end
Micromenus item 'Call an Employee' do item 'Select an employee below.' User.find(:all).each do |user| call user.extension, user.name end end call 'Join main conference' do play 'welcome' join 5555 end
Where Adhearsion is Headed is 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! 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_address] Adhearsion’s website:  http://adhearsion.com

More Related Content

PDF
Configuration of Ansible - DevOps: Beginner's Guide To Automation With Ansible
PDF
effective_r27
PDF
GNU Parallel
PDF
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
PDF
Buffer Overflows 101: Some Assembly Required
PDF
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
PDF
Simple callcenter platform with PHP
PPT
Automating a Vendor File Load Process with Perl and Shell Scripting
Configuration of Ansible - DevOps: Beginner's Guide To Automation With Ansible
effective_r27
GNU Parallel
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
Buffer Overflows 101: Some Assembly Required
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
Simple callcenter platform with PHP
Automating a Vendor File Load Process with Perl and Shell Scripting

Viewers also liked (6)

PDF
8 powodów dla których warto poznać Ruby
PDF
Adhearsion and Telegraph Framework Presentation
PDF
Ruby is Awesome
PDF
PPTX
JavaStart - kurs Java Podstawy
PDF
Asterisk, IM and Presence: how?
8 powodów dla których warto poznać Ruby
Adhearsion and Telegraph Framework Presentation
Ruby is Awesome
JavaStart - kurs Java Podstawy
Asterisk, IM and Presence: how?
Ad

Similar to Pwning Your Phone with Adhearsion and Asterisk (20)

ODP
Enhancing Free PBX with Adhearsion at Fosdem 2012
PDF
PDF
Enhancing FreePBX with Adhearsion
PDF
Make ruby talk to your users - literally
PPT
Stuff we noticed while building "Asterisk in the cloud"
PDF
Asterisk-Java Framework Presentation
POT
Carpenter Terry Best Practices Short
PPTX
Asterisk Phone Systems
ODP
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
PDF
Voip @ Unisi
PPT
Asterisk Introduction
PPT
Free Pbx Ot
PPT
Asterisk World2008
PPT
Lindheimer Philippe
PPT
Asterisk World Theater Talk Tlc 080319
PPT
deploymentofvoipserviceswithasteriskandfreepbx-150730234131-lva1-app6892
PDF
respond_to :voice - the convergence of voice and web interfaces with Rails an...
PPTX
Introduction to IP telephony & VoIP
PDF
Call Control Power Tools with Adhearsion
PDF
Twilio Web Service API for building Voice Applications
Enhancing Free PBX with Adhearsion at Fosdem 2012
Enhancing FreePBX with Adhearsion
Make ruby talk to your users - literally
Stuff we noticed while building "Asterisk in the cloud"
Asterisk-Java Framework Presentation
Carpenter Terry Best Practices Short
Asterisk Phone Systems
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Voip @ Unisi
Asterisk Introduction
Free Pbx Ot
Asterisk World2008
Lindheimer Philippe
Asterisk World Theater Talk Tlc 080319
deploymentofvoipserviceswithasteriskandfreepbx-150730234131-lva1-app6892
respond_to :voice - the convergence of voice and web interfaces with Rails an...
Introduction to IP telephony & VoIP
Call Control Power Tools with Adhearsion
Twilio Web Service API for building Voice Applications
Ad

Recently uploaded (20)

PPT
THE ROLE OF MANAGERIAL FINANCE MANAJEMEN KEUANGAN - GITMAN
PDF
Micro 8 - Cost Function of Microeconomics
PPTX
ratio analysis presentation for graduate
PPTX
Case study for Financial statements for Accounts
PPTX
ECN 3235 public finance public goods and planning
PDF
Income processes in Poland: An analysis based on GRID data
PPTX
Indonesia's Economic and Capital Market Development
PDF
southeast-asian-arts jjdjdjdjjfjjhfhfhfj
PPTX
cost-accounting ppt for basic understanding on cost accounting-new.pptx
PPT
Business Process Analysis and Quality Management (PMgt 771) with 2 Credit Housr
PPT
Managerial Accounting Chap 1. Guide to managerial accounting
PPTX
₹2 Lakh Personal Loan in India – Complete Guide
PPTX
Polio disease ujsn3 iksnuss. Isnnej.pptx
PPTX
NON - FARM - AREAS - OF - EMPLOYMENT.pptx
PDF
Modern Advanced Accounting in Canada, 9th Edition by Darrell Herauf, Murray H...
PPTX
Market Structures_-Perfect Competition, Monopoly, Monopolistic Competition 7 ...
PDF
Market Performance in Past Rate Cut Cycles and Current Strategy
PDF
Altcoin momentum and ETF-driven ETH flows clash with a cooling Bitcoin; Wall ...
DOCX
INCREASING THE BRAND AWARENESS OF SULWHASOO COSMETICS IN THE VIETNAMESE MARKET
DOCX
HOW TO OBTAIN COMPETITIVE ADVANTAGE USING SERVICE IN MOBILE COMMERCE – AMAZON
THE ROLE OF MANAGERIAL FINANCE MANAJEMEN KEUANGAN - GITMAN
Micro 8 - Cost Function of Microeconomics
ratio analysis presentation for graduate
Case study for Financial statements for Accounts
ECN 3235 public finance public goods and planning
Income processes in Poland: An analysis based on GRID data
Indonesia's Economic and Capital Market Development
southeast-asian-arts jjdjdjdjjfjjhfhfhfj
cost-accounting ppt for basic understanding on cost accounting-new.pptx
Business Process Analysis and Quality Management (PMgt 771) with 2 Credit Housr
Managerial Accounting Chap 1. Guide to managerial accounting
₹2 Lakh Personal Loan in India – Complete Guide
Polio disease ujsn3 iksnuss. Isnnej.pptx
NON - FARM - AREAS - OF - EMPLOYMENT.pptx
Modern Advanced Accounting in Canada, 9th Edition by Darrell Herauf, Murray H...
Market Structures_-Perfect Competition, Monopoly, Monopolistic Competition 7 ...
Market Performance in Past Rate Cut Cycles and Current Strategy
Altcoin momentum and ETF-driven ETH flows clash with a cooling Bitcoin; Wall ...
INCREASING THE BRAND AWARENESS OF SULWHASOO COSMETICS IN THE VIETNAMESE MARKET
HOW TO OBTAIN COMPETITIVE ADVANTAGE USING SERVICE IN MOBILE COMMERCE – AMAZON

Pwning Your Phone with Adhearsion and Asterisk

  • 1. Pwning Your Phone with Adhearsion and Asterisk
  • 2. Past & Today Started 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
  • 3. 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” Ad hear sion = “adhesion” you can “hear” Not Rails. For the VoIP domain specifically!
  • 4. Why VoIP Rocks 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! (why the lucky stiff???)
  • 5. Fun VoIP Projects Unlock 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
  • 6. Dave Troy’s Asterisk-Powered Roomba Dave’s also writing “Telephony with Ruby”. Will be published by The Prags in November
  • 7. 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
  • 8. 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!
  • 9. 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
  • 10. 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!
  • 13. 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...
  • 15. 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
  • 16. Installing Adhearsion gem install adhearsion [asterisk-context] exten => _.,1,AGI(agi://127.0.0.1)
  • 18. Writing Adhearsion Dialplans internal { play ‘hello-world’ }
  • 19. Writing Adhearsion Dialplans internal { loop { play ‘tt-monkeys’ } }
  • 20. Writing Adhearsion Dialplans internal { +foo } foo { record { dial SIP/:out_trunk/1234 } }
  • 21. Writing Adhearsion Dialplans internal { play %w”a-connect-charge-of 16 cents-per-minute will-apply” }
  • 22. 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 / &quot; berlin-office &quot; /extension[ 2 .. 4 ] else speak &quot; It is not business hours now in Germany. &quot; end ...
  • 23. 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 }
  • 24. Database-Driven Dialplans Dialplans 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&quot;sorry your-limit-of 100 hours has-been-reached&quot; }
  • 25. 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
  • 26. 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!
  • 28. 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)
  • 29. Helpers require &quot;hpricot&quot; require &quot;open-uri&quot; def lookup number hash = {} url = &quot; http://www.whitepages.com/9901/search/ReversePhone?phone=#{number} &quot; doc = Hpricot open(url) # This div contains all the information we need, unless it's an unlisted number if (results = doc.at &quot;#results_single_listing&quot;) 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) * &quot; &quot; elsif (results = doc.at &quot;#results_single_phone_info&quot;) 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] = &quot;#{hash[:first_name]} #{hash[:last_name]}&quot; else hash[:composite] = hash[:location] end hash end
  • 30. Helpers (in C) (in C) int fast_factorial(int input) { int prod = 1, count = 1; while(count <= input) { prod *= count++; } return sum; }
  • 32. Micromenus 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!
  • 33. Micromenus item 'Adhearsion Server Statistics' do item 'View Registered SIP Users' do PBX.sip_users.each do |u| item &quot;SIP user '#{u.username}' on IP #{u.ip}&quot; 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 end end
  • 34. Micromenus item 'Call an Employee' do item 'Select an employee below.' User.find(:all).each do |user| call user.extension, user.name end end call 'Join main conference' do play 'welcome' join 5555 end
  • 35. Where Adhearsion is Headed is 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
  • 36. 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_address] Adhearsion’s website: http://adhearsion.com