diff --git a/scripts/handler/upload_server.py b/scripts/handler/upload_server.py
index 09f33737..f923a6d5 100755
--- a/scripts/handler/upload_server.py
+++ b/scripts/handler/upload_server.py
@@ -9,7 +9,7 @@ import shutil
import time
import io
-from flask import Flask, request, jsonify, send_file
+from flask import Flask, request, jsonify, send_file, redirect
from flask_cors import CORS
from werkzeug.utils import secure_filename
@@ -21,14 +21,12 @@ from flask_admin import Admin, AdminIndexView, expose
from flask_admin.contrib.sqla import ModelView
from main import process_single_file, rebuild_indexes, generate_manifests, slugify
-from utils import ALLOWED_EXTENSIONS, ALLOWED_SAMPLE_EXTENSIONS, MMP_FOLDER, MMPZ_FOLDER, DATA_FOLDER, CERT_PATH, KEY_PATH, BASE_DATA, SRC_MMPSEARCH, SAMPLE_SRC, METADATA_FOLDER, XML_IMPORTED_PATH_PREFIX, SAMPLE_MANIFEST
+from utils import ALLOWED_EXTENSIONS, ALLOWED_SAMPLE_EXTENSIONS, MMP_FOLDER, MMPZ_FOLDER, DATA_FOLDER, BASE_DATA, SRC_MMPSEARCH, SAMPLE_SRC, METADATA_FOLDER, XML_IMPORTED_PATH_PREFIX, SAMPLE_MANIFEST
app = Flask(__name__)
# --- CONFIGURAÇÃO DE SEGURANÇA E BANCO ---
-# IMPORTANTE: Troque esta chave em produção!
app.config['SECRET_KEY'] = '25de5592bf94c2ca18e27baa0ae2d4ee22a63012f32e1be719d31f530c215a387b9ec0c9d96be38e80a7ccdd859e04408facefff8fd9119e7f5a2d987d85abb7'
-# O banco ficará salvo em /nethome/jotachina/projetos/mmpSearch/users.db (BASE_DATA)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(DATA_FOLDER, 'users.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
@@ -56,12 +54,17 @@ class SecureModelView(ModelView):
# Retorna erro JSON ou redireciona (como é painel, melhor redirecionar ou negar)
return jsonify({"error": "Acesso restrito a administradores."}), 403
-# Classe para proteger a Home do Admin (Dashboard)
class SecureIndexView(AdminIndexView):
@expose('/')
def index(self):
if not current_user.is_authenticated or not current_user.is_admin:
- return jsonify({"error": "Acesso restrito."}), 403
+ # Em vez de retornar JSON, redireciona para a home
+ # O usuário verá o botão de login lá.
+ return redirect('/')
+
+ # OU, se quiser ser mais explícito, retorna 403 mas em HTML (opcional)
+ # return "
Acesso Negado
Você precisa ser admin.
", 403
+
return super(SecureIndexView, self).index()
# Cria o banco na inicialização se não existir
@@ -72,7 +75,7 @@ with app.app_context():
def load_user(user_id):
return User.query.get(int(user_id))
-# --- SUAS FUNÇÕES UTILITÁRIAS MANTIDAS ---
+# --- FUNÇÕES UTILITÁRIAS ---
def allowed_file(filename):
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
@@ -81,8 +84,9 @@ def allowed_sample(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_SAMPLE_EXTENSIONS
def run_jekyll_build():
+ BUNDLE_PATH = "/nethome/jotachina/projetos/mmpSearch/vendor/bundle/ruby/3.2.0/bin/bundle"
print("Iniciando build do Jekyll...")
- command = ["bundle", "exec", "jekyll", "build", "--destination", "/var/www/html/trens/mmpSearch/"]
+ command = [BUNDLE_PATH, "exec", "jekyll", "build", "--destination", "/var/www/html/trens/mmpSearch/"]
try:
subprocess.run(command, check=True, cwd=BASE_DATA, capture_output=True, text=True)
print("Jekyll Build Sucesso!")
@@ -436,7 +440,8 @@ def upload_sample_standalone():
admin = Admin(
app,
name='MMP Admin',
- index_view=SecureIndexView(url='/api/admin')
+ url='/api/admin',
+ index_view=SecureIndexView()
)
# Adiciona a visualização da tabela de Usuários