node-opcua-samples 2.70.3 → 2.71.0

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.
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ts-node
2
- export {};
1
+ #!/usr/bin/env ts-node
2
+ export {};
@@ -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
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,89 +1,89 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- // tslint:disable:no-console
13
- const chalk = require("chalk");
14
- const path = require("path");
15
- const os = require("os");
16
- const node_opcua_1 = require("node-opcua");
17
- Error.stackTraceLimit = Infinity;
18
- const port = 26544;
19
- const envPaths = require("env-paths");
20
- const config = envPaths("MiniNodeOPCUA-Server").config;
21
- const pkiFolder = path.join(config, "PKI");
22
- const serverOptions = {
23
- serverCertificateManager: new node_opcua_1.OPCUACertificateManager({
24
- rootFolder: pkiFolder
25
- }),
26
- port,
27
- maxAllowedSessionNumber: 2,
28
- maxConnectionsPerEndpoint: 2,
29
- nodeset_filename: [(0, node_opcua_1.get_mini_nodeset_filename)()],
30
- serverInfo: {
31
- applicationUri: (0, node_opcua_1.makeApplicationUrn)(os.hostname(), "MiniNodeOPCUA-Server"),
32
- productUri: "Mini NodeOPCUA-Server",
33
- applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
34
- gatewayServerUri: null,
35
- discoveryProfileUri: null,
36
- discoveryUrls: []
37
- },
38
- buildInfo: {
39
- buildNumber: "1234"
40
- },
41
- serverCapabilities: {
42
- maxBrowseContinuationPoints: 10,
43
- maxHistoryContinuationPoints: 10,
44
- // maxInactiveLockTime
45
- operationLimits: {
46
- maxNodesPerBrowse: 10,
47
- maxNodesPerHistoryReadData: 6,
48
- maxNodesPerHistoryReadEvents: 10,
49
- maxNodesPerHistoryUpdateData: 10,
50
- maxNodesPerRead: 10,
51
- maxNodesPerWrite: 10
52
- }
53
- },
54
- isAuditing: false
55
- };
56
- function main() {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- process.title = "Node OPCUA Server on port : " + serverOptions.port;
59
- const server = new node_opcua_1.OPCUAServer(serverOptions);
60
- console.log(chalk.yellow(" server PID :"), process.pid);
61
- try {
62
- yield server.start();
63
- }
64
- catch (err) {
65
- console.log(" Server failed to start ... exiting");
66
- process.exit(-3);
67
- }
68
- const endpointUrl = server.getEndpointUrl();
69
- console.log(chalk.yellow(" server on port :"), server.endpoints[0].port.toString());
70
- console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
71
- console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
72
- server.on("create_session", (session) => {
73
- console.log(" SESSION CREATED");
74
- console.log(chalk.cyan(" client application URI: "), session.clientDescription.applicationUri);
75
- console.log(chalk.cyan(" client product URI: "), session.clientDescription.productUri);
76
- console.log(chalk.cyan(" client application name: "), session.clientDescription.applicationName.toString());
77
- console.log(chalk.cyan(" client application type: "), session.clientDescription.applicationType.toString());
78
- console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
79
- console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
80
- console.log(chalk.cyan(" session id: "), session.nodeId);
81
- });
82
- server.on("session_closed", (session, reason) => {
83
- console.log(" SESSION CLOSED :", reason);
84
- console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
85
- });
86
- });
87
- }
88
- main();
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ // tslint:disable:no-console
13
+ const chalk = require("chalk");
14
+ const path = require("path");
15
+ const os = require("os");
16
+ const node_opcua_1 = require("node-opcua");
17
+ Error.stackTraceLimit = Infinity;
18
+ const port = 26544;
19
+ const envPaths = require("env-paths");
20
+ const config = envPaths("MiniNodeOPCUA-Server").config;
21
+ const pkiFolder = path.join(config, "PKI");
22
+ const serverOptions = {
23
+ serverCertificateManager: new node_opcua_1.OPCUACertificateManager({
24
+ rootFolder: pkiFolder
25
+ }),
26
+ port,
27
+ maxAllowedSessionNumber: 2,
28
+ maxConnectionsPerEndpoint: 2,
29
+ nodeset_filename: [(0, node_opcua_1.get_mini_nodeset_filename)()],
30
+ serverInfo: {
31
+ applicationUri: (0, node_opcua_1.makeApplicationUrn)(os.hostname(), "MiniNodeOPCUA-Server"),
32
+ productUri: "Mini NodeOPCUA-Server",
33
+ applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
34
+ gatewayServerUri: null,
35
+ discoveryProfileUri: null,
36
+ discoveryUrls: []
37
+ },
38
+ buildInfo: {
39
+ buildNumber: "1234"
40
+ },
41
+ serverCapabilities: {
42
+ maxBrowseContinuationPoints: 10,
43
+ maxHistoryContinuationPoints: 10,
44
+ // maxInactiveLockTime
45
+ operationLimits: {
46
+ maxNodesPerBrowse: 10,
47
+ maxNodesPerHistoryReadData: 6,
48
+ maxNodesPerHistoryReadEvents: 10,
49
+ maxNodesPerHistoryUpdateData: 10,
50
+ maxNodesPerRead: 10,
51
+ maxNodesPerWrite: 10
52
+ }
53
+ },
54
+ isAuditing: false
55
+ };
56
+ function main() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ process.title = "Node OPCUA Server on port : " + serverOptions.port;
59
+ const server = new node_opcua_1.OPCUAServer(serverOptions);
60
+ console.log(chalk.yellow(" server PID :"), process.pid);
61
+ try {
62
+ yield server.start();
63
+ }
64
+ catch (err) {
65
+ console.log(" Server failed to start ... exiting");
66
+ process.exit(-3);
67
+ }
68
+ const endpointUrl = server.getEndpointUrl();
69
+ console.log(chalk.yellow(" server on port :"), server.endpoints[0].port.toString());
70
+ console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
71
+ console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
72
+ server.on("create_session", (session) => {
73
+ console.log(" SESSION CREATED");
74
+ console.log(chalk.cyan(" client application URI: "), session.clientDescription.applicationUri);
75
+ console.log(chalk.cyan(" client product URI: "), session.clientDescription.productUri);
76
+ console.log(chalk.cyan(" client application name: "), session.clientDescription.applicationName.toString());
77
+ console.log(chalk.cyan(" client application type: "), session.clientDescription.applicationType.toString());
78
+ console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
79
+ console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
80
+ console.log(chalk.cyan(" session id: "), session.nodeId);
81
+ });
82
+ server.on("session_closed", (session, reason) => {
83
+ console.log(" SESSION CLOSED :", reason);
84
+ console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
85
+ });
86
+ });
87
+ }
88
+ main();
89
89
  //# sourceMappingURL=mini_server.js.map
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ts-node
2
- export {};
1
+ #!/usr/bin/env ts-node
2
+ export {};
@@ -1,83 +1,83 @@
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
- /* eslint no-process-exit: 0 */
14
- // tslint:disable:no-console
15
- const path = require("path");
16
- const chalk = require("chalk");
17
- const node_opcua_1 = require("node-opcua");
18
- const node_opcua_pki_1 = require("node-opcua-pki");
19
- const node_opcua_server_configuration_1 = require("node-opcua-server-configuration");
20
- const yargs = require("yargs");
21
- const rootFolder = path.join(__dirname, "../../..");
22
- const envPaths = require("env-paths");
23
- const config = envPaths("node-opcua-default").config;
24
- const pkiFolder = path.join(config, "PKI");
25
- const certificateManager = new node_opcua_1.OPCUACertificateManager({
26
- automaticallyAcceptUnknownCertificate: true,
27
- name: "PKI",
28
- rootFolder: pkiFolder
29
- });
30
- function main() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const argv = yield yargs.wrap(132).option("port", {
33
- alias: "p",
34
- default: "26543",
35
- describe: "port to listen"
36
- }).argv;
37
- const port = parseInt(argv.port, 10) || 26555;
38
- const server_options = {
39
- port,
40
- nodeset_filename: [node_opcua_1.nodesets.standard],
41
- serverCertificateManager: certificateManager
42
- };
43
- process.title = "Node OPCUA Server on port : " + server_options.port;
44
- const tmpFolder = path.join(__dirname, "../certificates/myApp");
45
- const applicationGroup = new node_opcua_pki_1.CertificateManager({
46
- location: tmpFolder
47
- });
48
- yield applicationGroup.initialize();
49
- const server = new node_opcua_1.OPCUAServer(server_options);
50
- console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
51
- console.log(chalk.yellow(" server PID :"), process.pid);
52
- server.on("post_initialize", () => __awaiter(this, void 0, void 0, function* () {
53
- const addressSpace = server.engine.addressSpace;
54
- // to do: expose new nodeid here
55
- const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
56
- yield (0, node_opcua_server_configuration_1.installPushCertificateManagement)(addressSpace, {
57
- applicationGroup: server.serverCertificateManager,
58
- userTokenGroup: server.userCertificateManager,
59
- applicationUri: server.serverInfo.applicationUri
60
- });
61
- console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
62
- }));
63
- try {
64
- yield server.start();
65
- }
66
- catch (err) {
67
- console.log(" Server failed to start ... exiting");
68
- process.exit(-3);
69
- }
70
- const endpointUrl = server.getEndpointUrl();
71
- console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
72
- console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
73
- console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
74
- process.on("SIGINT", () => __awaiter(this, void 0, void 0, function* () {
75
- // only work on linux apparently
76
- yield server.shutdown(1000);
77
- console.log(chalk.red.bold(" shutting down completed "));
78
- process.exit(-1);
79
- }));
80
- });
81
- }
82
- 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
+ /* eslint no-process-exit: 0 */
14
+ // tslint:disable:no-console
15
+ const path = require("path");
16
+ const chalk = require("chalk");
17
+ const node_opcua_1 = require("node-opcua");
18
+ const node_opcua_pki_1 = require("node-opcua-pki");
19
+ const node_opcua_server_configuration_1 = require("node-opcua-server-configuration");
20
+ const yargs = require("yargs");
21
+ const rootFolder = path.join(__dirname, "../../..");
22
+ const envPaths = require("env-paths");
23
+ const config = envPaths("node-opcua-default").config;
24
+ const pkiFolder = path.join(config, "PKI");
25
+ const certificateManager = new node_opcua_1.OPCUACertificateManager({
26
+ automaticallyAcceptUnknownCertificate: true,
27
+ name: "PKI",
28
+ rootFolder: pkiFolder
29
+ });
30
+ function main() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const argv = yield yargs.wrap(132).option("port", {
33
+ alias: "p",
34
+ default: "26543",
35
+ describe: "port to listen"
36
+ }).argv;
37
+ const port = parseInt(argv.port, 10) || 26555;
38
+ const server_options = {
39
+ port,
40
+ nodeset_filename: [node_opcua_1.nodesets.standard],
41
+ serverCertificateManager: certificateManager
42
+ };
43
+ process.title = "Node OPCUA Server on port : " + server_options.port;
44
+ const tmpFolder = path.join(__dirname, "../certificates/myApp");
45
+ const applicationGroup = new node_opcua_pki_1.CertificateManager({
46
+ location: tmpFolder
47
+ });
48
+ yield applicationGroup.initialize();
49
+ const server = new node_opcua_1.OPCUAServer(server_options);
50
+ console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
51
+ console.log(chalk.yellow(" server PID :"), process.pid);
52
+ server.on("post_initialize", () => __awaiter(this, void 0, void 0, function* () {
53
+ const addressSpace = server.engine.addressSpace;
54
+ // to do: expose new nodeid here
55
+ const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
56
+ yield (0, node_opcua_server_configuration_1.installPushCertificateManagement)(addressSpace, {
57
+ applicationGroup: server.serverCertificateManager,
58
+ userTokenGroup: server.userCertificateManager,
59
+ applicationUri: server.serverInfo.applicationUri
60
+ });
61
+ console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
62
+ }));
63
+ try {
64
+ yield server.start();
65
+ }
66
+ catch (err) {
67
+ console.log(" Server failed to start ... exiting");
68
+ process.exit(-3);
69
+ }
70
+ const endpointUrl = server.getEndpointUrl();
71
+ console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
72
+ console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
73
+ console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
74
+ process.on("SIGINT", () => __awaiter(this, void 0, void 0, function* () {
75
+ // only work on linux apparently
76
+ yield server.shutdown(1000);
77
+ console.log(chalk.red.bold(" shutting down completed "));
78
+ process.exit(-1);
79
+ }));
80
+ });
81
+ }
82
+ main();
83
83
  //# sourceMappingURL=server_with_push_certificate.js.map