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
|
from flask_wtf import CSRFProtect
|
||||||
import markdown
|
import markdown
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from flask import flash
|
||||||
|
from app.utils.app_utils import validate_port_data
|
||||||
|
|
||||||
bp = Blueprint("api", __name__, url_prefix="/api")
|
bp = Blueprint("api", __name__, url_prefix="/api")
|
||||||
csrf = CSRFProtect()
|
csrf = CSRFProtect()
|
||||||
|
@ -285,60 +287,47 @@ def add_app_port(app_id):
|
||||||
"""Add a port to an application"""
|
"""Add a port to an application"""
|
||||||
app = App.query.get_or_404(app_id)
|
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:
|
try:
|
||||||
port_number = int(port_number)
|
port_number = request.form.get("port_number")
|
||||||
|
protocol = request.form.get("protocol", "TCP")
|
||||||
|
description = request.form.get("description", "")
|
||||||
|
|
||||||
# Check if port already exists for this app
|
# Validate port data
|
||||||
existing_port = Port.query.filter_by(app_id=app_id, number=port_number).first()
|
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:
|
if existing_port:
|
||||||
return (
|
return jsonify({
|
||||||
jsonify(
|
|
||||||
{
|
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": "Port already exists for this application",
|
"error": f"Port {clean_port} already exists for this application"
|
||||||
}
|
}), 400
|
||||||
),
|
|
||||||
400,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create new port
|
# Create new port
|
||||||
port = Port(
|
new_port = Port(
|
||||||
number=port_number,
|
|
||||||
protocol=protocol,
|
|
||||||
description=description,
|
|
||||||
app_id=app_id,
|
app_id=app_id,
|
||||||
|
port_number=clean_port,
|
||||||
|
protocol=protocol,
|
||||||
|
description=description
|
||||||
)
|
)
|
||||||
|
db.session.add(new_port)
|
||||||
db.session.add(port)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify(
|
flash(f"Port {clean_port}/{protocol} added successfully", "success")
|
||||||
{
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": f"Port {port_number} added to {app.name}",
|
"message": f"Port {clean_port}/{protocol} added successfully",
|
||||||
"port": {
|
"port": {
|
||||||
"id": port.id,
|
"id": new_port.id,
|
||||||
"number": port.number,
|
"number": new_port.port_number,
|
||||||
"protocol": port.protocol,
|
"protocol": new_port.protocol,
|
||||||
"description": port.description,
|
"description": new_port.description
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
except ValueError:
|
|
||||||
return jsonify({"success": False, "error": "Invalid port number"}), 400
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
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