Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ok this is going to be a quick guide on how to implement a callback system with firefox / selenium / geckodriver
- in asterisk on debian stretch
- This assumes you have a running debian system with asterisk already installed
- You must also have the asterisk user created
- I'm not testing this, so hopefully you can debug any small holes that might arise
- Usually I would re-do the whole thing on a fresh debian install, but I don't really have time atm
- Go to https://github.com/mozilla/geckodriver/releases and grab either the linux32 or linux64 version
- Most will probably want the 64 version
- extract it to /usr/local/bin
- sudo apt update
- sudo apt install firefox-esr python python-pip
- sudo pip install selenium
- xhost +
- sudo bash
- su asterisk
- cd
- Run firefox and login to voice.google.com
- If any popups come up asking to save the password, do it
- Now close firefox and re-open it
- See if you can go to voice.google.com without it asking for password
- If you can't you'll have to debug it until you can login w/o password
- Now find your firefox profile directory
- It's usually somewhere under the .mozilla directory in your homedir
- In my case, the .mozilla directory was in /var/lib/asterisk since we're using the asterisk user
- Replace the profile dir in the gvoice snippet with your profile dir
- exit
- You should be back at the root prompt now
- Now put gvoice into /usr/local/bin
- and
- chmod 755 /usr/local/bin/gvoice
- Now fill out the pjsip.conf and extensions.conf with your credentials and choice of passwords
- Place pjsip.conf and extensions.conf into /etc/asterisk
- service asterisk restart
- exit
- You should be back at your regular user prompt
- xhost -
- Now make a call out of either the 201 or 301 extension
- You will hear 1 or 2 rings that come from asterisk, then you'll hear the slightly different ring that comes from the google callback
- and then you'll be connected
- Thanks to twinclouds for the original callback system, mozilla for creating one of the first alternative open source web browsers,
- python for creating an awesome language, and selenium for being able to automate web browsers!
- -------------------------gvoice---------------------------
- #!/usr/bin/env python
- import sys, os
- from selenium import webdriver
- from selenium.webdriver.firefox.options import Options
- opts = Options()
- opts.set_headless()
- assert opts.headless # Operating in headless mode
- # REPLACE THE PROFILE DIRECTORY BELOW WITH *YOUR* PROFILE DIRECTORY
- driver = webdriver.Firefox(firefox_profile=webdriver.FirefoxProfile(r'/var/lib/asterisk/.mozilla/firefox/6bm0hyiq.default'), executable_path=r'/usr/local/bin/geckodriver', options=opts, log_path=os.devnull)
- driver.get('https://www.google.com/voice/b/0/redirection/voice')
- driver.find_element_by_css_selector('div.jfk-button-primary:nth-child(1)').click()
- search_form = driver.find_element_by_css_selector('.i18n_phone_number_input-inner_input')
- search_form.send_keys(sys.argv[1])
- search_form.submit()
- driver.close()
- driver.quit()
- quit()
- -------------------------gvoice---------------------------
- -------------------------pjsip.conf---------------------------
- [transport_udp]
- type=transport
- protocol=udp
- bind=0.0.0.0:5061
- [ipcomms]
- type = registration
- auth_rejection_permanent = no
- retry_interval = 20
- max_retries = 10
- contact_user = your_phone_num_here
- expiration = 7200
- transport = transport_udp
- outbound_auth = ipcomms
- client_uri = sip:your_phone_num_here@freedid.ipcomms.net
- server_uri = sip:freedid.ipcomms.net
- [ipcomms]
- type = auth
- password = your_password_here
- username = your_phone_num_here
- [ipcomms]
- type = aor
- contact = sip:your_phone_num_here@freedid.ipcomms.net
- [ipcomms]
- type = identify
- endpoint = ipcomms
- match = freedid.ipcomms.net
- [ipcomms]
- type = endpoint
- context = from-pstn
- dtmf_mode = rfc4733
- allow = !all,ulaw
- rtp_symmetric = yes
- rewrite_contact = yes
- direct_media = no
- trust_id_inbound = yes
- auth = ipcomms
- outbound_auth = ipcomms
- aors = ipcomms
- [201]
- type = aor
- max_contacts = 1
- [201]
- type = auth
- username = 201
- password = your_password_here
- [201]
- type = endpoint
- context = phone
- rtp_symmetric=yes
- force_rport=yes
- rewrite_contact=yes
- auth = 201
- outbound_auth = 201
- aors = 201
- allow = !all,ulaw
- direct_media=no
- [301]
- type = aor
- max_contacts = 1
- [301]
- type = auth
- username = 301
- password = your_password_here
- [301]
- type = endpoint
- context = phone
- rtp_symmetric=yes
- force_rport=yes
- rewrite_contact=yes
- auth = 301
- outbound_auth = 301
- aors = 301
- allow = !all,ulaw
- direct_media=no
- -------------------------pjsip.conf---------------------------
- -------------------------extensions.conf---------------------------
- [general]
- static=no
- writeprotect=no
- autofallthrough=yes
- clearglobalvars=yes
- priorityjumping=no
- [globals]
- ; Google voice callback stuff
- gtimeout=50 ; timeout value
- ; initialize
- gvuser=10000
- [from-pstn]
- exten = your_phone_num_here,1,ExecIf($[${gvuser}!=10000]?Bridge(${gvuser}):Dial(PJSIP/201&PJSIP/301,60,D(:1)))
- ;exten = your_phone_num_here,1,ExecIf($[${gvuser}!=10000]?Bridge(${gvuser}):Dial(PJSIP/301,60,D(:1)))
- exten = your_phone_num_here,n, Set(GLOBAL(gvuser)=10000)
- exten = your_phone_num_here, n, Hangup()
- [phone]
- include = from-pstn
- include = gv-outbound
- [gv-outbound]
- exten = _NXXNXXXXXX,1,GoTo(1${EXTEN},1)
- exten = _1NXXNXXXXXX,1,Answer
- exten = _1NXXNXXXXXX,n,Set(GLOBAL(gvuser)=${CHANNEL})
- exten = _1NXXNXXXXXX,n,System(gvoice ${EXTEN} &)
- exten = _1NXXNXXXXXX,n,Ringing
- exten = _1NXXNXXXXXX,n,Wait(30)
- exten = _X.,n,Noop(Never received callback from Google Voice on channel ${gvuser} . exiting)
- exten = h,1,GotoIf($["${CHANNEL(state)}" = "Ring"]?:bridged)
- exten = h,n,Noop(Hangup on channel ${gvuser})
- ;exten = h,n,System(gvoice -b -e user@gmail.com -p password cancel &) ; Remnant from old callback system - keep just in case
- exten = h,n, Set(GLOBAL(gvuser)=10000)
- exten = h,n,Hangup()
- exten = h,n(bridged),Noop(The channel has been bridged successfully)
- exten = h,n, Set(GLOBAL(gvuser)=10000)
- -------------------------extensions.conf---------------------------
Add Comment
Please, Sign In to add comment