blob: f0e220f9ca42334a6621d44aa06ce8be0972e5ea [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
3if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != 'admin') {
4 exit();
5}
6
7if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) {
8 if ($_GET['action'] == "start") {
9 header('Content-Type: text/html; charset=utf-8');
10 $retry = 0;
11 while (docker('info', $_GET['service'])['State']['Running'] != 1 && $retry <= 3) {
12 $response = docker('post', $_GET['service'], 'start');
13 $response = json_decode($response, true);
14 $last_response = ($response['type'] == "success") ? '<b><span class="pull-right text-success">OK</span></b>' : '<b><span class="pull-right text-danger">Error: ' . $response['msg'] . '</span></b>';
15 if ($response['type'] == "success") {
16 break;
17 }
18 usleep(1500000);
19 $retry++;
20 }
21 echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Already running</span></b>' : $last_response;
22 }
23 if ($_GET['action'] == "stop") {
24 header('Content-Type: text/html; charset=utf-8');
25 $retry = 0;
26 while (docker('info', $_GET['service'])['State']['Running'] == 1 && $retry <= 3) {
27 $response = docker('post', $_GET['service'], 'stop');
28 $response = json_decode($response, true);
29 $last_response = ($response['type'] == "success") ? '<b><span class="pull-right text-success">OK</span></b>' : '<b><span class="pull-right text-danger">Error: ' . $response['msg'] . '</span></b>';
30 if ($response['type'] == "success") {
31 break;
32 }
33 usleep(1500000);
34 $retry++;
35 }
36 echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Not running</span></b>' : $last_response;
37 }
38 if ($_GET['action'] == "restart") {
39 header('Content-Type: text/html; charset=utf-8');
40 $response = docker('post', $_GET['service'], 'restart');
41 $response = json_decode($response, true);
42 $last_response = ($response['type'] == "success") ? '<b><span class="pull-right text-success">OK</span></b>' : '<b><span class="pull-right text-danger">Error: ' . $response['msg'] . '</span></b>';
43 echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Cannot restart container</span></b>' : $last_response;
44 }
45 if ($_GET['action'] == "logs") {
46 $lines = (empty($_GET['lines']) || !is_numeric($_GET['lines'])) ? 1000 : $_GET['lines'];
47 header('Content-Type: text/plain; charset=utf-8');
48 print_r(preg_split('/\n/', docker('logs', $_GET['service'], $lines)));
49 }
50}
51
52?>