Quantcast
Channel: VOIP Tech Chat forum - dslreports.com
Viewing all articles
Browse latest Browse all 6358

GVSIP configuration helper for FreePBX users

$
0
0
This is a very simple script to help if you are creating multiple GVSIP accounts in FreePBX. You must replace the three items at the top of the file with values you use for oAuth Client ID and Client Secret (you only need one working pair of those, no matter how many accounts you have), and also a one word name for your system (can be anything, when you run it once you'll see how it's used). It then walks you through getting an oAuth Refresh Token (instructions mostly adapted from RonR's previous post), asks for a bit of additional information, and then gives you a suggested configuration. There is no error or sanity checking; "Garbage In - Garbage Out" applies here. This sort of assumes you have created at least one account already and therefore the only configuration information you need is for the new accounts. If you have never created any GVSIP account before, you should probably follow naf's instructions, at least for the [global] context. And also you may need to follow RonR's instructions to get an oAuth Client ID and Client Secret, if you don't already have those. I do things a little differently than others who have posted scripts and I think you will find that if you have several accounts, the way I do things makes it a little bit easier to keep track of your accounts. It works for me, but you are of course free to modify it as you see fit. No error checking, bells, whistles, or frills. Give it a dry run with dummy data to get a sense of what it does. If you're not satisfied, feel free to return it for a full refund. :D One hint to others who write scripts: No, you really don't need any added dialplan in extensions_custom.conf, not to make GVSIP work anyway. If you are using lines of custom dialplan to strip the +1 from the start of the incoming Google Voice number then forget about it and run this script once and it will show you the right way to do that, using the from-pstn-e164-us context in your trunk settings. EDIT: Added reminders to click Submit after creating pages in the FreePBX GUI. Also edited to make it more clear which token you are looking for on the page, since I found out the hard way that if you make a mistake and copy the access token rather than the refresh token, it actually will work for a short time (probably an hour) but then the access token expires and it stops working. You don't want to find out you've used the wrong token after you have done several accounts. Don't ask me how I know that, I don't want to talk about it! :( EDIT 2: Edited to use transport=0.0.0.0-tls rather than transport=transport_tls from naf's original instructions. If this isn't changed, you will get errors when you set tls - 0.0.0.0 - All to YES on FreePBX's Chan PJSIP Settings page (thanks to uid://1917447 for pointing this out to me in the other thread). If you have previously used this script and need to make that change in your existing pjsip_custom_post.conf file, just run sed -i -e 's/transport=transport_tls/transport=0.0.0.0-tls/g' /etc/asterisk/pjsip_custom_post.conf That should change all occurrences in the file. Then remove naf's original [transport_tls] context (all four lines) from your pjsip_custom_post.conf file, and set tls - 0.0.0.0 - All to YES on FreePBX's Chan PJSIP Settings page. EDIT 3: A few minor updates including taking elphone's suggestion to use the so-called HERE-document shell construct (see his post below), and checking to see that the entered phone number contains exactly 10 digits. As a byproduct of that, you can now enter the Google Voice number in formats such as 111-222-3333 or (111) 222-3333 and it will extract the digits and use them as long as there are exactly ten of them. This is my one concession to not having error checking, because it's far too easy to miss a digit while cutting and pasting. EDIT 4: There was a really dumb error that no one caught - in the instructions for trunk setup I had said this: "In the Dial Number Manipulation Rules tab add the pattern: 1|NXXNXXXXXX and also optionally aaa+NXXNXXXXXX (replace aaa with the assumed area code for 7 digit calls)". But that last part was wrong and actually could have prevented ten digit calls from completing. The actual optional pattern for 7 digit calls is aaa+NXXXXXX EDIT 5: Changed the outgoing Caller ID in the trunk settings to use RonR's suggested <+ prefix and +> suffix and to set Force Trunk CID, to help work around a Google Voice bug that occurs when calling your own Google Voice number. #!/bin/bash # BEFORE USING THIS SCRIPT, place YOUR OWN oAuthClientID, oAuthClientSecret, and# a one word name for your system (no spaces!) between the quotes on the lines# below, and save the modified script. If you do not already have an oAuthClientID# and oAuthClientSecret, go to# https://www.dslreports.com/forum/r30983990-Asterisk-OAuth-2-0-Support-for-Asterisk-13-or-Asterisk-14# and under the section "If you don't already have an OAuth 2.0 Client ID, Client# Secret, and refresh token(s)" follow steps 1 through 16 only (this script# replaces step 17 and all following steps). oAuthClientID="PUT YOUR OAUTH CLIENT ID HERE"oAuthClientSecret="PUT YOUR OAUTH CLIENT SECRET HERE"SystemName="PUT A ONE WORD NAME FOR YOUR SYSTEM HERE (NO SPACES!!!)"cat << EOF GVSIP Config Helper PLEASE NOTE: There is almost no error checking in this script. If you put garbage in, you get garbage out! Instructions to get Refresh Token: 1. Log into the Google Voice account for which you need a token 2. Go to https://developers.google.com/oauthplayground 3. Click the gear icon in the top right of the page 4. Check Use your own oAuth credentials 5. Enter oAuth Client ID: $oAuthClientID and oAuth Client secret: $oAuthClientSecret 6. Click Close 7. Enter https://www.googleapis.com/auth/googletalk at Input your own scopes 8. Click Authorize API 9. Sign into your Google Voice account again if you are prompted to do so 10. Click Allow 11. Click Exchange authorization code for tokens 12. Find the Refresh Token - it is the shorter of the two tokens returned, and appears at a lower position on the page.EOFread -p " Record the Refresh Token (without the quotation marks) in a safe place and enter it here: " oAuthRefreshTokencat << EOF Now please enter the following additional information: EOFread -p "Enter the Google Voice account name (the part before @gmail.com): " AccountNameecho ""while [ "${#GVPhoneNumber}" -ne "10" ]; do read -p "Enter the 10 digit Google Voice telephone number: " GVPhoneNumber GVPhoneNumber=${GVPhoneNumber//[!0-9]/} if [ "${#GVPhoneNumber}" -ne "10" ]; then echo "Telephone number must be 10 digits - please try again!"; fidoneecho ""read -p "Enter the account user's name with NO SPACES: " UserFirstNameecho ""read -p "Enter the city associated with the Google Voice telephone number, with NO SPACES: " PrefixCitycat << EOF Add the following to the file /etc/asterisk/pjsip_custom_post.conf: [gvsip-$AccountName]type=registrationoutbound_auth=gvsip-$AccountNameserver_uri=sip:obihai.sip.google.comoutbound_proxy=sip:obihai.telephony.goog:5061\;transport=tls\;lr\;hideclient_uri=sip:$AccountName$GVPhoneNumber@obihai.sip.google.comretry_interval=60support_path=yessupport_outbound=yesline=yesendpoint=gvsip-$AccountNamecontact_additional_params=obn=$SystemName-$UserFirstName-$PrefixCitytransport=0.0.0.0-tlstransport_reuse=nocontact_user=$GVPhoneNumber [gvsip-$AccountName]type=authauth_type=oauthrefresh_token=$oAuthRefreshTokenoauth_clientid=$oAuthClientIDoauth_secret=$oAuthClientSecretusername=$AccountName$GVPhoneNumberrealm=obihai.sip.google.com [gvsip-$AccountName]type=aorcontact=sip:obihai.sip.google.com [gvsip-$AccountName]type=endpointcontext=from-pstn-e164-usdisallow=allallow=ulawallow=opusoutbound_auth=gvsip-$AccountNameoutbound_proxy=sip:obihai.telephony.goog:5061\;transport=tls\;lr\;hideaors=gvsip-$AccountNamedirect_media=noice_support=yesrtcp_mux=yesmedia_use_received_transport=yesoutbound_registration=gvsip-$AccountName EOFread -p "Press ENTER after you have copied the above to the file /etc/asterisk/pjsip_custom_post.conf"cat << EOF In the FreePBX GUI: Add a custom trunk and make the trunk name: GVSIP-$AccountNameSet the Outbound CallerID to: <+$GVPhoneNumber+>Set CID Options to: Force Trunk CIDIn the Dial Number Manipulation Rules tab add the pattern: 1|NXXNXXXXXX and also optionally aaa+NXXXXXX (replace aaa with the assumed area code for 7 digit calls)In Custom Settings add the Custom Dial String: PJSIP/\$OUTNUM\$@gvsip-$AccountNameClick Submit Add an Inbound Route with the Description: Google Voice - $UserFirstName - $PrefixCitySet the DID Number to: $GVPhoneNumberSet Destination to the desired extension, ring group, IVR, etc.In the Advanced tab, set Force Answer to YES if you don't want to use Google's Voicemail.In the Other tab, optionally enable a CID Lookup Source, or Enable Superfecta Lookup and select a Superfecta Scheme (probably Default).Click Submit Don't forget to add or modify Outbound Routes to use the GVSIP-$AccountName trunk and click Submit after each. Click the Apply Config button in FreePBX and wait for the page to reload. If the new account doesn't register within several seconds,then go to the Asterisk CLI and enter core restart now (this will interrupt any calls in progress) or core restart when convenient(which will delay the restart until there are no active calls). EOF

Viewing all articles
Browse latest Browse all 6358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>