Files
Juan Denis 55d8fb1e44 Read route bodies through json_object()
328 more routes used a JSON body as a dict straight from
request.get_json(), so a body of null, [] or a bare string crashed them
into a 500. Bare reads become json_object(); the
'get_json(silent=True) or {}' reads of action routes become
json_object(optional=True), which still treats a missing body as {}.
Routes that take arrays or pass the body through untouched are left
alone. The full backend suite shows no new failures.

Also carries three files' bare section citations (apps, backups,
notifications) and the extended citation guard, which needed them.
2026-10-10 20:53:43 -04:00

65 lines
2.1 KiB
Python

from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required
from app.services.nginx_advanced_service import NginxAdvancedService
from app.middleware.rbac import get_current_user
from app.api._request import json_object
nginx_advanced_bp = Blueprint('nginx_advanced', __name__)
@nginx_advanced_bp.route('/proxy/<domain>', methods=['GET'])
@jwt_required()
def get_proxy_rules(domain):
result = NginxAdvancedService.get_proxy_rules(domain)
if 'error' in result:
return jsonify(result), 404
return jsonify(result)
@nginx_advanced_bp.route('/test', methods=['POST'])
@jwt_required()
def test_config():
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
result = NginxAdvancedService.test_config()
return jsonify(result)
@nginx_advanced_bp.route('/reload', methods=['POST'])
@jwt_required()
def reload():
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
result = NginxAdvancedService.reload_nginx()
return jsonify(result)
@nginx_advanced_bp.route('/diff', methods=['POST'])
@jwt_required()
def preview_diff():
# Admin-only: the diff includes the CURRENT vhost file's contents, so this
# is a file read as much as a preview.
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
data = json_object()
domain = data.get('domain')
new_config = data.get('config', '')
if not domain:
return jsonify({'error': 'domain required'}), 400
result = NginxAdvancedService.preview_diff(domain, new_config)
if 'error' in result:
return jsonify(result), 400
return jsonify(result)
@nginx_advanced_bp.route('/logs/<domain>', methods=['GET'])
@jwt_required()
def get_logs(domain):
log_type = request.args.get('type', 'access')
lines = request.args.get('lines', 100, type=int)
result = NginxAdvancedService.get_vhost_logs(domain, log_type, lines)
return jsonify(result)