Guest User

Google voice callback system with selenium #2

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