@gregoriusrippenstein/node-red-contrib-introspection 0.6.8 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nodes/60-client-code.js +4 -4
- package/package.json +1 -1
- package/plugins/sidebar.html +16 -19
package/nodes/60-client-code.js
CHANGED
|
@@ -79,7 +79,7 @@ module.exports = function(RED) {
|
|
|
79
79
|
if (req.body ) {
|
|
80
80
|
req.body.nodes.forEach( n => {
|
|
81
81
|
|
|
82
|
-
if (
|
|
82
|
+
if (n.format == "css" && !/[@]obfuscate-ignore/.test(n.template) ) {
|
|
83
83
|
let output = new CleanCSS(req.body.csscfg).minify(n.template);
|
|
84
84
|
if ( output.styles && (output.errors || []).length == 0 ) {
|
|
85
85
|
n.template = output.styles
|
|
@@ -89,7 +89,7 @@ module.exports = function(RED) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
if (n.format == "json") {
|
|
92
|
+
if (n.format == "json" && !/[@]obfuscate-ignore/.test(n.template)) {
|
|
93
93
|
let result = {}
|
|
94
94
|
try {
|
|
95
95
|
result.code = JSON.stringify(JSON.parse(n.template))
|
|
@@ -105,7 +105,7 @@ module.exports = function(RED) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
if (
|
|
108
|
+
if (n.format == "javascript" && !/[@]obfuscate-ignore/.test(n.template)) {
|
|
109
109
|
/* this handles PkgFile nodes and template nodes */
|
|
110
110
|
let result = UglifyJS.minify(n.template, req.body.jscfg)
|
|
111
111
|
|
|
@@ -117,7 +117,7 @@ module.exports = function(RED) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
if (n.type == "function") {
|
|
120
|
+
if (n.type == "function" && !/[@]obfuscate-ignore/.test(n.func)) {
|
|
121
121
|
let result = UglifyJS.minify(n.func, req.body.jscfg)
|
|
122
122
|
|
|
123
123
|
if (result.code && !result.error) {
|
package/package.json
CHANGED
package/plugins/sidebar.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function() {
|
|
3
3
|
var globalRefToSvgData;
|
|
4
4
|
|
|
5
|
-
let obfuscateHelpers={getFlowDataFromCurrentWorkspace:e=>{var e=e||RED.workspaces.active(),
|
|
5
|
+
let obfuscateHelpers={getFlowDataFromCurrentWorkspace:e=>{var e=e||RED.workspaces.active(),t=RED.nodes.groups(e),e=(t=(t=t.concat(RED.nodes.junctions(e))).concat(RED.nodes.filterNodes({z:e})),RED.nodes.eachConfig(function(e){e.z===RED.workspaces.active()&&!1===e._def.hasUsers&&t.push(e)}),RED.nodes.workspace(e)||RED.nodes.subflow(e));return t.unshift(e),RED.nodes.createExportableNodeSet(t)},openImportDialog:e=>{RED.clipboard.import();let t=e;setTimeout(()=>{$("#red-ui-clipboard-dialog-import-text").val(JSON.stringify(t)).trigger("paste")},300)}};function obfuscatieCurrentFlow(t){let i=obfuscateHelpers.getFlowDataFromCurrentWorkspace(),l=(t.remove_groups&&(i=i.filter(e=>"group"!=e.type)).forEach(e=>{delete e.g}),{}),r={},p={},f={},o=[],d={},u={};if(i.forEach(e=>{"subflow"==(l[e.id]=e).type&&(u[e.id]=e),"junction"==e.type&&(r[e.id]=e),"link out"==e.type&&(f[e.id]=e),"link in"==e.type&&(p[e.id]=e),"link call"==e.type&&o.push(e.id),"catch"==e.type&&(d[e.id]=(e.wires||[])[0]||[])}),t.remove_junctions&&(Object.keys(r).forEach(s=>{let n=r[s];u[n.z]||i.forEach(t=>{for(let e=0;e<(t.wires||[]).length;e++){var r=t.wires[e].indexOf(s);-1<r&&(t.wires[e].splice(r,1),t.wires[e].push(...n.wires[0]))}})}),i=i.filter(e=>!("junction"==e.type&&!u[e.z]))),t.remove_linkout_nodes||t.remove_linkcall_nodes){let s=[],r=[],u=[],a=(t.remove_linkout_nodes&&!t.copy_linkin_nodes&&Object.keys(f).forEach(n=>{var e=f[n],t=e.links||[];t.reduce((e,t)=>e&&!!p[t],!0)&&"return"!=e.mode&&(s.push(n),t.forEach(s=>{i.forEach(t=>{for(let e=0;e<(t.wires||[]).length;e++){var r=t.wires[e].indexOf(n);-1<r&&(t.wires[e].splice(r,1),t.wires[e].push(...p[s].wires[0]))}})}))}),(n,e)=>{if(!e)return!1;let t=[],o=[],r=[];function u(e){if(r.indexOf(e.id)<0)switch(r.push(e.id),t.push(e),e.type){case"link out":if("return"!=e.mode)throw"not handable";break;case"link call":throw"unhandled";default:RED.nodes.getNodeLinks(e).forEach(function(e){u(e.target)})}}try{RED.nodes.getNodeLinks(e).forEach(function(e){u(e.target),o.push(e.target.id)});if(Object.keys(d).forEach(e=>{((t,e)=>{try{return e.map(e=>e.id).forEach(e=>{if(t.includes(e))throw"yes"}),!1}catch(e){return!0}})(d[e],t)&&t.push(l[e])}),0==t.length)return!1;let r={};var a=t[0];let s={x:n.x-a.x,y:n.y-a.y};var i=t.map(e=>{var t=structuredClone(l[e.id]);return t||console.log("WARNING: nodeid not found",[e.id,l[e.id]]),t.id=RED.nodes.id(),t.x+=s.x,t.y+=s.y,r[e.id]=t});return i.forEach(e=>{"catch"==e.type&&Array.isArray(e.scope)&&(e.scope=e.scope.map(e=>{var t=r[e];return t&&t.id||e})),e.wires&&(e.wires=e.wires.map(e=>e.map(e=>{var t=r[e];return t&&"link out"==t.type?[...n.wires[0],(t||{}).id||e]:(t||{}).id||e}).flat()))}),{nodes:i.filter(e=>"link out"!=e.type),entryNodes:o.map(e=>r[e])}}catch(e){return!1}});t.remove_linkout_nodes&&t.copy_linkin_nodes&&Object.keys(f).forEach(o=>{let r=f[o];var e=r.links||[];"return"!=r.mode&&(e=e.map(e=>{var t=p[e],t=a(r,t);if(t)return[e,t]})).reduce((e,t)=>e&&!!t,!0)&&(s.push(o),e.forEach(([,n])=>{i.forEach(t=>{for(let e=0;e<(t.wires||[]).length;e++){var r,s=t.wires[e].indexOf(o);-1<s&&(r=n.entryNodes.map(e=>e.id),t.wires[e].splice(s,1),t.wires[e].push(...r),u.push(...n.nodes))}})}))}),t.remove_linkcall_nodes&&o.forEach(n=>{var e=l[n],t=p[e.links[0]];let o=a(e,t);t&&o&&(r.push(e.id),i.forEach(t=>{for(let e=0;e<(t.wires||[]).length;e++){var r,s=t.wires[e].indexOf(n);-1<s&&(r=o.entryNodes.map(e=>e.id),t.wires[e].splice(s,1),t.wires[e].push(...r),u.push(...o.nodes))}}))}),(i=i.filter(e=>s.indexOf(e.id)<0&&r.indexOf(e.id)<0)).push(...u)}if((i=t.remove_debugs?i.filter(e=>"debug"!=e.type&&"comment"!=e.type):i).forEach(e=>{t.name&&(e.name=RED.nodes.id()),t.shrink_node&&(e.l=!1),t.info&&(e.info="",delete e.outputLabels,delete e.inputLabels),t.position&&(e.x=150,e.y=150),t.remove_icons&&delete e.icon}),t.replace_switch){let s=(t,r)=>{for(let e=0;e<r.rules.length;e++){var s=r.rules[e];if("nnull"==s.t)t.push("if ( _propValue != null ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }");else if("null"==s.t)t.push("if ( _propValue == null ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }");else if("eq"==s.t&&"str"==s.vt){n=s.v;n=btoa(encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}));t.push("if ( _propValue === Buffer.from('"+n+"', 'base64').toString('utf-8') ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }")}else if("gt"==s.t&&"num"==s.vt)t.push("if ( _propValue > "+s.v+" ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }");else if("eq"==s.t&&"num"==s.vt)t.push("if ( _propValue == "+s.v+" ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }");else if("empty"==s.t)t.push('let p = _propValue ; if ( (Array.isArray(p) && p.length == 0) || ((typeof p === "object") && p != null && Object.keys(p).length == 0) || ((typeof p === "string") && p.length == 0) ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }');else if("nempty"==s.t)t.push('let p = _propValue ; if ( (Array.isArray(p) && p.length > 0) || ((typeof p === "object") && p != null && Object.keys(p).length > 0) || ((typeof p === "string") && p.length > 0) ) { _returnValue.push(msg) ; return node.send(_returnValue) } else { _returnValue.push(undefined) }');else{if("else"!=s.t)throw"unhandled";t.push("_returnValue.push(msg)","return node.send(_returnValue)")}}var n};i=i.map(t=>{if("switch"!=t.type)return t;var e={id:t.id,name:t.name,type:"function",x:t.x,y:t.y,func:"",outputs:t.outputs,timeout:"",noerr:0,initialize:"",finalize:"",libs:[{var:"process",module:"process"},{var:"jsonata",module:"jsonata"}],wires:t.wires};t.hasOwnProperty("z")&&(e.z=t.z),t.hasOwnProperty("l")&&(e.l=t.l);try{var r=[];if(t.checkAll)throw"unhandled";if("msg"==t.propertyType)r.push("((msg,node) => {","let _propValue = undefined","try { _propValue = RED.util.getMessageProperty(msg, '"+t.property+"') } catch (ex) {}","let _returnValue = []"),s(r,t),r.push("})(msg,node);");else{if("jsonata"!=t.propertyType)throw"unhandled";r.push("jsonata('"+t.property+"').evaluate(msg).then(_propValue => {","let _returnValue = []"),s(r,t),r.push("})")}return e.func=r.join("\n"),e}catch(e){return t}})}if(t.replace_change){let n=e=>btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}));i=i.map(t=>{if("change"!=t.type)return t;var e={id:t.id,name:t.name,type:"function",x:t.x,y:t.y,func:"",outputs:1,timeout:"",noerr:0,initialize:"",finalize:"",libs:[{var:"process",module:"process"},{var:"jsonata",module:"jsonata"}],wires:t.wires};t.hasOwnProperty("z")&&(e.z=t.z),t.hasOwnProperty("l")&&(e.l=t.l);try{var r=["(async (msg,node) => {","let __s = RED.util.setMessageProperty","let __g = RED.util.getMessageProperty"];for(let e=0;e<t.rules.length;e++){var s=t.rules[e];if("set"==s.t){if(s.dc)throw"unhandled";if("msg"==s.pt&&"str"==s.tot)r.push("__s(msg,'"+s.p+"', Buffer.from('"+n(s.to)+"', 'base64').toString('utf-8') )");else if("msg"==s.pt&&"bool"==s.tot)r.push("__s(msg,'"+s.p+"', "+s.to+")");else if("msg"==s.pt&&"num"==s.tot)r.push("__s(msg,'"+s.p+"', Number(Buffer.from('"+n(s.to)+"', 'base64').toString('utf-8')))");else if("msg"==s.pt&&"json"==s.tot)r.push("__s(msg,'"+s.p+"', JSON.parse(Buffer.from('"+n(s.to)+"', 'base64').toString('utf-8')))");else if("msg"==s.pt&&"msg"==s.tot)r.push("try { __s(msg,'"+s.p+"', __g(msg, '"+s.to+"')) } catch (ex) {}");else if("msg"==s.pt&&"env"==s.tot)r.push("__s(msg,'"+s.p+"', process.env['"+s.to+"'])");else{if("msg"!=s.pt||"jsonata"!=s.tot||!s.to.startsWith("/* @obfuscate-safe */"))throw"unhandlable";r.push("__s(msg,'"+s.p+"', await jsonata(Buffer.from('"+n(s.to)+"', 'base64').toString('utf-8')).evaluate(msg) )")}}else{if("delete"!=s.t||"msg"!=s.pt)throw"unhandlable";r.push("delete msg."+s.p)}}return r.push("node.send(msg) })(msg,node);"),e.func=r.join("\n"),e}catch(e){return console.log(e),t}})}if(t.javascript){let r={},t=[];i.forEach(e=>{"javascript"!=(r[e.id]=e).format&&"function"!=e.type&&"css"!=e.format&&"json"!=e.format||t.push(e)});var e={parse:{bare_returns:!0,expression:!1},compress:{},mangle:{reserved:["$","export","require"]},output:null,sourceMap:null,nameCache:null,toplevel:!1,warnings:!1},s={compatibility:"*",level:2};$.ajax({url:"ClientCode/"+RED.nodes.id()+"/ugify",type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify({nodes:t,jscfg:e,csscfg:s}),success:function(e){e.forEach(e=>{var t=r[e.id];e._error&&console.log("ERROR NODE",e),"function"==t.type?t.func=e.func:"javascript"!=t.format&&"css"!=t.format&&"json"!=t.format||(t.template=e.template)}),obfuscateHelpers.openImportDialog(i)},error:function(e,t,r){RED.notify("ClientCode Communcation Failure: "+n.id+": "+t,{type:"error",timeout:3e3})}})}else obfuscateHelpers.openImportDialog(i)}
|
|
6
6
|
|
|
7
7
|
function setupTreelist(){var e=collectOrphans();if(0==e.length){RED.notify("No Orphans Found",{type:"warning",timeout:2e3});try{$("#node-input-orphan-target-container-div").treeList("empty")}catch(e){}}else{try{$("#node-input-orphan-target-container-div").treeList("empty")}catch(e){$("#node-input-orphan-target-container-div").css({width:"100%",height:"calc(100%)"}).treeList({multi:!1}).on("treelistitemmouseover",function(e,t){}).on("treelistitemmouseout",function(e,t){}).on("treelistselect",function(e,t){t.node&&(RED.workspaces.show(t.node.z,!1,!1,!0),RED.view.reveal(t.node.id,!0),RED.view.redraw())}).on("treelistconfirm",function(e,t){var n;t.node&&(n=t.node.id,setTimeout(()=>{var e=RED.nodes.node(n);e&&(RED.view.reveal(e.id),RED.view.select(e.id),RED.editor.edit(e)),n==RED.workspaces.active()&&RED.workspaces.edit()},50))}),$("#node-input-orphan-target-filter").show();var n=$("#node-input-orphan-target-filter").searchBox({style:"compact",delay:300,change:function(){var e,t=$(this).val().trim().toLowerCase();""===t?($("#node-input-orphan-target-container-div").treeList("filter",null),n.searchBox("count","")):(e=$("#node-input-orphan-target-container-div").treeList("filter",function(e){return-1<e.label.toLowerCase().indexOf(t)||-1<e.node.type.toLowerCase().indexOf(t)}),n.searchBox("count",e+" / "+$("#node-input-orphan-target-container-div").treeList("data").length))}})}$("#node-input-orphan-target-container-div").treeList("data",e.sort((e,t)=>e.node.z>t.node.z))}}function collectOrphans(){const t=new Set;var n=[],i=(RED.nodes.eachLink(e=>{t.add(e.source),t.add(e.target)}),RED.nodes.eachNode(e=>{t.has(e)||n.push(e)}),[]),r={};return n.forEach(function(e){var t=RED.nodes.getType(e.type);if(t){var n=t.label,n=("function"==typeof n?n.call(e):n)||"",o=e.type;if(0===o.indexOf("subflow:"))return}t&&n||(n=e.type),r[e.id]={node:e,label:n,sublabel:o,selected:!1,checkbox:!1},i.push(r[e.id])}),i}
|
|
8
8
|
|
|
@@ -212,15 +212,6 @@
|
|
|
212
212
|
|
|
213
213
|
<div id="func-introspection-tab-obfuscation" style="display:none; min-height: calc(100%);">
|
|
214
214
|
|
|
215
|
-
<div class="form-row">
|
|
216
|
-
<div class="col-100">
|
|
217
|
-
<div class="form-row node-input-target-row" style="margin-left: 10px; margin-top: 30px">
|
|
218
|
-
<button id="node-input-obfuscation-generate-btn"
|
|
219
|
-
class="red-ui-button"><i class="fa fa-low-vision"></i> Obfuscate</button>
|
|
220
|
-
</div>
|
|
221
|
-
</div>
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
215
|
<div class="form-row col-100">
|
|
225
216
|
<label for="node-input-obfuscate-name" class="w-30">
|
|
226
217
|
<i class="fa fa-tag"></i>
|
|
@@ -242,7 +233,7 @@
|
|
|
242
233
|
<div class="form-row">
|
|
243
234
|
<label for="node-input-obfuscate-shrink-size" class="w-30">
|
|
244
235
|
<i class="fa fa-angle-down"></i>
|
|
245
|
-
<span>Shrink
|
|
236
|
+
<span>Shrink Nodes?</span>
|
|
246
237
|
</label>
|
|
247
238
|
<input type="checkbox" checked=checked id="node-input-obfuscate-shrink-size"
|
|
248
239
|
style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
@@ -295,6 +286,7 @@
|
|
|
295
286
|
|
|
296
287
|
<div class="form-row">
|
|
297
288
|
<label class='w-30'>
|
|
289
|
+
<i class="fa fa-refresh"></i>
|
|
298
290
|
<span>Replace Nodes:</span>
|
|
299
291
|
</label>
|
|
300
292
|
</div>
|
|
@@ -326,7 +318,7 @@
|
|
|
326
318
|
|
|
327
319
|
<div class="form-row">
|
|
328
320
|
<label for="node-input-obfuscate-remove-linknodes" class="w-30">
|
|
329
|
-
<i class="fa fa-
|
|
321
|
+
<i class="fa fa-unlink"></i>
|
|
330
322
|
<span>Coalesce Link Out Nodes?</span>
|
|
331
323
|
</label>
|
|
332
324
|
<input type="checkbox" checked=checked id="node-input-obfuscate-remove-linknodes"
|
|
@@ -337,24 +329,29 @@
|
|
|
337
329
|
<label for="node-input-obfuscate-copy-linkin-nodes" class="ml-30">
|
|
338
330
|
<span>Copy Link-In Nodes?</span>
|
|
339
331
|
</label>
|
|
340
|
-
<input type="checkbox" checked=checked id="node-input-obfuscate-copy-linkin-nodes"
|
|
341
|
-
style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
332
|
+
<input type="checkbox" checked=checked id="node-input-obfuscate-copy-linkin-nodes" style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
342
333
|
</div>
|
|
343
334
|
|
|
344
|
-
|
|
345
335
|
<div class="form-row">
|
|
346
336
|
<label for="node-input-obfuscate-remove-linkcall-nodes" class="w-30">
|
|
347
|
-
<i class="fa fa-
|
|
337
|
+
<i class="fa fa-unlink"></i>
|
|
348
338
|
<span>Coalesce Link Call Nodes?</span>
|
|
349
339
|
</label>
|
|
350
|
-
<input type="checkbox" checked=checked id="node-input-obfuscate-remove-linkcall-nodes"
|
|
351
|
-
style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
340
|
+
<input type="checkbox" checked=checked id="node-input-obfuscate-remove-linkcall-nodes" style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
352
341
|
</div>
|
|
353
342
|
|
|
343
|
+
<div class="form-row">
|
|
344
|
+
<div class="col-100">
|
|
345
|
+
<div class="form-row node-input-target-row" style="margin-left: 10px; margin-top: 30px">
|
|
346
|
+
<button id="node-input-obfuscation-generate-btn"
|
|
347
|
+
class="red-ui-button"><i class="fa fa-low-vision"></i> Obfuscate</button>
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
354
351
|
|
|
355
352
|
<div class="form-row" style="margin-left: 10px">
|
|
356
353
|
<b>Warning</b>: No guarantee is made that the obfuscated flow still works. This has not be
|
|
357
|
-
thoroughly tested
|
|
354
|
+
thoroughly tested. Ensure correctness by completely testing the resultant obfuscated flow.
|
|
358
355
|
</div>
|
|
359
356
|
</div>
|
|
360
357
|
|