Guest User

Google voice callback system with selenium

a guest
Apr 3rd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. Ok this is going to be a quick guide on how to implement a callback system with firefox / selenium / geckodriver
  2. in asterisk on debian stretch
  3. This assumes you have a running debian system with asterisk already installed
  4. You must also have the asterisk user created
  5. I'm not testing this, so hopefully you can debug any small holes that might arise
  6. Usually I would re-do the whole thing on a fresh debian install, but I don't really have time atm
  7.  
  8. Go to https://github.com/mozilla/geckodriver/releases and grab either the linux32 or linux64 version
  9. Most will probably want the 64 version
  10. extract it to /usr/local/bin
  11.  
  12. sudo apt update
  13. sudo apt install firefox-esr python python-pip
  14. sudo pip install selenium
  15.  
  16. sudo bash
  17.  
  18. su asterisk
  19. cd
  20. Run firefox and login to voice.google.com
  21. If any popups come up asking to save the password, do it
  22. Now close firefox and re-open it
  23. See if you can go to voice.google.com without it asking for password
  24. If you can't you'll have to debug it until you can login w/o password
  25.  
  26. Now find your firefox profile directory
  27.  
  28. It's usually somewhere under the .mozilla directory in your homedir
  29. In my case, the .mozilla directory was in /var/lib/asterisk since we're using the asterisk user
  30. Replace the profile dir in the gvoice snippet with your profile dir
  31.  
  32. exit
  33. You should be back at the root prompt now
  34.  
  35. Now put gvoice into /usr/local/bin
  36. and
  37. chmod 755 /usr/local/bin/gvoice
  38.  
  39. Now fill out the pjsip.conf and extensions.conf with your credentials and choice of passwords
  40. Place pjsip.conf and extensions.conf into /etc/asterisk
  41.  
  42. service asterisk restart
  43.  
  44. Now make a call out of either the 201 or 301 extension
  45.  
  46. 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
  47. and then you'll be connected
  48.  
  49. Thanks to twinclouds for the original callback system, mozilla for creating one of the first alternative open source web browsers,
  50. python for creating an awesome language, and selenium for being able to automate web browsers!
  51.  
  52. -------------------------gvoice---------------------------
  53. #!/usr/bin/env python
  54. import sys, os
  55. from selenium import webdriver
  56. from selenium.webdriver.firefox.options import Options
  57. opts = Options()
  58. opts.set_headless()
  59. assert opts.headless # Operating in headless mode
  60. # REPLACE THE PROFILE DIRECTORY BELOW WITH *YOUR* PROFILE DIRECTORY
  61. 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)
  62. driver.get('https://www.google.com/voice/b/0/redirection/voice')
  63. driver.find_element_by_css_selector('div.jfk-button-primary:nth-child(1)').click()
  64. search_form = driver.find_element_by_css_selector('.i18n_phone_number_input-inner_input')
  65. search_form.send_keys(sys.argv[1])
  66. search_form.submit()
  67. driver.close()
  68. driver.quit()
  69. quit()
  70. -------------------------gvoice---------------------------
  71.  
  72. -------------------------pjsip.conf---------------------------
  73. [transport_udp]
  74. type=transport
  75. protocol=udp
  76. bind=0.0.0.0:5061
  77.  
  78. [ipcomms]
  79. type = registration
  80. auth_rejection_permanent = no
  81. retry_interval = 20
  82. max_retries = 10
  83. contact_user = your_phone_num_here
  84. expiration = 7200
  85. transport = transport_udp
  86. outbound_auth = ipcomms
  87. client_uri = sip:your_phone_num_here@freedid.ipcomms.net
  88. server_uri = sip:freedid.ipcomms.net
  89.  
  90. [ipcomms]
  91. type = auth
  92. password = your_password_here
  93. username = your_phone_num_here
  94.  
  95. [ipcomms]
  96. type = aor
  97. contact = sip:your_phone_num_here@freedid.ipcomms.net
  98.  
  99. [ipcomms]
  100. type = identify
  101. endpoint = ipcomms
  102. match = freedid.ipcomms.net
  103.  
  104. [ipcomms]
  105. type = endpoint
  106. context = from-pstn
  107. dtmf_mode = rfc4733
  108. allow = !all,ulaw
  109. rtp_symmetric = yes
  110. rewrite_contact = yes
  111. direct_media = no
  112. trust_id_inbound = yes
  113. auth = ipcomms
  114. outbound_auth = ipcomms
  115. aors = ipcomms
  116.  
  117. [201]
  118. type = aor
  119. max_contacts = 1
  120.  
  121. [201]
  122. type = auth
  123. username = 201
  124. password = your_password_here
  125.  
  126. [201]
  127. type = endpoint
  128. context = phone
  129. rtp_symmetric=yes
  130. force_rport=yes
  131. rewrite_contact=yes
  132. auth = 201
  133. outbound_auth = 201
  134. aors = 201
  135. allow = !all,ulaw
  136. direct_media=no
  137.  
  138. [301]
  139. type = aor
  140. max_contacts = 1
  141.  
  142. [301]
  143. type = auth
  144. username = 301
  145. password = your_password_here
  146.  
  147. [301]
  148. type = endpoint
  149. context = phone
  150. rtp_symmetric=yes
  151. force_rport=yes
  152. rewrite_contact=yes
  153. auth = 301
  154. outbound_auth = 301
  155. aors = 301
  156. allow = !all,ulaw
  157. direct_media=no
  158. -------------------------pjsip.conf---------------------------
  159.  
  160. -------------------------extensions.conf---------------------------
  161. [general]
  162. static=no
  163. writeprotect=no
  164. autofallthrough=yes
  165. clearglobalvars=yes
  166. priorityjumping=no
  167.  
  168. [globals]
  169. ; Google voice callback stuff
  170. gtimeout=50 ; timeout value
  171. ; initialize
  172. gvuser=10000
  173.  
  174. [from-pstn]
  175. exten = your_phone_num_here,1,ExecIf($[${gvuser}!=10000]?Bridge(${gvuser}):Dial(PJSIP/201&PJSIP/301,60,D(:1)))
  176. ;exten = your_phone_num_here,1,ExecIf($[${gvuser}!=10000]?Bridge(${gvuser}):Dial(PJSIP/301,60,D(:1)))
  177. exten = your_phone_num_here,n, Set(GLOBAL(gvuser)=10000)
  178. exten = your_phone_num_here, n, Hangup()
  179. [phone]
  180. include = from-pstn
  181. include = gv-outbound
  182. [gv-outbound]
  183. exten = _NXXNXXXXXX,1,GoTo(1${EXTEN},1)
  184. exten = _1NXXNXXXXXX,1,Answer
  185. exten = _1NXXNXXXXXX,n,Set(GLOBAL(gvuser)=${CHANNEL})
  186. exten = _1NXXNXXXXXX,n,System(gvoice ${EXTEN} &)
  187. exten = _1NXXNXXXXXX,n,Ringing
  188. exten = _1NXXNXXXXXX,n,Wait(30)
  189. exten = _X.,n,Noop(Never received callback from Google Voice on channel ${gvuser} . exiting)
  190. exten = h,1,GotoIf($["${CHANNEL(state)}" = "Ring"]?:bridged)
  191. exten = h,n,Noop(Hangup on channel ${gvuser})
  192. ;exten = h,n,System(gvoice -b -e user@gmail.com -p password cancel &) ; Remnant from old callback system - keep just in case
  193. exten = h,n, Set(GLOBAL(gvuser)=10000)
  194. exten = h,n,Hangup()
  195. exten = h,n(bridged),Noop(The channel has been bridged successfully)
  196. exten = h,n, Set(GLOBAL(gvuser)=10000)
  197. -------------------------extensions.conf---------------------------
Add Comment
Please, Sign In to add comment