mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-10-04 11:50:09 +00:00
Compare commits
31 Commits
cde7460b5e
...
react
Author | SHA1 | Date | |
---|---|---|---|
|
227e818040 | ||
|
fcb08d3003 | ||
|
d0767baafa | ||
|
abdf8866e0 | ||
|
e36c1b99a5 | ||
|
9339626933 | ||
|
100a7e3ff8 | ||
|
4866988772 | ||
|
8884e3b261 | ||
|
a3d17249d0 | ||
|
fc8a5e8b97 | ||
|
da68fe29ac | ||
|
18537b9288 | ||
|
d85e515ab9 | ||
|
94375bbc5f | ||
|
54e036276a | ||
|
058f49ceea | ||
|
efcefe0c17 | ||
|
429046f32e | ||
|
8ad95c5695 | ||
|
038de3e5f9 | ||
|
1928e554fd | ||
|
d40e290a89 | ||
|
fb2708d81d | ||
|
7a6efd8ebb | ||
|
0b2fa826e0 | ||
|
6ab7198e61 | ||
|
61a92906f3 | ||
|
fadec9751e | ||
|
330993f028 | ||
|
487fa6d31b |
10
README.md
10
README.md
@@ -1,7 +1,7 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://nginxproxymanager.com/github.png">
|
<img src="https://nginxproxymanager.com/github.png">
|
||||||
<br><br>
|
<br><br>
|
||||||
<img src="https://img.shields.io/badge/version-2.12.6-green.svg?style=for-the-badge">
|
<img src="https://img.shields.io/badge/version-2.13.0-green.svg?style=for-the-badge">
|
||||||
<a href="https://hub.docker.com/repository/docker/jc21/nginx-proxy-manager">
|
<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">
|
<img src="https://img.shields.io/docker/stars/jc21/nginx-proxy-manager.svg?style=for-the-badge">
|
||||||
</a>
|
</a>
|
||||||
@@ -88,14 +88,6 @@ 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)
|
[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
|
## Contributing
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/2.2.3/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
||||||
"vcs": {
|
"vcs": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"clientKind": "git",
|
"clientKind": "git",
|
||||||
|
@@ -21,11 +21,9 @@ const internalAccessList = {
|
|||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
create: (access, data) => {
|
create: async (access, data) => {
|
||||||
return access
|
await access.can("access_lists:create", data);
|
||||||
.can("access_lists:create", data)
|
const row = await accessListModel
|
||||||
.then((/*access_data*/) => {
|
|
||||||
return accessListModel
|
|
||||||
.query()
|
.query()
|
||||||
.insertAndFetch({
|
.insertAndFetch({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
@@ -34,13 +32,11 @@ const internalAccessList = {
|
|||||||
owner_user_id: access.token.getUserId(1),
|
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
|
||||||
// Now add the items
|
|
||||||
data.items.map((item) => {
|
data.items.map((item) => {
|
||||||
promises.push(
|
promises.push(
|
||||||
accessListAuthModel.query().insert({
|
accessListAuthModel.query().insert({
|
||||||
@@ -52,9 +48,8 @@ const internalAccessList = {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now add the clients
|
// Clients
|
||||||
if (typeof data.clients !== "undefined" && data.clients) {
|
data.clients?.map((client) => {
|
||||||
data.clients.map((client) => {
|
|
||||||
promises.push(
|
promises.push(
|
||||||
accessListClientModel.query().insert({
|
accessListClientModel.query().insert({
|
||||||
access_list_id: row.id,
|
access_list_id: row.id,
|
||||||
@@ -64,45 +59,36 @@ const internalAccessList = {
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.all(promises);
|
await Promise.all(promises);
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// re-fetch with expansions
|
// re-fetch with expansions
|
||||||
return internalAccessList.get(
|
const freshRow = await internalAccessList.get(
|
||||||
access,
|
access,
|
||||||
{
|
{
|
||||||
id: data.id,
|
id: data.id,
|
||||||
expand: ["owner", "items", "clients", "proxy_hosts.access_list.[clients,items]"],
|
expand: ["owner", "items", "clients", "proxy_hosts.access_list.[clients,items]"],
|
||||||
},
|
},
|
||||||
true /* <- skip masking */,
|
true // skip masking
|
||||||
);
|
);
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
// Audit log
|
|
||||||
data.meta = _.assign({}, data.meta || {}, row.meta);
|
|
||||||
|
|
||||||
return internalAccessList
|
// Audit log
|
||||||
.build(row)
|
data.meta = _.assign({}, data.meta || {}, freshRow.meta);
|
||||||
.then(() => {
|
await internalAccessList.build(freshRow);
|
||||||
if (Number.parseInt(row.proxy_host_count, 10)) {
|
|
||||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
if (Number.parseInt(freshRow.proxy_host_count, 10)) {
|
||||||
|
await internalNginx.bulkGenerateConfigs("proxy_host", freshRow.proxy_hosts);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "created",
|
action: "created",
|
||||||
object_type: "access-list",
|
object_type: "access-list",
|
||||||
object_id: row.id,
|
object_id: freshRow.id,
|
||||||
meta: internalAccessList.maskItems(data),
|
meta: internalAccessList.maskItems(data),
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then(() => {
|
return internalAccessList.maskItems(freshRow);
|
||||||
return internalAccessList.maskItems(row);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,35 +99,29 @@ const internalAccessList = {
|
|||||||
* @param {String} [data.items]
|
* @param {String} [data.items]
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
update: (access, data) => {
|
update: async (access, data) => {
|
||||||
return access
|
await access.can("access_lists:update", data.id);
|
||||||
.can("access_lists:update", data.id)
|
const row = await internalAccessList.get(access, { id: data.id });
|
||||||
.then((/*access_data*/) => {
|
|
||||||
return internalAccessList.get(access, { id: data.id });
|
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (row.id !== data.id) {
|
if (row.id !== data.id) {
|
||||||
// Sanity check that something crazy hasn't happened
|
// Sanity check that something crazy hasn't happened
|
||||||
throw new errs.InternalValidationError(
|
throw new errs.InternalValidationError(
|
||||||
`Access List could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
`Access List could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// patch name if specified
|
// patch name if specified
|
||||||
if (typeof data.name !== "undefined" && data.name) {
|
if (typeof data.name !== "undefined" && data.name) {
|
||||||
return accessListModel.query().where({ id: data.id }).patch({
|
await accessListModel.query().where({ id: data.id }).patch({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
satisfy_any: data.satisfy_any,
|
satisfy_any: data.satisfy_any,
|
||||||
pass_auth: data.pass_auth,
|
pass_auth: data.pass_auth,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Check for items and add/update/remove them
|
// Check for items and add/update/remove them
|
||||||
if (typeof data.items !== "undefined" && data.items) {
|
if (typeof data.items !== "undefined" && data.items) {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const items_to_keep = [];
|
const itemsToKeep = [];
|
||||||
|
|
||||||
data.items.map((item) => {
|
data.items.map((item) => {
|
||||||
if (item.password) {
|
if (item.password) {
|
||||||
@@ -154,33 +134,30 @@ const internalAccessList = {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// This was supplied with an empty password, which means keep it but don't change the password
|
// This was supplied with an empty password, which means keep it but don't change the password
|
||||||
items_to_keep.push(item.username);
|
itemsToKeep.push(item.username);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
const query = accessListAuthModel.query().delete().where("access_list_id", data.id);
|
const query = accessListAuthModel.query().delete().where("access_list_id", data.id);
|
||||||
|
|
||||||
if (items_to_keep.length) {
|
if (itemsToKeep.length) {
|
||||||
query.andWhere("username", "NOT IN", items_to_keep);
|
query.andWhere("username", "NOT IN", itemsToKeep);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(() => {
|
await query;
|
||||||
// Add new items
|
// Add new items
|
||||||
if (promises.length) {
|
if (promises.length) {
|
||||||
return Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Check for clients and add/update/remove them
|
// Check for clients and add/update/remove them
|
||||||
if (typeof data.clients !== "undefined" && data.clients) {
|
if (typeof data.clients !== "undefined" && data.clients) {
|
||||||
const promises = [];
|
const clientPromises = [];
|
||||||
|
|
||||||
data.clients.map((client) => {
|
data.clients.map((client) => {
|
||||||
if (client.address) {
|
if (client.address) {
|
||||||
promises.push(
|
clientPromises.push(
|
||||||
accessListClientModel.query().insert({
|
accessListClientModel.query().insert({
|
||||||
access_list_id: data.id,
|
access_list_id: data.id,
|
||||||
address: client.address,
|
address: client.address,
|
||||||
@@ -192,48 +169,37 @@ const internalAccessList = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const query = accessListClientModel.query().delete().where("access_list_id", data.id);
|
const query = accessListClientModel.query().delete().where("access_list_id", data.id);
|
||||||
|
await query;
|
||||||
|
// Add new clitens
|
||||||
|
if (clientPromises.length) {
|
||||||
|
await Promise.all(clientPromises);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return query.then(() => {
|
|
||||||
// Add new items
|
|
||||||
if (promises.length) {
|
|
||||||
return Promise.all(promises);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "updated",
|
action: "updated",
|
||||||
object_type: "access-list",
|
object_type: "access-list",
|
||||||
object_id: data.id,
|
object_id: data.id,
|
||||||
meta: internalAccessList.maskItems(data),
|
meta: internalAccessList.maskItems(data),
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// re-fetch with expansions
|
// re-fetch with expansions
|
||||||
return internalAccessList.get(
|
const freshRow = await internalAccessList.get(
|
||||||
access,
|
access,
|
||||||
{
|
{
|
||||||
id: data.id,
|
id: data.id,
|
||||||
expand: ["owner", "items", "clients", "proxy_hosts.[certificate,access_list.[clients,items]]"],
|
expand: ["owner", "items", "clients", "proxy_hosts.[certificate,access_list.[clients,items]]"],
|
||||||
},
|
},
|
||||||
true /* <- skip masking */,
|
true // skip masking
|
||||||
);
|
);
|
||||||
})
|
|
||||||
.then((row) => {
|
await internalAccessList.build(freshRow)
|
||||||
return internalAccessList
|
|
||||||
.build(row)
|
|
||||||
.then(() => {
|
|
||||||
if (Number.parseInt(row.proxy_host_count, 10)) {
|
if (Number.parseInt(row.proxy_host_count, 10)) {
|
||||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
await internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||||
}
|
}
|
||||||
})
|
await internalNginx.reload();
|
||||||
.then(internalNginx.reload)
|
|
||||||
.then(() => {
|
|
||||||
return internalAccessList.maskItems(row);
|
return internalAccessList.maskItems(row);
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,15 +208,13 @@ const internalAccessList = {
|
|||||||
* @param {Integer} data.id
|
* @param {Integer} data.id
|
||||||
* @param {Array} [data.expand]
|
* @param {Array} [data.expand]
|
||||||
* @param {Array} [data.omit]
|
* @param {Array} [data.omit]
|
||||||
* @param {Boolean} [skip_masking]
|
* @param {Boolean} [skipMasking]
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
get: (access, data, skip_masking) => {
|
get: async (access, data, skipMasking) => {
|
||||||
const thisData = data || {};
|
const thisData = data || {};
|
||||||
|
const accessData = await access.can("access_lists:get", thisData.id)
|
||||||
|
|
||||||
return access
|
|
||||||
.can("access_lists:get", thisData.id)
|
|
||||||
.then((accessData) => {
|
|
||||||
const query = accessListModel
|
const query = accessListModel
|
||||||
.query()
|
.query()
|
||||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||||
@@ -275,22 +239,19 @@ const internalAccessList = {
|
|||||||
query.withGraphFetched(`[${thisData.expand.join(", ")}]`);
|
query.withGraphFetched(`[${thisData.expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(utils.omitRow(omissions()));
|
let row = await query.then(utils.omitRow(omissions()));
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
let thisRow = row;
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(thisData.id);
|
throw new errs.ItemNotFoundError(thisData.id);
|
||||||
}
|
}
|
||||||
if (!skip_masking && typeof thisRow.items !== "undefined" && thisRow.items) {
|
if (!skipMasking && typeof row.items !== "undefined" && row.items) {
|
||||||
thisRow = internalAccessList.maskItems(thisRow);
|
row = internalAccessList.maskItems(row);
|
||||||
}
|
}
|
||||||
// Custom omissions
|
// Custom omissions
|
||||||
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
||||||
thisRow = _.omit(thisRow, data.omit);
|
row = _.omit(row, data.omit);
|
||||||
}
|
}
|
||||||
return thisRow;
|
return row;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -300,13 +261,13 @@ const internalAccessList = {
|
|||||||
* @param {String} [data.reason]
|
* @param {String} [data.reason]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
delete: (access, data) => {
|
delete: async (access, data) => {
|
||||||
return access
|
await access.can("access_lists:delete", data.id);
|
||||||
.can("access_lists:delete", data.id)
|
const row = await internalAccessList.get(access, {
|
||||||
.then(() => {
|
id: data.id,
|
||||||
return internalAccessList.get(access, { id: data.id, expand: ["proxy_hosts", "items", "clients"] });
|
expand: ["proxy_hosts", "items", "clients"],
|
||||||
})
|
});
|
||||||
.then((row) => {
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(data.id);
|
throw new errs.ItemNotFoundError(data.id);
|
||||||
}
|
}
|
||||||
@@ -317,58 +278,47 @@ const internalAccessList = {
|
|||||||
// 4. audit log
|
// 4. audit log
|
||||||
|
|
||||||
// 1. update row to be deleted
|
// 1. update row to be deleted
|
||||||
return accessListModel
|
await accessListModel
|
||||||
.query()
|
.query()
|
||||||
.where("id", row.id)
|
.where("id", row.id)
|
||||||
.patch({
|
.patch({
|
||||||
is_deleted: 1,
|
is_deleted: 1,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
// 2. update any proxy hosts that were using it (ignoring permissions)
|
// 2. update any proxy hosts that were using it (ignoring permissions)
|
||||||
if (row.proxy_hosts) {
|
if (row.proxy_hosts) {
|
||||||
return proxyHostModel
|
await proxyHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("access_list_id", "=", row.id)
|
.where("access_list_id", "=", row.id)
|
||||||
.patch({ access_list_id: 0 })
|
.patch({ access_list_id: 0 });
|
||||||
.then(() => {
|
|
||||||
// 3. reconfigure those hosts, then reload nginx
|
|
||||||
|
|
||||||
|
// 3. reconfigure those hosts, then reload nginx
|
||||||
// set the access_list_id to zero for these items
|
// set the access_list_id to zero for these items
|
||||||
row.proxy_hosts.map((_val, idx) => {
|
row.proxy_hosts.map((_val, idx) => {
|
||||||
row.proxy_hosts[idx].access_list_id = 0;
|
row.proxy_hosts[idx].access_list_id = 0;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
await internalNginx.bulkGenerateConfigs("proxy_host", row.proxy_hosts);
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return internalNginx.reload();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// delete the htpasswd file
|
|
||||||
const htpasswd_file = internalAccessList.getFilename(row);
|
|
||||||
|
|
||||||
|
await internalNginx.reload();
|
||||||
|
|
||||||
|
// delete the htpasswd file
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(htpasswd_file);
|
fs.unlinkSync(internalAccessList.getFilename(row));
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// 4. audit log
|
// 4. audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "deleted",
|
action: "deleted",
|
||||||
object_type: "access-list",
|
object_type: "access-list",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: _.omit(internalAccessList.maskItems(row), ["is_deleted", "proxy_hosts"]),
|
meta: _.omit(internalAccessList.maskItems(row), ["is_deleted", "proxy_hosts"]),
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return true;
|
return true;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,13 +326,12 @@ const internalAccessList = {
|
|||||||
*
|
*
|
||||||
* @param {Access} access
|
* @param {Access} access
|
||||||
* @param {Array} [expand]
|
* @param {Array} [expand]
|
||||||
* @param {String} [search_query]
|
* @param {String} [searchQuery]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getAll: (access, expand, search_query) => {
|
getAll: async (access, expand, searchQuery) => {
|
||||||
return access
|
const accessData = await access.can("access_lists:list");
|
||||||
.can("access_lists:list")
|
|
||||||
.then((access_data) => {
|
|
||||||
const query = accessListModel
|
const query = accessListModel
|
||||||
.query()
|
.query()
|
||||||
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
.select("access_list.*", accessListModel.raw("COUNT(proxy_host.id) as proxy_host_count"))
|
||||||
@@ -398,14 +347,14 @@ const internalAccessList = {
|
|||||||
.allowGraph("[owner,items,clients]")
|
.allowGraph("[owner,items,clients]")
|
||||||
.orderBy("access_list.name", "ASC");
|
.orderBy("access_list.name", "ASC");
|
||||||
|
|
||||||
if (access_data.permission_visibility !== "all") {
|
if (accessData.permission_visibility !== "all") {
|
||||||
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
query.andWhere("access_list.owner_user_id", access.token.getUserId(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query is used for searching
|
// Query is used for searching
|
||||||
if (typeof search_query === "string") {
|
if (typeof searchQuery === "string") {
|
||||||
query.where(function () {
|
query.where(function () {
|
||||||
this.where("name", "like", `%${search_query}%`);
|
this.where("name", "like", `%${searchQuery}%`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,9 +362,7 @@ const internalAccessList = {
|
|||||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(utils.omitRows(omissions()));
|
const rows = await query.then(utils.omitRows(omissions()));
|
||||||
})
|
|
||||||
.then((rows) => {
|
|
||||||
if (rows) {
|
if (rows) {
|
||||||
rows.map((row, idx) => {
|
rows.map((row, idx) => {
|
||||||
if (typeof row.items !== "undefined" && row.items) {
|
if (typeof row.items !== "undefined" && row.items) {
|
||||||
@@ -424,28 +371,28 @@ const internalAccessList = {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report use
|
* Count is used in reports
|
||||||
*
|
*
|
||||||
* @param {Integer} user_id
|
* @param {Integer} userId
|
||||||
* @param {String} visibility
|
* @param {String} visibility
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getCount: (user_id, visibility) => {
|
getCount: async (userId, visibility) => {
|
||||||
const query = accessListModel.query().count("id as count").where("is_deleted", 0);
|
const query = accessListModel
|
||||||
|
.query()
|
||||||
|
.count("id as count")
|
||||||
|
.where("is_deleted", 0);
|
||||||
|
|
||||||
if (visibility !== "all") {
|
if (visibility !== "all") {
|
||||||
query.andWhere("owner_user_id", user_id);
|
query.andWhere("owner_user_id", userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.first().then((row) => {
|
const row = await query.first();
|
||||||
return Number.parseInt(row.count, 10);
|
return Number.parseInt(row.count, 10);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -455,20 +402,19 @@ const internalAccessList = {
|
|||||||
maskItems: (list) => {
|
maskItems: (list) => {
|
||||||
if (list && typeof list.items !== "undefined") {
|
if (list && typeof list.items !== "undefined") {
|
||||||
list.items.map((val, idx) => {
|
list.items.map((val, idx) => {
|
||||||
let repeat_for = 8;
|
let repeatFor = 8;
|
||||||
let first_char = "*";
|
let firstChar = "*";
|
||||||
|
|
||||||
if (typeof val.password !== "undefined" && val.password) {
|
if (typeof val.password !== "undefined" && val.password) {
|
||||||
repeat_for = val.password.length - 1;
|
repeatFor = val.password.length - 1;
|
||||||
first_char = val.password.charAt(0);
|
firstChar = val.password.charAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
list.items[idx].hint = first_char + "*".repeat(repeat_for);
|
list.items[idx].hint = firstChar + "*".repeat(repeatFor);
|
||||||
list.items[idx].password = "";
|
list.items[idx].password = "";
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -488,43 +434,33 @@ const internalAccessList = {
|
|||||||
* @param {Array} list.items
|
* @param {Array} list.items
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
build: (list) => {
|
build: async (list) => {
|
||||||
logger.info(`Building Access file #${list.id} for: ${list.name}`);
|
logger.info(`Building Access file #${list.id} for: ${list.name}`);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
const htpasswdFile = internalAccessList.getFilename(list);
|
||||||
const htpasswd_file = internalAccessList.getFilename(list);
|
|
||||||
|
|
||||||
// 1. remove any existing access file
|
// 1. remove any existing access file
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(htpasswd_file);
|
fs.unlinkSync(htpasswdFile);
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. create empty access file
|
// 2. create empty access file
|
||||||
try {
|
fs.writeFileSync(htpasswdFile, '', {encoding: 'utf8'});
|
||||||
fs.writeFileSync(htpasswd_file, "", { encoding: "utf8" });
|
|
||||||
resolve(htpasswd_file);
|
|
||||||
} catch (err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
}).then((htpasswd_file) => {
|
|
||||||
// 3. generate password for each user
|
// 3. generate password for each user
|
||||||
if (list.items.length) {
|
if (list.items.length) {
|
||||||
return new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
batchflow(list.items)
|
batchflow(list.items).sequential()
|
||||||
.sequential()
|
|
||||||
.each((_i, item, next) => {
|
.each((_i, item, next) => {
|
||||||
if (typeof item.password !== "undefined" && item.password.length) {
|
if (item.password?.length) {
|
||||||
logger.info(`Adding: ${item.username}`);
|
logger.info(`Adding: ${item.username}`);
|
||||||
|
|
||||||
utils
|
utils.execFile('openssl', ['passwd', '-apr1', item.password])
|
||||||
.execFile("openssl", ["passwd", "-apr1", item.password])
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
try {
|
try {
|
||||||
fs.appendFileSync(htpasswd_file, `${item.username}:${res}\n`, {
|
fs.appendFileSync(htpasswdFile, `${item.username}:${res}\n`, {encoding: 'utf8'});
|
||||||
encoding: "utf8",
|
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@@ -546,8 +482,7 @@ const internalAccessList = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
},
|
}
|
||||||
};
|
|
||||||
|
|
||||||
export default internalAccessList;
|
export default internalAccessList;
|
||||||
|
@@ -9,11 +9,12 @@ const internalAuditLog = {
|
|||||||
*
|
*
|
||||||
* @param {Access} access
|
* @param {Access} access
|
||||||
* @param {Array} [expand]
|
* @param {Array} [expand]
|
||||||
* @param {String} [search_query]
|
* @param {String} [searchQuery]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getAll: (access, expand, search_query) => {
|
getAll: async (access, expand, searchQuery) => {
|
||||||
return access.can("auditlog:list").then(() => {
|
await access.can("auditlog:list");
|
||||||
|
|
||||||
const query = auditLogModel
|
const query = auditLogModel
|
||||||
.query()
|
.query()
|
||||||
.orderBy("created_on", "DESC")
|
.orderBy("created_on", "DESC")
|
||||||
@@ -22,9 +23,9 @@ const internalAuditLog = {
|
|||||||
.allowGraph("[user]");
|
.allowGraph("[user]");
|
||||||
|
|
||||||
// Query is used for searching
|
// Query is used for searching
|
||||||
if (typeof search_query === "string" && search_query.length > 0) {
|
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||||
query.where(function () {
|
query.where(function () {
|
||||||
this.where(castJsonIfNeed("meta"), "like", `%${search_query}`);
|
this.where(castJsonIfNeed("meta"), "like", `%${searchQuery}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +33,36 @@ const internalAuditLog = {
|
|||||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query;
|
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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,27 +79,22 @@ const internalAuditLog = {
|
|||||||
* @param {Object} [data.meta]
|
* @param {Object} [data.meta]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
add: (access, data) => {
|
add: async (access, data) => {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
// Default the user id
|
|
||||||
if (typeof data.user_id === "undefined" || !data.user_id) {
|
if (typeof data.user_id === "undefined" || !data.user_id) {
|
||||||
data.user_id = access.token.getUserId(1);
|
data.user_id = access.token.getUserId(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof data.action === "undefined" || !data.action) {
|
if (typeof data.action === "undefined" || !data.action) {
|
||||||
reject(new errs.InternalValidationError("Audit log entry must contain an Action"));
|
throw new errs.InternalValidationError("Audit log entry must contain an Action");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Make sure at least 1 of the IDs are set and action
|
// Make sure at least 1 of the IDs are set and action
|
||||||
resolve(
|
return await auditLogModel.query().insert({
|
||||||
auditLogModel.query().insert({
|
|
||||||
user_id: data.user_id,
|
user_id: data.user_id,
|
||||||
action: data.action,
|
action: data.action,
|
||||||
object_type: data.object_type || "",
|
object_type: data.object_type || "",
|
||||||
object_id: data.object_id || 0,
|
object_id: data.object_id || 0,
|
||||||
meta: data.meta || {},
|
meta: data.meta || {},
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,25 +18,24 @@ const internalDeadHost = {
|
|||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
create: (access, data) => {
|
create: async (access, data) => {
|
||||||
const createCertificate = data.certificate_id === "new";
|
const createCertificate = data.certificate_id === "new";
|
||||||
|
|
||||||
if (createCertificate) {
|
if (createCertificate) {
|
||||||
delete data.certificate_id;
|
delete data.certificate_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return access
|
await access.can("dead_hosts:create", data);
|
||||||
.can("dead_hosts:create", data)
|
|
||||||
.then((/*access_data*/) => {
|
|
||||||
// Get a list of the domain names and check each of them against existing records
|
// Get a list of the domain names and check each of them against existing records
|
||||||
const domain_name_check_promises = [];
|
const domainNameCheckPromises = [];
|
||||||
|
|
||||||
data.domain_names.map((domain_name) => {
|
data.domain_names.map((domain_name) => {
|
||||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name));
|
domainNameCheckPromises.push(internalHost.isHostnameTaken(domain_name));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(domain_name_check_promises).then((check_results) => {
|
await Promise.all(domainNameCheckPromises).then((check_results) => {
|
||||||
check_results.map((result) => {
|
check_results.map((result) => {
|
||||||
if (result.is_taken) {
|
if (result.is_taken) {
|
||||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||||
@@ -44,8 +43,7 @@ const internalDeadHost = {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// At this point the domains should have been checked
|
// At this point the domains should have been checked
|
||||||
data.owner_user_id = access.token.getUserId(1);
|
data.owner_user_id = access.token.getUserId(1);
|
||||||
const thisData = internalHost.cleanSslHstsData(data);
|
const thisData = internalHost.cleanSslHstsData(data);
|
||||||
@@ -56,53 +54,43 @@ const internalDeadHost = {
|
|||||||
thisData.advanced_config = "";
|
thisData.advanced_config = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return deadHostModel.query().insertAndFetch(thisData).then(utils.omitRow(omissions()));
|
const row = await deadHostModel.query()
|
||||||
})
|
.insertAndFetch(thisData)
|
||||||
.then((row) => {
|
.then(utils.omitRow(omissions()));
|
||||||
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
|
// Add to audit log
|
||||||
return internalAuditLog
|
await internalAuditLog.add(access, {
|
||||||
.add(access, {
|
|
||||||
action: "created",
|
action: "created",
|
||||||
object_type: "dead-host",
|
object_type: "dead-host",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: data,
|
meta: thisData,
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return row;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,66 +99,51 @@ const internalDeadHost = {
|
|||||||
* @param {Number} data.id
|
* @param {Number} data.id
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
update: (access, data) => {
|
update: async (access, data) => {
|
||||||
let thisData = data;
|
const createCertificate = data.certificate_id === "new";
|
||||||
const createCertificate = thisData.certificate_id === "new";
|
|
||||||
|
|
||||||
if (createCertificate) {
|
if (createCertificate) {
|
||||||
delete thisData.certificate_id;
|
delete data.certificate_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return access
|
await access.can("dead_hosts:update", data.id);
|
||||||
.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 = [];
|
|
||||||
|
|
||||||
if (typeof thisData.domain_names !== "undefined") {
|
// Get a list of the domain names and check each of them against existing records
|
||||||
thisData.domain_names.map((domain_name) => {
|
const domainNameCheckPromises = [];
|
||||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name, "dead", data.id));
|
if (typeof data.domain_names !== "undefined") {
|
||||||
|
data.domain_names.map((domainName) => {
|
||||||
|
domainNameCheckPromises.push(internalHost.isHostnameTaken(domainName, "dead", data.id));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(domain_name_check_promises).then((check_results) => {
|
const checkResults = await Promise.all(domainNameCheckPromises);
|
||||||
check_results.map((result) => {
|
checkResults.map((result) => {
|
||||||
if (result.is_taken) {
|
if (result.is_taken) {
|
||||||
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
throw new errs.ValidationError(`${result.hostname} is already in use`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
const row = await internalDeadHost.get(access, { id: data.id });
|
||||||
.then(() => {
|
|
||||||
return internalDeadHost.get(access, { id: thisData.id });
|
if (row.id !== data.id) {
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (row.id !== thisData.id) {
|
|
||||||
// Sanity check that something crazy hasn't happened
|
// Sanity check that something crazy hasn't happened
|
||||||
throw new errs.InternalValidationError(
|
throw new errs.InternalValidationError(
|
||||||
`404 Host could not be updated, IDs do not match: ${row.id} !== ${thisData.id}`,
|
`404 Host could not be updated, IDs do not match: ${row.id} !== ${data.id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createCertificate) {
|
if (createCertificate) {
|
||||||
return internalCertificate
|
const cert = await internalCertificate.createQuickCertificate(access, {
|
||||||
.createQuickCertificate(access, {
|
domain_names: data.domain_names || row.domain_names,
|
||||||
domain_names: thisData.domain_names || row.domain_names,
|
meta: _.assign({}, row.meta, data.meta),
|
||||||
meta: _.assign({}, row.meta, thisData.meta),
|
|
||||||
})
|
|
||||||
.then((cert) => {
|
|
||||||
// update host with cert id
|
|
||||||
thisData.certificate_id = cert.id;
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return row;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update host with cert id
|
||||||
|
data.certificate_id = cert.id;
|
||||||
}
|
}
|
||||||
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.
|
// 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(
|
let thisData = _.assign(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
domain_names: row.domain_names,
|
domain_names: row.domain_names,
|
||||||
@@ -180,38 +153,31 @@ const internalDeadHost = {
|
|||||||
|
|
||||||
thisData = internalHost.cleanSslHstsData(thisData, row);
|
thisData = internalHost.cleanSslHstsData(thisData, row);
|
||||||
|
|
||||||
return deadHostModel
|
|
||||||
|
// do the row update
|
||||||
|
await deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where({ id: thisData.id })
|
.where({id: data.id})
|
||||||
.patch(thisData)
|
.patch(data);
|
||||||
.then((saved_row) => {
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog
|
await internalAuditLog.add(access, {
|
||||||
.add(access, {
|
|
||||||
action: "updated",
|
action: "updated",
|
||||||
object_type: "dead-host",
|
object_type: "dead-host",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: thisData,
|
meta: thisData,
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return _.omit(saved_row, omissions());
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
const thisRow = await internalDeadHost
|
||||||
.then(() => {
|
|
||||||
return internalDeadHost
|
|
||||||
.get(access, {
|
.get(access, {
|
||||||
id: thisData.id,
|
id: thisData.id,
|
||||||
expand: ["owner", "certificate"],
|
expand: ["owner", "certificate"],
|
||||||
})
|
});
|
||||||
.then((row) => {
|
|
||||||
// Configure nginx
|
// Configure nginx
|
||||||
return internalNginx.configure(deadHostModel, "dead_host", row).then((new_meta) => {
|
const newMeta = await internalNginx.configure(deadHostModel, "dead_host", row);
|
||||||
row.meta = new_meta;
|
row.meta = newMeta;
|
||||||
return _.omit(internalHost.cleanRowCertificateMeta(row), omissions());
|
return _.omit(internalHost.cleanRowCertificateMeta(thisRow), omissions());
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,39 +188,32 @@ const internalDeadHost = {
|
|||||||
* @param {Array} [data.omit]
|
* @param {Array} [data.omit]
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
get: (access, data) => {
|
get: async (access, data) => {
|
||||||
const thisData = data || {};
|
const accessData = await access.can("dead_hosts:get", data.id);
|
||||||
|
|
||||||
return access
|
|
||||||
.can("dead_hosts:get", thisData.id)
|
|
||||||
.then((access_data) => {
|
|
||||||
const query = deadHostModel
|
const query = deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("is_deleted", 0)
|
.where("is_deleted", 0)
|
||||||
.andWhere("id", dthisDataata.id)
|
.andWhere("id", data.id)
|
||||||
.allowGraph("[owner,certificate]")
|
.allowGraph("[owner,certificate]")
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (access_data.permission_visibility !== "all") {
|
if (accessData.permission_visibility !== "all") {
|
||||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof thisData.expand !== "undefined" && thisData.expand !== null) {
|
if (typeof data.expand !== "undefined" && data.expand !== null) {
|
||||||
query.withGraphFetched(`[${data.expand.join(", ")}]`);
|
query.withGraphFetched(`[${data.expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(utils.omitRow(omissions()));
|
const row = await query.then(utils.omitRow(omissions()));
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(thisData.id);
|
throw new errs.ItemNotFoundError(data.id);
|
||||||
}
|
}
|
||||||
// Custom omissions
|
// Custom omissions
|
||||||
if (typeof thisData.omit !== "undefined" && thisData.omit !== null) {
|
if (typeof data.omit !== "undefined" && data.omit !== null) {
|
||||||
return _.omit(row, thisData.omit);
|
return _.omit(row, data.omit);
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,42 +223,32 @@ const internalDeadHost = {
|
|||||||
* @param {String} [data.reason]
|
* @param {String} [data.reason]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
delete: (access, data) => {
|
delete: async (access, data) => {
|
||||||
return access
|
await access.can("dead_hosts:delete", data.id)
|
||||||
.can("dead_hosts:delete", data.id)
|
const row = await internalDeadHost.get(access, { id: data.id });
|
||||||
.then(() => {
|
|
||||||
return internalDeadHost.get(access, { id: data.id });
|
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(data.id);
|
throw new errs.ItemNotFoundError(data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deadHostModel
|
await deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("id", row.id)
|
.where("id", row.id)
|
||||||
.patch({
|
.patch({
|
||||||
is_deleted: 1,
|
is_deleted: 1,
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Delete Nginx Config
|
|
||||||
return internalNginx.deleteConfig("dead_host", row).then(() => {
|
|
||||||
return internalNginx.reload();
|
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then(() => {
|
// Delete Nginx Config
|
||||||
|
await internalNginx.deleteConfig("dead_host", row);
|
||||||
|
await internalNginx.reload();
|
||||||
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "deleted",
|
action: "deleted",
|
||||||
object_type: "dead-host",
|
object_type: "dead-host",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: _.omit(row, omissions()),
|
meta: _.omit(row, omissions()),
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return true;
|
return true;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,16 +258,12 @@ const internalDeadHost = {
|
|||||||
* @param {String} [data.reason]
|
* @param {String} [data.reason]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
enable: (access, data) => {
|
enable: async (access, data) => {
|
||||||
return access
|
await access.can("dead_hosts:update", data.id)
|
||||||
.can("dead_hosts:update", data.id)
|
const row = await internalDeadHost.get(access, {
|
||||||
.then(() => {
|
|
||||||
return internalDeadHost.get(access, {
|
|
||||||
id: data.id,
|
id: data.id,
|
||||||
expand: ["certificate", "owner"],
|
expand: ["certificate", "owner"],
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(data.id);
|
throw new errs.ItemNotFoundError(data.id);
|
||||||
}
|
}
|
||||||
@@ -328,29 +273,24 @@ const internalDeadHost = {
|
|||||||
|
|
||||||
row.enabled = 1;
|
row.enabled = 1;
|
||||||
|
|
||||||
return deadHostModel
|
await deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("id", row.id)
|
.where("id", row.id)
|
||||||
.patch({
|
.patch({
|
||||||
enabled: 1,
|
enabled: 1,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
// Configure nginx
|
// Configure nginx
|
||||||
return internalNginx.configure(deadHostModel, "dead_host", row);
|
await internalNginx.configure(deadHostModel, "dead_host", row);
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "enabled",
|
action: "enabled",
|
||||||
object_type: "dead-host",
|
object_type: "dead-host",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: _.omit(row, omissions()),
|
meta: _.omit(row, omissions()),
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return true;
|
return true;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,13 +300,9 @@ const internalDeadHost = {
|
|||||||
* @param {String} [data.reason]
|
* @param {String} [data.reason]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
disable: (access, data) => {
|
disable: async (access, data) => {
|
||||||
return access
|
await access.can("dead_hosts:update", data.id)
|
||||||
.can("dead_hosts:update", data.id)
|
const row = await internalDeadHost.get(access, { id: data.id });
|
||||||
.then(() => {
|
|
||||||
return internalDeadHost.get(access, { id: data.id });
|
|
||||||
})
|
|
||||||
.then((row) => {
|
|
||||||
if (!row || !row.id) {
|
if (!row || !row.id) {
|
||||||
throw new errs.ItemNotFoundError(data.id);
|
throw new errs.ItemNotFoundError(data.id);
|
||||||
}
|
}
|
||||||
@@ -376,31 +312,25 @@ const internalDeadHost = {
|
|||||||
|
|
||||||
row.enabled = 0;
|
row.enabled = 0;
|
||||||
|
|
||||||
return deadHostModel
|
await deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("id", row.id)
|
.where("id", row.id)
|
||||||
.patch({
|
.patch({
|
||||||
enabled: 0,
|
enabled: 0,
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Delete Nginx Config
|
|
||||||
return internalNginx.deleteConfig("dead_host", row).then(() => {
|
|
||||||
return internalNginx.reload();
|
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.then(() => {
|
// Delete Nginx Config
|
||||||
|
await internalNginx.deleteConfig("dead_host", row);
|
||||||
|
await internalNginx.reload();
|
||||||
|
|
||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
await internalAuditLog.add(access, {
|
||||||
action: "disabled",
|
action: "disabled",
|
||||||
object_type: "dead-host",
|
object_type: "dead-host",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: _.omit(row, omissions()),
|
meta: _.omit(row, omissions()),
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return true;
|
return true;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -408,13 +338,11 @@ const internalDeadHost = {
|
|||||||
*
|
*
|
||||||
* @param {Access} access
|
* @param {Access} access
|
||||||
* @param {Array} [expand]
|
* @param {Array} [expand]
|
||||||
* @param {String} [search_query]
|
* @param {String} [searchQuery]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getAll: (access, expand, search_query) => {
|
getAll: async (access, expand, searchQuery) => {
|
||||||
return access
|
const accessData = await access.can("dead_hosts:list")
|
||||||
.can("dead_hosts:list")
|
|
||||||
.then((access_data) => {
|
|
||||||
const query = deadHostModel
|
const query = deadHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("is_deleted", 0)
|
.where("is_deleted", 0)
|
||||||
@@ -422,14 +350,14 @@ const internalDeadHost = {
|
|||||||
.allowGraph("[owner,certificate]")
|
.allowGraph("[owner,certificate]")
|
||||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||||
|
|
||||||
if (access_data.permission_visibility !== "all") {
|
if (accessData.permission_visibility !== "all") {
|
||||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query is used for searching
|
// Query is used for searching
|
||||||
if (typeof search_query === "string" && search_query.length > 0) {
|
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||||
query.where(function () {
|
query.where(function () {
|
||||||
this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`);
|
this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,15 +365,11 @@ const internalDeadHost = {
|
|||||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(utils.omitRows(omissions()));
|
const rows = await query.then(utils.omitRows(omissions()));
|
||||||
})
|
|
||||||
.then((rows) => {
|
|
||||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||||
return internalHost.cleanAllRowsCertificateMeta(rows);
|
internalHost.cleanAllRowsCertificateMeta(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -455,16 +379,15 @@ const internalDeadHost = {
|
|||||||
* @param {String} visibility
|
* @param {String} visibility
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getCount: (user_id, visibility) => {
|
getCount: async (user_id, visibility) => {
|
||||||
const query = deadHostModel.query().count("id as count").where("is_deleted", 0);
|
const query = deadHostModel.query().count("id as count").where("is_deleted", 0);
|
||||||
|
|
||||||
if (visibility !== "all") {
|
if (visibility !== "all") {
|
||||||
query.andWhere("owner_user_id", user_id);
|
query.andWhere("owner_user_id", user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.first().then((row) => {
|
const row = await query.first();
|
||||||
return Number.parseInt(row.count, 10);
|
return Number.parseInt(row.count, 10);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -65,50 +65,33 @@ const internalHost = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns all the host types with any domain listed in the provided domain_names array.
|
* This returns all the host types with any domain listed in the provided domainNames array.
|
||||||
* This is used by the certificates to temporarily disable any host that is using the domain
|
* This is used by the certificates to temporarily disable any host that is using the domain
|
||||||
*
|
*
|
||||||
* @param {Array} domain_names
|
* @param {Array} domainNames
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getHostsWithDomains: (domain_names) => {
|
getHostsWithDomains: async (domainNames) => {
|
||||||
const promises = [
|
const responseObject = {
|
||||||
proxyHostModel.query().where("is_deleted", 0),
|
|
||||||
redirectionHostModel.query().where("is_deleted", 0),
|
|
||||||
deadHostModel.query().where("is_deleted", 0),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Promise.all(promises).then((promises_results) => {
|
|
||||||
const response_object = {
|
|
||||||
total_count: 0,
|
total_count: 0,
|
||||||
dead_hosts: [],
|
dead_hosts: [],
|
||||||
proxy_hosts: [],
|
proxy_hosts: [],
|
||||||
redirection_hosts: [],
|
redirection_hosts: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (promises_results[0]) {
|
const proxyRes = await proxyHostModel.query().where("is_deleted", 0);
|
||||||
// Proxy Hosts
|
responseObject.proxy_hosts = internalHost._getHostsWithDomains(proxyRes, domainNames);
|
||||||
response_object.proxy_hosts = internalHost._getHostsWithDomains(promises_results[0], domain_names);
|
responseObject.total_count += responseObject.proxy_hosts.length;
|
||||||
response_object.total_count += response_object.proxy_hosts.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (promises_results[1]) {
|
const redirRes = await redirectionHostModel.query().where("is_deleted", 0);
|
||||||
// Redirection Hosts
|
responseObject.redirection_hosts = internalHost._getHostsWithDomains(redirRes, domainNames);
|
||||||
response_object.redirection_hosts = internalHost._getHostsWithDomains(
|
responseObject.total_count += responseObject.redirection_hosts.length;
|
||||||
promises_results[1],
|
|
||||||
domain_names,
|
|
||||||
);
|
|
||||||
response_object.total_count += response_object.redirection_hosts.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (promises_results[2]) {
|
const deadRes = await deadHostModel.query().where("is_deleted", 0);
|
||||||
// Dead Hosts
|
responseObject.dead_hosts = internalHost._getHostsWithDomains(deadRes, domainNames);
|
||||||
response_object.dead_hosts = internalHost._getHostsWithDomains(promises_results[2], domain_names);
|
responseObject.total_count += responseObject.dead_hosts.length;
|
||||||
response_object.total_count += response_object.dead_hosts.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response_object;
|
return responseObject;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -301,8 +301,11 @@ const internalNginx = {
|
|||||||
* @param {String} filename
|
* @param {String} filename
|
||||||
*/
|
*/
|
||||||
deleteFile: (filename) => {
|
deleteFile: (filename) => {
|
||||||
logger.debug(`Deleting file: ${filename}`);
|
if (!fs.existsSync(filename)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
logger.debug(`Deleting file: ${filename}`);
|
||||||
fs.unlinkSync(filename);
|
fs.unlinkSync(filename);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.debug("Could not delete file:", JSON.stringify(err, null, 2));
|
logger.debug("Could not delete file:", JSON.stringify(err, null, 2));
|
||||||
|
@@ -420,10 +420,8 @@ const internalProxyHost = {
|
|||||||
* @param {String} [search_query]
|
* @param {String} [search_query]
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getAll: (access, expand, search_query) => {
|
getAll: async (access, expand, searchQuery) => {
|
||||||
return access
|
const accessData = await access.can("proxy_hosts:list");
|
||||||
.can("proxy_hosts:list")
|
|
||||||
.then((access_data) => {
|
|
||||||
const query = proxyHostModel
|
const query = proxyHostModel
|
||||||
.query()
|
.query()
|
||||||
.where("is_deleted", 0)
|
.where("is_deleted", 0)
|
||||||
@@ -431,14 +429,14 @@ const internalProxyHost = {
|
|||||||
.allowGraph("[owner,access_list,certificate]")
|
.allowGraph("[owner,access_list,certificate]")
|
||||||
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
.orderBy(castJsonIfNeed("domain_names"), "ASC");
|
||||||
|
|
||||||
if (access_data.permission_visibility !== "all") {
|
if (accessData.permission_visibility !== "all") {
|
||||||
query.andWhere("owner_user_id", access.token.getUserId(1));
|
query.andWhere("owner_user_id", access.token.getUserId(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query is used for searching
|
// Query is used for searching
|
||||||
if (typeof search_query === "string" && search_query.length > 0) {
|
if (typeof searchQuery === "string" && searchQuery.length > 0) {
|
||||||
query.where(function () {
|
query.where(function () {
|
||||||
this.where(castJsonIfNeed("domain_names"), "like", `%${search_query}%`);
|
this.where(castJsonIfNeed("domain_names"), "like", `%${searchQuery}%`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,15 +444,11 @@ const internalProxyHost = {
|
|||||||
query.withGraphFetched(`[${expand.join(", ")}]`);
|
query.withGraphFetched(`[${expand.join(", ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.then(utils.omitRows(omissions()));
|
const rows = await query.then(utils.omitRows(omissions()));
|
||||||
})
|
|
||||||
.then((rows) => {
|
|
||||||
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
|
||||||
return internalHost.cleanAllRowsCertificateMeta(rows);
|
return internalHost.cleanAllRowsCertificateMeta(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -348,7 +348,7 @@ const internalStream = {
|
|||||||
// Add to audit log
|
// Add to audit log
|
||||||
return internalAuditLog.add(access, {
|
return internalAuditLog.add(access, {
|
||||||
action: "disabled",
|
action: "disabled",
|
||||||
object_type: "stream-host",
|
object_type: "stream",
|
||||||
object_id: row.id,
|
object_id: row.id,
|
||||||
meta: _.omit(row, omissions()),
|
meta: _.omit(row, omissions()),
|
||||||
});
|
});
|
||||||
|
@@ -131,7 +131,7 @@ const internalUser = {
|
|||||||
action: "updated",
|
action: "updated",
|
||||||
object_type: "user",
|
object_type: "user",
|
||||||
object_id: user.id,
|
object_id: user.id,
|
||||||
meta: data,
|
meta: { ...data, id: user.id, name: user.name },
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return user;
|
return user;
|
||||||
|
@@ -107,7 +107,6 @@ export default function (tokenString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tokenUserId = tokenData.attrs.id ? tokenData.attrs.id : 0;
|
const tokenUserId = tokenData.attrs.id ? tokenData.attrs.id : 0;
|
||||||
let query;
|
|
||||||
|
|
||||||
if (typeof objectCache[objectType] !== "undefined") {
|
if (typeof objectCache[objectType] !== "undefined") {
|
||||||
objects = objectCache[objectType];
|
objects = objectCache[objectType];
|
||||||
@@ -120,15 +119,19 @@ export default function (tokenString) {
|
|||||||
|
|
||||||
// Proxy Hosts
|
// Proxy Hosts
|
||||||
case "proxy_hosts": {
|
case "proxy_hosts": {
|
||||||
query = proxyHostModel.query().select("id").andWhere("is_deleted", 0);
|
const query = proxyHostModel
|
||||||
|
.query()
|
||||||
|
.select("id")
|
||||||
|
.andWhere("is_deleted", 0);
|
||||||
|
|
||||||
if (permissions.visibility === "user") {
|
if (permissions.visibility === "user") {
|
||||||
query.andWhere("owner_user_id", tokenUserId);
|
query.andWhere("owner_user_id", tokenUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = await query();
|
const rows = await query;
|
||||||
objects = [];
|
objects = [];
|
||||||
_.forEach(rows, (ruleRow) => {
|
_.forEach(rows, (ruleRow) => {
|
||||||
result.push(ruleRow.id);
|
objects.push(ruleRow.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
// enum should not have less than 1 item
|
// enum should not have less than 1 item
|
||||||
@@ -141,7 +144,6 @@ export default function (tokenString) {
|
|||||||
objectCache[objectType] = objects;
|
objectCache[objectType] = objects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objects;
|
return objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -6,46 +6,6 @@ import utils from "./utils.js";
|
|||||||
|
|
||||||
const CERTBOT_VERSION_REPLACEMENT = "$(certbot --version | grep -Eo '[0-9](\\.[0-9]+)+')";
|
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
|
* Installs a cerbot plugin given the key for the object from
|
||||||
* ../global/certbot-dns-plugins.json
|
* ../global/certbot-dns-plugins.json
|
||||||
@@ -84,4 +44,43 @@ 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 };
|
export { installPlugins, installPlugin };
|
||||||
|
@@ -128,7 +128,7 @@ export default () => {
|
|||||||
*/
|
*/
|
||||||
getUserId: (defaultValue) => {
|
getUserId: (defaultValue) => {
|
||||||
const attrs = self.get("attrs");
|
const attrs = self.get("attrs");
|
||||||
if (attrs && typeof attrs.id !== "undefined" && attrs.id) {
|
if (attrs?.id) {
|
||||||
return attrs.id;
|
return attrs.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,5 +3,5 @@
|
|||||||
"ignore": [
|
"ignore": [
|
||||||
"data"
|
"data"
|
||||||
],
|
],
|
||||||
"ext": "js json ejs"
|
"ext": "js json ejs cjs"
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@apidevtools/swagger-parser": "^10.1.0",
|
"@apidevtools/swagger-parser": "^10.1.0",
|
||||||
"@biomejs/biome": "^2.2.3",
|
"@biomejs/biome": "^2.2.4",
|
||||||
"chalk": "4.1.2",
|
"chalk": "4.1.2",
|
||||||
"nodemon": "^2.0.2"
|
"nodemon": "^2.0.2"
|
||||||
},
|
},
|
||||||
|
@@ -52,4 +52,56 @@ router
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
|
import dnsPlugins from "../../global/certbot-dns-plugins.json" with { type: "json" };
|
||||||
import internalCertificate from "../../internal/certificate.js";
|
import internalCertificate from "../../internal/certificate.js";
|
||||||
import errs from "../../lib/error.js";
|
import errs from "../../lib/error.js";
|
||||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||||
@@ -72,6 +73,40 @@ router
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test HTTP challenge for domains
|
* Test HTTP challenge for domains
|
||||||
*
|
*
|
||||||
@@ -107,6 +142,41 @@ router
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific certificate
|
* Specific certificate
|
||||||
*
|
*
|
||||||
@@ -266,38 +336,4 @@ router
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -121,7 +121,7 @@ router
|
|||||||
/**
|
/**
|
||||||
* PUT /api/nginx/dead-hosts/123
|
* PUT /api/nginx/dead-hosts/123
|
||||||
*
|
*
|
||||||
* Update and existing dead-host
|
* Update an existing dead-host
|
||||||
*/
|
*/
|
||||||
.put(async (req, res, next) => {
|
.put(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
@@ -138,7 +138,7 @@ router
|
|||||||
/**
|
/**
|
||||||
* DELETE /api/nginx/dead-hosts/123
|
* DELETE /api/nginx/dead-hosts/123
|
||||||
*
|
*
|
||||||
* Update and existing dead-host
|
* Delete a dead-host
|
||||||
*/
|
*/
|
||||||
.delete(async (req, res, next) => {
|
.delete(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
@@ -14,11 +14,12 @@ router
|
|||||||
.options((_, res) => {
|
.options((_, res) => {
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
})
|
})
|
||||||
|
.all(jwtdecode())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /reports/hosts
|
* GET /reports/hosts
|
||||||
*/
|
*/
|
||||||
.get(jwtdecode(), async (req, res, next) => {
|
.get(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const data = await internalReport.getHostsReport(res.locals.access);
|
const data = await internalReport.getHostsReport(res.locals.access);
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
|
7
backend/schema/components/audit-log-list.json
Normal file
7
backend/schema/components/audit-log-list.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"description": "Audit Log list",
|
||||||
|
"items": {
|
||||||
|
"$ref": "./audit-log-object.json"
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,16 @@
|
|||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Audit Log 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,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
@@ -27,6 +36,9 @@
|
|||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"$ref": "./user-object.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,15 +62,9 @@
|
|||||||
"dns_provider_credentials": {
|
"dns_provider_credentials": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"letsencrypt_agree": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"letsencrypt_certificate": {
|
"letsencrypt_certificate": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"letsencrypt_email": {
|
|
||||||
"$ref": "../common.json#/properties/email"
|
|
||||||
},
|
|
||||||
"propagation_seconds": {
|
"propagation_seconds": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minimum": 0
|
"minimum": 0
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "ipv4"
|
"format": "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"operationId": "getAuditLog",
|
"operationId": "getAuditLogs",
|
||||||
"summary": "Get Audit Log",
|
"summary": "Get Audit Logs",
|
||||||
"tags": ["Audit Log"],
|
"tags": ["Audit Log"],
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "../../components/audit-log-object.json"
|
"$ref": "../../components/audit-log-list.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
backend/schema/paths/audit-log/id/get.json
Normal file
73
backend/schema/paths/audit-log/id/get.json
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -36,8 +36,6 @@
|
|||||||
"domain_names": ["test.example.com"],
|
"domain_names": ["test.example.com"],
|
||||||
"expires_on": "2025-01-07T04:34:18.000Z",
|
"expires_on": "2025-01-07T04:34:18.000Z",
|
||||||
"meta": {
|
"meta": {
|
||||||
"letsencrypt_email": "jc@jc21.com",
|
|
||||||
"letsencrypt_agree": true,
|
|
||||||
"dns_challenge": false
|
"dns_challenge": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,8 +37,6 @@
|
|||||||
"nice_name": "My Test Cert",
|
"nice_name": "My Test Cert",
|
||||||
"domain_names": ["test.jc21.supernerd.pro"],
|
"domain_names": ["test.jc21.supernerd.pro"],
|
||||||
"meta": {
|
"meta": {
|
||||||
"letsencrypt_email": "jc@jc21.com",
|
|
||||||
"letsencrypt_agree": true,
|
|
||||||
"dns_challenge": false
|
"dns_challenge": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,8 +36,6 @@
|
|||||||
"domain_names": ["test.example.com"],
|
"domain_names": ["test.example.com"],
|
||||||
"expires_on": "2025-01-07T04:34:18.000Z",
|
"expires_on": "2025-01-07T04:34:18.000Z",
|
||||||
"meta": {
|
"meta": {
|
||||||
"letsencrypt_email": "jc@jc21.com",
|
|
||||||
"letsencrypt_agree": true,
|
|
||||||
"dns_challenge": false
|
"dns_challenge": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,8 +52,6 @@
|
|||||||
"nice_name": "test.example.com",
|
"nice_name": "test.example.com",
|
||||||
"domain_names": ["test.example.com"],
|
"domain_names": ["test.example.com"],
|
||||||
"meta": {
|
"meta": {
|
||||||
"letsencrypt_email": "jc@jc21.com",
|
|
||||||
"letsencrypt_agree": true,
|
|
||||||
"dns_challenge": false,
|
"dns_challenge": false,
|
||||||
"letsencrypt_certificate": {
|
"letsencrypt_certificate": {
|
||||||
"cn": "test.example.com",
|
"cn": "test.example.com",
|
||||||
|
@@ -37,6 +37,9 @@
|
|||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"$ref": "../../../components/stream-object.json#/properties/meta"
|
"$ref": "../../../components/stream-object.json#/properties/meta"
|
||||||
|
},
|
||||||
|
"domain_names": {
|
||||||
|
"$ref": "../../../components/dead-host-object.json#/properties/domain_names"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,11 @@
|
|||||||
"$ref": "./paths/audit-log/get.json"
|
"$ref": "./paths/audit-log/get.json"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/audit-log/{id}": {
|
||||||
|
"get": {
|
||||||
|
"$ref": "./paths/audit-log/id/get.json"
|
||||||
|
}
|
||||||
|
},
|
||||||
"/nginx/access-lists": {
|
"/nginx/access-lists": {
|
||||||
"get": {
|
"get": {
|
||||||
"$ref": "./paths/nginx/access-lists/get.json"
|
"$ref": "./paths/nginx/access-lists/get.json"
|
||||||
|
@@ -121,12 +121,14 @@ const setupCertbotPlugins = async () => {
|
|||||||
// Make sure credentials file exists
|
// Make sure credentials file exists
|
||||||
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
const credentials_loc = `/etc/letsencrypt/credentials/credentials-${certificate.id}`;
|
||||||
// Escape single quotes and backslashes
|
// Escape single quotes and backslashes
|
||||||
|
if (typeof certificate.meta.dns_provider_credentials === "string") {
|
||||||
const escapedCredentials = certificate.meta.dns_provider_credentials
|
const escapedCredentials = certificate.meta.dns_provider_credentials
|
||||||
.replaceAll("'", "\\'")
|
.replaceAll("'", "\\'")
|
||||||
.replaceAll("\\", "\\\\");
|
.replaceAll("\\", "\\\\");
|
||||||
const credentials_cmd = `[ -f '${credentials_loc}' ] || { mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo '${escapedCredentials}' > '${credentials_loc}' && chmod 600 '${credentials_loc}'; }`;
|
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));
|
promises.push(utils.exec(credentials_cmd));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -43,59 +43,59 @@
|
|||||||
ajv-draft-04 "^1.0.0"
|
ajv-draft-04 "^1.0.0"
|
||||||
call-me-maybe "^1.0.2"
|
call-me-maybe "^1.0.2"
|
||||||
|
|
||||||
"@biomejs/biome@^2.2.3":
|
"@biomejs/biome@^2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-2.2.3.tgz#9d17991c80e006c5ca3e21bebe84b7afd71559e3"
|
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-2.2.4.tgz#184e4b83f89bd0d4151682a5aa3840df37748e17"
|
||||||
integrity sha512-9w0uMTvPrIdvUrxazZ42Ib7t8Y2yoGLKLdNne93RLICmaHw7mcLv4PPb5LvZLJF3141gQHiCColOh/v6VWlWmg==
|
integrity sha512-TBHU5bUy/Ok6m8c0y3pZiuO/BZoY/OcGxoLlrfQof5s8ISVwbVBdFINPQZyFfKwil8XibYWb7JMwnT8wT4WVPg==
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
"@biomejs/cli-darwin-arm64" "2.2.3"
|
"@biomejs/cli-darwin-arm64" "2.2.4"
|
||||||
"@biomejs/cli-darwin-x64" "2.2.3"
|
"@biomejs/cli-darwin-x64" "2.2.4"
|
||||||
"@biomejs/cli-linux-arm64" "2.2.3"
|
"@biomejs/cli-linux-arm64" "2.2.4"
|
||||||
"@biomejs/cli-linux-arm64-musl" "2.2.3"
|
"@biomejs/cli-linux-arm64-musl" "2.2.4"
|
||||||
"@biomejs/cli-linux-x64" "2.2.3"
|
"@biomejs/cli-linux-x64" "2.2.4"
|
||||||
"@biomejs/cli-linux-x64-musl" "2.2.3"
|
"@biomejs/cli-linux-x64-musl" "2.2.4"
|
||||||
"@biomejs/cli-win32-arm64" "2.2.3"
|
"@biomejs/cli-win32-arm64" "2.2.4"
|
||||||
"@biomejs/cli-win32-x64" "2.2.3"
|
"@biomejs/cli-win32-x64" "2.2.4"
|
||||||
|
|
||||||
"@biomejs/cli-darwin-arm64@2.2.3":
|
"@biomejs/cli-darwin-arm64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.2.3.tgz#e18240343fa705dafb08ba72a7b0e88f04a8be3e"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.2.4.tgz#9b50620c93501e370b7e6d5a8445f117f9946a0c"
|
||||||
integrity sha512-OrqQVBpadB5eqzinXN4+Q6honBz+tTlKVCsbEuEpljK8ASSItzIRZUA02mTikl3H/1nO2BMPFiJ0nkEZNy3B1w==
|
integrity sha512-RJe2uiyaloN4hne4d2+qVj3d3gFJFbmrr5PYtkkjei1O9c+BjGXgpUPVbi8Pl8syumhzJjFsSIYkcLt2VlVLMA==
|
||||||
|
|
||||||
"@biomejs/cli-darwin-x64@2.2.3":
|
"@biomejs/cli-darwin-x64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.2.3.tgz#964b51c9f649e3a725f6f43e75c4173b9ab8a3ae"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.2.4.tgz#343620c884fc8141155d114430e80e4eacfddc9e"
|
||||||
integrity sha512-OCdBpb1TmyfsTgBAM1kPMXyYKTohQ48WpiN9tkt9xvU6gKVKHY4oVwteBebiOqyfyzCNaSiuKIPjmHjUZ2ZNMg==
|
integrity sha512-cFsdB4ePanVWfTnPVaUX+yr8qV8ifxjBKMkZwN7gKb20qXPxd/PmwqUH8mY5wnM9+U0QwM76CxFyBRJhC9tQwg==
|
||||||
|
|
||||||
"@biomejs/cli-linux-arm64-musl@2.2.3":
|
"@biomejs/cli-linux-arm64-musl@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.2.3.tgz#1756c37960d5585ca865e184539b113e48719b41"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.2.4.tgz#cabcdadce2bc88b697f4063374224266c6f8b6e5"
|
||||||
integrity sha512-q3w9jJ6JFPZPeqyvwwPeaiS/6NEszZ+pXKF+IczNo8Xj6fsii45a4gEEicKyKIytalV+s829ACZujQlXAiVLBQ==
|
integrity sha512-7TNPkMQEWfjvJDaZRSkDCPT/2r5ESFPKx+TEev+I2BXDGIjfCZk2+b88FOhnJNHtksbOZv8ZWnxrA5gyTYhSsQ==
|
||||||
|
|
||||||
"@biomejs/cli-linux-arm64@2.2.3":
|
"@biomejs/cli-linux-arm64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.2.3.tgz#036c6334d5b09b51233ce5120b18f4c89a15a74c"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.2.4.tgz#55620f8f088145e62e1158eb85c568554d0c8673"
|
||||||
integrity sha512-g/Uta2DqYpECxG+vUmTAmUKlVhnGEcY7DXWgKP8ruLRa8Si1QHsWknPY3B/wCo0KgYiFIOAZ9hjsHfNb9L85+g==
|
integrity sha512-M/Iz48p4NAzMXOuH+tsn5BvG/Jb07KOMTdSVwJpicmhN309BeEyRyQX+n1XDF0JVSlu28+hiTQ2L4rZPvu7nMw==
|
||||||
|
|
||||||
"@biomejs/cli-linux-x64-musl@2.2.3":
|
"@biomejs/cli-linux-x64-musl@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.2.3.tgz#e6cce01910b9f56c1645c5518595d0b1eb38c245"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.2.4.tgz#6bfaea72505afdbda66a66c998d2d169a8b55f90"
|
||||||
integrity sha512-y76Dn4vkP1sMRGPFlNc+OTETBhGPJ90jY3il6jAfur8XWrYBQV3swZ1Jo0R2g+JpOeeoA0cOwM7mJG6svDz79w==
|
integrity sha512-m41nFDS0ksXK2gwXL6W6yZTYPMH0LughqbsxInSKetoH6morVj43szqKx79Iudkp8WRT5SxSh7qVb8KCUiewGg==
|
||||||
|
|
||||||
"@biomejs/cli-linux-x64@2.2.3":
|
"@biomejs/cli-linux-x64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-2.2.3.tgz#f328e7cfde92fad6c7ad215df1f51b146b4ed007"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-2.2.4.tgz#8c1ed61dcafb8a5939346c714ec122651f57e1db"
|
||||||
integrity sha512-LEtyYL1fJsvw35CxrbQ0gZoxOG3oZsAjzfRdvRBRHxOpQ91Q5doRVjvWW/wepgSdgk5hlaNzfeqpyGmfSD0Eyw==
|
integrity sha512-orr3nnf2Dpb2ssl6aihQtvcKtLySLta4E2UcXdp7+RTa7mfJjBgIsbS0B9GC8gVu0hjOu021aU8b3/I1tn+pVQ==
|
||||||
|
|
||||||
"@biomejs/cli-win32-arm64@2.2.3":
|
"@biomejs/cli-win32-arm64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.2.3.tgz#b8d64ca6dc1c50b8f3d42475afd31b7b44460935"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.2.4.tgz#b2528f6c436e753d6083d7779f0662e08786cedb"
|
||||||
integrity sha512-Ms9zFYzjcJK7LV+AOMYnjN3pV3xL8Prxf9aWdDVL74onLn5kcvZ1ZMQswE5XHtnd/r/0bnUd928Rpbs14BzVmA==
|
integrity sha512-NXnfTeKHDFUWfxAefa57DiGmu9VyKi0cDqFpdI+1hJWQjGJhJutHPX0b5m+eXvTKOaf+brU+P0JrQAZMb5yYaQ==
|
||||||
|
|
||||||
"@biomejs/cli-win32-x64@2.2.3":
|
"@biomejs/cli-win32-x64@2.2.4":
|
||||||
version "2.2.3"
|
version "2.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-2.2.3.tgz#ecafffddf0c0675c825735c7cc917cbc8c538433"
|
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-2.2.4.tgz#c8e21413120fe073fa49b78fdd987022941ff66f"
|
||||||
integrity sha512-gvCpewE7mBwBIpqk1YrUqNR4mCiyJm6UI3YWQQXkedSSEwzRdodRpaKhbdbHw1/hmTWOVXQ+Eih5Qctf4TCVOQ==
|
integrity sha512-3Y4V4zVRarVh/B/eSHczR4LYoSVyv3Dfuvm3cWs5w/HScccS0+Wt/lHOcDTRYeHjQmMYVC3rIRWqyN2EI52+zg==
|
||||||
|
|
||||||
"@gar/promisify@^1.0.1":
|
"@gar/promisify@^1.0.1":
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
|
@@ -15,7 +15,7 @@ ENV SUPPRESS_NO_CONFIG_WARNING=1 \
|
|||||||
|
|
||||||
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
|
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install -y jq python3-pip logrotate \
|
&& apt-get install -y jq python3-pip logrotate moreutils \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
@@ -71,12 +71,14 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- nginx_proxy_manager
|
- nginx_proxy_manager
|
||||||
environment:
|
environment:
|
||||||
|
TZ: "${TZ:-Australia/Brisbane}"
|
||||||
MYSQL_ROOT_PASSWORD: 'npm'
|
MYSQL_ROOT_PASSWORD: 'npm'
|
||||||
MYSQL_DATABASE: 'npm'
|
MYSQL_DATABASE: 'npm'
|
||||||
MYSQL_USER: 'npm'
|
MYSQL_USER: 'npm'
|
||||||
MYSQL_PASSWORD: 'npm'
|
MYSQL_PASSWORD: 'npm'
|
||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
|
- '/etc/localtime:/etc/localtime:ro'
|
||||||
|
|
||||||
db-postgres:
|
db-postgres:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/2.2.3/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
||||||
"vcs": {
|
"vcs": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"clientKind": "git",
|
"clientKind": "git",
|
||||||
@@ -64,7 +64,8 @@
|
|||||||
"useUniqueElementIds": "off"
|
"useUniqueElementIds": "off"
|
||||||
},
|
},
|
||||||
"suspicious": {
|
"suspicious": {
|
||||||
"noExplicitAny": "off"
|
"noExplicitAny": "off",
|
||||||
|
"noArrayIndexKey": "off"
|
||||||
},
|
},
|
||||||
"performance": {
|
"performance": {
|
||||||
"noDelete": "off"
|
"noDelete": "off"
|
||||||
|
@@ -12,47 +12,51 @@
|
|||||||
"prettier": "biome format --write ./src",
|
"prettier": "biome format --write ./src",
|
||||||
"locale-extract": "formatjs extract 'src/**/*.tsx'",
|
"locale-extract": "formatjs extract 'src/**/*.tsx'",
|
||||||
"locale-compile": "formatjs compile-folder src/locale/src src/locale/lang",
|
"locale-compile": "formatjs compile-folder src/locale/src src/locale/lang",
|
||||||
|
"locale-sort": "./src/locale/scripts/locale-sort.sh",
|
||||||
"test": "vitest"
|
"test": "vitest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tabler/core": "^1.4.0",
|
"@tabler/core": "^1.4.0",
|
||||||
"@tabler/icons-react": "^3.34.1",
|
"@tabler/icons-react": "^3.35.0",
|
||||||
"@tanstack/react-query": "^5.85.6",
|
"@tanstack/react-query": "^5.89.0",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
|
"@uiw/react-textarea-code-editor": "^3.1.1",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"country-flag-icons": "^1.5.19",
|
"country-flag-icons": "^1.5.20",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"formik": "^2.4.6",
|
"formik": "^2.4.6",
|
||||||
|
"generate-password-browser": "^1.1.0",
|
||||||
"humps": "^2.0.1",
|
"humps": "^2.0.1",
|
||||||
"query-string": "^9.2.2",
|
"query-string": "^9.3.1",
|
||||||
"react": "^19.1.1",
|
"react": "^19.1.1",
|
||||||
"react-bootstrap": "^2.10.10",
|
"react-bootstrap": "^2.10.10",
|
||||||
"react-dom": "^19.1.1",
|
"react-dom": "^19.1.1",
|
||||||
"react-intl": "^7.1.11",
|
"react-intl": "^7.1.11",
|
||||||
"react-router-dom": "^7.8.2",
|
"react-router-dom": "^7.9.1",
|
||||||
|
"react-select": "^5.10.2",
|
||||||
"react-toastify": "^11.0.5",
|
"react-toastify": "^11.0.5",
|
||||||
"rooks": "^9.2.0"
|
"rooks": "^9.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.2.3",
|
"@biomejs/biome": "^2.2.4",
|
||||||
"@formatjs/cli": "^6.7.2",
|
"@formatjs/cli": "^6.7.2",
|
||||||
"@tanstack/react-query-devtools": "^5.85.6",
|
"@tanstack/react-query-devtools": "^5.89.0",
|
||||||
"@testing-library/dom": "^10.4.1",
|
"@testing-library/dom": "^10.4.1",
|
||||||
"@testing-library/jest-dom": "^6.8.0",
|
"@testing-library/jest-dom": "^6.8.0",
|
||||||
"@testing-library/react": "^16.3.0",
|
"@testing-library/react": "^16.3.0",
|
||||||
"@types/country-flag-icons": "^1.2.2",
|
"@types/country-flag-icons": "^1.2.2",
|
||||||
"@types/humps": "^2.0.6",
|
"@types/humps": "^2.0.6",
|
||||||
"@types/react": "^19.1.12",
|
"@types/react": "^19.1.13",
|
||||||
"@types/react-dom": "^19.1.9",
|
"@types/react-dom": "^19.1.9",
|
||||||
"@types/react-table": "^7.7.20",
|
"@types/react-table": "^7.7.20",
|
||||||
"@vitejs/plugin-react": "^5.0.2",
|
"@vitejs/plugin-react": "^5.0.3",
|
||||||
"happy-dom": "^18.0.1",
|
"happy-dom": "^18.0.1",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.6",
|
||||||
"postcss-simple-vars": "^7.0.1",
|
"postcss-simple-vars": "^7.0.1",
|
||||||
"sass": "^1.91.0",
|
"sass": "^1.93.0",
|
||||||
"tmp": "^0.2.5",
|
"tmp": "^0.2.5",
|
||||||
"typescript": "5.9.2",
|
"typescript": "5.9.2",
|
||||||
"vite": "^7.1.4",
|
"vite": "^7.1.6",
|
||||||
"vite-plugin-checker": "^0.10.3",
|
"vite-plugin-checker": "^0.10.3",
|
||||||
"vite-tsconfig-paths": "^5.1.4",
|
"vite-tsconfig-paths": "^5.1.4",
|
||||||
"vitest": "^3.2.4"
|
"vitest": "^3.2.4"
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
.light {
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
.dark {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
|
||||||
.modal-backdrop {
|
.modal-backdrop {
|
||||||
--tblr-backdrop-opacity: 0.8 !important;
|
--tblr-backdrop-opacity: 0.8 !important;
|
||||||
}
|
}
|
||||||
@@ -12,3 +23,54 @@
|
|||||||
.ml-1 {
|
.ml-1 {
|
||||||
margin-left: 0.25rem;
|
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,13 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { AccessList } from "./models";
|
import type { AccessList } from "./models";
|
||||||
|
|
||||||
export async function createAccessList(item: AccessList, abortController?: AbortController): Promise<AccessList> {
|
export async function createAccessList(item: AccessList): Promise<AccessList> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/access-lists",
|
url: "/nginx/access-lists",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Certificate } from "./models";
|
import type { Certificate } from "./models";
|
||||||
|
|
||||||
export async function createCertificate(item: Certificate, abortController?: AbortController): Promise<Certificate> {
|
export async function createCertificate(item: Certificate): Promise<Certificate> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/certificates",
|
url: "/nginx/certificates",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { DeadHost } from "./models";
|
import type { DeadHost } from "./models";
|
||||||
|
|
||||||
export async function createDeadHost(item: DeadHost, abortController?: AbortController): Promise<DeadHost> {
|
export async function createDeadHost(item: DeadHost): Promise<DeadHost> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/dead-hosts",
|
url: "/nginx/dead-hosts",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { ProxyHost } from "./models";
|
import type { ProxyHost } from "./models";
|
||||||
|
|
||||||
export async function createProxyHost(item: ProxyHost, abortController?: AbortController): Promise<ProxyHost> {
|
export async function createProxyHost(item: ProxyHost): Promise<ProxyHost> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/proxy-hosts",
|
url: "/nginx/proxy-hosts",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { RedirectionHost } from "./models";
|
import type { RedirectionHost } from "./models";
|
||||||
|
|
||||||
export async function createRedirectionHost(
|
export async function createRedirectionHost(item: RedirectionHost): Promise<RedirectionHost> {
|
||||||
item: RedirectionHost,
|
return await api.post({
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<RedirectionHost> {
|
|
||||||
return await api.post(
|
|
||||||
{
|
|
||||||
url: "/nginx/redirection-hosts",
|
url: "/nginx/redirection-hosts",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Stream } from "./models";
|
import type { Stream } from "./models";
|
||||||
|
|
||||||
export async function createStream(item: Stream, abortController?: AbortController): Promise<Stream> {
|
export async function createStream(item: Stream): Promise<Stream> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/streams",
|
url: "/nginx/streams",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,11 @@ export interface NewUser {
|
|||||||
roles?: string[];
|
roles?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createUser(item: NewUser, noAuth?: boolean, abortController?: AbortController): Promise<User> {
|
export async function createUser(item: NewUser, noAuth?: boolean): Promise<User> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/users",
|
url: "/users",
|
||||||
// todo: only use whitelist of fields for this data
|
// todo: only use whitelist of fields for this data
|
||||||
data: item,
|
data: item,
|
||||||
noAuth,
|
noAuth,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteAccessList(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteAccessList(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/access-lists/${id}`,
|
url: `/nginx/access-lists/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteCertificate(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteCertificate(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/certificates/${id}`,
|
url: `/nginx/certificates/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteDeadHost(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteDeadHost(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/dead-hosts/${id}`,
|
url: `/nginx/dead-hosts/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteProxyHost(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteProxyHost(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/proxy-hosts/${id}`,
|
url: `/nginx/proxy-hosts/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteRedirectionHost(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteRedirectionHost(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/redirection-hosts/${id}`,
|
url: `/nginx/redirection-hosts/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteStream(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteStream(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/nginx/streams/${id}`,
|
url: `/nginx/streams/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function deleteUser(id: number, abortController?: AbortController): Promise<boolean> {
|
export async function deleteUser(id: number): Promise<boolean> {
|
||||||
return await api.del(
|
return await api.del({
|
||||||
{
|
|
||||||
url: `/users/${id}`,
|
url: `/users/${id}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Binary } from "./responseTypes";
|
import type { Binary } from "./responseTypes";
|
||||||
|
|
||||||
export async function downloadCertificate(id: number, abortController?: AbortController): Promise<Binary> {
|
export async function downloadCertificate(id: number): Promise<Binary> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/certificates/${id}/download`,
|
url: `/nginx/certificates/${id}/download`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
6
frontend/src/api/backend/expansions.ts
Normal file
6
frontend/src/api/backend/expansions.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
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,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { AccessListExpansion } from "./expansions";
|
||||||
import type { AccessList } from "./models";
|
import type { AccessList } from "./models";
|
||||||
|
|
||||||
export async function getAccessList(id: number, abortController?: AbortController): Promise<AccessList> {
|
export async function getAccessList(id: number, expand?: AccessListExpansion[], params = {}): Promise<AccessList> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/access-lists/${id}`,
|
url: `/nginx/access-lists/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { AccessListExpansion } from "./expansions";
|
||||||
import type { AccessList } from "./models";
|
import type { AccessList } from "./models";
|
||||||
|
|
||||||
export type AccessListExpansion = "owner" | "items" | "clients";
|
|
||||||
|
|
||||||
export async function getAccessLists(expand?: AccessListExpansion[], params = {}): Promise<AccessList[]> {
|
export async function getAccessLists(expand?: AccessListExpansion[], params = {}): Promise<AccessList[]> {
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/access-lists",
|
url: "/nginx/access-lists",
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { AuditLogExpansion } from "./expansions";
|
||||||
import type { AuditLog } from "./models";
|
import type { AuditLog } from "./models";
|
||||||
|
|
||||||
export async function getAuditLog(expand?: string[], params = {}): Promise<AuditLog[]> {
|
export async function getAuditLog(id: number, expand?: AuditLogExpansion[], params = {}): Promise<AuditLog> {
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/audit-log",
|
url: `/audit-log/${id}`,
|
||||||
params: {
|
params: {
|
||||||
expand: expand?.join(","),
|
expand: expand?.join(","),
|
||||||
...params,
|
...params,
|
||||||
|
13
frontend/src/api/backend/getAuditLogs.ts
Normal file
13
frontend/src/api/backend/getAuditLogs.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
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,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { CertificateExpansion } from "./expansions";
|
||||||
import type { Certificate } from "./models";
|
import type { Certificate } from "./models";
|
||||||
|
|
||||||
export async function getCertificate(id: number, abortController?: AbortController): Promise<Certificate> {
|
export async function getCertificate(id: number, expand?: CertificateExpansion[], params = {}): Promise<Certificate> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/certificates/${id}`,
|
url: `/nginx/certificates/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
9
frontend/src/api/backend/getCertificateDNSProviders.ts
Normal file
9
frontend/src/api/backend/getCertificateDNSProviders.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
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,7 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { CertificateExpansion } from "./expansions";
|
||||||
import type { Certificate } from "./models";
|
import type { Certificate } from "./models";
|
||||||
|
|
||||||
export async function getCertificates(expand?: string[], params = {}): Promise<Certificate[]> {
|
export async function getCertificates(expand?: CertificateExpansion[], params = {}): Promise<Certificate[]> {
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/certificates",
|
url: "/nginx/certificates",
|
||||||
params: {
|
params: {
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { HostExpansion } from "./expansions";
|
||||||
import type { DeadHost } from "./models";
|
import type { DeadHost } from "./models";
|
||||||
|
|
||||||
export async function getDeadHost(id: number, abortController?: AbortController): Promise<DeadHost> {
|
export async function getDeadHost(id: number, expand?: HostExpansion[], params = {}): Promise<DeadHost> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/dead-hosts/${id}`,
|
url: `/nginx/dead-hosts/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { HostExpansion } from "./expansions";
|
||||||
import type { DeadHost } from "./models";
|
import type { DeadHost } from "./models";
|
||||||
|
|
||||||
export type DeadHostExpansion = "owner" | "certificate";
|
export async function getDeadHosts(expand?: HostExpansion[], params = {}): Promise<DeadHost[]> {
|
||||||
|
|
||||||
export async function getDeadHosts(expand?: DeadHostExpansion[], params = {}): Promise<DeadHost[]> {
|
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/dead-hosts",
|
url: "/nginx/dead-hosts",
|
||||||
params: {
|
params: {
|
||||||
|
@@ -1,11 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { HealthResponse } from "./responseTypes";
|
import type { HealthResponse } from "./responseTypes";
|
||||||
|
|
||||||
export async function getHealth(abortController?: AbortController): Promise<HealthResponse> {
|
export async function getHealth(): Promise<HealthResponse> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: "/",
|
url: "/",
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function getHostsReport(abortController?: AbortController): Promise<Record<string, number>> {
|
export async function getHostsReport(): Promise<Record<string, number>> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: "/reports/hosts",
|
url: "/reports/hosts",
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { ProxyHostExpansion } from "./expansions";
|
||||||
import type { ProxyHost } from "./models";
|
import type { ProxyHost } from "./models";
|
||||||
|
|
||||||
export async function getProxyHost(id: number, abortController?: AbortController): Promise<ProxyHost> {
|
export async function getProxyHost(id: number, expand?: ProxyHostExpansion[], params = {}): Promise<ProxyHost> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/proxy-hosts/${id}`,
|
url: `/nginx/proxy-hosts/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { ProxyHostExpansion } from "./expansions";
|
||||||
import type { ProxyHost } from "./models";
|
import type { ProxyHost } from "./models";
|
||||||
|
|
||||||
export type ProxyHostExpansion = "owner" | "access_list" | "certificate";
|
|
||||||
|
|
||||||
export async function getProxyHosts(expand?: ProxyHostExpansion[], params = {}): Promise<ProxyHost[]> {
|
export async function getProxyHosts(expand?: ProxyHostExpansion[], params = {}): Promise<ProxyHost[]> {
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/proxy-hosts",
|
url: "/nginx/proxy-hosts",
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { ProxyHost } from "./models";
|
import type { HostExpansion } from "./expansions";
|
||||||
|
import type { RedirectionHost } from "./models";
|
||||||
|
|
||||||
export async function getRedirectionHost(id: number, abortController?: AbortController): Promise<ProxyHost> {
|
export async function getRedirectionHost(id: number, expand?: HostExpansion[], params = {}): Promise<RedirectionHost> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/redirection-hosts/${id}`,
|
url: `/nginx/redirection-hosts/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { HostExpansion } from "./expansions";
|
||||||
import type { RedirectionHost } from "./models";
|
import type { RedirectionHost } from "./models";
|
||||||
|
|
||||||
export type RedirectionHostExpansion = "owner" | "certificate";
|
export async function getRedirectionHosts(expand?: HostExpansion[], params = {}): Promise<RedirectionHost[]> {
|
||||||
export async function getRedirectionHosts(
|
|
||||||
expand?: RedirectionHostExpansion[],
|
|
||||||
params = {},
|
|
||||||
): Promise<RedirectionHost[]> {
|
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/redirection-hosts",
|
url: "/nginx/redirection-hosts",
|
||||||
params: {
|
params: {
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Setting } from "./models";
|
import type { Setting } from "./models";
|
||||||
|
|
||||||
export async function getSetting(id: string, abortController?: AbortController): Promise<Setting> {
|
export async function getSetting(id: string, expand?: string[], params = {}): Promise<Setting> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/settings/${id}`,
|
url: `/settings/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { HostExpansion } from "./expansions";
|
||||||
import type { Stream } from "./models";
|
import type { Stream } from "./models";
|
||||||
|
|
||||||
export async function getStream(id: number, abortController?: AbortController): Promise<Stream> {
|
export async function getStream(id: number, expand?: HostExpansion[], params = {}): Promise<Stream> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: `/nginx/streams/${id}`,
|
url: `/nginx/streams/${id}`,
|
||||||
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
abortController,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { HostExpansion } from "./expansions";
|
||||||
import type { Stream } from "./models";
|
import type { Stream } from "./models";
|
||||||
|
|
||||||
export type StreamExpansion = "owner" | "certificate";
|
export async function getStreams(expand?: HostExpansion[], params = {}): Promise<Stream[]> {
|
||||||
|
|
||||||
export async function getStreams(expand?: StreamExpansion[], params = {}): Promise<Stream[]> {
|
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/nginx/streams",
|
url: "/nginx/streams",
|
||||||
params: {
|
params: {
|
||||||
|
@@ -1,19 +1,9 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { TokenResponse } from "./responseTypes";
|
import type { TokenResponse } from "./responseTypes";
|
||||||
|
|
||||||
interface Options {
|
export async function getToken(identity: string, secret: string): Promise<TokenResponse> {
|
||||||
payload: {
|
return await api.post({
|
||||||
identity: string;
|
|
||||||
secret: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getToken({ payload }: Options, abortController?: AbortController): Promise<TokenResponse> {
|
|
||||||
return await api.post(
|
|
||||||
{
|
|
||||||
url: "/tokens",
|
url: "/tokens",
|
||||||
data: payload,
|
data: { identity, secret },
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,14 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { UserExpansion } from "./expansions";
|
||||||
import type { User } from "./models";
|
import type { User } from "./models";
|
||||||
|
|
||||||
export async function getUser(id: number | string = "me", params = {}): Promise<User> {
|
export async function getUser(id: number | string = "me", expand?: UserExpansion[], params = {}): Promise<User> {
|
||||||
const userId = id ? id : "me";
|
const userId = id ? id : "me";
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: `/users/${userId}`,
|
url: `/users/${userId}`,
|
||||||
params,
|
params: {
|
||||||
|
expand: expand?.join(","),
|
||||||
|
...params,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
import type { UserExpansion } from "./expansions";
|
||||||
import type { User } from "./models";
|
import type { User } from "./models";
|
||||||
|
|
||||||
export type UserExpansion = "permissions";
|
|
||||||
|
|
||||||
export async function getUsers(expand?: UserExpansion[], params = {}): Promise<User[]> {
|
export async function getUsers(expand?: UserExpansion[], params = {}): Promise<User[]> {
|
||||||
return await api.get({
|
return await api.get({
|
||||||
url: "/users",
|
url: "/users",
|
||||||
|
@@ -13,10 +13,13 @@ export * from "./deleteRedirectionHost";
|
|||||||
export * from "./deleteStream";
|
export * from "./deleteStream";
|
||||||
export * from "./deleteUser";
|
export * from "./deleteUser";
|
||||||
export * from "./downloadCertificate";
|
export * from "./downloadCertificate";
|
||||||
|
export * from "./expansions";
|
||||||
export * from "./getAccessList";
|
export * from "./getAccessList";
|
||||||
export * from "./getAccessLists";
|
export * from "./getAccessLists";
|
||||||
export * from "./getAuditLog";
|
export * from "./getAuditLog";
|
||||||
|
export * from "./getAuditLogs";
|
||||||
export * from "./getCertificate";
|
export * from "./getCertificate";
|
||||||
|
export * from "./getCertificateDNSProviders";
|
||||||
export * from "./getCertificates";
|
export * from "./getCertificates";
|
||||||
export * from "./getDeadHost";
|
export * from "./getDeadHost";
|
||||||
export * from "./getDeadHosts";
|
export * from "./getDeadHosts";
|
||||||
@@ -44,6 +47,7 @@ export * from "./toggleDeadHost";
|
|||||||
export * from "./toggleProxyHost";
|
export * from "./toggleProxyHost";
|
||||||
export * from "./toggleRedirectionHost";
|
export * from "./toggleRedirectionHost";
|
||||||
export * from "./toggleStream";
|
export * from "./toggleStream";
|
||||||
|
export * from "./toggleUser";
|
||||||
export * from "./updateAccessList";
|
export * from "./updateAccessList";
|
||||||
export * from "./updateAuth";
|
export * from "./updateAuth";
|
||||||
export * from "./updateDeadHost";
|
export * from "./updateDeadHost";
|
||||||
|
@@ -40,6 +40,8 @@ export interface AuditLog {
|
|||||||
objectId: number;
|
objectId: number;
|
||||||
action: string;
|
action: string;
|
||||||
meta: Record<string, any>;
|
meta: Record<string, any>;
|
||||||
|
// Expansions:
|
||||||
|
user?: User;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AccessList {
|
export interface AccessList {
|
||||||
@@ -51,7 +53,7 @@ export interface AccessList {
|
|||||||
meta: Record<string, any>;
|
meta: Record<string, any>;
|
||||||
satisfyAny: boolean;
|
satisfyAny: boolean;
|
||||||
passAuth: boolean;
|
passAuth: boolean;
|
||||||
proxyHostCount: number;
|
proxyHostCount?: number;
|
||||||
// Expansions:
|
// Expansions:
|
||||||
owner?: User;
|
owner?: User;
|
||||||
items?: AccessListItem[];
|
items?: AccessListItem[];
|
||||||
@@ -101,6 +103,7 @@ export interface ProxyHost {
|
|||||||
modifiedOn: string;
|
modifiedOn: string;
|
||||||
ownerUserId: number;
|
ownerUserId: number;
|
||||||
domainNames: string[];
|
domainNames: string[];
|
||||||
|
forwardScheme: string;
|
||||||
forwardHost: string;
|
forwardHost: string;
|
||||||
forwardPort: number;
|
forwardPort: number;
|
||||||
accessListId: number;
|
accessListId: number;
|
||||||
@@ -112,9 +115,8 @@ export interface ProxyHost {
|
|||||||
meta: Record<string, any>;
|
meta: Record<string, any>;
|
||||||
allowWebsocketUpgrade: boolean;
|
allowWebsocketUpgrade: boolean;
|
||||||
http2Support: boolean;
|
http2Support: boolean;
|
||||||
forwardScheme: string;
|
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
locations: string[]; // todo: string or object?
|
locations?: string[]; // todo: string or object?
|
||||||
hstsEnabled: boolean;
|
hstsEnabled: boolean;
|
||||||
hstsSubdomains: boolean;
|
hstsSubdomains: boolean;
|
||||||
// Expansions:
|
// Expansions:
|
||||||
@@ -191,3 +193,9 @@ export interface Setting {
|
|||||||
value: string;
|
value: string;
|
||||||
meta: Record<string, any>;
|
meta: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DNSProvider {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
credentials: string;
|
||||||
|
}
|
||||||
|
@@ -1,11 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { TokenResponse } from "./responseTypes";
|
import type { TokenResponse } from "./responseTypes";
|
||||||
|
|
||||||
export async function refreshToken(abortController?: AbortController): Promise<TokenResponse> {
|
export async function refreshToken(): Promise<TokenResponse> {
|
||||||
return await api.get(
|
return await api.get({
|
||||||
{
|
|
||||||
url: "/tokens",
|
url: "/tokens",
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,8 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Certificate } from "./models";
|
import type { Certificate } from "./models";
|
||||||
|
|
||||||
export async function renewCertificate(id: number, abortController?: AbortController): Promise<Certificate> {
|
export async function renewCertificate(id: number): Promise<Certificate> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: `/nginx/certificates/${id}/renew`,
|
url: `/nginx/certificates/${id}/renew`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { UserPermissions } from "./models";
|
import type { UserPermissions } from "./models";
|
||||||
|
|
||||||
export async function setPermissions(
|
export async function setPermissions(userId: number, data: UserPermissions): Promise<boolean> {
|
||||||
userId: number,
|
|
||||||
data: UserPermissions,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<boolean> {
|
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/users/${userId}/permissions`,
|
url: `/users/${userId}/permissions`,
|
||||||
data,
|
data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,10 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function testHttpCertificate(
|
export async function testHttpCertificate(domains: string[]): Promise<Record<string, string>> {
|
||||||
domains: string[],
|
return await api.get({
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<Record<string, string>> {
|
|
||||||
return await api.get(
|
|
||||||
{
|
|
||||||
url: "/nginx/certificates/test-http",
|
url: "/nginx/certificates/test-http",
|
||||||
params: {
|
params: {
|
||||||
domains: domains.join(","),
|
domains: domains.join(","),
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function toggleDeadHost(
|
export async function toggleDeadHost(id: number, enabled: boolean): Promise<boolean> {
|
||||||
id: number,
|
return await api.post({
|
||||||
enabled: boolean,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await api.post(
|
|
||||||
{
|
|
||||||
url: `/nginx/dead-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
url: `/nginx/dead-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function toggleProxyHost(
|
export async function toggleProxyHost(id: number, enabled: boolean): Promise<boolean> {
|
||||||
id: number,
|
return await api.post({
|
||||||
enabled: boolean,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await api.post(
|
|
||||||
{
|
|
||||||
url: `/nginx/proxy-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
url: `/nginx/proxy-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function toggleRedirectionHost(
|
export async function toggleRedirectionHost(id: number, enabled: boolean): Promise<boolean> {
|
||||||
id: number,
|
return await api.post({
|
||||||
enabled: boolean,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await api.post(
|
|
||||||
{
|
|
||||||
url: `/nginx/redirection-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
url: `/nginx/redirection-hosts/${id}/${enabled ? "enable" : "disable"}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
|
|
||||||
export async function toggleStream(id: number, enabled: boolean, abortController?: AbortController): Promise<boolean> {
|
export async function toggleStream(id: number, enabled: boolean): Promise<boolean> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: `/nginx/streams/${id}/${enabled ? "enable" : "disable"}`,
|
url: `/nginx/streams/${id}/${enabled ? "enable" : "disable"}`,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
10
frontend/src/api/backend/toggleUser.ts
Normal file
10
frontend/src/api/backend/toggleUser.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import type { User } from "./models";
|
||||||
|
import { updateUser } from "./updateUser";
|
||||||
|
|
||||||
|
export async function toggleUser(id: number, enabled: boolean): Promise<boolean> {
|
||||||
|
await updateUser({
|
||||||
|
id,
|
||||||
|
isDisabled: !enabled,
|
||||||
|
} as User);
|
||||||
|
return true;
|
||||||
|
}
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { AccessList } from "./models";
|
import type { AccessList } from "./models";
|
||||||
|
|
||||||
export async function updateAccessList(item: AccessList, abortController?: AbortController): Promise<AccessList> {
|
export async function updateAccessList(item: AccessList): Promise<AccessList> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/nginx/access-lists/${id}`,
|
url: `/nginx/access-lists/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,7 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { User } from "./models";
|
import type { User } from "./models";
|
||||||
|
|
||||||
export async function updateAuth(
|
export async function updateAuth(userId: number | "me", newPassword: string, current?: string): Promise<User> {
|
||||||
userId: number | "me",
|
|
||||||
newPassword: string,
|
|
||||||
current?: string,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<User> {
|
|
||||||
const data = {
|
const data = {
|
||||||
type: "password",
|
type: "password",
|
||||||
current: current,
|
current: current,
|
||||||
@@ -16,11 +11,8 @@ export async function updateAuth(
|
|||||||
data.current = current;
|
data.current = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/users/${userId}/auth`,
|
url: `/users/${userId}/auth`,
|
||||||
data,
|
data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { DeadHost } from "./models";
|
import type { DeadHost } from "./models";
|
||||||
|
|
||||||
export async function updateDeadHost(item: DeadHost, abortController?: AbortController): Promise<DeadHost> {
|
export async function updateDeadHost(item: DeadHost): Promise<DeadHost> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/nginx/dead-hosts/${id}`,
|
url: `/nginx/dead-hosts/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { ProxyHost } from "./models";
|
import type { ProxyHost } from "./models";
|
||||||
|
|
||||||
export async function updateProxyHost(item: ProxyHost, abortController?: AbortController): Promise<ProxyHost> {
|
export async function updateProxyHost(item: ProxyHost): Promise<ProxyHost> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/nginx/proxy-hosts/${id}`,
|
url: `/nginx/proxy-hosts/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { RedirectionHost } from "./models";
|
import type { RedirectionHost } from "./models";
|
||||||
|
|
||||||
export async function updateRedirectionHost(
|
export async function updateRedirectionHost(item: RedirectionHost): Promise<RedirectionHost> {
|
||||||
item: RedirectionHost,
|
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<RedirectionHost> {
|
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/nginx/redirection-hosts/${id}`,
|
url: `/nginx/redirection-hosts/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Setting } from "./models";
|
import type { Setting } from "./models";
|
||||||
|
|
||||||
export async function updateSetting(item: Setting, abortController?: AbortController): Promise<Setting> {
|
export async function updateSetting(item: Setting): Promise<Setting> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, ...data } = item;
|
const { id, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/settings/${id}`,
|
url: `/settings/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { Stream } from "./models";
|
import type { Stream } from "./models";
|
||||||
|
|
||||||
export async function updateStream(item: Stream, abortController?: AbortController): Promise<Stream> {
|
export async function updateStream(item: Stream): Promise<Stream> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/nginx/streams/${id}`,
|
url: `/nginx/streams/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
import * as api from "./base";
|
import * as api from "./base";
|
||||||
import type { User } from "./models";
|
import type { User } from "./models";
|
||||||
|
|
||||||
export async function updateUser(item: User, abortController?: AbortController): Promise<User> {
|
export async function updateUser(item: User): Promise<User> {
|
||||||
// Remove readonly fields
|
// Remove readonly fields
|
||||||
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
const { id, createdOn: _, modifiedOn: __, ...data } = item;
|
||||||
|
|
||||||
return await api.put(
|
return await api.put({
|
||||||
{
|
|
||||||
url: `/users/${id}`,
|
url: `/users/${id}`,
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -6,13 +6,9 @@ export async function uploadCertificate(
|
|||||||
certificate: string,
|
certificate: string,
|
||||||
certificateKey: string,
|
certificateKey: string,
|
||||||
intermediateCertificate?: string,
|
intermediateCertificate?: string,
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<Certificate> {
|
): Promise<Certificate> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: `/nginx/certificates/${id}/upload`,
|
url: `/nginx/certificates/${id}/upload`,
|
||||||
data: { certificate, certificateKey, intermediateCertificate },
|
data: { certificate, certificateKey, intermediateCertificate },
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -5,13 +5,9 @@ export async function validateCertificate(
|
|||||||
certificate: string,
|
certificate: string,
|
||||||
certificateKey: string,
|
certificateKey: string,
|
||||||
intermediateCertificate?: string,
|
intermediateCertificate?: string,
|
||||||
abortController?: AbortController,
|
|
||||||
): Promise<ValidatedCertificateResponse> {
|
): Promise<ValidatedCertificateResponse> {
|
||||||
return await api.post(
|
return await api.post({
|
||||||
{
|
|
||||||
url: "/nginx/certificates/validate",
|
url: "/nginx/certificates/validate",
|
||||||
data: { certificate, certificateKey, intermediateCertificate },
|
data: { certificate, certificateKey, intermediateCertificate },
|
||||||
},
|
});
|
||||||
abortController,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { intl } from "src/locale";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Button } from "src/components";
|
import { Button } from "src/components";
|
||||||
|
import { T } from "src/locale";
|
||||||
|
|
||||||
export function ErrorNotFound() {
|
export function ErrorNotFound() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -8,13 +8,15 @@ export function ErrorNotFound() {
|
|||||||
return (
|
return (
|
||||||
<div className="container-tight py-4">
|
<div className="container-tight py-4">
|
||||||
<div className="empty">
|
<div className="empty">
|
||||||
<p className="empty-title">{intl.formatMessage({ id: "notfound.title" })}</p>
|
<p className="empty-title">
|
||||||
|
<T id="notfound.title" />
|
||||||
|
</p>
|
||||||
<p className="empty-subtitle text-secondary">
|
<p className="empty-subtitle text-secondary">
|
||||||
{intl.formatMessage({ id: "notfound.text" })}
|
<T id="notfound.text" />
|
||||||
</p>
|
</p>
|
||||||
<div className="empty-action">
|
<div className="empty-action">
|
||||||
<Button type="button" size="md" onClick={() => navigate("/")}>
|
<Button type="button" size="md" onClick={() => navigate("/")}>
|
||||||
{intl.formatMessage({ id: "notfound.action" })}
|
<T id="notfound.action" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
99
frontend/src/components/Form/AccessField.tsx
Normal file
99
frontend/src/components/Form/AccessField.tsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { IconLock, IconLockOpen2 } from "@tabler/icons-react";
|
||||||
|
import { Field, useFormikContext } from "formik";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import Select, { type ActionMeta, components, type OptionProps } from "react-select";
|
||||||
|
import type { AccessList } from "src/api/backend";
|
||||||
|
import { useAccessLists } from "src/hooks";
|
||||||
|
import { DateTimeFormat, intl, T } from "src/locale";
|
||||||
|
|
||||||
|
interface AccessOption {
|
||||||
|
readonly value: number;
|
||||||
|
readonly label: string;
|
||||||
|
readonly subLabel: string;
|
||||||
|
readonly icon: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Option = (props: OptionProps<AccessOption>) => {
|
||||||
|
return (
|
||||||
|
<components.Option {...props}>
|
||||||
|
<div className="flex-fill">
|
||||||
|
<div className="font-weight-medium">
|
||||||
|
{props.data.icon} <strong>{props.data.label}</strong>
|
||||||
|
</div>
|
||||||
|
<div className="text-secondary mt-1 ps-3">{props.data.subLabel}</div>
|
||||||
|
</div>
|
||||||
|
</components.Option>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
export function AccessField({ name = "accessListId", label = "access.title", id = "accessListId" }: Props) {
|
||||||
|
const { isLoading, isError, error, data } = useAccessLists();
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
|
const handleChange = (newValue: any, _actionMeta: ActionMeta<AccessOption>) => {
|
||||||
|
setFieldValue(name, newValue?.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const options: AccessOption[] =
|
||||||
|
data?.map((item: AccessList) => ({
|
||||||
|
value: item.id || 0,
|
||||||
|
label: item.name,
|
||||||
|
subLabel: intl.formatMessage(
|
||||||
|
{ id: "access.subtitle" },
|
||||||
|
{
|
||||||
|
users: item?.items?.length,
|
||||||
|
rules: item?.clients?.length,
|
||||||
|
date: item?.createdOn ? DateTimeFormat(item?.createdOn) : "N/A",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
icon: <IconLock size={14} className="text-lime" />,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
|
// Public option
|
||||||
|
options?.unshift({
|
||||||
|
value: 0,
|
||||||
|
label: intl.formatMessage({ id: "access.public" }),
|
||||||
|
subLabel: "No basic auth required",
|
||||||
|
icon: <IconLockOpen2 size={14} className="text-red" />,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Field name={name}>
|
||||||
|
{({ field, form }: any) => (
|
||||||
|
<div className="mb-3">
|
||||||
|
<label className="form-label" htmlFor={id}>
|
||||||
|
<T id={label} />
|
||||||
|
</label>
|
||||||
|
{isLoading ? <div className="placeholder placeholder-lg col-12 my-3 placeholder-glow" /> : null}
|
||||||
|
{isError ? <div className="invalid-feedback">{`${error}`}</div> : null}
|
||||||
|
{!isLoading && !isError ? (
|
||||||
|
<Select
|
||||||
|
className="react-select-container"
|
||||||
|
classNamePrefix="react-select"
|
||||||
|
defaultValue={options.find((o) => o.value === field.value) || options[0]}
|
||||||
|
options={options}
|
||||||
|
components={{ Option }}
|
||||||
|
styles={{
|
||||||
|
option: (base) => ({
|
||||||
|
...base,
|
||||||
|
height: "100%",
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{form.errors[field.name] ? (
|
||||||
|
<div className="invalid-feedback">
|
||||||
|
{form.errors[field.name] && form.touched[field.name] ? form.errors[field.name] : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
);
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user