create function findValue
This commit is contained in:
parent
10d1bb5bed
commit
de44c57046
|
|
@ -7,4 +7,5 @@ export const editValue = API + "/editValue";
|
||||||
export const getLog = API + "/log/showLog";
|
export const getLog = API + "/log/showLog";
|
||||||
export const getListLog = API + "/getAllLogDetect";
|
export const getListLog = API + "/getAllLogDetect";
|
||||||
export const listOnFolder = API + "/private-log/getFileOnFolder";
|
export const listOnFolder = API + "/private-log/getFileOnFolder";
|
||||||
export const getContentFile = API + "/private-log/readFile";
|
export const getContentFile = API + "/private-log/readFile";
|
||||||
|
export const findValue = API + "/find-value";
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Link, Navigate, useParams } from "react-router-dom";
|
import { Link, Navigate, useParams } from "react-router-dom";
|
||||||
import { getListLog } from "../../api/apiLog";
|
import { findValue, getListLog } from "../../api/apiLog";
|
||||||
import "./ListLog.css";
|
import "./ListLog.css";
|
||||||
const ListLog = () => {
|
const ListLog = () => {
|
||||||
const [listFile, setListFile] = useState([]);
|
const [listFile, setListFile] = useState([]);
|
||||||
const [status, setStatus] = useState(200);
|
const [status, setStatus] = useState(200);
|
||||||
const [nameSearch, setNameSearch] = useState("");
|
const [nameSearch, setNameSearch] = useState("");
|
||||||
|
const [valueSearch, setValueSearch] = useState("");
|
||||||
|
const [value, setValue] = useState("");
|
||||||
const getListFile = async () => {
|
const getListFile = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(getListLog);
|
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(() => {
|
useEffect(() => {
|
||||||
getListFile();
|
getListFile();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -25,28 +36,59 @@ const ListLog = () => {
|
||||||
return (
|
return (
|
||||||
<div className="mainList">
|
<div className="mainList">
|
||||||
<div className="inputSearch">
|
<div className="inputSearch">
|
||||||
<Link to={"/"}>
|
<Link to={"/"}>
|
||||||
<button
|
<button
|
||||||
style={{
|
style={{
|
||||||
color: "white",
|
color: "white",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
float:"left"
|
float: "left",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Home
|
Home
|
||||||
</button></Link>
|
</button>
|
||||||
<label>Search: </label>
|
</Link>
|
||||||
<input value={nameSearch} placeholder={"Enter a file name"} onChange={(e)=>{
|
|
||||||
setNameSearch(e.target.value)
|
|
||||||
}}></input>
|
|
||||||
</div>
|
|
||||||
{listFile?.filter((f)=>f.toLocaleLowerCase().search(nameSearch.toLocaleLowerCase())!==-1).map((file) => (
|
|
||||||
<div>
|
<div>
|
||||||
<Link to={"/logs/" + file}>{file}</Link>
|
<label>Search file name: </label>
|
||||||
<br></br>
|
<input
|
||||||
|
value={nameSearch}
|
||||||
|
placeholder={"Enter a file name"}
|
||||||
|
onChange={(e) => {
|
||||||
|
setNameSearch(e.target.value);
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
</div>
|
</div>
|
||||||
))}
|
|
||||||
|
<div>
|
||||||
|
<label>Search value: </label>
|
||||||
|
<input
|
||||||
|
value={valueSearch}
|
||||||
|
placeholder={"Enter value"}
|
||||||
|
onChange={(e) => {
|
||||||
|
setValueSearch(e.target.value);
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
|
<button style={{backgroundColor:"#6cff00", cursor:"pointer"}} onClick={()=>findValueInLog()}>Run</button>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
style={{ height: "90vh", width: "50%", backgroundColor: "black", float:"right", color:"#6cff00", padding:10, display:value!==""?"block":"none" }}
|
||||||
|
value={value}
|
||||||
|
>
|
||||||
|
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
{listFile
|
||||||
|
?.filter(
|
||||||
|
(f) =>
|
||||||
|
f.toLocaleLowerCase().search(nameSearch.toLocaleLowerCase()) !==
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
.map((file) => (
|
||||||
|
<div>
|
||||||
|
<Link to={"/logs/" + file}>{file}</Link>
|
||||||
|
<br></br>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import { sendDeviceInfora } from "App/utils/sendDeviceInfor";
|
||||||
import InfoDevice from "App/Models/InfoDevice";
|
import InfoDevice from "App/Models/InfoDevice";
|
||||||
import LogReport from "App/Models/LogReport";
|
import LogReport from "App/Models/LogReport";
|
||||||
import Cache from "@ioc:Kaperskyguru/Adonis-Cache";
|
import Cache from "@ioc:Kaperskyguru/Adonis-Cache";
|
||||||
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
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 () => {
|
Route.post("/api/test", async () => {
|
||||||
try {
|
try {
|
||||||
const logs = await Cache.get('logs')
|
const logs = await Cache.get('logs')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue