From 7880f3348c4d8662df05726ef0a780fe6f12d339 Mon Sep 17 00:00:00 2001 From: Shalitha Suranga Date: Sun, 22 Sep 2019 10:13:31 +0530 Subject: [PATCH] Add debug log support for linux --- core-linux/bin/app/assets/neutralino.js | 2 +- core-linux/build.sh | 2 +- core-linux/src/core/debug/debug.cpp | 59 +++++++++++++++++++++++++ core-linux/src/core/debug/debug.h | 40 +++++++++++++++++ core-linux/src/router.cpp | 5 +++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 core-linux/src/core/debug/debug.cpp create mode 100644 core-linux/src/core/debug/debug.h diff --git a/core-linux/bin/app/assets/neutralino.js b/core-linux/bin/app/assets/neutralino.js index 70702d68..a27783be 100644 --- a/core-linux/bin/app/assets/neutralino.js +++ b/core-linux/bin/app/assets/neutralino.js @@ -1 +1 @@ -var Neutralino=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){let o=n(3);e.exports={ajax:function(e){e.method||(e.method=!0);var t=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");t.onreadystatechange=function(){4==t.readyState&&200==t.status?e.done&&e.done(JSON.parse(t.responseText)):4==t.readyState&&e.problem&&e.problem({message:"An error occured while connecting with Neutralino server!"})},void 0!==e.data&&(sendString=JSON.stringify(e.data)),"GET"==e.type&&(t.open("GET",e.url,e.method),t.setRequestHeader("Authorization","Basic "+o.getToken()),t.send()),"POST"==e.type&&(t.open("POST",e.url,e.method),t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.setRequestHeader("Authorization","Basic "+o.getToken()),t.send(sendString))}}},function(e,t,n){let o=n(2),r=n(4),a=n(5),i=n(6),u=n(7),c=n(8);e.exports={filesystem:o,settings:r,os:a,computer:i,storage:u,init:c}},function(e,t,n){let o=n(0);e.exports={createDirectory:function(e,t,n){o.ajax({url:"/filesystem/createDirectory",type:"POST",data:{dir:e},done:function(e){t(e)},problem:function(e){n(e)}})},removeDirectory:function(e,t,n){o.ajax({url:"/filesystem/removeDirectory",type:"POST",data:{dir:e},done:function(e){t(e)},problem:function(e){n(e)}})},writeFile:function(e,t,n,r){o.ajax({url:"/filesystem/writeFile",type:"POST",data:{filename:e,content:t},done:function(e){n(e)},problem:function(e){r(e)}})},readFile:function(e,t,n){o.ajax({url:"/filesystem/readFile",type:"POST",data:{filename:e},done:function(e){t(e)},problem:function(e){n(e)}})},removeFile:function(e,t,n){o.ajax({url:"/filesystem/removeFile",type:"POST",data:{filename:e},done:function(e){t(e)},problem:function(e){n(e)}})},readDirectory:function(e,t,n){o.ajax({url:"/filesystem/readDirectory",type:"POST",data:{path:e},done:function(e){t(e)},problem:function(e){n(e)}})}}},function(e,t){e.exports={getToken:function(){return NL_TOKEN}}},function(e,t,n){let o=n(0);e.exports={getSettings:function(e,t){o.ajax({url:"/settings.json",type:"GET",done:function(t){e(t)},problem:function(e){t(e)}})}}},function(e,t,n){let o=n(0);e.exports={runCommand:function(e,t,n){o.ajax({url:"/os/runCommand",type:"POST",data:{command:e},done:function(e){t(e)},problem:function(e){n(e)}})},getEnvar:function(e,t,n){o.ajax({url:"/os/getEnvar",type:"POST",data:{name:e},done:function(e){t(e)},problem:function(e){n(e)}})},dialogOpen:function(e,t,n){o.ajax({url:"/os/dialogOpen",type:"POST",data:{title:e},done:function(e){t(e)},problem:function(e){n(e)}})},dialogSave:function(e,t,n){o.ajax({url:"/os/dialogSave",type:"POST",data:{title:e},done:function(e){t(e)},problem:function(e){n(e)}})}}},function(e,t,n){let o=n(0);e.exports={getRamUsage:function(e,t){o.ajax({url:"/computer/getRamUsage",type:"GET",done:function(t){e(t)},problem:function(e){t(e)}})}}},function(e,t,n){let o=n(0);e.exports={putData:function(e,t,n){o.ajax({url:"/storage/putData",type:"POST",data:{bucket:e.bucket,content:e.content},done:function(e){t(e)},problem:function(e){n(e)}})},getData:function(e,t,n){o.ajax({url:"/storage/getData",type:"POST",data:{bucket:e},done:function(e){t(JSON.parse(e.content))},problem:function(e){n(e)}})}}},function(e,t,n){let o=n(9);e.exports=function(e){let t=null,n=null;e.load&&e.load(),e.pingSuccessCallback&&(t=e.pingSuccessCallback),e.pingFailCallback&&(n=e.pingFailCallback),"browser"==NL_MODE&&o.start(t,n)}},function(e,t,n){let o=n(0),r={start:function(e,t){setInterval(function(){o.ajax({url:"/ping",type:"GET",success:function(t){e&&e()},errorCallback:function(){t&&t()}})},5e3)}};e.exports=r}]); \ No newline at end of file +var Neutralino=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){let o=n(3);e.exports={ajax:function(e){e.method||(e.method=!0);var t=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");t.onreadystatechange=function(){4==t.readyState&&200==t.status?e.done&&e.done(JSON.parse(t.responseText)):4==t.readyState&&e.problem&&e.problem({message:"An error occured while connecting with Neutralino server!"})},void 0!==e.data&&(sendString=JSON.stringify(e.data)),"GET"==e.type&&(t.open("GET",e.url,e.method),t.setRequestHeader("Authorization","Basic "+o.getToken()),t.send()),"POST"==e.type&&(t.open("POST",e.url,e.method),t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.setRequestHeader("Authorization","Basic "+o.getToken()),t.send(sendString))}}},function(e,t,n){let o=n(2),r=n(4),a=n(5),i=n(6),u=n(7),c=n(8),l=n(9);e.exports={filesystem:o,settings:r,os:a,computer:i,storage:u,debug:c,init:l}},function(e,t,n){let o=n(0);e.exports={createDirectory:function(e,t,n){o.ajax({url:"/filesystem/createDirectory",type:"POST",data:{dir:e},done:function(e){t(e)},problem:function(e){n(e)}})},removeDirectory:function(e,t,n){o.ajax({url:"/filesystem/removeDirectory",type:"POST",data:{dir:e},done:function(e){t(e)},problem:function(e){n(e)}})},writeFile:function(e,t,n,r){o.ajax({url:"/filesystem/writeFile",type:"POST",data:{filename:e,content:t},done:function(e){n(e)},problem:function(e){r(e)}})},readFile:function(e,t,n){o.ajax({url:"/filesystem/readFile",type:"POST",data:{filename:e},done:function(e){t(e)},problem:function(e){n(e)}})},removeFile:function(e,t,n){o.ajax({url:"/filesystem/removeFile",type:"POST",data:{filename:e},done:function(e){t(e)},problem:function(e){n(e)}})},readDirectory:function(e,t,n){o.ajax({url:"/filesystem/readDirectory",type:"POST",data:{path:e},done:function(e){t(e)},problem:function(e){n(e)}})}}},function(e,t){e.exports={getToken:function(){return NL_TOKEN}}},function(e,t,n){let o=n(0);e.exports={getSettings:function(e,t){o.ajax({url:"/settings.json",type:"GET",done:function(t){e(t)},problem:function(e){t(e)}})}}},function(e,t,n){let o=n(0);e.exports={runCommand:function(e,t,n){o.ajax({url:"/os/runCommand",type:"POST",data:{command:e},done:function(e){t(e)},problem:function(e){n(e)}})},getEnvar:function(e,t,n){o.ajax({url:"/os/getEnvar",type:"POST",data:{name:e},done:function(e){t(e)},problem:function(e){n(e)}})},dialogOpen:function(e,t,n){o.ajax({url:"/os/dialogOpen",type:"POST",data:{title:e},done:function(e){t(e)},problem:function(e){n(e)}})},dialogSave:function(e,t,n){o.ajax({url:"/os/dialogSave",type:"POST",data:{title:e},done:function(e){t(e)},problem:function(e){n(e)}})}}},function(e,t,n){let o=n(0);e.exports={getRamUsage:function(e,t){o.ajax({url:"/computer/getRamUsage",type:"GET",done:function(t){e(t)},problem:function(e){t(e)}})}}},function(e,t,n){let o=n(0);e.exports={putData:function(e,t,n){o.ajax({url:"/storage/putData",type:"POST",data:{bucket:e.bucket,content:e.content},done:function(e){t(e)},problem:function(e){n(e)}})},getData:function(e,t,n){o.ajax({url:"/storage/getData",type:"POST",data:{bucket:e},done:function(e){t(JSON.parse(e.content))},problem:function(e){n(e)}})}}},function(e,t,n){let o=n(0);e.exports={log:function(e,t,n,r){o.ajax({url:"/debug/log",type:"POST",data:{type:e,message:t},done:function(e){n(e)},problem:function(e){r(e)}})}}},function(e,t,n){let o=n(10);e.exports=function(e){let t=null,n=null;e.load&&e.load(),e.pingSuccessCallback&&(t=e.pingSuccessCallback),e.pingFailCallback&&(n=e.pingFailCallback),"browser"==NL_MODE&&o.start(t,n)}},function(e,t,n){let o=n(0),r={start:function(e,t){setInterval(function(){o.ajax({url:"/ping",type:"GET",success:function(t){e&&e()},errorCallback:function(){t&&t()}})},5e3)}};e.exports=r}]); \ No newline at end of file diff --git a/core-linux/build.sh b/core-linux/build.sh index c33f23ea..6dfa140b 100644 --- a/core-linux/build.sh +++ b/core-linux/build.sh @@ -26,7 +26,7 @@ if [ -e bin/neutralino ]; then rm bin/neutralino fi -g++ -I ../core-shared -std=c++14 ../core-shared/log.cpp src/Buffer.cpp src/Handler.cpp src/requestparser.cpp src/Socket.cpp src/functions.cpp src/main.cpp src/router.cpp src/core/filesystem/filesystem.cpp src/settings.cpp src/core/os/os.cpp src/core/computer/computer.cpp src/auth/authbasic.cpp src/ping/ping.cpp src/core/storage/storage.cpp src/cloud/previleges.cpp -pthread -std=c++14 -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o bin/neutralino -no-pie -lstdc++fs +g++ -I ../core-shared -std=c++14 ../core-shared/log.cpp src/Buffer.cpp src/Handler.cpp src/requestparser.cpp src/Socket.cpp src/functions.cpp src/main.cpp src/router.cpp src/core/filesystem/filesystem.cpp src/settings.cpp src/core/os/os.cpp src/core/computer/computer.cpp src/core/debug/debug.cpp src/auth/authbasic.cpp src/ping/ping.cpp src/core/storage/storage.cpp src/cloud/previleges.cpp -pthread -std=c++14 -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o bin/neutralino -no-pie -lstdc++fs if [ -e bin/neutralino ]; then echo "Neutralino binary is compiled in to bin/netralino" diff --git a/core-linux/src/core/debug/debug.cpp b/core-linux/src/core/debug/debug.cpp new file mode 100644 index 00000000..9486690b --- /dev/null +++ b/core-linux/src/core/debug/debug.cpp @@ -0,0 +1,59 @@ +// MIT License + +// Copyright (c) 2018 Neutralinojs + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include "../../../lib/json/json.hpp" +#include "../../settings.h" +#include "../core-shared/log.h" + +using namespace std; +using json = nlohmann::json; + +namespace debug { + string log(string jso) { + json input; + json output; + try { + input = json::parse(jso); + } + catch(exception e){ + output["error"] = "JSON parse error is occurred!"; + return output.dump(); + } + string type = input["type"].get(); + string message = input["message"].get(); + + if(type == "INFO") + INFO() << message; + else if(type == "ERROR") + ERROR() << message; + else if(type == "WARN") + WARN() << message; + else + DEBUG() << message; + + output["message"] = "Wrote to log file neutralino.log"; + return output.dump(); + } + +} \ No newline at end of file diff --git a/core-linux/src/core/debug/debug.h b/core-linux/src/core/debug/debug.h new file mode 100644 index 00000000..63a2de97 --- /dev/null +++ b/core-linux/src/core/debug/debug.h @@ -0,0 +1,40 @@ +// MIT License + +// Copyright (c) 2018 Neutralinojs + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#ifndef DEBUG_H +#define DEBUG_H + +#include +#include + +using namespace std; + +namespace debug { + string log(string jso); + + typedef string (*pfunc)(string); + + map funcmap = { + {"debug.log", debug::log} + }; +} + +#endif \ No newline at end of file diff --git a/core-linux/src/router.cpp b/core-linux/src/router.cpp index bb6f8790..ed678b52 100644 --- a/core-linux/src/router.cpp +++ b/core-linux/src/router.cpp @@ -31,6 +31,7 @@ #include "core/os/os.h" #include "core/computer/computer.h" #include "core/storage/storage.h" +#include "core/debug/debug.h" #include "../lib/json/json.hpp" #include "auth/authbasic.h" #include "ping/ping.h" @@ -116,6 +117,10 @@ namespace routes { pfunc f = storage::funcmap[modfunc]; output = (*f)(j); } + else if(debug::funcmap.find(modfunc) != debug::funcmap.end() ){ + pfunc f = debug::funcmap[modfunc]; + output = (*f)(j); + } else { json o = {{"error", modfunc + " is not supported"}}; output = o.dump();