-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
218 lines (189 loc) · 7.38 KB
/
admin.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
<?php
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/header.php";
require_once "resources/paging.php";
require_once __DIR__."/vendor/autoload.php";
if(!if_group('superadmin')) {
echo "access denied";
require "footer.php";
die();
}
$desiredWebhookURL = "https://".$_SESSION['domain_name']."/app/webtexting/inbound-hook.php?provider=accelerate-networks";
$database = new database;
switch($_POST['fix']) {
case "inbound_webhook_url":
AccelerateNetworks::RegisterInboundRouting($_POST['number'], $desiredWebhookURL);
message::add("added SMS destination for ".$_POST['number']);
break;
case "sms_enable":
$sql = "UPDATE webtexting_destinations SET phone_number = :phone_number WHERE extension_uuid = :extension_uuid AND domain_uuid = :domain_uuid RETURNING *";
$parameters['phone_number'] = $_POST['phone_number'];
$parameters['extension_uuid'] = $_POST['extension_uuid'];
$parameters['domain_uuid'] = $domain_uuid;
if($database->select($sql, $parameters, 'row')) {
message::add("updated SMS for extension with number ".$_POST['phone_number']);
} else {
$sql = "INSERT INTO webtexting_destinations (phone_number, extension_uuid, domain_uuid) VALUES (:phone_number, :extension_uuid, :domain_uuid)";
if($database->execute($sql, $parameters)) {
message::add("enabled SMS for extension with number ".$_POST['phone_number']);
} else {
message::add("error updating SMS destination chatplan detail data ".$_POST['phone_number'], 'negative');
}
}
unset($parameters);
break;
case "sms_disable":
$sql = "DELETE FROM webtexting_destinations WHERE extension_uuid = :extension_uuid AND domain_uuid = :domain_uuid";
$parameters['extension_uuid'] = $_POST['extension_uuid'];
$parameters['domain_uuid'] = $domain_uuid;
if($database->execute($sql, $parameters)) {
message::add("disabled SMS for extension");
} else {
message::add("error disabling SMS", 'negative');
}
unset($parameters);
break;
default:
if($_POST['fix']) {
message::add("unknown fix: ".$_POST['fix'], 'negative');
}
break;
}
?>
<style type="text/css">
.error {
background-color: #fcc;
}
.success {
background-color: #cfc;
}
</style>
<?php
function fixbutton(array $params, $label="update") {
$out = "<form method='post'>";
foreach($params as $k=>$v) {
$opts = $v;
if (is_string($v)) {
$opts = [
"type" => "hidden",
"value" => $v,
];
}
$u = uuid();
if($opts['type'] != "hidden") {
$out .= "<label for='".$u."'>".$k.": ";
}
$out .= "<input type='".$opts['type']."' name='".$k."' value='".$opts['value']."' id='".$u."' />";
if($opts['type'] != "hidden") {
$out .= "</label><br />";
}
}
if($label == 'update'){
if($params['fix']){
if($params['fix'] == 'inbound_webhook_url'){
$params['fix'] = 'register_' . $params['fix'];
}
$label = explode('_',$params['fix']);
if($params['fix'] == 'register_inbound_webhook_url'){
$label[3] ='';
}
$label = implode(' ', $label);
}
}
$out .= "<input type='submit' class='btn' value='".$label."' />";
$out .= "</form>";
return $out;
}
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>WebTexting Administration</b></div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
$sql = "SELECT * FROM v_extensions WHERE domain_uuid = :domain_uuid";
$parameters['domain_uuid'] = $domain_uuid;
$extensions = $database->select($sql, $parameters, 'all');
unset($parameters);
$sql = "SELECT extension_uuid, phone_number FROM webtexting_destinations WHERE domain_uuid = :domain_uuid";
$parameters['domain_uuid'] = $domain_uuid;
foreach($database->select($sql, $parameters, 'all') as $d) {
$smsenabled_extensions[$d['extension_uuid']] = $d;
}
unset($parameters);
echo "<table class='table'>\n";
echo "<tr>";
echo "<th>Extension</th>";
echo "<th>SMS-enabled</th>";
echo "<th>Inbound Routing</th>";
echo "</tr>";
foreach($extensions as $extension) {
echo "<tr>";
echo "<td>".$extension['extension']."</td>";
$sms_number = $extension['outbound_caller_id_number'];
if($smsenabled_extensions[$extension['extension_uuid']]) {
$sms_number = $smsenabled_extensions[$extension['extension_uuid']]['phone_number'];
echo "<td class='success'>";
} else {
echo "<td>";
}
echo fixbutton(
[
'fix' => 'sms_enable',
'extension_uuid' => $extension['extension_uuid'],
'phone_number' => [
'type' => 'text',
'value' => $sms_number,
],
]
);
if($smsenabled_extensions[$extension['extension_uuid']]) {
echo "<br />";
echo fixbutton(['fix' => 'sms_disable', 'extension_uuid' => $extension['extension_uuid']], "disable SMS");
}
echo "</td>";
if($smsenabled_extensions[$extension['extension_uuid']]) {
$problems = array();
try {
if($sms_number[0]=='+'){
$sms_number= substr($sms_number,1);
}
if(strlen($sms_number)!=11){
$problems[] = "Desired number has incorrect number of digits. Expected 11 digits but ". $sms_number. " isn't 11 digits";
}
else{
$inboundRouting = AccelerateNetworks::GetInboundSMSRouting($sms_number);
}
if($inboundRouting->callbackUrl != $desiredWebhookURL) {
$problems[] = "webhook URL is wrong: <code>".$inboundRouting->callbackUrl."</code> should be <code>".$desiredWebhookURL."</code>";
}
if($inboundRouting->clientSecret != $_SESSION['webtexting']['acceleratenetworks_inbound_token']['text']){
$problems[] = "client secret incorrect. FusionPBX Client Secret: ". $inboundRouting->clientSecret . " FusionPBX Session Secret: ".$_SESSION['webtexting']['acceleratenetworks_inbound_token']['text'];
}
if ($inboundRouting->asDialed != $sms_number) {
$problems[] = "number formatting disagreement. theirs: ".$inboundRouting->asDialed." ours: ".$sms_number;
}
if (!$inboundRouting->registeredUpstream) {
$problems[] = "not routed by upstream carrier: ".$inboundRouting->upstreamStatusDescription;
}
} catch(GuzzleHttp\Exception\ClientException $e) {
$problems[] = GuzzleHttp\Psr7\Message::toString($e->getResponse());
}
if(count($problems) > 0) {
echo "<td class='error'><ul>";
foreach($problems as $problem) {
echo "<li>".$problem."</li>";
}
echo "</ul>";
} else {
echo "<td class='success'>configured<br />";
}
echo fixbutton(['fix' => 'inbound_webhook_url', 'number' => $sms_number]);
echo "</td>";
} else {
echo "<td>not routed</td>";
}
unset($sms_number);
echo "</tr>";
}
echo "</table>";
require "footer.php";