-
Notifications
You must be signed in to change notification settings - Fork 14
/
manager.php
1830 lines (1705 loc) · 53.5 KB
/
manager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* phpagi-asmanager.php : PHP Asterisk Manager functions
* Website: http://phpagi.sourceforge.net
*
* Copyright (c) 2004 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us>
* Copyright (c) 2005 - 2015 Schmooze Com, Inc
* All Rights Reserved.
*
* This software is released under the terms of the GNU Public License v2
* A copy of which is available from http://www.fsf.org/licenses/gpl.txt
*
* @package phpAGI
*/
/**
* Asterisk Manager class
*
* @link http://www.voip-info.org/wiki-Asterisk+config+manager.conf
* @link http://www.voip-info.org/wiki-Asterisk+manager+API
* @example examples/sip_show_peer.php Get information about a sip peer
* @package phpAGI
*/
namespace Asterisk\AMI;
class Manager {
/**
* Config variables
*
* @var array
*/
public $config;
/**
* Socket
*
*/
public $socket = NULL;
/**
* Server we are connected to
*
* @var string
*/
public $server;
/**
* Port on the server we are connected to
*
* @var integer
*/
public $port;
/**
* Parent AGI
*
* @var AGI
*/
private $pagi;
/**
* Username we connected with (for reconnect)
*
* @var string
*/
public $username = NULL;
/**
* Secret we connected with (for reconnect)
*
* @var string
*/
public $secret = NULL;
/**
* Current state of events (for reconnect)
*
* @var string
*/
public $events = NULL;
/**
* Number of reconnect attempts per incident
*
* @var string
*/
public $reconnects = 2;
/**
* Asterisk settings from CoreSettings
* @var array
*/
private $settings = null;
/**
* Event Handlers
*
* @var array
*/
private $event_handlers;
/**
* Log Level
*
* @var integer
*/
private $log_level;
/**
* Whether to cache the asterisk DB information
* @var bool
*/
private $useCaching = false;
/**
* The cached Asterisk DB
* @var array
*/
private $memAstDB = null;
/**
* Constructor
*
* @param string $config is an array of configuration vars and vals, stuffed into $this->config
*/
public function __construct($config=array()) {
//No Errors to the screen
//error_reporting(0);
//@ini_set('display_errors', 0);
// load config
if(!empty($config) && is_array($config)) {
$this->config = $config;
} elseif(defined("DEFAULT_PHPAGI_CONFIG") && file_exists(DEFAULT_PHPAGI_CONFIG)) {
$this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
} else {
throw new \Exception("Asterisk Manager Config not found. Aborting");
}
// add default values to config for uninitialized values
if (!isset($this->config['server'])) {
$this->config['server'] = 'localhost';
}
if (!isset($this->config['port'])) {
$this->config['port'] = 5038;
}
if (!isset($this->config['username'])) {
$this->config['username'] = 'phpagi';
}
if (!isset($this->config['secret'])) {
$this->config['secret'] = 'phpagi';
}
if (!isset($this->config['timeout'])) {
$this->config['timeout'] = 5;
}
if (isset($this->config['cachemode'])) {
$this->useCaching = $this->config['cachemode'];
}
$this->log_level = (isset($this->config['log_level']) && is_numeric($this->config['log_level'])) ? $this->config['log_level'] : false;
$this->reconnects = isset($this->config['reconnects']) ? $this->config['reconnects'] : 2;
}
/**
* Load Asterisk DB into local cache
*/
private function LoadAstDB() {
if ($this->memAstDB != null) {
unset($this->memAstDB);
}
$this->memAstDB = $this->database_show();
}
/**
* Send a request
*
* @param string $action
* @param array $parameters
* @return array of parameters
*/
public function send_request($action, $parameters=array(), $retry=true) {
$reconnects = $this->reconnects;
$req = "Action: $action\r\n";
foreach($parameters as $var=>$val) {
if (is_array($val)) {
foreach($val as $k => $v) {
$req .= "$var: $k=$v\r\n";
}
} else {
$req .= "$var: $val\r\n";
}
}
$req .= "\r\n";
$this->log("Sending Request down socket:",10);
$this->log($req,10);
if(!$this->connected()) {
throw new Exception("Asterisk is not connected");
}
fwrite($this->socket, $req);
$response = $this->wait_response();
// If we got a false back then something went wrong, we will try to reconnect the manager connection to try again
//
while ($response === false && $retry && $reconnects > 0) {
$this->log("Unexpected failure executing command: $action, reconnecting to manager and retrying: $reconnects");
$this->disconnect();
if ($this->connect($this->server.':'.$this->port, $this->username, $this->secret, $this->events) !== false) {
if(!$this->connected()) {
throw new Exception("Asterisk is not connected");
}
fwrite($this->socket, $req);
$response = $this->wait_response();
} else {
if ($reconnects > 1) {
$this->log("reconnect command failed, sleeping before next attempt");
sleep(1);
} else {
$this->log("FATAL: no reconnect attempts left, command permanently failed, returning to calling program with 'false' failure code");
}
}
$reconnects--;
}
if($action == 'Command' && empty($response['data']) && !empty($response['Output'])) {
$response['data'] = $response['Output'];
unset($response['Output']);
}
return $response;
}
/**
* Wait for a response
*
* If a request was just sent, this will return the response.
* Otherwise, it will loop forever, handling events.
*
* @param boolean $allow_timeout if the socket times out, return an empty array
* @return array of parameters, empty on timeout
*/
public function wait_response($allow_timeout = false) {
$timeout = false;
set_error_handler("Asterisk\AMI\phpasmanager_error_handler");
do {
$type = NULL;
$parameters = array();
if (!$this->socket || feof($this->socket)) {
$this->log("Got EOF in wait_response() from socket waiting for response, returning false",10);
restore_error_handler();
return false;
}
$buffer = trim(fgets($this->socket, 4096));
while($buffer != '') {
$a = strpos($buffer, ':');
if($a) {
if(!count($parameters)) {// first line in a response?
$type = strtolower(substr($buffer, 0, $a));
if((substr($buffer, $a + 2) == 'Follows')) {
// A 'follows' response means there is a muiltiline field that follows.
$parameters['data'] = '';
$buff = fgets($this->socket, 4096);
while(substr($buff, 0, 6) != '--END ') {
$parameters['data'] .= $buff;
$buff = fgets($this->socket, 4096);
}
}
} elseif(count($parameters) == 2) {
if($parameters['Response'] == "Success" && isset($parameters['Message']) && $parameters['Message'] == 'Command output follows') {
// A 'Command output follows' response means there is a muiltiline field that follows.
$parameters['data'] = '';
$buff = fgets($this->socket, 4096);
while($buff !== "\r\n") {
$buff = preg_replace("/^Output:\s*/","",$buff);
$parameters['data'] .= $buff;
$buff = fgets($this->socket, 4096);
}
if(empty($parameters['data'])) {
$parameters['data'] = preg_replace("/^Output:\s*/","",$buffer);
}
break;
}
}
// store parameter in $parameters
$parameters[substr($buffer, 0, $a)] = substr($buffer, $a + 2);
}
$buffer = trim(fgets($this->socket, 4096));
}
// process response
switch($type) {
case '': // timeout occured
$timeout = $allow_timeout;
break;
case 'event':
$this->process_event($parameters);
break;
case 'response':
case 'message':
break;
default:
$this->log('Unhandled response packet ('.$type.') from Manager: ' . print_r($parameters, true));
break;
}
} while($type != 'response' && $type != 'message' && !$timeout);
$this->log("returning from wait_response with with type: $type",10);
$this->log('$parmaters: '.print_r($parameters,true),10);
$this->log('$buffer: '.print_r($buffer,true),10);
if (isset($buff)) {
$this->log('$buff: '.print_r($buff,true),10);
}
restore_error_handler();
return $parameters;
}
/**
* Connect to Asterisk
*
* @example examples/sip_show_peer.php Get information about a sip peer
*
* @param string $server
* @param string $username
* @param string $secret
* @return boolean true on success
*/
public function connect($server=NULL, $username=NULL, $secret=NULL, $events='on') {
set_error_handler("Asterisk\AMI\phpasmanager_error_handler");
// use config if not specified
if(is_null($server)) {
$server = $this->config['server'];
}
$this->username = is_null($username) ? $this->config['username'] : $username;
$this->secret = is_null($secret) ? $this->config['secret'] : $secret;
$this->events = $events;
// get port from server if specified
if(strpos($server, ':') !== false) {
$c = explode(':', $server);
$this->server = $c[0];
$this->port = $c[1];
} else {
$this->server = $server;
$this->port = $this->config['port'];
}
// connect the socket
$errno = $errstr = NULL;
$this->socket = stream_socket_client("tcp://".$this->server.":".$this->port, $errno, $errstr);
stream_set_timeout($this->socket,30);
if(!$this->socket) {
restore_error_handler();
throw new \Exception("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr");
}
// read the header
$str = fgets($this->socket);
if($str == false) {
// a problem.
restore_error_handler();
throw new \Exception("Asterisk Manager Header not received");
} else {
// note: don't $this->log($str) until someone looks to see why it mangles the logging
}
stream_set_timeout($this->socket, $this->config['timeout']);
// login
$res = $this->send_request('login',
array(
'Username'=>$this->username,
'Secret'=>$this->secret,
'Events'=>$this->events
),
false);
if($res['Response'] != 'Success') {
$this->disconnect();
restore_error_handler();
throw new \Exception("Failed to login");
return false;
}
$this->CoreSettings();
restore_error_handler();
return true;
}
/**
* Disconnect
*
*/
public function disconnect() {
if($this->connected()) {
$this->logoff();
}
fclose($this->socket);
$this->settings = null;
}
/**
* Check if the socket is connected
*
*/
public function connected() {
return is_resource($this->socket) && !feof($this->socket);
}
/**
* Set Absolute Timeout
*
* Hangup a channel after a certain time. Acknowledges set time with Timeout Set message.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_AbsoluteTimeout
* @version 11
* @param string $channel
* @param integer $timeout
*/
public function AbsoluteTimeout($channel, $timeout) {
return $this->send_request('AbsoluteTimeout', array('Channel'=>$channel, 'Timeout'=>$timeout));
}
/**
* Show PBX core settings (version etc).
*
* Query for Core PBX settings.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_CoreSettings
*/
public function CoreSettings() {
if(empty($this->settings)) {
$this->settings = $this->send_request('CoreSettings');
}
return $this->settings;
}
/**
* Sets an agent as no longer logged in.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_AgentLogoff
* @version 11
* @param string $agent Agent ID of the agent to log off.
* @param string $soft Set to true to not hangup existing calls.
*/
public function AgentLogoff($agent, $soft='false') {
return $this->send_request('AgentLogoff', array('Agent'=>$agent, 'Soft'=>$soft));
}
/**
* Lists agents and their status.
*
* Will list info about all possible agents.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_Agents
* @version 11
*/
public function Agents() {
return $this->send_request('Agents');
}
/**
* Add an AGI command to execute by Async AGI.
*
* Add an AGI command to the execute queue of the channel in Async AGI.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_AGI
* @param string $channel Channel that is currently in Async AGI.
* @param string $command Application to execute.
* @param string $commandid This will be sent back in CommandID header of AsyncAGI exec event notification.
*/
public function AGI($channel, $command, $commandid) {
return $this->send_request('AGI', array('Channel'=>$channel, 'Command'=>$command, "CommandID" => $commandid));
}
/**
* Send an arbitrary event.
*
* Send an event to manager sessions.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_UserEvent
* @param string $channel
* @param string $file
*/
function UserEvent($event, $headers=array()) {
$d = array('UserEvent'=>$event);
$i = 1;
foreach($headers as $header) {
$d['Header'.$i] = $header;
$i++;
}
return $this->send_request('UserEvent', $d);
}
/**
* Change monitoring filename of a channel
*
* This action may be used to change the file started by a previous 'Monitor' action.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ChangeMonitor
* @param string $channel Used to specify the channel to record.
* @param string $file Is the new name of the file created in the monitor spool directory.
*/
public function ChangeMonitor($channel, $file) {
return $this->send_request('ChangeMonitor', array('Channel'=>$channel, 'File'=>$file));
}
/**
* Execute Asterisk CLI Command
*
* Run a CLI command
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_Command
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+Command+Line+Interface
* @param string $command Asterisk CLI command to run
* @param string $actionid message matching variable
*/
public function Command($command, $actionid=NULL) {
$parameters = array('Command'=>$command);
if($actionid) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('Command', $parameters);
}
/**
* Tell Asterisk to poll mailboxes for a change
*
* Normally, MWI indicators are only sent when Asterisk itself changes a mailbox.
* With external programs that modify the content of a mailbox from outside the
* application, an option exists called pollmailboxes that will cause voicemail
* to continually scan all mailboxes on a system for changes. This can cause a
* large amount of load on a system. This command allows external applications
* to signal when a particular mailbox has changed, thus permitting external
* applications to modify mailboxes and MWI to work without introducing
* considerable CPU load.
*
* If Context is not specified, all mailboxes on the system will be polled for
* changes. If Context is specified, but Mailbox is omitted, then all mailboxes
* within Context will be polled. Otherwise, only a single mailbox will be
* polled for changes.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+ManagerAction_VoicemailRefresh
* @param string $context
* @param string $mailbox
* @param string $actionid ActionID for this transaction. Will be returned.
*/
function VoicemailRefresh($context=NULL,$mailbox=NULL, $actionid=NULL) {
if(version_compare($this->settings['AsteriskVersion'], "12.0", "lt")) {
return false;
}
$parameters = array();
if(!empty($context)) {
$parameters['Context'] = $context;
}
if(!empty($mailbox)) {
$parameters['Mailbox'] = $mailbox;
}
if(!empty($actionid)) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('VoicemailRefresh', $parameters);
}
/**
* Get and parse codecs
* @param {string} $type='audio' Type of codec to look up
*/
public function Codecs($type='audio') {
$type = strtolower($type);
switch($type) {
case 'video':
$ret = $this->Command('core show codecs video');
break;
case 'text':
$ret = $this->Command('core show codecs text');
break;
case 'image':
$ret = $this->Command('core show codecs image');
break;
case 'audio':
default:
$ret = $this->Command('core show codecs audio');
break;
}
if(preg_match_all('/\d{1,6}\s*'.$type.'\s*([a-z0-9]*)\s/i',$ret['data'],$matches)) {
return $matches[1];
} else {
return array();
}
}
/**
* Kick a Confbridge user.
*
* Kick a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeKick
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
public function ConfbridgeKick($conference, $channel) {
return $this->send_request('ConfbridgeKick', array('Conference'=>$conference, 'Channel'=>$channel));
}
/**
* List Users in a Conference
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeList
* @param string $conference Conference number.
*/
public function ConfbridgeList($conference) {
$this->add_event_handler("confbridgelist", array($this, 'Confbridge_catch'));
$this->add_event_handler("confbridgelistcomplete", array($this, 'Confbridge_catch'));
$response = $this->send_request('ConfbridgeList', array('Conference'=>$conference));
if ($response["Response"] == "Success") {
$this->response_catch = array();
$this->wait_response(true);
stream_set_timeout($this->socket, 30);
} else {
return false;
}
return $this->response_catch;
}
/**
* List active conferences.
*
* Lists data about all active conferences. ConfbridgeListRooms will follow as separate events, followed by a final event called ConfbridgeListRoomsComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
public function ConfbridgeListRooms() {
$this->add_event_handler("confbridgelistrooms", array($this, 'Confbridge_catch'));
$this->add_event_handler("confbridgelistroomscomplete", array($this, 'Confbridge_catch'));
$response = $this->send_request('ConfbridgeListRooms');
if ($response["Response"] == "Success") {
$this->response_catch = array();
$this->wait_response(true);
stream_set_timeout($this->socket, 30);
} else {
return false;
}
return $this->response_catch;
}
/**
* Conference Bridge Event Catch
*
* This catches events obtained from the confbridge stream, it should not be used externally
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
private function Confbridge_catch($event, $data, $server, $port) {
switch($event) {
case 'confbridgelistcomplete':
case 'confbridgelistroomscomplete':
/* HACK: Force a timeout after we get this event, so that the wait_response() returns. */
stream_set_timeout($this->socket, 0, 1);
break;
case 'confbridgelist':
$this->response_catch[] = $data;
break;
case 'confbridgelistrooms':
$this->response_catch[] = $data;
break;
}
}
/**
* Conference Bridge Event Catch
*
* This catches events obtained from the confbridge stream, it should not be used externally
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
private function Meetme_catch($event, $data, $server, $port) {
switch($event) {
case 'meetmelistcomplete':
case 'meetmelistroomscomplete':
/* HACK: Force a timeout after we get this event, so that the wait_response() returns. */
stream_set_timeout($this->socket, 0, 1);
break;
case 'meetmelist':
$this->response_catch[] = $data;
break;
case 'meetmelistrooms':
$this->response_catch[] = $data;
break;
}
}
/**
* Lock a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeLock
* @param string $conference Conference number.
*/
function ConfbridgeLock($conference) {
return $this->send_request('ConfbridgeLock', array('Conference'=>$conference));
}
/**
* Mute a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeMute
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
function ConfbridgeMute($conference,$channel) {
return $this->send_request('ConfbridgeMute', array('Conference'=>$conference, 'Channel' => $channel));
}
/**
* Set a conference user as the single video source distributed to all other participants.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeSetSingleVideoSrc
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
function ConfbridgeSetSingleVideoSrc($conference,$channel) {
return $this->send_request('ConfbridgeSetSingleVideoSrc', array('Conference'=>$conference, 'Channel' => $channel));
}
/**
* Start recording a Confbridge conference.
*
* Start recording a conference. If recording is already present an error will be returned.
* If RecordFile is not provided, the default record file specified in the conference's bridge profile will be used, if that is not present either a file will automatically be generated in the monitor directory.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeMute
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
function ConfbridgeStartRecord($conference,$recordFile) {
return $this->send_request('ConfbridgeStartRecord', array('Conference'=>$conference, 'RecordFile' => $recordFile));
}
/**
* Stop recording a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeStopRecord
* @param string $conference Conference number.
*/
function ConfbridgeStopRecord($conference) {
return $this->send_request('ConfbridgeStopRecord', array('Conference'=>$conference));
}
/**
* Unlock a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeUnlock
* @param string $conference Conference number.
*/
function ConfbridgeUnlock($conference) {
return $this->send_request('ConfbridgeUnlock', array('Conference'=>$conference));
}
/**
* Unmute a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeUnmute
* @param string $conference Conference number.
*/
function ConfbridgeUnmute($conference,$channel) {
return $this->send_request('ConfbridgeUnmute', array('Conference'=>$conference,'Channel' => $channel));
}
/**
* Enable/Disable sending of events to this manager
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_Events
* @param string $eventmask is either 'on', 'off', or 'system,call,log'
*/
function Events($eventmask) {
$this->events = $eventmask;
return $this->send_request('Events', array('EventMask'=>$eventmask));
}
/**
* Check Extension Status
*
* Report the extension state for given extension.
* If the extension has a hint, will use devicestate to check the status of the device connected to the extension.
* Will return an Extension Status message.
* The response will include the hint for the extension and the status.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ExtensionState
* @param string $exten Extension to check state on
* @param string $context Context for extension
* @param string $actionid message matching variable
*/
function ExtensionState($exten, $context, $actionid = NULL) {
$parameters = array('Exten'=>$exten, 'Context'=>$context);
if($actionid) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('ExtensionState', $parameters);
}
/**
* Gets a Channel Variable
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_Getvar
* @param string $channel Channel to read variable from
* @param string $variable Variable name, function or expression
* @param string $actionid message matching variable
*/
function GetVar($channel, $variable, $actionid=NULL) {
$parameters = array('Channel'=>$channel, 'Variable'=>$variable);
if($actionid) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('GetVar', $parameters);
}
/**
* Hangup Channel
*
* @link https://wiki.asterisk.org/wiki/display/AST/ManagerAction_Hangup
* @param string $channel The channel name to be hungup
*/
function Hangup($channel) {
return $this->send_request('Hangup', array('Channel'=>$channel));
}
/**
* List IAX Peers
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_IAXpeers
*/
function IAXPeers() {
return $this->send_request('IAXPeers');
}
/**
* Check Presence State
*
* Report the presence state for the given presence provider.
* Will return a Presence State message.
* The response will include the presence state and, if set, a presence subtype and custom message.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerAction_PresenceState
* @param string $provider Presence Provider to check the state of
*/
function PresenceState($provider) {
return $this->send_request('PresenceState',array('Provider'=>$provider));
}
/**
* List available manager commands
*
* Returns the action name and synopsis for every action that is available to the user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ListCommands
* @param string $actionid message matching variable
*/
function ListCommands($actionid=NULL) {
if($actionid) {
return $this->send_request('ListCommands', array('ActionID'=>$actionid));
} else {
return $this->send_request('ListCommands');
}
}
/**
* Logoff Manager
*
* Logoff the current manager session.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_Logoff
*/
function Logoff() {
return $this->send_request('Logoff',array(),false);
}
/**
* Check Mailbox Message Count
*
* Returns number of new and old messages.
* Message: Mailbox Message Count
* Mailbox: <mailboxid>
* NewMessages: <count>
* OldMessages: <count>
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MailboxStatus
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
*/
function MailboxCount($mailbox, $actionid=NULL) {
$parameters = array('Mailbox'=>$mailbox);
if($actionid) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('MailboxCount', $parameters);
}
/**
* Check Mailbox
*
* Returns number of messages.
* Message: Mailbox Status
* Mailbox: <mailboxid>
* Waiting: <count>
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
* @param string $actionid message matching variable
*/
function MailboxStatus($mailbox, $actionid=NULL) {
$parameters = array('Mailbox'=>$mailbox);
if($actionid) {
$parameters['ActionID'] = $actionid;
}
return $this->send_request('MailboxStatus', $parameters);
}
/**
* MessageSend
*
* Send an SMS message
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MessageSend
* @param string $to
* @param string $from
* @param string $body
* @param string $variable optional
* @return array result of send_request
*/
function MessageSend($to, $from, $body, $variable=null) {
$parameters['To'] = $to;
$parameters['From'] = $from;
$parameters['Base64Body'] = base64_encode($body);
if($variable) {
$parameters['Variable'] = $variable;
}
return $this->send_request('MessageSend', $parameters);
}
/**
* List participants in a conference.
*
* Lists all users in a particular MeetMe conference. MeetmeList will follow as separate events, followed by a final event called MeetmeListComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeList
* @param string $conference Conference number.
*/
function MeetmeList($conference) {
$this->add_event_handler("meetmelist", array($this, 'Meetme_catch'));
$this->add_event_handler("meetmelistcomplete", array($this, 'Meetme_catch'));
$response = $this->send_request('MeetmeList', array('Conference'=>$conference));
if ($response["Response"] == "Success") {
$this->response_catch = array();
$this->wait_response(true);
stream_set_timeout($this->socket, 30);
} else {
return false;
}
return $this->response_catch;
}
/**
* List active conferences.
*
* Lists data about all active conferences. MeetmeListRooms will follow as separate events, followed by a final event called MeetmeListRoomsComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
public function MeetmeListRooms() {
$this->add_event_handler("meetmelistrooms", array($this, 'Meetme_catch'));
$this->add_event_handler("meetmelistroomscomplete", array($this, 'Meetme_catch'));
$response = $this->send_request('MeetmeListRooms');
if ($response["Response"] == "Success") {
$this->response_catch = array();
$this->wait_response(true);
stream_set_timeout($this->socket, 30);
} else {
return false;
}
return $this->response_catch;
}
/**
* Mute a Meetme user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeUnmute
* @param string $meetme Conference number.
* @param string $usernum User Number
*/
public function MeetmeMute($meetme,$usernum) {
return $this->send_request('MeetmeMute', array('Meetme'=>$meetme,'Usernum'=>$usernum));
}
/**
* Unmute a Meetme user.
*
* Unmute a Meetme user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeUnmute
* @param string $meetme Conference number.
* @param string $usernum User Number
*/
public function MeetmeUnmute($meetme,$usernum) {