Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*global require,setInterval,console */
var opcua = require("node-opcua");
// Let's create an instance of OPCUAServer
var server = new opcua.OPCUAServer({
securityPolicies: [opcua.SecurityPolicy.None, opcua.SecurityPolicy.Basic128Rsa15, opcua.SecurityPolicy.Basic256, opcua.SecurityPolicy.Basic256Sha256],
securityModes: [opcua.MessageSecurityMode.NONE, opcua.MessageSecurityMode.SIGN, opcua.MessageSecurityMode.SIGNANDENCRYPT],
port: 4855, // the port of the listening socket of the server
resourcePath: "", // this path will be added to the endpoint resource name
buildInfo: {
productName: "Node OPCUA Server",
buildNumber: "7658",
buildDate: new Date(2014, 5, 2)
},
alternateHostname: "127.0.0.1"
});
function post_initialize() {
console.log("initialized");
function construct_my_address_space(server) {
.alias("h", "history")
.example("simple_client --endpoint opc.tcp://localhost:49230 -P=Basic256 -s=SIGN")
.example("simple_client -e opc.tcp://localhost:49230 -P=Basic256 -s=SIGN -u JoeDoe -p P@338@rd ")
.example("simple_client --endpoint opc.tcp://localhost:49230 -n=\"ns=0;i=2258\"")
.argv;
const securityMode = opcua.coerceMessageSecurityMode(argv.securityMode || "None");
if (!securityMode) {
throw new Error("Invalid Security mode , should be " + opcua.MessageSecurityMode.enumItems.join(" "));
}
const securityPolicy = opcua.coerceSecurityPolicy(argv.securityPolicy || "None");
if (!securityPolicy) {
throw new Error("Invalid securityPolicy , should be " + opcua.SecurityPolicy.enumItems.join(" "));
}
//xx argv.securityMode = argv.securityMode || "SignAndEncrypt";
//xx argv.securityPolicy = argv.securityPolicy || "Basic128Rsa15";
const timeout = parseInt(argv.timeout) * 1000 || 20000;
const monitored_node = argv.node || "ns=1;s=PumpSpeed"; //"ns=1;s=Temperature";
console.log(chalk.cyan("securityMode = "), securityMode.toString());
console.log(chalk.cyan("securityPolicy = "), securityPolicy.toString());
console.log(chalk.cyan("timeout = "), timeout ? timeout : " Infinity ");
console.log(" monitoring node id = ", monitored_node);
let client = null;
const endpointUrl = argv.endpoint;
.example("simple_client --endpoint opc.tcp://localhost:49230 -P=Basic256Sha256 -s=SIGN")
.example("simple_client -e opc.tcp://localhost:49230 -P=Basic256Sha256 -s=SIGN -u JoeDoe -p P@338@rd ")
.example("simple_client --endpoint opc.tcp://localhost:49230 -n=\"ns=0;i=2258\"")
.argv;
const securityMode = opcua.MessageSecurityMode.get(argv.securityMode || "NONE");
if (!securityMode) {
throw new Error("Invalid Security mode , should be " + opcua.MessageSecurityMode.enums.join(" "));
}
const securityPolicy = opcua.SecurityPolicy.get(argv.securityPolicy || "None");
if (!securityPolicy) {
throw new Error("Invalid securityPolicy , should be " + opcua.SecurityPolicy.enums.join(" "));
}
//xx argv.securityMode = argv.securityMode || "SIGNANDENCRYPT";
//xx argv.securityPolicy = argv.securityPolicy || "Basic128Rsa15";
const timeout = parseInt(argv.timeout) * 1000 || 20000;
const monitored_node = argv.node || "ns=1;s=PumpSpeed"; //"ns=1;s=Temperature";
function constructFilename(filename) {
return path.join(__dirname,"../",filename);
}
const certificate_file = constructFilename("certificates/client_selfsigned_cert_2048.pem");
const certificate_privatekey_file = constructFilename("certificates/client_key_2048.pem");
console.log("securityMode = ".cyan, securityMode.toString());
console.log("securityPolicy = ".cyan, securityPolicy.toString());
.alias("d", "debug")
.alias("h", "history")
.example("simple_client --endpoint opc.tcp://localhost:49230 -P=Basic256Sha256 -s=SIGN")
.example("simple_client -e opc.tcp://localhost:49230 -P=Basic256Sha256 -s=SIGN -u JoeDoe -p P@338@rd ")
.example("simple_client --endpoint opc.tcp://localhost:49230 -n=\"ns=0;i=2258\"")
.argv;
const securityMode = opcua.MessageSecurityMode.get(argv.securityMode || "NONE");
if (!securityMode) {
throw new Error("Invalid Security mode , should be " + opcua.MessageSecurityMode.enums.join(" "));
}
const securityPolicy = opcua.SecurityPolicy.get(argv.securityPolicy || "None");
if (!securityPolicy) {
throw new Error("Invalid securityPolicy , should be " + opcua.SecurityPolicy.enums.join(" "));
}
//xx argv.securityMode = argv.securityMode || "SIGNANDENCRYPT";
//xx argv.securityPolicy = argv.securityPolicy || "Basic128Rsa15";
const timeout = parseInt(argv.timeout) * 1000 || 20000;
const monitored_node = argv.node || "ns=1;s=PumpSpeed"; //"ns=1;s=Temperature";
function constructFilename(filename) {
return path.join(__dirname,"../",filename);
}
const certificate_file = constructFilename("certificates/client_selfsigned_cert_2048.pem");
const certificate_privatekey_file = constructFilename("certificates/client_key_2048.pem");