2016-12-25 10:03:37 +01:00
|
|
|
<?php
|
2018-07-29 00:38:22 +02:00
|
|
|
function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $extra_headers = null) {
|
2018-07-23 20:01:01 +02:00
|
|
|
global $DOCKER_TIMEOUT;
|
2022-08-22 16:08:01 +02:00
|
|
|
global $redis;
|
2017-10-04 13:04:58 +02:00
|
|
|
$curl = curl_init();
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: application/json' ));
|
|
|
|
// We are using our mail certificates for dockerapi, the names will not match, the certs are trusted anyway
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
2017-10-04 13:04:58 +02:00
|
|
|
switch($action) {
|
|
|
|
case 'get_id':
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/containers/json');
|
2017-10-04 13:04:58 +02:00
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 0);
|
2018-07-23 20:01:01 +02:00
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
2017-10-04 13:04:58 +02:00
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
$containers = json_decode($response, true);
|
|
|
|
if (!empty($containers)) {
|
|
|
|
foreach ($containers as $container) {
|
2019-02-05 00:10:21 +01:00
|
|
|
if (isset($container['Config']['Labels']['com.docker.compose.service'])
|
|
|
|
&& $container['Config']['Labels']['com.docker.compose.service'] == $service_name
|
2020-07-11 13:32:40 +02:00
|
|
|
&& strtolower($container['Config']['Labels']['com.docker.compose.project']) == strtolower(getenv('COMPOSE_PROJECT_NAME'))) {
|
2017-10-04 13:04:58 +02:00
|
|
|
return trim($container['Id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2022-08-09 20:29:33 +02:00
|
|
|
break;
|
2018-07-29 00:38:22 +02:00
|
|
|
case 'containers':
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/containers/json');
|
2018-05-20 23:28:03 +02:00
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 0);
|
2018-07-23 20:01:01 +02:00
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
2018-05-20 23:28:03 +02:00
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
$containers = json_decode($response, true);
|
|
|
|
if (!empty($containers)) {
|
|
|
|
foreach ($containers as $container) {
|
2020-07-11 13:32:40 +02:00
|
|
|
if (strtolower($container['Config']['Labels']['com.docker.compose.project']) == strtolower(getenv('COMPOSE_PROJECT_NAME'))) {
|
2018-07-29 00:38:22 +02:00
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['State'] = $container['State'];
|
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['Config'] = $container['Config'];
|
2022-08-22 16:08:01 +02:00
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($container['Id']);
|
2018-07-29 00:38:22 +02:00
|
|
|
}
|
2018-05-20 23:28:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (!empty($out)) ? $out : false;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-04 13:04:58 +02:00
|
|
|
break;
|
|
|
|
case 'info':
|
2018-07-29 00:38:22 +02:00
|
|
|
if (empty($service_name)) {
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/containers/json');
|
2017-10-04 13:04:58 +02:00
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
2017-10-05 23:38:33 +02:00
|
|
|
curl_setopt($curl, CURLOPT_POST, 0);
|
2018-07-23 20:01:01 +02:00
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
2018-07-29 00:38:22 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$container_id = docker('get_id', $service_name);
|
|
|
|
if (ctype_xdigit($container_id)) {
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/containers/' . $container_id . '/json');
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-07-29 00:38:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 0);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
$decoded_response = json_decode($response, true);
|
|
|
|
if (!empty($decoded_response)) {
|
|
|
|
if (empty($service_name)) {
|
|
|
|
foreach ($decoded_response as $container) {
|
2019-02-05 00:10:21 +01:00
|
|
|
if (isset($container['Config']['Labels']['com.docker.compose.project'])
|
2020-07-11 13:32:40 +02:00
|
|
|
&& strtolower($container['Config']['Labels']['com.docker.compose.project']) == strtolower(getenv('COMPOSE_PROJECT_NAME'))) {
|
2018-07-29 00:38:22 +02:00
|
|
|
unset($container['Config']['Env']);
|
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['State'] = $container['State'];
|
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['Config'] = $container['Config'];
|
2022-08-22 16:08:01 +02:00
|
|
|
$out[$container['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($container['Id']);
|
2018-07-29 00:38:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-05 00:10:21 +01:00
|
|
|
if (isset($decoded_response['Config']['Labels']['com.docker.compose.project'])
|
2020-07-11 13:32:40 +02:00
|
|
|
&& strtolower($decoded_response['Config']['Labels']['com.docker.compose.project']) == strtolower(getenv('COMPOSE_PROJECT_NAME'))) {
|
2018-07-29 00:38:22 +02:00
|
|
|
unset($container['Config']['Env']);
|
|
|
|
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['State'] = $decoded_response['State'];
|
|
|
|
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['Config'] = $decoded_response['Config'];
|
2022-08-22 16:08:01 +02:00
|
|
|
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($decoded_response['Id']);
|
2018-07-29 00:38:22 +02:00
|
|
|
}
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 00:38:22 +02:00
|
|
|
if (empty($response)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (!empty($out)) ? $out : false;
|
|
|
|
}
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'post':
|
2017-12-09 13:17:15 +01:00
|
|
|
if (!empty($attr1)) {
|
2018-07-29 00:38:22 +02:00
|
|
|
$container_id = docker('get_id', $service_name);
|
2017-12-09 13:17:15 +01:00
|
|
|
if (ctype_xdigit($container_id) && ctype_alnum($attr1)) {
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/containers/' . $container_id . '/' . $attr1);
|
2017-10-04 13:04:58 +02:00
|
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
2018-07-23 20:01:01 +02:00
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
2017-12-09 13:17:15 +01:00
|
|
|
if (!empty($attr2)) {
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($attr2));
|
|
|
|
}
|
|
|
|
if (!empty($extra_headers) && is_array($extra_headers)) {
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $extra_headers);
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
if (empty($response)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-08-22 16:08:01 +02:00
|
|
|
case 'container_stats':
|
|
|
|
if (empty($service_name)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$container_id = $service_name;
|
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/container/' . $container_id . '/stats/update');
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
$stats = json_decode($response, true);
|
|
|
|
if (!empty($stats)) return $stats;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
2022-08-09 20:29:33 +02:00
|
|
|
case 'host_stats':
|
|
|
|
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/host/stats');
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 0);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
if ($response === false) {
|
|
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $err;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_close($curl);
|
|
|
|
$stats = json_decode($response, true);
|
|
|
|
if (!empty($stats)) return $stats;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
2017-10-04 13:04:58 +02:00
|
|
|
}
|
2018-04-26 14:06:10 +02:00
|
|
|
}
|