-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
90 lines (77 loc) · 3 KB
/
import.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
<?php
/*
GNU Public License
Version: GPL 3
*/
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";
if(!if_group('superadmin')) {
echo "permission denied";
require "footer.php";
die();
}
if($_POST['action'] == "import") {
$sql = "SELECT * FROM v_devices WHERE domain_uuid = :domain_uuid AND device_uuid = :device_uuid";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['device_uuid'] = $_POST['device_uuid'];
$database = new database;
$device = $database->select($sql, $parameters, 'row');
unset($parameters);
if(!$device) {
echo "cannot find device";
require "footer.php";
die();
}
$token = generate_password(20, 3);
$sql = "INSERT INTO grandstream_devices (device_uuid, domain_uuid, token, model, firmware_version) VALUES (:device_uuid, :domain_uuid, :token, :model, :firmware_version)";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['device_uuid'] = $device['device_uuid'];
$parameters['token'] = $token;
$parameters['model'] = null;
$parameters['firmware_version'] = null;
if (preg_match('/Grandstream Model HW (?P<hw>\w+) SW (?P<sw>[\d+\.]+) DevId (?P<mac>\w\w\w\w\w\w\w\w\w\w\w\w)/', $device['device_provisioned_agent'], $ua)) {
$parameters['model'] = $ua['hw'];
$parameters['firmware_version'] = $ua['sw'];
}
$database->execute($sql, $parameters);
unset($parameters);
}
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>Grandstream Device Management</b><br />import devices from FusionPBX provisioning</div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>"back",'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'index.php']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<table class='table'>";
echo "<tr>";
echo "<th>mac</th>";
echo "<th>label</th>";
echo "<th>description</th>";
echo "<th>UA</th>";
echo "<th>actions</th>";
echo "</tr>";
$sql = "SELECT * FROM v_devices WHERE domain_uuid = :domain_uuid AND device_vendor = 'grandstream' AND device_uuid NOT IN (SELECT device_uuid FROM grandstream_devices WHERE domain_uuid = :domain_uuid)";
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$devices = $database->select($sql, $parameters, 'all');
unset($parameters);
foreach($devices as $device) {
echo "<tr>";
echo "<td>".$device['device_mac_address']."</td>";
echo "<td>".$device['device_label']."</td>";
echo "<td>".$device['device_description']."</td>";
echo "<td>".$device['device_provisioned_agent']."</td>";
echo "<td><form method='post'>";
echo "<input type='hidden' name='action' value='import' />";
echo "<input type='hidden' name='device_uuid' value='".$device['device_uuid']."' />";
echo button::create(['type'=>'submit','label'=>"Import",'id'=>'btn_import','name'=>'btn_import']);
echo "</form>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
require "footer.php";