aboutsummaryrefslogtreecommitdiffstats
path: root/bin/manage.php
blob: c4858ca239001c5dae4bff8a5d0be8c4e177c2d5 (plain)
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
<?php
require_once('util.php');
require_once('serviceDefinitions.php');

session_start();

$container = $_GET['container'];
$action = $_GET['action'];

Util\doSessionCheck('manage.php?container=' . $container);
?>
<!DOCTYPE html>
<html>

<head>
    <title>Manage container</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <div class="container">
        <h1>Manage container: <?php echo $container ?></h1>
        <a href="index.php">Home</a>
        <a href="status.php">Status</a>
        <hr>
        <?php
        //if (empty($container)) {
        //    Util\createBanner('✗', 'No service specified', 'bad');
        //    return;
        //}
        //if (!in_array($service, array_map(function ($s) {
        //    return $s->name;
        //}, $services))) {
        //    Util\createBanner('✗', "Service '$service' is unknown", 'bad');
        //    return;
        //}

        $status = Util\getDockerStatus($container);

        if ($status->status === '-') {
            Util\createBanner('✗', "Container '$container' not found", 'bad');
            return;
        }
        
        if ($action === 'start' || $action === 'stop' || $action === 'restart' || $action === 'logs') {
        // if ($action === 'start' || $action === 'stop' || $action === 'restart') {
            $safeService = escapeshellarg($container);
            Util\doShellExec('sudo docker ' . $action . ' ' . $safeService, '/manage.php?container=' . $container, $action);
        }
        
        Util\createStatusBanner($status);
        ?>
        <p>
        <details>
            <summary>Status as reported by Docker</summary>
            <?php Util\createStatusTable($status); ?>
        </details>
        </p>

        <p class="control-list">
            <a href="manage.php?container=<?php echo $container ?>&action=logs">[Logs]</a>
            <a href="manage.php?container=<?php echo $container ?>&action=start">[Start]</a>
            <a href="manage.php?container=<?php echo $container ?>&action=stop">[Stop]</a>
            <a href="manage.php?container=<?php echo $container ?>&action=restart">[Restart]</a>
        </p>
    </div>
</body>