Automatic detect of clients
This commit is contained in:
@@ -1,11 +1,54 @@
|
||||
from database import Session
|
||||
from models.models import Client, ClientGroup
|
||||
from flask import Blueprint, request, jsonify
|
||||
import sys
|
||||
sys.path.append('/workspace')
|
||||
from flask import Blueprint, request, jsonify
|
||||
from models.models import Client, ClientGroup
|
||||
from database import Session
|
||||
|
||||
clients_bp = Blueprint("clients", __name__, url_prefix="/api/clients")
|
||||
|
||||
@clients_bp.route("/without_description", methods=["GET"])
|
||||
def get_clients_without_description():
|
||||
session = Session()
|
||||
clients = session.query(Client).filter(
|
||||
(Client.description == None) | (Client.description == "")
|
||||
).all()
|
||||
result = [
|
||||
{
|
||||
"uuid": c.uuid,
|
||||
"hardware_token": c.hardware_token,
|
||||
"ip": c.ip,
|
||||
"type": c.type,
|
||||
"hostname": c.hostname,
|
||||
"os_version": c.os_version,
|
||||
"software_version": c.software_version,
|
||||
"macs": c.macs,
|
||||
"model": c.model,
|
||||
"registration_time": c.registration_time.isoformat() if c.registration_time else None,
|
||||
"last_alive": c.last_alive.isoformat() if c.last_alive else None,
|
||||
"is_active": c.is_active,
|
||||
"group_id": c.group_id,
|
||||
}
|
||||
for c in clients
|
||||
]
|
||||
session.close()
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@clients_bp.route("/<uuid>/description", methods=["PUT"])
|
||||
def set_client_description(uuid):
|
||||
data = request.get_json()
|
||||
description = data.get("description", "").strip()
|
||||
if not description:
|
||||
return jsonify({"error": "Beschreibung darf nicht leer sein"}), 400
|
||||
session = Session()
|
||||
client = session.query(Client).filter_by(uuid=uuid).first()
|
||||
if not client:
|
||||
session.close()
|
||||
return jsonify({"error": "Client nicht gefunden"}), 404
|
||||
client.description = description
|
||||
session.commit()
|
||||
session.close()
|
||||
return jsonify({"success": True})
|
||||
|
||||
@clients_bp.route("", methods=["GET"])
|
||||
def get_clients():
|
||||
@@ -14,10 +57,18 @@ def get_clients():
|
||||
result = [
|
||||
{
|
||||
"uuid": c.uuid,
|
||||
"location": c.location,
|
||||
"hardware_hash": c.hardware_hash,
|
||||
"ip_address": c.ip_address,
|
||||
"hardware_token": c.hardware_token,
|
||||
"ip": c.ip,
|
||||
"type": c.type,
|
||||
"hostname": c.hostname,
|
||||
"os_version": c.os_version,
|
||||
"software_version": c.software_version,
|
||||
"macs": c.macs,
|
||||
"model": c.model,
|
||||
"description": c.description,
|
||||
"registration_time": c.registration_time.isoformat() if c.registration_time else None,
|
||||
"last_alive": c.last_alive.isoformat() if c.last_alive else None,
|
||||
"is_active": c.is_active,
|
||||
"group_id": c.group_id,
|
||||
}
|
||||
for c in clients
|
||||
|
||||
21
server/routes/setup.py
Normal file
21
server/routes/setup.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from flask import Blueprint, jsonify
|
||||
from server.database import get_db
|
||||
from models.models import Client
|
||||
|
||||
bp = Blueprint('setup', __name__, url_prefix='/api/setup')
|
||||
|
||||
@bp.route('/clients_without_description', methods=['GET'])
|
||||
def clients_without_description():
|
||||
db = get_db()
|
||||
clients = db.query(Client).filter(Client.description == None).all()
|
||||
result = []
|
||||
for c in clients:
|
||||
result.append({
|
||||
'uuid': c.uuid,
|
||||
'hostname': c.hostname,
|
||||
'ip_address': c.ip_address,
|
||||
'last_alive': c.last_alive,
|
||||
'created_at': c.created_at,
|
||||
'group': c.group_id,
|
||||
})
|
||||
return jsonify(result)
|
||||
@@ -35,7 +35,8 @@ def get_screenshot(uuid):
|
||||
pattern = os.path.join("screenshots", f"{uuid}*.jpg")
|
||||
files = glob.glob(pattern)
|
||||
if not files:
|
||||
return jsonify({"error": "Screenshot not found"}), 404
|
||||
# Dummy-Bild als Redirect oder direkt als Response
|
||||
return jsonify({"error": "Screenshot not found", "dummy": "https://placehold.co/400x300?text=No+Screenshot"}), 404
|
||||
filename = os.path.basename(files[0])
|
||||
return send_from_directory("screenshots", filename)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user