aboutsummaryrefslogtreecommitdiff
path: root/superadmin/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'superadmin/index.js')
-rw-r--r--superadmin/index.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/superadmin/index.js b/superadmin/index.js
new file mode 100644
index 0000000..d80ac17
--- /dev/null
+++ b/superadmin/index.js
@@ -0,0 +1,29 @@
+const express = require("express");
+const db = require("../db");
+const app = express.Router();
+const { checkSuperAdmin } = require("../auth");
+const { exec } = require("child_process");
+
+app.use("/", checkSuperAdmin, express.static(__dirname + "/public"))
+
+app.post("/api/query", checkSuperAdmin, async (req, res) => {
+ const { query } = req.body;
+ let s;
+ if (!query || !query.toLowerCase().startsWith("select") || (s = query.split(";")).length > 1 && s[1] !== "")
+ return res.status(403).json({ success: false });
+ try {
+ const response = await db.query(query);
+ res.json({ success: true, response });
+ } catch (e) {
+ res.json({ success: false, message: e });
+ }
+});
+
+app.get("/api/pull", checkSuperAdmin, (req, res) => {
+ exec("git pull", (error, stdout, stderr) => {
+ if (stderr) return res.json({ success: false, stderr, error });
+ return res.json({ success: true, stdout });
+ });
+});
+
+module.exports = app; \ No newline at end of file