From 8d47b5cd5280e3485c983c84b8dc246383286eea Mon Sep 17 00:00:00 2001 From: mercury Date: Fri, 10 Feb 2023 19:20:09 +0400 Subject: [PATCH] authorization --- app/bot.php | 15 +++++++++++++++ app/index.php | 20 ++++++++++---------- scripts/init.sh | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/bot.php b/app/bot.php index c54bafe..e8d42da 100644 --- a/app/bot.php +++ b/app/bot.php @@ -39,11 +39,25 @@ class Bot 'new_member_id' => $input['my_chat_member']['new_chat_member']['user']['id'] ?? false, 'new_member_status' => $input['my_chat_member']['new_chat_member']['status'] ?? false, ]; + $this->auth(); $this->session(); $this->action(); $this->callbackCheck(); } + public function auth() + { + $file = __DIR__ . '/config.php'; + require $file; + if (empty($c['admin'])) { + $c['admin'] = $this->input['from']; + file_put_contents($file, "input['from']) { + $this->send($this->input['chat'], 'you are not authorized', $this->input['message_id']); + exit; + } + } + public function callbackCheck() { if (empty($this->callback) && !empty($this->input['callback_id'])) { @@ -84,6 +98,7 @@ class Bot switch (true) { // смена айпи сервера case preg_match('~^/menu$~', $this->input['message'], $m): + case preg_match('~^/start$~', $this->input['message'], $m): case preg_match('~^/menu$~', $this->input['callback'], $m): case preg_match('~^/menu (?Paddpeer) (?P(?:-)?\d+)$~', $this->input['callback'], $m): case preg_match('~^/menu (?Pwg) (?P(?:-)?\d+)$~', $this->input['callback'], $m): diff --git a/app/index.php b/app/index.php index c231152..a1a7930 100644 --- a/app/index.php +++ b/app/index.php @@ -4,33 +4,33 @@ date_default_timezone_set(getenv('TZ')); // bot require __DIR__ . '/config.php'; -if ('POST' == $_SERVER['REQUEST_METHOD'] && $_GET['k'] == $key) { +if ('POST' == $_SERVER['REQUEST_METHOD'] && $_GET['k'] == $c['key']) { // require __DIR__ . '/debug.php'; require __DIR__ . '/bot.php'; - $bot = new Bot($key); + $bot = new Bot($c['key']); $bot->input(); - die(); + exit; } // pac -$type = $_GET['t'] ?? 'pac'; +$type = $_GET['t'] ?? 'pac'; $address = $_GET['a'] ?: '127.0.0.1'; -$port = $_GET['p'] ?: '1080'; -$hash = $_GET['h']; +$port = $_GET['p'] ?: '1080'; +$hash = $_GET['h']; if ($hash == substr(md5($key), 0, 8)) { if (file_exists($file = __DIR__ . "/zapretlists/$type")) { $pac = file_get_contents($file); - header("Content-Type: text/plain"); + header('Content-Type: text/plain'); echo str_replace([ '~address~', '~port~', ], [ $address, - $port + $port, ], $pac); - die(); + exit; } } header('500', true, 500); -die(); +exit; diff --git a/scripts/init.sh b/scripts/init.sh index 05242ec..f70275d 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -15,5 +15,5 @@ apt update apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin git clone https://github.com/mercurykd/vpnbot.git cd ./vpnbot -echo " ./app/config.php +echo " '$1'];\n" > ./app/config.php make u