FreePBX

How to run System() in dialplan in the background on Asterisk/FreePBX

In Asterisk, a System() command like

exten => 123456,n,System(mycommand)

will generally run in the foreground, i.e. Asterisk will wait until the command is finished before continuing with the Dialplan.

However, just like in any normal Linux shell, you can add a & to the end to run the command in the background:

exten => 123456,n,System(mycommand &)

 

Posted by Uli Köhler in FreePBX

How to restart Asterisk from Dialplan in FreePBX

In our previous post How to add action on call to custom extension in FreePBX we showed how to get. Moreover, in our post on How to restart Asterisk in FreePBX we explored the three different options of restarting Asterisk, e.g. core restart gracefully.

In this post, we’ll add a dialplan extension (i.e. a number that you can dial) that restarts Asterisk. This will not restart FreePBX, but completely restart (and not only reload) Asterisk itself, loading any new configuration options and re-intializing all SIP trunks, for example. In this case we’re using core restart gracefully, i.e. we’ll be waiting for any currently active calls to finish, but not admit new calls.

Add this block to /etc/asterisk/extensions_custom.conf (see How to add action on call to custom extension in FreePBX):

[from-internal-additional-custom]
exten => 999999,1,Answer()
exten => 999999,n,Wait(0.5)
exten => 999999,n,SayAlpha(OK)
exten => 999999,n,System(bash -c "sleep 1 && asterisk -rx 'core restart gracefully'" &)
exten => 999999,n,Hangup()

Reload Asterisk and now you can call 999999 to restart Asterisk

How it works

Basically, we’re reading OK to the user and then running

System(bash -c "sleep 1 && asterisk -rx 'core restart gracefully'" &)

Basically, you could thing we’ll get away with just running

System(asterisk -rx 'core restart gracefully')

However, this will fail (or at least delay the restart for approximately one minute) because the call initiating the restart is still ongoing. Also, we can’t run System() after Hangup() because Hangup() will terminate the dialplan, hence System() will never run. Hence, we run it with a delay ( sleep 1) in the background (& at the end of the command), causing Asterisk to first cleanly hang up on the call and then the command will be run.

Note that the background & at the end is absolutely essential, omitting it will cause Asterisk to just wait for the sleep 1 && asterisk ... command to finish, not Hangup() in between.

Using bash -c to run the command is just a workaround so we can stuff the multiple chained commands of sleep 1 && asterisk ... into a single command which we can run in the background using the trailing &.

Posted by Uli Köhler in FreePBX

How to run HTTP request on call to extension using FreePBX

This post is based on our previous post How to add custom action on call to custom extension in FreePBX

In FreePBX, add the following config to /etc/asterisk/extensions_custom.conf in order to add a custom extension 999 that uses System() to run curlon a fixed URL.

[from-internal-additional-custom]
exten => 999,1,Answer()
exten => 999,n,Wait(1)
exten => 999,n,System(curl http://mydomain.com/myurl)
exten => 999,n,Wait(1)
exten => 999,n,Hangup()

Don’t forget to reload Asterisk e.g. using the core reload command from the Administrator menu => Asterisk CLI in order for the changes to take effect.

For details on how [from-internal-additional-custom] works, see our previous post How to add action on call to custom extension in FreePBX

Posted by Uli Köhler in FreePBX

How to add action on call to custom extension in FreePBX

In FreePBX, add the following config to /etc/asterisk/extensions_custom.conf in order to add a custom extension 999 that just plays Hello world when called:

[from-internal-additional-custom]
exten => 999,1,Answer()
exten => 999,n,Wait(1)
exten => 999,n,Playback(hello-world)
exten => 999,n,Wait(1)
exten => 999,n,Hangup()

Don’t forget to reload Asterisk e.g. using the core reload command from the Administrator menu => Asterisk CLI in order for the changes to take effect.

How the dialplan routing works

Note that we have added this in the [from-internal-additional-custom] context, which is included at the beginning of the [from-internal-additional] context by FreePBX in extensions_additional.conf:

[from-internal-additional]
include => from-internal-additional-custom

The [from-internal-additional] context in turn is included in [from-internal]In other words, our custom extension 999 will be active for all phones calling from the [from-internal] context – which is, by default, all internal extensions.

Posted by Uli Köhler in FreePBX

How to view active calls details on FreePBX

Just want to know how many active calls are going on and not interested in the details? See How to view number of active calls on FreePBX

In order to view the details of ongoing calls on FreePBX, go to Admin -> Asterisk CLI

and enter

core show channels verbose

Now click Send command on the right:

This will display, for example

Channel              Context              Extension        Prio State   Application  Data                      CallerID        Duration Accountcode PeerAccount BridgeID
PJSIP/MyTrunk-4924   from-sip-external                        1 Up      AppDial      (Outgoing Line)           015212345678    00:00:28                         4e5accae-8a9c-48bb-b
PJSIP/123-0000000e   macro-dialout-trunk  s                  27 Up      Dial         PJSIP/01521234567@MyTrunk 492468024123    00:00:28                         4e5accae-8a9c-48bb-b
2 active channels
1 active call
8 calls processed

In the example shown, a PJSIP client (phone) registered as extension 123, calls out on a PJSIP trunk line named MyTrunk-492468024123, calling the PSTN number 015212345678.

Posted by Uli Köhler in FreePBX

How to view number of active calls on FreePBX

Also want to see call details like which extension is calling which number, call duration and which trunks are being used? See How to view active calls details on FreePBX instead.

In order to view how many calls are active concurrently on FreePBX, go to Admin -> Asterisk CLI

and enter

core show calls

Now click Send command on the right:

This will display, for example

1 active call
6 calls processed

indicating that one call is currently going on.

If no calls are currently in process, it will display

0 active calls
6 calls processed

 

Posted by Uli Köhler in FreePBX

Wie kann man sip.alice-voip.de DNS-IP ohne O2-Nameserver auflösen?

Aktuell ist die IP-Addresse von sip.alice-voip.de nur über die offiziellen O2-DNS-Server auflösbar. Für viele Anwendungen ist es jedoch sinnvoll oder möglich, nicht die DNS-Server von O2 zu nutzen und trotzdem muss sip.alice-voip.de korrekt aufgelöst werden.

TechOverflow publiziert aus diesem Grund die IP-Addrese von sip.alice-voip.de unter dem Domainnamen sip.alice-voip.de.techoverflow.net, um die reibungslose Zusammenarbeit zwischen IT-Systemen zu ermöglichen – so können beispielsweise. Beispielsweise.

Aktuell ist es unbekannt, ob die IP-Addresse von allen O2-Anschlüssen gleich aufgelöst wird. Aus diesem und anderen Gründen wird keinerlei Gewähr für die Richtigkeit oder Funktionalität der publizierten IP-Addresse übernommen. Wessen Prozesse von der Richtigkeit der IP-Addresse abhängen, sollte (wie unten beschrieben) selbst einen FlareDNS-Updater für seine eigene Domain hosten.

Selbst hosten

Die IP-Addresse wird mithilfe des FlareDNS-Beispiels CopyDNS.py alle 2 Minuten vollautomatisch aktualisiert, falls sie sich ändern sollte.

docker run --network host --rm --name FlareDNS-sip.alice-voip.de ulikoehler/flaredns:latest python CopyDNS.py --email [email protected] --api-key c6c94fd52184dcc783c5ec1d5089ec354b9d9 --hostname sip.alice-voip.de.techoverflow.net -q sip.alice-voip.de -s 192.168.178.1 --ipv4 --interval 120 --debug

Dieses Skript wird automatisch per systemd ausgeführt:

[Unit]
Description=FlareDNS DyDNS update for domain sip.alice-voip.de.techoverflow.net
Requires=docker.service
After=docker.service

[Service]
ExecStart=/usr/bin/env docker run --network host --rm --name FlareDNS-sip.alice-voip.de ulikoehler/flaredns:latest python CopyDNS.py --email [email protected] --api-key c6c94fd52184dcc783c5ec1d5089ec354b9d9 --hostname sip.alice-voip.de.techoverflow.net -q sip.alice-voip.de -s 192.168.178.1 --ipv4 --interval 120 --debug
WorkingDirectory=/opt/FlareDNS
Restart=always
User=root
Group=docker

[Install]
WantedBy=multi-user.target

 

Posted by Uli Köhler in FreePBX, Networking

How I connected a network_mode: host container to its database container

I have setup my FreePBX to use network_mode: 'host' but faced issues when it couldn’t connect to the MariaDB container which was not using network_mode: 'host'.

I fixed this by:

  • Setting the MariaDB container to network_mode: 'host'
  • Setting the FreePBX container to connect to 127.0.0.1 (DB_HOST=127.0.0.1). Setting it to localhost did NOT allow FreePBX to connect to MariaDB!
Posted by Uli Köhler in Docker, FreePBX, Networking

How to run Asterisk command from shell

Use

asterisk -rx "[command]"

to run an Asterisk command (-x) in an already running Asterisk server (-r), for example:

asterisk -rx "core restart now"

 

Posted by Uli Köhler in FreePBX

How to restart Asterisk in FreePBX

This tutorial will show how to restart the Asterisk service in FreePBX.

First, you need to install the Asterisk CLI module. In order to do that, login to your FreePBX admin panel and click at the Admin -> Module Admin menu entry.

After the module is installed, open Admin -> Asterisk CLI

Now enter one of the following commands

  • If you just want to restart Asterisk immediately, even if that stops ongoing calls, enter
    core restart now

    This is typically used while setting up the PBX

  • If you don’t want to interrupt ongoing calls but you don’t want to admit new calls, use
    core restart gracefully

    Asterisk will restart when all ongoing calls have been finished

  • In case you don’t want to interrupt ongoing calls but still admit new calls to the system, use
    core restart when convenient

    Asterisk will restart at the first opportunity when no calls are in progress

Posted by Uli Köhler in FreePBX

How to change SIP port in FreePBX

In order to change the SIP port for chan_pjsip from the default port 5060 to a custom value first go to Settings => Asterisk SIP Settings

Then go to the SIP settings [chan_pjsip] tab:

Now scroll down to the bottom of the page and look for

Change it to the desired port, e.g. 15060

click Submit on the bottom right

After that, don’t forget to click Apply Config on the top right

You also need to Restart Asterisk after the change.

Posted by Uli Köhler in FreePBX

How to fix FreePBX 15 The Module Named “manager” is required.

Problem:

When trying to install a FreePBX 15 module like Asterisk REST Interface Users you see the error message

The Module Named "manager" is required.

but you can’t find the manager module in the module list

Solution:

As you can see in module.xml in manager’s GitHub repository (which you can find easily by just googling FreePBX manager), the module is called

Asterisk API

Note that you can just click on the The Module Named "arimanager" is required. message if you disable your AdBlocker.

Posted by Uli Köhler in FreePBX

How to fix FreePBX 15 The Module Named “arimanager” is required.

Problem:

When trying to install a FreePBX 15 module like Asterisk Info you see the error message

The Module Named "arimanager" is required.

but you can’t find the arimanager module in the list of available modules.

Solution:

As you can see in module.xml in arimanager’s GitHub repository (which you can find easily by just googling arimanager), the module is called

Asterisk REST Interface Users

In order to install it, you also need the manager module which is called

Asterisk API

Note that you can just click on the The Module Named "arimanager" is required. message if you disable your AdBlocker.

Posted by Uli Köhler in FreePBX