From ee14dbda74ebcbd043e26004d1f7d7a46be07fa0 Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Thu, 23 Nov 2023 20:21:14 +1100 Subject: [PATCH 1/4] update findValue --- .../src/components/ListLog/ListLog.jsx | 2 +- start/routes.ts | 23 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/manage-view/src/components/ListLog/ListLog.jsx b/manage-view/src/components/ListLog/ListLog.jsx index 5f6237d..5d099aa 100644 --- a/manage-view/src/components/ListLog/ListLog.jsx +++ b/manage-view/src/components/ListLog/ListLog.jsx @@ -11,7 +11,7 @@ const ListLog = () => { const [value, setValue] = useState(""); const getListFile = async () => { try { - const res = await axios.get(getListLog); + const res = await axios.get(getListLog,{value: value}); setListFile(res.data); setStatus(res.status); } catch (error) { diff --git a/start/routes.ts b/start/routes.ts index 2e12ec2..a95c086 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -30,7 +30,8 @@ import { sendDeviceInfora } from "App/utils/sendDeviceInfor"; import InfoDevice from "App/Models/InfoDevice"; import LogReport from "App/Models/LogReport"; import Cache from "@ioc:Kaperskyguru/Adonis-Cache"; -import { exec } from 'child_process'; +const util = require('util'); +const exec = util.promisify(require('child_process').exec); runtimeCheckLogs(Env.get("FOLDER_LOGS")); @@ -179,23 +180,17 @@ Route.post("/api/private-log/readFile", async ({ request, response }) => { Route.post("/api/find-value", async ({ request, response }) => { try { - let result = ""; - let value = request.all().value; - console.log("value ", value) + const { value } = request.all(); - exec("grep -nr "+value+" /home/logs", (error, stdout, stderr) => { - if (error) { - // console.error(`Error executing command: ${error.message}`); - return "Error:"+ error; - } - console.log("stdout ", stdout) + const { stdout, stderr } = await exec(`grep -nr "${value}" /home/logs`); - response.status(300).send("blabla"+JSON.stringify(stdout) ); - }); + + response.status(200).send(JSON.stringify(stdout)); } catch (error) { - console.log(error); + console.error(error); + response.status(500).send(`Error: ${error.message}`); } -}) +}); Route.post("/api/test", async () => { try { From 3a377f9f25017c5424deae7c59de3a3eccb38493 Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Thu, 23 Nov 2023 20:21:59 +1100 Subject: [PATCH 2/4] update findValue --- .gitconfig | 3 --- .gitignore | 2 +- skip | 0 3 files changed, 1 insertion(+), 4 deletions(-) create mode 100644 skip diff --git a/.gitconfig b/.gitconfig index ef3a38f..f27da43 100644 --- a/.gitconfig +++ b/.gitconfig @@ -1,6 +1,3 @@ [safe] directory = /home/Log_service/ -<<<<<<< HEAD directory = /home/Log_service/ -======= ->>>>>>> 33b850875e644a9a1c9a0b988004d95d5e503573 diff --git a/.gitignore b/.gitignore index 3cf3718..d84c174 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules build -coverage + .vscode .DS_STORE .env diff --git a/skip b/skip new file mode 100644 index 0000000..e69de29 From ecf5cc4ccff813e5ae238cd1290a12b17a96365c Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Thu, 23 Nov 2023 20:29:55 +1100 Subject: [PATCH 3/4] update findValue --- manage-view/src/components/ListLog/ListLog.jsx | 4 ++-- start/routes.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/manage-view/src/components/ListLog/ListLog.jsx b/manage-view/src/components/ListLog/ListLog.jsx index 5d099aa..7e70f23 100644 --- a/manage-view/src/components/ListLog/ListLog.jsx +++ b/manage-view/src/components/ListLog/ListLog.jsx @@ -11,7 +11,7 @@ const ListLog = () => { const [value, setValue] = useState(""); const getListFile = async () => { try { - const res = await axios.get(getListLog,{value: value}); + const res = await axios.get(getListLog); setListFile(res.data); setStatus(res.status); } catch (error) { @@ -21,7 +21,7 @@ const ListLog = () => { const findValueInLog = async () =>{ try { - const res = await axios.post(findValue); + const res = await axios.post(findValue,{value: value}); setValue(res.data) } catch (error) { diff --git a/start/routes.ts b/start/routes.ts index a95c086..11d4529 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -182,6 +182,7 @@ Route.post("/api/find-value", async ({ request, response }) => { try { const { value } = request.all(); + console.log(value) const { stdout, stderr } = await exec(`grep -nr "${value}" /home/logs`); From e4f4f54dbbc88eabbfab5db69aa0c46a6c46f4f5 Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Thu, 23 Nov 2023 20:37:11 +1100 Subject: [PATCH 4/4] update findValue --- manage-view/src/components/ListLog/ListLog.jsx | 2 +- start/routes.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manage-view/src/components/ListLog/ListLog.jsx b/manage-view/src/components/ListLog/ListLog.jsx index 7e70f23..6720695 100644 --- a/manage-view/src/components/ListLog/ListLog.jsx +++ b/manage-view/src/components/ListLog/ListLog.jsx @@ -21,7 +21,7 @@ const ListLog = () => { const findValueInLog = async () =>{ try { - const res = await axios.post(findValue,{value: value}); + const res = await axios.post(findValue,{value: valueSearch}); setValue(res.data) } catch (error) { diff --git a/start/routes.ts b/start/routes.ts index 11d4529..ae423bc 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -183,9 +183,9 @@ Route.post("/api/find-value", async ({ request, response }) => { const { value } = request.all(); console.log(value) - const { stdout, stderr } = await exec(`grep -nr "${value}" /home/logs`); + const { stdout, stderr } = await exec(`grep -nr "${value}" /home/logs`,{maxBuffer: 1024 * 500}); - + // response.status(200).send("sdjkghs"); response.status(200).send(JSON.stringify(stdout)); } catch (error) { console.error(error);