Categories
Asterisk Support Covid-19 FreePBX Knowledge Base Remote Working

Disabling Router SIP ALG

With many companies asking their employees to work from home, a common problem when trying to use a sip phone on a home network is the SIP ‘helper’ or ALG, Here is some advice on how to disable it on the more common routers that you may encounter.

SIP ALG (Application Layer Gateway) modifies VoIP traffic with the aim of solving NAT and firewall related problems. SIP ALG does this by inspecting SIP packets and modifying SIP Header and SDP data.

Unfortunately, SIP ALG was poorly implemented in a lot of cases, which has lead to it causing more issues than it corrects and due to this, we believe that, in general, it is best disabled.

Note – Many routers will re-enable SIP ALG after being powered off and on, or sometimes after a firmware update, therefore if it has been disabled in the past, and you know that the router was recently updated and powered off and on again, then it is always a good idea to log in to the router and double check the setting.

Virgin SuperHub: SIP ALG cannot be disabled in the settings of SuperHubs. Please click here for advice troubleshooting issues with SuperHubs. 

BT: SIP ALG cannot be disabled in the settings of BT HomeHubs, but can be disable with BT Business Hub versions 3 and higher:

Disabling a BT Business Hub 5’s SIP ALG

Fritz!Box: SIP ALG can’t be disabled.

DrayTek routers: Log in to your DrayTek via Telnet using an SSH client such as Putty: http://www.putty.org/

Check if SIP ALG is Enabled or Disabled:

To check if SIP ALG is Enabled or Disabled enter this command: sys sip_alg ?

If SIP ALG is disabled a ” 0 ” result will be returned.  If SIP ALG is enabled the result will be ” 1 “.

Disabling SIP ALG:

To Disable SIP ALG enter the following:

sys sip_alg 0
sys commit
sys reboot

The router will restart and save your changes.

Click here for additional general information about DrayTek Firewall setup. 

TP-Link routers: How to Disable SIP ALG on TP-Link ADSL modem router

Linksys: Check for a ‘SIP ALG’ option, in the ‘Administration’ tab under ‘Advanced’. 

May also need to disable SPI Firewall. 

Microtik: Disable ‘SIP Helper‘. 

Netgear: Look for a ‘SIP ALG’ checkbox in the ‘WAN’ settings.

Port Scan and DoS Protection should also be disabled.

Disable STUN in VoIP phone’s settings. 

D-Link: In your router’s ‘Advanced’ settings –> ‘Application Level Gateway (ALG) Configuration’ uncheck the ‘SIP’ option. 

Huawei: Many routers support SIP ALG (usually found in the ‘Security’ menu). 

SonicWALL Firewall: Under the VoIP tab, the option ‘Enable Consistent NAT’ should be enabled and ‘Enable SIP Transformations’ unchecked.  

Thomson: How to Disable SIP ALG on a Thomson Router HERE

Test with STUN disabled in your VoIP phone’s settings.

Adtran Netvanta: Disable SIP ALG under ‘Firewall/ACLs’ –> ‘ALG Settings’.

For Technicolor TG588V routers see this document for step by step details

Even if there isn’t a SIP ALG option in your router’s settings, it may still be implemented. TelNet commands must be used to disable SIP ALG with TechnicolorThomsonSpeedTouch, some Draytek and some ZyXEL routers. 

Categories
Knowledge Base

Using FreePBX FollowMe

Follow Me allows you to redirect a call that is placed to one of your extension to another extension or external number.

You can program the system to ring your extension alone for a certain period of time, then ring some other destination(s), such as a mobile phone or another extension, then go to the original extension’s voicemail if the call is not answered.  

It can also be used to divert calls to another extension without ringing the ‘original’ extension, or ring both together in a ‘twinned’ manner. This is useful if you are regularly away from your desk

Your can modify certain Follow Me settings using the User Control Panel as well as disable and enable Follow Me using a feature code that is normally *21,

To use the UCP to change settings if you have had permissions enabled is done by clicking the COG icon on teh Follow me Widget and below is a short Video on the key settings

Categories
Knowledge Base

Setting Up your UCP

The UCP or user control panel is an integral part of freePBX, It lets users have control over their telephone experience.

Below is a short video for setting up the key components of the UCP including voicemail and the WebRTC softphone.

The UCP Phone or WebRTC Phone is an in-browser phone. The Administrator can enable the “WebRTC phone” and that is “attached” to a user’s extension, this phone will then receive phone calls at the same time as the users extension .

The UCP allows users to add multiple dashboards and resizable widgets, This functionality allows users to completely customize the look and feel of their User Control Panel.

The Voicemail widget allows you to view, listen and manage your voicemail settings. The voicemail widget also allows you to monitor and listen to other peoples mailboxes, This feature is invaluable for receptionists and PA’s as it allows them to monitor their Managers or teh main company mailbox. To monitor additional mailboxes contact your system administrator.

 The FreePBX User Management Module controls which mailboxes a user will be able to add as a widget in UCP as it is not just limited to the extensions own mailbox, This is useful for department managers or Receptionists.

The UCP also has a chat function built-in that allows remote users to chat between each other similar to any other webchat but with the added security of it being ‘siloed’ in your company.

For full details and instructions of all options please see the WIKI at Sangoma.com

Categories
Asterisk Support FreePBX Knowledge Base Support Technical

Backing up files in FreePBX 15

The first time you come to restore your FREEpbx 15 system you may find that not everything that you expected is there !

The new backup module backs up on a module by module base and not like before where is was DBs and Files.

Linked here is a repository that has the files to create a module that can be edited to backup directories.

https://bitbucket.org/cybercottage/filebackup

The file you need to edit is Backup.php

<?php

namespace FreePBX\modules\Filebackup;
use FreePBX\modules\Backup as Base;

class Backup extends Base\BackupBase
{
    public function runBackup($id, $transaction)
    {
        $this->addDirectories([
            '/etc/asterisk','/tftpboot',
        ]);
        $files = glob("/etc/asterisk/*conf");
        foreach ($files as $file) {
            $path = pathinfo($file, PATHINFO_DIRNAME);
            $this->addFile(basename($file), $path, '', "conf");
    }
    $files = glob("/tftpboot/*xml");
        foreach ($files as $file) {
            $path = pathinfo($file, PATHINFO_DIRNAME);
            $this->addFile(basename($file), $path, '', "conf");
        }
        return $this;
    }
}

As you see we are backing up /etc/asterisk and /tftpboot , But only *.conf files in /etc/asterisk and only *.xml files in /tftpboot

Details on the new backup system are here https://wiki.freepbx.org/display/FOP/Implementing+Backup

Thanks to James Finstrom for the original version of this, This version is not to replace his work but only to give an example of working with Multiple directories

The downloaded zip file needs to be added as a Local module via Module Admin and enabled, It will obviously give a signing error but this can be disabled in Advanced settings or ignored ;-)

Enjoy but don’t blame me if it doesn’t work. Ive tested it on my systems and all seems good by your experience may be different

Categories
Blog Knowledge Base

SSL, FOP2 and All that..

There are a few common questions and gotchas when using fop2 on a FreePBX server using ssl.

The symptom is simple you cant connect and at the bottom left if tels you that it cant connect over websockets to port 4445 and will finally time out saying Flash is required.. None of this is awfully helpful to be honest.

But the fix is simple and its a shame by default its not this .

In your fop2.cfg file local the lines below and edit them so they match .

It maybe that your certificate names aren’t as below, In that case substitute webserver.XXX with the correct file names.

; If you access fop2 via https, browsers will try to use wss (Secure 
; web sockets) and for that it requires a certificate file and key file,
; the same ones you have in your web server configuration. Be sure to
; specify the correct certificates, the defaults are the ones for a 
; regular Centos installation:
;

ssl_certificate_file=/etc/httpd/pki/webserver.crt
ssl_certificate_key_file=/etc/httpd/pki/webserver.key
;ssl_certificate_file=/etc/pki/tls/certs/localhost.crt
;ssl_certificate_key_file=/etc/pki/tls/private/localhost.key

Thats its. Fop2 will now work over HTTPS

Categories
Blog Knowledge Base

Recording Announcements in FreePBX 13 and later

This was recorded a while ago as an aid to a customer, Its a short video on recording prompts and then adding them to an announcment so they can be used in call flow.

Categories
FreePBX Knowledge Base

FreePBX EPM Whoopsing

We have seen on some installations of FreePBX with EPM that when you upload a photo it Whoops when trying to rebulid the config.

The clue to whats happening is that it cant call function imagecreatefromjpeg or imagecreatefrompng depending on your file format

The most common cause of this is php-gd isnt installed. To Check this is simple, create a simple PHP file in the web root called phpcheck.php add the following to it:

phpcheck.php

<?php
if (extension_loaded('gd') && function_exists('gd_info')) {
    echo "PHP GD library is installed on your web server";
}
else {
    echo "PHP GD library is NOT installed on your web server";
}
?>
<?php phpinfo(); ?>

Now browse in your favourite browser to this and it will show at the top if gd is installed or not.

If its not and php was installed via yum then :

yum search php-gd
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.clouvider.net
 * extras: mirrors.clouvider.net
 * updates: mirror.sov.uk.goscomb.net
=============================================================== N/S Matched: php-gd ================================================================
php-gd.x86_64 : A module for PHP applications for using the gd graphics library

Will show if its avalible. (your version of PHP may mean this is different for you) then to install yum install php-gd and restart the httpd service

You should now be able to go to phpcheck.php again and it should show as installed. if it does you are good to go installing screen images for phones

Categories
Asterisk Support FreePBX Knowledge Base Support Technical

Resetting root password on FreePBX 14 and other Centos 7 servers

Boot your system and wait until the GRUB menu appears. On some systems you may need to press the “Escape” key to access the GRUB menu. FreePBX should show this for a few seconds on Boot

Highlight your Operating System and then press “e” to edit. You have to be quick here simpler to just press e when the menu appears and you will see similar to below.

Find the line beginning with linux. In this example the line begins linux16.

Manually delete the entries quiet and rhgb from the line. then append the following statement to the end of the line init=/bin/sh Don’t worry if your command is spread across more than one line. A continuation character “\ will be inserted automatically.

Now reboot your system now using the options specified by pressing the keys Ctrl +X

Once the system has re-booted, you will be presented with a shell prompt without having to enter any user name or password.

At this command prompt you will need to enter the following commands:

Remount the “/” root filesystem in Read/Write mode: mount -o remount,rw /

Issue the passwd command to reset the root account password: passwd

Then enter the new password as prompted twice

Then remount the “/” root filesystem in Read Only mode: mount -o remount,ro /

You can now restart the system and login with your new password.

Categories
FIrmware releases Knowledge Base

Sangoma Phone Firmware

This firmware version fixes a problem with the S400 and low audio level when making calls. 

2.0.4.57

Categories
Blog Knowledge Base

Transcribing Voicemail with Google Speech api

This is part 2 and rather long awaited description of how to transcribe voicemails to email and deliver them with text and an attached MP3

You will need to install the files from here https://zaf.github.io/asterisk-speech-recog/ and also have a Google Developers account.

Also create a directory:-

/var/lib/asterisk/sounds/catline

Lets begin.

  • Script to create the mp3 and the file for transcription
#!/bin/sh
PATH=/var/spool/asterisk/voicemail/default/
callerchan=$1
callerid=$2
origdate=$3
origtime=$4
origmailbox=$5
origdir=$6
duration=$7
apikey=YOUR GOOGLE SPEECH API KEY
FILENUM=$(/bin/ls ${PATH}${origmailbox}/INBOX |/bin/grep txt | /usr/bin/wc -l)


##Added to allow 999 messages
if  (( $FILENUM <= 9 ));
then
FILENAME=msg000${FILENUM}
elif (( $FILENUM <= 99 ));
then
FILENAME=msg00${FILENUM}
else
FILENAME=msg0${FILENUM}
fi

IN=$(/bin/grep "${origmailbox} =>" /etc/asterisk/voicemail.conf)
set -- "$IN"
IFS=","; declare -a Array=($*)
email=${Array[2]}


/bin/echo "[message]" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo origmailbox=${origmailbox} >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "context=demo" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "macrocontext=" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "exten=s" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "priority=11" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo callerchan=${callerchan} >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo callerid=${callerid} >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo origdate=${origdate} >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo origtime=${origtime} >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "category=" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt
/bin/echo "duration=${duration}" >> ${PATH}${origmailbox}/INBOX/${FILENAME}.txt

/bin/nice /usr/bin/sox /var/lib/asterisk/sounds/catline/${origdir}.wav ${PATH}${origmailbox}/INBOX/${FILENAME}.flac   silence -l 1 0.1 1% -1 0.3 1% 

/bin/nice /usr/bin/lame -b 16 -m m -q 9-resample /var/lib/asterisk/sounds/catline/${origdir}.wav  ${PATH}${origmailbox}/INBOX/${FILENAME}.mp3

voicemailbody=$(/usr/bin/perl -w /usr/src/asterisk-speech-recog-cloud_api/cli/speech-recog-cli.pl -k $apikey -o detailed -r 8000 -n 1  /var/spool/asterisk/voicemail/default/${origmailbox}/INBOX/${FILENAME}.flac)

/bin/cp /var/lib/asterisk/sounds/catline/${origdir}.wav ${PATH}${origmailbox}/INBOX/${FILENAME}.wav

echo "You have a new voicemail from ${callerid} it was left on ${origdate} and is ${duration} seconds long ${voicemailbody}" | /bin/mail -s "A new voicemail has arrived from ${callerid}" -a "${PATH}${origmailbox}/INBOX/${FILENAME}.mp3" "$email"

/bin/rm -f ${PATH}${origmailbox}/INBOX/${FILENAME}.flac
/bin/rm -f ${PATH}${origmailbox}/INBOX/${FILENAME}.mp3
  • Asterisk Dialplan to pass the call to the above script
[vmail2text]
exten => _XXXX,1,Set(__EXTTOCALL=${EXTEN})
exten => _XXXX,n,Noop(${EXTTOCALL})
exten => _XXXX,n,Goto(s,1)

exten => s,1,Answer()  ; Listen to ringing for 1 seconds
exten => s,n,Noop(${EXTTOCALL} , ${DIALSTATUS} , ${SV_DIALSTATUS})
exten => s,n,GotoIf($["${DIALSTATUS}"="BUSY"]?busy:bnext)
exten => s,n(busy),Set(greeting=busy)
exten => s,n,Goto(carryon)
exten => s,n(bnext),GotoIf($["${DIALSTATUS}"="NOANSWER"]?unavail:unext)
exten => s,n(unavail),Set(greeting=unavail)
exten => s,n,Goto(carryon)
exten => s,n(unext),Set(greeting=unavail)
exten => s,n,Goto(carryon)
exten => s,n(carryon),Set(origmailbox=${EXTTOCALL})
exten => s,n,Set(msg=${STAT(e,${ASTSPOOLDIR}/voicemail/default/${origmailbox}/${greeting}.wav)})
exten => s,n,Set(__start=0)
exten => s,n,Set(__end=0)
exten => s,n,NoOp(${UNIQUEID})
exten => s,n,Set(origdate=${STRFTIME(${EPOCH},,%a %b %d %r %Z %G)})
exten => s,n,Set(origtime=${EPOCH})
exten => s,n,Set(callerchan=${CHANNEL})
exten => s,n,Set(callerid=${CALLERID(num)})
exten => s,n,Set(origmailbox=${origmailbox})
exten => s,n,Answer()
exten => s,n,GotoIf($["${msg}"="1"]?msgy:msgn)
exten => s,n(msgy),Playback(${ASTSPOOLDIR}/voicemail/default/${origmailbox}/${greeting});(local/catreq/how_did)
exten => s,n,Goto(beep)
exten => s,n(msgn),Playback(vm-intro)
exten => s,n(beep),System(/bin/touch /var/lib/asterisk/sounds/catline/${UNIQUEID}.wav)
exten => s,n,Playback(beep)
exten => s,n,Set(__start=${EPOCH})
exten => s,n,Record(catline/${UNIQUEID}.wav,3,60,kaq)
exten => s,n,Playback(beep)
exten => s,n,Hangup()
exten => h,1,Noop(${start} ${end})
exten => h,n,GotoIf($["${start}"!="0"]?ok:end)
exten => h,n(ok),Set(end=${EPOCH})
exten => h,n,Set(duration=${MATH(${end}-${start},int)})
exten => h,n,System(/usr/local/sbin/makevmal.sh "${callerchan}" ${callerid} "${origdate}" ${origtime} ${origmailbox} ${UNIQUEID} ${duration})
exten => h,n(end),Noop(finished)
  • Modified api script, Note the language and enhanced mode setting
    • For these to work you need “datalogging ” enabled in the dialogflow api settings
#!/usr/bin/env perl

#
# Render speech to text using Google's Cloud Speech API.
#
# Copyright (C) 2011 - 2016, Lefteris Zafiris <zaf@fastmail.com>
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the COPYING file
# at the top of the source tree.
#
# This has been altered to work with Googles new Speech models
#

use strict;
use warnings;
use File::Temp qw(tempfile);
use Getopt::Std;
use File::Basename;
use LWP::UserAgent;
use LWP::ConnCache;
use JSON;
use MIME::Base64;

my %options;
my $flac;
my $key;
my $url        = "https://speech.googleapis.com/v1p1beta1/speech";
my $samplerate = 16000;
my $language   = "en-US";
my $output     = "detailed";
my $results    = 1;
my $pro_filter = "false";
my $error      = 0;
my $thetext = ".";
my $score = ".";
getopts('k:l:o:r:n:fhq', \%options);

VERSION_MESSAGE() if (defined $options{h} || !@ARGV);

parse_options();

my %config = (
        "encoding"         => "FLAC",
        "sampleRateHertz"      => $samplerate,
        "languageCode"    => $language,
        "profanityFilter" => $pro_filter,
        "maxAlternatives" => $results,
        "model" => "phone_call",
        "useEnhanced" => 'true' 
);

my $ua = LWP::UserAgent->new(ssl_opts => {verify_hostname => 1});
$ua->agent("CLI speech recognition script");
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
$ua->timeout(60);

# send each sound file to Google and get the recognition results #
foreach my $file (@ARGV) {
        my ($filename, $dir, $ext) = fileparse($file, qr/\.[^.]*/);
        if ($ext ne ".flac" && $ext ne ".wav") {
                say_msg("Unsupported file-type: $ext");
                ++$error;
                next;
        }
        if ($ext eq ".wav") {
                if (($file = encode_flac($file)) eq '-1') {
                        ++$error;
                        next;
                }
        }
#       print("File $filename\n") if (!defined $options{q});
        my $audio;
        if (open(my $fh, "<", "$file")) {
                $audio = do { local $/; <$fh> };
                close($fh);
        } else {
                say_msg("Cant read file $file");
                ++$error;
                next;
        }
        my %audio = ( "content" => encode_base64($audio, "") );
        my %json = (
                "config" => \%config,
                "audio"  => \%audio,
        );
        my $response = $ua->post(
                "$url:recognize?key=$key",
                Content_Type => "application/json",
                Content      => encode_json(\%json),
        );
        if (!$response->is_success) {
                say_msg("Failed to get data for file: $file");
                ++$error;
                next;
        }
        if ($output eq "raw") {
                print $response->content;
                next;
        }
        my $jdata = decode_json($response->content);
        if ($output eq "detailed") {
                foreach (@{$jdata->{"results"}[0]->{"alternatives"}}) {
                        $score = $_->{"confidence"};
                        $thetext = $_->{"transcript"};
                        }
        } elsif ($output eq "compact") {
                print $_->{"transcript"}."\n" foreach (@{$jdata->{"results"}[0]->{"alternatives"}});
        }
}

print "\n\nThe transcription of message is below:\n\n$thetext\n\nWe are $score out of 1 sure its correct\n\nTranscribed using Googles Cloud Speech API ";

exit(($error) ? 1 : 0);

sub parse_options {
# Command line options parsing #
        if (defined $options{k}) {
        # check API key #
                $key = $options{k};
        } else {
                say_msg("Invalid or missing API key.\n");
                exit 1;
        }
        if (defined $options{l}) {
        # check if language setting is valid #
                if ($options{l} =~ /^[a-z]{2}(-[a-zA-Z]{2,6})?$/) {
                        $language = $options{l};
                } else {
                        say_msg("Invalid language setting. Using default.\n");
                }
        }
        if (defined $options{o}) {
        # check if output setting is valid #
                if ($options{o} =~ /^(detailed|compact|raw)$/) {
                        $output = $options{o};
                } else {
                        say_msg("Invalid output formatting setting. Using default.\n");
                }
        }
        if (defined $options{n}) {
        # set number or results #
                $results = $options{n} if ($options{n} =~ /\d+/);
        }
        if (defined $options{r}) {
        # set audio sampling rate #
                $samplerate = $options{r} if ($options{r} =~ /\d+/);
        }
        # set profanity filter #
        $pro_filter = "true" if (defined $options{f});

        return;
}

sub say_msg {
# Print messages to user if 'quiet' flag is not set #
        my @message = @_;
        warn @message if (!defined $options{q});
        return;
}

sub VERSION_MESSAGE {
# Help message #
        print "Speech recognition using Google Cloud Speech API.\n\n",
                "Usage: $0 [options] [file(s)]\n\n",
                "Supported options:\n",
                " -k <key>       specify the Speech API key\n",
                " -l <lang>      specify the language to use (default 'en-US')\n",
                " -o <type>      specify the type of output formatting\n",
                "    detailed    print detailed output with info like confidence (default)\n",
                "    compact     print only the transcripted string\n",
                "    raw         raw JSON output\n",
                " -r <rate>      specify the audio sample rate in Hz (default 16000)\n",
                " -n <number>    specify the maximum number of results (default 1)\n",
                " -f             filter out profanities\n",
                " -q             don't print any error messages or warnings\n",
                " -h             this help message\n\n";
        exit(1);
}
  • In Freepbx create a Custom Destination as    “vmail2text,s,1”  and if you require certain queues to go to specific mailboxes one like “vmail2text,2000,1” so calls will be sent to mailbox 2000
  • Then in extensions that want to use transcription set the “Optional Destinations” to the custom destination.

And thats it. Enjoy.