Compare commits

...

7 Commits

Author SHA1 Message Date
mercury 95f92791b1 update version 2024-10-23 10:08:32 +04:00
mercury cedfb66ca0 fix autoupdate wireguard crash 2024-10-23 10:05:06 +04:00
mercury 6215836926 fix empty route rules for singbox 2024-10-23 03:01:10 +04:00
mercury 842d76261a update version 2024-10-23 02:45:17 +04:00
mercury 4c63ae669a improve selfupdate 2024-10-23 02:32:19 +04:00
mercury bba1ec9e17 improve selfupdate 2024-10-23 02:25:00 +04:00
mercury a798df0fd3 improve selfupdate 2024-10-23 02:20:16 +04:00
3 changed files with 51 additions and 33 deletions
+44 -33
View File
@@ -1324,7 +1324,7 @@ class Bot
]; ];
} }
public function importFile($file = false) public function importFile($file = false, $autoupdate = false)
{ {
if (!empty($file)) { if (!empty($file)) {
$json = json_decode(file_get_contents($file), true); $json = json_decode(file_get_contents($file), true);
@@ -1364,7 +1364,11 @@ class Bot
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->wg = 0; $this->wg = 0;
$this->saveClients($json['wg']['clients']); $this->saveClients($json['wg']['clients']);
$this->restartWG($this->createConfig($json['wg']['server']), $switch_amnezia); if (empty($autoupdate)) {
$this->restartWG($this->createConfig($json['wg']['server']), $switch_amnezia);
} else {
file_put_contents('/config/wg0.conf', $this->createConfig($json['wg']['server']));
}
$this->iptablesWG(); $this->iptablesWG();
} }
// wg1 // wg1
@@ -1373,7 +1377,11 @@ class Bot
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->wg = 1; $this->wg = 1;
$this->saveClients($json['wg1']['clients']); $this->saveClients($json['wg1']['clients']);
$this->restartWG($this->createConfig($json['wg1']['server']), $switch_wg1amnezia); if (empty($autoupdate)) {
$this->restartWG($this->createConfig($json['wg1']['server']), $switch_wg1amnezia);
} else {
file_put_contents('/config/wg1.conf', $this->createConfig($json['wg1']['server']));
}
$this->iptablesWG(); $this->iptablesWG();
} }
// ad // ad
@@ -1456,8 +1464,10 @@ class Bot
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->language = $this->getPacConf()['language'] ?: 'en'; $this->language = $this->getPacConf()['language'] ?: 'en';
$this->limit = $this->getPacConf()['limitpage'] ?: 5; $this->limit = $this->getPacConf()['limitpage'] ?: 5;
sleep(3); if (empty($file)) {
$this->menu(); sleep(3);
$this->menu();
}
} }
} }
@@ -1804,7 +1814,7 @@ class Bot
$this->addDomain(str_replace('.', '-', $this->ip) . '.nip.io', 1); $this->addDomain(str_replace('.', '-', $this->ip) . '.nip.io', 1);
$this->setSSL('letsencrypt'); $this->setSSL('letsencrypt');
} }
$this->menu(dontshowcron: 1); $this->menu();
} }
public function comment($text, $tag) public function comment($text, $tag)
@@ -3855,13 +3865,13 @@ DNS-over-HTTPS with IP:
$this->menu('wg', 0); $this->menu('wg', 0);
} }
public function menu($type = false, $arg = false, $return = false, $dontshowcron = false) public function menu($type = false, $arg = false, $return = false)
{ {
$domain = $this->getPacConf()['domain'] ?: $this->ip; $domain = $this->getPacConf()['domain'] ?: $this->ip;
$cron = exec('pgrep -f cron.php'); $cron = exec('pgrep -f cron.php');
$menu = [ $menu = [
'main' => [ 'main' => [
'text' => 'v' . getenv('VER') . ($dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show <code>logs/php_error</code>')), 'text' => 'v' . getenv('VER') . ($this->dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show <code>logs/php_error</code>')),
'data' => [ 'data' => [
[ [
[ [
@@ -5041,6 +5051,14 @@ DNS-over-HTTPS with IP:
} }
$json['routing']['rules'] = array_values($json['routing']['rules']); $json['routing']['rules'] = array_values($json['routing']['rules']);
} }
if (!empty($json['route']['rules'])) {
foreach ($json['route']['rules'] as $k => $v) {
if (count($v) < 2) {
unset($json['route']['rules'][$k]);
}
}
$json['route']['rules'] = array_values($json['route']['rules']);
}
return json_encode($json); return json_encode($json);
} }
@@ -5732,28 +5750,21 @@ DNS-over-HTTPS with IP:
public function selfUpdate() public function selfUpdate()
{ {
require __DIR__ . '/config.php'; $ip = getenv('IP');
if (!empty($c['admin'])) { $rm = explode(':', trim(file_get_contents('/update/reload_message')));
$ip = getenv('IP'); $m = file_get_contents('/update/message');
$rm = explode(':', trim(file_get_contents('/update/reload_message'))); $this->input['chat'] = $rm[0];
$m = file_get_contents('/update/message'); $this->input['message_id'] = $rm[1];
if (file_exists($this->update)) { $this->input['callback_id'] = $rm[1];
$r = $this->send($c['admin'][0], "start update"); if (file_exists($this->update)) {
$this->input['chat'] = $c['admin'][0]; if (!empty($m)) {
$this->input['message_id'] = $r['result']['message_id']; $this->send($this->input['chat'], "<pre>$m</pre>", $rm[1]);
if (!empty($m)) {
$this->send($c['admin'][0], "<pre>$m</pre>", $rm[1]);
}
$r = $this->send($c['admin'][0], "import settings");
$this->input['chat'] = $c['admin'][0];
$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;
}
} }
$r = $this->send($this->input['chat'], "import settings");
$this->input['message_id'] = $r['result']['message_id'];
$this->input['callback_id'] = $r['result']['message_id'];
$this->importFile($this->update, 1);
unlink($this->update);
} }
file_put_contents('/update/message', ''); file_put_contents('/update/message', '');
file_put_contents('/update/reload_message', ''); file_put_contents('/update/reload_message', '');
@@ -6013,25 +6024,25 @@ DNS-over-HTTPS with IP:
public function createConfig($data) public function createConfig($data)
{ {
$pac = $this->getPacConf();
$conf[] = "[Interface]"; $conf[] = "[Interface]";
if (empty($data['interface']['ListenPort'])) { if (empty($data['interface']['ListenPort'])) {
if (empty($data['interface']['DNS'])) { if (empty($data['interface']['DNS'])) {
$data['interface']['DNS'] = $this->getPacConf()[$this->getInstanceWG(1) . 'dns'] ?: $this->dns; $data['interface']['DNS'] = $pac[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
} }
if (empty($data['interface']['MTU'])) { if (empty($data['interface']['MTU'])) {
$data['interface']['MTU'] = $this->getPacConf()[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu; $data['interface']['MTU'] = $pac[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu;
} }
} }
foreach ($data['interface'] as $k => $v) { foreach ($data['interface'] as $k => $v) {
$conf[] = "$k = $v"; $conf[] = "$k = $v";
} }
$pac = $this->getPacConf();
if (!empty($data['peers'])) { if (!empty($data['peers'])) {
foreach ($data['peers'] as $peer) { foreach ($data['peers'] as $peer) {
$conf[] = ''; $conf[] = '';
$conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]'; $conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]';
if (!empty($peer['Endpoint'])) { if (!empty($peer['Endpoint'])) {
$peer['Endpoint'] = ($this->getPacConf()[$this->getInstanceWG(1) . 'endpoint'] ? $this->ip : $this->getDomain()) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT'); $peer['Endpoint'] = ($pac[$this->getInstanceWG(1) . 'endpoint'] ? $this->ip : $this->getDomain()) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT');
} }
foreach ($peer as $k => $v) { foreach ($peer as $k => $v) {
$conf[] = "$k = $v"; $conf[] = "$k = $v";
+1
View File
@@ -13,5 +13,6 @@ if ($c['debug']) {
$bot = new Bot($c['key'], $i); $bot = new Bot($c['key'], $i);
$bot->restartTG(); $bot->restartTG();
$bot->dontshowcron = 1;
$bot->sslip(); $bot->sslip();
$bot->cleanDocker(); $bot->cleanDocker();
+6
View File
@@ -1,3 +1,9 @@
23.10.2024 v1.81
- фикс краша wireguard после апдейта
23.10.2024 v1.80
- фикс пустых правил для singbox
23.10.2024 v1.79
- улучшение процесса обновления
23.10.2024 v1.78 23.10.2024 v1.78
- фикс двойного импорта при обновлении, когда админов больше одного - фикс двойного импорта при обновлении, когда админов больше одного
- рестарт бота сбрасывает очередь сообщений от телеграма - рестарт бота сбрасывает очередь сообщений от телеграма