diff --git a/.gitignore b/.gitignore index f651c25..c8cd08e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ update/* override.env override.html -override.php \ No newline at end of file +override.php +docker-compose.override.yml \ No newline at end of file diff --git a/app/bot.php b/app/bot.php index 52c201c..3d7fa07 100644 --- a/app/bot.php +++ b/app/bot.php @@ -142,6 +142,9 @@ class Bot case preg_match('~^/autoupdate$~', $this->input['message'], $m): $this->autoupdate(); break; + case preg_match('~^/ports$~', $this->input['callback'], $m): + $this->ports(); + break; case preg_match('~^/adgFillAllowedClients(?: (\d+))?$~', $this->input['callback'], $m): $this->adgFillAllowedClients($m[1] ?: false); break; @@ -181,6 +184,9 @@ class Bot case preg_match('~^/exportList (\w+)$~', $this->input['callback'], $m): $this->exportList($m[1]); break; + case preg_match('~^/hidePort (\w+)$~', $this->input['callback'], $m): + $this->hidePort($m[1]); + break; case preg_match('~^/deleteYes (\w+)$~', $this->input['callback'], $m): $this->deleteYes($m[1]); break; @@ -5814,6 +5820,10 @@ DNS-over-HTTPS with IP: 'text' => $this->i18n('fake html'), 'callback_data' => "/addOverrideHtml", ], + [ + 'text' => $this->i18n('ports'), + 'callback_data' => "/ports", + ], ]; $data[] = [ [ @@ -5843,6 +5853,69 @@ DNS-over-HTTPS with IP: ]; } + public function ports() + { + $text[] = 'Settings -> Ports'; + $f = '/docker/compose'; + $c = yaml_parse_file($f)['services']; + $data = [ + [[ + 'text' => 'Letsencrypt 80 ' . $this->i18n($c['ng'] ? 'off' : 'on'), + 'callback_data' => "/hidePort ng", + ]], + [[ + 'text' => 'Shadowsocks ' . getenv('SSPORT') . ' ' . $this->i18n($c['ss'] ? 'off' : 'on'), + 'callback_data' => "/hidePort ss", + ]], + [[ + 'text' => 'DoT 853 ' . $this->i18n($c['ad'] ? 'off' : 'on'), + 'callback_data' => "/hidePort ad", + ]], + [[ + 'text' => 'Wireguard-1 ' . getenv('WGPORT') . ' ' . $this->i18n($c['wg'] ? 'off' : 'on'), + 'callback_data' => "/hidePort wg", + ]], + [[ + 'text' => 'Wireguard-2 ' . getenv('WG1PORT') . ' ' . $this->i18n($c['wg1'] ? 'off' : 'on'), + 'callback_data' => "/hidePort wg1", + ]], + [[ + 'text' => 'MTProto ' . getenv('TGPORT') . ' ' . $this->i18n($c['tg'] ? 'off' : 'on'), + 'callback_data' => "/hidePort tg", + ]], + ]; + $data[] = [ + [ + 'text' => $this->i18n('back'), + 'callback_data' => "/menu config", + ], + ]; + $this->update( + $this->input['chat'], + $this->input['message_id'], + implode("\n", $text ?: ['...']), + $data ?: false, + ); + } + + public function hidePort($container) + { + $f = '/docker/compose'; + $c = yaml_parse_file($f); + if (!empty($c['services'][$container])) { + unset($c['services'][$container]); + } else { + $c['services'][$container]['ports'] = []; + } + if (empty($c['services'])) { + file_put_contents($f, ''); + } else { + yaml_emit_file($f, $c); + file_put_contents($f, str_replace('ports:', 'ports: !override', file_get_contents($f))); + } + $this->ports(); + } + public function branches() { exec('git -C / branch -r', $m); diff --git a/docker-compose.yml b/docker-compose.yml index 181e3a4..e444103 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,6 +118,7 @@ services: - ./update:/update - ./.git:/.git - ./singbox_windows:/singbox + - ./docker-compose.override.yml:/docker/compose - /var/run/docker.sock:/var/run/docker.sock:ro environment: IP: ${IP}