From 06ca54756c6ef54ca155032c31d2021108530f64 Mon Sep 17 00:00:00 2001 From: mercury Date: Sat, 8 Apr 2023 00:53:23 +0400 Subject: [PATCH] optimize ip info --- app/bot.php | 17 +++++++++-------- docker-compose.yml | 4 ++-- scripts/start_unit.sh | 3 ++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/bot.php b/app/bot.php index 7eb1666..fd47529 100644 --- a/app/bot.php +++ b/app/bot.php @@ -11,6 +11,7 @@ class Bot $this->file = "https://api.telegram.org/file/bot$key/"; $this->clients = '/config/clients.json'; $this->pac = '/config/pac.json'; + $this->ip = getenv('IP'); } public function input() @@ -305,7 +306,7 @@ class Bot $ssl = $this->nginxGetTypeCert(); $c = $this->getSSConfig(); $l = $this->getSSLocalConfig(); - $domain = $this->getPacConf()['domain'] ?: file_get_contents('https://ipinfo.io/ip'); + $domain = $this->getPacConf()['domain'] ?: $this->ip; if ($c['plugin']) { unset($c['plugin']); unset($c['plugin_opts']); @@ -510,7 +511,7 @@ class Bot public function qrSS() { $conf = $this->getPacConf(); - $ip = file_get_contents('https://ipinfo.io/ip'); + $ip = $this->ip; $domain = $conf['domain'] ?: $ip; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); @@ -1326,7 +1327,7 @@ DNS-over-HTTPS with IP: $pac = stat(__DIR__ . '/zapretlists/pac'); $conf = $this->getPacConf(); $zapret = $conf['zapret'] ? 'ON' : 'OFF'; - $ip = $conf['domain'] ?: file_get_contents('https://ipinfo.io/ip'); + $ip = $conf['domain'] ?: $this->ip; $hash = substr(md5($this->key), 0, 8); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $text = <<getPacConf(); - $ip = file_get_contents('https://ipinfo.io/ip'); + $ip = $this->ip; $domain = $conf['domain'] ?: $ip; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); @@ -1716,7 +1717,7 @@ DNS-over-HTTPS with IP: public function adguardMenu() { $conf = $this->getPacConf(); - $ip = file_get_contents('https://ipinfo.io/ip'); + $ip = $this->ip; $domain = $conf['domain'] ?: $ip; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; @@ -2017,7 +2018,7 @@ DNS-over-HTTPS with IP: 'peers' => [ [ 'PublicKey' => $public_server_key, - 'Endpoint' => file_get_contents('https://ipinfo.io/ip') . ":" . getenv('WGPORT'), + 'Endpoint' => $this->ip . ":" . getenv('WGPORT'), 'AllowedIPs' => $ips_user ?: "0.0.0.0/0", 'PersistentKeepalive' => 20, ] @@ -2044,7 +2045,7 @@ DNS-over-HTTPS with IP: public function syncPortClients() { - $endpoint = file_get_contents('https://ipinfo.io/ip') . ':' . getenv('WGPORT'); + $endpoint = $this->ip . ':' . getenv('WGPORT'); $clients = $this->readClients(); foreach ($clients as $k => $v) { foreach ($v['peers'] as $i => $j) { @@ -2119,7 +2120,7 @@ DNS-over-HTTPS with IP: public function setwebhook() { - $ip = file_get_contents('https://ipinfo.io/ip'); + $ip = $this->ip; if (empty($ip)) { die('нет айпи'); } diff --git a/docker-compose.yml b/docker-compose.yml index f56893a..97a455f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,12 @@ version: "3.7" -x-logging: +x-logging: &default-logging driver: "json-file" options: max-size: "200k" max-file: "10" - + networks: default: ipam: diff --git a/scripts/start_unit.sh b/scripts/start_unit.sh index 19f0861..9fce67a 100644 --- a/scripts/start_unit.sh +++ b/scripts/start_unit.sh @@ -1,6 +1,7 @@ +export IP=$(curl https://ipinfo.io/ip) rm /ssh/key* ssh-keygen -m PEM -t rsa -f /ssh/key -N '' -openssl req -newkey rsa:2048 -sha256 -nodes -x509 -days 365 -keyout /certs/self_private -out /certs/self_public -subj "/C=NN/ST=N/L=N/O=N/CN=$(curl https://ipinfo.io/ip)" +openssl req -newkey rsa:2048 -sha256 -nodes -x509 -days 365 -keyout /certs/self_private -out /certs/self_public -subj "/C=NN/ST=N/L=N/O=N/CN=$IP" php init.php unitd --log /logs/unit_error curl -X PUT --data-binary @/config/unit.json --unix-socket /var/run/control.unit.sock http://localhost/config