Compare commits

...

2 Commits

Author SHA1 Message Date
mercury d225e7c039 fix double import after update 2024-10-23 02:06:35 +04:00
mercury 3b9b930b48 - autobackup check formate
- cron status
- fix with sending a backup when there are special characters in the bot name
2024-10-23 01:24:36 +04:00
3 changed files with 58 additions and 29 deletions
+49 -29
View File
@@ -1081,15 +1081,23 @@ class Bot
[$start, $period] = explode('/', $c['backup']); [$start, $period] = explode('/', $c['backup']);
$start = strtotime($start); $start = strtotime($start);
$period = strtotime($period, 0); $period = strtotime($period, 0);
if ($now - $start >= $period && ($now - $start) % $period == 0) { if (!empty($start) && !empty($period)) {
if (!empty($c['pinbackup'])) { if ($now - $start >= $period && ($now - $start) % $period == 0) {
$this->pinAdmin($c['pinbackup'], 1); if (!empty($c['pinbackup'])) {
$this->pinAdmin($c['pinbackup'], 1);
}
$this->pinBackup();
} }
$this->pinBackup();
} }
} }
} }
public function cleanQueue()
{
$r = $this->request('deleteWebhook', []);
$r = $this->request('getUpdates', ['offset' => -1]);
}
public function pinAdmin($pin, $unpin = false) public function pinAdmin($pin, $unpin = false)
{ {
require __DIR__ . '/config.php'; require __DIR__ . '/config.php';
@@ -1296,7 +1304,7 @@ class Bot
if (!empty($file)) { if (!empty($file)) {
file_put_contents($file, $json); file_put_contents($file, $json);
} }
$bot = $this->request('getMyName', [])['result']['name']; $bot = preg_replace('~[\W]~iu', '_', $this->request('getMyName', [])['result']['name']);
return $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $json); return $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $json);
} }
@@ -1785,11 +1793,18 @@ class Bot
public function sslip() public function sslip()
{ {
$c = $this->getPacConf(); require __DIR__ . '/config.php';
if (empty($c['domain'])) { $p = $this->getPacConf();
$ip = getenv('IP');
$r = $this->send($c['admin'][0], "start $ip");
$this->input['chat'] = $c['admin'][0];
$this->input['message_id'] = $r['result']['message_id'];
if (empty($p['domain'])) {
$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);
} }
public function comment($text, $tag) public function comment($text, $tag)
@@ -3840,12 +3855,13 @@ DNS-over-HTTPS with IP:
$this->menu('wg', 0); $this->menu('wg', 0);
} }
public function menu($type = false, $arg = false, $return = false) public function menu($type = false, $arg = false, $return = false, $dontshowcron = false)
{ {
$domain = $this->getPacConf()['domain'] ?: $this->ip; $domain = $this->getPacConf()['domain'] ?: $this->ip;
$cron = exec('pgrep -f cron.php');
$menu = [ $menu = [
'main' => [ 'main' => [
'text' => 'v' . getenv('VER'), 'text' => 'v' . getenv('VER') . ($dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show <code>logs/php_error</code>')),
'data' => [ 'data' => [
[ [
[ [
@@ -5565,7 +5581,11 @@ DNS-over-HTTPS with IP:
]; ];
$backup = array_filter(explode('/', $conf['backup'])); $backup = array_filter(explode('/', $conf['backup']));
if (!empty($backup)) { if (!empty($backup)) {
$backup = "{$backup[0]} start / {$backup[1]} period"; if (!empty(strtotime($backup[0])) && !empty(strtotime($backup[1]))) {
$backup = "{$backup[0]} start / {$backup[1]} period";
} else {
$backup = $this->i18n('off') . " {$conf['backup']} - wrong format";
}
} }
$data[] = [ $data[] = [
[ [
@@ -5717,25 +5737,21 @@ DNS-over-HTTPS with IP:
$ip = getenv('IP'); $ip = getenv('IP');
$rm = explode(':', trim(file_get_contents('/update/reload_message'))); $rm = explode(':', trim(file_get_contents('/update/reload_message')));
$m = file_get_contents('/update/message'); $m = file_get_contents('/update/message');
foreach ($c['admin'] as $k => $v) { if (file_exists($this->update)) {
$r = $this->send($v, "start $ip"); $r = $this->send($c['admin'][0], "start update");
$this->input['chat'] = $v; $this->input['chat'] = $c['admin'][0];
$this->input['message_id'] = $r['result']['message_id']; $this->input['message_id'] = $r['result']['message_id'];
if (file_exists($this->update)) { if (!empty($m)) {
if (!empty($m)) { $this->send($c['admin'][0], "<pre>$m</pre>", $rm[1]);
$this->send($v, "<pre>$m</pre>", $v == $rm[0] ? $rm[1] : 0); }
} $r = $this->send($c['admin'][0], "import settings");
$r = $this->send($v, "import settings"); $this->input['chat'] = $c['admin'][0];
$this->input['chat'] = $v; $this->input['message_id'] = $r['result']['message_id'];
$this->input['message_id'] = $r['result']['message_id']; $this->input['callback_id'] = $r['result']['message_id'];
$this->input['callback_id'] = $r['result']['message_id']; if (empty($flag)) {
if (empty($flag)) { $this->importFile($this->update);
$this->importFile($this->update); unlink($this->update);
unlink($this->update); $flag = true;
$flag = true;
}
} else {
$this->menu();
} }
} }
} }
@@ -5875,7 +5891,11 @@ DNS-over-HTTPS with IP:
$c['backup'] = ''; $c['backup'] = '';
} else { } else {
[$start, $period] = explode('/', $text); [$start, $period] = explode('/', $text);
$c['backup'] = implode(' / ', [date('Y-m-d H:i', strtotime($start)), trim($period)]); if (!empty(strtotime($start)) && !empty(strtotime($period))) {
$c['backup'] = implode(' / ', [date('Y-m-d H:i', strtotime($start)), trim($period)]);
} else {
$this->send($this->input['from'], $this->input['message'] . ' - wrong format');
}
} }
if ($c['pinbackup']) { if ($c['pinbackup']) {
$this->pinAdmin($c['pinbackup'], 1); $this->pinAdmin($c['pinbackup'], 1);
+1
View File
@@ -10,6 +10,7 @@ if ($c['debug']) {
} }
$bot = new Bot($c['key'], $i); $bot = new Bot($c['key'], $i);
$bot->cleanQueue();
$bot->setwebhook(); $bot->setwebhook();
$bot->selfUpdate(); $bot->selfUpdate();
$bot->adguardCheckPswd(); $bot->adguardCheckPswd();
+8
View File
@@ -1,3 +1,11 @@
23.10.2024 v1.78
- фикс двойного импорта при обновлении, когда админов больше одного
- рестарт бота сбрасывает очередь сообщений от телеграма
- при старте статус крона не показывается, т.к он еще не успел запуститься
23.10.2024 v1.77
- вывод статуса cron
- фикс с отправкой бэкапа при спецсимволах в названии бота
- проверка формата времени в автобэкапе
22.10.2024 v1.76 22.10.2024 v1.76
- улучшение определения ip бота при старте - улучшение определения ip бота при старте
22.10.2024 v1.75 22.10.2024 v1.75