Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env php
<?php
if (!isset($argv[2])){
echo "
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
*
* Script: lgaetz-dnd.php
*
* Latest version: https://gist.github.com/lgaetz/b350b9fa9ac18730150b387a1525aa4e
*
* Usage: Run at bash prompt of FreePBX system running FreePBX 13+ with first argument as
* action (show,set,unset,toggle), and the second argument as extension number
*
* # lgaetz-dnd.php <action> <ext#> [debug]
*
*
* License: GNU/GPL3+
*
* History:
* 2017-11-18 First commit by lgaetz
* 2018-05-29 added extension validation and debug option
*
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
";
exit;
}
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();
$debug=false;
if (isset($argv[3])) {
$debug=true;
}
// Check to see if extension is valid
$user=$FreePBX->Core->getUser($argv[2]);
if ($user['extension']!=$argv[2]) {
echo "Error ".$argv[2]." is not a valid extension, exiting.";
exit;
}
// get current dnd status
$status=$FreePBX->Donotdisturb->getStatusByExtension($argv[2]);
switch (strtolower($argv[1])) {
case "show":
if($status=="YES") {
echo"DND Enabled\n";
} else {
echo"DND Disabled\n";
}
break;
case "set":
if($status=="YES") {
output("DND already enabled for ".$argv[2]);
} else {
$device=$FreePBX->Donotdisturb->setStatusByExtension($argv[2],"YES");
output("Enabling DND for ".$argv[2]);
}
break;
case "unset":
if($status=="YES") {
$device=$FreePBX->Donotdisturb->setStatusByExtension($argv[2],"");
output("Disabling DND for ".$argv[2]);;
} else {
output("DND already disabled for ".$argv[2]);
}
break;
case "toggle":
if($status=="YES") {
$device=$FreePBX->Donotdisturb->setStatusByExtension($argv[2],"");
output("Disabling DND for ".$argv[2]);
} else {
$device=$FreePBX->Donotdisturb->setStatusByExtension($argv[2],"YES");
output("Enabling DND for ".$argv[2]);
}
break;
default:
echo "invalid action\n";
exit;
}
function output($string) {
global $debug;
if ($debug) {
echo $string."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment