From 3c813fa0b1bbb1e07a68d6318d01e9da7619dbc2 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 11 Jul 2025 14:15:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=20(=D0=B7=D0=B5=D0=BB=D1=91=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9/=D0=BA=D1=80=D0=B0=D1=81=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=B2=D0=B0=D0=B4=D1=80=D0=B0=D1=82=D0=B8=D0=BA=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B4=D0=B0=D1=82=D1=8B)=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5,=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20Uptime=20Kuma=20=D0=B8=20=D0=B4=D1=80=D1=83=D0=B3?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B8=D0=B7=20config.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 6 +++++- config.yaml | 32 ++++++++++++++++++++++---------- main.py | 21 ++++++++++++++++++++- templates/index.html | 7 +++++++ 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index a08c835..634ceb0 100644 --- a/changelog.md +++ b/changelog.md @@ -21,4 +21,8 @@ - Перенесены ассеты из example/home_files в static/ ## [fix] Мгновенное применение изменений config.yaml на главной странице -- Исправлено: после сохранения config.yaml главная страница теперь сразу отображает актуальные данные (конфиг перечитывается при каждом запросе, кэш убран) \ No newline at end of file +- Исправлено: после сохранения config.yaml главная страница теперь сразу отображает актуальные данные (конфиг перечитывается при каждом запросе, кэш убран) + +## [feature] Индикатор статуса сервисов на главной странице +- Добавлен индикатор (зелёный/красный квадратик после даты) для отображения доступности всех сервисов из config.yaml (включая Uptime Kuma) +- Проверка доступности реализована через HTTP-запросы при каждом открытии главной страницы \ No newline at end of file diff --git a/config.yaml b/config.yaml index c9b1200..fe62cbf 100644 --- a/config.yaml +++ b/config.yaml @@ -119,14 +119,7 @@ bookmarks: - name: auto.ru url: http://auto.ru/ icon_name: truck - - group: Work - links: - - name: COPART - url: https://www.copart.com/ - icon_name: briefcase - - name: IAAI - url: https://www.iaai.com/ - icon_name: briefcase + - group: 3D links: - name: cults3d @@ -165,6 +158,13 @@ bookmarks: - name: Salvagedb url: https://salvagedb.com/ icon_name: database + - name: COPART + url: https://www.copart.com/ + icon_name: briefcase + - name: IAAI + url: https://www.iaai.com/ + icon_name: briefcase + - group: VPN links: - name: 3ui gui @@ -177,5 +177,17 @@ bookmarks: weather: api_key: "8e548386d3c6492f8ef220308231903" lat: 55.751244 - lon: 37,618423 - cache_ttl: 60 \ No newline at end of file + lon: 37.618423 + cache_ttl: 60 + +services: + - name: Uptime Kuma + url: http://192.168.1.222:3001/ + - name: PiHole X86 + url: https://192.168.1.11/admin + - name: Router + url: http://192.168.1.1/ + - name: Portainer + url: https://portainer.ddl.su/ + - name: Grafana + url: http://192.168.1.143:3000/ \ No newline at end of file diff --git a/main.py b/main.py index d1b8cd4..e422c4a 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import os import requests import time import locale +import socket app = Flask(__name__) @@ -104,6 +105,22 @@ def get_weather_forecast(): except: return {'_error': str(e)} +def check_services_status(services, timeout=2): + """ + Проверяет доступность всех сервисов из списка. + Возвращает True, если все доступны, иначе False. + """ + import requests + for srv in services: + url = srv.get('url') + try: + resp = requests.get(url, timeout=timeout, verify=False) + if not (200 <= resp.status_code < 400): + return False + except Exception: + return False + return True + @app.route('/api/config', methods=['GET']) def get_config(): try: @@ -151,7 +168,9 @@ def index(): current_time = now.strftime('%H:%M:%S') weather = get_weather() config = load_config() # Загружаем актуальный конфиг при каждом запросе - return render_template('index.html', applications=config['applications'], bookmarks=config['bookmarks'], now=now_str, current_time=current_time, weather=weather) + services = config.get('services', []) + all_services_up = check_services_status(services) if services else None + return render_template('index.html', applications=config['applications'], bookmarks=config['bookmarks'], now=now_str, current_time=current_time, weather=weather, all_services_up=all_services_up) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0') diff --git a/templates/index.html b/templates/index.html index 3698a7b..16ea5f3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -29,6 +29,13 @@
{{ current_time }} {{ now }} + {% if all_services_up is not none %} + {% if all_services_up %} + + {% else %} + + {% endif %} + {% endif %}