-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
506 lines (430 loc) · 21.5 KB
/
index.php
File metadata and controls
506 lines (430 loc) · 21.5 KB
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
<?php
# Start the session
InitSession();
# Load the config file
$mCfg = LoadConfig();
# Authenticating
if(!empty($_POST['authPass']) && !empty($mCfg)) {
if(password_verify($_POST['authPass'], $mCfg['auth']['password'])) {
$_SESSION['Authenticated'] = 1;
}
}
# Updating the configuration
if(isset($_GET['udc']) && !empty($_POST) && isset($_SESSION['Authenticated']) && $_SESSION['Authenticated'] == 1) {
# Initialise the array
$defCfg = array();
# Password change?
if(!empty($_POST['password'])) {
$defCfg['auth']['password'] = password_hash($_POST['password'], PASSWORD_BCRYPT);
}else{
$defCfg['auth']['password'] = $mCfg['auth']['password'];
}
# Server name
if(!empty($_POST['server-name'])) {
$defCfg['server']['name'] = $_POST['server-name'];
}
# Nexmo settings
if(!empty($_POST['nexmo-key']) || !empty($_POST['nexmo-secret'])) {
$defCfg['nexmo']['key'] = $_POST['nexmo-key'];
$defCfg['nexmo']['secret'] = $_POST['nexmo-secret'];
}
# Build the drive array
for($i=0;$i<5;$i++) {
if(!empty($_POST['drive' . ($i+1) . '_name']) && !empty($_POST['drive' . ($i+1) . '_loc']) && isset($_POST['drive' . ($i+1) . '_limit'])) {
$defCfg['disks'][$i]['name'] = $_POST['drive' . ($i+1) . '_name'];
$defCfg['disks'][$i]['location'] = $_POST['drive' . ($i+1) . '_loc'];
$defCfg['disks'][$i]['limit'] = $_POST['drive' . ($i+1) . '_limit'];
}
}
# Build up the contact emails
for($i=0;$i<3;$i++) {
if(!empty($_POST['email' . ($i+1)])) {
$defCfg['contacts']['email_' . ($i+1)] = $_POST['email' . ($i+1)];
}
}
# Memory usage alert percentage
if(isset($_POST['mem_level'])) {
$defCfg['limits']['memory_usage'] = $_POST['mem_level'];
}
# Load alert level
if(isset($_POST['load_level'])) {
$defCfg['limits']['load_alert'] = $_POST['load_level'];
}
# Encode the array into json
$defCfg = json_encode($defCfg);
# Write the new configuration file
file_put_contents(__DIR__ . '/resources/data/config.json', $defCfg);
# Redirect back to refresh
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Silo - Resource Panel</title>
<link type="text/css" rel="stylesheet" href="resources/style/css/bootstrap.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="resources/style/css/font-awesome.min.css" media="screen"/>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
<link type="text/css" rel="stylesheet" href="resources/style/css/montr.css" media="screen"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.pdR {
margin-right:8px;
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcollapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">
<img alt="" class="menuimg" />
<p class="logo_letter">s</p>
</a>
</div>
<div class="collapse navbar-collapse" id="navcollapse">
<ul class="nav navbar-nav" style="margin-left:22px;">
<li class="active"><a href="index.php">Home <span class="sr-only">(current)</span></a></li>
<!--<li><a href="partners.php">Partners</a></li>-->
<li><a href="logfiles.php">Logs</a></li>
</ul>
<?php
if(isset($_SESSION['Authenticated'])) {
echo '<button type="button" style="margin-right:15px; margin-top:10px;" class="btn btn-primary btn-sm navbar-right" data-toggle="modal" data-target="#myModal">Configuration</button>';
}else{
echo '<form method="post" class="navbar-form navbar-right" role="search">';
echo '<div class="form-group"><input type="password" id="authPass" name="authPass" class="form-control" placeholder="Enter password.."></div>';
echo '<button type="submit" style="margin-left:5px;" class="btn btn-default">Auth</button></form>';
}
?>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
<p align="center" class="title">silo</p>
<div class="fill-in">
</div>
</div>
</div>
</div>
<br />
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="resources/style/js/bootstrap.min.js"></script>
<script>
// Initially load the table
$(document).ready(function () {
$('.fill-in').load('resources/load.php').stop().fadeIn();
});
// Reload the table every 5 seconds
setInterval(function(){
$('.fill-in').load('resources/load.php').stop().fadeIn();
}, 5000);
</script>
</body>
</html>
<?php
if(isset($_SESSION['Authenticated']) && $_SESSION['Authenticated'] == 1) {
?>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Configuration Editor</h4>
</div>
<div class="modal-body">
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#drives" aria-controls="drives" role="tab" data-toggle="tab">Drives</a></li>
<li role="presentation"><a href="#contacts" aria-controls="contacts" role="tab" data-toggle="tab">Contacts</a></li>
<li role="presentation"><a href="#limits" aria-controls="limits" role="tab" data-toggle="tab">Limits</a></li>
<li role="presentation"><a href="#password" aria-controls="settings" role="tab" data-toggle="tab">Password</a></li>
<li role="presentation"><a href="#site" aria-controls="site" role="tab" data-toggle="tab">Site</a></li>
<li role="presentation"><a href="#about" aria-controls="about" role="tab" data-toggle="tab">About</a></li>
</ul>
<!-- Form -->
<form class="form-inline" action="?udc" id="cfgUp" name="cfgUp" method="post">
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="drives">
<h4>Drive Information</h4>
<p>Enter the details of all the drives you would like to monitor here, make sure they are valid before submitting.
If you would not like to set an alarm limit, set it to "0".</p>
<hr>
<?php
############# DRIVE ONE
echo '<h5>Drive 1</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Drive Name</label>';
# Check if we have a name
if(!empty($mCfg['disks'][0]['name'])) {
echo '<input type="text" class="form-control pdR" id="drive1_name" name="drive1_name" placeholder="Name" value="' . $mCfg['disks'][0]['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive1_name" name="drive1_name" placeholder="Name">';
}
echo '<label class="sr-only" for="drive2">Drive Path</label>';
# Check if we have a location
if(!empty($mCfg['disks'][0]['location'])) {
echo '<input type="text" class="form-control pdR" id="drive1_loc" name="drive1_loc" placeholder="Path" value="' . $mCfg['disks'][0]['location'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive1_loc" name="drive1_loc" placeholder="Path">';
}
echo '<label class="sr-only" for="drive3">Alert Limit</label>';
# Check if we have a limit
if(isset($mCfg['disks'][0]['limit'])) {
echo '<input type="text" size="10" class="form-control" id="drive1_limit" name="drive1_limit" placeholder="Limit" value="' . $mCfg['disks'][0]['limit'] . '">';
}else{
echo '<input type="text" size="10" class="form-control" id="drive1_limit" name="drive1_limit" placeholder="Limit">';
}
echo '</div>';
############# DRIVE TWO
echo '<br /><h5>Drive 2</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Drive Name</label>';
# Check if we have a name
if(!empty($mCfg['disks'][1]['name'])) {
echo '<input type="text" class="form-control pdR" id="drive2_name" name="drive2_name" placeholder="Name" value="' . $mCfg['disks'][1]['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive2_name" name="drive2_name" placeholder="Name">';
}
echo '<label class="sr-only" for="drive2">Drive Path</label>';
# Check if we have a location
if(!empty($mCfg['disks'][1]['location'])) {
echo '<input type="text" class="form-control pdR" id="drive2_loc" name="drive2_loc" placeholder="Path" value="' . $mCfg['disks'][1]['location'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive2_loc" name="drive2_loc" placeholder="Path">';
}
echo '<label class="sr-only" for="drive3">Alert Limit</label>';
# Check if we have a limit
if(isset($mCfg['disks'][1]['limit'])) {
echo '<input type="text" size="10" class="form-control" id="drive2_limit" name="drive2_limit" placeholder="Limit" value="' . $mCfg['disks'][1]['limit'] . '">';
}else{
echo '<input type="text" size="10" class="form-control" id="drive2_limit" name="drive2_limit" placeholder="Limit">';
}
echo '</div>';
############# DRIVE THREE
echo '<br /><h5>Drive 3</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Drive Name</label>';
# Check if we have a name
if(!empty($mCfg['disks'][2]['name'])) {
echo '<input type="text" class="form-control pdR" id="drive3_name" name="drive3_name" placeholder="Name" value="' . $mCfg['disks'][2]['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive3_name" name="drive3_name" placeholder="Name">';
}
echo '<label class="sr-only" for="drive2">Drive Path</label>';
# Check if we have a location
if(!empty($mCfg['disks'][2]['location'])) {
echo '<input type="text" class="form-control pdR" id="drive3_loc" name="drive3_loc" placeholder="Path" value="' . $mCfg['disks'][2]['location'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive3_loc" name="drive3_loc" placeholder="Path">';
}
echo '<label class="sr-only" for="drive3">Alert Limit</label>';
# Check if we have a limit
if(isset($mCfg['disks'][2]['limit'])) {
echo '<input type="text" size="10" class="form-control" id="drive3_limit" name="drive3_limit" placeholder="Limit" value="' . $mCfg['disks'][2]['limit'] . '">';
}else{
echo '<input type="text" size="10" class="form-control" id="drive3_limit" name="drive3_limit" placeholder="Limit">';
}
echo '</div>';
############# DRIVE FOUR
echo '<br /><h5>Drive 4</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Drive Name</label>';
# Check if we have a name
if(!empty($mCfg['disks'][3]['name'])) {
echo '<input type="text" class="form-control pdR" id="drive4_name" name="drive4_name" placeholder="Name" value="' . $mCfg['disks'][3]['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive4_name" name="drive4_name" placeholder="Name">';
}
echo '<label class="sr-only" for="drive2">Drive Path</label>';
# Check if we have a location
if(!empty($mCfg['disks'][3]['location'])) {
echo '<input type="text" class="form-control pdR" id="drive4_loc" name="drive4_loc" placeholder="Path" value="' . $mCfg['disks'][3]['location'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive4_loc" name="drive4_loc" placeholder="Path">';
}
echo '<label class="sr-only" for="drive3">Alert Limit</label>';
# Check if we have a limit
if(isset($mCfg['disks'][3]['limit'])) {
echo '<input type="text" size="10" class="form-control" id="drive4_limit" name="drive4_limit" placeholder="Limit" value="' . $mCfg['disks'][3]['limit'] . '">';
}else{
echo '<input type="text" size="10" class="form-control" id="drive4_limit" name="drive4_limit" placeholder="Limit">';
}
echo '</div>';
############# DRIVE FIVE
echo '<br /><h5>Drive 5</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Drive Name</label>';
# Check if we have a name
if(!empty($mCfg['disks'][4]['name'])) {
echo '<input type="text" class="form-control pdR" id="drive5_name" name="drive5_name" placeholder="Name" value="' . $mCfg['disks'][4]['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive5_name" name="drive5_name" placeholder="Name">';
}
echo '<label class="sr-only" for="drive2">Drive Path</label>';
# Check if we have a location
if(!empty($mCfg['disks'][4]['location'])) {
echo '<input type="text" class="form-control pdR" id="drive5_loc" name="drive5_loc" placeholder="Path" value="' . $mCfg['disks'][4]['location'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="drive5_loc" name="drive5_loc" placeholder="Path">';
}
echo '<label class="sr-only" for="drive3">Alert Limit</label>';
# Check if we have a limit
if(isset($mCfg['disks'][4]['limit'])) {
echo '<input type="text" size="10" class="form-control" id="drive5_limit" name="drive5_limit" placeholder="Limit" value="' . $mCfg['disks'][4]['limit'] . '">';
}else{
echo '<input type="text" size="10" class="form-control" id="drive5_limit" name="drive5_limit" placeholder="Limit">';
}
echo '</div>';
?>
</div>
<div role="tabpanel" class="tab-pane" id="contacts">
<h4>Contact Information</h4>
<p>Enter the information for the people who would need to be contacted when alert limits are hit. They will be alerted for drive, memory and load limits.</p>
<hr>
<?php
############# CONTACT ONE
echo '<h5>Contact 1</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Contact Email</label>';
# Check if we have an email
if(!empty($mCfg['contacts']['email_1'])) {
echo '<input type="email" class="form-control pdR" id="email1" name="email1" placeholder="Email" value="' . $mCfg['contacts']['email_1'] . '">';
}else{
echo '<input type="email" class="form-control pdR" id="email1" name="email1" placeholder="Email">';
}
echo '</div>';
############# CONTACT TWO
echo '<br /><h5>Contact 2</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Contact Email</label>';
# Check if we have an email
if(!empty($mCfg['contacts']['email_2'])) {
echo '<input type="email" class="form-control pdR" id="email2" name="email2" placeholder="Email" value="' . $mCfg['contacts']['email_2'] . '">';
}else{
echo '<input type="email" class="form-control pdR" id="email2" name="email2" placeholder="Email">';
}
echo '</div>';
############# CONTACT THREE
echo '<br /><h5>Contact 3</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Contact Email</label>';
# Check if we have an email
if(!empty($mCfg['contacts']['email_3'])) {
echo '<input type="email" class="form-control pdR" id="email3" name="email3" placeholder="Email" value="' . $mCfg['contacts']['email_3'] . '">';
}else{
echo '<input type="email" class="form-control pdR" id="email3" name="email3" placeholder="Email">';
}
echo '</div>';
?>
</div>
<div role="tabpanel" class="tab-pane" id="limits">
<h4>Limit Alerts</h4>
<p>Set the limits for memory usage and the load level. The load level which it will alarm on is the 5 minute average.</p>
<hr>
<?php
############# ALERT LIMITS
echo '<h5>Memory and load Limits</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="drive1">Memory percentage alert level</label>';
# Check if we have an email
if(isset($mCfg['limits']['memory_usage'])) {
echo '<input type="number" min="0" max="100" class="form-control pdR" id="mem_level" name="mem_level" placeholder="Memory usage percentage" value="' . $mCfg['limits']['memory_usage'] . '">';
}else{
echo '<input type="number" min="0" max="100" class="form-control pdR" id="mem_level" name="mem_level" placeholder="Memory usage percentage">';
}
echo '<label class="sr-only" for="drive2">Load alert level</label>';
# Check if we have a phone #
if(isset($mCfg['limits']['load_alert'])) {
echo '<input type="number" class="form-control" id="load_level" name="load_level" placeholder="Load max level" value="' . $mCfg['limits']['load_alert'] . '">';
}else{
echo '<input type="number" class="form-control" id="load_level" name="load_level" placeholder="Load max level">';
}
echo '</div>';
?>
</div>
<div role="tabpanel" class="tab-pane" id="password">
<h4>Update Password</h4>
<p>You can update your password here. This should be done on the first install to replace the default. If you would not like to change it, leave it blank.</p>
<hr>
<?php
echo '<h5>Password</h5>';
echo '<input type="password" size="64" class="form-control" id="password" name="password" placeholder="Leave blank for no change">';
?>
</div>
<div role="tabpanel" class="tab-pane" id="site">
<h4>Site Settings</h4>
<p>You can update site-wide settings here, such as the server name and API key. The API key is based on the server name and password to access your resource panel, updating these will change your key.</p>
<hr>
<?php
echo '<h5>Server Name</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="server-name">Server Name</label>';
# Check if we have an email
if(!empty($mCfg['server']['name'])) {
echo '<input type="text" class="form-control pdR" id="server-name" name="server-name" placeholder="Server name" value="' . $mCfg['server']['name'] . '">';
}else{
echo '<input type="text" class="form-control pdR" id="server-name" name="server-name" placeholder="Server name">';
}
echo '</div>';
echo '<h5>API Key</h5>';
echo '<div class="form-group">';
echo '<label class="sr-only" for="api-key">API Key</label>';
echo '<input type="text" class="form-control pdR" id="api-key" name="api-key" value="' . sha1($mCfg['server']['name'] . $mCfg['auth']['password']) . '" readonly>';
echo '</div>';
?>
</div>
<div role="tabpanel" class="tab-pane" id="about">
<h4>About Silo</h4>
<p>Welcome! Silo is a simple resource panel for servers. It can monitor drive, memory and load usage.</p>
<p>Silo can send email alerts to specified contacts when
the alarm thresholds are hit. </p>
<p>If you have any ideas for improvement or general feedback, you can email me at <a href="mailto:[email protected]">[email protected]</a></p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
# Function to load the configuration file into an array
function LoadConfig() {
if(file_exists(__DIR__ . '/resources/data/config.json')) {
$cfgCont = file_get_contents(__DIR__ . '/resources/data/config.json');
$cfgCont = json_decode($cfgCont, true);
return $cfgCont;
}
}
# Custom session function
function InitSession($timeout = 3600) {
ini_set('session.gc_maxlifetime', $timeout);
session_start();
if(isset($_SESSION['timeout_idle']) && $_SESSION['timeout_idle'] < time()) {
session_destroy();
session_start();
session_regenerate_id();
$_SESSION = array();
}
$_SESSION['timeout_idle'] = time() + $timeout;
}
?>