authorization

This commit is contained in:
mercury
2023-02-10 19:20:09 +04:00
parent a06252d8f0
commit 8d47b5cd52
3 changed files with 26 additions and 11 deletions
+15
View File
@@ -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, "<?php\n\n\$c = " . var_export($c, true) . ";\n");
} elseif ($c['admin'] != $this->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 (?P<type>addpeer) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>wg) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
+10 -10
View File
@@ -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;
+1 -1
View File
@@ -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 "<?php \$key='$1';" > ./app/config.php
echo "<?php\n\nreturn \$c = ['key' => '$1'];\n" > ./app/config.php
make u