Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active December 8, 2020 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lgaetz/64212eceab5e2c8381b586ba14df4fcf to your computer and use it in GitHub Desktop.
Save lgaetz/64212eceab5e2c8381b586ba14df4fcf to your computer and use it in GitHub Desktop.
#!/usr/bin/php -q
<?php
if (!isset($argv[2])){
echo "
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
*
* Script: lgaetz-pay-it-fwd.php
* sets,unsets,toggles and lists Unconditional Call Fwd setting for provided extension
*
* Latest version: https://gist.github.com/lgaetz/64212eceab5e2c8381b586ba14df4fcf
*
* Usage: Run at bash prompt of FreePBX system running FreePBX 13+ with arguments:
*
* # lgaetz-pay-it-fwd.php <command> <ext> <fwd dest>
*
* Commands:
* enable - enable for provided extension requires <fwd dest>
* disable - if enabled, disable for provided extension ignores <fwd dest>
* toggle - either enable or disable depending on current state requires <fwd dest> if enabling
* list - show all CF details ignores arg3
*
* License: GNU/GPL3+
*
* History:
* 2020-04-20 Covid-19 Quarantine - Initial commit
* 2020-04-21 Cleanup
*
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
";
exit;
}
// user params
$verbose = true; // set to false to diable all console output TODO:
// include FreePBX bootstrap environment
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();
// Check to see if extension is valid
$user=$FreePBX->Core->getUser($argv[2]);
if ($user['extension']!=$argv[2]) {
output("Error ".$argv[2]." is not a valid extension, exiting.");
exit;
}
// TODO validate arg3
// get current CF status of extension $argv[2]
$foo=$FreePBX->Callforward->getStatusesByExtension($argv[2]);
$current_status=$foo['CF']; // fwd dest if enabled, false if disabled
//get command
switch (strtolower($argv[1])) {
case "enable":
if (isset($argv[3])) {
setcf($argv[2],$argv[3]);
output("CF Unconditional enabled for ".$argv[2]." to ".$argv[3]);
} else {
output('CF destination required but not provided - exiting');
}
break;
case "disable":
unsetcf($argv[2]);
output("CF Unconditional disabled for ".$argv[2]);
break;
case "toggle":
if ($current_status) {
unsetcf($argv[2]);
output("CF Unconditional disabled for ".$argv[2]);
} else {
if (isset($argv[3])) {
setcf($argv[2],$argv[3]);
output("CF Unconditional enabled for ".$argv[2]." to ".$argv[3]);
} else {
echo 'CF destination required but not provided - exiting';
}
}
break;
case "list":
if ($current_status) {
output("CF Unconditional is currently enabled for ".$argv[2]." to ".$current_status);
} else {
output("CF Unconditional is currently disabled for ".$argv[2]);
}
break;
default:
echo "Unrecognized command";
break;
}
exit ;
function setcf($ext,$dst) {
global $FreePBX;
$foo=$FreePBX->Callforward->setNumberByExtension($ext,$dst);
}
function unsetcf($ext){
global $FreePBX;
$foo=$FreePBX->Callforward->setNumberByExtension($ext,false);
}
function output($string) {
global $verbose;
if ($verbose) {
echo $string."\n";
}
}
@lgaetz
Copy link
Author

lgaetz commented Apr 22, 2020

As of now, there's no support for CFU or CFB, only supports call fwd unconditional.

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