diff --git a/app/bot.php b/app/bot.php
index dd04130..4ce2f63 100644
--- a/app/bot.php
+++ b/app/bot.php
@@ -63,7 +63,7 @@ class Bot
$c['admin'] = [$c['admin']];
file_put_contents($file, "input['from'], $c['admin'])) {
- $this->send($this->input['chat'], 'you are not authorized', $this->input['message_id']);
+ // $this->send($this->input['chat'], 'you are not authorized', $this->input['message_id']);
exit;
}
}
@@ -127,6 +127,9 @@ class Bot
case preg_match('~^/debug$~', $this->input['callback'], $m):
$this->debug();
break;
+ case preg_match('~^/backup$~', $this->input['callback'], $m):
+ $this->backup();
+ break;
case preg_match('~^/generateSecret$~', $this->input['callback'], $m):
$this->generateSecret();
break;
@@ -276,7 +279,7 @@ class Bot
$this->showpac();
break;
case preg_match('~^/export$~', $this->input['callback'], $m):
- $this->export();
+ $this->exportManual();
break;
case preg_match('~^/import$~', $this->input['callback'], $m):
$this->import();
@@ -554,10 +557,54 @@ class Bot
while (true) {
$this->shutdownClient();
$this->checkVersion();
+ $this->checkBackup();
sleep(10);
}
}
+ public function checkBackup()
+ {
+ $c = time();
+ $conf = $this->getPacConf();
+ $time = $conf['backup'];
+ if ($time) {
+ preg_match('~(\d+\s\w+)(?:\s+)?/(?:\s+)?(\d{2}:\d{2})~', $time, $m);
+ $period = strtotime($m[1]) - $c;
+ $start = strtotime($m[2]);
+ $last = $conf['pinbackup'];
+ if ($last) {
+ [$pin, $time] = explode('/', $last);
+ if ($c - $time >= $period) {
+ $this->pinAdmin($pin, 1);
+ $this->pinBackup();
+ return;
+ }
+ } elseif ($c - $start > 0 && $c - $start < 30) {
+ $this->pinBackup();
+ }
+ }
+ }
+
+ public function pinAdmin($pin, $unpin = false)
+ {
+ require __DIR__ . '/config.php';
+ if ($unpin) {
+ return $this->unpin($c['admin'][0], $pin);
+ } else {
+ return $this->pin($c['admin'][0], $pin);
+ }
+ }
+
+ public function pinBackup()
+ {
+ require __DIR__ . '/config.php';
+ $conf = $this->getPacConf();
+ $pin = $this->upload('vpnbot_export_' . date('d_m_Y_H_i') . '.json', $this->export(), $c['admin'][0])['result']['message_id'];
+ $conf['pinbackup'] = "$pin/" . time();
+ $this->setPacConf($conf);
+ $this->pinAdmin($pin);
+ }
+
public function checkVersion()
{
try {
@@ -673,7 +720,28 @@ class Bot
'mtproto' => file_get_contents('/config/mtprotosecret'),
];
- $this->upload('vpnbot_export_' . date('d_m_Y_H_i') . '.json', json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+ return json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+ }
+
+ public function exportManual()
+ {
+ $conf = [
+ 'wg' => [
+ 'server' => $this->readConfig(),
+ 'clients' => json_decode(file_get_contents($this->clients), true) ?: [],
+ ],
+ 'ss' => $this->getSSConfig(),
+ 'sl' => $this->getSSLocalConfig(),
+ 'ad' => yaml_parse_file('/config/adguard/AdGuardHome.yaml'),
+ 'pac' => $this->getPacConf(),
+ 'ssl' => [
+ 'private' => file_exists('/certs/cert_private') ? file_get_contents('/certs/cert_private') : false,
+ 'public' => file_exists('/certs/cert_public') ? file_get_contents('/certs/cert_public') : false,
+ ],
+ 'mtproto' => file_get_contents('/config/mtprotosecret'),
+
+ ];
+ return $this->upload('vpnbot_export_' . date('d_m_Y_H_i') . '.json', $this->export());
}
public function import()
@@ -888,15 +956,16 @@ class Bot
}
}
- public function upload($name, $code)
+ public function upload($name, $code, $chat = false)
{
$path = "/logs/$name";
file_put_contents($path, $code);
- $this->sendFile(
- $this->input['chat'],
+ $r = $this->sendFile(
+ $chat ?: $this->input['chat'],
curl_file_create($path),
);
unlink($path);
+ return $r;
}
public function proxy()
@@ -2662,6 +2731,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/export",
],
];
+ $data[] = [
+ [
+ 'text' => $this->i18n('backup') . ': ' . (implode(' / ', explode('/', $conf['backup'])) ?: 'off'),
+ 'callback_data' => "/backup",
+ ],
+ ];
$data[] = [
[
'text' => $this->i18n($conf['blinkmenu'] ? 'blinkmenuon' : 'blinkmenuoff'),
@@ -2686,6 +2761,41 @@ DNS-over-HTTPS with IP:
];
}
+ public function backup()
+ {
+ $r = $this->send(
+ $this->input['chat'],
+ "@{$this->input['username']} enter like 1 day/00:00",
+ $this->input['message_id'],
+ reply: 'enter like 1 day/00:00',
+ );
+ $_SESSION['reply'][$r['result']['message_id']] = [
+ 'start_message' => $this->input['message_id'],
+ 'start_callback' => $this->input['callback_id'],
+ 'callback' => 'setBackup',
+ 'args' => [],
+ ];
+ }
+
+ public function setBackup($text)
+ {
+ $text = trim($text);
+ $c = $this->getPacConf();
+ if (empty($text)) {
+ $c['backup'] = '';
+ } elseif (preg_match('~(\d+\s\w+)(?:\s+)?/(?:\s+)?(\d{2}:\d{2})~', $text, $m)) {
+ $period = $m[1];
+ $start = $m[2];
+ $c['backup'] = $text;
+ }
+ if ($pin = explode('/', $c['pinbackup'])[0]) {
+ $this->pinAdmin($pin, 1);
+ $c['pinbackup'] = '';
+ }
+ $this->setPacConf($c);
+ $this->menu('config');
+ }
+
public function debug()
{
$file = __DIR__ . '/config.php';
@@ -3127,4 +3237,23 @@ DNS-over-HTTPS with IP:
];
return $this->request('deleteMessage', $data);
}
+
+ public function pin($chat, $message_id, $notnotify = true)
+ {
+ $data = [
+ 'chat_id' => $chat,
+ 'message_id' => $message_id,
+ 'disable_notification' => $notnotify,
+ ];
+ return $this->request('pinChatMessage', $data);
+ }
+
+ public function unpin($chat, $message_id)
+ {
+ $data = [
+ 'chat_id' => $chat,
+ 'message_id' => $message_id,
+ ];
+ return $this->request('unpinChatMessage', $data);
+ }
}
diff --git a/app/i18n.php b/app/i18n.php
index 9e7a562..8c90262 100644
--- a/app/i18n.php
+++ b/app/i18n.php
@@ -241,4 +241,8 @@ $i = [
'en' => 'debug mode',
'ru' => 'режим отладки',
],
+ 'backup' => [
+ 'en' => 'backup',
+ 'ru' => 'бэкап',
+ ],
];
diff --git a/dockerfile/adguard.dockerfile b/dockerfile/adguard.dockerfile
index a5e3104..4bf6a30 100644
--- a/dockerfile/adguard.dockerfile
+++ b/dockerfile/adguard.dockerfile
@@ -6,11 +6,11 @@ run apt update && \
apt install -y git net-tools lsof ssh wget && \
apt clean autoclean && \
apt autoremove -y && \
-wget https://github.com/AdguardTeam/AdGuardHome/releases/download/v0.107.31/AdGuardHome_linux_amd64.tar.gz && \
+wget https://github.com/ameshkov/dnslookup/releases/download/v1.8.1/dnslookup-linux-amd64-v1.8.1.tar.gz && \
+tar -xf dnslookup-linux-amd64-v1.8.1.tar.gz
+run wget https://github.com/AdguardTeam/AdGuardHome/releases/download/v0.107.31/AdGuardHome_linux_amd64.tar.gz && \
tar -xf AdGuardHome_linux_amd64.tar.gz && \
mkdir -p /opt/adguardhome && \
mkdir /root/.ssh && \
-wget https://github.com/ameshkov/dnslookup/releases/download/v1.8.1/dnslookup-linux-amd64-v1.8.1.tar.gz && \
-tar -xf dnslookup-linux-amd64-v1.8.1.tar.gz
copy config/AdGuardHome.yaml /opt/adguardhome/AdGuardHome.yaml
env PATH="$PATH:/linux-amd64"
diff --git a/version b/version
index 6e18492..f74c43b 100644
--- a/version
+++ b/version
@@ -1,3 +1,6 @@
+18.06.2023 бэкап по крону
+git pull
+make r
18.06.2023 изменение меню MTProto
git pull
16.06.2023 время пира в абсолютном формате