diff --git a/main.py b/main.py index 959a703..fb09afa 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ -from flask import Flask, render_template, jsonify, url_for +from flask import Flask, render_template, jsonify import requests from concurrent.futures import ThreadPoolExecutor import socket +import subprocess +import platform app = Flask(__name__) @@ -12,7 +14,7 @@ def check_status(site): elif ':22' in url: return check_ssh_status(site) else: - return {'url': url, 'title': site['title'], 'status': False} + return check_ping_status(site) def check_http_status(site): try: @@ -33,9 +35,20 @@ def check_ssh_status(site): except: return {'url': site['url'], 'title': site['title'], 'status': False} -#Add your URL´s here. -#For SSH-URL´s please don´t add the http:// and check the Port the SSH Server is running on -#For Normal URL´s please use http:// and the Port the Website runs on +def check_ping_status(site): + host = site['url'].split(':')[0] + param = '-n' if platform.system().lower() == 'windows' else '-c' + command = ['ping', param, '1', host] + try: + output = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + status = output.returncode == 0 + return {'url': site['url'], 'title': site['title'], 'status': status} + except Exception as e: + return {'url': site['url'], 'title': site['title'], 'status': False} + + #Add your URL´s here. + #For SSH-URL´s please don´t add the http:// and check the Port the SSH Server is running on + #For Normal URL´s please use http:// and the Port the Website runs on websites = [ {'url': '192.168.3.11:22', 'title': 'PVE Main'}, @@ -51,17 +64,30 @@ websites = [ {'url': 'http://192.168.3.21:8080', 'title': 'AMP'}, {'url': '192.168.100.16:22', 'title': 'VPN Tunnel'}, {'url': '192.168.3.30:22', 'title': 'Nextcloud'}, + {'url': '1.1.1.1', 'title': 'Outside'}, + +] +# Add the second Row of URL´s in the same Sceme +websites2 = [ + {'url': '192.168.100.65', 'title': 'MacBook'}, + {'url': '192.168.100.68', 'title': 'Desktop'}, + {'url': '192.168.100.80', 'title': 'iPhone'}, + {'url': '192.168.100.84', 'title': 'iPad'}, ] @app.route('/') def status_page(): - return render_template('status.html', websites=websites) + return render_template('status.html', websites=websites, websites2=websites2) @app.route('/update_status') def update_status(): with ThreadPoolExecutor(max_workers=10) as executor: - results = list(executor.map(check_status, websites)) - return jsonify(results) + results1 = list(executor.map(check_status, websites)) + results2 = list(executor.map(check_status, websites2)) + + # Combine results from both lists + combined_results = results1 + results2 + return jsonify(combined_results) if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True) \ No newline at end of file diff --git a/readme.md b/readme.md index e69de29..bd8b7a9 100644 --- a/readme.md +++ b/readme.md @@ -0,0 +1,47 @@ +## FoxStatus™ + +Das Programm ist eine Webanwendung, die den Status verschiedener Webseiten und Server überwacht. Es verwendet Flask, ein leichtgewichtiges Web-Framework für Python, um eine Benutzeroberfläche zu erstellen, die den aktuellen Status von angegebenen URLs anzeigt. Die Anwendung prüft, ob die Webseiten online oder offline sind und aktualisiert diese Informationen in Echtzeit. + +### Funktionsweise + +1. **Webseitenüberwachung**: + - Das Programm überprüft den Status von Webseiten und Servern, indem es verschiedene Protokolle wie HTTP, SSH und Ping verwendet. + - Für jede URL wird die entsprechende Überprüfungsmethode aufgerufen: + - **HTTP-Status**: Überprüfung, ob die Webseite erreichbar ist (Statuscode 200). + - **SSH-Status**: Überprüfung, ob der SSH-Dienst auf dem angegebenen Port läuft. + - **Ping-Status**: Überprüfung der Erreichbarkeit über das ICMP-Protokoll. + +2. **Benutzeroberfläche**: + - Die HTML-Seite zeigt die aktuelle Uhrzeit und das Datum an. + - Der Status jeder Webseite wird in Kartenform dargestellt, wobei der Hintergrund je nach Status (online oder offline) farblich angepasst wird. + +3. **Echtzeit-Updates**: + - Die Anwendung aktualisiert den Status der Webseiten alle 5 Sekunden und die Uhrzeit jede Sekunde durch AJAX-Anfragen an den Server. + +### Installationsanleitung + +Um das Programm zu installieren und auszuführen, folgen Sie diesen Schritten: + +1. **Voraussetzungen**: + - Stellen Sie sicher, dass Python 3.x installiert ist. + - Installieren Sie Flask und Requests mit pip: + ```bash + pip install -r requirements.txt + ``` + +3. **URLs anpassen**: + - Bearbeiten Sie die `websites` und `websites2` Listen in `main.py`, um Ihre eigenen URLs hinzuzufügen. + +4. **Server starten**: + - Führen Sie das Programm aus: + ```bash + python main.py + ``` + - Der Server sollte nun auf `http://127.0.0.1:5000` laufen. + +5. **Zugriff auf die Anwendung**: + - Öffnen Sie einen Webbrowser und navigieren Sie zur URL `http://127.0.0.1:5000`, um die Benutzeroberfläche anzuzeigen. + +### Fazit + +Dieses Programm bietet eine einfache Möglichkeit zur Überwachung des Status von Webseiten und Servern in einer benutzerfreundlichen Oberfläche. Durch regelmäßige Aktualisierungen bleibt der Benutzer stets informiert über den Zustand seiner Dienste. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e50f299 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.1.0 +Requests==2.32.3 diff --git a/templates/status.html b/templates/status.html index 7d0a812..846cfd0 100644 --- a/templates/status.html +++ b/templates/status.html @@ -82,11 +82,21 @@ {% for website in websites %}

{{ website.title }}

-

Checking...

{% endfor %} + +
+
+ {% for website in websites2 %} +
+

{{ website.title }}

+

Checking...

+
+ {% endfor %} +
+