From 37d392a2404e82ff1f5ca54b89a439d2d98a3c8f Mon Sep 17 00:00:00 2001 From: mercury Date: Sat, 16 Nov 2024 01:10:47 +0400 Subject: [PATCH] update backup --- app/bot.php | 34 ++++++++++++++-------------------- scripts/dns_close_53_port.sh | 5 ----- scripts/dns_open_53_port.sh | 8 -------- 3 files changed, 14 insertions(+), 33 deletions(-) delete mode 100755 scripts/dns_close_53_port.sh delete mode 100755 scripts/dns_open_53_port.sh diff --git a/app/bot.php b/app/bot.php index 52c597d..9b89e02 100644 --- a/app/bot.php +++ b/app/bot.php @@ -600,7 +600,7 @@ class Bot $this->addOverrideHtml(); break; case preg_match('~^/export$~', $this->input['callback'], $m): - $this->exportManual(); + $this->pinBackup(); break; case preg_match('~^/import$~', $this->input['callback'], $m): $this->import(); @@ -1228,7 +1228,7 @@ class Bot public function checkBackup($delta) { - $c = $this->getPacConf(); + $c = $this->getPacConf(); if (!empty($c['backup'])) { $now = strtotime(date('Y-m-d H:i:s')); [$start, $period] = explode('/', $c['backup']); @@ -1241,9 +1241,6 @@ class Bot && $now - $start >= 0 && (($now - $start) % $period < $delta) ) { - if (!empty($c['pinbackup'])) { - $this->pinAdmin($c['pinbackup'], 1); - } $this->pinBackup(); } } @@ -1265,12 +1262,19 @@ class Bot } } - public function pinBackup() + public function pinBackup($file = false) { require __DIR__ . '/config.php'; - $conf = $this->getPacConf(); - $bot = preg_replace('~[\W]~iu', '_', $this->request('getMyName', [])['result']['name']); - $conf['pinbackup'] = $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $this->export(), $c['admin'][0])['result']['message_id']; + $conf = $this->getPacConf(); + $bot = preg_replace('~[\W]~iu', '_', $this->request('getMyName', [])['result']['name']); + $json = $this->export(); + if (!empty($file)) { + file_put_contents($file, $json); + } + if (!empty($conf['pinbackup'])) { + $this->pinAdmin($conf['pinbackup'], 1); + } + $conf['pinbackup'] = $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $json, $c['admin'][0])['result']['message_id']; $this->setPacConf($conf); $this->pinAdmin($conf['pinbackup']); } @@ -1458,16 +1462,6 @@ class Bot return json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } - public function exportManual($file = false) - { - $json = $this->export(); - if (!empty($file)) { - file_put_contents($file, $json); - } - $bot = preg_replace('~[\W]~iu', '_', $this->request('getMyName', [])['result']['name']); - return $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $json); - } - public function import() { $r = $this->send( @@ -6372,7 +6366,7 @@ DNS-over-HTTPS with IP: public function applyupdatebot() { - $this->exportManual($this->update); + $this->pinBackup($this->update); $r = $this->send($this->input['from'], 'update...'); file_put_contents('/update/reload_message', "{$this->input['from']}:{$r['result']['message_id']}"); file_put_contents('/update/key', $this->key); diff --git a/scripts/dns_close_53_port.sh b/scripts/dns_close_53_port.sh deleted file mode 100755 index ea175d4..0000000 --- a/scripts/dns_close_53_port.sh +++ /dev/null @@ -1,5 +0,0 @@ -make d -rm /etc/systemd/resolved.conf.d/adguardhome.conf -mv /etc/resolv.conf.backup /etc/resolv.conf -systemctl reload-or-restart systemd-resolved -make u diff --git a/scripts/dns_open_53_port.sh b/scripts/dns_open_53_port.sh deleted file mode 100755 index 785e6bd..0000000 --- a/scripts/dns_open_53_port.sh +++ /dev/null @@ -1,8 +0,0 @@ -mkdir /etc/systemd/resolved.conf.d -echo "[Resolve] -DNS=127.0.0.1 -DNSStubListener=no" > /etc/systemd/resolved.conf.d/adguardhome.conf -mv /etc/resolv.conf /etc/resolv.conf.backup -ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf -systemctl reload-or-restart systemd-resolved -make d u