node-opcua-samples 2.71.0 → 2.72.2
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/bin/di_server.js +10 -10
- package/bin/mini_server.ts +4 -2
- package/bin/server_with_push_certificate.ts +48 -20
- package/bin/simple_secure_server.ts +20 -9
- package/bin/simple_server.js +19 -17
- package/dist/get_endpoints.d.ts +2 -2
- package/dist/get_endpoints.js +141 -141
- package/dist/mini_server.d.ts +1 -1
- package/dist/mini_server.js +88 -88
- package/dist/mini_server.js.map +1 -1
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +111 -82
- package/dist/server_with_push_certificate.js.map +1 -1
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +660 -660
- package/dist/simple_findservers.d.ts +2 -2
- package/dist/simple_findservers.js +48 -48
- package/dist/simple_secure_server.d.ts +2 -2
- package/dist/simple_secure_server.js +125 -121
- package/dist/simple_secure_server.js.map +1 -1
- package/dist/simple_server_with_custom_extension_objects.d.ts +2 -2
- package/dist/simple_server_with_custom_extension_objects.js +81 -81
- package/dist/stressing_client.d.ts +1 -1
- package/dist/stressing_client.js +36 -36
- package/package.json +4 -4
package/bin/di_server.js
CHANGED
|
@@ -61,7 +61,11 @@ const keySize = argv.keySize;
|
|
|
61
61
|
const server_certificate_file = constructFilename("certificates/server_selfsigned_cert_" + keySize + ".pem");
|
|
62
62
|
const server_certificate_privatekey_file = constructFilename("certificates/server_key_" + keySize + ".pem");
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const server = new OPCUAServer({
|
|
67
|
+
|
|
68
|
+
alternateHostname: argv.alternateHostname,
|
|
65
69
|
|
|
66
70
|
certificateFile: server_certificate_file,
|
|
67
71
|
privateKeyFile: server_certificate_privatekey_file,
|
|
@@ -69,8 +73,6 @@ const server_options = {
|
|
|
69
73
|
port,
|
|
70
74
|
resourcePath: "/UA/Server",
|
|
71
75
|
|
|
72
|
-
maxAllowedSessionNumber: 1500,
|
|
73
|
-
|
|
74
76
|
nodeset_filename: [
|
|
75
77
|
nodesets.standard,
|
|
76
78
|
nodesets.di,
|
|
@@ -89,22 +91,20 @@ const server_options = {
|
|
|
89
91
|
buildNumber: "1234"
|
|
90
92
|
},
|
|
91
93
|
serverCapabilities: {
|
|
94
|
+
maxSessions: 1500,
|
|
92
95
|
operationLimits: {
|
|
93
96
|
maxNodesPerRead: 1000,
|
|
94
97
|
maxNodesPerBrowse: 2000
|
|
95
98
|
}
|
|
96
99
|
},
|
|
100
|
+
maxConnectionsPerEndpoint: 1500,
|
|
101
|
+
|
|
97
102
|
userManager: userManager,
|
|
98
103
|
registerServerMethod: opcua.RegisterServerMethod.LDS,
|
|
99
104
|
discoveryServerEndpointUrl: argv.discoveryServerEndpointUrl || "opc.tcp://" + require("os").hostname() + ":4840"
|
|
105
|
+
});
|
|
100
106
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
process.title = "Node OPCUA Server on port : " + server_options.port;
|
|
104
|
-
|
|
105
|
-
server_options.alternateHostname = argv.alternateHostname;
|
|
106
|
-
|
|
107
|
-
const server = new OPCUAServer(server_options);
|
|
107
|
+
process.title = "Node OPCUA Server on port : " + port;
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
const hostname = os.hostname();
|
package/bin/mini_server.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
import * as chalk from "chalk";
|
|
3
2
|
import * as path from "path";
|
|
4
3
|
import * as os from "os";
|
|
5
4
|
|
|
5
|
+
import * as chalk from "chalk";
|
|
6
|
+
|
|
6
7
|
import {
|
|
7
8
|
makeApplicationUrn,
|
|
8
9
|
get_mini_nodeset_filename,
|
|
@@ -27,7 +28,6 @@ const serverOptions: OPCUAServerOptions = {
|
|
|
27
28
|
|
|
28
29
|
port,
|
|
29
30
|
|
|
30
|
-
maxAllowedSessionNumber: 2,
|
|
31
31
|
maxConnectionsPerEndpoint: 2,
|
|
32
32
|
|
|
33
33
|
nodeset_filename: [get_mini_nodeset_filename()],
|
|
@@ -49,6 +49,8 @@ const serverOptions: OPCUAServerOptions = {
|
|
|
49
49
|
},
|
|
50
50
|
|
|
51
51
|
serverCapabilities: {
|
|
52
|
+
maxSessions: 10,
|
|
53
|
+
|
|
52
54
|
maxBrowseContinuationPoints: 10,
|
|
53
55
|
maxHistoryContinuationPoints: 10,
|
|
54
56
|
// maxInactiveLockTime
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import * as chalk from "chalk";
|
|
6
6
|
|
|
7
|
-
import { nodesets, OPCUACertificateManager, OPCUAServer } from "node-opcua";
|
|
7
|
+
import { makeRoles, nodesets, OPCUACertificateManager, OPCUAServer, OPCUAServerOptions, WellKnownRoles } from "node-opcua";
|
|
8
8
|
import { CertificateManager } from "node-opcua-pki";
|
|
9
9
|
import { installPushCertificateManagement } from "node-opcua-server-configuration";
|
|
10
10
|
import * as yargs from "yargs";
|
|
@@ -21,27 +21,57 @@ const certificateManager = new OPCUACertificateManager({
|
|
|
21
21
|
rootFolder: pkiFolder
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
const users = [
|
|
25
|
+
{
|
|
26
|
+
username: "user1",
|
|
27
|
+
password: "password1",
|
|
28
|
+
role: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.ConfigureAdmin, WellKnownRoles.SecurityAdmin])
|
|
29
|
+
},
|
|
30
|
+
{ username: "user2", password: "password2", role: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.Operator]) }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const userManager = {
|
|
34
|
+
isValidUser(username: string, password: string) {
|
|
35
|
+
const uIndex = users.findIndex((x) => x.username === username);
|
|
36
|
+
if (uIndex < 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (users[uIndex].password !== password) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
getUserRoles(username: string) {
|
|
45
|
+
const uIndex = users.findIndex((x) => x.username === username);
|
|
46
|
+
if (uIndex < 0) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const userRole = users[uIndex].role;
|
|
50
|
+
return userRole;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
24
53
|
|
|
25
54
|
async function main() {
|
|
26
|
-
|
|
27
55
|
const argv = await yargs.wrap(132).option("port", {
|
|
28
56
|
alias: "p",
|
|
29
57
|
default: "26543",
|
|
30
58
|
describe: "port to listen"
|
|
31
59
|
}).argv;
|
|
32
60
|
|
|
33
|
-
|
|
34
61
|
const port = parseInt(argv.port, 10) || 26555;
|
|
35
62
|
|
|
36
|
-
const
|
|
63
|
+
const serverOptions: OPCUAServerOptions = {
|
|
37
64
|
port,
|
|
38
65
|
|
|
39
66
|
nodeset_filename: [nodesets.standard],
|
|
40
67
|
|
|
41
|
-
serverCertificateManager: certificateManager
|
|
68
|
+
serverCertificateManager: certificateManager,
|
|
69
|
+
userCertificateManager: certificateManager,
|
|
70
|
+
|
|
71
|
+
userManager
|
|
42
72
|
};
|
|
43
73
|
|
|
44
|
-
process.title = "Node OPCUA Server on port : " +
|
|
74
|
+
process.title = "Node OPCUA Server on port : " + serverOptions.port;
|
|
45
75
|
const tmpFolder = path.join(__dirname, "../certificates/myApp");
|
|
46
76
|
|
|
47
77
|
const applicationGroup = new CertificateManager({
|
|
@@ -49,27 +79,25 @@ async function main() {
|
|
|
49
79
|
});
|
|
50
80
|
await applicationGroup.initialize();
|
|
51
81
|
|
|
52
|
-
const server = new OPCUAServer(
|
|
82
|
+
const server = new OPCUAServer(serverOptions);
|
|
53
83
|
|
|
54
84
|
console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
|
|
55
|
-
|
|
56
85
|
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
57
86
|
|
|
58
|
-
server.
|
|
59
|
-
const addressSpace = server.engine.addressSpace!;
|
|
60
|
-
// to do: expose new nodeid here
|
|
61
|
-
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
62
|
-
|
|
63
|
-
await installPushCertificateManagement(addressSpace, {
|
|
64
|
-
applicationGroup: server.serverCertificateManager,
|
|
65
|
-
userTokenGroup: server.userCertificateManager,
|
|
87
|
+
await server.initialize();
|
|
66
88
|
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
const addressSpace = server.engine.addressSpace!;
|
|
90
|
+
// to do: expose new nodeid here
|
|
91
|
+
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
69
92
|
|
|
70
|
-
|
|
93
|
+
await installPushCertificateManagement(addressSpace, {
|
|
94
|
+
applicationGroup: server.serverCertificateManager,
|
|
95
|
+
userTokenGroup: server.userCertificateManager,
|
|
96
|
+
applicationUri: server.serverInfo.applicationUri!
|
|
71
97
|
});
|
|
72
98
|
|
|
99
|
+
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
|
|
100
|
+
|
|
73
101
|
try {
|
|
74
102
|
await server.start();
|
|
75
103
|
} catch (err) {
|
|
@@ -83,7 +111,7 @@ async function main() {
|
|
|
83
111
|
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
84
112
|
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
85
113
|
|
|
86
|
-
process.
|
|
114
|
+
process.once("SIGINT", async () => {
|
|
87
115
|
// only work on linux apparently
|
|
88
116
|
await server.shutdown(1000);
|
|
89
117
|
console.log(chalk.red.bold(" shutting down completed "));
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
2
|
/* eslint no-process-exit: 0 */
|
|
3
3
|
// tslint:disable:no-console
|
|
4
|
-
import * as chalk from "chalk";
|
|
5
4
|
import * as path from "path";
|
|
6
|
-
import * as yargs from "yargs";
|
|
7
5
|
import * as os from "os";
|
|
8
6
|
|
|
9
|
-
import
|
|
7
|
+
import * as chalk from "chalk";
|
|
8
|
+
import * as yargs from "yargs";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
makeApplicationUrn,
|
|
12
|
+
MessageSecurityMode,
|
|
13
|
+
nodesets,
|
|
14
|
+
OPCUAServer,
|
|
15
|
+
OPCUAServerOptions,
|
|
16
|
+
SecurityPolicy,
|
|
17
|
+
ServerSession
|
|
18
|
+
} from "node-opcua";
|
|
10
19
|
|
|
11
20
|
Error.stackTraceLimit = Infinity;
|
|
12
21
|
|
|
@@ -26,9 +35,7 @@ const userManager = {
|
|
|
26
35
|
}
|
|
27
36
|
};
|
|
28
37
|
|
|
29
|
-
|
|
30
38
|
async function main() {
|
|
31
|
-
|
|
32
39
|
const argv = await yargs(process.argv)
|
|
33
40
|
.wrap(132)
|
|
34
41
|
|
|
@@ -47,17 +54,16 @@ async function main() {
|
|
|
47
54
|
default: false,
|
|
48
55
|
describe: "silent - no trace"
|
|
49
56
|
})
|
|
50
|
-
.option("
|
|
57
|
+
.option("maxSessions", {
|
|
51
58
|
alias: "m",
|
|
52
59
|
default: 10
|
|
53
60
|
})
|
|
54
61
|
.help(true).argv;
|
|
55
62
|
|
|
56
|
-
|
|
57
63
|
const port = argv.port || 26543;
|
|
58
64
|
// server_options.alternateHostname = argv.alternateHostname;
|
|
59
65
|
|
|
60
|
-
const server_options = {
|
|
66
|
+
const server_options: OPCUAServerOptions = {
|
|
61
67
|
securityPolicies: [SecurityPolicy.Basic128Rsa15, SecurityPolicy.Basic256],
|
|
62
68
|
|
|
63
69
|
securityModes: [MessageSecurityMode.Sign, MessageSecurityMode.SignAndEncrypt],
|
|
@@ -81,6 +87,12 @@ async function main() {
|
|
|
81
87
|
buildNumber: "1234"
|
|
82
88
|
},
|
|
83
89
|
|
|
90
|
+
serverCapabilities: {
|
|
91
|
+
maxSessions: argv.maxSessions
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
maxConnectionsPerEndpoint: argv.maxSessions,
|
|
95
|
+
|
|
84
96
|
userManager,
|
|
85
97
|
|
|
86
98
|
isAuditing: false
|
|
@@ -88,7 +100,6 @@ async function main() {
|
|
|
88
100
|
|
|
89
101
|
process.title = "Node OPCUA Server on port : " + server_options.port;
|
|
90
102
|
|
|
91
|
-
|
|
92
103
|
const server = new OPCUAServer(server_options);
|
|
93
104
|
|
|
94
105
|
server.on("post_initialize", () => {
|
package/bin/simple_server.js
CHANGED
|
@@ -39,12 +39,12 @@ const argv = yargs(process.argv)
|
|
|
39
39
|
.number("port")
|
|
40
40
|
.default("port", 26543)
|
|
41
41
|
|
|
42
|
-
.number("
|
|
43
|
-
.describe("
|
|
44
|
-
.default("
|
|
42
|
+
.number("maxSessions")
|
|
43
|
+
.describe("maxSessions", "the maximum number of concurrent client session that the server will accept")
|
|
44
|
+
.default("maxSessions", 500)
|
|
45
45
|
|
|
46
|
-
.number("
|
|
47
|
-
.describe("
|
|
46
|
+
.number("maxSubscriptionsPerSession")
|
|
47
|
+
.describe("maxSubscriptionsPerSession", "the maximum number of concurrent subscriptions per session")
|
|
48
48
|
|
|
49
49
|
.boolean("silent")
|
|
50
50
|
.default("silent", false)
|
|
@@ -63,17 +63,16 @@ const argv = yargs(process.argv)
|
|
|
63
63
|
.default("applicationName", "NodeOPCUA-Server")
|
|
64
64
|
|
|
65
65
|
.alias("a", "alternateHostname")
|
|
66
|
-
.alias("m", "
|
|
66
|
+
.alias("m", "maxSessions")
|
|
67
67
|
.alias("n", "applicationName")
|
|
68
68
|
.alias("p", "port")
|
|
69
69
|
|
|
70
70
|
.help(true).argv;
|
|
71
71
|
|
|
72
72
|
const port = argv.port;
|
|
73
|
-
const
|
|
74
|
-
const maxConnectionsPerEndpoint =
|
|
75
|
-
const
|
|
76
|
-
OPCUAServer.MAX_SUBSCRIPTION = maxAllowedSubscriptionNumber;
|
|
73
|
+
const maxSessions = argv.maxSessions;
|
|
74
|
+
const maxConnectionsPerEndpoint = maxSessions;
|
|
75
|
+
const maxSubscriptionsPerSession = argv.maxSubscriptionsPerSession || 50;
|
|
77
76
|
|
|
78
77
|
async function getIpAddresses() {
|
|
79
78
|
const ipAddresses = [];
|
|
@@ -122,12 +121,12 @@ const userManager = {
|
|
|
122
121
|
return true;
|
|
123
122
|
},
|
|
124
123
|
getUserRoles(username) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
const uIndex = users.findIndex((x) => x.username === username);
|
|
125
|
+
if (uIndex < 0) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const userRole = users[uIndex].role;
|
|
129
|
+
return userRole;
|
|
131
130
|
}
|
|
132
131
|
};
|
|
133
132
|
|
|
@@ -187,7 +186,6 @@ const paths = envPaths(productUri);
|
|
|
187
186
|
|
|
188
187
|
port,
|
|
189
188
|
|
|
190
|
-
maxAllowedSessionNumber: maxAllowedSessionNumber,
|
|
191
189
|
maxConnectionsPerEndpoint: maxConnectionsPerEndpoint,
|
|
192
190
|
|
|
193
191
|
nodeset_filename: [nodesets.standard, nodesets.di],
|
|
@@ -204,6 +202,10 @@ const paths = envPaths(productUri);
|
|
|
204
202
|
buildNumber: "1234"
|
|
205
203
|
},
|
|
206
204
|
serverCapabilities: {
|
|
205
|
+
maxSessions,
|
|
206
|
+
maxSubscriptionsPerSession,
|
|
207
|
+
maxSubscription: maxSessions * maxSubscriptionsPerSession,
|
|
208
|
+
|
|
207
209
|
maxBrowseContinuationPoints: 10,
|
|
208
210
|
maxHistoryContinuationPoints: 10,
|
|
209
211
|
// maxInactiveLockTime
|
package/dist/get_endpoints.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
export {};
|
package/dist/get_endpoints.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
// tslint:disable:no-console
|
|
14
|
-
const chalk = require("chalk");
|
|
15
|
-
const fs = require("fs");
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const yargs = require("yargs");
|
|
18
|
-
const node_opcua_1 = require("node-opcua");
|
|
19
|
-
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
20
|
-
// tslint:disable:no-var-requires
|
|
21
|
-
const Table = require("easy-table");
|
|
22
|
-
const treeify = require("treeify");
|
|
23
|
-
// eslint-disable-next-line max-statements
|
|
24
|
-
function main() {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
// ts-node bin/simple_client.ts --endpoint opc.tcp://localhost:53530/OPCUA/SimulationServer --node "ns=5;s=Sinusoid1"
|
|
27
|
-
const argv = yield yargs(process.argv)
|
|
28
|
-
.wrap(132)
|
|
29
|
-
.option("endpoint", {
|
|
30
|
-
alias: "e",
|
|
31
|
-
demandOption: true,
|
|
32
|
-
describe: "the end point to connect to "
|
|
33
|
-
})
|
|
34
|
-
.option("securityMode", {
|
|
35
|
-
alias: "s",
|
|
36
|
-
default: "None",
|
|
37
|
-
describe: "the security mode ( None Sign SignAndEncrypt )"
|
|
38
|
-
})
|
|
39
|
-
.option("securityPolicy", {
|
|
40
|
-
alias: "P",
|
|
41
|
-
default: "None",
|
|
42
|
-
describe: "the policy mode : (" + Object.keys(node_opcua_1.SecurityPolicy).join(" - ") + ")"
|
|
43
|
-
})
|
|
44
|
-
.option("discovery", {
|
|
45
|
-
alias: "D",
|
|
46
|
-
describe: "specify the endpoint uri of discovery server (by default same as server endpoint uri)"
|
|
47
|
-
})
|
|
48
|
-
.example("get_endpoints --endpoint opc.tcp://localhost:49230", "").argv;
|
|
49
|
-
const securityMode = (0, node_opcua_1.coerceMessageSecurityMode)(argv.securityMode);
|
|
50
|
-
if (securityMode === node_opcua_1.MessageSecurityMode.Invalid) {
|
|
51
|
-
throw new Error("Invalid Security mode");
|
|
52
|
-
}
|
|
53
|
-
const securityPolicy = (0, node_opcua_1.coerceSecurityPolicy)(argv.securityPolicy);
|
|
54
|
-
if (securityPolicy === node_opcua_1.SecurityPolicy.Invalid) {
|
|
55
|
-
throw new Error("Invalid securityPolicy");
|
|
56
|
-
}
|
|
57
|
-
console.log(chalk.cyan("securityMode = "), securityMode.toString());
|
|
58
|
-
console.log(chalk.cyan("securityPolicy = "), securityPolicy.toString());
|
|
59
|
-
const endpointUrl = argv.endpoint;
|
|
60
|
-
if (!endpointUrl) {
|
|
61
|
-
yargs.showHelp();
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
const discoveryUrl = argv.discovery ? argv.discovery : endpointUrl;
|
|
65
|
-
const optionsInitial = {
|
|
66
|
-
securityMode,
|
|
67
|
-
securityPolicy,
|
|
68
|
-
endpointMustExist: false,
|
|
69
|
-
connectionStrategy: {
|
|
70
|
-
initialDelay: 2000,
|
|
71
|
-
maxDelay: 10 * 1000,
|
|
72
|
-
maxRetry: 10
|
|
73
|
-
},
|
|
74
|
-
discoveryUrl
|
|
75
|
-
};
|
|
76
|
-
const client = node_opcua_1.OPCUAClient.create(optionsInitial);
|
|
77
|
-
client.on("backoff", (retry, delay) => {
|
|
78
|
-
console.log(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
|
|
79
|
-
});
|
|
80
|
-
console.log(" connecting to ", chalk.cyan.bold(endpointUrl));
|
|
81
|
-
console.log(" strategy", client.connectionStrategy);
|
|
82
|
-
try {
|
|
83
|
-
yield client.connect(endpointUrl);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
console.log(chalk.red(" Cannot connect to ") + endpointUrl);
|
|
87
|
-
if (err instanceof Error) {
|
|
88
|
-
console.log(" Error = ", err.message);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const endpoints = yield client.getEndpoints();
|
|
93
|
-
if (argv.debug) {
|
|
94
|
-
fs.writeFileSync("tmp/endpoints.log", JSON.stringify(endpoints, null, " "));
|
|
95
|
-
console.log(treeify.asTree(endpoints, true));
|
|
96
|
-
}
|
|
97
|
-
const table = new Table();
|
|
98
|
-
let serverCertificate;
|
|
99
|
-
let i = 0;
|
|
100
|
-
for (const endpoint of endpoints) {
|
|
101
|
-
table.cell("endpoint", endpoint.endpointUrl + "");
|
|
102
|
-
table.cell("Application URI", endpoint.server.applicationUri);
|
|
103
|
-
table.cell("Product URI", endpoint.server.productUri);
|
|
104
|
-
table.cell("Application Name", endpoint.server.applicationName.text);
|
|
105
|
-
table.cell("securityLevel", endpoint.securityLevel);
|
|
106
|
-
table.cell("Security Mode", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()));
|
|
107
|
-
table.cell("securityPolicyUri", chalk.cyan(endpoint.securityPolicyUri));
|
|
108
|
-
table.cell("Type", node_opcua_1.ApplicationType[endpoint.server.applicationType]);
|
|
109
|
-
table.cell("certificate", "..." /*endpoint.serverCertificate*/);
|
|
110
|
-
endpoint.server.discoveryUrls = endpoint.server.discoveryUrls || [];
|
|
111
|
-
table.cell("discoveryUrls", endpoint.server.discoveryUrls.join(" - "));
|
|
112
|
-
serverCertificate = endpoint.serverCertificate;
|
|
113
|
-
const certificate_filename = path.join(__dirname, "../certificates/PKI/server_certificate" + i + ".pem");
|
|
114
|
-
if (serverCertificate) {
|
|
115
|
-
fs.writeFile(certificate_filename, (0, node_opcua_crypto_1.toPem)(serverCertificate, "CERTIFICATE"), () => {
|
|
116
|
-
/**/
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
table.newRow();
|
|
120
|
-
i++;
|
|
121
|
-
}
|
|
122
|
-
console.log(table.toString());
|
|
123
|
-
for (const endpoint of endpoints) {
|
|
124
|
-
console.log("Identify Token for : Security Mode=", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()), " Policy=", chalk.cyan(endpoint.securityPolicyUri));
|
|
125
|
-
const table2 = new Table();
|
|
126
|
-
for (const token of endpoint.userIdentityTokens) {
|
|
127
|
-
table2.cell("policyId", token.policyId);
|
|
128
|
-
table2.cell("tokenType", node_opcua_1.UserTokenType[token.tokenType]);
|
|
129
|
-
table2.cell("issuedTokenType", token.issuedTokenType);
|
|
130
|
-
table2.cell("issuerEndpointUrl", token.issuerEndpointUrl);
|
|
131
|
-
table2.cell("securityPolicyUri", token.securityPolicyUri);
|
|
132
|
-
table2.newRow();
|
|
133
|
-
}
|
|
134
|
-
console.log(table2.toString());
|
|
135
|
-
}
|
|
136
|
-
yield client.disconnect();
|
|
137
|
-
console.log("success !! ");
|
|
138
|
-
process.exit(0);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
main();
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// tslint:disable:no-console
|
|
14
|
+
const chalk = require("chalk");
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const yargs = require("yargs");
|
|
18
|
+
const node_opcua_1 = require("node-opcua");
|
|
19
|
+
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
20
|
+
// tslint:disable:no-var-requires
|
|
21
|
+
const Table = require("easy-table");
|
|
22
|
+
const treeify = require("treeify");
|
|
23
|
+
// eslint-disable-next-line max-statements
|
|
24
|
+
function main() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
// ts-node bin/simple_client.ts --endpoint opc.tcp://localhost:53530/OPCUA/SimulationServer --node "ns=5;s=Sinusoid1"
|
|
27
|
+
const argv = yield yargs(process.argv)
|
|
28
|
+
.wrap(132)
|
|
29
|
+
.option("endpoint", {
|
|
30
|
+
alias: "e",
|
|
31
|
+
demandOption: true,
|
|
32
|
+
describe: "the end point to connect to "
|
|
33
|
+
})
|
|
34
|
+
.option("securityMode", {
|
|
35
|
+
alias: "s",
|
|
36
|
+
default: "None",
|
|
37
|
+
describe: "the security mode ( None Sign SignAndEncrypt )"
|
|
38
|
+
})
|
|
39
|
+
.option("securityPolicy", {
|
|
40
|
+
alias: "P",
|
|
41
|
+
default: "None",
|
|
42
|
+
describe: "the policy mode : (" + Object.keys(node_opcua_1.SecurityPolicy).join(" - ") + ")"
|
|
43
|
+
})
|
|
44
|
+
.option("discovery", {
|
|
45
|
+
alias: "D",
|
|
46
|
+
describe: "specify the endpoint uri of discovery server (by default same as server endpoint uri)"
|
|
47
|
+
})
|
|
48
|
+
.example("get_endpoints --endpoint opc.tcp://localhost:49230", "").argv;
|
|
49
|
+
const securityMode = (0, node_opcua_1.coerceMessageSecurityMode)(argv.securityMode);
|
|
50
|
+
if (securityMode === node_opcua_1.MessageSecurityMode.Invalid) {
|
|
51
|
+
throw new Error("Invalid Security mode");
|
|
52
|
+
}
|
|
53
|
+
const securityPolicy = (0, node_opcua_1.coerceSecurityPolicy)(argv.securityPolicy);
|
|
54
|
+
if (securityPolicy === node_opcua_1.SecurityPolicy.Invalid) {
|
|
55
|
+
throw new Error("Invalid securityPolicy");
|
|
56
|
+
}
|
|
57
|
+
console.log(chalk.cyan("securityMode = "), securityMode.toString());
|
|
58
|
+
console.log(chalk.cyan("securityPolicy = "), securityPolicy.toString());
|
|
59
|
+
const endpointUrl = argv.endpoint;
|
|
60
|
+
if (!endpointUrl) {
|
|
61
|
+
yargs.showHelp();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
const discoveryUrl = argv.discovery ? argv.discovery : endpointUrl;
|
|
65
|
+
const optionsInitial = {
|
|
66
|
+
securityMode,
|
|
67
|
+
securityPolicy,
|
|
68
|
+
endpointMustExist: false,
|
|
69
|
+
connectionStrategy: {
|
|
70
|
+
initialDelay: 2000,
|
|
71
|
+
maxDelay: 10 * 1000,
|
|
72
|
+
maxRetry: 10
|
|
73
|
+
},
|
|
74
|
+
discoveryUrl
|
|
75
|
+
};
|
|
76
|
+
const client = node_opcua_1.OPCUAClient.create(optionsInitial);
|
|
77
|
+
client.on("backoff", (retry, delay) => {
|
|
78
|
+
console.log(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
|
|
79
|
+
});
|
|
80
|
+
console.log(" connecting to ", chalk.cyan.bold(endpointUrl));
|
|
81
|
+
console.log(" strategy", client.connectionStrategy);
|
|
82
|
+
try {
|
|
83
|
+
yield client.connect(endpointUrl);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.log(chalk.red(" Cannot connect to ") + endpointUrl);
|
|
87
|
+
if (err instanceof Error) {
|
|
88
|
+
console.log(" Error = ", err.message);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const endpoints = yield client.getEndpoints();
|
|
93
|
+
if (argv.debug) {
|
|
94
|
+
fs.writeFileSync("tmp/endpoints.log", JSON.stringify(endpoints, null, " "));
|
|
95
|
+
console.log(treeify.asTree(endpoints, true));
|
|
96
|
+
}
|
|
97
|
+
const table = new Table();
|
|
98
|
+
let serverCertificate;
|
|
99
|
+
let i = 0;
|
|
100
|
+
for (const endpoint of endpoints) {
|
|
101
|
+
table.cell("endpoint", endpoint.endpointUrl + "");
|
|
102
|
+
table.cell("Application URI", endpoint.server.applicationUri);
|
|
103
|
+
table.cell("Product URI", endpoint.server.productUri);
|
|
104
|
+
table.cell("Application Name", endpoint.server.applicationName.text);
|
|
105
|
+
table.cell("securityLevel", endpoint.securityLevel);
|
|
106
|
+
table.cell("Security Mode", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()));
|
|
107
|
+
table.cell("securityPolicyUri", chalk.cyan(endpoint.securityPolicyUri));
|
|
108
|
+
table.cell("Type", node_opcua_1.ApplicationType[endpoint.server.applicationType]);
|
|
109
|
+
table.cell("certificate", "..." /*endpoint.serverCertificate*/);
|
|
110
|
+
endpoint.server.discoveryUrls = endpoint.server.discoveryUrls || [];
|
|
111
|
+
table.cell("discoveryUrls", endpoint.server.discoveryUrls.join(" - "));
|
|
112
|
+
serverCertificate = endpoint.serverCertificate;
|
|
113
|
+
const certificate_filename = path.join(__dirname, "../certificates/PKI/server_certificate" + i + ".pem");
|
|
114
|
+
if (serverCertificate) {
|
|
115
|
+
fs.writeFile(certificate_filename, (0, node_opcua_crypto_1.toPem)(serverCertificate, "CERTIFICATE"), () => {
|
|
116
|
+
/**/
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
table.newRow();
|
|
120
|
+
i++;
|
|
121
|
+
}
|
|
122
|
+
console.log(table.toString());
|
|
123
|
+
for (const endpoint of endpoints) {
|
|
124
|
+
console.log("Identify Token for : Security Mode=", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()), " Policy=", chalk.cyan(endpoint.securityPolicyUri));
|
|
125
|
+
const table2 = new Table();
|
|
126
|
+
for (const token of endpoint.userIdentityTokens) {
|
|
127
|
+
table2.cell("policyId", token.policyId);
|
|
128
|
+
table2.cell("tokenType", node_opcua_1.UserTokenType[token.tokenType]);
|
|
129
|
+
table2.cell("issuedTokenType", token.issuedTokenType);
|
|
130
|
+
table2.cell("issuerEndpointUrl", token.issuerEndpointUrl);
|
|
131
|
+
table2.cell("securityPolicyUri", token.securityPolicyUri);
|
|
132
|
+
table2.newRow();
|
|
133
|
+
}
|
|
134
|
+
console.log(table2.toString());
|
|
135
|
+
}
|
|
136
|
+
yield client.disconnect();
|
|
137
|
+
console.log("success !! ");
|
|
138
|
+
process.exit(0);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
main();
|
|
142
142
|
//# sourceMappingURL=get_endpoints.js.map
|
package/dist/mini_server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|