From a8054d3e68fbbb55b7bd677a0fff5f7cd3b923b2 Mon Sep 17 00:00:00 2001 From: mercury Date: Mon, 5 Jun 2023 13:39:24 +0400 Subject: [PATCH] versioning --- app/bot.php | 45 +++++++++++++++++++++++++++++++++++---------- docker-compose.yml | 1 + version | 1 + 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 version diff --git a/app/bot.php b/app/bot.php index d162407..c44716c 100644 --- a/app/bot.php +++ b/app/bot.php @@ -541,20 +541,45 @@ class Bot public function cron() { while (true) { - try { - $clients = $this->readClients(); - if ($clients) { - foreach ($clients as $k => $v) { - if (!empty($v['interface']['## time'])) { - if (strtotime($v['interface']['## time']) < time()) { - $this->switchClient($k); - } + $this->shutdownClient(); + $this->checkVersion(); + sleep(10); + } + } + + public function checkVersion() + { + try { + require __DIR__ . '/config.php'; + if (!empty($c['admin'])) { + $current = file_get_contents('/version'); + $last = file_get_contents('https://raw.githubusercontent.com/mercurykd/vpnbot/master/version'); + if (!empty($last) && $last != $this->last && $last != $current) { + $this->last = $last; + $diff = implode("\n", array_diff(explode("\n", $last), explode("\n", $current))); + foreach ($c['admin'] as $k => $v) { + $this->send($v, "update:\n$diff"); + } + } + } + } catch (Exception $e) { + } + } + + public function shutdownClient() + { + try { + $clients = $this->readClients(); + if ($clients) { + foreach ($clients as $k => $v) { + if (!empty($v['interface']['## time'])) { + if (strtotime($v['interface']['## time']) < time()) { + $this->switchClient($k); } } } - } catch (Exception $e) { } - sleep(10); + } catch (Exception $e) { } } diff --git a/docker-compose.yml b/docker-compose.yml index a6d77b5..62a14bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -72,6 +72,7 @@ services: - ./logs/:/logs/ - ./scripts/start_unit.sh:/start_unit.sh - ./scripts/check_file.sh:/check_file.sh + - ./version:/version environment: TZ: ${TZ} IP: ${IP} diff --git a/version b/version new file mode 100644 index 0000000..cac0dc7 --- /dev/null +++ b/version @@ -0,0 +1 @@ +05.06.2023 версионирование \ No newline at end of file