Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active April 7, 2022 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgaetz/ff7d6806c798086e144396d275f7a8ab to your computer and use it in GitHub Desktop.
Save lgaetz/ff7d6806c798086e144396d275f7a8ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
if (!isset($argv[1])){
echo "
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
*
* Script: lgaetz-fmfm.php
*
* Latest version: https://gist.github.com/lgaetz/ff7d6806c798086e144396d275f7a8ab
*
* Usage: Run at bash prompt of FreePBX system running FreePBX 13+ with single argument
* of extension to display whether FMFM is enabled for the extension. Use optional command
* as second argument to change
*
* # lgaetz-fmfm.php 3002 [command]
*
* Commands:
* enable - if disabled, enable for provided extension
* disable - if enabled, disable for provided extension
* toggle - either enable or disable depending on current state
* list - show all FMFM details
*
* License: GNU/GPL3+
*
* History:
* 2017-11-18 First commit by lgaetz
* 2020-04-06 Covid-19 Quarantine update - added improvements suggested by https://gist.github.com/t-oster
*
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
";
exit;
}
// user params
$verbose = true; // set to false to diable all console output
// include FreePBX bootstrap environment
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();
$device=$FreePBX->Findmefollow->get($argv[1],true);
// print_r($device); // uncomment for dbug
// get current fmfm status
if (array_key_exists ("ddial",$device)){
if($device[ddial]=="CHECKED"){
$fmfm=false;
} elseif($device[ddial]=="") {
$fmfm=true;
}
} else {
// prob an invalid extension
verbose_output("Invalid extenion - exiting");
exit;
}
switch ($argv[2]) {
case "enable":
if (!$fmfm) {
$FreePBX->Findmefollow->setDDial($argv[1], true);
verbose_output("FMFM changed to enabled");
} else {
verbose_output("FMFM already enabled - no change");
}
break;
case "disable":
if ($fmfm) {
$FreePBX->Findmefollow->setDDial($argv[1], false);
verbose_output("FMFM changed to diabled");
} else {
verbose_output("FMFM already diabled - no change");
}
break;
case "toggle":
if ($fmfm){
$FreePBX->Findmefollow->setDDial($argv[1], false);
verbose_output("FMFM changed to diabled");
} else {
$FreePBX->Findmefollow->setDDial($argv[1], true);
verbose_output("FMFM changed to enabled");
}
break;
case "list":
print_r($device);
break;
default: // maintain compatibility for previous version
if(!$fmfm){
verbose_output("FMFM disabled");
} elseif($device[ddial]=="") {
verbose_output("FMFM enabled");
}
}
function verbose_output($string) {
global $quiet, $verbose;
if (!$quiet && $verbose) {
echo $string."\n";
}
}
@lgaetz
Copy link
Author

lgaetz commented Nov 18, 2017

To do - add support to enable/disable/toggle FMFM

@lukakiro
Copy link

Sorry, in which path this file is supposed to be placed?

@t-oster
Copy link

t-oster commented Apr 6, 2020

Seems as if you can use $FreePBX->Findmefollow->setDDial($argv[1], true); or $FreePBX->Findmefollow->setDDial($argv[1], false); in order to enable/disable. This can be executed from bash anywhere in the freepbx server or you can modify it to work via HTTP and place it in /var/www/html of the freepbx server.

@lgaetz
Copy link
Author

lgaetz commented Apr 6, 2020

Thanks for the suggestion @t-oster. This script has been neglected for too long, I updated to incorporate your suggestion.

@lgaetz
Copy link
Author

lgaetz commented Apr 6, 2020

@lukakiro, you can put the script wherever you wish. It's common to place scripts like these in /var/lib/asterisk/agi-bin

@dovi5988
Copy link

dovi5988 commented Apr 6, 2022

I tried making my own script while using your script for inspiration. See https://www.reddit.com/r/freepbx/comments/txwwk2/issue_writing_my_own_fmfm_script/. Any idea what I may be doing wrong?

@lgaetz
Copy link
Author

lgaetz commented Apr 7, 2022

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