📁 Quản Lý & Sửa File Nhanh
Mở Trang Reels (Port 5000) ↗
Danh sách file trong /home/luan
📄 ai_post.py
📄 bai_dang_affiliate.txt
📄 batch_gen.py
📄 dashboard.log
📄 docker-compose.yml
📄 editor.log
📄 fb_auto_post.py
📄 file_editor.py
📄 filebrowser.log
📄 loi_binh.mp3
📄 products_state.json
📄 sensor.py
📄 web_dashboard.py
✏️ Đang sửa: file_editor.py
import os, glob from flask import Flask, request, redirect, render_template_string app = Flask(__name__) BASE_DIR = "/home/luan" HTML = """ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Trình Sửa File Trực Tiếp</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light p-4"> <div class="container" style="max-width: 1000px;"> <div class="d-flex justify-content-between align-items-center mb-3"> <h4 class="text-primary fw-bold mb-0">📁 Quản Lý & Sửa File Nhanh</h4> <a href="http://192.168.5.56:5000" target="_blank" class="btn btn-sm btn-outline-success">Mở Trang Reels (Port 5000) ↗</a> </div> {% if msg %} <div class="alert alert-success py-2">{{ msg }}</div> {% endif %} <div class="card shadow-sm border-0 mb-3"> <div class="card-header bg-dark text-white fw-bold">Danh sách file trong /home/luan</div> <div class="card-body p-2"> <div class="d-flex flex-wrap gap-2"> {% for f in files %} <a href="/?file={{ f }}" class="btn btn-sm {% if cur_file == f %}btn-primary{% else %}btn-outline-secondary{% endif %}"> 📄 {{ f }} </a> {% endfor %} </div> </div> </div> {% if cur_file %} <div class="card shadow-sm border-0"> <div class="card-header bg-primary text-white fw-bold d-flex justify-content-between align-items-center"> <span>✏️ Đang sửa: {{ cur_file }}</span> </div> <div class="card-body"> <form method="POST" action="/save"> <input type="hidden" name="filename" value="{{ cur_file }}"> <div class="mb-3"> <textarea name="content" rows="23" class="form-control font-monospace bg-dark text-light" style="font-size: 13px; tab-size: 4;" wrap="off">{{ content }}</textarea> </div> <button type="submit" class="btn btn-success fw-bold px-4 py-2">💾 LƯU FILE & KHỞI ĐỘNG LẠI DASHBOARD</button> </form> </div> </div> {% endif %} </div> </body> </html> """ @app.route("/", methods=["GET"]) def index(): cur_file = request.args.get("file", "web_dashboard.py") files = [os.path.basename(p) for p in glob.glob(os.path.join(BASE_DIR, "*")) if os.path.isfile(p)] files.sort() file_path = os.path.join(BASE_DIR, cur_file) content = "" if os.path.exists(file_path): try: with open(file_path, "r", encoding="utf-8") as f: content = f.read() except Exception as e: content = f"Lỗi đọc file: {e}" msg = request.args.get("msg", "") return render_template_string(HTML, files=files, cur_file=cur_file, content=content, msg=msg) @app.route("/save", methods=["POST"]) def save(): filename = request.form.get("filename", "") content = request.form.get("content", "") file_path = os.path.join(BASE_DIR, filename) with open(file_path, "w", encoding="utf-8") as f: f.write(content) if filename == "web_dashboard.py": os.system("pkill -f web_dashboard.py; nohup python3 /home/luan/web_dashboard.py > /home/luan/dashboard.log 2>&1 &") return redirect(f"/?file={filename}&msg=Đã lưu file thành công!") if __name__ == "__main__": app.run(host="0.0.0.0", port=8888)
💾 LƯU FILE & KHỞI ĐỘNG LẠI DASHBOARD