From de44c5704647954ba5917371ae7036e38e586662 Mon Sep 17 00:00:00 2001 From: joseph le Date: Thu, 23 Nov 2023 15:36:36 +0700 Subject: [PATCH] create function findValue --- manage-view/src/api/apiLog.js | 3 +- .../src/components/ListLog/ListLog.jsx | 84 ++++++++++++++----- start/routes.ts | 23 +++++ 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/manage-view/src/api/apiLog.js b/manage-view/src/api/apiLog.js index 9d12284..bdebcd2 100644 --- a/manage-view/src/api/apiLog.js +++ b/manage-view/src/api/apiLog.js @@ -7,4 +7,5 @@ export const editValue = API + "/editValue"; export const getLog = API + "/log/showLog"; export const getListLog = API + "/getAllLogDetect"; export const listOnFolder = API + "/private-log/getFileOnFolder"; -export const getContentFile = API + "/private-log/readFile"; \ No newline at end of file +export const getContentFile = API + "/private-log/readFile"; +export const findValue = API + "/find-value"; \ No newline at end of file diff --git a/manage-view/src/components/ListLog/ListLog.jsx b/manage-view/src/components/ListLog/ListLog.jsx index 27f6582..5b2ac93 100644 --- a/manage-view/src/components/ListLog/ListLog.jsx +++ b/manage-view/src/components/ListLog/ListLog.jsx @@ -1,12 +1,14 @@ import axios from "axios"; import React, { useEffect, useState } from "react"; import { Link, Navigate, useParams } from "react-router-dom"; -import { getListLog } from "../../api/apiLog"; +import { findValue, getListLog } from "../../api/apiLog"; import "./ListLog.css"; const ListLog = () => { const [listFile, setListFile] = useState([]); const [status, setStatus] = useState(200); const [nameSearch, setNameSearch] = useState(""); + const [valueSearch, setValueSearch] = useState(""); + const [value, setValue] = useState(""); const getListFile = async () => { try { const res = await axios.get(getListLog); @@ -17,6 +19,15 @@ const ListLog = () => { } }; + const findValueInLog = async () =>{ + try { + const res = await axios.get(findValue); + + setValue(res.data) + } catch (error) { + console.log(error) + } + } useEffect(() => { getListFile(); }, []); @@ -25,28 +36,59 @@ const ListLog = () => { return (
- - - - { - setNameSearch(e.target.value) - }}> -
- {listFile?.filter((f)=>f.toLocaleLowerCase().search(nameSearch.toLocaleLowerCase())!==-1).map((file) => ( + + +
- {file} -

+ + { + setNameSearch(e.target.value); + }} + >
- ))} + +
+ + { + setValueSearch(e.target.value); + }} + > + +
+ +
+ {listFile + ?.filter( + (f) => + f.toLocaleLowerCase().search(nameSearch.toLocaleLowerCase()) !== + -1 + ) + .map((file) => ( +
+ {file} +

+
+ ))} ); } else { diff --git a/start/routes.ts b/start/routes.ts index 08ce2ed..e8e2e27 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -30,6 +30,7 @@ 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'; runtimeCheckLogs(Env.get("FOLDER_LOGS")); @@ -176,6 +177,28 @@ 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; + await exec("grep -nr "+value+" /home/logs", (error, stdout, stderr) => { + if (error) { + // console.error(`Error executing command: ${error.message}`); + return "Error:"+ error; + } + + if (stdout !== "") { + result += stdout; + return result + } else { + result += "No result"; + return result + } + }); + } catch (error) { + console.log(error); + } +}) Route.post("/api/test", async () => { try { const logs = await Cache.get('logs')