Added a nice table for displaying currently available servers
This commit is contained in:
parent
25b68c4bc6
commit
b41b246483
@ -6,6 +6,10 @@ class Server {
|
|||||||
|
|
||||||
// server root directory
|
// server root directory
|
||||||
private string $rootDir;
|
private string $rootDir;
|
||||||
|
// server name
|
||||||
|
private string $serverName;
|
||||||
|
// server Minecraft version
|
||||||
|
private string $serverVersion;
|
||||||
// PID file path
|
// PID file path
|
||||||
private string $pidFilePath;
|
private string $pidFilePath;
|
||||||
// server run status
|
// server run status
|
||||||
@ -13,9 +17,17 @@ class Server {
|
|||||||
|
|
||||||
// class constructor
|
// class constructor
|
||||||
public function __construct($dir) {
|
public function __construct($dir) {
|
||||||
|
$dirBits = explode('/', $dir);
|
||||||
$this->rootDir = $dir;
|
$this->rootDir = $dir;
|
||||||
|
$this->serverName = $dirBits[count($dirBits) - 1];
|
||||||
$this->pidFilePath = $dir . '/pid.txt';
|
$this->pidFilePath = $dir . '/pid.txt';
|
||||||
|
|
||||||
|
// get server version
|
||||||
|
$versionFile = join('/', array($this->rootDir, 'current_version.txt'));
|
||||||
|
if (file_exists($versionFile)) {
|
||||||
|
$this->serverVersion = file($versionFile)[0];
|
||||||
|
}
|
||||||
|
|
||||||
// search for server state
|
// search for server state
|
||||||
if (file_exists($this->pidFilePath)) {
|
if (file_exists($this->pidFilePath)) {
|
||||||
$this->state = true;
|
$this->state = true;
|
||||||
@ -38,6 +50,12 @@ class Server {
|
|||||||
public function getDirectory(): string {
|
public function getDirectory(): string {
|
||||||
return $this->rootDir;
|
return $this->rootDir;
|
||||||
}
|
}
|
||||||
|
public function getName(): string {
|
||||||
|
return $this->serverName;
|
||||||
|
}
|
||||||
|
public function getVersion(): string {
|
||||||
|
return $this->serverVersion;
|
||||||
|
}
|
||||||
public function getState(): bool {
|
public function getState(): bool {
|
||||||
return $this->state;
|
return $this->state;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,15 @@ $app->post('/create', function (Request $request, Response $response, $args) {
|
|||||||
fclose($scriptFile);
|
fclose($scriptFile);
|
||||||
chmod($scriptFilePath, 0755);
|
chmod($scriptFilePath, 0755);
|
||||||
|
|
||||||
|
// save the current version to a text file - this will hopefully be temporary solution
|
||||||
|
$versionFilePath = join('/', array($serverDir, 'current_version.txt'));
|
||||||
|
$versionFile = fopen($versionFilePath, 'w');
|
||||||
|
$versionContent = $params['serverVersion'];
|
||||||
|
fwrite($versionFile, $versionContent);
|
||||||
|
fclose($versionFile);
|
||||||
|
chmod($versionFilePath, 0644);
|
||||||
|
|
||||||
|
// redirect the user back to the home page
|
||||||
return $response
|
return $response
|
||||||
->withHeader('Location', '/')
|
->withHeader('Location', '/')
|
||||||
->withStatus(302);
|
->withStatus(302);
|
||||||
|
@ -14,10 +14,33 @@
|
|||||||
<section class="row">
|
<section class="row">
|
||||||
<div class="columns twelve">
|
<div class="columns twelve">
|
||||||
<h3>List of servers:</h3>
|
<h3>List of servers:</h3>
|
||||||
<span><p>There are currently no servers registered.</p></span>
|
{% if servers|length < 1 %}
|
||||||
{% for m in servers %}
|
<p>There are currently no servers registered.</p>
|
||||||
<p>Server directory: {{ m.getDirectory() }}</p>
|
{% else %}
|
||||||
{% endfor %}
|
<table class="u-full-width">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Server name</th>
|
||||||
|
<th>Minecraft version</th>
|
||||||
|
<th>State</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
{% for m in servers %}
|
||||||
|
<td>{{ m.getName() }}</td>
|
||||||
|
<td>{{ m.getVersion() }}</td>
|
||||||
|
<td>{{ m.getState() ? 'Running' : 'Stopped' }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="/server/{{ m.getName() }}/start">Start</a>
|
||||||
|
<a href="/server/{{ m.getName() }}/stop">Stop</a>
|
||||||
|
</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user