Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Refactor - Breaking Changes for current DockStat frontend#18

Merged
Its4Nik merged 25 commits intodevfrom
refactor
Nov 1, 2024
Merged

Refactor - Breaking Changes for current DockStat frontend#18
Its4Nik merged 25 commits intodevfrom
refactor

Conversation

@Its4Nik
Copy link
Owner

@Its4Nik Its4Nik commented Oct 20, 2024

Rewrite the backend to optimize, well everything.

Documentation needs to be updated

@Its4Nik Its4Nik added the enhancement New feature or request label Oct 20, 2024
@Its4Nik Its4Nik self-assigned this Oct 20, 2024
@Its4Nik Its4Nik linked an issue Oct 20, 2024 that may be closed by this pull request
22 tasks
@Its4Nik Its4Nik mentioned this pull request Oct 20, 2024
22 tasks
Comment on lines +219 to +229
router.get("/config", async (req, res) => {
const configPath = path.join(__dirname, "../../config/dockerConfig.json");
try {
const rawData = fs.readFileSync(configPath);
const jsonData = JSON.parse(rawData.toString());
res.status(200).json(jsonData);
} catch (error) {
logger.error("Error loading dockerConfig.json: " + error.message);
res.status(500).json({ error: "Failed to load Docker configuration" });
}
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
const regex = /(\d+)([smh])/g;
let match;

while ((match = regex.exec(interval))) {

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data

This [regular expression](1) that depends on [a user-provided value](2) may run slow on strings with many repetitions of '9'.
Comment on lines +49 to +94
router.post("/enable", (req, res) => {
fs.readFile(passwordBool, "utf8", (err, data) => {
const password = req.query.password;
if (err) {
logger.error("Error reading the file:", err);
return;
}

const isAuthEnabled = data.trim() === "true";
if (isAuthEnabled) {
logger.error(
"Passowrd Authentication is already enabled, please dactivate it first",
);
return res.status(401).json({
message:
"Passowrd Authentication is already enabled, please dactivate it first",
});
}

if (!password) {
return res.status(400).json({ message: "Password is required" });
}

bcrypt.genSalt(saltRounds, (err, salt) => {
if (err) {
logger.error("Error generating salt");
return res.status(500).json({ message: "Error generating salt" });
}

bcrypt.hash(password, salt, (err, hash) => {
if (err) {
logger.error("Error hashing password");
return res.status(500).json({ message: "Error hashing password" });
}

const passwordData = { hash, salt };
fs.writeFile(passwordFile, JSON.stringify(passwordData), (err) => {
if (err)
return res.status(500).json({ message: "Error saving password" });
setTrue();
res.json({ message: "Authentication enabled" });
});
});
});
});
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
Comment on lines +116 to +143
router.post("/disable", (req, res) => {
const password = req.query.password;
if (!password) {
logger.error("Password is required!");
return res.status(400).json({ message: "Password is required" });
}

fs.readFile(passwordFile, "utf8", (err, data) => {
if (err) {
logger.error("Error reading password");
return res.status(500).json({ message: "Error reading password" });
}

const storedData = JSON.parse(data);
bcrypt.compare(password, storedData.hash, (err, result) => {
if (err) {
logger.error("Error validating password");
return res.status(500).json({ message: "Error validating password" });
}
if (!result) {
logger.error("Invalid password");
return res.status(401).json({ message: "Invalid password" });
}
setFalse();
res.json({ message: "Authentication disabled" });
});
});
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
Comment on lines +32 to +43
router.get("/latest", (req, res) => {
db.get(
"SELECT info FROM data ORDER BY timestamp DESC LIMIT 1",
(err, row) => {
if (err) {
logger.error("Error fetching latest data:", err.message);
return res.status(500).json({ error: "Internal server error" });
}
res.json(JSON.parse(row.info));
},
);
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a database access](1), but is not rate-limited.
Comment on lines +70 to +83
router.get("/time/24h", (req, res) => {
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
db.all(
"SELECT info FROM data WHERE timestamp >= ?",
[oneDayAgo],
(err, rows) => {
if (err) {
logger.error("Error fetching data from last 24 hours:", err.message);
return res.status(500).json({ error: "Internal server error" });
}
res.json(formatRows(rows));
},
);
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a database access](1), but is not rate-limited.
scheduleFetch();

// Routes
app.use("/api", authMiddleware, api);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.

// Routes
app.use("/api", authMiddleware, api);
app.use("/conf", authMiddleware, conf);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
// Routes
app.use("/api", authMiddleware, api);
app.use("/conf", authMiddleware, conf);
app.use("/auth", authMiddleware, auth);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
app.use("/api", authMiddleware, api);
app.use("/conf", authMiddleware, conf);
app.use("/auth", authMiddleware, auth);
app.use("/data", authMiddleware, data);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
app.use("/conf", authMiddleware, conf);
app.use("/auth", authMiddleware, auth);
app.use("/data", authMiddleware, data);
app.use("/frontend", authMiddleware, frontend);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
@Its4Nik Its4Nik changed the base branch from main to dev November 1, 2024 17:51
@Its4Nik Its4Nik marked this pull request as ready for review November 1, 2024 18:11
@Its4Nik Its4Nik changed the base branch from dev to main November 1, 2024 18:12
@Its4Nik Its4Nik closed this Nov 1, 2024
@Its4Nik Its4Nik reopened this Nov 1, 2024
@Its4Nik Its4Nik changed the base branch from main to dev November 1, 2024 18:14
@Its4Nik Its4Nik merged commit be46a81 into dev Nov 1, 2024
@Its4Nik Its4Nik deleted the refactor branch January 16, 2025 08:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToDo for next release:

1 participant