From 6b0d0f46995d9b155cfe0615fd42545ec3e1db31 Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:16:38 -0400 Subject: [PATCH 1/8] added endpoint to query by domain --- backend/internal/proxy-host.js | 50 +++++++++++++++++++++++++++++ backend/routes/nginx/proxy_hosts.js | 45 ++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js index 32f2bc0dc..81fc51972 100644 --- a/backend/internal/proxy-host.js +++ b/backend/internal/proxy-host.js @@ -258,6 +258,56 @@ const internalProxyHost = { }); }, + /** + * @param {Access} access + * @param {Object} data + * @param {String} data.domain + * @param {Array} [data.expand] + * @param {Array} [data.omit] + * @return {Promise} + */ + getByDomain: (access, data) => { + if (typeof data === 'undefined') { + data = {}; + } + + return access.can('proxy_hosts:get', data.domain) + .then((access_data) => { + let query = proxyHostModel + .query() + .where('is_deleted', 0) + .andWhereRaw("domain_names::jsonb @> ?::jsonb", [JSON.stringify([data.domain])]) + .allowGraph('[owner,access_list.[clients,items],certificate]') + .modify(function(queryBuilder) { + if (data.expand) { + queryBuilder.withGraphFetched(`[${data.expand.join(', ')}]`); + } + }) + .first(); + + if (access_data.permission_visibility !== 'all') { + query.andWhere('owner_user_id', access.token.getUserId(1)); + } + + if (typeof data.expand !== 'undefined' && data.expand !== null) { + query.withGraphFetched('[' + data.expand.join(', ') + ']'); + } + + return query.then(utils.omitRow(omissions())); + }) + .then((row) => { + if (!row || !row.id) { + throw new error.ItemNotFoundError(data.id); + } + row = internalHost.cleanRowCertificateMeta(row); + // Custom omissions + if (typeof data.omit !== 'undefined' && data.omit !== null) { + row = _.omit(row, data.omit); + } + return row; + }); + }, + /** * @param {Access} access * @param {Object} data diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index 3be4582a8..c2257d5a4 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -4,6 +4,7 @@ const jwtdecode = require('../../lib/express/jwt-decode'); const apiValidator = require('../../lib/validator/api'); const internalProxyHost = require('../../internal/proxy-host'); const schema = require('../../schema'); +const {castJsonIfNeed} = require('../../lib/helpers'); let router = express.Router({ caseSensitive: true, @@ -114,6 +115,50 @@ router .catch(next); }) +/** + * Specific proxy-host + * + * /api/nginx/proxy-hosts/domain/:domain + */ +router + .route('/domain/:domain') + .options((req, res) => { + res.sendStatus(204); + }) + .all(jwtdecode()) + + /** + * GET /api/nginx/proxy-hosts/domain/:domain + * + * Retrieve a specific proxy-host by domain + */ + .get((req, res, next) => { + validator({ + required: ['domain'], + additionalProperties: false, + properties: { + domain: {type: "string"}, + expand: { + $ref: 'common#/properties/expand' + } + } + }, { + domain: req.params.domain, + expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) + }) + .then((data) => { + return internalProxyHost.getByDomain(res.locals.access, { + domain: data.domain, + expand: data.expand + }); + }) + .then((row) => { + res.status(200) + .send(row); + }) + .catch(next); + }) + /** * PUT /api/nginx/proxy-hosts/123 * From 86c834ffbccdbad969a1e4c0479fe032035d111d Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:33:49 -0400 Subject: [PATCH 2/8] added endpoint to query by domain --- backend/routes/nginx/proxy_hosts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index c2257d5a4..fefbf4503 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -4,7 +4,6 @@ const jwtdecode = require('../../lib/express/jwt-decode'); const apiValidator = require('../../lib/validator/api'); const internalProxyHost = require('../../internal/proxy-host'); const schema = require('../../schema'); -const {castJsonIfNeed} = require('../../lib/helpers'); let router = express.Router({ caseSensitive: true, From ba518d2d1497e3093460e65e6770c62c44a558b4 Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:37:58 -0400 Subject: [PATCH 3/8] added endpoint to query by domain --- backend/routes/nginx/proxy_hosts.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index fefbf4503..ad8fb7e20 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -112,7 +112,7 @@ router .send(row); }) .catch(next); - }) + }); /** * Specific proxy-host @@ -133,10 +133,12 @@ router */ .get((req, res, next) => { validator({ - required: ['domain'], + required: ['domain'], additionalProperties: false, properties: { - domain: {type: "string"}, + domain: { + type: 'string' + }, expand: { $ref: 'common#/properties/expand' } @@ -156,7 +158,7 @@ router .send(row); }) .catch(next); - }) + }); /** * PUT /api/nginx/proxy-hosts/123 From 6a7214caab2587074ea98123080321cdd1316830 Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:39:06 -0400 Subject: [PATCH 4/8] added endpoint to query by domain --- backend/routes/nginx/proxy_hosts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index ad8fb7e20..2020f17f9 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -145,7 +145,7 @@ router } }, { domain: req.params.domain, - expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) + expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) }) .then((data) => { return internalProxyHost.getByDomain(res.locals.access, { From 8178951ff7fa16f81f71c228f29405ebf00f3ce4 Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:45:38 -0400 Subject: [PATCH 5/8] added endpoint to query by domain --- backend/routes/nginx/proxy_hosts.js | 70 ++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index 2020f17f9..ba9bf0729 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -117,39 +117,39 @@ router /** * Specific proxy-host * - * /api/nginx/proxy-hosts/domain/:domain + * /api/nginx/proxy-hosts/123 */ router - .route('/domain/:domain') + .route('/:host_id') .options((req, res) => { res.sendStatus(204); }) .all(jwtdecode()) /** - * GET /api/nginx/proxy-hosts/domain/:domain + * GET /api/nginx/proxy-hosts/123 * - * Retrieve a specific proxy-host by domain + * Retrieve a specific proxy-host */ .get((req, res, next) => { validator({ - required: ['domain'], + required: ['host_id'], additionalProperties: false, properties: { - domain: { - type: 'string' + host_id: { + $ref: 'common#/properties/id' }, expand: { $ref: 'common#/properties/expand' } } }, { - domain: req.params.domain, - expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) + host_id: req.params.host_id, + expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) }) .then((data) => { - return internalProxyHost.getByDomain(res.locals.access, { - domain: data.domain, + return internalProxyHost.get(res.locals.access, { + id: parseInt(data.host_id, 10), expand: data.expand }); }) @@ -158,7 +158,7 @@ router .send(row); }) .catch(next); - }); + }) /** * PUT /api/nginx/proxy-hosts/123 @@ -192,6 +192,52 @@ router .catch(next); }); +/** + * Specific proxy-host by domain + * + * /api/nginx/proxy-hosts/domain/:domain + */ +router + .route('/domain/:domain') + .options((req, res) => { + res.sendStatus(204); + }) + .all(jwtdecode()) + + /** + * GET /api/nginx/proxy-hosts/domain/:domain + * + * Retrieve a specific proxy-host by domain + */ + .get((req, res, next) => { + validator({ + required: ['domain'], + additionalProperties: false, + properties: { + domain: { + type: 'string' + }, + expand: { + $ref: 'common#/properties/expand' + } + } + }, { + domain: req.params.domain, + expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) + }) + .then((data) => { + return internalProxyHost.getByDomain(res.locals.access, { + domain: data.domain, + expand: data.expand + }); + }) + .then((row) => { + res.status(200) + .send(row); + }) + .catch(next); + }); + /** * Enable proxy-host * From b60647795dc57fa360a5c81ffa941deec84337bb Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:49:34 -0400 Subject: [PATCH 6/8] added endpoint to query by domain --- backend/internal/proxy-host.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js index 81fc51972..8aaf69035 100644 --- a/backend/internal/proxy-host.js +++ b/backend/internal/proxy-host.js @@ -276,7 +276,7 @@ const internalProxyHost = { let query = proxyHostModel .query() .where('is_deleted', 0) - .andWhereRaw("domain_names::jsonb @> ?::jsonb", [JSON.stringify([data.domain])]) + .andWhereRaw('domain_names::jsonb @> ?::jsonb', [JSON.stringify([data.domain])]) .allowGraph('[owner,access_list.[clients,items],certificate]') .modify(function(queryBuilder) { if (data.expand) { From 37302dd22a99d43af0827f19785cf8734758d5a1 Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:55:42 -0400 Subject: [PATCH 7/8] added endpoint to query by domain --- backend/routes/nginx/proxy_hosts.js | 46 ----------------------------- 1 file changed, 46 deletions(-) diff --git a/backend/routes/nginx/proxy_hosts.js b/backend/routes/nginx/proxy_hosts.js index ba9bf0729..c123963cb 100644 --- a/backend/routes/nginx/proxy_hosts.js +++ b/backend/routes/nginx/proxy_hosts.js @@ -68,52 +68,6 @@ router .catch(next); }); -/** - * Specific proxy-host - * - * /api/nginx/proxy-hosts/123 - */ -router - .route('/:host_id') - .options((req, res) => { - res.sendStatus(204); - }) - .all(jwtdecode()) - - /** - * GET /api/nginx/proxy-hosts/123 - * - * Retrieve a specific proxy-host - */ - .get((req, res, next) => { - validator({ - required: ['host_id'], - additionalProperties: false, - properties: { - host_id: { - $ref: 'common#/properties/id' - }, - expand: { - $ref: 'common#/properties/expand' - } - } - }, { - host_id: req.params.host_id, - expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null) - }) - .then((data) => { - return internalProxyHost.get(res.locals.access, { - id: parseInt(data.host_id, 10), - expand: data.expand - }); - }) - .then((row) => { - res.status(200) - .send(row); - }) - .catch(next); - }); - /** * Specific proxy-host * From 549408f448e6e96b387bd3f11ec25702133b9d2e Mon Sep 17 00:00:00 2001 From: code-a-cola <26146122+code-a-cola@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:24:20 -0400 Subject: [PATCH 8/8] added endpoint to query by domain --- backend/internal/proxy-host.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js index 8aaf69035..65947aa87 100644 --- a/backend/internal/proxy-host.js +++ b/backend/internal/proxy-host.js @@ -276,7 +276,7 @@ const internalProxyHost = { let query = proxyHostModel .query() .where('is_deleted', 0) - .andWhereRaw('domain_names::jsonb @> ?::jsonb', [JSON.stringify([data.domain])]) + .andWhere(castJsonIfNeed('domain_names'), 'like', '%' + data.domain + '%') .allowGraph('[owner,access_list.[clients,items],certificate]') .modify(function(queryBuilder) { if (data.expand) {