modified: app.py
modified: templates/logs.html
This commit is contained in:
21
app.py
21
app.py
@@ -167,5 +167,26 @@ def download_logs():
|
||||
return send_file(LOG_FILE_PATH, as_attachment=True)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
import shutil
|
||||
|
||||
ARCHIVE_DIR = "archive_logs"
|
||||
if not os.path.exists(ARCHIVE_DIR):
|
||||
os.makedirs(ARCHIVE_DIR)
|
||||
|
||||
@app.route("/archive_logs", methods=["POST"])
|
||||
def archive_logs():
|
||||
"""Archiviert die aktuelle Log-Datei und beginnt eine neue Log-Datei."""
|
||||
if "username" in session:
|
||||
if os.path.exists(LOG_FILE_PATH):
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
|
||||
archive_file = os.path.join(ARCHIVE_DIR, f"log_{timestamp}.log")
|
||||
shutil.move(LOG_FILE_PATH, archive_file)
|
||||
with open(LOG_FILE_PATH, 'w', encoding='utf-8') as file:
|
||||
file.write("") # Neue leere Log-Datei starten
|
||||
return jsonify({"status": "success", "message": "Logs archived successfully."})
|
||||
else:
|
||||
return jsonify({"status": "error", "message": "Log file not found."})
|
||||
return redirect(url_for("login"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
@@ -18,6 +18,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-warning mb-3" onclick="archiveLogs()">Archive Logs</button>
|
||||
|
||||
<script>
|
||||
function archiveLogs() {
|
||||
fetch('{{ url_for("archive_logs") }}', { method: "POST" })
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
alert(data.message);
|
||||
refreshLogs();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user