DweebUI/router/index.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-01-08 02:29:56 +00:00
import express from "express";
export const router = express.Router();
2024-01-08 02:29:56 +00:00
// Controllers
import { Login, submitLogin, Logout } from "../controllers/login.js";
2024-01-08 02:29:56 +00:00
import { Register, submitRegister } from "../controllers/register.js";
import { Dashboard, Logs, Modals, Stats, Chart, SSE, Card, updateCards, Containers, Action } from "../controllers/dashboard.js";
2024-03-17 08:00:11 +00:00
import { Apps, appSearch, InstallModal, LearnMore } from "../controllers/apps.js";
2024-01-08 02:29:56 +00:00
import { Users } from "../controllers/users.js";
import { Images, removeImage } from "../controllers/images.js";
import { Networks, removeNetwork } from "../controllers/networks.js";
import { Volumes, removeVolume } from "../controllers/volumes.js";
2024-01-08 02:29:56 +00:00
import { Account } from "../controllers/account.js";
import { Variables } from "../controllers/variables.js";
2024-01-08 02:29:56 +00:00
import { Settings } from "../controllers/settings.js";
2024-02-14 09:45:29 +00:00
import { Supporters, Thanks } from "../controllers/supporters.js";
import { Syslogs } from "../controllers/syslogs.js";
import { Portal } from "../controllers/portal.js"
2024-01-08 02:29:56 +00:00
// Auth middleware
2024-01-08 02:29:56 +00:00
const auth = (req, res, next) => {
if (req.session.role == "admin") {
next();
} else {
2024-01-11 08:05:38 +00:00
res.redirect("/login");
2024-01-08 02:29:56 +00:00
}
};
// Admin routes
2024-01-08 02:29:56 +00:00
router.get("/", auth, Dashboard);
2024-03-17 19:10:16 +00:00
router.post("/action/:action", auth, Action);
2024-03-17 08:00:11 +00:00
2024-02-14 09:45:29 +00:00
router.get("/logs", auth, Logs);
2024-03-17 19:10:16 +00:00
router.get("/modals", auth, Modals);
2024-02-14 09:45:29 +00:00
router.get("/stats", auth, Stats);
router.get("/chart", auth, Chart);
2024-03-12 23:23:37 +00:00
router.get("/sse_event", auth, SSE);
router.get("/containers", auth, Containers);
2024-03-12 23:23:37 +00:00
router.get("/card", auth, Card);
router.get("/new_cards", auth, updateCards);
2024-02-14 09:45:29 +00:00
router.get("/images", auth, Images);
router.post("/removeImage", auth, removeImage);
router.get("/volumes", auth, Volumes);
router.post("/removeVolume", auth, removeVolume);
router.get("/networks", auth, Networks);
router.post("/removeNetwork", auth, removeNetwork);
2024-01-08 02:29:56 +00:00
router.get("/apps", auth, Apps);
router.get("/apps/:page", auth, Apps);
router.post("/apps", auth, appSearch);
2024-03-17 08:00:11 +00:00
router.get("/install_modal", auth, InstallModal)
router.get("/learn_more", auth, LearnMore)
2024-01-08 02:29:56 +00:00
router.get("/users", auth, Users);
router.get("/syslogs", auth, Syslogs);
router.get("/variables", auth, Variables);
2024-01-08 02:29:56 +00:00
router.get("/settings", auth, Settings);
2024-02-14 09:45:29 +00:00
// User routes
router.get("/portal", Portal);
router.get("/account", Account);
router.get("/supporters", Supporters);
2024-02-14 09:45:29 +00:00
router.post("/thank", Thanks);
router.get("/login", Login);
router.post("/login", submitLogin);
router.get("/register", Register);
router.post("/register", submitRegister);
router.get("/logout", Logout);
// Functions
import { Install } from "../functions/install.js"
import { Uninstall } from "../functions/uninstall.js"
router.post("/install", auth, Install);
router.post("/uninstall", auth, Uninstall);