fix(gateway): set password to send write commands
This commit is contained in:
@@ -9,17 +9,21 @@ import {Color} from "../utils/Color";
|
|||||||
export class Gateway extends events.EventEmitter {
|
export class Gateway extends events.EventEmitter {
|
||||||
static iv: Buffer = Buffer.from([0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58, 0x56, 0x2e]);
|
static iv: Buffer = Buffer.from([0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58, 0x56, 0x2e]);
|
||||||
protected lastToken: string;
|
protected lastToken: string;
|
||||||
protected password: string;
|
protected _password: string;
|
||||||
private _subdevices: { [sid: string]: GatewaySubdevice } = {};
|
private _subdevices: { [sid: string]: GatewaySubdevice } = {};
|
||||||
|
|
||||||
constructor(public sid: string, public ip: string) {
|
constructor(public sid: string, public ip: string) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
get key(): string {
|
set password(password: string) {
|
||||||
if (!this.lastToken || !this.password) return null;
|
this._password = password;
|
||||||
|
}
|
||||||
|
|
||||||
var cipher = crypto.createCipheriv('aes-128-cbc', this.password, Gateway.iv);
|
get key(): string {
|
||||||
|
if (!this.lastToken || !this._password) return null;
|
||||||
|
|
||||||
|
var cipher = crypto.createCipheriv('aes-128-cbc', this._password, Gateway.iv);
|
||||||
var key = cipher.update(Buffer.from(this.lastToken), "ascii", "hex");
|
var key = cipher.update(Buffer.from(this.lastToken), "ascii", "hex");
|
||||||
cipher.final('hex');
|
cipher.final('hex');
|
||||||
|
|
||||||
@@ -30,7 +34,6 @@ export class Gateway extends events.EventEmitter {
|
|||||||
if (msg.data) {
|
if (msg.data) {
|
||||||
if (msg.model === "gateway" && msg.sid === this.sid && msg.token) {
|
if (msg.model === "gateway" && msg.sid === this.sid && msg.token) {
|
||||||
this.lastToken = msg.token;
|
this.lastToken = msg.token;
|
||||||
this.setLight(100, {red: 255, green: 0, blue: 0});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ export class GatewayServer extends events.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendToGateway(sid: string, message: any) {
|
sendToGateway(sid: string, message: any) {
|
||||||
|
console.log(message);
|
||||||
if (this.server && this._gateways[sid]) {
|
if (this.server && this._gateways[sid]) {
|
||||||
let msg = Buffer.from(JSON.stringify(message));
|
let msg = Buffer.from(JSON.stringify(message));
|
||||||
this.server.send(msg, 0, msg.length, GatewayServer.SERVER_PORT, this._gateways[sid].ip);
|
this.server.send(msg, 0, msg.length, GatewayServer.SERVER_PORT, this._gateways[sid].ip);
|
||||||
|
|||||||
@@ -56,12 +56,15 @@ export default (RED: Red) => {
|
|||||||
|
|
||||||
protected setGateway() {
|
protected setGateway() {
|
||||||
this._gateway = GatewayServer.getInstance().getGateway(this.sid);
|
this._gateway = GatewayServer.getInstance().getGateway(this.sid);
|
||||||
this._gateway && this._gateway.on("subdevice-values-updated", (sid: string) => {
|
if (this._gateway) {
|
||||||
let subdevice = this._gateway.getSubdevice(sid);
|
this._gateway.password = this.key;
|
||||||
if (subdevice) {
|
this._gateway.on("subdevice-values-updated", (sid: string) => {
|
||||||
(<any> this).emit('subdevice-update', subdevice);
|
let subdevice = this._gateway.getSubdevice(sid);
|
||||||
}
|
if (subdevice) {
|
||||||
});
|
(<any> this).emit('subdevice-update', subdevice);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get gateway(): Gateway {
|
get gateway(): Gateway {
|
||||||
|
|||||||
Reference in New Issue
Block a user