Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions backend/internal/proxy-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,31 @@ const internalProxyHost = {
return rows;
},

/**
* @param {Access} access
* @param {Number} hostId
* @return {Promise}
*/
getHostForLogs: (access, hostId) => {
return access
.can("proxy_hosts:logs", hostId)
.then((access_data) => {
const query = proxyHostModel.query().where("is_deleted", 0).andWhere("id", hostId).first();

if (access_data.permission_visibility !== "all") {
query.andWhere("owner_user_id", access.token.getUserId(1));
}

return query;
})
.then((row) => {
if (!row?.id) {
throw new errs.ItemNotFoundError(hostId);
}
return row;
});
},

/**
* Report use
*
Expand Down
23 changes: 23 additions & 0 deletions backend/lib/access/proxy_hosts-logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"anyOf": [
{
"$ref": "roles#/definitions/admin"
},
{
"type": "object",
"required": ["permission_proxy_hosts", "roles"],
"properties": {
"permission_proxy_hosts": {
"$ref": "perms#/definitions/view"
},
"roles": {
"type": "array",
"items": {
"type": "string",
"enum": ["user"]
}
}
}
}
]
}
34 changes: 34 additions & 0 deletions backend/routes/ci.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from "express";
import fs from "node:fs/promises";
import dnsPlugins from "../certbot/dns-plugins.json" with { type: "json" };
import { installPlugin } from "../lib/certbot.js";
import { debug, express as logger } from "../logger.js";
Expand Down Expand Up @@ -56,4 +57,37 @@ router
return;
});

/**
* /api/ci/mock-log
*
* Write mock log files in CI environment
*/
router
.route("/mock-log")
.options((_, res) => {
res.sendStatus(204);
})

.post(async (req, res, next) => {
try {
const { hostId, type, content } = req.body;
if (!hostId || !type || content === undefined) {
return res.status(400).send({
error: "Missing required fields: hostId, type, or content",
});
}

const filePath = `/data/logs/proxy-host-${hostId}_${type}.log`;
const dirPath = "/data/logs";

await fs.mkdir(dirPath, { recursive: true });
await fs.writeFile(filePath, content, "utf8");

res.status(200).send(true);
} catch (err) {
debug(logger, `${req.method.toUpperCase()} ${req.path}: ${err}`);
next(err);
}
});

export default router;
Loading