Skip to content

Commit

Permalink
Merge pull request #284 from skadefro/master
Browse files Browse the repository at this point in the history
push 1.5.3
  • Loading branch information
skadefro authored Nov 25, 2023
2 parents c31ddd1 + 740e752 commit 13e1c9b
Show file tree
Hide file tree
Showing 27 changed files with 1,029 additions and 824 deletions.
811 changes: 412 additions & 399 deletions OpenFlow/src/Config.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions OpenFlow/src/Crypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class Crypt {
throw new Error('jwt must be provided');
}
if (NoderedUtil.IsNullEmpty(Crypt.encryption_key)) Crypt.encryption_key = Config.aes_secret.substring(0, 32);
if(ignoreExpiration == false && Config.ignore_expiration == true) ignoreExpiration = true;
if(Config.allow_signin_with_expired_jwt == false) ignoreExpiration = false;
const o: any = jsonwebtoken.verify(token, Crypt.encryption_key, { ignoreExpiration: ignoreExpiration });
let impostor: string = null;
if (!NoderedUtil.IsNullUndefinded(o) && !NoderedUtil.IsNullUndefinded(o.data) && !NoderedUtil.IsNullEmpty(o.data._id)) {
Expand Down Expand Up @@ -162,6 +162,6 @@ export class Crypt {
}
static decryptToken(token: string): any {
if (NoderedUtil.IsNullEmpty(Crypt.encryption_key)) Crypt.encryption_key = Config.aes_secret.substring(0, 32);
return jsonwebtoken.verify(token, Crypt.encryption_key, { ignoreExpiration: Config.ignore_expiration });
return jsonwebtoken.verify(token, Crypt.encryption_key, { ignoreExpiration: Config.allow_signin_with_expired_jwt });
}
}
8 changes: 6 additions & 2 deletions OpenFlow/src/DBHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export class DBHelper {
for (var i = 0; i < keys.length; i++) {
if (keys[i] && !keys[i].startsWith("requesttoken")) {
this.memoryCache.del(keys[i]);
} else {
console.log("not deleting " + keys[i]);
}
}
Logger.instanse.debug("clearCache called with reason: " + reason, span);
Expand All @@ -106,6 +104,12 @@ export class DBHelper {
} else {
keys = await this.memoryCache.keys();
}
} else if(this.memoryCache &&this.memoryCache.store && this.memoryCache.store.keys) {
if(this.memoryCache.store.keys.get) {
keys = await this.memoryCache.store.keys.get();
} else {
keys = await this.memoryCache.store.keys();
}
}
} catch (error) {

Expand Down
152 changes: 125 additions & 27 deletions OpenFlow/src/DatabaseConnection.ts

Large diffs are not rendered by default.

67 changes: 53 additions & 14 deletions OpenFlow/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ export class Logger {
}
span.addEvent(obj.message, obj)
}
if (obj.ms != null && obj.ms != "" && obj.func != "query" && Config.log_database_queries) {
if(Config.log_all_watches && obj.cls == "DatabaseConnection" && obj.func == "onchange") {

} else if(Config.log_database_queries && obj.requestId != null) {
} else if (obj.ms != null && obj.ms != "" && obj.func != "query" && Config.log_database_queries) {
if (obj.ms < Config.log_database_queries_ms) return;
} else if (Logger.enabled[cls]) {
if (Logger.enabled[cls] < lvl) return;
Expand Down Expand Up @@ -152,7 +155,7 @@ export class Logger {
return JSON.stringify(plainObject, filter, space);
};
if (Config.log_to_exchange && !Config.unittesting) {
if (NoderedUtil.IsNullEmpty(Logger._hostname)) Logger._hostname = (Config.getEnv("HOSTNAME", undefined) || os.hostname()) || "unknown";
if (NoderedUtil.IsNullEmpty(Logger._hostname)) Logger._hostname = (process.env.HOSTNAME || os.hostname()) || "unknown";
if (amqpwrapper.Instance() && amqpwrapper.Instance().connected && amqpwrapper.Instance().of_logger_ready) {
if (typeof obj.message == "object") obj.message = JSON.parse(stringifyError(obj.message, null, 2));
amqpwrapper.Instance().send("openflow_logs", "", { ...obj, host: Logger._hostname }, 500, null, "", span, 1);
Expand All @@ -173,8 +176,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand All @@ -193,8 +202,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand All @@ -212,8 +227,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand All @@ -231,8 +252,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand All @@ -251,8 +278,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand All @@ -271,8 +304,14 @@ export class Logger {
obj.cls = "";
if (s.file != '') obj.cls = s.file.replace(".js", "");
}
if(options?.openapi) {
obj.cls = "OpenAIProxy";
if(obj.func.indexOf("anonymous") > -1 || obj.func.indexOf("<") > -1 || obj.func.indexOf("[") > -1) {
obj.func = "anonymous";
}
if(options?.cls != null && options?.cls != "") {
obj.cls = options.cls;
}
if(options?.func != null && options?.func != "") {
obj.func = options.func;
}
this.json(obj, span);
}
Expand Down
18 changes: 6 additions & 12 deletions OpenFlow/src/LoginProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Span } from "@opentelemetry/api";
import { Logger } from "./Logger";
import { DatabaseConnection } from "./DatabaseConnection";
import { TokenRequest } from "./TokenRequest";
import { WebServer } from "./WebServer";
var nodemailer = require('nodemailer');
var dns = require('dns');
const got = require("got");
Expand Down Expand Up @@ -1126,10 +1127,6 @@ export class LoginProvider {
let _url = Config.basewsurl();
if (!NoderedUtil.IsNullEmpty(Config.api_ws_url)) _url = Config.api_ws_url;
if (!_url.endsWith("/")) _url += "/";
let nodered_domain_schema = Config.nodered_domain_schema;
if (NoderedUtil.IsNullEmpty(nodered_domain_schema)) {
nodered_domain_schema = "$nodered_id$." + Config.domain;
}
let agent_domain_schema = Config.agent_domain_schema;
if (NoderedUtil.IsNullEmpty(agent_domain_schema)) {
agent_domain_schema = "$slug$." + Config.domain;
Expand All @@ -1151,7 +1148,6 @@ export class LoginProvider {
auto_create_personal_nodered_group: Config.auto_create_personal_nodered_group,
auto_create_personal_noderedapi_group: Config.auto_create_personal_noderedapi_group,
namespace: Config.namespace,
nodered_domain_schema: nodered_domain_schema,
agent_domain_schema: agent_domain_schema,
websocket_package_size: Config.websocket_package_size,
version: Config.version,
Expand All @@ -1160,7 +1156,7 @@ export class LoginProvider {
validate_user_form: Config.validate_user_form,
validate_emails: Config.validate_emails,
forgot_pass_emails: Config.forgot_pass_emails,
supports_watch: Config.supports_watch,
supports_watch: true,
agent_images: Config.agent_images,
amqp_enabled_exchange: Config.amqp_enabled_exchange,
multi_tenant: Config.multi_tenant,
Expand Down Expand Up @@ -1197,14 +1193,16 @@ export class LoginProvider {
static async post_AddTokenRequest(req: any, res: any, next: any): Promise<void> {
const span: Span = Logger.otel.startSpanExpress("LoginProvider.login", req);
try {
const remoteip = LoginProvider.remoteip(req);
span?.setAttribute("remoteip", remoteip);
const key = req.body.key;
let exists: TokenRequest = await Logger.DBHelper.FindRequestTokenID(key, span);
if (!NoderedUtil.IsNullUndefinded(exists)) {
Logger.instanse.error("Key has already been used! " + key, span);
return res.status(500).send({ message: "Illegal key" });
}
await Logger.DBHelper.AddRequestTokenID(key, {}, span);
Logger.instanse.info("Added token request " + key, span);
Logger.instanse.info("Added token request " + key + " from " + remoteip, span);
res.status(200).send({ message: "ok" });
} catch (error) {
Logger.instanse.error(error, span);
Expand All @@ -1216,6 +1214,7 @@ export class LoginProvider {
static async get_GetTokenRequest(req: any, res: any, next: any): Promise<void> {
const span: Span = Logger.otel.startSpanExpress("LoginProvider.login", req);
try {
span?.setAttribute("remoteip", LoginProvider.remoteip(req));
const key = req.query.key;
let exists: TokenRequest = null;
exists = await Logger.DBHelper.FindRequestTokenID(key, span);
Expand Down Expand Up @@ -1477,11 +1476,6 @@ export class LoginProvider {
}
}

Config.smtp_service = Config.getEnv("smtp_service", "");
Config.smtp_from = Config.getEnv("smtp_from", "");
Config.smtp_user = Config.getEnv("smtp_user", "");
Config.smtp_pass = Config.getEnv("smtp_service", "");

if (Config.validate_emails) {
let email: string = tuser.username;
if (tuser.email && tuser.email.indexOf("@") > -1) email = tuser.email;
Expand Down
Loading

0 comments on commit 13e1c9b

Please sign in to comment.