From 68e6e5919d7e86f927313ca64def3a39ba686a81 Mon Sep 17 00:00:00 2001 From: mercury Date: Mon, 21 Oct 2024 01:07:05 +0400 Subject: [PATCH] fixes for first launch --- app/bot.php | 43 +++++++++++++++++-- app/cron.php | 3 +- app/init.php | 9 ++-- app/service.php | 26 ----------- config/pac.json | 100 +------------------------------------------ docker-compose.yml | 5 ++- scripts/start_php.sh | 14 +++--- version | 3 ++ 8 files changed, 61 insertions(+), 142 deletions(-) diff --git a/app/bot.php b/app/bot.php index 591d972..676e35a 100644 --- a/app/bot.php +++ b/app/bot.php @@ -1760,10 +1760,14 @@ class Bot $this->adguardProtect(); $u = $this->ssh("nginx -t 2>&1", 'ng'); $out[] = $u; - $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); + if (empty($nomenu)) { + $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); + } if (preg_match('~test is successful~', $u)) { $out[] = $this->ssh("nginx -s reload 2>&1", 'ng'); - $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); + if (empty($nomenu)) { + $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); + } $this->setPacConf($conf); $this->chocdomain($domain); $this->setUpstreamDomainOcserv($domain); @@ -5734,13 +5738,44 @@ DNS-over-HTTPS with IP: $this->logs(); } + public function selfUpdate() + { + require __DIR__ . '/config.php'; + if (!empty($c['admin'])) { + $ip = getenv('IP'); + $rm = explode(':', trim(file_get_contents('/update/reload_message'))); + $m = file_get_contents('/update/message'); + foreach ($c['admin'] as $k => $v) { + $r = $this->send($v, "start $ip"); + $this->input['chat'] = $v; + $this->input['message_id'] = $r['result']['message_id']; + if (file_exists($this->update)) { + if (!empty($m)) { + $this->send($v, "
$m
", $v == $rm[0] ? $rm[1] : 0); + } + $r = $this->send($v, "import settings"); + $this->input['chat'] = $v; + $this->input['message_id'] = $r['result']['message_id']; + $this->input['callback_id'] = $r['result']['message_id']; + if (empty($flag)) { + $this->importFile($this->update); + unlink($this->update); + $flag = true; + } + } + } + } + file_put_contents('/update/message', ''); + file_put_contents('/update/reload_message', ''); + } + public function backup() { $r = $this->send( $this->input['chat'], - "@{$this->input['username']} enter like start / period", + "@{$this->input['username']} enter like: start / period", $this->input['message_id'], - reply: 'enter like now / 12:00', + reply: 'enter like: now / 12 hours', ); $_SESSION['reply'][$r['result']['message_id']] = [ 'start_message' => $this->input['message_id'], diff --git a/app/cron.php b/app/cron.php index ee3faaa..043a500 100644 --- a/app/cron.php +++ b/app/cron.php @@ -7,5 +7,4 @@ require __DIR__ . '/bot.php'; require __DIR__ . '/config.php'; require __DIR__ . '/i18n.php'; -$bot = new Bot($c['key'], $i); -$bot->cron(); +(new Bot($c['key'], $i))->cron(); diff --git a/app/init.php b/app/init.php index ce1a671..f33a958 100644 --- a/app/init.php +++ b/app/init.php @@ -10,8 +10,9 @@ if ($c['debug']) { } $bot = new Bot($c['key'], $i); -$bot->adguardProtect(); -$bot->adguardCheckPswd(); -$bot->setcommands(); -$bot->syncPortClients(); $bot->setwebhook(); +$bot->selfUpdate(); +$bot->adguardCheckPswd(); +$bot->adguardProtect(); +$bot->syncPortClients(); +$bot->setcommands(); diff --git a/app/service.php b/app/service.php index b524a87..d898b6e 100644 --- a/app/service.php +++ b/app/service.php @@ -12,32 +12,6 @@ if ($c['debug']) { $bot = new Bot($c['key'], $i); -if (!empty($c['admin'])) { - $ip = getenv('IP'); - $rm = explode(':', trim(file_get_contents('/update/reload_message'))); - $m = file_get_contents('/update/message'); - foreach ($c['admin'] as $k => $v) { - $r = $bot->send($v, "start $ip"); - $bot->input['chat'] = $v; - $bot->input['message_id'] = $r['result']['message_id']; - if (file_exists($bot->update)) { - if (!empty($m)) { - $bot->send($v, "
$m
", $v == $rm[0] ? $rm[1] : 0); - } - $r = $bot->send($v, "import settings"); - $bot->input['chat'] = $v; - $bot->input['message_id'] = $r['result']['message_id']; - $bot->input['callback_id'] = $r['result']['message_id']; - if (empty($flag)) { - $bot->importFile($bot->update); - unlink($bot->update); - $flag = true; - } - } - } -} -file_put_contents('/update/message', ''); -file_put_contents('/update/reload_message', ''); $bot->restartTG(); $bot->sslip(); $bot->cleanDocker(); diff --git a/config/pac.json b/config/pac.json index 1a24005..0967ef4 100644 --- a/config/pac.json +++ b/config/pac.json @@ -1,99 +1 @@ -{ - "zapret": false, - "excludelist": { - "(?:v|w)ul(?:c|k)an": true, - "^\\d": true, - "^a\\w-": true, - "^admiral": true, - "^avtomaty": true, - "^azart": true, - "^azimob": true, - "^baltplay": true, - "a(?:s|z)ino": true, - "adrenalin": true, - "alco": true, - "bet": true, - "prostitut": true, - "zenit": true, - "zerkalo": true, - "777": true - }, - "includelist": {}, - "reverselist": {}, - "subzoneslist": { - "3dn": false, - "3nx": true, - "akadns": true, - "appspot": true, - "azurewebsites": true, - "beget": true, - "berlogovo": true, - "biz": true, - "brightcove": true, - "cc": true, - "cloudfront": true, - "co": true, - "com": true, - "cu": true, - "ddns": true, - "deviantart": true, - "dn": true, - "dp": true, - "dyndns": true, - "edgecastcdn": true, - "edu": true, - "eu": true, - "fastly": true, - "force": true, - "github": true, - "google": true, - "googleusercontent": true, - "gov": true, - "herokuapp": true, - "hldns": true, - "ho": true, - "hopto": true, - "hwcdn": true, - "i": true, - "iboards": true, - "in": true, - "info": true, - "int": true, - "itch": true, - "keenetic": true, - "kiev": true, - "kirov": true, - "linode": true, - "livejournal": true, - "maryno": true, - "mil": true, - "msk": true, - "my1": true, - "mybb2": true, - "ne": true, - "net": true, - "netdna-ssl": true, - "nnov": true, - "notion": true, - "nov": true, - "od": true, - "org": true, - "pp": true, - "pximg": true, - "pythonanywhere": true, - "ru": true, - "scaleway": true, - "sl": true, - "sl-reverse": true, - "spb": true, - "tilda": true, - "trafficmanager": true, - "tut": true, - "u-stream": true, - "ucoz": true, - "v": true, - "vercel": true, - "wix": true, - "wixmp": true - } -} +{} diff --git a/docker-compose.yml b/docker-compose.yml index 6634999..762075f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,8 @@ services: - ./config/sshd_config:/etc/ssh/sshd_config - ./logs/:/logs/ ports: - - 443:443 + - 443:443/tcp + - 443:443/udp hostname: upstream container_name: upstream-${VER} depends_on: @@ -127,7 +128,7 @@ services: required: false hostname: php container_name: php-${VER} - restart: unless-stopped + # restart: unless-stopped stop_grace_period: 1s command: ["/bin/sh", "/start_php.sh"] working_dir: /app diff --git a/scripts/start_php.sh b/scripts/start_php.sh index e6dce92..8526ce0 100755 --- a/scripts/start_php.sh +++ b/scripts/start_php.sh @@ -2,8 +2,12 @@ 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=$IP" php init.php -php cron.php & -unitd --log /logs/unit_error -curl -X PUT --data-binary @/config/unit.json --unix-socket /var/run/control.unit.sock http://localhost/config -pkill unitd -unitd --no-daemon --control 0.0.0.0:8080 --log /logs/unit_error +if [[ -f "/start" && -f "/ssh/key.pub" && -s "/ssh/key.pub" ]]; then + php cron.php & + unitd --log /logs/unit_error + curl -X PUT --data-binary @/config/unit.json --unix-socket /var/run/control.unit.sock http://localhost/config + pkill unitd + unitd --no-daemon --control 0.0.0.0:8080 --log /logs/unit_error +else + exit 1; +fi diff --git a/version b/version index 4d9d971..634af44 100644 --- a/version +++ b/version @@ -1,3 +1,6 @@ +21.10.2024 v1.71 +- фикс установки nip.io при первом запуске +- фикс инициализации вебпанели adguardHome при первом запуске 14.10.2024 v1.70 - xray route: учет регистра в process_name, package_name 14.10.2024 v1.69