Last active
June 30, 2025 13:44
-
-
Save lgaetz/28d41cf0ff5af1179d7840d67aae971c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/php | |
| <?php | |
| // script requires a command - echo help and exit if arg1 | |
| if (!isset($argv[1])) { | |
| echo " | |
| *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** | |
| * | |
| * Script: lgaetz-tctoggle.php | |
| * | |
| * Latest version: https://gist.github.com/lgaetz/28d41cf0ff5af1179d7840d67aae971c | |
| * | |
| * Usage: Scipt to list/toggle FreePBX Time Conditions. Developed for FreePBX 14 | |
| * | |
| * lgaetz-tctoggle <command> [<id>] | |
| * | |
| * commands - list echos all Time Conditions with ID, all other args ignored | |
| * - toggle toggles TC requires id as 2nd argument | |
| * - reset resets TC to default, requires id as 2nd argument | |
| * | |
| * License: GNU/GPL3+ | |
| * | |
| * History: | |
| * 2019-02-03 First commit by lgaetz, crude but works | |
| * 2019-02-04 add reset command, still rough | |
| * | |
| *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** | |
| \n | |
| "; | |
| exit; | |
| } | |
| // FreePBX Bootstrap environment | |
| include '/etc/freepbx.conf'; | |
| $FreePBX = FreePBX::Create(); | |
| // TODO add check to see if Time Conditions module is installed | |
| switch (strtolower($argv[1])) { | |
| case 'list': | |
| // get list of all time conditions on system | |
| $tclist = $FreePBX->Timeconditions->listTimeconditions(); | |
| foreach ($tclist as $tcitem) { | |
| $tcstate = gettcstate($tcitem['timeconditions_id']); | |
| echo $tcitem['timeconditions_id']." ".$tcitem['displayname']." ".$tcstate."\n"; | |
| } | |
| exit; | |
| case 'toggle': | |
| if (!isset($argv[2])) { | |
| echo "toggle command requires time condition ID\n"; | |
| exit; | |
| } | |
| // does specified tc id exist? | |
| $tc = $FreePBX->Timeconditions->getTimeCondition($argv[2]); | |
| if(!isset($tc['timeconditions_id'])){ | |
| echo "Not a valid time condition ID\n"; | |
| exit; | |
| } | |
| // get current state of TC and change to opposite | |
| $tcstate = $FreePBX->Timeconditions->getState($argv[2]); // returns true or null | |
| if ($tcstate=='true') { | |
| $toggle = $FreePBX->Timeconditions->setState($argv[2],'false'); | |
| } else { | |
| $toggle = $FreePBX->Timeconditions->setState($argv[2],'true'); | |
| } | |
| // todo: check state after and confirm change to screen | |
| break; | |
| case 'reset': | |
| if (!isset($argv[2])) { | |
| echo "reset command requires time condition ID\n"; | |
| exit; | |
| } | |
| // does specified tc id exist? | |
| $tc = $FreePBX->Timeconditions->getTimeCondition($argv[2]); | |
| if(!isset($tc['timeconditions_id'])){ | |
| echo "not a valid tc id\n"; | |
| exit; | |
| } | |
| $reset = $FreePBX->Timeconditions->setState($argv[2],null); | |
| // todo: check state after and echo confirmation | |
| exit; | |
| default: | |
| echo "unknown command \n"; | |
| exit; | |
| } | |
| exit; | |
| function gettcstate($id) { | |
| global $FreePBX; | |
| $foo = $FreePBX->Timeconditions->getState($id); | |
| // print_r($foo); | |
| switch ($foo) { | |
| case null: | |
| return "default"; | |
| break; | |
| case 'true': | |
| return "Temp Match"; | |
| break; | |
| case 'true_sticky': | |
| return "Perm Match"; | |
| break; | |
| case 'false': | |
| return "Temp Unmatch"; | |
| break; | |
| case 'false_sticky': | |
| return "Perm Unmatch"; | |
| break; | |
| } | |
| } | |
| function settcstate($id,$state=null) { | |
| global $FreePBX; | |
| $foo = $FreePBX->Timeconditions->setState($id,$state); | |
| print_r($foo); | |
| } | |
| // Timeconditions methods ... | |
| // get list of all time groups on system | |
| $tglist = $FreePBX->Timeconditions->listTimegroups(); | |
| //print_r($tclist); | |
| // get list of all time conditions on system | |
| $tclist = $FreePBX->Timeconditions->listTimeconditions(); | |
| // get details of specific time condition | |
| $tc = $FreePBX->Timeconditions->getTimeCondition(3); | |
| // toggle state of specific time condition | |
| $toggle = $FreePBX->Timeconditions->setState(2,'false'); // null, true = temporary match, true_sticky = permanent match, false = temporary unmatch, false_sticky = perm unmatch | |
| // get state of specific time condition | |
| $tcstate = $FreePBX->Timeconditions->getState(2); // returns null, true = temporary match, true_sticky = permanent match, false = temporary unmatch, false_sticky = perm unmatch |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@erobertus had reworked this script extensively for the better. ToDo: incorporate changes from:
https://gist.github.com/erobertus/36ed36c71a7480622a1dfa963529eeb5