mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-10-04 11:50:09 +00:00
Compare commits
6 Commits
react
...
ca84e3a146
Author | SHA1 | Date | |
---|---|---|---|
|
ca84e3a146 | ||
|
fa11945235 | ||
|
432afe73ad | ||
|
5a01da2916 | ||
|
ebd9148813 | ||
|
a12553fec7 |
10
README.md
10
README.md
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<img src="https://nginxproxymanager.com/github.png">
|
||||
<br><br>
|
||||
<img src="https://img.shields.io/badge/version-2.13.0-green.svg?style=for-the-badge">
|
||||
<img src="https://img.shields.io/badge/version-2.12.6-green.svg?style=for-the-badge">
|
||||
<a href="https://hub.docker.com/repository/docker/jc21/nginx-proxy-manager">
|
||||
<img src="https://img.shields.io/docker/stars/jc21/nginx-proxy-manager.svg?style=for-the-badge">
|
||||
</a>
|
||||
@@ -88,6 +88,14 @@ Sometimes this can take a little bit because of the entropy of keys.
|
||||
|
||||
[http://127.0.0.1:81](http://127.0.0.1:81)
|
||||
|
||||
Default Admin User:
|
||||
```
|
||||
Email: admin@example.com
|
||||
Password: changeme
|
||||
```
|
||||
|
||||
Immediately after logging in with this default user you will be asked to modify your details and change your password.
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.2.3/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
|
@@ -21,74 +21,88 @@ const internalAccessList = {
|
||||
* @param {Object} data
|
||||
* @returns {Promise}
|
||||
*/
|
||||
create: async (access, data) => {
|
||||
await access.can("access_lists:create", data);
|
||||
const row = await accessListModel
|
||||
.query()
|
||||
.insertAndFetch({
|
||||
name: data.name,
|
||||
satisfy_any: data.satisfy_any,
|
||||
pass_auth: data.pass_auth,
|
||||
owner_user_id: access.token.getUserId(1),
|
||||
create: (access, data) => {
|
||||
return access
|
||||
.can("access_lists:create", data)
|
||||
.then((/*access_data*/) => {
|
||||
return accessListModel
|
||||
.query()
|
||||
.insertAndFetch({
|
||||
name: data.name,
|
||||
satisfy_any: data.satisfy_any,
|
||||
pass_auth: data.pass_auth,
|
||||
owner_user_id: access.token.getUserId(1),
|
||||
})
|
||||
.then(utils.omitRow(omissions()));
|
||||
})
|
||||
.then(utils.omitRow(omissions()));
|
||||
.then((row) => {
|
||||
data.id = row.id;
|
||||
|
||||
data.id = row.id;
|
||||
const promises = [];
|
||||
|
||||
const promises = [];
|
||||
// Items
|
||||
data.items.map((item) => {
|
||||
promises.push(
|
||||
accessListAuthModel.query().insert({
|
||||
access_list_id: row.id,
|
||||
username: item.username,
|
||||
password: item.password,
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
});
|
||||
// Now add the items
|
||||
data.items.map((item) => {
|
||||
promises.push(
|
||||
accessListAuthModel.query().insert({
|
||||
access_list_id: row.id,
|
||||
username: item.username,
|
||||
password: item.password,
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
});
|
||||
|
||||
// Clients
|
||||
data.clients?.map((client) => {
|
||||
promises.push(
|
||||
accessListClientModel.query().insert({
|
||||
access_list_id: row.id,
|
||||
address: client.address,
|
||||
directive: client.directive,
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
});
|
||||
// Now add the clients
|
||||
if (typeof data.clients !== "undefined" && data.clients) {
|
||||
data.clients.map((client) => {
|
||||
promises.push(
|
||||
accessListClientModel.query().insert({
|
||||
access_list_id: row.id,
|
||||
address: client.address,
|
||||
directive: client.directive,
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(() => {
|
||||
// re-fetch with expansions
|
||||
return internalAccessList.get(
|
||||
access,
|
||||
{
|
||||
id: data.id,
|
||||
expand: ["owner", "items", "clients", "proxy_hosts.access_list.[clients,items]"],
|
||||
},
|
||||
true /* <- skip masking */,
|
||||
);
|
||||
})
|
||||
.then((row) => {
|
||||
// Audit log
|
||||
data.meta = _.assign({}, data.meta || {}, row.meta);
|
||||
|
||||
// re-fetch with expansions
|
||||
const freshRow = await internalAccessList.get(
|
||||
access,
|
||||
{
|
||||
id: data.id,
|
||||
expand: ["owner", "items", "clients", "proxy_hosts.access_list.[clients,items]"],
|
||||
},
|
||||
true // skip masking
|
||||
);
|
||||
|
||||
// Audit log
|
||||
data.meta = _.assign({}, data.meta || {}, freshRow.meta);
|
||||
await internalAccessList.build(freshRow);
|
||||
|
||||
if (Number.parseInt(freshRow.proxy_host_count, 10)) {
|
||||
await internalNginx.bulkGenerateConfigs("proxy_host", freshRow.proxy_hosts);
|
||||
}
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "created",
|
||||
object_type: "access-list",
|
||||
object_id: freshRow.id,
|
||||
meta: internalAccessList.maskItems(data),
|
||||
});
|
||||
|
||||
return internalAccessList.maskItems(freshRow);
|
||||
return internalAccessList
|
||||
.build(row)
|
||||
.then(() => {
|
||||
if (Number.parseInt(row.proxy_host_count, 10)) {
|
||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "created",
|
||||
object_type: "access-list",
|
||||
object_id: row.id,
|
||||
meta: internalAccessList.maskItems(data),
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return internalAccessList.maskItems(row);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -99,107 +113,127 @@ const internalAccessList = {
|
||||
* @param {String} [data.items]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update: async (access, data) => {
|
||||
await access.can("access_lists:update", data.id);
|
||||
const row = await internalAccessList.get(access, { id: data.id });
|
||||
if (row.id !== data.id) {
|
||||
// Sanity check that something crazy hasn't happened
|
||||
throw new errs.InternalValidationError(
|
||||
`Access List could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
// patch name if specified
|
||||
if (typeof data.name !== "undefined" && data.name) {
|
||||
await accessListModel.query().where({ id: data.id }).patch({
|
||||
name: data.name,
|
||||
satisfy_any: data.satisfy_any,
|
||||
pass_auth: data.pass_auth,
|
||||
});
|
||||
}
|
||||
|
||||
// Check for items and add/update/remove them
|
||||
if (typeof data.items !== "undefined" && data.items) {
|
||||
const promises = [];
|
||||
const itemsToKeep = [];
|
||||
|
||||
data.items.map((item) => {
|
||||
if (item.password) {
|
||||
promises.push(
|
||||
accessListAuthModel.query().insert({
|
||||
access_list_id: data.id,
|
||||
username: item.username,
|
||||
password: item.password,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
// This was supplied with an empty password, which means keep it but don't change the password
|
||||
itemsToKeep.push(item.username);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const query = accessListAuthModel.query().delete().where("access_list_id", data.id);
|
||||
|
||||
if (itemsToKeep.length) {
|
||||
query.andWhere("username", "NOT IN", itemsToKeep);
|
||||
}
|
||||
|
||||
await query;
|
||||
// Add new items
|
||||
if (promises.length) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for clients and add/update/remove them
|
||||
if (typeof data.clients !== "undefined" && data.clients) {
|
||||
const clientPromises = [];
|
||||
data.clients.map((client) => {
|
||||
if (client.address) {
|
||||
clientPromises.push(
|
||||
accessListClientModel.query().insert({
|
||||
access_list_id: data.id,
|
||||
address: client.address,
|
||||
directive: client.directive,
|
||||
}),
|
||||
update: (access, data) => {
|
||||
return access
|
||||
.can("access_lists:update", data.id)
|
||||
.then((/*access_data*/) => {
|
||||
return internalAccessList.get(access, { id: data.id });
|
||||
})
|
||||
.then((row) => {
|
||||
if (row.id !== data.id) {
|
||||
// Sanity check that something crazy hasn't happened
|
||||
throw new errs.InternalValidationError(
|
||||
`Access List could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.then(() => {
|
||||
// patch name if specified
|
||||
if (typeof data.name !== "undefined" && data.name) {
|
||||
return accessListModel.query().where({ id: data.id }).patch({
|
||||
name: data.name,
|
||||
satisfy_any: data.satisfy_any,
|
||||
pass_auth: data.pass_auth,
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// Check for items and add/update/remove them
|
||||
if (typeof data.items !== "undefined" && data.items) {
|
||||
const promises = [];
|
||||
const items_to_keep = [];
|
||||
|
||||
data.items.map((item) => {
|
||||
if (item.password) {
|
||||
promises.push(
|
||||
accessListAuthModel.query().insert({
|
||||
access_list_id: data.id,
|
||||
username: item.username,
|
||||
password: item.password,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
// This was supplied with an empty password, which means keep it but don't change the password
|
||||
items_to_keep.push(item.username);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const query = accessListAuthModel.query().delete().where("access_list_id", data.id);
|
||||
|
||||
if (items_to_keep.length) {
|
||||
query.andWhere("username", "NOT IN", items_to_keep);
|
||||
}
|
||||
|
||||
return query.then(() => {
|
||||
// Add new items
|
||||
if (promises.length) {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// Check for clients and add/update/remove them
|
||||
if (typeof data.clients !== "undefined" && data.clients) {
|
||||
const promises = [];
|
||||
|
||||
data.clients.map((client) => {
|
||||
if (client.address) {
|
||||
promises.push(
|
||||
accessListClientModel.query().insert({
|
||||
access_list_id: data.id,
|
||||
address: client.address,
|
||||
directive: client.directive,
|
||||
}),
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const query = accessListClientModel.query().delete().where("access_list_id", data.id);
|
||||
|
||||
return query.then(() => {
|
||||
// Add new items
|
||||
if (promises.length) {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "updated",
|
||||
object_type: "access-list",
|
||||
object_id: data.id,
|
||||
meta: internalAccessList.maskItems(data),
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
// re-fetch with expansions
|
||||
return internalAccessList.get(
|
||||
access,
|
||||
{
|
||||
id: data.id,
|
||||
expand: ["owner", "items", "clients", "proxy_hosts.[certificate,access_list.[clients,items]]"],
|
||||
},
|
||||
true /* <- skip masking */,
|
||||
);
|
||||
})
|
||||
.then((row) => {
|
||||
return internalAccessList
|
||||
.build(row)
|
||||
.then(() => {
|
||||
if (Number.parseInt(row.proxy_host_count, 10)) {
|
||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||
}
|
||||
})
|
||||
.then(internalNginx.reload)
|
||||
.then(() => {
|
||||
return internalAccessList.maskItems(row);
|
||||
});
|
||||
});
|
||||
|
||||
const query = accessListClientModel.query().delete().where("access_list_id", data.id);
|
||||
await query;
|
||||
// Add new clitens
|
||||
if (clientPromises.length) {
|
||||
await Promise.all(clientPromises);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "updated",
|
||||
object_type: "access-list",
|
||||
object_id: data.id,
|
||||
meta: internalAccessList.maskItems(data),
|
||||
});
|
||||
|
||||
// re-fetch with expansions
|
||||
const freshRow = await internalAccessList.get(
|
||||
access,
|
||||
{
|
||||
id: data.id,
|
||||
expand: ["owner", "items", "clients", "proxy_hosts.[certificate,access_list.[clients,items]]"],
|
||||
},
|
||||
true // skip masking
|
||||
);
|
||||
|
||||
await internalAccessList.build(freshRow)
|
||||
if (Number.parseInt(row.proxy_host_count, 10)) {
|
||||
await internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||
}
|
||||
await internalNginx.reload();
|
||||
return internalAccessList.maskItems(row);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -208,50 +242,55 @@ const internalAccessList = {
|
||||
* @param {Integer} data.id
|
||||
* @param {Array} [data.expand]
|
||||
* @param {Array} [data.omit]
|
||||
* @param {Boolean} [skipMasking]
|
||||
* @param {Boolean} [skip_masking]
|
||||
* @return {Promise}
|
||||
*/
|
||||
get: async (access, data, skipMasking) => {
|
||||
get: (access, data, skip_masking) => {
|
||||
const thisData = data || {};
|
||||
const accessData = await access.can("access_lists:get", thisData.id)
|
||||
|
||||
const query = accessListModel
|
||||
.query()
|
||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||
.leftJoin("proxy_host", function () {
|
||||
this.on("proxy_host.access_list_id", "=", "access_list.id").andOn(
|
||||
"proxy_host.is_deleted",
|
||||
"=",
|
||||
0,
|
||||
);
|
||||
return access
|
||||
.can("access_lists:get", thisData.id)
|
||||
.then((accessData) => {
|
||||
const query = accessListModel
|
||||
.query()
|
||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||
.leftJoin("proxy_host", function () {
|
||||
this.on("proxy_host.access_list_id", "=", "access_list.id").andOn(
|
||||
"proxy_host.is_deleted",
|
||||
"=",
|
||||
0,
|
||||
);
|
||||
})
|
||||
.where("access_list.is_deleted", 0)
|
||||
.andWhere("access_list.id", thisData.id)
|
||||
.groupBy("access_list.id")
|
||||
.allowGraph("[owner,items,clients,proxy_hosts.[certificate,access_list.[clients,items]]]")
|
||||
.first();
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
if (typeof thisData.expand !== "undefined" && thisData.expand !== null) {
|
||||
query.withGraphFetched(`[${thisData.expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return query.then(utils.omitRow(omissions()));
|
||||
})
|
||||
.where("access_list.is_deleted", 0)
|
||||
.andWhere("access_list.id", thisData.id)
|
||||
.groupBy("access_list.id")
|
||||
.allowGraph("[owner,items,clients,proxy_hosts.[certificate,access_list.[clients,items]]]")
|
||||
.first();
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
if (typeof thisData.expand !== "undefined" && thisData.expand !== null) {
|
||||
query.withGraphFetched(`[${thisData.expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
let row = await query.then(utils.omitRow(omissions()));
|
||||
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(thisData.id);
|
||||
}
|
||||
if (!skipMasking && typeof row.items !== "undefined" && row.items) {
|
||||
row = internalAccessList.maskItems(row);
|
||||
}
|
||||
// Custom omissions
|
||||
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
||||
row = _.omit(row, data.omit);
|
||||
}
|
||||
return row;
|
||||
.then((row) => {
|
||||
let thisRow = row;
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(thisData.id);
|
||||
}
|
||||
if (!skip_masking && typeof thisRow.items !== "undefined" && thisRow.items) {
|
||||
thisRow = internalAccessList.maskItems(thisRow);
|
||||
}
|
||||
// Custom omissions
|
||||
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
||||
thisRow = _.omit(thisRow, data.omit);
|
||||
}
|
||||
return thisRow;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -261,64 +300,75 @@ const internalAccessList = {
|
||||
* @param {String} [data.reason]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
delete: async (access, data) => {
|
||||
await access.can("access_lists:delete", data.id);
|
||||
const row = await internalAccessList.get(access, {
|
||||
id: data.id,
|
||||
expand: ["proxy_hosts", "items", "clients"],
|
||||
});
|
||||
delete: (access, data) => {
|
||||
return access
|
||||
.can("access_lists:delete", data.id)
|
||||
.then(() => {
|
||||
return internalAccessList.get(access, { id: data.id, expand: ["proxy_hosts", "items", "clients"] });
|
||||
})
|
||||
.then((row) => {
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
// 1. update row to be deleted
|
||||
// 2. update any proxy hosts that were using it (ignoring permissions)
|
||||
// 3. reconfigure those hosts
|
||||
// 4. audit log
|
||||
|
||||
// 1. update row to be deleted
|
||||
// 2. update any proxy hosts that were using it (ignoring permissions)
|
||||
// 3. reconfigure those hosts
|
||||
// 4. audit log
|
||||
// 1. update row to be deleted
|
||||
return accessListModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
is_deleted: 1,
|
||||
})
|
||||
.then(() => {
|
||||
// 2. update any proxy hosts that were using it (ignoring permissions)
|
||||
if (row.proxy_hosts) {
|
||||
return proxyHostModel
|
||||
.query()
|
||||
.where("access_list_id", "=", row.id)
|
||||
.patch({ access_list_id: 0 })
|
||||
.then(() => {
|
||||
// 3. reconfigure those hosts, then reload nginx
|
||||
|
||||
// 1. update row to be deleted
|
||||
await accessListModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
is_deleted: 1,
|
||||
});
|
||||
// set the access_list_id to zero for these items
|
||||
row.proxy_hosts.map((_val, idx) => {
|
||||
row.proxy_hosts[idx].access_list_id = 0;
|
||||
return true;
|
||||
});
|
||||
|
||||
// 2. update any proxy hosts that were using it (ignoring permissions)
|
||||
if (row.proxy_hosts) {
|
||||
await proxyHostModel
|
||||
.query()
|
||||
.where("access_list_id", "=", row.id)
|
||||
.patch({ access_list_id: 0 });
|
||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||
})
|
||||
.then(() => {
|
||||
return internalNginx.reload();
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// delete the htpasswd file
|
||||
const htpasswd_file = internalAccessList.getFilename(row);
|
||||
|
||||
// 3. reconfigure those hosts, then reload nginx
|
||||
// set the access_list_id to zero for these items
|
||||
row.proxy_hosts.map((_val, idx) => {
|
||||
row.proxy_hosts[idx].access_list_id = 0;
|
||||
try {
|
||||
fs.unlinkSync(htpasswd_file);
|
||||
} catch (_err) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// 4. audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "deleted",
|
||||
object_type: "access-list",
|
||||
object_id: row.id,
|
||||
meta: _.omit(internalAccessList.maskItems(row), ["is_deleted", "proxy_hosts"]),
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return true;
|
||||
});
|
||||
|
||||
await internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||
}
|
||||
|
||||
await internalNginx.reload();
|
||||
|
||||
// delete the htpasswd file
|
||||
try {
|
||||
fs.unlinkSync(internalAccessList.getFilename(row));
|
||||
} catch (_err) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// 4. audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "deleted",
|
||||
object_type: "access-list",
|
||||
object_id: row.id,
|
||||
meta: _.omit(internalAccessList.maskItems(row), ["is_deleted", "proxy_hosts"]),
|
||||
});
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -326,73 +376,76 @@ const internalAccessList = {
|
||||
*
|
||||
* @param {Access} access
|
||||
* @param {Array} [expand]
|
||||
* @param {String} [searchQuery]
|
||||
* @param {String} [search_query]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getAll: async (access, expand, searchQuery) => {
|
||||
const accessData = await access.can("access_lists:list");
|
||||
getAll: (access, expand, search_query) => {
|
||||
return access
|
||||
.can("access_lists:list")
|
||||
.then((access_data) => {
|
||||
const query = accessListModel
|
||||
.query()
|
||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||
.leftJoin("proxy_host", function () {
|
||||
this.on("proxy_host.access_list_id", "=", "access_list.id").andOn(
|
||||
"proxy_host.is_deleted",
|
||||
"=",
|
||||
0,
|
||||
);
|
||||
})
|
||||
.where("access_list.is_deleted", 0)
|
||||
.groupBy("access_list.id")
|
||||
.allowGraph("[owner,items,clients]")
|
||||
.orderBy("access_list.name", "ASC");
|
||||
|
||||
const query = accessListModel
|
||||
.query()
|
||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||
.leftJoin("proxy_host", function () {
|
||||
this.on("proxy_host.access_list_id", "=", "access_list.id").andOn(
|
||||
"proxy_host.is_deleted",
|
||||
"=",
|
||||
0,
|
||||
);
|
||||
})
|
||||
.where("access_list.is_deleted", 0)
|
||||
.groupBy("access_list.id")
|
||||
.allowGraph("[owner,items,clients]")
|
||||
.orderBy("access_list.name", "ASC");
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
// Query is used for searching
|
||||
if (typeof searchQuery === "string") {
|
||||
query.where(function () {
|
||||
this.where("name", "like", `%${searchQuery}%`);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
const rows = await query.then(utils.omitRows(omissions()));
|
||||
if (rows) {
|
||||
rows.map((row, idx) => {
|
||||
if (typeof row.items !== "undefined" && row.items) {
|
||||
rows[idx] = internalAccessList.maskItems(row);
|
||||
if (access_data.permission_visibility !== "all") {
|
||||
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
return true;
|
||||
|
||||
// Query is used for searching
|
||||
if (typeof search_query === "string") {
|
||||
query.where(function () {
|
||||
this.where("name", "like", `%${search_query}%`);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return query.then(utils.omitRows(omissions()));
|
||||
})
|
||||
.then((rows) => {
|
||||
if (rows) {
|
||||
rows.map((row, idx) => {
|
||||
if (typeof row.items !== "undefined" && row.items) {
|
||||
rows[idx] = internalAccessList.maskItems(row);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
},
|
||||
|
||||
/**
|
||||
* Count is used in reports
|
||||
* Report use
|
||||
*
|
||||
* @param {Integer} userId
|
||||
* @param {Integer} user_id
|
||||
* @param {String} visibility
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getCount: async (userId, visibility) => {
|
||||
const query = accessListModel
|
||||
.query()
|
||||
.count("id as count")
|
||||
.where("is_deleted", 0);
|
||||
getCount: (user_id, visibility) => {
|
||||
const query = accessListModel.query().count("id as count").where("is_deleted", 0);
|
||||
|
||||
if (visibility !== "all") {
|
||||
query.andWhere("owner_user_id", userId);
|
||||
query.andWhere("owner_user_id", user_id);
|
||||
}
|
||||
|
||||
const row = await query.first();
|
||||
return Number.parseInt(row.count, 10);
|
||||
return query.first().then((row) => {
|
||||
return Number.parseInt(row.count, 10);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -402,19 +455,20 @@ const internalAccessList = {
|
||||
maskItems: (list) => {
|
||||
if (list && typeof list.items !== "undefined") {
|
||||
list.items.map((val, idx) => {
|
||||
let repeatFor = 8;
|
||||
let firstChar = "*";
|
||||
let repeat_for = 8;
|
||||
let first_char = "*";
|
||||
|
||||
if (typeof val.password !== "undefined" && val.password) {
|
||||
repeatFor = val.password.length - 1;
|
||||
firstChar = val.password.charAt(0);
|
||||
repeat_for = val.password.length - 1;
|
||||
first_char = val.password.charAt(0);
|
||||
}
|
||||
|
||||
list.items[idx].hint = firstChar + "*".repeat(repeatFor);
|
||||
list.items[idx].hint = first_char + "*".repeat(repeat_for);
|
||||
list.items[idx].password = "";
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
@@ -434,55 +488,66 @@ const internalAccessList = {
|
||||
* @param {Array} list.items
|
||||
* @returns {Promise}
|
||||
*/
|
||||
build: async (list) => {
|
||||
build: (list) => {
|
||||
logger.info(`Building Access file #${list.id} for: ${list.name}`);
|
||||
|
||||
const htpasswdFile = internalAccessList.getFilename(list);
|
||||
return new Promise((resolve, reject) => {
|
||||
const htpasswd_file = internalAccessList.getFilename(list);
|
||||
|
||||
// 1. remove any existing access file
|
||||
try {
|
||||
fs.unlinkSync(htpasswdFile);
|
||||
} catch (_err) {
|
||||
// do nothing
|
||||
}
|
||||
// 1. remove any existing access file
|
||||
try {
|
||||
fs.unlinkSync(htpasswd_file);
|
||||
} catch (_err) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// 2. create empty access file
|
||||
fs.writeFileSync(htpasswdFile, '', {encoding: 'utf8'});
|
||||
// 2. create empty access file
|
||||
try {
|
||||
fs.writeFileSync(htpasswd_file, "", { encoding: "utf8" });
|
||||
resolve(htpasswd_file);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}).then((htpasswd_file) => {
|
||||
// 3. generate password for each user
|
||||
if (list.items.length) {
|
||||
return new Promise((resolve, reject) => {
|
||||
batchflow(list.items)
|
||||
.sequential()
|
||||
.each((_i, item, next) => {
|
||||
if (typeof item.password !== "undefined" && item.password.length) {
|
||||
logger.info(`Adding: ${item.username}`);
|
||||
|
||||
// 3. generate password for each user
|
||||
if (list.items.length) {
|
||||
await new Promise((resolve, reject) => {
|
||||
batchflow(list.items).sequential()
|
||||
.each((_i, item, next) => {
|
||||
if (item.password?.length) {
|
||||
logger.info(`Adding: ${item.username}`);
|
||||
|
||||
utils.execFile('openssl', ['passwd', '-apr1', item.password])
|
||||
.then((res) => {
|
||||
try {
|
||||
fs.appendFileSync(htpasswdFile, `${item.username}:${res}\n`, {encoding: 'utf8'});
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
next();
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
})
|
||||
.error((err) => {
|
||||
logger.error(err);
|
||||
reject(err);
|
||||
})
|
||||
.end((results) => {
|
||||
logger.success(`Built Access file #${list.id} for: ${list.name}`);
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
utils
|
||||
.execFile("openssl", ["passwd", "-apr1", item.password])
|
||||
.then((res) => {
|
||||
try {
|
||||
fs.appendFileSync(htpasswd_file, `${item.username}:${res}\n`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
next();
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
})
|
||||
.error((err) => {
|
||||
logger.error(err);
|
||||
reject(err);
|
||||
})
|
||||
.end((results) => {
|
||||
logger.success(`Built Access file #${list.id} for: ${list.name}`);
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default internalAccessList;
|
||||
|
@@ -9,60 +9,31 @@ const internalAuditLog = {
|
||||
*
|
||||
* @param {Access} access
|
||||
* @param {Array} [expand]
|
||||
* @param {String} [searchQuery]
|
||||
* @param {String} [search_query]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getAll: async (access, expand, searchQuery) => {
|
||||
await access.can("auditlog:list");
|
||||
getAll: (access, expand, search_query) => {
|
||||
return access.can("auditlog:list").then(() => {
|
||||
const query = auditLogModel
|
||||
.query()
|
||||
.orderBy("created_on", "DESC")
|
||||
.orderBy("id", "DESC")
|
||||
.limit(100)
|
||||
.allowGraph("[user]");
|
||||
|
||||
const query = auditLogModel
|
||||
.query()
|
||||
.orderBy("created_on", "DESC")
|
||||
.orderBy("id", "DESC")
|
||||
.limit(100)
|
||||
.allowGraph("[user]");
|
||||
// Query is used for searching
|
||||
if (typeof search_query === "string" && search_query.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("meta"), "like", `%${search_query}`);
|
||||
});
|
||||
}
|
||||
|
||||
// Query is used for searching
|
||||
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("meta"), "like", `%${searchQuery}`);
|
||||
});
|
||||
}
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return await query;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Access} access
|
||||
* @param {Object} [data]
|
||||
* @param {Integer} [data.id] Defaults to the token user
|
||||
* @param {Array} [data.expand]
|
||||
* @return {Promise}
|
||||
*/
|
||||
get: async (access, data) => {
|
||||
await access.can("auditlog:list");
|
||||
|
||||
const query = auditLogModel
|
||||
.query()
|
||||
.andWhere("id", data.id)
|
||||
.allowGraph("[user]")
|
||||
.first();
|
||||
|
||||
if (typeof data.expand !== "undefined" && data.expand !== null) {
|
||||
query.withGraphFetched(`[${data.expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
const row = await query;
|
||||
|
||||
if (!row?.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
|
||||
return row;
|
||||
return query;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -79,22 +50,27 @@ const internalAuditLog = {
|
||||
* @param {Object} [data.meta]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
add: async (access, data) => {
|
||||
if (typeof data.user_id === "undefined" || !data.user_id) {
|
||||
data.user_id = access.token.getUserId(1);
|
||||
}
|
||||
add: (access, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Default the user id
|
||||
if (typeof data.user_id === "undefined" || !data.user_id) {
|
||||
data.user_id = access.token.getUserId(1);
|
||||
}
|
||||
|
||||
if (typeof data.action === "undefined" || !data.action) {
|
||||
throw new errs.InternalValidationError("Audit log entry must contain an Action");
|
||||
}
|
||||
|
||||
// Make sure at least 1 of the IDs are set and action
|
||||
return await auditLogModel.query().insert({
|
||||
user_id: data.user_id,
|
||||
action: data.action,
|
||||
object_type: data.object_type || "",
|
||||
object_id: data.object_id || 0,
|
||||
meta: data.meta || {},
|
||||
if (typeof data.action === "undefined" || !data.action) {
|
||||
reject(new errs.InternalValidationError("Audit log entry must contain an Action"));
|
||||
} else {
|
||||
// Make sure at least 1 of the IDs are set and action
|
||||
resolve(
|
||||
auditLogModel.query().insert({
|
||||
user_id: data.user_id,
|
||||
action: data.action,
|
||||
object_type: data.object_type || "",
|
||||
object_id: data.object_id || 0,
|
||||
meta: data.meta || {},
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,79 +18,91 @@ const internalDeadHost = {
|
||||
* @param {Object} data
|
||||
* @returns {Promise}
|
||||
*/
|
||||
create: async (access, data) => {
|
||||
create: (access, data) => {
|
||||
const createCertificate = data.certificate_id === "new";
|
||||
|
||||
if (createCertificate) {
|
||||
delete data.certificate_id;
|
||||
}
|
||||
|
||||
await access.can("dead_hosts:create", data);
|
||||
return access
|
||||
.can("dead_hosts:create", data)
|
||||
.then((/*access_data*/) => {
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
const domain_name_check_promises = [];
|
||||
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
const domainNameCheckPromises = [];
|
||||
data.domain_names.map((domain_name) => {
|
||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name));
|
||||
return true;
|
||||
});
|
||||
|
||||
data.domain_names.map((domain_name) => {
|
||||
domainNameCheckPromises.push(internalHost.isHostnameTaken(domain_name));
|
||||
return true;
|
||||
});
|
||||
return Promise.all(domain_name_check_promises).then((check_results) => {
|
||||
check_results.map((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
// At this point the domains should have been checked
|
||||
data.owner_user_id = access.token.getUserId(1);
|
||||
const thisData = internalHost.cleanSslHstsData(data);
|
||||
|
||||
await Promise.all(domainNameCheckPromises).then((check_results) => {
|
||||
check_results.map((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||
// Fix for db field not having a default value
|
||||
// for this optional field.
|
||||
if (typeof data.advanced_config === "undefined") {
|
||||
thisData.advanced_config = "";
|
||||
}
|
||||
return true;
|
||||
|
||||
return deadHostModel.query().insertAndFetch(thisData).then(utils.omitRow(omissions()));
|
||||
})
|
||||
.then((row) => {
|
||||
if (createCertificate) {
|
||||
return internalCertificate
|
||||
.createQuickCertificate(access, data)
|
||||
.then((cert) => {
|
||||
// update host with cert id
|
||||
return internalDeadHost.update(access, {
|
||||
id: row.id,
|
||||
certificate_id: cert.id,
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return row;
|
||||
});
|
||||
}
|
||||
return row;
|
||||
})
|
||||
.then((row) => {
|
||||
// re-fetch with cert
|
||||
return internalDeadHost.get(access, {
|
||||
id: row.id,
|
||||
expand: ["certificate", "owner"],
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
// Configure nginx
|
||||
return internalNginx.configure(deadHostModel, "dead_host", row).then(() => {
|
||||
return row;
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
data.meta = _.assign({}, data.meta || {}, row.meta);
|
||||
|
||||
// Add to audit log
|
||||
return internalAuditLog
|
||||
.add(access, {
|
||||
action: "created",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: data,
|
||||
})
|
||||
.then(() => {
|
||||
return row;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// At this point the domains should have been checked
|
||||
data.owner_user_id = access.token.getUserId(1);
|
||||
const thisData = internalHost.cleanSslHstsData(data);
|
||||
|
||||
// Fix for db field not having a default value
|
||||
// for this optional field.
|
||||
if (typeof data.advanced_config === "undefined") {
|
||||
thisData.advanced_config = "";
|
||||
}
|
||||
|
||||
const row = await deadHostModel.query()
|
||||
.insertAndFetch(thisData)
|
||||
.then(utils.omitRow(omissions()));
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "created",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: thisData,
|
||||
});
|
||||
|
||||
if (createCertificate) {
|
||||
const cert = await internalCertificate.createQuickCertificate(access, data);
|
||||
|
||||
// update host with cert id
|
||||
await internalDeadHost.update(access, {
|
||||
id: row.id,
|
||||
certificate_id: cert.id,
|
||||
});
|
||||
}
|
||||
|
||||
// re-fetch with cert
|
||||
const freshRow = await internalDeadHost.get(access, {
|
||||
id: row.id,
|
||||
expand: ["certificate", "owner"],
|
||||
});
|
||||
|
||||
// Sanity check
|
||||
if (createCertificate && !freshRow.certificate_id) {
|
||||
throw new errs.InternalValidationError("The host was created but the Certificate creation failed.");
|
||||
}
|
||||
|
||||
// Configure nginx
|
||||
await internalNginx.configure(deadHostModel, "dead_host", freshRow);
|
||||
|
||||
return freshRow;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -99,85 +111,107 @@ const internalDeadHost = {
|
||||
* @param {Number} data.id
|
||||
* @return {Promise}
|
||||
*/
|
||||
update: async (access, data) => {
|
||||
const createCertificate = data.certificate_id === "new";
|
||||
update: (access, data) => {
|
||||
let thisData = data;
|
||||
const createCertificate = thisData.certificate_id === "new";
|
||||
|
||||
if (createCertificate) {
|
||||
delete data.certificate_id;
|
||||
delete thisData.certificate_id;
|
||||
}
|
||||
|
||||
await access.can("dead_hosts:update", data.id);
|
||||
return access
|
||||
.can("dead_hosts:update", thisData.id)
|
||||
.then((/*access_data*/) => {
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
const domain_name_check_promises = [];
|
||||
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
const domainNameCheckPromises = [];
|
||||
if (typeof data.domain_names !== "undefined") {
|
||||
data.domain_names.map((domainName) => {
|
||||
domainNameCheckPromises.push(internalHost.isHostnameTaken(domainName, "dead", data.id));
|
||||
return true;
|
||||
});
|
||||
if (typeof thisData.domain_names !== "undefined") {
|
||||
thisData.domain_names.map((domain_name) => {
|
||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name, "dead", data.id));
|
||||
return true;
|
||||
});
|
||||
|
||||
const checkResults = await Promise.all(domainNameCheckPromises);
|
||||
checkResults.map((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||
return Promise.all(domain_name_check_promises).then((check_results) => {
|
||||
check_results.map((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.then(() => {
|
||||
return internalDeadHost.get(access, { id: thisData.id });
|
||||
})
|
||||
.then((row) => {
|
||||
if (row.id !== thisData.id) {
|
||||
// Sanity check that something crazy hasn't happened
|
||||
throw new errs.InternalValidationError(
|
||||
`404 Host could not be updated, IDs do not match: ${row.id} !== ${thisData.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (createCertificate) {
|
||||
return internalCertificate
|
||||
.createQuickCertificate(access, {
|
||||
domain_names: thisData.domain_names || row.domain_names,
|
||||
meta: _.assign({}, row.meta, thisData.meta),
|
||||
})
|
||||
.then((cert) => {
|
||||
// update host with cert id
|
||||
thisData.certificate_id = cert.id;
|
||||
})
|
||||
.then(() => {
|
||||
return row;
|
||||
});
|
||||
}
|
||||
return row;
|
||||
})
|
||||
.then((row) => {
|
||||
// Add domain_names to the data in case it isn't there, so that the audit log renders correctly. The order is important here.
|
||||
thisData = _.assign(
|
||||
{},
|
||||
{
|
||||
domain_names: row.domain_names,
|
||||
},
|
||||
data,
|
||||
);
|
||||
|
||||
thisData = internalHost.cleanSslHstsData(thisData, row);
|
||||
|
||||
return deadHostModel
|
||||
.query()
|
||||
.where({ id: thisData.id })
|
||||
.patch(thisData)
|
||||
.then((saved_row) => {
|
||||
// Add to audit log
|
||||
return internalAuditLog
|
||||
.add(access, {
|
||||
action: "updated",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: thisData,
|
||||
})
|
||||
.then(() => {
|
||||
return _.omit(saved_row, omissions());
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return internalDeadHost
|
||||
.get(access, {
|
||||
id: thisData.id,
|
||||
expand: ["owner", "certificate"],
|
||||
})
|
||||
.then((row) => {
|
||||
// Configure nginx
|
||||
return internalNginx.configure(deadHostModel, "dead_host", row).then((new_meta) => {
|
||||
row.meta = new_meta;
|
||||
return _.omit(internalHost.cleanRowCertificateMeta(row), omissions());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
const row = await internalDeadHost.get(access, { id: data.id });
|
||||
|
||||
if (row.id !== data.id) {
|
||||
// Sanity check that something crazy hasn't happened
|
||||
throw new errs.InternalValidationError(
|
||||
`404 Host could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (createCertificate) {
|
||||
const cert = await internalCertificate.createQuickCertificate(access, {
|
||||
domain_names: data.domain_names || row.domain_names,
|
||||
meta: _.assign({}, row.meta, data.meta),
|
||||
});
|
||||
|
||||
// update host with cert id
|
||||
data.certificate_id = cert.id;
|
||||
}
|
||||
|
||||
// Add domain_names to the data in case it isn't there, so that the audit log renders correctly. The order is important here.
|
||||
let thisData = _.assign(
|
||||
{},
|
||||
{
|
||||
domain_names: row.domain_names,
|
||||
},
|
||||
data,
|
||||
);
|
||||
|
||||
thisData = internalHost.cleanSslHstsData(thisData, row);
|
||||
|
||||
|
||||
// do the row update
|
||||
await deadHostModel
|
||||
.query()
|
||||
.where({id: data.id})
|
||||
.patch(data);
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "updated",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: thisData,
|
||||
});
|
||||
|
||||
const thisRow = await internalDeadHost
|
||||
.get(access, {
|
||||
id: thisData.id,
|
||||
expand: ["owner", "certificate"],
|
||||
});
|
||||
|
||||
// Configure nginx
|
||||
const newMeta = await internalNginx.configure(deadHostModel, "dead_host", row);
|
||||
row.meta = newMeta;
|
||||
return _.omit(internalHost.cleanRowCertificateMeta(thisRow), omissions());
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -188,32 +222,39 @@ const internalDeadHost = {
|
||||
* @param {Array} [data.omit]
|
||||
* @return {Promise}
|
||||
*/
|
||||
get: async (access, data) => {
|
||||
const accessData = await access.can("dead_hosts:get", data.id);
|
||||
const query = deadHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.andWhere("id", data.id)
|
||||
.allowGraph("[owner,certificate]")
|
||||
.first();
|
||||
get: (access, data) => {
|
||||
const thisData = data || {};
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
return access
|
||||
.can("dead_hosts:get", thisData.id)
|
||||
.then((access_data) => {
|
||||
const query = deadHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.andWhere("id", dthisDataata.id)
|
||||
.allowGraph("[owner,certificate]")
|
||||
.first();
|
||||
|
||||
if (typeof data.expand !== "undefined" && data.expand !== null) {
|
||||
query.withGraphFetched(`[${data.expand.join(", ")}]`);
|
||||
}
|
||||
if (access_data.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
const row = await query.then(utils.omitRow(omissions()));
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
// Custom omissions
|
||||
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
||||
return _.omit(row, data.omit);
|
||||
}
|
||||
return row;
|
||||
if (typeof thisData.expand !== "undefined" && thisData.expand !== null) {
|
||||
query.withGraphFetched(`[${data.expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return query.then(utils.omitRow(omissions()));
|
||||
})
|
||||
.then((row) => {
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(thisData.id);
|
||||
}
|
||||
// Custom omissions
|
||||
if (typeof thisData.omit !== "undefined" && thisData.omit !== null) {
|
||||
return _.omit(row, thisData.omit);
|
||||
}
|
||||
return row;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -223,32 +264,42 @@ const internalDeadHost = {
|
||||
* @param {String} [data.reason]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
delete: async (access, data) => {
|
||||
await access.can("dead_hosts:delete", data.id)
|
||||
const row = await internalDeadHost.get(access, { id: data.id });
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
delete: (access, data) => {
|
||||
return access
|
||||
.can("dead_hosts:delete", data.id)
|
||||
.then(() => {
|
||||
return internalDeadHost.get(access, { id: data.id });
|
||||
})
|
||||
.then((row) => {
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
|
||||
await deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
is_deleted: 1,
|
||||
return deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
is_deleted: 1,
|
||||
})
|
||||
.then(() => {
|
||||
// Delete Nginx Config
|
||||
return internalNginx.deleteConfig("dead_host", row).then(() => {
|
||||
return internalNginx.reload();
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "deleted",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return true;
|
||||
});
|
||||
|
||||
// Delete Nginx Config
|
||||
await internalNginx.deleteConfig("dead_host", row);
|
||||
await internalNginx.reload();
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "deleted",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -258,39 +309,48 @@ const internalDeadHost = {
|
||||
* @param {String} [data.reason]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
enable: async (access, data) => {
|
||||
await access.can("dead_hosts:update", data.id)
|
||||
const row = await internalDeadHost.get(access, {
|
||||
id: data.id,
|
||||
expand: ["certificate", "owner"],
|
||||
});
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
if (row.enabled) {
|
||||
throw new errs.ValidationError("Host is already enabled");
|
||||
}
|
||||
enable: (access, data) => {
|
||||
return access
|
||||
.can("dead_hosts:update", data.id)
|
||||
.then(() => {
|
||||
return internalDeadHost.get(access, {
|
||||
id: data.id,
|
||||
expand: ["certificate", "owner"],
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
if (row.enabled) {
|
||||
throw new errs.ValidationError("Host is already enabled");
|
||||
}
|
||||
|
||||
row.enabled = 1;
|
||||
row.enabled = 1;
|
||||
|
||||
await deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
enabled: 1,
|
||||
return deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
enabled: 1,
|
||||
})
|
||||
.then(() => {
|
||||
// Configure nginx
|
||||
return internalNginx.configure(deadHostModel, "dead_host", row);
|
||||
})
|
||||
.then(() => {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "enabled",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return true;
|
||||
});
|
||||
|
||||
// Configure nginx
|
||||
await internalNginx.configure(deadHostModel, "dead_host", row);
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "enabled",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -300,37 +360,47 @@ const internalDeadHost = {
|
||||
* @param {String} [data.reason]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
disable: async (access, data) => {
|
||||
await access.can("dead_hosts:update", data.id)
|
||||
const row = await internalDeadHost.get(access, { id: data.id });
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
if (!row.enabled) {
|
||||
throw new errs.ValidationError("Host is already disabled");
|
||||
}
|
||||
disable: (access, data) => {
|
||||
return access
|
||||
.can("dead_hosts:update", data.id)
|
||||
.then(() => {
|
||||
return internalDeadHost.get(access, { id: data.id });
|
||||
})
|
||||
.then((row) => {
|
||||
if (!row || !row.id) {
|
||||
throw new errs.ItemNotFoundError(data.id);
|
||||
}
|
||||
if (!row.enabled) {
|
||||
throw new errs.ValidationError("Host is already disabled");
|
||||
}
|
||||
|
||||
row.enabled = 0;
|
||||
row.enabled = 0;
|
||||
|
||||
await deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
enabled: 0,
|
||||
return deadHostModel
|
||||
.query()
|
||||
.where("id", row.id)
|
||||
.patch({
|
||||
enabled: 0,
|
||||
})
|
||||
.then(() => {
|
||||
// Delete Nginx Config
|
||||
return internalNginx.deleteConfig("dead_host", row).then(() => {
|
||||
return internalNginx.reload();
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "disabled",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return true;
|
||||
});
|
||||
|
||||
// Delete Nginx Config
|
||||
await internalNginx.deleteConfig("dead_host", row);
|
||||
await internalNginx.reload();
|
||||
|
||||
// Add to audit log
|
||||
await internalAuditLog.add(access, {
|
||||
action: "disabled",
|
||||
object_type: "dead-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -338,38 +408,44 @@ const internalDeadHost = {
|
||||
*
|
||||
* @param {Access} access
|
||||
* @param {Array} [expand]
|
||||
* @param {String} [searchQuery]
|
||||
* @param {String} [search_query]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getAll: async (access, expand, searchQuery) => {
|
||||
const accessData = await access.can("dead_hosts:list")
|
||||
const query = deadHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.groupBy("id")
|
||||
.allowGraph("[owner,certificate]")
|
||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||
getAll: (access, expand, search_query) => {
|
||||
return access
|
||||
.can("dead_hosts:list")
|
||||
.then((access_data) => {
|
||||
const query = deadHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.groupBy("id")
|
||||
.allowGraph("[owner,certificate]")
|
||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
if (access_data.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
// Query is used for searching
|
||||
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`);
|
||||
// Query is used for searching
|
||||
if (typeof search_query === "string" && search_query.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return query.then(utils.omitRows(omissions()));
|
||||
})
|
||||
.then((rows) => {
|
||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||
return internalHost.cleanAllRowsCertificateMeta(rows);
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
const rows = await query.then(utils.omitRows(omissions()));
|
||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||
internalHost.cleanAllRowsCertificateMeta(rows);
|
||||
}
|
||||
return rows;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -379,15 +455,16 @@ const internalDeadHost = {
|
||||
* @param {String} visibility
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getCount: async (user_id, visibility) => {
|
||||
getCount: (user_id, visibility) => {
|
||||
const query = deadHostModel.query().count("id as count").where("is_deleted", 0);
|
||||
|
||||
if (visibility !== "all") {
|
||||
query.andWhere("owner_user_id", user_id);
|
||||
}
|
||||
|
||||
const row = await query.first();
|
||||
return Number.parseInt(row.count, 10);
|
||||
return query.first().then((row) => {
|
||||
return Number.parseInt(row.count, 10);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -65,33 +65,50 @@ const internalHost = {
|
||||
},
|
||||
|
||||
/**
|
||||
* This returns all the host types with any domain listed in the provided domainNames array.
|
||||
* This returns all the host types with any domain listed in the provided domain_names array.
|
||||
* This is used by the certificates to temporarily disable any host that is using the domain
|
||||
*
|
||||
* @param {Array} domainNames
|
||||
* @param {Array} domain_names
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getHostsWithDomains: async (domainNames) => {
|
||||
const responseObject = {
|
||||
total_count: 0,
|
||||
dead_hosts: [],
|
||||
proxy_hosts: [],
|
||||
redirection_hosts: [],
|
||||
};
|
||||
getHostsWithDomains: (domain_names) => {
|
||||
const promises = [
|
||||
proxyHostModel.query().where("is_deleted", 0),
|
||||
redirectionHostModel.query().where("is_deleted", 0),
|
||||
deadHostModel.query().where("is_deleted", 0),
|
||||
];
|
||||
|
||||
const proxyRes = await proxyHostModel.query().where("is_deleted", 0);
|
||||
responseObject.proxy_hosts = internalHost._getHostsWithDomains(proxyRes, domainNames);
|
||||
responseObject.total_count += responseObject.proxy_hosts.length;
|
||||
return Promise.all(promises).then((promises_results) => {
|
||||
const response_object = {
|
||||
total_count: 0,
|
||||
dead_hosts: [],
|
||||
proxy_hosts: [],
|
||||
redirection_hosts: [],
|
||||
};
|
||||
|
||||
const redirRes = await redirectionHostModel.query().where("is_deleted", 0);
|
||||
responseObject.redirection_hosts = internalHost._getHostsWithDomains(redirRes, domainNames);
|
||||
responseObject.total_count += responseObject.redirection_hosts.length;
|
||||
if (promises_results[0]) {
|
||||
// Proxy Hosts
|
||||
response_object.proxy_hosts = internalHost._getHostsWithDomains(promises_results[0], domain_names);
|
||||
response_object.total_count += response_object.proxy_hosts.length;
|
||||
}
|
||||
|
||||
const deadRes = await deadHostModel.query().where("is_deleted", 0);
|
||||
responseObject.dead_hosts = internalHost._getHostsWithDomains(deadRes, domainNames);
|
||||
responseObject.total_count += responseObject.dead_hosts.length;
|
||||
if (promises_results[1]) {
|
||||
// Redirection Hosts
|
||||
response_object.redirection_hosts = internalHost._getHostsWithDomains(
|
||||
promises_results[1],
|
||||
domain_names,
|
||||
);
|
||||
response_object.total_count += response_object.redirection_hosts.length;
|
||||
}
|
||||
|
||||
return responseObject;
|
||||
if (promises_results[2]) {
|
||||
// Dead Hosts
|
||||
response_object.dead_hosts = internalHost._getHostsWithDomains(promises_results[2], domain_names);
|
||||
response_object.total_count += response_object.dead_hosts.length;
|
||||
}
|
||||
|
||||
return response_object;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -301,11 +301,8 @@ const internalNginx = {
|
||||
* @param {String} filename
|
||||
*/
|
||||
deleteFile: (filename) => {
|
||||
if (!fs.existsSync(filename)) {
|
||||
return;
|
||||
}
|
||||
logger.debug(`Deleting file: ${filename}`);
|
||||
try {
|
||||
logger.debug(`Deleting file: ${filename}`);
|
||||
fs.unlinkSync(filename);
|
||||
} catch (err) {
|
||||
logger.debug("Could not delete file:", JSON.stringify(err, null, 2));
|
||||
|
@@ -420,35 +420,41 @@ const internalProxyHost = {
|
||||
* @param {String} [search_query]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getAll: async (access, expand, searchQuery) => {
|
||||
const accessData = await access.can("proxy_hosts:list");
|
||||
const query = proxyHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.groupBy("id")
|
||||
.allowGraph("[owner,access_list,certificate]")
|
||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||
getAll: (access, expand, search_query) => {
|
||||
return access
|
||||
.can("proxy_hosts:list")
|
||||
.then((access_data) => {
|
||||
const query = proxyHostModel
|
||||
.query()
|
||||
.where("is_deleted", 0)
|
||||
.groupBy("id")
|
||||
.allowGraph("[owner,access_list,certificate]")
|
||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||
|
||||
if (accessData.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
if (access_data.permission_visibility !== "all") {
|
||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||
}
|
||||
|
||||
// Query is used for searching
|
||||
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`);
|
||||
// Query is used for searching
|
||||
if (typeof search_query === "string" && search_query.length > 0) {
|
||||
query.where(function () {
|
||||
this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
return query.then(utils.omitRows(omissions()));
|
||||
})
|
||||
.then((rows) => {
|
||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||
return internalHost.cleanAllRowsCertificateMeta(rows);
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof expand !== "undefined" && expand !== null) {
|
||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||
}
|
||||
|
||||
const rows = await query.then(utils.omitRows(omissions()));
|
||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||
return internalHost.cleanAllRowsCertificateMeta(rows);
|
||||
}
|
||||
return rows;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -348,7 +348,7 @@ const internalStream = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: "disabled",
|
||||
object_type: "stream",
|
||||
object_type: "stream-host",
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions()),
|
||||
});
|
||||
|
@@ -9,7 +9,7 @@ import internalAuditLog from "./audit-log.js";
|
||||
import internalToken from "./token.js";
|
||||
|
||||
const omissions = () => {
|
||||
return ["is_deleted", "permissions.id", "permissions.user_id", "permissions.created_on", "permissions.modified_on"];
|
||||
return ["is_deleted"];
|
||||
};
|
||||
|
||||
const DEFAULT_AVATAR = gravatar.url("admin@example.com", { default: "mm" });
|
||||
@@ -131,7 +131,7 @@ const internalUser = {
|
||||
action: "updated",
|
||||
object_type: "user",
|
||||
object_id: user.id,
|
||||
meta: { ...data, id: user.id, name: user.name },
|
||||
meta: data,
|
||||
})
|
||||
.then(() => {
|
||||
return user;
|
||||
@@ -250,14 +250,6 @@ const internalUser = {
|
||||
});
|
||||
},
|
||||
|
||||
deleteAll: async () => {
|
||||
await userModel
|
||||
.query()
|
||||
.patch({
|
||||
is_deleted: 1,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* This will only count the users
|
||||
*
|
||||
|
@@ -107,6 +107,7 @@ export default function (tokenString) {
|
||||
}
|
||||
|
||||
const tokenUserId = tokenData.attrs.id ? tokenData.attrs.id : 0;
|
||||
let query;
|
||||
|
||||
if (typeof objectCache[objectType] !== "undefined") {
|
||||
objects = objectCache[objectType];
|
||||
@@ -119,19 +120,15 @@ export default function (tokenString) {
|
||||
|
||||
// Proxy Hosts
|
||||
case "proxy_hosts": {
|
||||
const query = proxyHostModel
|
||||
.query()
|
||||
.select("id")
|
||||
.andWhere("is_deleted", 0);
|
||||
|
||||
query = proxyHostModel.query().select("id").andWhere("is_deleted", 0);
|
||||
if (permissions.visibility === "user") {
|
||||
query.andWhere("owner_user_id", tokenUserId);
|
||||
}
|
||||
|
||||
const rows = await query;
|
||||
const rows = await query();
|
||||
objects = [];
|
||||
_.forEach(rows, (ruleRow) => {
|
||||
objects.push(ruleRow.id);
|
||||
result.push(ruleRow.id);
|
||||
});
|
||||
|
||||
// enum should not have less than 1 item
|
||||
@@ -144,6 +141,7 @@ export default function (tokenString) {
|
||||
objectCache[objectType] = objects;
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
};
|
||||
|
||||
|
@@ -6,6 +6,46 @@ import utils from "./utils.js";
|
||||
|
||||
const CERTBOT_VERSION_REPLACEMENT = "$(certbot --version | grep -Eo '[0-9](\\.[0-9]+)+')";
|
||||
|
||||
/**
|
||||
* @param {array} pluginKeys
|
||||
*/
|
||||
const installPlugins = async (pluginKeys) => {
|
||||
let hasErrors = false;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (pluginKeys.length === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
batchflow(pluginKeys)
|
||||
.sequential()
|
||||
.each((_i, pluginKey, next) => {
|
||||
certbot
|
||||
.installPlugin(pluginKey)
|
||||
.then(() => {
|
||||
next();
|
||||
})
|
||||
.catch((err) => {
|
||||
hasErrors = true;
|
||||
next(err);
|
||||
});
|
||||
})
|
||||
.error((err) => {
|
||||
logger.error(err.message);
|
||||
})
|
||||
.end(() => {
|
||||
if (hasErrors) {
|
||||
reject(
|
||||
new errs.CommandError("Some plugins failed to install. Please check the logs above", 1),
|
||||
);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Installs a cerbot plugin given the key for the object from
|
||||
* ../global/certbot-dns-plugins.json
|
||||
@@ -44,43 +84,4 @@ const installPlugin = async (pluginKey) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {array} pluginKeys
|
||||
*/
|
||||
const installPlugins = async (pluginKeys) => {
|
||||
let hasErrors = false;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (pluginKeys.length === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
batchflow(pluginKeys)
|
||||
.sequential()
|
||||
.each((_i, pluginKey, next) => {
|
||||
installPlugin(pluginKey)
|
||||
.then(() => {
|
||||
next();
|
||||
})
|
||||
.catch((err) => {
|
||||
hasErrors = true;
|
||||
next(err);
|
||||
});
|
||||
})
|
||||
.error((err) => {
|
||||
logger.error(err.message);
|
||||
})
|
||||
.end(() => {
|
||||
if (hasErrors) {
|
||||
reject(
|
||||
new errs.CommandError("Some plugins failed to install. Please check the logs above", 1),
|
||||
);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export { installPlugins, installPlugin };
|
||||
|
@@ -199,13 +199,6 @@ const isPostgres = () => {
|
||||
*/
|
||||
const isDebugMode = () => !!process.env.DEBUG;
|
||||
|
||||
/**
|
||||
* Are we running in CI?
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isCI = () => process.env.CI === 'true' && process.env.DEBUG === 'true';
|
||||
|
||||
/**
|
||||
* Returns a public key
|
||||
*
|
||||
@@ -241,4 +234,4 @@ const useLetsencryptServer = () => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export { isCI, configHas, configGet, isSqlite, isMysql, isPostgres, isDebugMode, getPrivateKey, getPublicKey, useLetsencryptStaging, useLetsencryptServer };
|
||||
export { configHas, configGet, isSqlite, isMysql, isPostgres, isDebugMode, getPrivateKey, getPublicKey, useLetsencryptStaging, useLetsencryptServer };
|
||||
|
@@ -14,10 +14,7 @@ const errs = {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
this.name = this.constructor.name;
|
||||
this.previous = previous;
|
||||
this.message = "Not Found";
|
||||
if (id) {
|
||||
this.message = `Not Found - ${id}`;
|
||||
}
|
||||
this.message = `Item Not Found - ${id}`;
|
||||
this.public = true;
|
||||
this.status = 404;
|
||||
},
|
||||
|
@@ -128,7 +128,7 @@ export default () => {
|
||||
*/
|
||||
getUserId: (defaultValue) => {
|
||||
const attrs = self.get("attrs");
|
||||
if (attrs?.id) {
|
||||
if (attrs && typeof attrs.id !== "undefined" && attrs.id) {
|
||||
return attrs.id;
|
||||
}
|
||||
|
||||
|
@@ -3,5 +3,5 @@
|
||||
"ignore": [
|
||||
"data"
|
||||
],
|
||||
"ext": "js json ejs cjs"
|
||||
"ext": "js json ejs"
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apidevtools/swagger-parser": "^10.1.0",
|
||||
"@biomejs/biome": "^2.2.4",
|
||||
"@biomejs/biome": "^2.2.3",
|
||||
"chalk": "4.1.2",
|
||||
"nodemon": "^2.0.2"
|
||||
},
|
||||
|
@@ -2,7 +2,6 @@ import express from "express";
|
||||
import internalAuditLog from "../internal/audit-log.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import validator from "../lib/validator/index.js";
|
||||
import { express as logger } from "../logger.js";
|
||||
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
@@ -25,83 +24,31 @@ router
|
||||
*
|
||||
* Retrieve all logs
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalAuditLog.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Specific audit log entry
|
||||
*
|
||||
* /api/audit-log/123
|
||||
*/
|
||||
router
|
||||
.route("/:event_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /api/audit-log/123
|
||||
*
|
||||
* Retrieve a specific entry
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["event_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
event_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
event_id: req.params.event_id,
|
||||
expand:
|
||||
typeof req.query.expand === "string"
|
||||
? req.query.expand.split(",")
|
||||
: null,
|
||||
},
|
||||
);
|
||||
|
||||
const item = await internalAuditLog.get(res.locals.access, {
|
||||
id: data.event_id,
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(item);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAuditLog.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -3,7 +3,6 @@ import internalAccessList from "../../internal/access-list.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,31 +26,31 @@ router
|
||||
*
|
||||
* Retrieve all access-lists
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalAccessList.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAccessList.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ router
|
||||
*
|
||||
* Create a new access-list
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/access-lists", "post"), req.body);
|
||||
const result = await internalAccessList.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/access-lists", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalAccessList.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -87,35 +86,35 @@ router
|
||||
*
|
||||
* Retrieve a specific access-list
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["list_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
required: ["list_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
{
|
||||
list_id: req.params.list_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
);
|
||||
const row = await internalAccessList.get(res.locals.access, {
|
||||
id: Number.parseInt(data.list_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
list_id: req.params.list_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAccessList.get(res.locals.access, {
|
||||
id: Number.parseInt(data.list_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -123,16 +122,16 @@ router
|
||||
*
|
||||
* Update and existing access-list
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/access-lists/{listID}", "put"), req.body);
|
||||
payload.id = Number.parseInt(req.params.list_id, 10);
|
||||
const result = await internalAccessList.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/access-lists/{listID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = Number.parseInt(req.params.list_id, 10);
|
||||
return internalAccessList.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -140,16 +139,13 @@ router
|
||||
*
|
||||
* Delete and existing access-list
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalAccessList.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.list_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalAccessList
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.list_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -1,11 +1,9 @@
|
||||
import express from "express";
|
||||
import dnsPlugins from "../../global/certbot-dns-plugins.json" with { type: "json" };
|
||||
import internalCertificate from "../../internal/certificate.js";
|
||||
import errs from "../../lib/error.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -29,31 +27,31 @@ router
|
||||
*
|
||||
* Retrieve all certificates
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalCertificate.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalCertificate.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -61,50 +59,16 @@ router
|
||||
*
|
||||
* Create a new certificate
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/certificates", "post"), req.body);
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
const result = await internalCertificate.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/certificates/dns-providers
|
||||
*/
|
||||
router
|
||||
.route("/dns-providers")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /api/nginx/certificates/dns-providers
|
||||
*
|
||||
* Get list of all supported DNS providers
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
if (!res.locals.access.token.getUserId()) {
|
||||
throw new errs.PermissionError("Login required");
|
||||
}
|
||||
const clean = Object.keys(dnsPlugins).map((key) => ({
|
||||
id: key,
|
||||
name: dnsPlugins[key].name,
|
||||
credentials: dnsPlugins[key].credentials,
|
||||
}));
|
||||
|
||||
clean.sort((a, b) => a.name.localeCompare(b.name));
|
||||
res.status(200).send(clean);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/certificates", "post"), req.body)
|
||||
.then((payload) => {
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
return internalCertificate.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -124,57 +88,18 @@ router
|
||||
*
|
||||
* Test HTTP challenge for domains
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
.get((req, res, next) => {
|
||||
if (req.query.domains === undefined) {
|
||||
next(new errs.ValidationError("Domains are required as query parameters"));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await internalCertificate.testHttpsChallenge(
|
||||
res.locals.access,
|
||||
JSON.parse(req.query.domains),
|
||||
);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Validate Certs before saving
|
||||
*
|
||||
* /api/nginx/certificates/validate
|
||||
*/
|
||||
router
|
||||
.route("/validate")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* POST /api/nginx/certificates/validate
|
||||
*
|
||||
* Validate certificates
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
if (!req.files) {
|
||||
res.status(400).send({ error: "No files were uploaded" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await internalCertificate.validate({
|
||||
files: req.files,
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
internalCertificate
|
||||
.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -194,35 +119,35 @@ router
|
||||
*
|
||||
* Retrieve a specific certificate
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["certificate_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
certificate_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
required: ["certificate_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
certificate_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
{
|
||||
certificate_id: req.params.certificate_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
);
|
||||
const row = await internalCertificate.get(res.locals.access, {
|
||||
id: Number.parseInt(data.certificate_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
certificate_id: req.params.certificate_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalCertificate.get(res.locals.access, {
|
||||
id: Number.parseInt(data.certificate_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -230,16 +155,13 @@ router
|
||||
*
|
||||
* Update and existing certificate
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalCertificate.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalCertificate
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.certificate_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -259,21 +181,19 @@ router
|
||||
*
|
||||
* Upload certificates
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
.post((req, res, next) => {
|
||||
if (!req.files) {
|
||||
res.status(400).send({ error: "No files were uploaded" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await internalCertificate.upload(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
files: req.files,
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
} else {
|
||||
internalCertificate
|
||||
.upload(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
files: req.files,
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -294,17 +214,16 @@ router
|
||||
*
|
||||
* Renew certificate
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
.post((req, res, next) => {
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
try {
|
||||
const result = await internalCertificate.renew(res.locals.access, {
|
||||
internalCertificate
|
||||
.renew(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -324,15 +243,46 @@ router
|
||||
*
|
||||
* Renew certificate
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalCertificate.download(res.locals.access, {
|
||||
.get((req, res, next) => {
|
||||
internalCertificate
|
||||
.download(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
});
|
||||
res.status(200).download(result.fileName);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).download(result.fileName);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Validate Certs before saving
|
||||
*
|
||||
* /api/nginx/certificates/validate
|
||||
*/
|
||||
router
|
||||
.route("/validate")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* POST /api/nginx/certificates/validate
|
||||
*
|
||||
* Validate certificates
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
if (!req.files) {
|
||||
res.status(400).send({ error: "No files were uploaded" });
|
||||
} else {
|
||||
internalCertificate
|
||||
.validate({
|
||||
files: req.files,
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -3,7 +3,6 @@ import internalDeadHost from "../../internal/dead-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,31 +26,31 @@ router
|
||||
*
|
||||
* Retrieve all dead-hosts
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalDeadHost.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalDeadHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ router
|
||||
*
|
||||
* Create a new dead-host
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/dead-hosts", "post"), req.body);
|
||||
const result = await internalDeadHost.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/dead-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalDeadHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -87,69 +86,66 @@ router
|
||||
*
|
||||
* Retrieve a specific dead-host
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.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,
|
||||
},
|
||||
);
|
||||
const row = await internalDeadHost.get(res.locals.access, {
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
host_id: req.params.host_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalDeadHost.get(res.locals.access, {
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* PUT /api/nginx/dead-hosts/123
|
||||
*
|
||||
* Update an existing dead-host
|
||||
* Update and existing dead-host
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/dead-hosts/{hostID}", "put"), req.body);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
const result = await internalDeadHost.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/dead-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalDeadHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* DELETE /api/nginx/dead-hosts/123
|
||||
*
|
||||
* Delete a dead-host
|
||||
* Update and existing dead-host
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalDeadHost.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalDeadHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -167,16 +163,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/dead-hosts/123/enable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalDeadHost.enable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalDeadHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -195,13 +188,12 @@ router
|
||||
* POST /api/nginx/dead-hosts/123/disable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
try {
|
||||
const result = internalDeadHost.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) });
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
internalDeadHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -3,7 +3,6 @@ import internalProxyHost from "../../internal/proxy-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,31 +26,31 @@ router
|
||||
*
|
||||
* Retrieve all proxy-hosts
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalProxyHost.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalProxyHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ router
|
||||
*
|
||||
* Create a new proxy-host
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/proxy-hosts", "post"), req.body);
|
||||
const result = await internalProxyHost.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/proxy-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalProxyHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -87,35 +86,35 @@ router
|
||||
*
|
||||
* Retrieve a specific proxy-host
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.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,
|
||||
},
|
||||
);
|
||||
const row = await internalProxyHost.get(res.locals.access, {
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
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: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -123,16 +122,16 @@ router
|
||||
*
|
||||
* Update and existing proxy-host
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/proxy-hosts/{hostID}", "put"), req.body);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
const result = await internalProxyHost.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/proxy-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalProxyHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -140,16 +139,13 @@ router
|
||||
*
|
||||
* Update and existing proxy-host
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalProxyHost.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalProxyHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -167,16 +163,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/proxy-hosts/123/enable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalProxyHost.enable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalProxyHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -194,16 +187,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/proxy-hosts/123/disable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalProxyHost.disable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalProxyHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -3,7 +3,6 @@ import internalRedirectionHost from "../../internal/redirection-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,31 +26,31 @@ router
|
||||
*
|
||||
* Retrieve all redirection-hosts
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalRedirectionHost.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalRedirectionHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ router
|
||||
*
|
||||
* Create a new redirection-host
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/redirection-hosts", "post"), req.body);
|
||||
const result = await internalRedirectionHost.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/redirection-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalRedirectionHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -87,35 +86,35 @@ router
|
||||
*
|
||||
* Retrieve a specific redirection-host
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.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,
|
||||
},
|
||||
);
|
||||
const row = await internalRedirectionHost.get(res.locals.access, {
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
host_id: req.params.host_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalRedirectionHost.get(res.locals.access, {
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -123,19 +122,16 @@ router
|
||||
*
|
||||
* Update and existing redirection-host
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(
|
||||
getValidationSchema("/nginx/redirection-hosts/{hostID}", "put"),
|
||||
req.body,
|
||||
);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
const result = await internalRedirectionHost.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/redirection-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalRedirectionHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -143,16 +139,13 @@ router
|
||||
*
|
||||
* Update and existing redirection-host
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalRedirectionHost.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalRedirectionHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -170,16 +163,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/redirection-hosts/123/enable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalRedirectionHost.enable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalRedirectionHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -197,16 +187,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/redirection-hosts/123/disable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalRedirectionHost.disable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalRedirectionHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -3,7 +3,6 @@ import internalStream from "../../internal/stream.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { express as logger } from "../../logger.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,31 +26,31 @@ router
|
||||
*
|
||||
* Retrieve all streams
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const rows = await internalStream.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalStream.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ router
|
||||
*
|
||||
* Create a new stream
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/streams", "post"), req.body);
|
||||
const result = await internalStream.create(res.locals.access, payload);
|
||||
res.status(201).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/streams", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalStream.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -87,35 +86,35 @@ router
|
||||
*
|
||||
* Retrieve a specific stream
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["stream_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
stream_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
required: ["stream_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
stream_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
{
|
||||
stream_id: req.params.stream_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
);
|
||||
const row = await internalStream.get(res.locals.access, {
|
||||
id: Number.parseInt(data.stream_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
stream_id: req.params.stream_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalStream.get(res.locals.access, {
|
||||
id: Number.parseInt(data.stream_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -123,16 +122,16 @@ router
|
||||
*
|
||||
* Update and existing stream
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/nginx/streams/{streamID}", "put"), req.body);
|
||||
payload.id = Number.parseInt(req.params.stream_id, 10);
|
||||
const result = await internalStream.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/nginx/streams/{streamID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = Number.parseInt(req.params.stream_id, 10);
|
||||
return internalStream.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -140,16 +139,13 @@ router
|
||||
*
|
||||
* Update and existing stream
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalStream.delete(res.locals.access, {
|
||||
id: Number.parseInt(req.params.stream_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.delete((req, res, next) => {
|
||||
internalStream
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.stream_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -167,16 +163,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/streams/123/enable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalStream.enable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalStream
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -194,16 +187,13 @@ router
|
||||
/**
|
||||
* POST /api/nginx/streams/123/disable
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalStream.disable(res.locals.access, {
|
||||
id: Number.parseInt(req.params.host_id, 10),
|
||||
});
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.post((req, res, next) => {
|
||||
internalStream
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import express from "express";
|
||||
import internalReport from "../internal/report.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import { express as logger } from "../logger.js";
|
||||
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
@@ -14,19 +13,17 @@ router
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /reports/hosts
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await internalReport.getHostsReport(res.locals.access);
|
||||
res.status(200).send(data);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.get(jwtdecode(), (_, res, next) => {
|
||||
internalReport
|
||||
.getHostsReport(res.locals.access)
|
||||
.then((data) => {
|
||||
res.status(200).send(data);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import express from "express";
|
||||
import { express as logger } from "../logger.js";
|
||||
import PACKAGE from "../package.json" with { type: "json" };
|
||||
import { getCompiledSchema } from "../schema/index.js";
|
||||
|
||||
@@ -19,26 +18,21 @@ router
|
||||
* GET /schema
|
||||
*/
|
||||
.get(async (req, res) => {
|
||||
try {
|
||||
const swaggerJSON = await getCompiledSchema();
|
||||
const swaggerJSON = await getCompiledSchema();
|
||||
|
||||
let proto = req.protocol;
|
||||
if (typeof req.headers["x-forwarded-proto"] !== "undefined" && req.headers["x-forwarded-proto"]) {
|
||||
proto = req.headers["x-forwarded-proto"];
|
||||
}
|
||||
|
||||
let origin = `${proto}://${req.hostname}`;
|
||||
if (typeof req.headers.origin !== "undefined" && req.headers.origin) {
|
||||
origin = req.headers.origin;
|
||||
}
|
||||
|
||||
swaggerJSON.info.version = PACKAGE.version;
|
||||
swaggerJSON.servers[0].url = `${origin}/api`;
|
||||
res.status(200).send(swaggerJSON);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
let proto = req.protocol;
|
||||
if (typeof req.headers["x-forwarded-proto"] !== "undefined" && req.headers["x-forwarded-proto"]) {
|
||||
proto = req.headers["x-forwarded-proto"];
|
||||
}
|
||||
|
||||
let origin = `${proto}://${req.hostname}`;
|
||||
if (typeof req.headers.origin !== "undefined" && req.headers.origin) {
|
||||
origin = req.headers.origin;
|
||||
}
|
||||
|
||||
swaggerJSON.info.version = PACKAGE.version;
|
||||
swaggerJSON.servers[0].url = `${origin}/api`;
|
||||
res.status(200).send(swaggerJSON);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -3,7 +3,6 @@ import internalSetting from "../internal/setting.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../lib/validator/api.js";
|
||||
import validator from "../lib/validator/index.js";
|
||||
import { express as logger } from "../logger.js";
|
||||
import { getValidationSchema } from "../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
@@ -27,14 +26,13 @@ router
|
||||
*
|
||||
* Retrieve all settings
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const rows = await internalSetting.getAll(res.locals.access);
|
||||
res.status(200).send(rows);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.get((_, res, next) => {
|
||||
internalSetting
|
||||
.getAll(res.locals.access)
|
||||
.then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -54,31 +52,31 @@ router
|
||||
*
|
||||
* Retrieve a specific setting
|
||||
*/
|
||||
.get(async (req, res, next) => {
|
||||
try {
|
||||
const data = await validator(
|
||||
{
|
||||
required: ["setting_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
setting_id: {
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
},
|
||||
.get((req, res, next) => {
|
||||
validator(
|
||||
{
|
||||
required: ["setting_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
setting_id: {
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
setting_id: req.params.setting_id,
|
||||
},
|
||||
);
|
||||
const row = await internalSetting.get(res.locals.access, {
|
||||
id: data.setting_id,
|
||||
});
|
||||
res.status(200).send(row);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
},
|
||||
{
|
||||
setting_id: req.params.setting_id,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalSetting.get(res.locals.access, {
|
||||
id: data.setting_id,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -86,16 +84,16 @@ router
|
||||
*
|
||||
* Update and existing setting
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(getValidationSchema("/settings/{settingID}", "put"), req.body);
|
||||
payload.id = req.params.setting_id;
|
||||
const result = await internalSetting.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
.put((req, res, next) => {
|
||||
apiValidator(getValidationSchema("/settings/{settingID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.setting_id;
|
||||
return internalSetting.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@@ -1,8 +1,6 @@
|
||||
import express from "express";
|
||||
import internalUser from "../internal/user.js";
|
||||
import Access from "../lib/access.js";
|
||||
import { isCI } from "../lib/config.js";
|
||||
import errs from "../lib/error.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import userIdFromMe from "../lib/express/user-id-from-me.js";
|
||||
import apiValidator from "../lib/validator/api.js";
|
||||
@@ -47,18 +45,11 @@ router
|
||||
},
|
||||
},
|
||||
{
|
||||
expand:
|
||||
typeof req.query.expand === "string"
|
||||
? req.query.expand.split(",")
|
||||
: null,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
);
|
||||
const users = await internalUser.getAll(
|
||||
res.locals.access,
|
||||
data.expand,
|
||||
data.query,
|
||||
);
|
||||
const users = await internalUser.getAll(res.locals.access, data.expand, data.query);
|
||||
res.status(200).send(users);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
@@ -94,43 +85,13 @@ router
|
||||
}
|
||||
}
|
||||
|
||||
const payload = await apiValidator(
|
||||
getValidationSchema("/users", "post"),
|
||||
body,
|
||||
);
|
||||
const payload = await apiValidator(getValidationSchema("/users", "post"), body);
|
||||
const user = await internalUser.create(res.locals.access, payload);
|
||||
res.status(201).send(user);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* DELETE /api/users
|
||||
*
|
||||
* Deletes ALL users. This is NOT GENERALLY AVAILABLE!
|
||||
* (!) It is NOT an authenticated endpoint.
|
||||
* (!) Only CI should be able to call this endpoint. As a result,
|
||||
*
|
||||
* it will only work when the env vars DEBUG=true and CI=true
|
||||
*
|
||||
* Do NOT set those env vars in a production environment!
|
||||
*/
|
||||
.delete(async (_, res, next) => {
|
||||
if (isCI()) {
|
||||
try {
|
||||
logger.warn("Deleting all users - CI environment detected, allowing this operation");
|
||||
await internalUser.deleteAll();
|
||||
res.status(200).send(true);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
next(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
next(new errs.ItemNotFoundError());
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -168,20 +129,14 @@ router
|
||||
},
|
||||
{
|
||||
user_id: req.params.user_id,
|
||||
expand:
|
||||
typeof req.query.expand === "string"
|
||||
? req.query.expand.split(",")
|
||||
: null,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
);
|
||||
|
||||
const user = await internalUser.get(res.locals.access, {
|
||||
id: data.user_id,
|
||||
expand: data.expand,
|
||||
omit: internalUser.getUserOmisionsByAccess(
|
||||
res.locals.access,
|
||||
data.user_id,
|
||||
),
|
||||
omit: internalUser.getUserOmisionsByAccess(res.locals.access, data.user_id),
|
||||
});
|
||||
res.status(200).send(user);
|
||||
} catch (err) {
|
||||
@@ -197,10 +152,7 @@ router
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(
|
||||
getValidationSchema("/users/{userID}", "put"),
|
||||
req.body,
|
||||
);
|
||||
const payload = await apiValidator(getValidationSchema("/users/{userID}", "put"), req.body);
|
||||
payload.id = req.params.user_id;
|
||||
const result = await internalUser.update(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
@@ -217,9 +169,7 @@ router
|
||||
*/
|
||||
.delete(async (req, res, next) => {
|
||||
try {
|
||||
const result = await internalUser.delete(res.locals.access, {
|
||||
id: req.params.user_id,
|
||||
});
|
||||
const result = await internalUser.delete(res.locals.access, { id: req.params.user_id });
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
@@ -247,10 +197,7 @@ router
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(
|
||||
getValidationSchema("/users/{userID}/auth", "put"),
|
||||
req.body,
|
||||
);
|
||||
const payload = await apiValidator(getValidationSchema("/users/{userID}/auth", "put"), req.body);
|
||||
payload.id = req.params.user_id;
|
||||
const result = await internalUser.setPassword(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
@@ -280,15 +227,9 @@ router
|
||||
*/
|
||||
.put(async (req, res, next) => {
|
||||
try {
|
||||
const payload = await apiValidator(
|
||||
getValidationSchema("/users/{userID}/permissions", "put"),
|
||||
req.body,
|
||||
);
|
||||
const payload = await apiValidator(getValidationSchema("/users/{userID}/permissions", "put"), req.body);
|
||||
payload.id = req.params.user_id;
|
||||
const result = await internalUser.setPermissions(
|
||||
res.locals.access,
|
||||
payload,
|
||||
);
|
||||
const result = await internalUser.setPermissions(res.locals.access, payload);
|
||||
res.status(200).send(result);
|
||||
} catch (err) {
|
||||
logger.debug(`${req.method.toUpperCase()} ${req.path}: ${err}`);
|
||||
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"type": "array",
|
||||
"description": "Audit Log list",
|
||||
"items": {
|
||||
"$ref": "./audit-log-object.json"
|
||||
}
|
||||
}
|
@@ -1,16 +1,7 @@
|
||||
{
|
||||
"type": "object",
|
||||
"description": "Audit Log object",
|
||||
"required": [
|
||||
"id",
|
||||
"created_on",
|
||||
"modified_on",
|
||||
"user_id",
|
||||
"object_type",
|
||||
"object_id",
|
||||
"action",
|
||||
"meta"
|
||||
],
|
||||
"required": ["id", "created_on", "modified_on", "user_id", "object_type", "object_id", "action", "meta"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -36,9 +27,6 @@
|
||||
},
|
||||
"meta": {
|
||||
"type": "object"
|
||||
},
|
||||
"user": {
|
||||
"$ref": "./user-object.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -62,9 +62,15 @@
|
||||
"dns_provider_credentials": {
|
||||
"type": "string"
|
||||
},
|
||||
"letsencrypt_agree": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"letsencrypt_certificate": {
|
||||
"type": "object"
|
||||
},
|
||||
"letsencrypt_email": {
|
||||
"$ref": "../common.json#/properties/email"
|
||||
},
|
||||
"propagation_seconds": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
|
@@ -9,11 +9,6 @@
|
||||
"description": "Healthy",
|
||||
"example": "OK"
|
||||
},
|
||||
"setup": {
|
||||
"type": "boolean",
|
||||
"description": "Whether the initial setup has been completed",
|
||||
"example": true
|
||||
},
|
||||
"version": {
|
||||
"type": "object",
|
||||
"description": "The version object",
|
||||
|
@@ -31,7 +31,7 @@
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"format": "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$"
|
||||
"format": "ipv4"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
|
@@ -54,63 +54,6 @@
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"permissions": {
|
||||
"type": "object",
|
||||
"description": "Permissions if expanded in request",
|
||||
"required": [
|
||||
"visibility",
|
||||
"proxy_hosts",
|
||||
"redirection_hosts",
|
||||
"dead_hosts",
|
||||
"streams",
|
||||
"access_lists",
|
||||
"certificates"
|
||||
],
|
||||
"properties": {
|
||||
"visibility": {
|
||||
"type": "string",
|
||||
"description": "Visibility level",
|
||||
"example": "all",
|
||||
"pattern": "^(all|user)$"
|
||||
},
|
||||
"proxy_hosts": {
|
||||
"type": "string",
|
||||
"description": "Proxy Hosts access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
},
|
||||
"redirection_hosts": {
|
||||
"type": "string",
|
||||
"description": "Redirection Hosts access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
},
|
||||
"dead_hosts": {
|
||||
"type": "string",
|
||||
"description": "Dead Hosts access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
},
|
||||
"streams": {
|
||||
"type": "string",
|
||||
"description": "Streams access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
},
|
||||
"access_lists": {
|
||||
"type": "string",
|
||||
"description": "Access Lists access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
},
|
||||
"certificates": {
|
||||
"type": "string",
|
||||
"description": "Certificates access level",
|
||||
"example": "all",
|
||||
"pattern": "^(manage|view|hidden)$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"operationId": "getAuditLogs",
|
||||
"summary": "Get Audit Logs",
|
||||
"operationId": "getAuditLog",
|
||||
"summary": "Get Audit Log",
|
||||
"tags": ["Audit Log"],
|
||||
"security": [
|
||||
{
|
||||
@@ -44,7 +44,7 @@
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"$ref": "../../components/audit-log-list.json"
|
||||
"$ref": "../../components/audit-log-object.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,73 +0,0 @@
|
||||
{
|
||||
"operationId": "getAuditLog",
|
||||
"summary": "Get Audit Log Event",
|
||||
"tags": [
|
||||
"Audit Log"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"BearerAuth": [
|
||||
"audit-log"
|
||||
]
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "id",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"required": true,
|
||||
"example": 1
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "200 response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"examples": {
|
||||
"default": {
|
||||
"value": {
|
||||
"id": 1,
|
||||
"created_on": "2025-09-15T17:27:45.000Z",
|
||||
"modified_on": "2025-09-15T17:27:45.000Z",
|
||||
"user_id": 1,
|
||||
"object_type": "user",
|
||||
"object_id": 1,
|
||||
"action": "created",
|
||||
"meta": {
|
||||
"id": 1,
|
||||
"created_on": "2025-09-15T17:27:45.000Z",
|
||||
"modified_on": "2025-09-15T17:27:45.000Z",
|
||||
"is_disabled": false,
|
||||
"email": "jc@jc21.com",
|
||||
"name": "Jamie",
|
||||
"nickname": "Jamie",
|
||||
"avatar": "//www.gravatar.com/avatar/6193176330f8d38747f038c170ddb193?default=mm",
|
||||
"roles": [
|
||||
"admin"
|
||||
],
|
||||
"permissions": {
|
||||
"visibility": "all",
|
||||
"proxy_hosts": "manage",
|
||||
"redirection_hosts": "manage",
|
||||
"dead_hosts": "manage",
|
||||
"streams": "manage",
|
||||
"access_lists": "manage",
|
||||
"certificates": "manage"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"$ref": "../../../components/audit-log-object.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@
|
||||
"default": {
|
||||
"value": {
|
||||
"status": "OK",
|
||||
"setup": true,
|
||||
"version": {
|
||||
"major": 2,
|
||||
"minor": 1,
|
||||
|
@@ -36,6 +36,8 @@
|
||||
"domain_names": ["test.example.com"],
|
||||
"expires_on": "2025-01-07T04:34:18.000Z",
|
||||
"meta": {
|
||||
"letsencrypt_email": "jc@jc21.com",
|
||||
"letsencrypt_agree": true,
|
||||
"dns_challenge": false
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,8 @@
|
||||
"nice_name": "My Test Cert",
|
||||
"domain_names": ["test.jc21.supernerd.pro"],
|
||||
"meta": {
|
||||
"letsencrypt_email": "jc@jc21.com",
|
||||
"letsencrypt_agree": true,
|
||||
"dns_challenge": false
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@
|
||||
"domain_names": ["test.example.com"],
|
||||
"expires_on": "2025-01-07T04:34:18.000Z",
|
||||
"meta": {
|
||||
"letsencrypt_email": "jc@jc21.com",
|
||||
"letsencrypt_agree": true,
|
||||
"dns_challenge": false
|
||||
}
|
||||
}
|
||||
|
@@ -52,6 +52,8 @@
|
||||
"nice_name": "test.example.com",
|
||||
"domain_names": ["test.example.com"],
|
||||
"meta": {
|
||||
"letsencrypt_email": "jc@jc21.com",
|
||||
"letsencrypt_agree": true,
|
||||
"dns_challenge": false,
|
||||
"letsencrypt_certificate": {
|
||||
"cn": "test.example.com",
|
||||
|
@@ -37,9 +37,6 @@
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "../../../components/stream-object.json#/properties/meta"
|
||||
},
|
||||
"domain_names": {
|
||||
"$ref": "../../../components/dead-host-object.json#/properties/domain_names"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,11 +29,6 @@
|
||||
"$ref": "./paths/audit-log/get.json"
|
||||
}
|
||||
},
|
||||
"/audit-log/{id}": {
|
||||
"get": {
|
||||
"$ref": "./paths/audit-log/id/get.json"
|
||||
}
|
||||
},
|
||||
"/nginx/access-lists": {
|
||||
"get": {
|
||||
"$ref": "./paths/nginx/access-lists/get.json"
|
||||
|
@@ -121,13 +121,11 @@ const setupCertbotPlugins = async () => {
|
||||
// Make sure credentials file exists
|
||||
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
||||
// Escape single quotes and backslashes
|
||||
if (typeof certificate.meta.dns_provider_credentials === "string") {
|
||||
const escapedCredentials = certificate.meta.dns_provider_credentials
|
||||
.replaceAll("'", "\\'")
|
||||
.replaceAll("\\", "\\\\");
|
||||
const credentials_cmd = `[ -f '${credentials_loc}' ] || { mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo '${escapedCredentials}' > '${credentials_loc}' && chmod 600 '${credentials_loc}'; }`;
|
||||
promises.push(utils.exec(credentials_cmd));
|
||||
}
|
||||
const escapedCredentials = certificate.meta.dns_provider_credentials
|
||||
.replaceAll("'", "\\'")
|
||||
.replaceAll("\\", "\\\\");
|
||||
const credentials_cmd = `[ -f '${credentials_loc}' ] || { mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo '${escapedCredentials}' > '${credentials_loc}' && chmod 600 '${credentials_loc}'; }`;
|
||||
promises.push(utils.exec(credentials_cmd));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@@ -43,59 +43,59 @@
|
||||
ajv-draft-04 "^1.0.0"
|
||||
call-me-maybe "^1.0.2"
|
||||
|
||||
"@biomejs/biome@^2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-2.2.4.tgz#184e4b83f89bd0d4151682a5aa3840df37748e17"
|
||||
integrity sha512-TBHU5bUy/Ok6m8c0y3pZiuO/BZoY/OcGxoLlrfQof5s8ISVwbVBdFINPQZyFfKwil8XibYWb7JMwnT8wT4WVPg==
|
||||
"@biomejs/biome@^2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-2.2.3.tgz#9d17991c80e006c5ca3e21bebe84b7afd71559e3"
|
||||
integrity sha512-9w0uMTvPrIdvUrxazZ42Ib7t8Y2yoGLKLdNne93RLICmaHw7mcLv4PPb5LvZLJF3141gQHiCColOh/v6VWlWmg==
|
||||
optionalDependencies:
|
||||
"@biomejs/cli-darwin-arm64" "2.2.4"
|
||||
"@biomejs/cli-darwin-x64" "2.2.4"
|
||||
"@biomejs/cli-linux-arm64" "2.2.4"
|
||||
"@biomejs/cli-linux-arm64-musl" "2.2.4"
|
||||
"@biomejs/cli-linux-x64" "2.2.4"
|
||||
"@biomejs/cli-linux-x64-musl" "2.2.4"
|
||||
"@biomejs/cli-win32-arm64" "2.2.4"
|
||||
"@biomejs/cli-win32-x64" "2.2.4"
|
||||
"@biomejs/cli-darwin-arm64" "2.2.3"
|
||||
"@biomejs/cli-darwin-x64" "2.2.3"
|
||||
"@biomejs/cli-linux-arm64" "2.2.3"
|
||||
"@biomejs/cli-linux-arm64-musl" "2.2.3"
|
||||
"@biomejs/cli-linux-x64" "2.2.3"
|
||||
"@biomejs/cli-linux-x64-musl" "2.2.3"
|
||||
"@biomejs/cli-win32-arm64" "2.2.3"
|
||||
"@biomejs/cli-win32-x64" "2.2.3"
|
||||
|
||||
"@biomejs/cli-darwin-arm64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.2.4.tgz#9b50620c93501e370b7e6d5a8445f117f9946a0c"
|
||||
integrity sha512-RJe2uiyaloN4hne4d2+qVj3d3gFJFbmrr5PYtkkjei1O9c+BjGXgpUPVbi8Pl8syumhzJjFsSIYkcLt2VlVLMA==
|
||||
"@biomejs/cli-darwin-arm64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.2.3.tgz#e18240343fa705dafb08ba72a7b0e88f04a8be3e"
|
||||
integrity sha512-OrqQVBpadB5eqzinXN4+Q6honBz+tTlKVCsbEuEpljK8ASSItzIRZUA02mTikl3H/1nO2BMPFiJ0nkEZNy3B1w==
|
||||
|
||||
"@biomejs/cli-darwin-x64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.2.4.tgz#343620c884fc8141155d114430e80e4eacfddc9e"
|
||||
integrity sha512-cFsdB4ePanVWfTnPVaUX+yr8qV8ifxjBKMkZwN7gKb20qXPxd/PmwqUH8mY5wnM9+U0QwM76CxFyBRJhC9tQwg==
|
||||
"@biomejs/cli-darwin-x64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.2.3.tgz#964b51c9f649e3a725f6f43e75c4173b9ab8a3ae"
|
||||
integrity sha512-OCdBpb1TmyfsTgBAM1kPMXyYKTohQ48WpiN9tkt9xvU6gKVKHY4oVwteBebiOqyfyzCNaSiuKIPjmHjUZ2ZNMg==
|
||||
|
||||
"@biomejs/cli-linux-arm64-musl@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.2.4.tgz#cabcdadce2bc88b697f4063374224266c6f8b6e5"
|
||||
integrity sha512-7TNPkMQEWfjvJDaZRSkDCPT/2r5ESFPKx+TEev+I2BXDGIjfCZk2+b88FOhnJNHtksbOZv8ZWnxrA5gyTYhSsQ==
|
||||
"@biomejs/cli-linux-arm64-musl@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.2.3.tgz#1756c37960d5585ca865e184539b113e48719b41"
|
||||
integrity sha512-q3w9jJ6JFPZPeqyvwwPeaiS/6NEszZ+pXKF+IczNo8Xj6fsii45a4gEEicKyKIytalV+s829ACZujQlXAiVLBQ==
|
||||
|
||||
"@biomejs/cli-linux-arm64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.2.4.tgz#55620f8f088145e62e1158eb85c568554d0c8673"
|
||||
integrity sha512-M/Iz48p4NAzMXOuH+tsn5BvG/Jb07KOMTdSVwJpicmhN309BeEyRyQX+n1XDF0JVSlu28+hiTQ2L4rZPvu7nMw==
|
||||
"@biomejs/cli-linux-arm64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.2.3.tgz#036c6334d5b09b51233ce5120b18f4c89a15a74c"
|
||||
integrity sha512-g/Uta2DqYpECxG+vUmTAmUKlVhnGEcY7DXWgKP8ruLRa8Si1QHsWknPY3B/wCo0KgYiFIOAZ9hjsHfNb9L85+g==
|
||||
|
||||
"@biomejs/cli-linux-x64-musl@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.2.4.tgz#6bfaea72505afdbda66a66c998d2d169a8b55f90"
|
||||
integrity sha512-m41nFDS0ksXK2gwXL6W6yZTYPMH0LughqbsxInSKetoH6morVj43szqKx79Iudkp8WRT5SxSh7qVb8KCUiewGg==
|
||||
"@biomejs/cli-linux-x64-musl@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.2.3.tgz#e6cce01910b9f56c1645c5518595d0b1eb38c245"
|
||||
integrity sha512-y76Dn4vkP1sMRGPFlNc+OTETBhGPJ90jY3il6jAfur8XWrYBQV3swZ1Jo0R2g+JpOeeoA0cOwM7mJG6svDz79w==
|
||||
|
||||
"@biomejs/cli-linux-x64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-2.2.4.tgz#8c1ed61dcafb8a5939346c714ec122651f57e1db"
|
||||
integrity sha512-orr3nnf2Dpb2ssl6aihQtvcKtLySLta4E2UcXdp7+RTa7mfJjBgIsbS0B9GC8gVu0hjOu021aU8b3/I1tn+pVQ==
|
||||
"@biomejs/cli-linux-x64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-2.2.3.tgz#f328e7cfde92fad6c7ad215df1f51b146b4ed007"
|
||||
integrity sha512-LEtyYL1fJsvw35CxrbQ0gZoxOG3oZsAjzfRdvRBRHxOpQ91Q5doRVjvWW/wepgSdgk5hlaNzfeqpyGmfSD0Eyw==
|
||||
|
||||
"@biomejs/cli-win32-arm64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.2.4.tgz#b2528f6c436e753d6083d7779f0662e08786cedb"
|
||||
integrity sha512-NXnfTeKHDFUWfxAefa57DiGmu9VyKi0cDqFpdI+1hJWQjGJhJutHPX0b5m+eXvTKOaf+brU+P0JrQAZMb5yYaQ==
|
||||
"@biomejs/cli-win32-arm64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.2.3.tgz#b8d64ca6dc1c50b8f3d42475afd31b7b44460935"
|
||||
integrity sha512-Ms9zFYzjcJK7LV+AOMYnjN3pV3xL8Prxf9aWdDVL74onLn5kcvZ1ZMQswE5XHtnd/r/0bnUd928Rpbs14BzVmA==
|
||||
|
||||
"@biomejs/cli-win32-x64@2.2.4":
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-2.2.4.tgz#c8e21413120fe073fa49b78fdd987022941ff66f"
|
||||
integrity sha512-3Y4V4zVRarVh/B/eSHczR4LYoSVyv3Dfuvm3cWs5w/HScccS0+Wt/lHOcDTRYeHjQmMYVC3rIRWqyN2EI52+zg==
|
||||
"@biomejs/cli-win32-x64@2.2.3":
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-2.2.3.tgz#ecafffddf0c0675c825735c7cc917cbc8c538433"
|
||||
integrity sha512-gvCpewE7mBwBIpqk1YrUqNR4mCiyJm6UI3YWQQXkedSSEwzRdodRpaKhbdbHw1/hmTWOVXQ+Eih5Qctf4TCVOQ==
|
||||
|
||||
"@gar/promisify@^1.0.1":
|
||||
version "1.1.3"
|
||||
|
@@ -15,7 +15,7 @@ ENV SUPPRESS_NO_CONFIG_WARNING=1 \
|
||||
|
||||
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y jq python3-pip logrotate moreutils \
|
||||
&& apt-get install -y jq python3-pip logrotate \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
@@ -9,7 +9,6 @@ services:
|
||||
environment:
|
||||
TZ: "${TZ:-Australia/Brisbane}"
|
||||
DEBUG: 'true'
|
||||
CI: 'true'
|
||||
FORCE_COLOR: 1
|
||||
# Required for DNS Certificate provisioning in CI
|
||||
LE_SERVER: 'https://ca.internal/acme/acme/directory'
|
||||
|
@@ -52,7 +52,7 @@ services:
|
||||
- ../global:/app/global
|
||||
- '/etc/localtime:/etc/localtime:ro'
|
||||
healthcheck:
|
||||
test: [ "CMD", "/usr/bin/check-health" ]
|
||||
test: ["CMD", "/usr/bin/check-health"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
depends_on:
|
||||
@@ -71,14 +71,12 @@ services:
|
||||
networks:
|
||||
- nginx_proxy_manager
|
||||
environment:
|
||||
TZ: "${TZ:-Australia/Brisbane}"
|
||||
MYSQL_ROOT_PASSWORD: 'npm'
|
||||
MYSQL_DATABASE: 'npm'
|
||||
MYSQL_USER: 'npm'
|
||||
MYSQL_PASSWORD: 'npm'
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
- '/etc/localtime:/etc/localtime:ro'
|
||||
|
||||
db-postgres:
|
||||
image: postgres:latest
|
||||
@@ -204,7 +202,7 @@ services:
|
||||
- nginx_proxy_manager
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: [ 'CMD-SHELL', 'redis-cli ping | grep PONG' ]
|
||||
test: ['CMD-SHELL', 'redis-cli ping | grep PONG']
|
||||
start_period: 20s
|
||||
interval: 30s
|
||||
retries: 5
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.2.3/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
@@ -64,8 +64,7 @@
|
||||
"useUniqueElementIds": "off"
|
||||
},
|
||||
"suspicious": {
|
||||
"noExplicitAny": "off",
|
||||
"noArrayIndexKey": "off"
|
||||
"noExplicitAny": "off"
|
||||
},
|
||||
"performance": {
|
||||
"noDelete": "off"
|
||||
|
@@ -12,51 +12,47 @@
|
||||
"prettier": "biome format --write ./src",
|
||||
"locale-extract": "formatjs extract 'src/**/*.tsx'",
|
||||
"locale-compile": "formatjs compile-folder src/locale/src src/locale/lang",
|
||||
"locale-sort": "./src/locale/scripts/locale-sort.sh",
|
||||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tabler/core": "^1.4.0",
|
||||
"@tabler/icons-react": "^3.35.0",
|
||||
"@tanstack/react-query": "^5.89.0",
|
||||
"@tabler/icons-react": "^3.34.1",
|
||||
"@tanstack/react-query": "^5.85.6",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"@uiw/react-textarea-code-editor": "^3.1.1",
|
||||
"classnames": "^2.5.1",
|
||||
"country-flag-icons": "^1.5.20",
|
||||
"country-flag-icons": "^1.5.19",
|
||||
"date-fns": "^4.1.0",
|
||||
"formik": "^2.4.6",
|
||||
"generate-password-browser": "^1.1.0",
|
||||
"humps": "^2.0.1",
|
||||
"query-string": "^9.3.1",
|
||||
"query-string": "^9.2.2",
|
||||
"react": "^19.1.1",
|
||||
"react-bootstrap": "^2.10.10",
|
||||
"react-dom": "^19.1.1",
|
||||
"react-intl": "^7.1.11",
|
||||
"react-router-dom": "^7.9.1",
|
||||
"react-select": "^5.10.2",
|
||||
"react-router-dom": "^7.8.2",
|
||||
"react-toastify": "^11.0.5",
|
||||
"rooks": "^9.3.0"
|
||||
"rooks": "^9.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.2.4",
|
||||
"@biomejs/biome": "^2.2.3",
|
||||
"@formatjs/cli": "^6.7.2",
|
||||
"@tanstack/react-query-devtools": "^5.89.0",
|
||||
"@tanstack/react-query-devtools": "^5.85.6",
|
||||
"@testing-library/dom": "^10.4.1",
|
||||
"@testing-library/jest-dom": "^6.8.0",
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"@types/country-flag-icons": "^1.2.2",
|
||||
"@types/humps": "^2.0.6",
|
||||
"@types/react": "^19.1.13",
|
||||
"@types/react": "^19.1.12",
|
||||
"@types/react-dom": "^19.1.9",
|
||||
"@types/react-table": "^7.7.20",
|
||||
"@vitejs/plugin-react": "^5.0.3",
|
||||
"@vitejs/plugin-react": "^5.0.2",
|
||||
"happy-dom": "^18.0.1",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss-simple-vars": "^7.0.1",
|
||||
"sass": "^1.93.0",
|
||||
"sass": "^1.91.0",
|
||||
"tmp": "^0.2.5",
|
||||
"typescript": "5.9.2",
|
||||
"vite": "^7.1.6",
|
||||
"vite": "^7.1.4",
|
||||
"vite-plugin-checker": "^0.10.3",
|
||||
"vite-tsconfig-paths": "^5.1.4",
|
||||
"vitest": "^3.2.4"
|
||||
|
@@ -1,14 +1,3 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
.light {
|
||||
color-scheme: light;
|
||||
}
|
||||
.dark {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
--tblr-backdrop-opacity: 0.8 !important;
|
||||
}
|
||||
@@ -23,54 +12,3 @@
|
||||
.ml-1 {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.react-select-container {
|
||||
.react-select__control {
|
||||
color: var(--tblr-body-color);
|
||||
background-color: var(--tblr-bg-forms);
|
||||
border: var(--tblr-border-width) solid var(--tblr-border-color);
|
||||
|
||||
.react-select__input {
|
||||
color: var(--tblr-body-color) !important;
|
||||
}
|
||||
|
||||
.react-select__single-value {
|
||||
color: var(--tblr-body-color);
|
||||
}
|
||||
|
||||
.react-select__multi-value {
|
||||
border: 1px solid var(--tblr-border-color);
|
||||
background-color: var(--tblr-bg-surface-tertiary);
|
||||
color: var(--tblr-secondary) !important;
|
||||
|
||||
.react-select__multi-value__label {
|
||||
color: var(--tblr-secondary) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.react-select__menu {
|
||||
background-color: var(--tblr-bg-forms);
|
||||
|
||||
.react-select__option {
|
||||
background: rgba(var(--tblr-primary-rgb), .04);
|
||||
color: inherit !important;
|
||||
&.react-select__option--is-focused {
|
||||
background: rgba(var(--tblr-primary-rgb), .1);
|
||||
}
|
||||
|
||||
&.react-select__option--is-focused.react-select__option--is-selected {
|
||||
background: rgba(var(--tblr-primary-rgb), .2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.textareaMono {
|
||||
font-family: 'Courier New', Courier, monospace !important;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
label.row {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import * as api from "./base";
|
||||
import type { AccessList } from "./models";
|
||||
|
||||
export async function createAccessList(item: AccessList): Promise<AccessList> {
|
||||
return await api.post({
|
||||
url: "/nginx/access-lists",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createAccessList(item: AccessList, abortController?: AbortController): Promise<AccessList> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/access-lists",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import * as api from "./base";
|
||||
import type { Certificate } from "./models";
|
||||
|
||||
export async function createCertificate(item: Certificate): Promise<Certificate> {
|
||||
return await api.post({
|
||||
url: "/nginx/certificates",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createCertificate(item: Certificate, abortController?: AbortController): Promise<Certificate> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/certificates",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import * as api from "./base";
|
||||
import type { DeadHost } from "./models";
|
||||
|
||||
export async function createDeadHost(item: DeadHost): Promise<DeadHost> {
|
||||
return await api.post({
|
||||
url: "/nginx/dead-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createDeadHost(item: DeadHost, abortController?: AbortController): Promise<DeadHost> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/dead-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import * as api from "./base";
|
||||
import type { ProxyHost } from "./models";
|
||||
|
||||
export async function createProxyHost(item: ProxyHost): Promise<ProxyHost> {
|
||||
return await api.post({
|
||||
url: "/nginx/proxy-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createProxyHost(item: ProxyHost, abortController?: AbortController): Promise<ProxyHost> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/proxy-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,16 @@
|
||||
import * as api from "./base";
|
||||
import type { RedirectionHost } from "./models";
|
||||
|
||||
export async function createRedirectionHost(item: RedirectionHost): Promise<RedirectionHost> {
|
||||
return await api.post({
|
||||
url: "/nginx/redirection-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createRedirectionHost(
|
||||
item: RedirectionHost,
|
||||
abortController?: AbortController,
|
||||
): Promise<RedirectionHost> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/redirection-hosts",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import * as api from "./base";
|
||||
import type { Stream } from "./models";
|
||||
|
||||
export async function createStream(item: Stream): Promise<Stream> {
|
||||
return await api.post({
|
||||
url: "/nginx/streams",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
});
|
||||
export async function createStream(item: Stream, abortController?: AbortController): Promise<Stream> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/nginx/streams",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -15,11 +15,14 @@ export interface NewUser {
|
||||
roles?: string[];
|
||||
}
|
||||
|
||||
export async function createUser(item: NewUser, noAuth?: boolean): Promise<User> {
|
||||
return await api.post({
|
||||
url: "/users",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
noAuth,
|
||||
});
|
||||
export async function createUser(item: NewUser, noAuth?: boolean, abortController?: AbortController): Promise<User> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/users",
|
||||
// todo: only use whitelist of fields for this data
|
||||
data: item,
|
||||
noAuth,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteAccessList(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/access-lists/${id}`,
|
||||
});
|
||||
export async function deleteAccessList(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/access-lists/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteCertificate(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/certificates/${id}`,
|
||||
});
|
||||
export async function deleteCertificate(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/certificates/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteDeadHost(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/dead-hosts/${id}`,
|
||||
});
|
||||
export async function deleteDeadHost(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/dead-hosts/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteProxyHost(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/proxy-hosts/${id}`,
|
||||
});
|
||||
export async function deleteProxyHost(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/proxy-hosts/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteRedirectionHost(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/redirection-hosts/${id}`,
|
||||
});
|
||||
export async function deleteRedirectionHost(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/redirection-hosts/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteStream(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/nginx/streams/${id}`,
|
||||
});
|
||||
export async function deleteStream(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/nginx/streams/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function deleteUser(id: number): Promise<boolean> {
|
||||
return await api.del({
|
||||
url: `/users/${id}`,
|
||||
});
|
||||
export async function deleteUser(id: number, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.del(
|
||||
{
|
||||
url: `/users/${id}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { Binary } from "./responseTypes";
|
||||
|
||||
export async function downloadCertificate(id: number): Promise<Binary> {
|
||||
return await api.get({
|
||||
url: `/nginx/certificates/${id}/download`,
|
||||
});
|
||||
export async function downloadCertificate(id: number, abortController?: AbortController): Promise<Binary> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/certificates/${id}/download`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
export type AccessListExpansion = "owner" | "items" | "clients";
|
||||
export type AuditLogExpansion = "user";
|
||||
export type CertificateExpansion = "owner" | "proxy_hosts" | "redirection_hosts" | "dead_hosts";
|
||||
export type HostExpansion = "owner" | "certificate";
|
||||
export type ProxyHostExpansion = "owner" | "access_list" | "certificate";
|
||||
export type UserExpansion = "permissions";
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { AccessListExpansion } from "./expansions";
|
||||
import type { AccessList } from "./models";
|
||||
|
||||
export async function getAccessList(id: number, expand?: AccessListExpansion[], params = {}): Promise<AccessList> {
|
||||
return await api.get({
|
||||
url: `/nginx/access-lists/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getAccessList(id: number, abortController?: AbortController): Promise<AccessList> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/access-lists/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import * as api from "./base";
|
||||
import type { AccessListExpansion } from "./expansions";
|
||||
import type { AccessList } from "./models";
|
||||
|
||||
export type AccessListExpansion = "owner" | "items" | "clients";
|
||||
|
||||
export async function getAccessLists(expand?: AccessListExpansion[], params = {}): Promise<AccessList[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/access-lists",
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import * as api from "./base";
|
||||
import type { AuditLogExpansion } from "./expansions";
|
||||
import type { AuditLog } from "./models";
|
||||
|
||||
export async function getAuditLog(id: number, expand?: AuditLogExpansion[], params = {}): Promise<AuditLog> {
|
||||
export async function getAuditLog(expand?: string[], params = {}): Promise<AuditLog[]> {
|
||||
return await api.get({
|
||||
url: `/audit-log/${id}`,
|
||||
url: "/audit-log",
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
|
@@ -1,13 +0,0 @@
|
||||
import * as api from "./base";
|
||||
import type { AuditLogExpansion } from "./expansions";
|
||||
import type { AuditLog } from "./models";
|
||||
|
||||
export async function getAuditLogs(expand?: AuditLogExpansion[], params = {}): Promise<AuditLog[]> {
|
||||
return await api.get({
|
||||
url: "/audit-log",
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { CertificateExpansion } from "./expansions";
|
||||
import type { Certificate } from "./models";
|
||||
|
||||
export async function getCertificate(id: number, expand?: CertificateExpansion[], params = {}): Promise<Certificate> {
|
||||
return await api.get({
|
||||
url: `/nginx/certificates/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getCertificate(id: number, abortController?: AbortController): Promise<Certificate> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/certificates/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
import * as api from "./base";
|
||||
import type { DNSProvider } from "./models";
|
||||
|
||||
export async function getCertificateDNSProviders(params = {}): Promise<DNSProvider[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/certificates/dns-providers",
|
||||
params,
|
||||
});
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
import * as api from "./base";
|
||||
import type { CertificateExpansion } from "./expansions";
|
||||
import type { Certificate } from "./models";
|
||||
|
||||
export async function getCertificates(expand?: CertificateExpansion[], params = {}): Promise<Certificate[]> {
|
||||
export async function getCertificates(expand?: string[], params = {}): Promise<Certificate[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/certificates",
|
||||
params: {
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { DeadHost } from "./models";
|
||||
|
||||
export async function getDeadHost(id: number, expand?: HostExpansion[], params = {}): Promise<DeadHost> {
|
||||
return await api.get({
|
||||
url: `/nginx/dead-hosts/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getDeadHost(id: number, abortController?: AbortController): Promise<DeadHost> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/dead-hosts/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { DeadHost } from "./models";
|
||||
|
||||
export async function getDeadHosts(expand?: HostExpansion[], params = {}): Promise<DeadHost[]> {
|
||||
export type DeadHostExpansion = "owner" | "certificate";
|
||||
|
||||
export async function getDeadHosts(expand?: DeadHostExpansion[], params = {}): Promise<DeadHost[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/dead-hosts",
|
||||
params: {
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { HealthResponse } from "./responseTypes";
|
||||
|
||||
export async function getHealth(): Promise<HealthResponse> {
|
||||
return await api.get({
|
||||
url: "/",
|
||||
});
|
||||
export async function getHealth(abortController?: AbortController): Promise<HealthResponse> {
|
||||
return await api.get(
|
||||
{
|
||||
url: "/",
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function getHostsReport(): Promise<Record<string, number>> {
|
||||
return await api.get({
|
||||
url: "/reports/hosts",
|
||||
});
|
||||
export async function getHostsReport(abortController?: AbortController): Promise<Record<string, number>> {
|
||||
return await api.get(
|
||||
{
|
||||
url: "/reports/hosts",
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { ProxyHostExpansion } from "./expansions";
|
||||
import type { ProxyHost } from "./models";
|
||||
|
||||
export async function getProxyHost(id: number, expand?: ProxyHostExpansion[], params = {}): Promise<ProxyHost> {
|
||||
return await api.get({
|
||||
url: `/nginx/proxy-hosts/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getProxyHost(id: number, abortController?: AbortController): Promise<ProxyHost> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/proxy-hosts/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import * as api from "./base";
|
||||
import type { ProxyHostExpansion } from "./expansions";
|
||||
import type { ProxyHost } from "./models";
|
||||
|
||||
export type ProxyHostExpansion = "owner" | "access_list" | "certificate";
|
||||
|
||||
export async function getProxyHosts(expand?: ProxyHostExpansion[], params = {}): Promise<ProxyHost[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/proxy-hosts",
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { RedirectionHost } from "./models";
|
||||
import type { ProxyHost } from "./models";
|
||||
|
||||
export async function getRedirectionHost(id: number, expand?: HostExpansion[], params = {}): Promise<RedirectionHost> {
|
||||
return await api.get({
|
||||
url: `/nginx/redirection-hosts/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getRedirectionHost(id: number, abortController?: AbortController): Promise<ProxyHost> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/redirection-hosts/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { RedirectionHost } from "./models";
|
||||
|
||||
export async function getRedirectionHosts(expand?: HostExpansion[], params = {}): Promise<RedirectionHost[]> {
|
||||
export type RedirectionHostExpansion = "owner" | "certificate";
|
||||
export async function getRedirectionHosts(
|
||||
expand?: RedirectionHostExpansion[],
|
||||
params = {},
|
||||
): Promise<RedirectionHost[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/redirection-hosts",
|
||||
params: {
|
||||
|
@@ -1,12 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { Setting } from "./models";
|
||||
|
||||
export async function getSetting(id: string, expand?: string[], params = {}): Promise<Setting> {
|
||||
return await api.get({
|
||||
url: `/settings/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getSetting(id: string, abortController?: AbortController): Promise<Setting> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/settings/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { Stream } from "./models";
|
||||
|
||||
export async function getStream(id: number, expand?: HostExpansion[], params = {}): Promise<Stream> {
|
||||
return await api.get({
|
||||
url: `/nginx/streams/${id}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
export async function getStream(id: number, abortController?: AbortController): Promise<Stream> {
|
||||
return await api.get(
|
||||
{
|
||||
url: `/nginx/streams/${id}`,
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import * as api from "./base";
|
||||
import type { HostExpansion } from "./expansions";
|
||||
import type { Stream } from "./models";
|
||||
|
||||
export async function getStreams(expand?: HostExpansion[], params = {}): Promise<Stream[]> {
|
||||
export type StreamExpansion = "owner" | "certificate";
|
||||
|
||||
export async function getStreams(expand?: StreamExpansion[], params = {}): Promise<Stream[]> {
|
||||
return await api.get({
|
||||
url: "/nginx/streams",
|
||||
params: {
|
||||
|
@@ -1,9 +1,19 @@
|
||||
import * as api from "./base";
|
||||
import type { TokenResponse } from "./responseTypes";
|
||||
|
||||
export async function getToken(identity: string, secret: string): Promise<TokenResponse> {
|
||||
return await api.post({
|
||||
url: "/tokens",
|
||||
data: { identity, secret },
|
||||
});
|
||||
interface Options {
|
||||
payload: {
|
||||
identity: string;
|
||||
secret: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getToken({ payload }: Options, abortController?: AbortController): Promise<TokenResponse> {
|
||||
return await api.post(
|
||||
{
|
||||
url: "/tokens",
|
||||
data: payload,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,14 +1,10 @@
|
||||
import * as api from "./base";
|
||||
import type { UserExpansion } from "./expansions";
|
||||
import type { User } from "./models";
|
||||
|
||||
export async function getUser(id: number | string = "me", expand?: UserExpansion[], params = {}): Promise<User> {
|
||||
export async function getUser(id: number | string = "me", params = {}): Promise<User> {
|
||||
const userId = id ? id : "me";
|
||||
return await api.get({
|
||||
url: `/users/${userId}`,
|
||||
params: {
|
||||
expand: expand?.join(","),
|
||||
...params,
|
||||
},
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import * as api from "./base";
|
||||
import type { UserExpansion } from "./expansions";
|
||||
import type { User } from "./models";
|
||||
|
||||
export type UserExpansion = "permissions";
|
||||
|
||||
export async function getUsers(expand?: UserExpansion[], params = {}): Promise<User[]> {
|
||||
return await api.get({
|
||||
url: "/users",
|
||||
|
@@ -13,13 +13,10 @@ export * from "./deleteRedirectionHost";
|
||||
export * from "./deleteStream";
|
||||
export * from "./deleteUser";
|
||||
export * from "./downloadCertificate";
|
||||
export * from "./expansions";
|
||||
export * from "./getAccessList";
|
||||
export * from "./getAccessLists";
|
||||
export * from "./getAuditLog";
|
||||
export * from "./getAuditLogs";
|
||||
export * from "./getCertificate";
|
||||
export * from "./getCertificateDNSProviders";
|
||||
export * from "./getCertificates";
|
||||
export * from "./getDeadHost";
|
||||
export * from "./getDeadHosts";
|
||||
@@ -47,7 +44,6 @@ export * from "./toggleDeadHost";
|
||||
export * from "./toggleProxyHost";
|
||||
export * from "./toggleRedirectionHost";
|
||||
export * from "./toggleStream";
|
||||
export * from "./toggleUser";
|
||||
export * from "./updateAccessList";
|
||||
export * from "./updateAuth";
|
||||
export * from "./updateDeadHost";
|
||||
|
@@ -40,8 +40,6 @@ export interface AuditLog {
|
||||
objectId: number;
|
||||
action: string;
|
||||
meta: Record<string, any>;
|
||||
// Expansions:
|
||||
user?: User;
|
||||
}
|
||||
|
||||
export interface AccessList {
|
||||
@@ -53,7 +51,7 @@ export interface AccessList {
|
||||
meta: Record<string, any>;
|
||||
satisfyAny: boolean;
|
||||
passAuth: boolean;
|
||||
proxyHostCount?: number;
|
||||
proxyHostCount: number;
|
||||
// Expansions:
|
||||
owner?: User;
|
||||
items?: AccessListItem[];
|
||||
@@ -103,7 +101,6 @@ export interface ProxyHost {
|
||||
modifiedOn: string;
|
||||
ownerUserId: number;
|
||||
domainNames: string[];
|
||||
forwardScheme: string;
|
||||
forwardHost: string;
|
||||
forwardPort: number;
|
||||
accessListId: number;
|
||||
@@ -115,8 +112,9 @@ export interface ProxyHost {
|
||||
meta: Record<string, any>;
|
||||
allowWebsocketUpgrade: boolean;
|
||||
http2Support: boolean;
|
||||
forwardScheme: string;
|
||||
enabled: boolean;
|
||||
locations?: string[]; // todo: string or object?
|
||||
locations: string[]; // todo: string or object?
|
||||
hstsEnabled: boolean;
|
||||
hstsSubdomains: boolean;
|
||||
// Expansions:
|
||||
@@ -193,9 +191,3 @@ export interface Setting {
|
||||
value: string;
|
||||
meta: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface DNSProvider {
|
||||
id: string;
|
||||
name: string;
|
||||
credentials: string;
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { TokenResponse } from "./responseTypes";
|
||||
|
||||
export async function refreshToken(): Promise<TokenResponse> {
|
||||
return await api.get({
|
||||
url: "/tokens",
|
||||
});
|
||||
export async function refreshToken(abortController?: AbortController): Promise<TokenResponse> {
|
||||
return await api.get(
|
||||
{
|
||||
url: "/tokens",
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import * as api from "./base";
|
||||
import type { Certificate } from "./models";
|
||||
|
||||
export async function renewCertificate(id: number): Promise<Certificate> {
|
||||
return await api.post({
|
||||
url: `/nginx/certificates/${id}/renew`,
|
||||
});
|
||||
export async function renewCertificate(id: number, abortController?: AbortController): Promise<Certificate> {
|
||||
return await api.post(
|
||||
{
|
||||
url: `/nginx/certificates/${id}/renew`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,17 @@
|
||||
import * as api from "./base";
|
||||
import type { UserPermissions } from "./models";
|
||||
|
||||
export async function setPermissions(userId: number, data: UserPermissions): Promise<boolean> {
|
||||
export async function setPermissions(
|
||||
userId: number,
|
||||
data: UserPermissions,
|
||||
abortController?: AbortController,
|
||||
): Promise<boolean> {
|
||||
// Remove readonly fields
|
||||
return await api.put({
|
||||
url: `/users/${userId}/permissions`,
|
||||
data,
|
||||
});
|
||||
return await api.put(
|
||||
{
|
||||
url: `/users/${userId}/permissions`,
|
||||
data,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,16 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function testHttpCertificate(domains: string[]): Promise<Record<string, string>> {
|
||||
return await api.get({
|
||||
url: "/nginx/certificates/test-http",
|
||||
params: {
|
||||
domains: domains.join(","),
|
||||
export async function testHttpCertificate(
|
||||
domains: string[],
|
||||
abortController?: AbortController,
|
||||
): Promise<Record<string, string>> {
|
||||
return await api.get(
|
||||
{
|
||||
url: "/nginx/certificates/test-http",
|
||||
params: {
|
||||
domains: domains.join(","),
|
||||
},
|
||||
},
|
||||
});
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,14 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function toggleDeadHost(id: number, enabled: boolean): Promise<boolean> {
|
||||
return await api.post({
|
||||
url: `/nginx/dead-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
});
|
||||
export async function toggleDeadHost(
|
||||
id: number,
|
||||
enabled: boolean,
|
||||
abortController?: AbortController,
|
||||
): Promise<boolean> {
|
||||
return await api.post(
|
||||
{
|
||||
url: `/nginx/dead-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,14 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function toggleProxyHost(id: number, enabled: boolean): Promise<boolean> {
|
||||
return await api.post({
|
||||
url: `/nginx/proxy-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
});
|
||||
export async function toggleProxyHost(
|
||||
id: number,
|
||||
enabled: boolean,
|
||||
abortController?: AbortController,
|
||||
): Promise<boolean> {
|
||||
return await api.post(
|
||||
{
|
||||
url: `/nginx/proxy-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,14 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function toggleRedirectionHost(id: number, enabled: boolean): Promise<boolean> {
|
||||
return await api.post({
|
||||
url: `/nginx/redirection-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
});
|
||||
export async function toggleRedirectionHost(
|
||||
id: number,
|
||||
enabled: boolean,
|
||||
abortController?: AbortController,
|
||||
): Promise<boolean> {
|
||||
return await api.post(
|
||||
{
|
||||
url: `/nginx/redirection-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import * as api from "./base";
|
||||
|
||||
export async function toggleStream(id: number, enabled: boolean): Promise<boolean> {
|
||||
return await api.post({
|
||||
url: `/nginx/streams/${id}/${enabled ? "enable" : "disable"}`,
|
||||
});
|
||||
export async function toggleStream(id: number, enabled: boolean, abortController?: AbortController): Promise<boolean> {
|
||||
return await api.post(
|
||||
{
|
||||
url: `/nginx/streams/${id}/${enabled ? "enable" : "disable"}`,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user