From ae61a38dbcd2783d47818dacc4a5ccc6520a080b Mon Sep 17 00:00:00 2001 From: mercury Date: Sun, 29 Sep 2024 16:10:16 +0400 Subject: [PATCH] on/off warp-svc --- app/bot.php | 41 +++++++++++++++++++++++++++++++++++++---- scripts/start_wp.sh | 18 +++++++++++------- version | 2 ++ 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/app/bot.php b/app/bot.php index df2eb20..11c1651 100644 --- a/app/bot.php +++ b/app/bot.php @@ -145,6 +145,9 @@ class Bot case preg_match('~^/appOutbound$~', $this->input['callback'], $m): $this->appOutbound(); break; + case preg_match('~^/offWarp$~', $this->input['callback'], $m): + $this->offWarp(); + break; case preg_match('~^/addSubdomain$~', $this->input['callback'], $m): $this->addSubdomain(); break; @@ -4520,23 +4523,53 @@ DNS-over-HTTPS with IP: public function warpStatus() { - $st = $this->ssh('curl -m 1 -x socks5://127.0.0.1:40000 https://cloudflare.com/cdn-cgi/trace', 'wp'); - preg_match('~warp=(\w+)~', $st, $m); - return $m[1]; + if (!empty($this->ssh('pgrep warp-svc', 'wp'))) { + $st = $this->ssh('curl -m 1 -x socks5://127.0.0.1:40000 https://cloudflare.com/cdn-cgi/trace', 'wp'); + preg_match('~warp=(\w+)~', $st, $m); + return $m[1]; + } + return 'off'; + } + + public function offWarp() + { + $p = $this->getPacConf(); + if (empty($p['warpoff'])) { + $this->ssh('pkill warp-svc', 'wp'); + $p['warpoff'] = 1; + } else { + $this->ssh('warp-svc > /dev/null 2>&1 &', 'wp'); + sleep(3); + $this->ssh('warp-cli --accept-tos registration new', 'wp'); + if (!empty($p['warp'])) { + $this->ssh("warp-cli --accept-tos registration license {$p['warp']}", 'wp'); + } + $this->ssh('warp-cli --accept-tos mode proxy', 'wp'); + $this->ssh('warp-cli --accept-tos connect', 'wp'); + unset($p['warpoff']); + } + $this->setPacConf($p); + $this->warp(); } public function warp() { + $p = $this->getPacConf(); $text[] = "Menu -> " . $this->i18n('warp'); $text[] = "status: " . $this->warpStatus(); $text[] = "key: " . $this->getPacConf()['warp']; + $data[] = [ + [ + 'text' => $this->i18n($p['warpoff'] ? 'off' : 'on'), + 'callback_data' => "/offWarp", + ], + ]; $data[] = [ [ 'text' => $this->i18n('set key'), 'callback_data' => "/warpPlus", ], ]; - $data[] = [ [ 'text' => $this->i18n('back'), diff --git a/scripts/start_wp.sh b/scripts/start_wp.sh index f8b57eb..b4e51dd 100755 --- a/scripts/start_wp.sh +++ b/scripts/start_wp.sh @@ -1,14 +1,18 @@ cat /ssh/key.pub > /root/.ssh/authorized_keys ssh-keygen -A exec /usr/sbin/sshd -D -e "$@" & -warp-svc > /dev/null & -sleep 3 -warp-cli --accept-tos registration new +off=$(cat /config/pac.json | jq -r .warpoff) key=$(cat /config/pac.json | jq -r .warp) -if [ ! -z "$key" ] +if [ "$off" == 'null' ] then - warp-cli --accept-tos registration license $key + warp-svc > /dev/null & + sleep 3 + warp-cli --accept-tos registration new + if [ ! -z "$key" ] + then + warp-cli --accept-tos registration license $key + fi + warp-cli --accept-tos mode proxy + warp-cli --accept-tos connect fi -warp-cli --accept-tos mode proxy -warp-cli --accept-tos connect socat TCP-LISTEN:4000,fork TCP:127.0.0.1:40000 diff --git a/version b/version index e5df585..6c06b86 100644 --- a/version +++ b/version @@ -1,3 +1,5 @@ +29.09.2024 v1.61 +- включение/отключение процесса warp 29.09.2024 v1.60 - ускорение сборки архива sing-box windows 23.09.2024 v1.59