addet static content.. WIP
This commit is contained in:
parent
9eab091e7c
commit
7f7853a412
5 changed files with 5479 additions and 48 deletions
Binary file not shown.
|
@ -8,6 +8,8 @@ import ipaddress
|
|||
from flask_wtf import CSRFProtect
|
||||
import markdown
|
||||
from datetime import datetime
|
||||
from flask import flash
|
||||
from app.utils.app_utils import validate_port_data
|
||||
|
||||
bp = Blueprint("api", __name__, url_prefix="/api")
|
||||
csrf = CSRFProtect()
|
||||
|
@ -284,61 +286,48 @@ def suggest_port(server_id):
|
|||
def add_app_port(app_id):
|
||||
"""Add a port to an application"""
|
||||
app = App.query.get_or_404(app_id)
|
||||
|
||||
# Accept both JSON and form data
|
||||
if request.is_json:
|
||||
data = request.json
|
||||
else:
|
||||
data = request.form
|
||||
|
||||
port_number = data.get("port")
|
||||
protocol = data.get("protocol", "TCP")
|
||||
description = data.get("description", "")
|
||||
|
||||
if not port_number:
|
||||
return jsonify({"success": False, "error": "Port number is required"}), 400
|
||||
|
||||
|
||||
try:
|
||||
port_number = int(port_number)
|
||||
|
||||
# Check if port already exists for this app
|
||||
existing_port = Port.query.filter_by(app_id=app_id, number=port_number).first()
|
||||
port_number = request.form.get("port_number")
|
||||
protocol = request.form.get("protocol", "TCP")
|
||||
description = request.form.get("description", "")
|
||||
|
||||
# Validate port data
|
||||
valid, clean_port, error = validate_port_data(port_number, protocol, description)
|
||||
|
||||
if not valid:
|
||||
return jsonify({"success": False, "error": error}), 400
|
||||
|
||||
# Check if port already exists
|
||||
existing_port = Port.query.filter_by(app_id=app_id, port_number=clean_port).first()
|
||||
if existing_port:
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"success": False,
|
||||
"error": "Port already exists for this application",
|
||||
}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": f"Port {clean_port} already exists for this application"
|
||||
}), 400
|
||||
|
||||
# Create new port
|
||||
port = Port(
|
||||
number=port_number,
|
||||
protocol=protocol,
|
||||
description=description,
|
||||
new_port = Port(
|
||||
app_id=app_id,
|
||||
port_number=clean_port,
|
||||
protocol=protocol,
|
||||
description=description
|
||||
)
|
||||
|
||||
db.session.add(port)
|
||||
db.session.add(new_port)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"success": True,
|
||||
"message": f"Port {port_number} added to {app.name}",
|
||||
"port": {
|
||||
"id": port.id,
|
||||
"number": port.number,
|
||||
"protocol": port.protocol,
|
||||
"description": port.description,
|
||||
},
|
||||
|
||||
flash(f"Port {clean_port}/{protocol} added successfully", "success")
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"Port {clean_port}/{protocol} added successfully",
|
||||
"port": {
|
||||
"id": new_port.id,
|
||||
"number": new_port.port_number,
|
||||
"protocol": new_port.protocol,
|
||||
"description": new_port.description
|
||||
}
|
||||
)
|
||||
except ValueError:
|
||||
return jsonify({"success": False, "error": "Invalid port number"}), 400
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
|
1814
app/static/libs/tabler-icons/fonts/tabler-icons.ttf
Normal file
1814
app/static/libs/tabler-icons/fonts/tabler-icons.ttf
Normal file
File diff suppressed because one or more lines are too long
1814
app/static/libs/tabler-icons/fonts/tabler-icons.woff
Normal file
1814
app/static/libs/tabler-icons/fonts/tabler-icons.woff
Normal file
File diff suppressed because one or more lines are too long
1814
app/static/libs/tabler-icons/fonts/tabler-icons.woff2
Normal file
1814
app/static/libs/tabler-icons/fonts/tabler-icons.woff2
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue