From bd9fa1d1620cb80c9665901ce701768a49f582e3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Oct 2021 12:23:09 +0200 Subject: [PATCH 1/5] Latest Changes in Governance --- Projects/Governance/Plugins/Pools/Superalgos.json | 2 +- .../Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Projects/Governance/Plugins/Pools/Superalgos.json b/Projects/Governance/Plugins/Pools/Superalgos.json index 89861b27c..30ed151de 100644 --- a/Projects/Governance/Plugins/Pools/Superalgos.json +++ b/Projects/Governance/Plugins/Pools/Superalgos.json @@ -1064,7 +1064,7 @@ "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": true, + "isCollapsed": false, "angleToParent": 1, "distanceToParent": 3, "arrangementStyle": 0 diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 9a85a4ee1..e67809472 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -11847,7 +11847,7 @@ "type": "Tokens Awarded", "name": "New Tokens Awarded", "project": "Governance", - "id": "b66c668c-8411-4401-8aa7-10d8b2c4c233", + "id": "90876ef0-3d01-4a3f-afc8-52914972a040", "savedPayload": { "position": { "x": 33628.04190627182, From 216dbbc7d2f7af3831e662401d8b456e890b7a4c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Oct 2021 12:55:50 +0200 Subject: [PATCH 2/5] Environment reaching the UI at the Platform --- Environment.js | 1 + Platform/Client/httpInterface.js | 6 +++++- Platform/UI/AppPostLoader.js | 15 ++++++++++++--- Platform/UI/Globals.js | 3 ++- platform.js | 10 ++++++++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Environment.js b/Environment.js index efd66849b..47627f378 100644 --- a/Environment.js +++ b/Environment.js @@ -8,6 +8,7 @@ if (process.env.PACKAGED_PATH) { exports.newEnvironment = function () { let thisObject = { + DEMO_MODE: false, BASE_PATH: basePath, WEB_SERVER_URL: 'localhost', PLATFORM_WEB_SOCKETS_INTERFACE_PORT: 18041, diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index 08e617350..0d2f8a2a3 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -44,7 +44,11 @@ exports.newHttpInterface = function newHttpInterface() { let endpointOrFile = requestPath[1] switch (endpointOrFile) { - + case 'Environment': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.env), httpResponse) + } + break case 'WEB3': { SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) diff --git a/Platform/UI/AppPostLoader.js b/Platform/UI/AppPostLoader.js index b73803e3c..9d5cccd81 100644 --- a/Platform/UI/AppPostLoader.js +++ b/Platform/UI/AppPostLoader.js @@ -4,7 +4,7 @@ function newAppPostLoader() { const MODULE_NAME = 'Post Loader' const ERROR_LOG = true const logger = newWebDebugLog() - + let thisObject = { start: start @@ -14,9 +14,18 @@ function newAppPostLoader() { function start() { try { - + // autoSaveWhenClosingTheBrowser() - setupProjectsSchema() + setupEnvironment() + + function setupEnvironment() { + httpRequest(undefined, 'Environment', onResponse) + + function onResponse(err, file) { + UI.environment = JSON.parse(file) + setupProjectsSchema() + } + } function setupProjectsSchema() { httpRequest(undefined, 'ProjectsSchema', onResponse) diff --git a/Platform/UI/Globals.js b/Platform/UI/Globals.js index b3588616d..83bf7c5de 100644 --- a/Platform/UI/Globals.js +++ b/Platform/UI/Globals.js @@ -5,7 +5,8 @@ let PROJECTS_SCHEMA let SCHEMAS_BY_PROJECT = new Map() /* New Root object*/ let UI = { - projects: {} + projects: {}, + environment: {} } /* User Interface Colors */ diff --git a/platform.js b/platform.js index 5058dba87..28b0de345 100644 --- a/platform.js +++ b/platform.js @@ -26,13 +26,14 @@ if ( console.log('') console.log('TELEGRAM COMMUNITY: https://t.me/superalgoscommunity') console.log('') - console.log('USAGE: node platform [help] [noBrowser] [minMemo]') + console.log('USAGE: node platform [help] [noBrowser] [minMemo] [demoMode]') console.log('') console.log('OPTIONS:') console.log('') console.log(' help: Optional. Use it to see this helping information.') console.log(' noBrowser: Optional. Use it to launch Superalgos Platform Client only. The Superalgos Platform UI will not be loaded.') console.log(' minMemo: Optional. Use it when your hardware has less than 8 Gb or memory.') + console.log(' demoMode: Optional. Use it to launch Superalgos in Demo Mode. Users will be able to use the UI but not run Tasks.') console.log('') console.log('If you are having an error while trying to run the Superalgos Platform Client, consider this:') @@ -68,7 +69,6 @@ console.log('OPTIONS ACCEPTED:') console.log('') let optionsAccepted = 0 - if (process.argv.includes("minMemo")) { optionsAccepted++ console.log('minMemo ..................................................... Running with Minimun Required Memory.') @@ -79,9 +79,15 @@ if (process.argv.includes("noBrowser")) { console.log('noBrowser ................................................... Running without User Interface.') } +if (process.argv.includes("demoMode")) { + optionsAccepted++ + console.log('demoMode .................................................... Running without User Interface.') +} + if (optionsAccepted === 0) { console.log('none ........................................................ Running without any command line options.') } + console.log('') console.log('') From 40772b09af24c93bed87b95c7080b6180b9b1ff7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Oct 2021 13:25:34 +0200 Subject: [PATCH 3/5] Demo Mode implemented at the UI --- Environment.js | 2 +- .../Function-Libraries/TradingSessionFunctions.js | 14 ++++++++++++++ .../UI/Function-Libraries/TaskFunctions.js | 13 +++++++++++++ .../Function-Libraries/LearningSessionFunctions.js | 14 ++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Environment.js b/Environment.js index 47627f378..98bcecd46 100644 --- a/Environment.js +++ b/Environment.js @@ -8,7 +8,7 @@ if (process.env.PACKAGED_PATH) { exports.newEnvironment = function () { let thisObject = { - DEMO_MODE: false, + DEMO_MODE: true, BASE_PATH: basePath, WEB_SERVER_URL: 'localhost', PLATFORM_WEB_SOCKETS_INTERFACE_PORT: 18041, diff --git a/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js b/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js index 66fc16d5e..a8ef566a9 100644 --- a/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js +++ b/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js @@ -42,6 +42,13 @@ function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() { } function runSession(node, resume, callBackFunction) { + + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let validationsResult = validations(node) if (validationsResult === undefined) { /* If something fails at validations we just quit. */ @@ -195,6 +202,13 @@ function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() { } function stopSession(node, callBackFunction) { + + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let validationsResult = validations(node) if (validationsResult === undefined) { /* If something fails at validations we just quit. */ diff --git a/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js b/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js index 2f66119c7..3f49b07e8 100644 --- a/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js +++ b/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js @@ -90,6 +90,12 @@ function newFoundationsFunctionLibraryTaskFunctions() { function runTask(node, isDebugging, callBackFunction) { + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Tasks.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let lanNetworkNode = validations(node) if (lanNetworkNode === undefined) { /* This means that the validations failed. */ @@ -218,6 +224,13 @@ function newFoundationsFunctionLibraryTaskFunctions() { } function stopTask(node, callBackFunction) { + + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Tasks.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let lanNetworkNode = validations(node) if (lanNetworkNode === undefined) { /* This means that the validations failed. */ diff --git a/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js b/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js index c4323334b..0fefe9cda 100644 --- a/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js +++ b/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js @@ -42,6 +42,13 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { } function runSession(node, resume, callBackFunction) { + + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not execute Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let validationsResult = validations(node) if (validationsResult === undefined) { /* If something fails at validations we just quit. */ @@ -169,6 +176,13 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { } function stopSession(node, callBackFunction) { + + if (UI.environment.DEMO_MODE === true) { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + let validationsResult = validations(node) if (validationsResult === undefined) { /* If something fails at validations we just quit. */ From 00c47b2065967f809f864c492b5bfcc325ef4335 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Oct 2021 13:37:05 +0200 Subject: [PATCH 4/5] Demo Mode at UI improved wit localhost allowed --- .../TradingSessionFunctions.js | 18 ++++++++----- .../UI/Function-Libraries/TaskFunctions.js | 16 +++++++----- .../LearningSessionFunctions.js | 26 +++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js b/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js index a8ef566a9..1a3d66ec7 100644 --- a/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js +++ b/Projects/Algorithmic-Trading/UI/Function-Libraries/TradingSessionFunctions.js @@ -44,9 +44,11 @@ function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() { function runSession(node, resume, callBackFunction) { if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Sessions.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let validationsResult = validations(node) @@ -171,7 +173,7 @@ function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() { let defaultExchange = UI.projects.visualScripting.utilities.nodeConfig.loadConfigProperty(validationsResult.exchange.payload, 'codeName') let defaultMarket = UI.projects.visualScripting.utilities.nodeConfig.loadConfigProperty(validationsResult.market.baseAsset.payload.referenceParent.payload, 'codeName') - + '-' + + + '-' + UI.projects.visualScripting.utilities.nodeConfig.loadConfigProperty(validationsResult.market.quotedAsset.payload.referenceParent.payload, 'codeName') let dependencyFilter = UI.projects.foundations.functionLibraries.dependenciesFilter.createDependencyFilter( @@ -204,9 +206,11 @@ function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() { function stopSession(node, callBackFunction) { if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let validationsResult = validations(node) diff --git a/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js b/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js index 3f49b07e8..4e1884a41 100644 --- a/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js +++ b/Projects/Foundations/UI/Function-Libraries/TaskFunctions.js @@ -91,9 +91,11 @@ function newFoundationsFunctionLibraryTaskFunctions() { function runTask(node, isDebugging, callBackFunction) { if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Tasks.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not RUN Tasks.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let lanNetworkNode = validations(node) @@ -226,9 +228,11 @@ function newFoundationsFunctionLibraryTaskFunctions() { function stopTask(node, callBackFunction) { if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Tasks.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Tasks.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let lanNetworkNode = validations(node) diff --git a/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js b/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js index 0fefe9cda..bfd25b838 100644 --- a/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js +++ b/Projects/Machine-Learning/UI/Function-Libraries/LearningSessionFunctions.js @@ -42,11 +42,13 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { } function runSession(node, resume, callBackFunction) { - + if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not execute Sessions.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not execute Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let validationsResult = validations(node) @@ -81,13 +83,13 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { 'Layers API->Core API->' + 'Sequential Model->Functional Model->' + 'Data Reporting->' + - 'Input Layer->Sequential layer->Output Layer->'+ + 'Input Layer->Sequential layer->Output Layer->' + 'Input Features->Data Feature->Feature Formula->Input Shape->Batch Input Shape->Feature Preprocessing->MinMax Scaler->Standard Scaler->Collection Condition->' + 'Output Labels->Data Label->Label Formula->' + 'Advanced Activation Layers->Basic Layers->Convolutional Layers->' + 'Conv 1D Layer->Conv 2D Layer->Conv 2D Transpose Layer->Conv 3D Layer->Cropping 2D Layer->Depthwise Convo 2D Layer->Separable Convo 2D Layer->Up Sampling 2D Layer->' + 'Activation Layer->Dense Layer->Dropout Layer->Embedding Layer->Flatten Layer->Permutable Layer->Rrepeat Vector Layer->Reshape Layer->Spatial Dropout 1D Layer->' + - 'Elu Layer->Leaky Relu Layer->Prelu Layer->Relu Layer->Softmax Layer->Thresholded Relu Layer->'+ + 'Elu Layer->Leaky Relu Layer->Prelu Layer->Relu Layer->Softmax Layer->Thresholded Relu Layer->' + 'Dimensionality Units->Activation Function->Dtype->Trainable->Weights->Tensor->Kernel->Bias->' + 'Kernel Initializer->Kernel Constraint->Kernel Regularizer->' + 'Bias Initializer->Bias Constraint->Bias Regularizer->' @@ -128,8 +130,8 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { 'Serial Number->Identifier->Begin->End->Begin Rate->End Rate->Strategy Name->Status->Exit Type->' + 'Balance->Begin Balance->End Balance->' + 'Index->Situation Name->Formula->Periods->' + - 'Features->Feature->Begin->End->Feature Value->'+ - 'Labels->Label->Begin->End->Label Value->'+ + 'Features->Feature->Begin->End->Feature Value->' + + 'Labels->Label->Begin->End->Label Value->' + 'Predictions->Prediction->Begin->End->Prediction Value->' let learningEngine = UI.projects.visualScripting.functionLibraries.protocolNode.getProtocolNode(node.learningEngineReference.payload.referenceParent, false, true, true, false, false, lightingPath) @@ -178,9 +180,11 @@ function newMachineLearningFunctionLibraryLearningSessionFunctions() { function stopSession(node, callBackFunction) { if (UI.environment.DEMO_MODE === true) { - node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return + if (window.location.hostname !== 'localhost') { + node.payload.uiObject.setWarningMessage('Superalgos is running is DEMO MODE. This means that you can not STOP Sessions.', 5) + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } } let validationsResult = validations(node) From 27c7c8ea0b6e9ffd29220ad3ac1ed6a995c02b73 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Oct 2021 14:56:03 +0200 Subject: [PATCH 5/5] Hackers protection at websockets level --- Environment.js | 2 +- Platform/Client/eventServer.js | 3 -- Platform/Client/webSocketsInterface.js | 39 ++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Environment.js b/Environment.js index 98bcecd46..47627f378 100644 --- a/Environment.js +++ b/Environment.js @@ -8,7 +8,7 @@ if (process.env.PACKAGED_PATH) { exports.newEnvironment = function () { let thisObject = { - DEMO_MODE: true, + DEMO_MODE: false, BASE_PATH: basePath, WEB_SERVER_URL: 'localhost', PLATFORM_WEB_SOCKETS_INTERFACE_PORT: 18041, diff --git a/Platform/Client/eventServer.js b/Platform/Client/eventServer.js index 7b3067777..dd34a53e7 100644 --- a/Platform/Client/eventServer.js +++ b/Platform/Client/eventServer.js @@ -1,8 +1,5 @@ exports.newEventServer = function newEventServer() { - const MODULE = "Events Server" - const LOG_INFO = false - let thisObject = { initialize: initialize, finalize: finalize, diff --git a/Platform/Client/webSocketsInterface.js b/Platform/Client/webSocketsInterface.js index 5797173da..6159d840b 100644 --- a/Platform/Client/webSocketsInterface.js +++ b/Platform/Client/webSocketsInterface.js @@ -9,7 +9,7 @@ const WEB_SOCKET = SA.nodeModules.ws let socketServer - let port = global.env.PLATFORM_WEB_SOCKETS_INTERFACE_PORT + let port = global.env.PLATFORM_WEB_SOCKETS_INTERFACE_PORT return thisObject @@ -36,13 +36,42 @@ socket.on('message', onMenssage) - function onMenssage(message){ + function onMenssage(message) { try { - if (LOG_INFO === true) { - console.log('Message Received: ' + message.substring(0, 1000)) + if (global.env.DEMO_MODE === true) { + /* + In DEMO MODE we will accept Task / Sessioins Running or Stopping if you are requesting this from localhost only. + */ + if (socket._socket.remoteAddress !== "::1") { + if ( + message.toString().indexOf('"eventType":"Run Task"') >= 0 + || + message.toString().indexOf('"eventType":"Stop Task"') >= 0 + || + message.toString().indexOf('"eventType":"Run Trading Session"') >= 0 + || + message.toString().indexOf('"eventType":"Stop Trading Session"') >= 0 + || + message.toString().indexOf('"eventType":"Resume Trading Session"') >= 0 + || + message.toString().indexOf('"eventType":"Run Learning Session"') >= 0 + || + message.toString().indexOf('"eventType":"Stop Learning Session"') >= 0 + || + message.toString().indexOf('"eventType":"Resume Learning Session"') >= 0 + ) { + console.log('Trying to execute a Task while in DEMO MODE. Some hacking has taken place!') + console.log('Hacker IP Address is: ' + socket._socket.remoteAddress) + return + } + } } - + + if (LOG_INFO === true) { + console.log('Message Received: ' + message.toString().substring(0, 10000)) + } + let messageArray = message.toString().split('|*|') let origin = messageArray[0]