Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
Changelog:
- Improved animations
- Added an admin page
- Improved security
- Better styling on server pages
- Server pages can now have multiple columns of players
  • Loading branch information
franga2000 committed Aug 3, 2014
1 parent 52d863f commit 446cd7e
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 53 deletions.
5 changes: 4 additions & 1 deletion API/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

$config['servers'][$server]['Offline_reason'] = $reason;

unset($config['password']);
unset($config['columns']);
unset($config['player-columns']);

file_put_contents($back . 'servers.json', indent(json_encode($config)));
//echo '<pre>' . indent(json_encode($config)) . '</pre>';

?>
140 changes: 140 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
$back = '../';
include $back . 'header.php';
include $back . 'password_protect.php';

session_start();
$token = md5(uniqid(mt_rand(), true));
$_SESSION['token'] = $token;
?>
<body style="margin-right: 10px; margin-top: 10px;">
<a href="?logout"><button type="submit" name="logout" class="btn btn-danger pull-right"><span class="glyphicon glyphicon-log-out"></span> Log out</button></a>
<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
<li class="active"><a href="#new-server" data-toggle="tab"><b><span class="glyphicon glyphicon-plus-sign"></span> New server</b></a></li>
<?php
foreach ($config['servers'] as $key => $server) {
echo '<li><a href="#server-' . $key . '" data-toggle="tab"><span class="glyphicon glyphicon-hdd"></span> ' . $server['Name'] . '</a></li>' . "\n";
}
?>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="new-server">

<form role="form" class="col-md-3" method="post" action="manage.php">
<br/>
<div class="form-group">
<label for="name">Server name:</label>
<input type="text" class="form-control" name="name" placeholder="My server" autocomplete="off" required/>
</div>

<div class="form-group">
<label for="adress">Adress:</label>
<input type="text" class="form-control" name="adress" placeholder="mc.example.com" autocomplete="off" required/>
</div>
<div class="form-group">
<label for="port">Port:</label>
<input type="number" class="form-control" name="port" placeholder="25565" autocomplete="off" required/>
</div>

<div class="form-group">
<label for="description">Description:</label>
<input class="form-control" name="description" autocomplete="off"/>
</div>

<input type="hidden" name="token" value="<?php echo $token; ?>" />

<button type="submit" name="action" value="add" class="btn btn-primary"><span class="glyphicon glyphicon-plus-sign"></span> Add Server</button>
</form>
</div>

<?php
foreach ($config['servers'] as $key => $server) {
echo '
<div class="tab-pane" id="server-' . $key . '">
<form role="form" method="post" action="manage.php" class="col-md-5">
<input type="hidden" name="id" value="' . $key . '"/>
<input type="hidden" name="token" value="' . $token . '"/>
<legend>Edit server</legend>
<div class="form-group">
<label for="name">Server name:</label>
<input type="text" class="form-control" name="name" placeholder="My server" value="' . $server['Name'] . '" autocomplete="off" required/>
</div>
<div class="form-group">
<label for="adress">Adress:</label>
<input type="text" class="form-control" name="adress" placeholder="mc.example.com" value="' . $server['Adress'] . '" autocomplete="off" autocomplete="off" required/>
</div>
<div class="form-group">
<label for="port">Port:</label>
<input type="number" class="form-control" name="port" placeholder="25565" value="' . $server['Port'] . '" autocomplete="off" required/>
</div>
<div class="form-group">
<label for="description">Description:</label>
<input class="form-control" name="description" value="' . $server['Description'] . '" autocomplete="off" />
</div>
<div class="form-group">
<label for="offline-reason">Offline reason:</label>
<input class="form-control" name="offline-reason" value="' . $server['Offline_reason'] . '" autocomplete="off" />
</div>
<button type="submit" class="btn btn-primary" name="action" value="edit"><span class="glyphicon glyphicon-save"></span> Save</button>
<button type="submit" class="btn btn-danger pull-right" name="action" value="remove"><span class="glyphicon glyphicon-remove-circle"></span> Remove server</button>
</form>
</div>' . "\n";
}
?>
</div>
</div>
</body>

<style>
.tabs-left > .nav-tabs {
border-bottom: 0;
}

.pill-content > .pill-pane {
display: none;
}

.tab-content > .active,
.pill-content > .active {
display: block;
}

.tabs-left > .nav-tabs > li,
.tabs-right > .nav-tabs > li {
float: none;
}

.tabs-left > .nav-tabs {
float: left;
margin-right: 19px;
border-right: 1px solid #ddd;
}

.tabs-left > .nav-tabs > li > a {
margin-right: -1px;
-webkit-border-radius: 4px 0 0 4px;
-moz-border-radius: 4px 0 0 4px;
border-radius: 4px 0 0 4px;
}

.tabs-left > .nav-tabs > li > a:hover,
.tabs-left > .nav-tabs > li > a:focus {
border-color: #eeeeee #dddddd #eeeeee #eeeeee;
}

.tabs-left > .nav-tabs .active > a,
.tabs-left > .nav-tabs .active > a:hover,
.tabs-left > .nav-tabs .active > a:focus {
border-color: #ddd transparent #ddd #ddd;
*border-right-color: #ffffff;
}
</style>
58 changes: 58 additions & 0 deletions admin/manage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
$back = '../';
include $back . 'password_protect.php';

include $back . 'header.php';

include $back . 'FancyJson.php';

session_start();

if($_POST['token'] != $_SESSION['token'] && php_sapi_name() != 'cli') {
die("Unauthorized source!");
}

$_SESSION['token'] = "";

var_dump($_POST);

switch($_POST['action']) {
case 'add':
array_push($config['servers'], Array(
'Name' => $_POST['name'],
'Adress' => $_POST['adress'],
'Port' => $_POST['port'],
'Description' => $_POST['description'],
'Offline_reason' => ''
));

unset($config['password']);
unset($config['columns']);
unset($config['player-columns']);
file_put_contents($back . 'servers.json', indent(json_encode($config)));
break;

case 'remove':
unset($config['servers'][$_POST['id']]);

file_put_contents($back . 'servers.json', indent(json_encode($config)));
break;

case 'edit':
$config['servers'][$_POST['id']] = Array(
'Name' => $_POST['name'],
'Adress' => $_POST['adress'],
'Port' => $_POST['port'],
'Description' => $_POST['description'],
'Offline_reason' => $_POST['offline-reason']
);

unset($config['password']);
unset($config['columns']);
unset($config['player-columns']);
file_put_contents($back . 'servers.json', indent(json_encode($config)));
break;

}

header('Location: ../') ;
5 changes: 3 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
}

$password = 'CHANGE-THIS' ; //Not implemented yet
$columns = 2 ; //The number of columns on the page
$columns = 2 ; //The number of columns of serverson the main page
$player_columns = 2 ; //The number of columns of playerson the server page

//DO NOT EDIT ANYTHING BELOW THIS LINE!
$config = array_merge(json_decode(file_get_contents($back . 'servers.json'), true), Array("columns" => $columns) , Array("password" => $password));
$config = array_merge(json_decode(file_get_contents($back . 'servers.json'), true), Array("columns" => $columns), Array("player-columns" => $player_columns) , Array("password" => $password));
?>
36 changes: 22 additions & 14 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
<link rel="icon" type="image/x-icon" href="<?php echo $back; ?>favicon.ico" />
<meta charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>

<style>
body {
body:not(.nope) {
font-family:Verdana, Geneva, sans-serif;
}

table {
table:not(.nope) {
margin:10px;
table-layout:fixed;
overflow-x:auto;
}

table, th, td {
//border: 1px solid black;
}

th, td {
th:not(.nope), td:not(.nope) {
text-align:center;
vertical-align:top;
text-align:center;
Expand All @@ -35,24 +36,31 @@
box-shadow: 0 0 5px #DDD inset;
}

a:link {
select:not(.nope) {
border-radius:4px;
border:1px solid #dcdcdc;
font-size:15px;
font-weight:bold;
padding:7px 7px;
}

a:link:not(.nope) {
text-decoration:none;
color:blue;
}

a:visited {
a:visited:not(.nope) {
text-decoration:none;
color:blue;
}

a:hover {
a:hover:not(.nope) {
text-decoration:none;
color:black;
}

a:active {
a:active:not(.nope) {
text-decoration:none;
color:blue;
}

</style>
29 changes: 15 additions & 14 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$back = './';
include $back . 'header.php';
?>
<body>
<body onload="animate();">
<h1>Network status</h1>

<?php
Expand Down Expand Up @@ -38,20 +38,21 @@
}
echo '</tr></table>';
?>
<script>$("tr").fadeOut(0);</script>
<script>
var i = 0; // set your counter to 1

function myLoop () { // create a loop function
setTimeout(function () { // call a 3s setTimeout when the loop is called
$("#td_"+i).fadeIn(500); // your code here
i++; // increment the counter
if (i < 10) { // if the counter < 10, call the loop function
myLoop(); // .. again which will trigger another
} // .. setTimeout()
}, 300)
function animate() {
$("tr").fadeOut(0);

var i = 0;
function myLoop () {
setTimeout(function () {
$("#td_"+i).fadeIn(500);
i++;
if (i < 10) {
myLoop();
}
}, 100)
}
myLoop();
}

myLoop(); // start the loop
</script>
</body>
Loading

0 comments on commit 446cd7e

Please sign in to comment.