diff --git a/app/bot.php b/app/bot.php index acaf834..d4ddab2 100644 --- a/app/bot.php +++ b/app/bot.php @@ -3371,6 +3371,49 @@ DNS-over-HTTPS with IP: return "vless://{$c['inbounds'][0]['settings']['clients'][$i]['id']}@$domain:443?security=reality&sni={$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0]}&type=tcp&flow=xtls-rprx-vision#vpnbot"; } + public function dockerApi($url, $method = 'GET', $data = []) + { + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_POSTFIELDS => !empty($data) ? json_encode($data) : null, + CURLOPT_URL => "http://localhost$url", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock' + ]); + $r = json_decode(curl_exec($ch), true); + curl_close($ch); + return $r; + } + + public function cleanDocker() + { + $r = $this->dockerApi('/images/json'); + foreach ($r as $v) { + if (!empty($v['RepoTags'])) { + foreach ($v['RepoTags'] as $j) { + if (preg_match('~^mercurykd/vpnbot~', $j)) { + $i[] = $v['Id']; + break; + } + } + } + } + $r = $this->dockerApi('/containers/json?all=1'); + foreach ($r as $v) { + if (preg_match('~^mercurykd/vpnbot~', $v['Image'])) { + $c[] = $v['ImageID']; + } + } + if (!empty($d = array_diff($i, $c))) { + foreach ($d as $v) { + $this->dockerApi("/images/$v", 'DELETE'); + } + } + $this->dockerApi('/images/prune', 'POST', ['dangling' => true]); + $this->dockerApi('/build/prune', 'POST'); + } + public function naiveMenu() { $pac = $this->getPacConf(); diff --git a/app/service.php b/app/service.php index 8d1cd0f..b524a87 100644 --- a/app/service.php +++ b/app/service.php @@ -40,3 +40,4 @@ file_put_contents('/update/message', ''); file_put_contents('/update/reload_message', ''); $bot->restartTG(); $bot->sslip(); +$bot->cleanDocker(); diff --git a/docker-compose.yml b/docker-compose.yml index 9f1c23c..e2fa3e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -116,6 +116,7 @@ services: - ./update:/update - ./.git:/.git - ./singbox_windows:/singbox + - /var/run/docker.sock:/var/run/docker.sock:ro environment: IP: ${IP} VER: ${VER} @@ -157,6 +158,7 @@ services: - ./logs/:/logs/ - ./update:/update - ./scripts/start_service.sh:/start_service.sh + - /var/run/docker.sock:/var/run/docker.sock:ro environment: IP: ${IP} VER: ${VER} diff --git a/makefile b/makefile index c633b0d..3a0905a 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,7 @@ d: # остановка контейнеров docker compose down --remove-orphans dv: # остановка контейнеров docker compose down -v -r: d cleanf u cleanf +r: d u ps: # список контейнеров docker compose ps l: # логи из контейнеров