FreePBX | Register | Issues | Wiki | Portal | Support

Implementing and Testing Naf's GVsip Google Voice Sip Ubuntu 18.04 Freepbx


#1

Last Tested July 19, 2018

!!DISCLAIMER!!, This guide uses sample config files and does NOTHING as ROOT, it uses SUDO.
If you follow this guide start to finish, google voice calls will work without issue.
sample config files can pose a security concern, that is why they are undesirable.

If you omit the sample config files section, and install as root user, there’s lots of errors.
I have tried and tried and tried, to install this without the sample config files on Ubuntu 18.04 without success.
If you do resolve all of the issues, be sure to post your solution here and I will update the guide. Thank You!

Discussion: http://www.dslreports.com/forum/r32016984-Asterisk-Google-Voice-SIP-testing-and-technical-discussion
gvsip info: https://gvsip.info/
Nafs Gvsip: https://github.com/naf419/asterisk/tree/gvsip

Any questions pertaining to this guide, please ask them here.
The discussion link posted above is for those that have gvsip installed and working and wish to contribute logs and help with debugging any issues with gvsip as they crop up.

Install Ubuntu 18.04 server (any ubuntu 18.04 will do, I just prefer server or minimal)

Anywhere that I use 7775551234, replace with your 10-digit google voice number.
When prompted to enter your ITU-T telephone code, search “country dialing codes” (US is 1)

While testing I noticed that sometimes ppa:ondrej/php does not respond while trying to add it as a repository, wait a minute and try again, keep doing that until it successfully adds.

ffmpeg+lame optional, required for m4a+mp3, HTML5 format converters.
mailutils optional, required for sending email with voicemail attachment, or Module Update emails.
fail2ban optional, recommended for security.
mongodb optional, used for some XMPP features, have had no trouble without it.

Install dependencies:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install -y git curl apt-transport-https net-tools mpg123 sox \
default-libmysqlclient-dev default-mysql-client default-mysql-client-core \
default-mysql-server default-mysql-server-core apache2 libapache2-mod-php5.6 \
libapache2-mod-security2 php-pear php5.6 php5.6-cgi php5.6-cli php5.6-curl \
php5.6-fpm php5.6-gd php5.6-mbstring php5.6-mysql php5.6-odbc php5.6-xml \
unixodbc rename ffmpeg lame mailutils fail2ban mongodb

Install nodejs (optional, but required for UCP module, which I find useful so I recommend installing):

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Prep system for asterisk & Freepbx:

sudo a2enmod rewrite
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php5.6-fpm
sudo sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
sudo sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sudo sed -i 's/^memory_limit =.*/memory_limit = 256M/' /etc/php/5.6/apache2/php.ini
sudo sed -i 's/^upload_ma.*/upload_max_filesize = 120M/' /etc/php/5.6/apache2/php.ini
sudo rm /var/www/html/index.html

Clone Naf’s gvsip branch:

cd /usr/src
sudo git clone https://github.com/naf419/asterisk.git --branch gvsip
cd asterisk
sudo sed -i 's/^MAINLINE_BRANCH=master/MAINLINE_BRANCH=15/' build_tools/make_version
sudo contrib/scripts/install_prereq install
sudo contrib/scripts/get_mp3_source.sh
sudo reboot

In make menuselect add the following:
Add-ons -> format_mp3 (on the first page)
Applications -> app_macro (under Applications scroll down to the bottom, section labeled deprecated)
core sounds > wav/ulaw

cd /usr/src/asterisk
sudo ./configure
sudo make menuselect

After selecting ‘Save & Exit’ you can then continue:

sudo make
sudo make install
    (excellent point to create a backup image)
    cd /usr/src/asterisk
sudo make config
sudo ldconfig

cd /etc/asterisk
sudo cp /usr/src/asterisk/configs/samples/*.conf.sample /etc/asterisk/
sudo rename 's/.conf.sample$/.conf/' *.conf.sample
cd /usr/src/asterisk
sudo sed -i 's|;runuser|runuser|' /etc/asterisk/asterisk.conf
sudo sed -i 's|;rungroup|rungroup|' /etc/asterisk/asterisk.conf
sudo sed -i 's/^\[directories.*/\[directories\]/' /etc/asterisk/asterisk.conf

sudo groupadd asterisk
sudo useradd -d /var/lib/asterisk -g asterisk asterisk
sudo chown asterisk:asterisk /var/run/asterisk
sudo chown -R asterisk:asterisk /var/{lib,log,spool}/asterisk
sudo chown -R asterisk:asterisk /etc/asterisk /usr/lib/asterisk /var/www
sudo /etc/init.d/asterisk start
sudo /etc/init.d/asterisk stop
sudo sed -i '/END I/aAST_USER="asterisk"\nAST_GROUP="asterisk"' /etc/init.d/asterisk
sudo reboot

Setup Mysql ODBC driver (Optional, only used for CDR/CEL):

Summary

sudo nano /etc/mysql/conf.d/mysqld.cnf

[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"

ctrl+x to save and exit

sudo service mysql restart

sudo nano /etc/odbc.ini

[MySQL-asteriskcdrdb]
Description=MySQL connection to asteriskcdrdb database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3

ctrl+x to save and exit

wget https://cdn.mysql.com/Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.10-linux-ubuntu17.10-x86-64bit.tar.gz
tar -xzf mysql-connector-odbc-5.3.10-linux-ubuntu17.10-x86-64bit.tar.gz
rm -f mysql-connector-odbc-5.3.10-linux-ubuntu17.10-x86-64bit.tar.gz
cd mysql-connector-odbc-5.3.10-linux-ubuntu17.10-x86-64bit
sudo cp bin/* /usr/bin/
sudo cp lib/* /usr/lib/x86_64-linux-gnu/odbc/
sudo myodbc-installer -a -d -n "MySQL" -t "Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc5a.so"
sudo ldconfig
sudo odbcinst -i -d -f /etc/odbcinst.ini
sudo odbcinst -i -s -l -f /etc/odbc.ini
sudo odbcinst -q -d

Install Latest Freepbx:

cd /usr/src
sudo wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
sudo tar vxfz freepbx-14.0-latest.tgz
sudo rm -f freepbx-14.0-latest.tgz
cd freepbx
sudo ./install -n
sudo reboot

Now open a browser and enter the machines http://IP.ADDRESS.GOES.HERE/index.php to finish setup. You will be asked to create an admin account and choose localization settings.
http://192.168.5.240/index.php

Admin -> Module Admin
 Check Online, look for modules that have updates,
  click into them and select download and upgrade,
  I recommend installing "CID Superfecta" and "Phonebook" modules.
  If using "User Control Panel", install now so its ready during extension creation.
   UCP requirements, "user management", "process management", "certificate manager"
 then click process at the top or bottom of page.

 Other Very useful modules to install (optional):
  Blacklist, IVR, Ring Groups

Settings -> Asterisk SIP Settings
 "General SIP Settings"-Tab
   NAT Settings, External Address, click detect network settings
   Delete TURN server username & pass
   Stun Server Address: stun.l.google.com:19302   (Optional, usually)

 "Chan PJSIP Settings"-Tab
   tls - 0.0.0.0 - All - YES
   Bind Port > 5160
   TLS Bind Port > 5161

Applications -> Extensions
 Add New PJSIP Extension
  701,701,(blank),password-for-extension
Sumbit

Connectivity -> Trunks
 Add Trunk -> Add Custom Trunk
  "General"-Tab
   Trunk Name: gvtrunk1
   Outbound CallerID 7775551234

  "custom Settings"-Tab
   Custom Dial String: PJSIP/$OUTNUM$@gvsip1
Submit

Connectivity -> Outbound Routes
 Add Outbound Route
  "Route Settings"-Tab
   Route Name: gvout1
   Route CID: (blank)
   override extension No
   route password: (blank)
   Route type: (leave default)
   music on hold?: (leave default)
   route position: (leave default)
   trunk sequence for matched routes: gvtrunk1
   optional destination on congestion: Normal Congestion

  "Dial Patterns"-Tab
   (blank),(blank),1NXXNXXXXXX,701
   1,(blank),NXXNXXXXXX,701
   1777,(blank),NXXXXXX,701
Sumbit

Connectivity -> Inbound Routes
 Add Inbound Route
  "General"-Tab
   Description: gvin1
   DID Number: 7775551234
   Set Destination: 701

  "Other"-Tab
   Enable Superfecta Lookup: YES
Submit & Apply

Edit pjsip_custom_post.conf to make use of the new gvsip:
There are 6 lines <change me> that need changed, make sure you get them all, look carefully
Actually 7 lines including contact_user=7775551234 (set this to your 10 digit google voice number)

sudo nano /etc/asterisk/pjsip_custom_post.conf

debug=true
keep_alive_interval=90

[gvsip1]
type=registration
contact_user=7775551234
outbound_auth=gvsip1
server_uri=sip:obihai.sip.google.com
outbound_proxy=sip:obihai.telephony.goog:5061\;transport=tls\;lr\;hide
client_uri=sip:<your choice for device identifier>@obihai.sip.google.com
retry_interval=60
support_path=yes
support_outbound=yes
line=yes
endpoint=gvsip1
contact_additional_params=obn=<name to appear on GV settings page>
transport=0.0.0.0-tls
transport_reuse=no

[gvsip1]
type=auth
auth_type=oauth
refresh_token=<your oauth refresh token>
oauth_clientid=<your oauth client id>
oauth_secret=<your oauth client secret>
username=<your choice for device identifier>
realm=obihai.sip.google.com

[gvsip1]
type=aor
contact=sip:obihai.sip.google.com

[gvsip1]
type=endpoint
context=from-pstn
disallow=all
allow=ulaw
allow=opus
outbound_auth=gvsip1
outbound_proxy=sip:obihai.telephony.goog:5061\;transport=tls\;lr\;hide
aors=gvsip1
direct_media=no
ice_support=yes
rtcp_mux=yes
media_use_received_transport=yes
outbound_registration=gvsip1

ctrl+x to save and exit

here is how to get your OAuth 2.0 Client ID, Client Secret, and refresh token for gvsip: Creating Oauth credentials for Google Voice gvsip

For <your choice for device identifier>, make it unique such as gv7775551234
Also None of the fields that need edited should include quotes in your pjsip_custom.conf file
If you use the above guide for getting your refresh token from google, you will notice they present it with it in quotes, but when you enter the token into the file it should be without the quotes

sudo reboot
sudo asterisk -rvvv

Both the asterisk CLI and log files can help with troubleshooting if things are not working properly.
You can view the asterisk log files from Reports -> Asterisk Log Files
Start by looking for the ERROR[] lines that are in RED.
The asterisk CLI is useful to watch as your troubleshooting something such as trying to place or receive a call.

Now try placing a call from one of your extensions, If it does not work, try 1-2 more reboots, if it still does not work consult your Asterisk CLI and Asterisk Log files for clues.

It should be noted that this guide does NOT cover securing your server such as Fail2ban, there are plenty of guides that cover that, search google for securing ubuntu server, securing freepbx, securing asterisk, etc and you should find plenty of info.

I recommend backing up your system prior to making changes if you have a working system
That way you can always restore from a backup.

To Install Support for the Opus codec for HD Voice (optional):

Summary
cd /usr/src
sudo wget http://downloads.digium.com/pub/telephony/codec_opus/asterisk-16.0/x86-64/codec_opus-16.0_current-x86_64.tar.gz
sudo tar -xvzf codec_opus-16.0_current-x86_64.tar.gz
cd codec_opus-16.0_1.3.0-x86_64
sudo cp codec_opus.so /usr/lib/asterisk/modules/
sudo cp codec_opus_config-en_US.xml /var/lib/asterisk/documentation/thirdparty
sudo reboot

sudo asterisk -rvvvv
core show translation
module show like opus
(The above two commands should show opus is loaded)

Settings -> Asterisk SIP Settings
 "General SIP Settings"-Tab
   Audio Codecs Section at bottom, enable Opus, and set codec priorities.

Opus may only work with intel CPUs, if Opus breaks your asterisk then remove it:

sudo rm /usr/lib/asterisk/modules/codec_opus.so
sudo rm /var/lib/asterisk/documentation/thirdparty/codec_opus_config-en_US.xml
sudo reboot

To Later update the system with Naf’s latest changes:

cd /usr/src/asterisk
sudo make clean
sudo make distclean
sudo git pull
sudo sed -i 's/^MAINLINE_BRANCH=master/MAINLINE_BRANCH=15/' build_tools/make_version
sudo contrib/scripts/install_prereq install
sudo ./configure
    (Add-ons -> format_mp3, Applications -> app_macro, core sounds > wav/ulaw):
sudo make menuselect
sudo make
sudo make install
sudo reboot

GV Trunk Issue Diagnosis
Google voice outgoing calls one way audio
Could not determine Asterisk version (got: Asterisk GIT-master-2fd0a875d4 built by root @ myhost on a x86_64 running Linux on 2018-06-30 16:00:25 UTC). Please report this
Could not determine Asterisk version (got: Asterisk GIT-master-2fd0a875d4 built by root @ myhost on a x86_64 running Linux on 2018-06-30 16:00:25 UTC). Please report this
(Itzik) #2

Cool stuff here.


(GPz1100) #3

Nice!

Does this work with the freepbx iso installation too?


#5

I decided to try this yesterday. I installed a FreePBX Distro ISO and then built Asterisk from source in /usr/local/src. I then installed overtop of the Asterisk already in place. It works, but there’s a bit of clean-up to do. Of course this also screws up the update system which is a huge feature of the distro. Not worth it, in my opinion. If you’re going to build Asterisk from scratch, then do the manual/open-source install of FreePBX also.


(Itzik) #6

Bill, does that mean that there’s hope your service will come back to life? :pray:


#7

No. This is about helping the Asterisk/FreePBX community with a DIY solution so that a gateway service is not necessary.


#8

Much of what is being done here in _custom.conf files can be done in the GUI for a nicer integration.

Settings -> Asterisk SIP Settings -> STUN Server Address: stun.l.google.com:19302

Set up a custom Trunk first, and make the Dial string = “PJSIP/$OUTNUM$@gvsip”

Then set up Outbound Routes as usual, using 1 + NXXNXXXXXX and 1NXXNXXXXXX to represent NANP numbers and select your custom trunk as the target.

Omit these from the custom file and instead just enable the UDP and TLS transports in the Asterisk SIP Settings -> Chan_PJSIP settings screen.

The rest should go in the pjsip_custom_post.conf file because the GUI doesn’t have all the options that were added.

In the type=registration section, add contact_user=GVNUM replacing GVNUM with your number, and then you can use Inbound Routes to route the incoming call.


#9

Thank you so much billsimon! I really appreciate that and am going to try these changes today!

After trying it out, I will update the guide to include all of these changes.

Awesome Info! Exactly what I was hoping to do actually, but you obviously have a really good understanding of how it all works.

Which field should I add the stun address to? or is it both?


(Asteriskadmin) #11

how viable is it to spin up a second asterisk install just to be a gvoice gateway, and setup a sip trunk between the main freepbx and the ‘gateway’? until freepbx implements this internally, anyway


#13

A very simple asterisk basic install (with NAF’s patches) providing a pass through trunk to a full-on FreePBX would need surprisingly routing on the NAF , just a choice of chan_sip or chan_pjsip between the FBX and the NAF


#14

Whichever one results in it putting the stunaddr into the rtp_additional.conf file :slight_smile:

I think it’s the Media Transport Settings

By the way, I’m not certain this is required. I tested without it and it works fine, but my server has a public IP (no NAT).


#15

Did you find that you needed to install any new packages for openssl, libssl, libssl-dev or anything like that? I ask because I have seen where some people apparently have had issues due to having an old version of SSL-related packages, so I thought maybe you might have installed them and forgot to mention them, unless Ubuntu 18.04 already has them.


#17

When you get the asterisk source files, there a shell script included:-

contrib/scripts/install_prereq

It conveniently looks for the software A) that is necessary and B) that the ‘addons’ like to have. It is OS independent and will in this case, have suggested and then by request have the appropriate package manager install all the above.

If you regularly “roll-your-own” you will have long ago have realized that it might well save hours later in the ./configure/make/make install/make config/test_if_you_got_what_you_want cycle.

Edit : After reviewing the install process, you found the mp3 script in that directory but you REALLY don’t want to do “make samples” thing on a working FreePBX :wink:

( the other scripts in that directory are also worth looking at :slight_smile: )


#18

@dicko I am assuming that means on a fresh install, meaning the first time setting it up after install ubuntu, it would be ok to do the “make samples” then.

But when you build again the latest changes, you should NOT be running that command? I assume it would wipe out some of the changes you made if you did.

Thanks, and if I am assuming this correctly. I will make note of it in the opening post.


#19

It would probably be ‘ok’ but it would be a waste of time if two lines later you install FreePBX, from that point onwards, modifying anything that is not a “custom” or “override” file will not be “a good thing”, Just delete that ‘unnecessary’ from your process and you will be fine.


(Feh) #20

I’ve followed the asterisk rebuild process presented for IncrediblePBX from page 26267 of the nerdvittles site (can’t post the link).

Everything compiles without error, but I don’t have a working system. If anybody can explain why I can’t place an outgoing call, I’d appreciated it:

== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
> 0xb6324220 – Strict RTP learning after remote address set to: 192.168.2.21:5004
– Executing [6085------@from-internal:1] Set(“SIP/1024-00000003”, “CALLERID(dnid)=6085------”) in new stack
– Executing [6085------@from-internal:2] Set(“SIP/1024-00000003”, “CALLERID(dnid)=16085------”) in new stack
– Executing [6085------7@from-internal:3] Goto(“SIP/1024-00000003”, “16085------,1”) in new stack
– Goto (from-internal,16085------,1)
– Executing [16085------@from-internal:1] Set(“SIP/1024-00000003”, “CHANNEL(accountcode)=Google Voice”) in new stack
– Executing [1608------@from-internal:2] Dial(“SIP/1024-00000003”, “PJSIP/16085------@gvsip,r”) in new stack
[2018-07-04 18:53:17] ERROR[3286]: chan_pjsip.c:2215 request: Unable to create PJSIP channel - endpoint ‘gvsip’ was not found
[2018-07-04 18:53:17] WARNING[3285][C-00000002]: app_dial.c:2527 dial_exec_full: Unable to create channel of type ‘PJSIP’ (cause 3 - No route to destination)
== Everyone is busy/congested at this time (1:0/0/1)
– Executing [16085------@from-internal:3] Progress(“SIP/1024-00000003”, “”) in new stack
– Executing [16085------@from-internal:4] Wait(“SIP/1024-00000003”, “1”) in new stack
> 0xb6324220 – Strict RTP switching to RTP target address 192.168.2.21:5004 as source
– Executing [16085------@from-internal:5] Playback(“SIP/1024-00000003”, “silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer”) in new stack
– Playing ‘silence/1.ulaw’ (language ‘en’)
– Playing ‘cannot-complete-as-dialed.ulaw’ (language ‘en’)
– Playing ‘check-number-dial-again.ulaw’ (language ‘en’)


#21

Sorry its been about 6-7 years since ive tried IncrediblePBX, you might try asking over here: https://pbxinaflash.com/community/forums/

When I first started using google voice I used IncrediblePBX for about a year or two. Then I had an issue, its been so long I can’t even remember what it was, I actually think it might have been when I switched from using pygooglevoice to GV motif, so I installed Freepbx distro, and I ran that for about the last 6 years without really any problems.

To just readover what you posted, one line seems to indicate that the ‘gvsip’ trunk is missing, however without having tried IncrediblePBX recently, I could not speculate why.

Now I am somewhat comfortable using Freepbx so it’s what I continue to use.

From what I can tell Incredible PBX seems to take a lot of the leg work out of setting things up, so I would have guessed it should have just worked without issue, hopefully somebody over on the PIAF forums can help, PIAF and incredible PBX are intertwined.(at least that’s my understanding.)


(Andrew Nagy) #22

One could also modify the Google voice module to add everything that’s needed in here. Including adding the additional settings into pjsip. Only issue is being able to tell if it’s nafs version of asterisk.


(Andrew Nagy) #23

Make samples has caused issues with freepbx installs in the past. Plus as dicko said there’s no reason to run it.


#25

My compliments on your efforts, you jumped in at the deep end, and we see you learning fast,watch out for any inappropriate slings and arrows that often come , just get it working, then reply to any critiques :slight_smile: