Guac clients
This commit is contained in:
61
server.cjs
61
server.cjs
@@ -687,6 +687,67 @@ app.post("/trigger/api/wakeClient", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Guacamole Clients //
|
||||
//////////////////////////////////////////////
|
||||
|
||||
app.get("/trigger/api/guacamoleClients", async (_req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * from trigger_database.guacamoleClients;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.post("/trigger/api/guacamoleClients", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.guacamoleClients (clientName, clientIdentifier, enabled) VALUES (${escapeString(req.body.clientName)}, ${escapeString(req.body.clientIdentifier)}, ${req.body.enabled})`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((_rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/guacamoleClients", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.guacamoleClients SET clientName = ${escapeString(req.body.clientName)}, clientIdentifier = ${escapeString(req.body.clientIdentifier)} , enabled = ${req.body.enabled} WHERE id = ${req.body.id}`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((_rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/guacamoleClients", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.guacamoleClients WHERE id = ${req.body.id}`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((_rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.post("/trigger/api/wakeClient", async (req, res) => {
|
||||
wol.wake(req.body.macAddress, () => {
|
||||
res.status(200).send({ status: "success" });
|
||||
});
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Search //
|
||||
//////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user