Skip to content

Commit

Permalink
Merge pull request #274 from skadefro/master
Browse files Browse the repository at this point in the history
push latest updates
  • Loading branch information
skadefro authored Aug 1, 2023
2 parents 13a1c85 + 7180010 commit 0759da4
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 24 deletions.
7 changes: 6 additions & 1 deletion OpenFlow/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class dbConfig extends Base {
public cache_workitem_queues: boolean;

public agent_images: NoderedImage[]
public agent_node_selector: string;


public async Save(jwt: string, parent: Span): Promise<void> {
Expand Down Expand Up @@ -241,6 +242,8 @@ export class dbConfig extends Base {
Config.cache_workitem_queues = Config.parseBoolean(!NoderedUtil.IsNullEmpty(conf.cache_workitem_queues) ? conf.cache_workitem_queues : Config.getEnv("cache_workitem_queues", "false"));


Config.agent_node_selector = (!NoderedUtil.IsNullEmpty(conf.agent_node_selector) ? conf.agent_node_selector : Config.getEnv("agent_node_selector", ""))

if(!NoderedUtil.IsNullUndefinded(conf.agent_images)) {
Config.agent_images = conf.agent_images;
if(typeof conf.agent_images === "string") conf.agent_images = JSON.parse(conf.agent_images);
Expand Down Expand Up @@ -472,6 +475,7 @@ export class Config {
JSON.stringify([{"name":"Agent", "image":"openiap/nodeagent", "languages": ["nodejs", "python"]}, {"name":"Agent+Chromium", "image":"openiap/nodechromiumagent", "chromium": true, "languages": ["nodejs", "python"]}, {"name":"NodeRED", "image":"openiap/noderedagent", "port": 3000}, {"name":"DotNet 6", "image":"openiap/dotnetagent", "languages": ["dotnet"]} ])
));
Config.agent_domain_schema = Config.getEnv("agent_domain_schema", "");
Config.agent_node_selector = Config.getEnv("agent_node_selector", "");

Config.agent_apiurl = Config.getEnv("agent_apiurl", "");
Config.agent_oidc_config = Config.getEnv("agent_oidc_config", "");
Expand Down Expand Up @@ -741,9 +745,10 @@ export class Config {
// public static nodered_image: string = Config.getEnv("nodered_image", "openiap/nodered");
public static nodered_images: NoderedImage[] = JSON.parse(Config.getEnv("nodered_images", "[{\"name\":\"Latest Plain Nodered\", \"image\":\"openiap/nodered\"}]"));
public static agent_images: NoderedImage[] = JSON.parse(Config.getEnv("agent_images",
JSON.stringify([{"name":"Agent", "image":"openiap/nodeagent", "languages": ["nodejs", "python"]}, {"name":"Agent+Chromium", "image":"openiap/nodechromiumagent", "chromium": true, "languages": ["nodejs", "python"]}, {"name":"NodeRED", "image":"openiap/noderedagent", "port": 3000}, {"name":"DotNet 6", "image":"openiap/dotnetagent", "languages": ["dotnet"]} ])
JSON.stringify([{"name":"Agent", "image":"openiap/nodeagent", "languages": ["nodejs", "python"]}, {"name":"Agent+Chromium", "image":"openiap/nodechromiumagent", "chromium": true, "languages": ["nodejs", "python"]}, {"name":"NodeRED", "image":"openiap/noderedagent", "port": 3000}, {"name":"DotNet 6", "image":"openiap/dotnetagent", "languages": ["dotnet"]} , {"name":"PowerShell 7.3", "image":"openiap/nodeagent:pwsh", "languages": ["powershell"]} ])
));
public static agent_domain_schema: string = Config.getEnv("agent_domain_schema", "");
public static agent_node_selector:string = Config.getEnv("agent_node_selector", "");

public static agent_apiurl: string = Config.getEnv("agent_apiurl", "");
public static agent_oidc_config: string = Config.getEnv("agent_oidc_config", "");
Expand Down
36 changes: 31 additions & 5 deletions OpenFlow/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,18 @@ export class DatabaseConnection extends events.EventEmitter {
}
if (sendit) {
// if (payload == null) payload = await this.GetOne({ jwt, collectionname, query }, null);
payload = {}
payload = {
"wiq": wiq.name,
"wiqid": wiq._id,
"packageid": (wiq as any).packageid,
}
var sendthis = payload;
if (client.clientagent == "openrpa") {
sendthis = {
command: "invoke",
workflowid: wiq.workflowid,
data: { }
data: { },
"wiq": wiq.name, "wiqid": wiq._id, "packageid": (wiq as any).packageid,
}
}
if (payload != null) {
Expand Down Expand Up @@ -1676,9 +1681,11 @@ export class DatabaseConnection extends events.EventEmitter {
if (NoderedUtil.IsNullEmpty(agent.slug)) {
throw new Error("Slug is required for agents");
}
agent.slug = agent.slug.toLowerCase();
if (NoderedUtil.IsNullEmpty(agent.runas)) {
agent.runas = user._id
}

if (!NoderedUtil.IsNullEmpty(agent.runas)) {
var agentcount = 1;
const resource: Resource = await Config.db.GetResource("Agent Instance", span);
Expand Down Expand Up @@ -2071,6 +2078,12 @@ export class DatabaseConnection extends events.EventEmitter {
throw new Error("Access denied");
}
}
// @ts-ignore
if(NoderedUtil.IsNullEmpty(item.slug)) {
throw new Error("Slug is required for agents");
}
// @ts-ignore
item.slug = item.slug.toLowerCase();
if (NoderedUtil.IsNullEmpty((item as any).customerid)) {
if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) {
var customer = await this.getbyid<Customer>(user.selectedcustomerid, "users", jwt, true, span)
Expand Down Expand Up @@ -2423,6 +2436,15 @@ export class DatabaseConnection extends events.EventEmitter {
if (NoderedUtil.IsNullEmpty(agent.runas)) {
agent.runas = user._id
}
if(NoderedUtil.IsNullEmpty(agent.slug)) {
throw new Error("Agent slug cannot be empty");
}
agent.slug = agent.slug.toLowerCase();
// @ts-ignore
if (!user.HasRoleName("admins") && agent.slug != original.slug) {
throw new Error("Access denied, changing slug");
}

if (!NoderedUtil.IsNullEmpty(agent.runas)) {
var agentcount = 1;
const resource: Resource = await Config.db.GetResource("Agent Instance", span);
Expand Down Expand Up @@ -3554,6 +3576,9 @@ export class DatabaseConnection extends events.EventEmitter {
if (skip_array.indexOf(collectionname) == -1) {
if (!collectionname.endsWith("_hist")) addToHist = true;
}
if(DatabaseConnection.istimeseries(collectionname)) {
addToHist = false;
}


Logger.instanse.verbose("quering items to delete from " + collectionname, span, { collection: collectionname, user: user?.username });
Expand Down Expand Up @@ -3714,10 +3739,11 @@ export class DatabaseConnection extends events.EventEmitter {
*/
public getbasequery(user: TokenUser | User, bits: number[], collectionname: string): Object {
let field = "_acl";
var bypassquery:any = { _id: { $ne: "bum" } }
// var bypassquery:any = { _id: { $ne: "bum" } }
var bypassquery:any = { }
if(DatabaseConnection.usemetadata(collectionname)) {
bypassquery = { }
bypassquery[DatabaseConnection.metadataname(collectionname) + "._id"] = { $ne: "bum" }
// bypassquery = { }
// bypassquery[DatabaseConnection.metadataname(collectionname) + "._id"] = { $ne: "bum" }
field = DatabaseConnection.metadataname(collectionname) + "._acl";
}
if (Config.api_bypass_perm_check) {
Expand Down
2 changes: 2 additions & 0 deletions OpenFlow/src/LoginProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class samlauthstrategyoptions {
public entryPoint: string = "";
public issuer: string = "";
public cert: string = null;
public disableRequestedAuthnContext: boolean = false;

public audience: any = false;
public signatureAlgorithm: 'sha1' | 'sha256' | 'sha512' = "sha256";
Expand Down Expand Up @@ -347,6 +348,7 @@ export class LoginProvider {
options.entryPoint = singin_url;
options.cert = cert;
options.issuer = issuer;
options.disableRequestedAuthnContext = true;
options.callbackUrl = url.parse(baseurl).protocol + "//" + url.parse(baseurl).host + "/" + key + "/";
options.verify = (LoginProvider.samlverify).bind(this);
options.wantAuthnResponseSigned = false;
Expand Down
10 changes: 7 additions & 3 deletions OpenFlow/src/Messages/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4450,10 +4450,9 @@ export class Message {
// wi = await Config.db.InsertOne(wi, "workitems", 1, true, jwt, parent);
additems.push(wi);
}
await Config.db.InsertMany(additems, "workitems", 1, true, jwt, parent);
var items = await Config.db.InsertMany(additems, "workitems", 1, true, jwt, parent);

delete msg.items;
msg.items = [];
msg.items = items;


end = new Date().getTime();
Expand Down Expand Up @@ -4849,6 +4848,8 @@ export class Message {
wiq.failed_wiqid = msg.failed_wiqid;
wiq.success_wiq = msg.success_wiq;
wiq.success_wiqid = msg.success_wiqid;
// @ts-ignore
wiq.packageid = msg.packageid;

msg.result = await Config.db.InsertOne(wiq, "mq", 1, true, jwt, parent);

Expand Down Expand Up @@ -4913,6 +4914,9 @@ export class Message {
if (!NoderedUtil.IsNullEmpty(msg.success_wiq) || msg.success_wiq == "") wiq.success_wiq = msg.success_wiq;
if (!NoderedUtil.IsNullEmpty(msg.success_wiqid) || msg.success_wiqid == "") wiq.success_wiqid = msg.success_wiqid;
if (msg.success_wiq === null) { delete wiq.success_wiq; delete wiq.success_wiqid; }
// @ts-ignore
if (!NoderedUtil.IsNullEmpty(msg.packageid) || msg.packageid == "") wiq.packageid = msg.packageid;


if (msg._acl) wiq._acl = msg._acl;

Expand Down
27 changes: 25 additions & 2 deletions OpenFlow/src/WebServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ export class WebServer {
} else if (command == "download") {
if(msg.id && msg.id != "") {
reply.command = "downloadreply"
const rows = await Config.db.query({ query: { _id: safeObjectID(msg.id) }, top: 1, collectionname: "files", jwt: client.jwt }, null);
let rows = await Config.db.query({ query: { _id: safeObjectID(msg.id) }, top: 1, collectionname: "files", jwt: client.jwt }, null);
if(rows.length == 0) {
const rows2 = await Config.db.query({ query: { fileid: msg.id, "_type": "package"}, top:1, collectionname: "agents", jwt: client.jwt }, null);
if(rows2.length > 0) {
rows = await Config.db.query({ query: { _id: safeObjectID(msg.id) }, top: 1, collectionname: "files", jwt: Crypt.rootToken() }, null);
}
}
if(rows.length > 0) {
result = rows[0];
await WebServer.sendFileContent(client, reply.rid, msg.id)
Expand Down Expand Up @@ -549,7 +555,6 @@ export class WebServer {
}
if(reply.command == "addworkitemsreply") {
reply.command = "pushworkitemsreply";
reply.workitems = result.results;
}
var res = result.data;
if(typeof res == "string") var res = JSON.parse(res);
Expand All @@ -570,6 +575,16 @@ export class WebServer {
}
delete res.result;
}
if(reply.command == "pushworkitemsreply") {
res.workitems = res.items;
if(res.workitem && res.workitem.errormessage) {
if(typeof res.workitem.errormessage !== "string") {
res.workitem.errormessage = JSON.stringify(res.workitem.errormessage);
}

}
delete res.items;
}
if(result.command == "popworkitem") {
let includefiles = msg.includefiles || false;
// @ts-ignore
Expand Down Expand Up @@ -599,6 +614,14 @@ export class WebServer {
if(res.workitem && !NoderedUtil.IsNullUndefinded(res.workitem.payload) ) {
res.workitem.payload = JSON.stringify(res.workitem.payload);
}
if(res.workitems) {
for(let i = 0; i < res.workitems.length; i++) {
const wi = res.workitems[i];
if(!NoderedUtil.IsNullUndefinded(wi.payload)) {
wi.payload = JSON.stringify(wi.payload);
}
}
}
if(res.results) res.results = JSON.stringify(res.results);
if(reply.command == "queuemessagereply") res.data = JSON.stringify(res.data);
// reply.data = QueueMessageResponse.encode(QueueMessageResponse.create(res)).finish()
Expand Down
38 changes: 33 additions & 5 deletions OpenFlow/src/public/Controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4910,10 +4910,14 @@ export class AuditlogsCtrl extends entitiesCtrl<Role> {
const model: any = this.models[i];
model.fa = "far fa-question-circle";
model.fa2 = "";
if (model.imagename != null && model.imagename != "") model.fa = 'fab fa-docker';
if (model.clientagent == 'openrpa') model.fa = 'fas fa-robot';
if (model.clientagent == 'webapp') model.fa = 'fas fa-globe';
if (model.clientagent == 'browser') model.fa = 'fas fa-globe';
if (model.clientagent == 'mobileapp') model.fa = 'fas fa-mobile-alt';
if (model.clientagent == 'python') model.fa = 'fab python';
if (model.clientagent == 'node') model.fa = 'fab fa-node-js';
if (model.clientagent == 'nodeagent') model.fa = 'fab fa-node-js';
if (model.clientagent == 'nodered') model.fa = 'fab fa-node-js';
if (model.clientagent == 'getUserFromRequest') model.fa = 'fab fa-node-js';
if (model.clientagent == 'googleverify') model.fa = 'fab fa-google';
Expand Down Expand Up @@ -7129,6 +7133,9 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
public users: Base[] = [];
public amqpqueues: Base[] = [];
public workitemqueues: Base[] = [];
public agents: Base[];
public packages: Base[];

public stats: string = "calculating...";
constructor(
public $rootScope: ng.IRootScopeService,
Expand Down Expand Up @@ -7189,6 +7196,14 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
this.workitemqueues.forEach((e: any) => { e.display = e.name });
// this.workitemqueues.forEach((e: any) => { this.amqpqueues.push(e) });
this.workitemqueues.unshift({ "_id": "", "name": "", "display": "(no workitem queue)" } as any);

this.agents = await NoderedUtil.Query({ collectionname: "agents", query: { "_type": "agent" }, orderby: "name", projection: { "slug": 1, "name": 1 } });
console.log(this.agents);
this.agents.unshift({ "name": "" } as any)
this.packages = await NoderedUtil.Query({ collectionname: "agents", query: { "_type": "package" }, orderby: "name", projection: { "name": 1 } });
console.log(this.packages);
this.packages.unshift({ "name": "" } as any)

if (!this.$scope.$$phase) { this.$scope.$apply(); }
}
async processdata() {
Expand Down Expand Up @@ -7249,6 +7264,8 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
q.success_wiqid = model.success_wiqid;
q.failed_wiq = model.failed_wiq;
q.failed_wiqid = model.failed_wiqid;
// @ts-ignore
q.packageid = model.packageid;
if ((q.robotqueue == null || q.robotqueue == "") && (q.amqpqueue == null || q.amqpqueue == "")) {
q.amqpqueue = model.name;
}
Expand All @@ -7271,6 +7288,8 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
q.success_wiqid = model.success_wiqid;
q.failed_wiq = model.failed_wiq;
q.failed_wiqid = model.failed_wiqid;
// @ts-ignore
q.packageid = model.packageid;
_msg.command = 'updateworkitemqueue';
_msg.data = JSON.stringify(q);
const result: UpdateWorkitemQueueMessage = await WebSocketClient.instance.Send<UpdateWorkitemQueueMessage>(_msg, 1);
Expand Down Expand Up @@ -8137,7 +8156,15 @@ export class AgentCtrl extends entityCtrl<any> {
try {
this.loading = true;
this.instancelogpodname = podname;
this.instancelog = await NoderedUtil.CustomCommand({ command: "getagentlog", id: this.model._id, name: podname })
var lines:any = await NoderedUtil.CustomCommand({ command: "getagentlog", id: this.model._id, name: podname });
if(lines != null) {
lines = lines.split("\n")
// reverse lines
lines = lines.reverse()
} else {
lines = [];
}
this.instancelog = lines.join("\n");
this.errormessage = "";
} catch (error) {
this.errormessage = error.message ? error.message : error
Expand Down Expand Up @@ -8392,7 +8419,7 @@ export class PackagesCtrl extends entitiesCtrl<Base> {

export class PackageCtrl extends entityCtrl<Base> {
e: any = null;
languages: string[] = ["nodejs", "python", "dotnet"];
languages: string[] = ["nodejs", "python", "dotnet", "powershell"];
oldfileid: string = "";
constructor(
public $rootScope: ng.IRootScopeService,
Expand Down Expand Up @@ -8488,7 +8515,7 @@ export class PackageCtrl extends entityCtrl<Base> {

export class RunPackageCtrl extends entityCtrl<Base> {
e: any = null;
languages: string[] = ["nodejs", "python", "dotnet"];
languages: string[] = ["nodejs", "python", "dotnet", "powershell"];
oldfileid: string = "";
packageid: string = "";
package: string = "";
Expand Down Expand Up @@ -8666,8 +8693,9 @@ export class RunPackageCtrl extends entityCtrl<Base> {
if(pre == null) return;
const decoder = new TextDecoder("utf-8");
const string = decoder.decode(new Uint8Array(data as any));
// pre.innerText += string;
pre.innerText = string + pre.innerText;
var strings = string.split("\n").reverse();

pre.innerText = strings.join("\n") + pre.innerText;
}
if (!this.$scope.$$phase) { this.$scope.$apply(); }

Expand Down
Loading

0 comments on commit 0759da4

Please sign in to comment.