Skip to content

Instantly share code, notes, and snippets.

@billsimon

billsimon/gw.php Secret

Last active March 6, 2024 03:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billsimon/5ae9c5db8c6036c63b3f9aee34176654 to your computer and use it in GitHub Desktop.
Save billsimon/5ae9c5db8c6036c63b3f9aee34176654 to your computer and use it in GitHub Desktop.
Groundwire FreePBX provisioning
<?php
// Licensed GPL v3.0 (https://www.gnu.org/licenses/gpl-3.0.en.html) by Bill Simon
//
// USAGE: gw.php?EXTNUM=ACCOUNTCODE, example: https://pbx/gw.php?1000=asdfasdfasdf
//
// Configure these:
// Transport options: https://doc.acrobits.net/cloudsoftphone/account.html#transport
$transport = "tls+sip:"; // use "udp:", "tcp:", "tls+sip:", or "tls:"
// If using a non-standard port, use the format ':xxxx' e.g. ':5062' otherwise leave empty
$port = '';
// Configure account block below
$bootstrap_settings['freepbx_auth'] = false;
require_once '/etc/freepbx.conf';
$ext = (int) array_keys($_REQUEST)[0];
if ($ext <= 0)
exit; // if we didn't get something like an extension number
$code = $_REQUEST[$ext];
if (! $device = FreePBX::Core()->getDevice($ext))
exit; // if device doesn't exist
if (empty($device['accountcode']) || ($device['accountcode'] !== $code))
exit; // if code is wrong or no code for extension
if ((strpos($_SERVER['HTTP_USER_AGENT'], "Acrobits Softphone Business") === 0) || // iOS
(strpos($_SERVER['HTTP_USER_AGENT'], "Groundwire") === 0)) { // Android
// provisioning
header('Content-type: application/xml');
// Documentation at https://doc.acrobits.net/cloudsoftphone/account.html
echo <<<AccountBlock
<account>
<title>$ext</title>
<username>$ext</username>
<password>{$device['secret']}</password>
<host>{$_SERVER['SERVER_NAME']}$port</host>
<transport>$transport</transport>
<allowMessage>1</allowMessage>
<voiceMailNumber>*97</voiceMailNumber>
<allowVideo>1</allowVideo>
<natTraversal>off</natTraversal>
<icm>auto</icm>
</account>
AccountBlock;
} else {
// generate link
header('Content-type: text/html');
// for iOS
echo '<html><body><a href="provlinkb';
if ($_SERVER['HTTPS']) { echo 's'; }
echo ':';
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo '">Add account ' . $ext . ' to Groundwire iOS</a><p></p>';
// for Android
echo '<a href="intent://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo '#Intent;scheme=provlinkb';
if ($_SERVER['HTTPS']) { echo 's'; }
echo ';package=cz.acrobits.softphone.aliengroundwire;end">Add account ' . $ext . ' to Groundwire Android</a>';
echo '</body></html>';
}
?>
@carlostico
Copy link

carlostico commented Mar 6, 2024

I followed all the instructions provided and successfully used the script, which displayed links for both iOS and Android platforms. Since I only have an iOS device, I selected the iOS option. The script appeared to provision Groundwire with the extension, password, and server details correctly. However, despite these settings being applied, I'm unable to connect, and Groundwire displays an error message. Interestingly, there is absolutely no corresponding log in Asterisk, which is quite puzzling. On the other hand provisioning the same extension manually works without a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment