2
0

Moved gateway key into configurator

This commit is contained in:
Harald Rietman
2017-06-30 22:02:50 +02:00
parent 34a94a3615
commit 15d1a38dce
4 changed files with 11 additions and 11 deletions

View File

@@ -3,7 +3,8 @@
category: 'config',
defaults: {
name: {value: ""},
deviceList: {value:[{ sid:"a", desc:"b", model:"plug"}]}
deviceList: {value:[{ sid:"a", desc:"b", model:"plug"}]},
key: {value: ""}
},
label: function () {
return this.name || "xiaomi-configurator";
@@ -11,8 +12,6 @@
oneditprepare: function() {
var node = this;
console.log("config window openend: " + node.deviceList);
$("#node-config-input-devices").css('min-height','250px').css('min-width','450px').editableList({
addItem: function(container, i, device) {
if (!device.hasOwnProperty('model')) {
@@ -46,7 +45,6 @@
removable: true
});
console.log("Devices: " + JSON.stringify(node.deviceList));
for (var i=0;i<this.deviceList.length;i++) {
var device = this.deviceList[i];
$("#node-config-input-devices").editableList('addItem', device);
@@ -62,16 +60,13 @@
var sid = deviceElement.find("#node-config-input-sid-"+i).val();
var desc = deviceElement.find("#node-config-input-desc-"+i).val();
var model = deviceElement.find("#node-config-input-model-"+i).val();
console.log(desc, model, sid);
var d = {};
d['sid']=sid;
d['desc']=desc;
d['model']=model;
console.log(d);
devicesArray.push(d);
});
node.deviceList = devicesArray;
console.log("devices-list: " + JSON.stringify(node.deviceList));
}
});
</script>
@@ -80,6 +75,10 @@
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-key"><i class="fa fa-ticket"></i> Key</label>
<input type="text" id="node-config-input-key" placeholder="Key">
</div>
<div class="form-row node-config-input-devices">
<ol id="node-config-input-devices"></ol>

View File

@@ -4,6 +4,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this, n);
this.name = n.name;
this.deviceList = n.deviceList || [];
this.key = n.key;
var node = this;
}

View File

@@ -74,11 +74,11 @@
</select>
</div>
<div class="form-row node-input-msg">
<label for="node-input-onmsg"><i class="fa fa-thermometer-three-quarters"></i> On msg</label>
<label for="node-input-onmsg"><i class="fa fa-power-off"></i> On msg</label>
<input type="text" id="node-input-onmsg">
</div>
<div class="form-row node-input-msg">
<label for="node-input-offmsg"><i class="fa fa-mixcloud"></i> Off msg</label>
<label for="node-input-offmsg"><i class="fa fa-power-off"></i> Off msg</label>
<input type="text" id="node-input-offmsg">
</div>
</script>

View File

@@ -10,6 +10,7 @@ module.exports = function(RED) {
this.output = config.output;
this.onmsg = config.onmsg;
this.offmsg = config.offmsg;
this.key = this.gateway.key;
var node = this;
var currentToken = "";
@@ -23,11 +24,10 @@ module.exports = function(RED) {
var payload = msg.payload;
if (payload.cmd == "heartbeat" && payload.model == "gateway") {
var key = "c7utmdo2acpzai5b";
var token = payload.token;
if (token) {
var cipher = crypto.createCipheriv('aes128', key, (new Buffer("17996d093d28ddb3ba695a2e6f58562e", "hex")));
var cipher = crypto.createCipheriv('aes128', node.key, (new Buffer("17996d093d28ddb3ba695a2e6f58562e", "hex")));
var encoded_string = cipher.update(token, 'utf8', 'hex');
encoded_string += cipher.final('hex');