-
Notifications
You must be signed in to change notification settings - Fork 59
/
dashboard.php
261 lines (244 loc) · 7.38 KB
/
dashboard.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
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
<?php
require_once 'inc/lib.php';
session_start();
if (!empty($_SESSION['user'])) {
if (!$user = user_info($_SESSION['user'])) {
// User does not exist, redirect to login page
header('Location: .');
exit('Not Authorized');
}
} elseif (!empty($_POST['user']) && !empty($_POST['pass'])) {
// Get user data
$user = user_info($_POST['user']);
$_SESSION['is_admin'] = $user['role'] == 'admin';
// Check user exists and password is good
if (!$user || !bcrypt_verify($_POST['pass'], $user['pass'])) {
// Login failure, redirect to login page
header('Location: ./?error=badlogin');
exit('Not Authorized');
}
// Current user is valid
$_SESSION['user'] = $user['user'];
} else {
// Not logged in, redirect to login page
header('Location: .');
exit('Not Authorized');
}
?><!doctype html>
<html>
<head>
<title>Dashboard | MCHostPanel</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/smooth.css" id="smooth-css">
<link rel="stylesheet" href="css/style.css">
<meta name="author" content="Alan Hardman <[email protected]>">
<style type="text/css">
#cmd {
height: 30px;
}
form {
margin: 0;
}
</style>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function updateStatus(once) {
$.post('ajax.php', {
req: 'server_running'
}, function (data) {
if (data) {
$('#lbl-status').text('Running').addClass('label-success').removeClass('label-important');
$('#btn-srv-start').prop('disabled', true);
$('#btn-srv-stop,#btn-srv-restart').prop('disabled', false);
$('#cmd').prop('disabled', false);
} else {
$('#lbl-status').text('Stopped').addClass('label-important').removeClass('label-success');
$('#btn-srv-start').prop('disabled', false);
$('#btn-srv-stop,#btn-srv-restart').prop('disabled', true);
$('#cmd').prop('disabled', true);
}
}, 'json');
if (!once)
window.setTimeout(updateStatus, 5000);
}
function updatePlayers() {
$.post('ajax.php', {
req: 'players'
}, function (data) {
if (data.error) {
$('#lbl-players').text('Unknown').attr('title', 'Enable Query in server.properties to see player information').tooltip();
} else {
try{
console.log(data);
} catch(ex) {}
if(data.players === false) {
$('#lbl-players').text(0 + '/' + data.info.MaxPlayers);
} else {
$('#lbl-players').text(data.players.length + '/' + data.info.MaxPlayers);
$('#lbl-players').append('<br/><br/>');
$('#lbl-players').append('<legend>Player List</legend>');
}
$.each(data.players, function (i, val) {
console.log(val);
$('#lbl-players').append('<img src="inc/getFace.php?username=' + val + '&size=24"> ' + val + '<br>');
});
}
}, 'json').error(function(){
$('#lbl-players').text('Error');
});
}
function server_start() {
$.post('ajax.php', {
req: 'server_start'
}, function () {
updateStatus(true);
});
}
function server_stop(callback) {
$.post('ajax.php', {
req: 'server_stop'
}, function () {
updateStatus(true);
if (callback)
callback();
});
}
function set_jar() {
$.post('ajax.php', {
req: 'set_jar',
jar: $('#server-jar').val()
});
}
function refreshLog() {
updateStatus();
$.post('ajax.php', {
req: 'server_log'
}, function (data) {
if ($('#log').scrollTop() == $('#log')[0].scrollHeight) {
$('#log').html(data).scrollTop($('#log')[0].scrollHeight);
} else {
$('#log').html(data);
}
window.setTimeout(refreshLog, 3000);
});
}
function refreshLogOnce() {
$.post('ajax.php', {
req: 'server_log'
}, function (data) {
$('#log').html(data).scrollTop($('#log')[0].scrollHeight);
});
}
$(document).ready(function () {
updateStatus();
updatePlayers();
$('button.ht').tooltip();
$('#btn-srv-start').click(function () {
server_start();
$(this).prop('disabled', true).tooltip('hide');
});
$('#btn-srv-stop').click(function () {
server_stop();
$(this).prop('disabled', true).tooltip('hide');
});
$('#btn-srv-restart').click(function () {
server_stop(server_start);
$('').prop('disabled', true).tooltip('hide');
});
// Send commands with form onSubmit
$('#frm-cmd').submit(function () {
$.post('ajax.php', {
req: 'server_cmd',
cmd: $('#cmd').val()
}, function () {
$('#cmd').val('').prop('disabled', false).focus();
refreshLogOnce();
});
$('#cmd').prop('disabled', true);
return false;
});
// Handle JAR change
$('#server-jar').change(set_jar);
// Fix sizing
$('#log').css('height', $(window).height() - 200 + 'px');
// Initialize log
$.post('ajax.php', {
req: 'server_log'
}, function (data) {
$('#log').html(data).scrollTop($('#log')[0].scrollHeight);
window.setTimeout(refreshLog, 3000);
});
// Keep sizing correct
$(document).resize(function () {
$('#log').css('height', $(window).height() - 200 + 'px');
});
});
</script>
</head>
<body>
<?php require 'inc/top.php'; ?>
<div class="tab-content">
<div class="tab-pane active">
<?php if (!empty($user['ram'])) { ?>
<div class="row-fluid">
<div class="span5">
<div class="well">
<legend>Server Controls</legend>
<div class="btn-toolbar">
<div class="btn-group">
<button class="btn btn-large btn-primary ht" id="btn-srv-start" title="Start" disabled><i class="icon-play"></i></button>
<button class="btn btn-large btn-danger ht" id="btn-srv-stop" title="Stop" disabled><i class="icon-stop"></i></button>
</div>
<div class="btn-group">
<button class="btn btn-large btn-warning ht" id="btn-srv-restart" title="Restart" disabled><i class="icon-refresh"></i></button>
</div>
</div>
<br>
<p>Server JAR</p>
<select id="server-jar">
<?php
$jars = scandir($user['home']);
foreach($jars as $file) {
if(substr($file, -4) == '.jar') {
if((!empty($user['jar']) && $user['jar'] == $file) || (empty($user['jar']) && $file == 'craftbukkit.jar')) {
echo "<option value=\"$file\" selected>$file</option>";
} else {
echo "<option value=\"$file\">$file</option>";
}
}
}
?>
</select>
</div>
<div class="well">
<legend>Server Information</legend>
<p><b>Server Status:</b> <span class="label" id="lbl-status">Checking…</span><br>
<b>IP:</b> <?php echo KT_LOCAL_IP . ':' . $user['port']; ?><br>
<b>RAM:</b> <?php echo $user['ram'] . 'MB'; ?><br>
<b>Players:</b> <span id="lbl-players">Checking…</span>
</p>
<div class="player-list"></div>
</div>
<footer class="muted">© <?php echo date('Y'); ?> Alan Hardman</footer>
</div>
<div class="span7">
<pre id="log" class="well well-small"></pre>
<form id="frm-cmd">
<input type="text" id="cmd" name="cmd" maxlength="250" placeholder="Enter a command" autofocus>
</form>
</div>
</div>
<?php
} else
echo '
<p class="alert alert-info">Your account does not have a server.</p>
<footer class="muted">© ' . date('Y') . ' Alan Hardman</footer>
';
?>
</div>
</div>
</body>
</html>