public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/web/inc/ajax/container_ctrl.php
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
<?php
3
// Block requests by checking the 'Sec-Fetch-Dest' header.
4
if (isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] !== 'empty') {
5
header('HTTP/1.1 403 Forbidden');
6
exit;
7
}
9
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
10
if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != 'admin') {
11
exit();
12
}
14
if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) {
15
if ($_GET['action'] == "start") {
16
header('Content-Type: text/html; charset=utf-8');
17
$retry = 0;
18
while (docker('info', $_GET['service'])['State']['Running'] != 1 && $retry <= 3) {
19
$response = docker('post', $_GET['service'], 'start');
20
$response = json_decode($response, true);
21
$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>';
22
if ($response['type'] == "success") {
23
break;
24
}
25
usleep(1500000);
26
$retry++;
27
}
28
echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Already running</span></b>' : $last_response;
29
}
30
if ($_GET['action'] == "stop") {
31
header('Content-Type: text/html; charset=utf-8');
32
$retry = 0;
33
while (docker('info', $_GET['service'])['State']['Running'] == 1 && $retry <= 3) {
34
$response = docker('post', $_GET['service'], 'stop');
35
$response = json_decode($response, true);
36
$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>';
37
if ($response['type'] == "success") {
38
break;
39
}
40
usleep(1500000);
41
$retry++;
42
}
43
echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Not running</span></b>' : $last_response;
44
}
45
if ($_GET['action'] == "restart") {
46
header('Content-Type: text/html; charset=utf-8');
47
$response = docker('post', $_GET['service'], 'restart');
48
$response = json_decode($response, true);
49
$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>';
50
echo (!isset($last_response)) ? '<b><span class="pull-right text-warning">Cannot restart container</span></b>' : $last_response;
51
}
52
if ($_GET['action'] == "logs") {
53
$lines = (empty($_GET['lines']) || !is_numeric($_GET['lines'])) ? 1000 : $_GET['lines'];
54
header('Content-Type: text/plain; charset=utf-8');
55
print_r(preg_split('/\n/', docker('logs', $_GET['service'], $lines)));
56
}
57
}
59
?>