-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAsteriskdashcli.class.php
97 lines (90 loc) · 2.66 KB
/
Asteriskdashcli.class.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
<?php
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2013 Schmooze Com Inc.
namespace FreePBX\modules;
#[\AllowDynamicProperties]
class Asteriskdashcli implements \BMO {
public function __construct($freepbx = null) {
if ($freepbx == null) {
throw new Exception("Not given a FreePBX Object");
}
$this->FreePBX = $freepbx;
$this->AstMan = $freepbx->astman;
}
public function install() {
}
public function uninstall() {
}
public function backup() {
}
public function restore($backup) {
}
public function doConfigPageInit($page) {
}
public function ajaxRequest($req, &$setting) {
$return_data = false;
$return_data = match ($req) {
"clicmd", "getCliCommands" => true,
default => $return_data,
};
return $return_data;
}
public function ajaxHandler() {
switch ($_REQUEST['command']) {
case "clicmd":
$res = $this->cli_runcommand($_REQUEST['data']);
return json_encode($res, JSON_THROW_ON_ERROR);
break;
case "getCliCommands":
$res = $this->cli_getcommands(true);
return [ 'status' => true, 'cliCommands' => $res ];
break;
}
}
/**
* This function is a modified version of what was in the original asterisk-cli module
* With Copyright (C) 2005, Xorcom
* Written by Diego Iastrubni <[email protected]>
* Copyright (C) 2005, Xorcom
* This function was derived from ASTLinux 0.3
* The original author of AST linux is:
* Kristian Kielhofner - KrisCompanies, LLC - http://astlinux.org/
*/
public function cli_runcommand($txtCommand) {
if ($this->AstMan) {
$response = $this->AstMan->send_request('Command', [ 'Command' => "$txtCommand" ]);
if (!empty($response['data'])) {
$response = explode("\n", (string) $response['data']);
unset($response[0]); //remove the Priviledge Command line
$response = implode("\n", $response);
$html_out = htmlspecialchars($response);
return $html_out;
}
else {
return _("No Output Returned");
}
}
}
public function cli_getcommands($info = false) {
$return_data = [];
if ($this->AstMan) {
$response = $this->AstMan->send_request('Command', [ 'Command' => "core show help" ]);
if (!empty($response['data'])) {
$response = explode("\n", (string) $response['data']);
unset($response[0]); //remove the Priviledge Command line
foreach ($response as $line) {
if (strlen((trim($line))) == 0) {
continue;
}
$help_cmd = $cmd = explode("--", $line);
$add_cmd = [ 'cmd' => trim($help_cmd[0]) ];
if ($info) {
$add_cmd['info'] = trim(trim($help_cmd[1]));
}
$return_data[] = $add_cmd;
}
}
}
return $return_data;
}
}