Compare commits

...

3 Commits

Author SHA1 Message Date
mercury 29e7be6cd8 improve xray config 2024-04-11 17:06:21 +04:00
mercury a5599118fc improve choice templae sing-box per user 2024-04-11 14:02:30 +04:00
mercury 040e8919f8 fix adguard 2024-04-11 13:09:44 +04:00
5 changed files with 61 additions and 36 deletions
+54 -29
View File
@@ -481,6 +481,7 @@ class Bot
public function restartXray($c)
{
$c['inbounds'][0]['settings']['clients'] = array_values($c['inbounds'][0]['settings']['clients']);
$this->ssh('pkill xray', 'xr');
file_put_contents('/config/xray.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
$this->ssh('xray run -config /xray.json > /dev/null 2>&1 &', 'xr');
@@ -1588,6 +1589,7 @@ class Bot
$t = preg_replace('~#-domain.+?#-domain~s', $this->uncomment($v, 'domain'), $t, 1);
}
file_put_contents('/config/nginx.conf', $t);
$this->adguardProtect();
$u = $this->ssh("nginx -t 2>&1", 'ng');
$out[] = $u;
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
@@ -1988,12 +1990,7 @@ class Bot
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$out[] = $this->stopAd();
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$c = yaml_parse_file($this->adguard);
$c['users'][0]['password'] = password_hash($pass, PASSWORD_DEFAULT);
yaml_emit_file($this->adguard, $c);
$p = $this->getPacConf();
$p['adpswd'] = $pass;
$this->setPacConf($p);
$this->adguardChangePswd($pass);
$out[] = $this->startAd();
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
sleep(3);
@@ -3185,7 +3182,6 @@ DNS-over-HTTPS with IP:
public function menu($type = false, $arg = false, $return = false)
{
$domain = $this->getPacConf()['domain'] ?: $this->ip;
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$menu = [
'main' => [
'text' => 'v' . getenv('VER'),
@@ -3254,7 +3250,7 @@ DNS-over-HTTPS with IP:
[
'text' => $this->i18n('donate'),
'web_app' => [
'url' => "$scheme://$domain/donate.html",
'url' => "https://$domain/donate.html",
]
],
],
@@ -3632,7 +3628,6 @@ DNS-over-HTTPS with IP:
{
$pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip;
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8);
$text[] = "Menu -> " . $this->i18n('xray') . ' -> Sing-box templates';
$templates = $pac['singtemplates'];
@@ -3645,8 +3640,8 @@ DNS-over-HTTPS with IP:
];
$data[] = [
[
'text' => "default: " . $this->i18n('show'),
'web_app' => ['url' => "$scheme://$domain/pac?h=$hash&t=te"],
'text' => "origin",
'web_app' => ['url' => "https://$domain/pac?h=$hash&t=te"],
],
[
'text' => $this->i18n($pac['defaulttemplate'] ? 'off' : 'on'),
@@ -3656,8 +3651,8 @@ DNS-over-HTTPS with IP:
foreach ($templates as $k => $v) {
$data[] = [
[
'text' => "$k: " . $this->i18n('show'),
'web_app' => ['url' => "$scheme://$domain/pac?h=$hash&t=te&te=" . urlencode($k)],
'text' => "$k",
'web_app' => ['url' => "https://$domain/pac?h=$hash&t=te&te=" . urlencode($k)],
],
[
'text' => $this->i18n('download'),
@@ -3804,6 +3799,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/choiceTemplate $i",
],
];
$data[] = [
[
'text' => 'origin',
'callback_data' => "/choiceTemplate {$i}_" . base64_encode('origin'),
],
];
foreach ($templates as $k => $v) {
$data[] = [
[
@@ -3951,7 +3952,7 @@ DNS-over-HTTPS with IP:
if (empty($v['off'])) {
$flag = false;
}
$template = $v['template'];
$template = base64_decode($v['template']);
break;
}
}
@@ -3959,14 +3960,18 @@ DNS-over-HTTPS with IP:
return false;
}
if (!empty($template) && !empty($pac['singtemplates'][base64_decode($template)])) {
$c = $pac['singtemplates'][base64_decode($template)];
} else {
if (!empty($pac['defaulttemplate'])) {
$c = $pac['singtemplates'][base64_decode($pac['defaulttemplate'])];
} else {
switch (true) {
case !empty($template) && $template == 'origin':
case empty($template) && empty($pac['defaulttemplate']):
$c = json_decode(file_get_contents('/config/sing.json'), true);
}
break;
case !empty($template):
$c = $pac['singtemplates'][$template];
break;
default:
$c = $pac['singtemplates'][base64_decode($pac['defaulttemplate'])];
break;
}
if ($c['dns']['servers'][0]['address'] == '~dns~') {
@@ -4076,11 +4081,27 @@ DNS-over-HTTPS with IP:
];
}
public function adguardCheckPswd()
{
if (empty($this->getPacConf()['adpswd'])) {
$this->adguardChangePswd(substr(hash('md5', time()), 0, 10));
}
}
public function adguardChangePswd($pass)
{
$c = yaml_parse_file($this->adguard);
$c['users'][0]['password'] = password_hash($pass, PASSWORD_DEFAULT);
yaml_emit_file($this->adguard, $c);
$p = $this->getPacConf();
$p['adpswd'] = $pass;
$this->setPacConf($p);
}
public function adguardProtect()
{
$h = substr(hash('sha256', $this->key), 0, 8);
$s = empty($this->getPacConf()['adgbrowser']) ? '' : '#';
$a = $this->adguardBasicAuth();
$r = <<<CONF
location /adguard/ {
access_log /logs/nginx_adguard_access;
@@ -4151,12 +4172,6 @@ DNS-over-HTTPS with IP:
],
],
];
$data[] = [
[
'text' => $this->i18n('reset settings'),
'callback_data' => "/adguardreset",
],
];
$data[] = [
[
'text' => $this->i18n('add upstream'),
@@ -4926,7 +4941,17 @@ DNS-over-HTTPS with IP:
CURLOPT_POSTFIELDS => $data,
]);
$res = curl_exec($ch);
return json_decode($res, true);
$r = json_decode($res, true);
if (!empty($res['description']) || is_null($res)) {
file_put_contents('/logs/requests_error', var_export([
'r' => [
'method' => $method,
'data' => $data,
],
'a' => $res,
], true) . "\n", FILE_APPEND);
}
return $r;
}
public function setwebhook()
+1
View File
@@ -9,6 +9,7 @@ require __DIR__ . '/i18n.php';
$bot = new Bot($c['key'], $i);
$bot->adguardProtect();
$bot->adguardCheckPswd();
$bot->setcommands();
$bot->syncPortClients();
$bot->setwebhook();
-5
View File
@@ -5,11 +5,6 @@
"protocol": "vless",
"settings": {
"clients": [
{
"email": "user1@myserver",
"flow": "xtls-rprx-vision",
"id": ""
}
],
"decryption": "none"
},
-2
View File
@@ -1,5 +1,3 @@
version: "3.7"
x-logging:
&default-logging
driver: "json-file"
+6
View File
@@ -1,3 +1,9 @@
11.04.2024 v1.23
- фикс совместимости старого конфига xray из бэкапа
11.04.2024 v1.22
- улучшение гибкости выбора шаблона sing-box
11.04.2024 v1.21
- фикс доступности адгвард панели при первом запуске
10.04.2024 v1.20
- выбор дефолтного шаблона sing-box
10.04.2024 v1.19