Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active January 29, 2024 06:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lgaetz/b350b9fa9ac18730150b387a1525aa4e to your computer and use it in GitHub Desktop.
Save lgaetz/b350b9fa9ac18730150b387a1525aa4e to your computer and use it in GitHub Desktop.
#!/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";
}
}
@Dirk6665
Copy link

Awesome script - thank you!

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