node-opcua-samples 2.97.0 → 2.98.1
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/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/server_with_changing_password.d.ts +1 -1
- package/dist/server_with_changing_password.js +100 -100
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +111 -111
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +661 -661
- 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 -125
- 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/dist/tiny_client.d.ts +1 -1
- package/dist/tiny_client.js +32 -32
- package/package.json +15 -12
- package/bin/createOPCUACertificate.cmd +0 -6
- package/bin/create_certificates.js +0 -2
- package/bin/crypto_create_CA.js +0 -2
- package/bin/demo_server_with_alarm.js +0 -51
- package/bin/findServersOnNetwork.js +0 -32
- package/bin/get_endpoints.ts +0 -166
- package/bin/machineryServer.js +0 -83
- package/bin/mini_server.ts +0 -106
- package/bin/more.js +0 -40
- package/bin/node-opcua.js +0 -2
- package/bin/opcua_interceptor.js +0 -122
- package/bin/server_with_changing_password.ts +0 -97
- package/bin/server_with_push_certificate.ts +0 -122
- package/bin/simple_client.js +0 -830
- package/bin/simple_client_ts.ts +0 -847
- package/bin/simple_findservers.ts +0 -45
- package/bin/simple_secure_server.ts +0 -152
- package/bin/simple_server_with_custom_extension_objects.ts +0 -89
- package/bin/stressing_client.ts +0 -28
- package/bin/tiny_client.ts +0 -24
|
@@ -1,101 +1,101 @@
|
|
|
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
|
-
const node_opcua_1 = require("node-opcua");
|
|
13
|
-
const port = 2510;
|
|
14
|
-
let server;
|
|
15
|
-
const users = [
|
|
16
|
-
{
|
|
17
|
-
username: "user1",
|
|
18
|
-
password: "passwor1",
|
|
19
|
-
roles: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.ConfigureAdmin])
|
|
20
|
-
}
|
|
21
|
-
];
|
|
22
|
-
const userManager = {
|
|
23
|
-
isValidUser: (username, password) => {
|
|
24
|
-
const uIndex = users.findIndex(function (u) {
|
|
25
|
-
return u.username === username;
|
|
26
|
-
});
|
|
27
|
-
if (uIndex < 0) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (users[uIndex].password !== password) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
getUserRoles: (username) => {
|
|
36
|
-
const uIndex = users.findIndex(function (x) {
|
|
37
|
-
return x.username === username;
|
|
38
|
-
});
|
|
39
|
-
if (uIndex < 0) {
|
|
40
|
-
return (0, node_opcua_1.makeRoles)("Anonymous");
|
|
41
|
-
}
|
|
42
|
-
const userRole = users[uIndex].roles;
|
|
43
|
-
return userRole;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function startServer() {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
server = new node_opcua_1.OPCUAServer({
|
|
49
|
-
port: port,
|
|
50
|
-
nodeset_filename: [node_opcua_1.nodesets.standard],
|
|
51
|
-
userManager,
|
|
52
|
-
maxConnectionsPerEndpoint: 1,
|
|
53
|
-
serverCapabilities: {
|
|
54
|
-
maxSessions: 2,
|
|
55
|
-
maxSubscriptions: 10,
|
|
56
|
-
maxSubscriptionsPerSession: 3
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
yield server.initialize();
|
|
60
|
-
yield server.start();
|
|
61
|
-
server.on("newChannel", () => {
|
|
62
|
-
console.log("server => new channel");
|
|
63
|
-
});
|
|
64
|
-
server.on("session_activated", () => {
|
|
65
|
-
console.log("server session activated");
|
|
66
|
-
});
|
|
67
|
-
server.on("connectionRefused", () => {
|
|
68
|
-
console.log("server connection refused");
|
|
69
|
-
});
|
|
70
|
-
server.on("session_closed", () => {
|
|
71
|
-
console.log("server sesion closed");
|
|
72
|
-
});
|
|
73
|
-
server.on("create_session", () => {
|
|
74
|
-
console.log("server create session");
|
|
75
|
-
});
|
|
76
|
-
return server;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
let counter = 0;
|
|
81
|
-
process.on("SIGINT", () => {
|
|
82
|
-
if (counter > 5) {
|
|
83
|
-
process.exit();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
while (true) {
|
|
87
|
-
users[0].password = `password${counter % 2}`;
|
|
88
|
-
counter++;
|
|
89
|
-
console.log("user: user1, password: ", users[0].password);
|
|
90
|
-
const server = yield startServer();
|
|
91
|
-
console.log("server started at", server.getEndpointUrl());
|
|
92
|
-
yield new Promise((resolve) => {
|
|
93
|
-
console.log("waiting for CTRL+C to cycle");
|
|
94
|
-
process.once("SIGINT", resolve);
|
|
95
|
-
});
|
|
96
|
-
console.log("now shutting down");
|
|
97
|
-
yield server.shutdown(1000);
|
|
98
|
-
console.log("server stopped for maintenance");
|
|
99
|
-
}
|
|
100
|
-
}))();
|
|
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
|
+
const node_opcua_1 = require("node-opcua");
|
|
13
|
+
const port = 2510;
|
|
14
|
+
let server;
|
|
15
|
+
const users = [
|
|
16
|
+
{
|
|
17
|
+
username: "user1",
|
|
18
|
+
password: "passwor1",
|
|
19
|
+
roles: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.ConfigureAdmin])
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
const userManager = {
|
|
23
|
+
isValidUser: (username, password) => {
|
|
24
|
+
const uIndex = users.findIndex(function (u) {
|
|
25
|
+
return u.username === username;
|
|
26
|
+
});
|
|
27
|
+
if (uIndex < 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (users[uIndex].password !== password) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
getUserRoles: (username) => {
|
|
36
|
+
const uIndex = users.findIndex(function (x) {
|
|
37
|
+
return x.username === username;
|
|
38
|
+
});
|
|
39
|
+
if (uIndex < 0) {
|
|
40
|
+
return (0, node_opcua_1.makeRoles)("Anonymous");
|
|
41
|
+
}
|
|
42
|
+
const userRole = users[uIndex].roles;
|
|
43
|
+
return userRole;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function startServer() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
server = new node_opcua_1.OPCUAServer({
|
|
49
|
+
port: port,
|
|
50
|
+
nodeset_filename: [node_opcua_1.nodesets.standard],
|
|
51
|
+
userManager,
|
|
52
|
+
maxConnectionsPerEndpoint: 1,
|
|
53
|
+
serverCapabilities: {
|
|
54
|
+
maxSessions: 2,
|
|
55
|
+
maxSubscriptions: 10,
|
|
56
|
+
maxSubscriptionsPerSession: 3
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
yield server.initialize();
|
|
60
|
+
yield server.start();
|
|
61
|
+
server.on("newChannel", () => {
|
|
62
|
+
console.log("server => new channel");
|
|
63
|
+
});
|
|
64
|
+
server.on("session_activated", () => {
|
|
65
|
+
console.log("server session activated");
|
|
66
|
+
});
|
|
67
|
+
server.on("connectionRefused", () => {
|
|
68
|
+
console.log("server connection refused");
|
|
69
|
+
});
|
|
70
|
+
server.on("session_closed", () => {
|
|
71
|
+
console.log("server sesion closed");
|
|
72
|
+
});
|
|
73
|
+
server.on("create_session", () => {
|
|
74
|
+
console.log("server create session");
|
|
75
|
+
});
|
|
76
|
+
return server;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
let counter = 0;
|
|
81
|
+
process.on("SIGINT", () => {
|
|
82
|
+
if (counter > 5) {
|
|
83
|
+
process.exit();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
while (true) {
|
|
87
|
+
users[0].password = `password${counter % 2}`;
|
|
88
|
+
counter++;
|
|
89
|
+
console.log("user: user1, password: ", users[0].password);
|
|
90
|
+
const server = yield startServer();
|
|
91
|
+
console.log("server started at", server.getEndpointUrl());
|
|
92
|
+
yield new Promise((resolve) => {
|
|
93
|
+
console.log("waiting for CTRL+C to cycle");
|
|
94
|
+
process.once("SIGINT", resolve);
|
|
95
|
+
});
|
|
96
|
+
console.log("now shutting down");
|
|
97
|
+
yield server.shutdown(1000);
|
|
98
|
+
console.log("server stopped for maintenance");
|
|
99
|
+
}
|
|
100
|
+
}))();
|
|
101
101
|
//# sourceMappingURL=server_with_changing_password.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
export {};
|
|
@@ -1,112 +1,112 @@
|
|
|
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 env_paths_1 = require("env-paths");
|
|
23
|
-
const config = (0, env_paths_1.default)("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
|
-
const users = [
|
|
31
|
-
{
|
|
32
|
-
username: "user1",
|
|
33
|
-
password: "password1",
|
|
34
|
-
role: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.ConfigureAdmin, node_opcua_1.WellKnownRoles.SecurityAdmin])
|
|
35
|
-
},
|
|
36
|
-
{ username: "user2", password: "password2", role: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.Operator]) }
|
|
37
|
-
];
|
|
38
|
-
const userManager = {
|
|
39
|
-
isValidUser(username, password) {
|
|
40
|
-
const uIndex = users.findIndex((x) => x.username === username);
|
|
41
|
-
if (uIndex < 0) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (users[uIndex].password !== password) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
},
|
|
49
|
-
getUserRoles(username) {
|
|
50
|
-
const uIndex = users.findIndex((x) => x.username === username);
|
|
51
|
-
if (uIndex < 0) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const userRole = users[uIndex].role;
|
|
55
|
-
return userRole;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
function main() {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const argv = yield yargs.wrap(132).option("port", {
|
|
61
|
-
alias: "p",
|
|
62
|
-
default: "26543",
|
|
63
|
-
describe: "port to listen"
|
|
64
|
-
}).argv;
|
|
65
|
-
const port = parseInt(argv.port, 10) || 26555;
|
|
66
|
-
const serverOptions = {
|
|
67
|
-
port,
|
|
68
|
-
nodeset_filename: [node_opcua_1.nodesets.standard],
|
|
69
|
-
serverCertificateManager: certificateManager,
|
|
70
|
-
userCertificateManager: certificateManager,
|
|
71
|
-
userManager
|
|
72
|
-
};
|
|
73
|
-
process.title = "Node OPCUA Server on port : " + serverOptions.port;
|
|
74
|
-
const tmpFolder = path.join(__dirname, "../certificates/myApp");
|
|
75
|
-
const applicationGroup = new node_opcua_pki_1.CertificateManager({
|
|
76
|
-
location: tmpFolder
|
|
77
|
-
});
|
|
78
|
-
yield applicationGroup.initialize();
|
|
79
|
-
const server = new node_opcua_1.OPCUAServer(serverOptions);
|
|
80
|
-
console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
|
|
81
|
-
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
82
|
-
yield server.initialize();
|
|
83
|
-
const addressSpace = server.engine.addressSpace;
|
|
84
|
-
// to do: expose new nodeid here
|
|
85
|
-
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
86
|
-
yield (0, node_opcua_server_configuration_1.installPushCertificateManagement)(addressSpace, {
|
|
87
|
-
applicationGroup: server.serverCertificateManager,
|
|
88
|
-
userTokenGroup: server.userCertificateManager,
|
|
89
|
-
applicationUri: server.serverInfo.applicationUri
|
|
90
|
-
});
|
|
91
|
-
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
|
|
92
|
-
try {
|
|
93
|
-
yield server.start();
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
console.log(" Server failed to start ... exiting");
|
|
97
|
-
process.exit(-3);
|
|
98
|
-
}
|
|
99
|
-
const endpointUrl = server.getEndpointUrl();
|
|
100
|
-
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
|
|
101
|
-
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
102
|
-
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
103
|
-
process.once("SIGINT", () => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
// only work on linux apparently
|
|
105
|
-
yield server.shutdown(1000);
|
|
106
|
-
console.log(chalk.red.bold(" shutting down completed "));
|
|
107
|
-
process.exit(-1);
|
|
108
|
-
}));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
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 env_paths_1 = require("env-paths");
|
|
23
|
+
const config = (0, env_paths_1.default)("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
|
+
const users = [
|
|
31
|
+
{
|
|
32
|
+
username: "user1",
|
|
33
|
+
password: "password1",
|
|
34
|
+
role: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.ConfigureAdmin, node_opcua_1.WellKnownRoles.SecurityAdmin])
|
|
35
|
+
},
|
|
36
|
+
{ username: "user2", password: "password2", role: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.Operator]) }
|
|
37
|
+
];
|
|
38
|
+
const userManager = {
|
|
39
|
+
isValidUser(username, password) {
|
|
40
|
+
const uIndex = users.findIndex((x) => x.username === username);
|
|
41
|
+
if (uIndex < 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (users[uIndex].password !== password) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
49
|
+
getUserRoles(username) {
|
|
50
|
+
const uIndex = users.findIndex((x) => x.username === username);
|
|
51
|
+
if (uIndex < 0) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const userRole = users[uIndex].role;
|
|
55
|
+
return userRole;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function main() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const argv = yield yargs.wrap(132).option("port", {
|
|
61
|
+
alias: "p",
|
|
62
|
+
default: "26543",
|
|
63
|
+
describe: "port to listen"
|
|
64
|
+
}).argv;
|
|
65
|
+
const port = parseInt(argv.port, 10) || 26555;
|
|
66
|
+
const serverOptions = {
|
|
67
|
+
port,
|
|
68
|
+
nodeset_filename: [node_opcua_1.nodesets.standard],
|
|
69
|
+
serverCertificateManager: certificateManager,
|
|
70
|
+
userCertificateManager: certificateManager,
|
|
71
|
+
userManager
|
|
72
|
+
};
|
|
73
|
+
process.title = "Node OPCUA Server on port : " + serverOptions.port;
|
|
74
|
+
const tmpFolder = path.join(__dirname, "../certificates/myApp");
|
|
75
|
+
const applicationGroup = new node_opcua_pki_1.CertificateManager({
|
|
76
|
+
location: tmpFolder
|
|
77
|
+
});
|
|
78
|
+
yield applicationGroup.initialize();
|
|
79
|
+
const server = new node_opcua_1.OPCUAServer(serverOptions);
|
|
80
|
+
console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
|
|
81
|
+
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
82
|
+
yield server.initialize();
|
|
83
|
+
const addressSpace = server.engine.addressSpace;
|
|
84
|
+
// to do: expose new nodeid here
|
|
85
|
+
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
86
|
+
yield (0, node_opcua_server_configuration_1.installPushCertificateManagement)(addressSpace, {
|
|
87
|
+
applicationGroup: server.serverCertificateManager,
|
|
88
|
+
userTokenGroup: server.userCertificateManager,
|
|
89
|
+
applicationUri: server.serverInfo.applicationUri
|
|
90
|
+
});
|
|
91
|
+
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
|
|
92
|
+
try {
|
|
93
|
+
yield server.start();
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
console.log(" Server failed to start ... exiting");
|
|
97
|
+
process.exit(-3);
|
|
98
|
+
}
|
|
99
|
+
const endpointUrl = server.getEndpointUrl();
|
|
100
|
+
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
|
|
101
|
+
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
102
|
+
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
103
|
+
process.once("SIGINT", () => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
// only work on linux apparently
|
|
105
|
+
yield server.shutdown(1000);
|
|
106
|
+
console.log(chalk.red.bold(" shutting down completed "));
|
|
107
|
+
process.exit(-1);
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
main();
|
|
112
112
|
//# sourceMappingURL=server_with_push_certificate.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
export {};
|