From 6fc7571e769c51d74e8a18204b15aa869a997e0e Mon Sep 17 00:00:00 2001 From: mercury Date: Fri, 17 Nov 2023 00:11:16 +0400 Subject: [PATCH] notify expire certificate --- app/bot.php | 26 +++++++++++++++++++++++++- dockerfile/php.dockerfile | 2 +- version | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/bot.php b/app/bot.php index 61fbd39..c8c92b4 100644 --- a/app/bot.php +++ b/app/bot.php @@ -605,6 +605,7 @@ class Bot $this->shutdownClient(); $this->checkVersion(); $this->checkBackup(); + $this->checkCert(); sleep(10); } } @@ -675,6 +676,23 @@ class Bot } } + public function checkCert() + { + try { + require __DIR__ . '/config.php'; + if (!empty($c['admin']) && (empty($this->time2) || ((time() - $this->time2) > 3600))) { + $this->time2 = time(); + $cert = $this->expireCert(); + if (!empty($cert) && $cert - 60 * 60 * 24 * 14 < time()) { + foreach ($c['admin'] as $k => $v) { + $this->send($v, "certificate expire: " . date('Y-m-d H:i:s', $cert)); + } + } + } + } catch (Exception $e) { + } + } + public function getTime(int $seconds) { $seconds = ($seconds - time()) > 0 ? $seconds - time() : 0; @@ -2867,6 +2885,12 @@ DNS-over-HTTPS with IP: ]; } + public function expireCert() + { + $c = openssl_x509_read(file_get_contents("/certs/cert_public")); + return openssl_x509_parse($c)["validTo_time_t"] ?: false; + } + public function configMenu() { $conf = $this->getPacConf(); @@ -2885,7 +2909,7 @@ DNS-over-HTTPS with IP: case 'letsencrypt': $data[] = [ [ - 'text' => $this->i18n('renew SSL'), + 'text' => $this->i18n('renew SSL') . ': ' . date('Y-m-d H:i:s', $this->expireCert()), 'callback_data' => "/setSSL letsencrypt", ], [ diff --git a/dockerfile/php.dockerfile b/dockerfile/php.dockerfile index 16f001f..7ab06d4 100644 --- a/dockerfile/php.dockerfile +++ b/dockerfile/php.dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.17 +FROM alpine:3.18.2 RUN apk add --no-cache --update php81 \ php81-mbstring \ php81-session \ diff --git a/version b/version index 110b555..b5e2497 100644 --- a/version +++ b/version @@ -1,3 +1,6 @@ +17.11.2023 уведомление о скорой просрочке сертификата +git pull +make r 12.11.2023 AdGuardHome latest docker image git pull make r