node-opcua-samples 2.73.1 → 2.76.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,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 path = require("path");
14
- const os = require("os");
15
- const chalk = require("chalk");
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
- maxConnectionsPerEndpoint: 2,
28
- nodeset_filename: [(0, node_opcua_1.get_mini_nodeset_filename)()],
29
- serverInfo: {
30
- applicationUri: (0, node_opcua_1.makeApplicationUrn)(os.hostname(), "MiniNodeOPCUA-Server"),
31
- productUri: "Mini NodeOPCUA-Server",
32
- applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
33
- gatewayServerUri: null,
34
- discoveryProfileUri: null,
35
- discoveryUrls: []
36
- },
37
- buildInfo: {
38
- buildNumber: "1234"
39
- },
40
- serverCapabilities: {
41
- maxSessions: 10,
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 path = require("path");
14
+ const os = require("os");
15
+ const chalk = require("chalk");
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
+ maxConnectionsPerEndpoint: 2,
28
+ nodeset_filename: [(0, node_opcua_1.get_mini_nodeset_filename)()],
29
+ serverInfo: {
30
+ applicationUri: (0, node_opcua_1.makeApplicationUrn)(os.hostname(), "MiniNodeOPCUA-Server"),
31
+ productUri: "Mini NodeOPCUA-Server",
32
+ applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
33
+ gatewayServerUri: null,
34
+ discoveryProfileUri: null,
35
+ discoveryUrls: []
36
+ },
37
+ buildInfo: {
38
+ buildNumber: "1234"
39
+ },
40
+ serverCapabilities: {
41
+ maxSessions: 10,
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 +1 @@
1
- export {};
1
+ export {};
@@ -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 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
- 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 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
+ 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 {};