From 8dd96a68f2e84a10b30c2cadcc2adc1372a8bf93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 24 Feb 2025 08:53:06 +0100 Subject: [PATCH] fix cron on start, move from nicorn to waitress --- app.py | 41 +++++++++++++++++++++++++++++++++++++++++ gunicorn_config.py | 7 ------- routeros_backup.service | 6 +++--- templates/settings.html | 9 +++++++++ 4 files changed, 53 insertions(+), 10 deletions(-) delete mode 100644 gunicorn_config.py diff --git a/app.py b/app.py index f52c56e..2784ee5 100644 --- a/app.py +++ b/app.py @@ -1390,6 +1390,47 @@ def delete_old_logs(): flash(f"Usunięto {deleted_count} logów starszych niż {delete_days} dni.") return redirect(url_for('logs_page')) +@app.route('/test_email', methods=['POST']) +@login_required +def test_email(): + s = get_settings() + # Sprawdzamy, czy ustawienia SMTP są skonfigurowane + if not (s.smtp_host and s.smtp_login and s.smtp_password): + flash("Brak skonfigurowanych ustawień SMTP.") + return redirect(url_for('settings_view')) + subject = "Testowy e-mail z RouterOS Backup" + body = "To jest testowa wiadomość e-mail wysłana z systemu RouterOS Backup." + success = send_mail_with_attachment( + smtp_host=s.smtp_host, + smtp_port=s.smtp_port, + smtp_user=s.smtp_login, + smtp_pass=s.smtp_password, + to_address=s.smtp_login, + subject=subject, + plain_body=body + ) + if success: + flash("Testowy e-mail został wysłany.") + else: + flash("Wysyłka testowego e-maila nie powiodła się.") + return redirect(url_for('settings_view')) + +@app.route('/test_pushover', methods=['POST']) +@login_required +def test_pushover(): + s = get_settings() + # Sprawdzamy, czy ustawienia Pushover są skonfigurowane + if not (s.pushover_token and s.pushover_userkey): + flash("Brak skonfigurowanych ustawień Pushover.") + return redirect(url_for('settings_view')) + message = "Testowe powiadomienie Pushover z systemu RouterOS Backup." + success = send_pushover(s.pushover_token, s.pushover_userkey, message) + if success: + flash("Testowe powiadomienie Pushover zostało wysłane.") + else: + flash("Wysyłka testowego powiadomienia Pushover nie powiodła się.") + return redirect(url_for('settings_view')) + if __name__ == '__main__': with app.app_context(): reschedule_jobs() diff --git a/gunicorn_config.py b/gunicorn_config.py deleted file mode 100644 index 2b682c8..0000000 --- a/gunicorn_config.py +++ /dev/null @@ -1,7 +0,0 @@ -bind = "0.0.0.0:81" -workers = 4 -timeout = 120 -server_header = False -def on_starting(server): - server.cfg.server_header = False - server.log.info("Server header disabled") diff --git a/routeros_backup.service b/routeros_backup.service index 943914f..267e3da 100644 --- a/routeros_backup.service +++ b/routeros_backup.service @@ -3,10 +3,10 @@ Description=RouterOS Backup Waitress Service After=network.target [Service] -User=routeros -Group=routeros +#User=routeros +#Group=routeros WorkingDirectory=/opt/routeros_backup -ExecStart=/opt/routeros_backup/venv/bin/python3 run_waitress.py +ExecStart=/opt/routeros_backup/venv/bin/python3 /opt/routeros_backup/run_waitress.py Restart=always Environment=PYTHONUNBUFFERED=1 diff --git a/templates/settings.html b/templates/settings.html index 8b20adb..e0e92ca 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -63,6 +63,15 @@ + +
+
+ +
+
+ +
+