IIP calculation corrected : GWM

This commit is contained in:
Gowtham M 2026-04-16 15:13:43 +05:30
parent c3cac46cce
commit 466fcecda8
2 changed files with 86 additions and 5 deletions

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= title %></title>
<style>
body { font-family: Arial, sans-serif; background: #f3f4f6; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
.card { width: 360px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 18px; box-shadow: 0 6px 20px rgba(0,0,0,0.08); }
h2 { margin: 0 0 8px 0; font-size: 20px; }
p { margin: 0 0 14px 0; color: #6b7280; font-size: 13px; }
input { width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: 8px; box-sizing: border-box; margin-bottom: 10px; }
button { width: 100%; padding: 10px; border: 1px solid #1d4ed8; border-radius: 8px; background: #1d4ed8; color: #fff; cursor: pointer; }
button:hover { background: #1e40af; }
.err { color: #b91c1c; font-size: 13px; margin-bottom: 10px; }
</style>
</head>
<body>
<div class="card">
<h2>IPI Demo Access</h2>
<p>Enter `IPI_DEMO_KEY` to access demo dashboard.</p>
<% if (error) { %>
<div class="err"><%= error %></div>
<% } %>
<form method="post" action="/ipi-demo-auth">
<input type="password" name="key" placeholder="Enter demo key" required />
<button type="submit">Unlock Demo</button>
</form>
</div>
</body>
</html>

View File

@ -57,6 +57,7 @@ app.set("trust proxy", 1);
* =========================
*/
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
@ -305,11 +306,59 @@ app.post("/deploy", deploymentController.deployment);
* IPI DEMO UI
* =========================
*/
app.get("/ipi-demo", ipiDemoController.renderPage);
app.get("/ipi-demo/data", ipiDemoController.getData);
app.get("/ipi-demo/table-data", ipiDemoController.getTableData);
app.get("/ipi-demo/run-status", ipiDemoController.getRunStatus);
app.post("/ipi-demo/run-month", ipiDemoController.runMonthCalculation);
const requireIpiDemoAuth = (req, res, next) => {
const demoKey = process.env.IPI_DEMO_KEY;
if (!demoKey) return next();
if (req.cookies.ipi_demo_auth === "1") return next();
if (req.path.startsWith("/ipi-demo") && req.method === "GET" && req.headers.accept?.includes("text/html")) {
return res.redirect("/ipi-demo-auth");
}
return res.status(401).json({
success: false,
message: "Unauthorized demo access",
});
};
app.get("/ipi-demo-auth", (req, res) => {
if (!process.env.IPI_DEMO_KEY) return res.redirect("/ipi-demo");
if (req.cookies.ipi_demo_auth === "1") return res.redirect("/ipi-demo");
return res.render("ipi-demo-auth", { title: "IPI Demo Access", error: null });
});
app.post("/ipi-demo-auth", (req, res) => {
const expectedKey = process.env.IPI_DEMO_KEY;
if (!expectedKey) return res.redirect("/ipi-demo");
const providedKey = String(req.body.key || "").trim();
if (providedKey !== expectedKey) {
return res.status(401).render("ipi-demo-auth", {
title: "IPI Demo Access",
error: "Invalid demo key",
});
}
res.cookie("ipi_demo_auth", "1", {
httpOnly: true,
sameSite: "lax",
secure: isProd,
maxAge: 12 * 60 * 60 * 1000,
});
return res.redirect("/ipi-demo");
});
app.post("/ipi-demo-logout", (req, res) => {
res.clearCookie("ipi_demo_auth");
return res.redirect("/ipi-demo-auth");
});
app.get("/ipi-demo", requireIpiDemoAuth, ipiDemoController.renderPage);
app.get("/ipi-demo/data", requireIpiDemoAuth, ipiDemoController.getData);
app.get("/ipi-demo/table-data", requireIpiDemoAuth, ipiDemoController.getTableData);
app.get("/ipi-demo/run-status", requireIpiDemoAuth, ipiDemoController.getRunStatus);
app.post("/ipi-demo/run-month", requireIpiDemoAuth, ipiDemoController.runMonthCalculation);
/**