Untitled

 avatar
unknown
plain_text
2 months ago
6.7 kB
2
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Smart Office Control</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #1a1a1a;
            color: #e0e0e0;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        header {
            width: 100%;
            background-color: #121212;
            text-align: center;
            padding: 1rem;
            color: #00A3FF;
            font-size: 1.8rem;
            font-weight: bold;
        }
        .system-info {
            display: flex;
            justify-content: center;
            gap: 2rem;
            margin: 1rem 0;
        }
        .system-info div {
            color: #FFA500;
        }
        .container {
            max-width: 900px;
            width: 100%;
            margin: 0 auto;
            padding: 1rem;
        }
        .card {
            background: #292929;
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1rem;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        h2 {
            margin: 0 0 1rem 0;
            color: #00A3FF;
        }
        .form-group {
            display: flex;
            gap: 1rem;
        }
        input, select, button {
            padding: 0.5rem;
            border-radius: 5px;
            border: none;
            font-size: 1rem;
        }
        button {
            background-color: #00A3FF;
            color: #fff;
            cursor: pointer;
        }
        button:hover {
            background-color: #0080CC;
        }
        .device-grid {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }
        .device-card {
            background: #292929;
            border-radius: 8px;
            padding: 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        .status {
            font-weight: bold;
            color: #00FF00;
        }
        .button-group button {
            margin: 0 0.5rem;
        }
        .button-group button:first-child {
            margin-left: 0;
        }
    </style>
</head>
<body>
    <header>SMART OFFICE CONTROL</header>
    <div class="system-info">
        <div>CPU: <span id="cpu">0%</span></div>
        <div>Memory: <span id="memory">0%</span></div>
        <div>Temperature: <span id="temperature">0°C</span></div>
    </div>
    <div class="container">
        <div class="card">
            <h2>Add Device</h2>
            <form id="add-form">
                <div class="form-group">
                    <select id="device" name="device">
                        <option disabled selected>Loading devices...</option>
                    </select>
                    <input type="text" name="name" placeholder="Custom Name" required>
                    <button type="submit">Add Device</button>
                </div>
            </form>
        </div>
        <div class="card">
            <h2>Saved Devices</h2>
            <div id="device-list" class="device-grid"></div>
        </div>
    </div>
    <script>
        function updateSystemInfo() {
            fetch("/api/system")
                .then(response => response.json())
                .then(data => {
                    document.getElementById("cpu").textContent = data.cpu + "%";
                    document.getElementById("memory").textContent = data.memory + "%";
                    document.getElementById("temperature").textContent = data.temperature + "°C";
                });
        }

        function updateDevices() {
            fetch("/api/pcs")
                .then(response => response.json())
                .then(data => {
                    const deviceList = document.getElementById("device-list");
                    const deviceDropdown = document.getElementById("device");
                    deviceList.innerHTML = "";
                    deviceDropdown.innerHTML = "";

                    data.available.forEach(device => {
                        const option = document.createElement("option");
                        option.value = `${device.ip}|${device.mac}`;
                        option.textContent = `${device.name} (${device.ip} - ${device.mac})`;
                        deviceDropdown.appendChild(option);
                    });

                    data.saved.forEach(pc => {
                        const div = document.createElement("div");
                        div.className = "device-card";
                        div.innerHTML = `
                            <div>
                                <strong>${pc.name}</strong><br>
                                IP: ${pc.ip}<br>
                                MAC: ${pc.mac}<br>
                                Status: <span class="status">${pc.status}</span><br>
                                Uptime: ${pc.uptime}
                            </div>
                            <div class="button-group">
                                <button onclick="wake('${pc.mac}')">Wake</button>
                                <button onclick="shutdown('${pc.name}')">Shutdown</button>
                                <button onclick="deletePC('${pc.name}')">Delete</button>
                            </div>
                        `;
                        deviceList.appendChild(div);
                    });
                });
        }

        function wake(mac) {
            fetch("/wake", {
                method: "POST",
                body: new URLSearchParams({ mac })
            }).then(updateDevices);
        }

        function shutdown(name) {
            fetch("/shutdown", {
                method: "POST",
                body: new URLSearchParams({ name })
            }).then(updateDevices);
        }

        function deletePC(name) {
            fetch("/delete", {
                method: "POST",
                body: new URLSearchParams({ name })
            }).then(updateDevices);
        }

        document.getElementById("add-form").addEventListener("submit", function (e) {
            e.preventDefault();
            const formData = new FormData(e.target);
            fetch("/add", {
                method: "POST",
                body: new URLSearchParams(formData)
            }).then(updateDevices);
        });

        updateSystemInfo();
        setInterval(updateSystemInfo, 5000);
        updateDevices();
    </script>
</body>
</html>
Editor is loading...
Leave a Comment