@theotherwillembotha/node-red-nginxproxymanager 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +156 -0
- package/build/GenerateNodes.js +14 -0
- package/build/Nodes.html +1386 -0
- package/build/Nodes.js +22 -0
- package/build/Plugins.js +70 -0
- package/build/icons/nginx.png +0 -0
- package/build/index.js +22 -0
- package/build/nginx/node/NginxGetHostsNode.js +63 -0
- package/build/nginx/node/NginxProxyManagerConfigNode.js +39 -0
- package/build/nginx/node/UpdateHostNode.js +61 -0
- package/build/nginx/service/NginxProxyManagerClient.js +50 -0
- package/build/nginx/service/NginxProxyManagerService.js +90 -0
- package/build/nginx/service/client/NginxClient.js +185 -0
- package/build/nginx/service/client/NginxHttpClient.js +95 -0
- package/build/nginx/service/client/types.js +3 -0
- package/icons/nginx.png +0 -0
- package/package.json +59 -0
package/build/Nodes.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
|
|
4
|
+
This file was automatically generated using the NODERED Core utility.
|
|
5
|
+
Any modifications to his file will be overwritten the next time the code is regenerated.
|
|
6
|
+
|
|
7
|
+
You have been warned.
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
const NodeManager = require("@theotherwillembotha/node-red-plugincore").NodeManager;
|
|
12
|
+
const NginxProxyManagerConfigNode = require("@theotherwillembotha/nodered_nginxproxymanager").NginxProxyManagerConfigNode;
|
|
13
|
+
const UpdateNginxHostNode = require("@theotherwillembotha/nodered_nginxproxymanager").UpdateNginxHostNode;
|
|
14
|
+
const NginxGetHostsNode = require("@theotherwillembotha/nodered_nginxproxymanager").NginxGetHostsNode;
|
|
15
|
+
module.exports = (RED) => {
|
|
16
|
+
let manager = new NodeManager(RED);
|
|
17
|
+
manager.registerNodeType("NginxProxyManagerConfigNode", NginxProxyManagerConfigNode);
|
|
18
|
+
manager.registerNodeType("UpdateNginxHostNode", UpdateNginxHostNode);
|
|
19
|
+
manager.registerNodeType("NginxGetHostsNode", NginxGetHostsNode);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
package/build/Plugins.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
|
|
4
|
+
This file was automatically generated using the NODERED Core utility.
|
|
5
|
+
Any modifications to his file will be overwritten the next time the code is regenerated.
|
|
6
|
+
|
|
7
|
+
You have been warned.
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
const runtime = require("node-red").runtime;
|
|
12
|
+
const NginxProxyManagerService = require("./nginx/service/NginxProxyManagerService").NginxProxyManagerService;
|
|
13
|
+
|
|
14
|
+
module.exports = function (RED) {
|
|
15
|
+
|
|
16
|
+
// 1. make a list of all the plugins that need to be installed.
|
|
17
|
+
let pluginList = [NginxProxyManagerService]
|
|
18
|
+
.map(service => service.getServiceDescriptor())
|
|
19
|
+
.filter(plugin => !RED.plugins.get(plugin.id()));
|
|
20
|
+
|
|
21
|
+
// 2. register a listener if there are any plugins in the pluginList.
|
|
22
|
+
if(pluginList.length > 0){
|
|
23
|
+
RED.events.on('registry:plugin-added', async pluginID => {
|
|
24
|
+
|
|
25
|
+
let addedPlugin = pluginList.find(plugin => plugin.id() === pluginID);
|
|
26
|
+
let plugin = RED.plugins.get(pluginID);
|
|
27
|
+
|
|
28
|
+
if(addedPlugin && plugin.instantiate && !plugin.instance){
|
|
29
|
+
console.log("Deploying instance of: " + plugin.id);
|
|
30
|
+
plugin.instance = new plugin.class();
|
|
31
|
+
|
|
32
|
+
// instantiate the plugin.
|
|
33
|
+
await plugin.instance.init(RED);
|
|
34
|
+
|
|
35
|
+
// publish an event that it has ben deployed.
|
|
36
|
+
RED.events.emit("plugin.instantiated", pluginID);
|
|
37
|
+
|
|
38
|
+
pluginList.splice(pluginList.findIndex(current => current.id() === addedPlugin.id()), 1);
|
|
39
|
+
|
|
40
|
+
// register a flow deployment listener.
|
|
41
|
+
let startupDeployment = true;
|
|
42
|
+
RED.events.on('runtime-event', async (event) => {
|
|
43
|
+
// startup deployment.
|
|
44
|
+
if ("runtime-deploy" === event?.id && startupDeployment) {
|
|
45
|
+
console.log("STARTUP DEPLOYMENT");
|
|
46
|
+
startupDeployment = false;
|
|
47
|
+
const flows = await runtime.flows.getFlows({});
|
|
48
|
+
await plugin.instance.onDeploy(flows);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// stopping flows on redeployment.
|
|
52
|
+
if ("runtime-state" === event?.id && event?.payload?.state === "stop" && event?.payload?.deploy) {
|
|
53
|
+
console.log("REDEPLOY!");
|
|
54
|
+
const flows = await runtime.flows.getFlows({});
|
|
55
|
+
await plugin.instance.onDeploy(flows);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 3. register the plugins.
|
|
63
|
+
[...pluginList].forEach(plugin => {
|
|
64
|
+
RED.plugins.registerPlugin(plugin.id(), {
|
|
65
|
+
type: plugin.type(),
|
|
66
|
+
instantiate:true,
|
|
67
|
+
class: plugin.clazz()
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
};
|
|
Binary file
|
package/build/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Services
|
|
18
|
+
__exportStar(require("./nginx/service/NginxProxyManagerService"), exports);
|
|
19
|
+
// Nodes
|
|
20
|
+
__exportStar(require("./nginx/node/NginxProxyManagerConfigNode"), exports);
|
|
21
|
+
__exportStar(require("./nginx/node/UpdateHostNode"), exports);
|
|
22
|
+
__exportStar(require("./nginx/node/NginxGetHostsNode"), exports);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NginxGetHostsNode = void 0;
|
|
13
|
+
const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
|
|
14
|
+
const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
|
|
15
|
+
const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
|
|
16
|
+
const NginxProxyManagerConfigNode_1 = require("./NginxProxyManagerConfigNode");
|
|
17
|
+
let NginxGetHostsNode = class NginxGetHostsNode extends node_red_plugincore_1.BaseNode {
|
|
18
|
+
constructor(node, config) {
|
|
19
|
+
super(node, config);
|
|
20
|
+
this._client = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.proxymanagerconfig).node().client();
|
|
21
|
+
}
|
|
22
|
+
async onInput(message, errorHandler) {
|
|
23
|
+
this.log.log(message);
|
|
24
|
+
this.counter.inc();
|
|
25
|
+
const hosts = await this._client.getHosts().catch(e => { errorHandler(e); return null; });
|
|
26
|
+
if (hosts === null)
|
|
27
|
+
return;
|
|
28
|
+
const outputPath = this.config().outputpath || "payload";
|
|
29
|
+
node_red_plugincore_1.NodeManager.RED.util.setMessageProperty(message, outputPath, hosts);
|
|
30
|
+
this.node().send(message);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.NginxGetHostsNode = NginxGetHostsNode;
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, node_red_plugincore_3.Logger)(),
|
|
36
|
+
__metadata("design:type", Object)
|
|
37
|
+
], NginxGetHostsNode.prototype, "log", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, node_red_plugincore_2.Metrics)({ name: "get_hosts_requests", type: node_red_plugincore_2.MetricType.Counter, description: "number of get hosts requests made" }),
|
|
40
|
+
__metadata("design:type", node_red_plugincore_2.CounterMetric)
|
|
41
|
+
], NginxGetHostsNode.prototype, "counter", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, node_red_plugincore_1.onInput)(),
|
|
44
|
+
__metadata("design:type", Function),
|
|
45
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
46
|
+
__metadata("design:returntype", Promise)
|
|
47
|
+
], NginxGetHostsNode.prototype, "onInput", null);
|
|
48
|
+
exports.NginxGetHostsNode = NginxGetHostsNode = __decorate([
|
|
49
|
+
(0, node_red_plugincore_1.NodeDescription)({
|
|
50
|
+
id: "NginxGetHostsNode",
|
|
51
|
+
name: "Nginx Get Hosts",
|
|
52
|
+
group: "nginxproxymanager",
|
|
53
|
+
sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "NginxGetHostsNode.html",
|
|
54
|
+
package: "@theotherwillembotha/nodered_nginxproxymanager",
|
|
55
|
+
templates: [
|
|
56
|
+
{ template: node_red_plugincore_3.LoggerTemplate, config: {} },
|
|
57
|
+
{ template: node_red_plugincore_2.MetricsTemplate, config: {} }
|
|
58
|
+
],
|
|
59
|
+
dependencies: [NginxProxyManagerConfigNode_1.NginxProxyManagerConfigNode],
|
|
60
|
+
tags: ["Nginx"]
|
|
61
|
+
}),
|
|
62
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
63
|
+
], NginxGetHostsNode);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NginxProxyManagerConfigNode = void 0;
|
|
13
|
+
const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
|
|
14
|
+
const NginxProxyManagerClient_1 = require("../service/NginxProxyManagerClient");
|
|
15
|
+
let NginxProxyManagerConfigNode = class NginxProxyManagerConfigNode extends node_red_plugincore_1.ConfigNode {
|
|
16
|
+
constructor(node, config) {
|
|
17
|
+
super(node, config);
|
|
18
|
+
let _this = this;
|
|
19
|
+
this._client = new NginxProxyManagerClient_1.NginxProxyManagerClient(config.url, config.email, config.password);
|
|
20
|
+
}
|
|
21
|
+
client() {
|
|
22
|
+
return this._client;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.NginxProxyManagerConfigNode = NginxProxyManagerConfigNode;
|
|
26
|
+
exports.NginxProxyManagerConfigNode = NginxProxyManagerConfigNode = __decorate([
|
|
27
|
+
(0, node_red_plugincore_1.NodeDescription)({
|
|
28
|
+
id: "NginxProxyManagerConfigNode",
|
|
29
|
+
name: "Nginx Proxy Manager Config",
|
|
30
|
+
group: "config",
|
|
31
|
+
sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "NginxProxyManagerConfigNode.html",
|
|
32
|
+
package: "@theotherwillembotha/nodered_nginxproxymanager",
|
|
33
|
+
tags: ["ReverseProxyType"],
|
|
34
|
+
templates: [
|
|
35
|
+
{ template: node_red_plugincore_1.UIHelperTemplate, config: {} }
|
|
36
|
+
]
|
|
37
|
+
}),
|
|
38
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
39
|
+
], NginxProxyManagerConfigNode);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UpdateNginxHostNode = void 0;
|
|
13
|
+
const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
|
|
14
|
+
const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
|
|
15
|
+
const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
|
|
16
|
+
const NginxProxyManagerConfigNode_1 = require("./NginxProxyManagerConfigNode");
|
|
17
|
+
let UpdateNginxHostNode = class UpdateNginxHostNode extends node_red_plugincore_1.BaseNode {
|
|
18
|
+
constructor(node, config) {
|
|
19
|
+
super(node, config);
|
|
20
|
+
let _this = this;
|
|
21
|
+
// get a reference to the NGINXPROXYMANAGER client.
|
|
22
|
+
this._client = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.proxymanagerconfig).node().client();
|
|
23
|
+
}
|
|
24
|
+
async onInput(message, errorHandler) {
|
|
25
|
+
this.log.log(message);
|
|
26
|
+
this.counter.inc();
|
|
27
|
+
await this._client.updateHost(message.payload).catch(e => errorHandler(e));
|
|
28
|
+
this.node().send(message);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.UpdateNginxHostNode = UpdateNginxHostNode;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, node_red_plugincore_3.Logger)(),
|
|
34
|
+
__metadata("design:type", Object)
|
|
35
|
+
], UpdateNginxHostNode.prototype, "log", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, node_red_plugincore_2.Metrics)({ name: "request", type: node_red_plugincore_2.MetricType.Counter, description: "number of requests made" }),
|
|
38
|
+
__metadata("design:type", node_red_plugincore_2.CounterMetric)
|
|
39
|
+
], UpdateNginxHostNode.prototype, "counter", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, node_red_plugincore_1.onInput)(),
|
|
42
|
+
__metadata("design:type", Function),
|
|
43
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
44
|
+
__metadata("design:returntype", Promise)
|
|
45
|
+
], UpdateNginxHostNode.prototype, "onInput", null);
|
|
46
|
+
exports.UpdateNginxHostNode = UpdateNginxHostNode = __decorate([
|
|
47
|
+
(0, node_red_plugincore_1.NodeDescription)({
|
|
48
|
+
id: "UpdateNginxHostNode",
|
|
49
|
+
name: "Update Nginx Host",
|
|
50
|
+
group: "nginxproxymanager",
|
|
51
|
+
sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "UpdateHostNode.html",
|
|
52
|
+
package: "@theotherwillembotha/nodered_nginxproxymanager",
|
|
53
|
+
templates: [
|
|
54
|
+
{ template: node_red_plugincore_3.LoggerTemplate, config: {} },
|
|
55
|
+
{ template: node_red_plugincore_2.MetricsTemplate, config: {} }
|
|
56
|
+
],
|
|
57
|
+
dependencies: [NginxProxyManagerConfigNode_1.NginxProxyManagerConfigNode],
|
|
58
|
+
tags: ["NiginX", "ReverseProxy"]
|
|
59
|
+
}),
|
|
60
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
61
|
+
], UpdateNginxHostNode);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NginxProxyManagerClient = void 0;
|
|
4
|
+
const NginxClient_1 = require("./client/NginxClient");
|
|
5
|
+
class NginxProxyManagerClient {
|
|
6
|
+
constructor(url, email, password) {
|
|
7
|
+
this._client = new NginxClient_1.NginxClient(url, email, password);
|
|
8
|
+
}
|
|
9
|
+
async updateHost(data) {
|
|
10
|
+
const payload = {};
|
|
11
|
+
if (data.domainNames !== undefined) {
|
|
12
|
+
payload.domain_names = data.domainNames;
|
|
13
|
+
}
|
|
14
|
+
if (data.scheme !== undefined) {
|
|
15
|
+
payload.forward_scheme = data.scheme;
|
|
16
|
+
}
|
|
17
|
+
if (data.forwardHost !== undefined) {
|
|
18
|
+
payload.forward_host = data.forwardHost;
|
|
19
|
+
}
|
|
20
|
+
if (data.forwardPort !== undefined) {
|
|
21
|
+
payload.forward_port = data.forwardPort;
|
|
22
|
+
}
|
|
23
|
+
if (data.cacheAssets !== undefined) {
|
|
24
|
+
payload.caching_enabled = data.cacheAssets;
|
|
25
|
+
}
|
|
26
|
+
if (data.blockCommonExploits !== undefined) {
|
|
27
|
+
payload.block_exploits = data.blockCommonExploits;
|
|
28
|
+
}
|
|
29
|
+
if (data.websocketSupport !== undefined) {
|
|
30
|
+
payload.allow_websocket_upgrade = data.websocketSupport;
|
|
31
|
+
}
|
|
32
|
+
if (data.id) {
|
|
33
|
+
await this._client.updateProxyHost(data.id, payload);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await this._client.createProxyHost(payload);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async getHosts() {
|
|
40
|
+
const hosts = await this._client.listProxyHosts();
|
|
41
|
+
return hosts.map(h => ({
|
|
42
|
+
id: h.id,
|
|
43
|
+
domainNames: h.domain_names,
|
|
44
|
+
scheme: h.forward_scheme,
|
|
45
|
+
forwardHost: h.forward_host,
|
|
46
|
+
forwardPort: h.forward_port,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.NginxProxyManagerClient = NginxProxyManagerClient;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NginxProxyManagerService = void 0;
|
|
4
|
+
const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
|
|
5
|
+
const NginxClient_1 = require("./client/NginxClient");
|
|
6
|
+
const NginxHttpClient_1 = require("./client/NginxHttpClient");
|
|
7
|
+
class NginxProxyManagerService extends node_red_plugincore_1.BaseService {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("NginxProxyManagerService");
|
|
10
|
+
}
|
|
11
|
+
init(red) {
|
|
12
|
+
console.log("STARTING: " + this.name());
|
|
13
|
+
this.red = red;
|
|
14
|
+
this.red.httpAdmin.post("/nginxproxymanagerservice/testconnection", this.red.auth.needsPermission("inject.write"), async (req, response) => {
|
|
15
|
+
const { url, username, password } = req.body.connection;
|
|
16
|
+
if (!url || !username || !password) {
|
|
17
|
+
response.status(400).send({ error: "url, username and password are required" });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const client = new NginxClient_1.NginxClient(url, username, password);
|
|
22
|
+
await client.testConnection();
|
|
23
|
+
response.status(200).send({ message: "Connection successful" });
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
if (e instanceof NginxHttpClient_1.NginxApiError) {
|
|
27
|
+
try {
|
|
28
|
+
let errorMessage = JSON.parse(e.apiMessage).error.message;
|
|
29
|
+
response.status(e.statusCode).send({ error: errorMessage });
|
|
30
|
+
}
|
|
31
|
+
catch (parseError) {
|
|
32
|
+
response.status(e.statusCode).send({ error: e.apiMessage });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
let errorMessage = e.message ?? "Unknown error";
|
|
37
|
+
if (errorMessage === "fetch failed") {
|
|
38
|
+
errorMessage = "Invalid URL / URL not reachable";
|
|
39
|
+
}
|
|
40
|
+
response.status(400).send({ error: errorMessage });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.red.httpAdmin.post("/nginxproxymanagerservice/hosts", this.red.auth.needsPermission("inject.write"), async (req, response) => {
|
|
45
|
+
const { url, username, password } = req.body.connection;
|
|
46
|
+
if (!url || !username || !password) {
|
|
47
|
+
response.status(400).send({ error: "url, username and password are required" });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const client = new NginxClient_1.NginxClient(url, username, password);
|
|
52
|
+
const raw = await client.listProxyHosts();
|
|
53
|
+
const proxyHosts = raw.map(h => ({
|
|
54
|
+
id: h.id,
|
|
55
|
+
domain_names: h.domain_names,
|
|
56
|
+
forward_host: h.forward_host,
|
|
57
|
+
forward_port: h.forward_port,
|
|
58
|
+
forward_scheme: h.forward_scheme,
|
|
59
|
+
enabled: h.enabled,
|
|
60
|
+
}));
|
|
61
|
+
response.status(200).send({ hosts: { proxyHosts } });
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (e instanceof NginxHttpClient_1.NginxApiError) {
|
|
65
|
+
try {
|
|
66
|
+
const errorMessage = JSON.parse(e.apiMessage).error.message;
|
|
67
|
+
response.status(e.statusCode).send({ error: errorMessage });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
response.status(e.statusCode).send({ error: e.apiMessage });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
let errorMessage = e.message ?? "Unknown error";
|
|
75
|
+
if (errorMessage === "fetch failed") {
|
|
76
|
+
errorMessage = "Invalid URL / URL not reachable";
|
|
77
|
+
}
|
|
78
|
+
response.status(400).send({ error: errorMessage });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
deinit(red) {
|
|
84
|
+
console.log("STOPPING SERVICE: " + this.name());
|
|
85
|
+
}
|
|
86
|
+
static getServiceDescriptor() {
|
|
87
|
+
return new node_red_plugincore_1.ServiceDescriptor("@theotherwillembotha/nginxproxymanagerservice", "NginxProxyManagerService", "integration-plugin", "./nginx/service/NginxProxyManagerService", NginxProxyManagerService);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.NginxProxyManagerService = NginxProxyManagerService;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NginxClient = void 0;
|
|
4
|
+
const NginxHttpClient_1 = require("./NginxHttpClient");
|
|
5
|
+
/**
|
|
6
|
+
* High-level Nginx Proxy Manager API client.
|
|
7
|
+
* Covers all resources exposed by the NPM REST API.
|
|
8
|
+
*/
|
|
9
|
+
class NginxClient {
|
|
10
|
+
constructor(baseUrl, email, password) {
|
|
11
|
+
this.http = new NginxHttpClient_1.NginxHttpClient(baseUrl, email, password);
|
|
12
|
+
}
|
|
13
|
+
// ─── Proxy Hosts ──────────────────────────────────────────────────────────
|
|
14
|
+
listProxyHosts() {
|
|
15
|
+
return this.http.get("/nginx/proxy-hosts");
|
|
16
|
+
}
|
|
17
|
+
getProxyHost(id) {
|
|
18
|
+
return this.http.get(`/nginx/proxy-hosts/${id}`);
|
|
19
|
+
}
|
|
20
|
+
createProxyHost(data) {
|
|
21
|
+
return this.http.post("/nginx/proxy-hosts", data);
|
|
22
|
+
}
|
|
23
|
+
updateProxyHost(id, data) {
|
|
24
|
+
return this.http.put(`/nginx/proxy-hosts/${id}`, data);
|
|
25
|
+
}
|
|
26
|
+
deleteProxyHost(id) {
|
|
27
|
+
return this.http.delete(`/nginx/proxy-hosts/${id}`);
|
|
28
|
+
}
|
|
29
|
+
enableProxyHost(id) {
|
|
30
|
+
return this.http.post(`/nginx/proxy-hosts/${id}/enable`);
|
|
31
|
+
}
|
|
32
|
+
disableProxyHost(id) {
|
|
33
|
+
return this.http.post(`/nginx/proxy-hosts/${id}/disable`);
|
|
34
|
+
}
|
|
35
|
+
// ─── Access Lists ─────────────────────────────────────────────────────────
|
|
36
|
+
listAccessLists() {
|
|
37
|
+
return this.http.get("/nginx/access-lists");
|
|
38
|
+
}
|
|
39
|
+
getAccessList(id) {
|
|
40
|
+
return this.http.get(`/nginx/access-lists/${id}`);
|
|
41
|
+
}
|
|
42
|
+
createAccessList(data) {
|
|
43
|
+
return this.http.post("/nginx/access-lists", data);
|
|
44
|
+
}
|
|
45
|
+
updateAccessList(id, data) {
|
|
46
|
+
return this.http.put(`/nginx/access-lists/${id}`, data);
|
|
47
|
+
}
|
|
48
|
+
deleteAccessList(id) {
|
|
49
|
+
return this.http.delete(`/nginx/access-lists/${id}`);
|
|
50
|
+
}
|
|
51
|
+
// ─── Certificates ─────────────────────────────────────────────────────────
|
|
52
|
+
listCertificates() {
|
|
53
|
+
return this.http.get("/nginx/certificates");
|
|
54
|
+
}
|
|
55
|
+
getCertificate(id) {
|
|
56
|
+
return this.http.get(`/nginx/certificates/${id}`);
|
|
57
|
+
}
|
|
58
|
+
createCertificate(data) {
|
|
59
|
+
return this.http.post("/nginx/certificates", data);
|
|
60
|
+
}
|
|
61
|
+
deleteCertificate(id) {
|
|
62
|
+
return this.http.delete(`/nginx/certificates/${id}`);
|
|
63
|
+
}
|
|
64
|
+
renewCertificate(id) {
|
|
65
|
+
return this.http.post(`/nginx/certificates/${id}/renew`);
|
|
66
|
+
}
|
|
67
|
+
validateCertificate(data) {
|
|
68
|
+
return this.http.post("/nginx/certificates/validate", data);
|
|
69
|
+
}
|
|
70
|
+
listDnsProviders() {
|
|
71
|
+
return this.http.get("/nginx/certificates/dns-providers");
|
|
72
|
+
}
|
|
73
|
+
// ─── Redirection Hosts ────────────────────────────────────────────────────
|
|
74
|
+
listRedirectionHosts() {
|
|
75
|
+
return this.http.get("/nginx/redirection-hosts");
|
|
76
|
+
}
|
|
77
|
+
getRedirectionHost(id) {
|
|
78
|
+
return this.http.get(`/nginx/redirection-hosts/${id}`);
|
|
79
|
+
}
|
|
80
|
+
createRedirectionHost(data) {
|
|
81
|
+
return this.http.post("/nginx/redirection-hosts", data);
|
|
82
|
+
}
|
|
83
|
+
updateRedirectionHost(id, data) {
|
|
84
|
+
return this.http.put(`/nginx/redirection-hosts/${id}`, data);
|
|
85
|
+
}
|
|
86
|
+
deleteRedirectionHost(id) {
|
|
87
|
+
return this.http.delete(`/nginx/redirection-hosts/${id}`);
|
|
88
|
+
}
|
|
89
|
+
enableRedirectionHost(id) {
|
|
90
|
+
return this.http.post(`/nginx/redirection-hosts/${id}/enable`);
|
|
91
|
+
}
|
|
92
|
+
disableRedirectionHost(id) {
|
|
93
|
+
return this.http.post(`/nginx/redirection-hosts/${id}/disable`);
|
|
94
|
+
}
|
|
95
|
+
// ─── Dead Hosts (404) ─────────────────────────────────────────────────────
|
|
96
|
+
listDeadHosts() {
|
|
97
|
+
return this.http.get("/nginx/dead-hosts");
|
|
98
|
+
}
|
|
99
|
+
getDeadHost(id) {
|
|
100
|
+
return this.http.get(`/nginx/dead-hosts/${id}`);
|
|
101
|
+
}
|
|
102
|
+
createDeadHost(data) {
|
|
103
|
+
return this.http.post("/nginx/dead-hosts", data);
|
|
104
|
+
}
|
|
105
|
+
updateDeadHost(id, data) {
|
|
106
|
+
return this.http.put(`/nginx/dead-hosts/${id}`, data);
|
|
107
|
+
}
|
|
108
|
+
deleteDeadHost(id) {
|
|
109
|
+
return this.http.delete(`/nginx/dead-hosts/${id}`);
|
|
110
|
+
}
|
|
111
|
+
enableDeadHost(id) {
|
|
112
|
+
return this.http.post(`/nginx/dead-hosts/${id}/enable`);
|
|
113
|
+
}
|
|
114
|
+
disableDeadHost(id) {
|
|
115
|
+
return this.http.post(`/nginx/dead-hosts/${id}/disable`);
|
|
116
|
+
}
|
|
117
|
+
// ─── Streams ──────────────────────────────────────────────────────────────
|
|
118
|
+
listStreams() {
|
|
119
|
+
return this.http.get("/nginx/streams");
|
|
120
|
+
}
|
|
121
|
+
getStream(id) {
|
|
122
|
+
return this.http.get(`/nginx/streams/${id}`);
|
|
123
|
+
}
|
|
124
|
+
createStream(data) {
|
|
125
|
+
return this.http.post("/nginx/streams", data);
|
|
126
|
+
}
|
|
127
|
+
updateStream(id, data) {
|
|
128
|
+
return this.http.put(`/nginx/streams/${id}`, data);
|
|
129
|
+
}
|
|
130
|
+
deleteStream(id) {
|
|
131
|
+
return this.http.delete(`/nginx/streams/${id}`);
|
|
132
|
+
}
|
|
133
|
+
enableStream(id) {
|
|
134
|
+
return this.http.post(`/nginx/streams/${id}/enable`);
|
|
135
|
+
}
|
|
136
|
+
disableStream(id) {
|
|
137
|
+
return this.http.post(`/nginx/streams/${id}/disable`);
|
|
138
|
+
}
|
|
139
|
+
// ─── Users ────────────────────────────────────────────────────────────────
|
|
140
|
+
listUsers() {
|
|
141
|
+
return this.http.get("/users");
|
|
142
|
+
}
|
|
143
|
+
getUser(id) {
|
|
144
|
+
return this.http.get(`/users/${id}`);
|
|
145
|
+
}
|
|
146
|
+
createUser(data) {
|
|
147
|
+
return this.http.post("/users", data);
|
|
148
|
+
}
|
|
149
|
+
updateUser(id, data) {
|
|
150
|
+
return this.http.put(`/users/${id}`, data);
|
|
151
|
+
}
|
|
152
|
+
deleteUser(id) {
|
|
153
|
+
return this.http.delete(`/users/${id}`);
|
|
154
|
+
}
|
|
155
|
+
// ─── Settings ─────────────────────────────────────────────────────────────
|
|
156
|
+
listSettings() {
|
|
157
|
+
return this.http.get("/settings");
|
|
158
|
+
}
|
|
159
|
+
getSetting(id) {
|
|
160
|
+
return this.http.get(`/settings/${id}`);
|
|
161
|
+
}
|
|
162
|
+
updateSetting(id, value) {
|
|
163
|
+
return this.http.put(`/settings/${id}`, { value });
|
|
164
|
+
}
|
|
165
|
+
// ─── Reports ──────────────────────────────────────────────────────────────
|
|
166
|
+
getHostReport() {
|
|
167
|
+
return this.http.get("/reports/hosts");
|
|
168
|
+
}
|
|
169
|
+
// ─── Audit Log ────────────────────────────────────────────────────────────
|
|
170
|
+
listAuditLog() {
|
|
171
|
+
return this.http.get("/audit-log");
|
|
172
|
+
}
|
|
173
|
+
getAuditLogEntry(id) {
|
|
174
|
+
return this.http.get(`/audit-log/${id}`);
|
|
175
|
+
}
|
|
176
|
+
// ─── Connection test ──────────────────────────────────────────────────────
|
|
177
|
+
/**
|
|
178
|
+
* Verifies credentials by authenticating against the NPM API.
|
|
179
|
+
* Resolves on success, rejects with NginxApiError on failure.
|
|
180
|
+
*/
|
|
181
|
+
async testConnection() {
|
|
182
|
+
await this.http.get("/");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.NginxClient = NginxClient;
|