Skip to content

Commit f9a2c3c

Browse files
committed
plumming dashboard auth
1 parent 930b32e commit f9a2c3c

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

OpenFlowNodeRED/src/WebServer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { WebSocketClient } from "./WebSocketClient";
1818
import { noderedcontribopenflowstorage } from "./node-red-contrib-openflow-storage";
1919
import { SigninMessage, Message } from "./Message";
2020
import { noderedcontribmiddlewareauth } from "./node-red-contrib-middleware-auth";
21+
import { dashboardAuth } from "./dashboardAuth";
2122

2223
export class WebServer {
2324
private static _logger: winston.Logger;
@@ -124,6 +125,8 @@ export class WebServer {
124125

125126
this.settings.storageModule = new noderedcontribopenflowstorage(logger, socket);
126127

128+
this.settings.ui.middleware = new dashboardAuth();
129+
127130
// initialise the runtime with a server and settings
128131
await (RED as any).init(server, this.settings);
129132

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class dashboardAuth {
2+
3+
async tokenValidate(username, token) {
4+
}
5+
6+
dashboardAuth(req, res, next) {
7+
8+
next();
9+
}
10+
}

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export class noderedcontribopenflowstorage {
5656
this._logger.debug("creating new packageFile " + packageFile);
5757
fs.writeFileSync(packageFile, JSON.stringify(defaultPackage, null, 4));
5858
}
59-
var dbsettings = await this._getSettings();
59+
// var dbsettings = await this._getSettings();
60+
// spawn gettings, so it starts installing
6061
return true;
6162
}
6263
public async _getFlows(): Promise<any[]> {
@@ -132,33 +133,36 @@ export class noderedcontribopenflowstorage {
132133
console.error(error);
133134
}
134135
}
135-
private firstrun: boolean = true;
136+
// private firstrun: boolean = true;
136137
public async _getSettings(): Promise<any> {
137138
try {
138139
this._logger.silly("noderedcontribopenflowstorage::_getSettings");
139140
var result = await NoderedUtil.Query("nodered", { _type: "setting", nodered_id: Config.nodered_id }, null, null, 1, 0, null);
140141
if (result.length === 0) { return {}; }
141142

142143
var settings = JSON.parse(result[0].settings);
143-
if (this.firstrun) {
144-
var child_process = require("child_process");
145-
var keys = Object.keys(settings.nodes);
146-
var modules = "";
147-
for (var i = 0; i < keys.length; i++) {
148-
var key = keys[i];
149-
var val = settings.nodes[key];
150-
if (["node-red", "node-red-node-email", "node-red-node-feedparser", "node-red-node-rbe",
151-
"node-red-node-sentiment", "node-red-node-tail", "node-red-node-twitter"].indexOf(key) === -1) {
152-
var pname = val.name + "@" + val.version;
153-
// this._logger.info("Installing " + pname);
154-
// child_process.execSync("npm install " + pname, { stdio: [0, 1, 2], cwd: this.settings.userDir });
155-
modules += (" " + pname);
144+
//if (this.firstrun) {
145+
var child_process = require("child_process");
146+
var keys = Object.keys(settings.nodes);
147+
var modules = "";
148+
for (var i = 0; i < keys.length; i++) {
149+
var key = keys[i];
150+
var val = settings.nodes[key];
151+
if (["node-red", "node-red-node-email", "node-red-node-feedparser", "node-red-node-rbe",
152+
"node-red-node-sentiment", "node-red-node-tail", "node-red-node-twitter"].indexOf(key) === -1) {
153+
var pname: string = val.name + "@" + val.version;
154+
if (val.pending_version) {
155+
pname = val.name + "@" + val.pending_version;
156156
}
157+
// this._logger.info("Installing " + pname);
158+
// child_process.execSync("npm install " + pname, { stdio: [0, 1, 2], cwd: this.settings.userDir });
159+
modules += (" " + pname);
157160
}
158-
this._logger.info("Installing " + modules);
159-
child_process.execSync("npm install " + modules, { stdio: [0, 1, 2], cwd: this.settings.userDir });
160-
this.firstrun = false;
161161
}
162+
this._logger.info("Installing " + modules);
163+
child_process.execSync("npm install " + modules, { stdio: [0, 1, 2], cwd: this.settings.userDir });
164+
//this.firstrun = false;
165+
//}
162166
this._logger.silly("noderedcontribopenflowstorage::_getSettings: return result");
163167
return settings;
164168
} catch (error) {

OpenFlowNodeRED/src/nodered_settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Config } from "./Config";
22

3+
export class dashboard_settings {
4+
public path: string = "ui";
5+
public middleware: any;
6+
}
37
// tslint:disable-next-line: class-name
48
export class nodered_settings {
9+
constructor() {
10+
this.ui = new dashboard_settings();
11+
}
512
public flowFile: string = "flows.json";
613
public settingsFile: string = "nodered_settings.js";
714
public nodesDir: string = ".";
@@ -13,6 +20,8 @@ export class nodered_settings {
1320
public httpStaticAuth: any = null;
1421
public httpNodeMiddleware: any;
1522

23+
public ui: dashboard_settings;
24+
1625
public httpAdminRoot: string = "/";
1726
public httpNodeRoot: string = "/";
1827
public storageModule: any = null;

0 commit comments

Comments
 (0)