');function sr(){Rt(()=>{Dn()});const e=qt(()=>Zt(()=>import("./HostPage-BkN2pMDv.js"),[]));return(()=>{var t=rr(),n=t.firstChild,r=n.firstChild;return O(r,I(An,{get children(){return[I(We,{path:"/",component:nr}),I(We,{path:"/host/:id",component:e})]}})),t})()}const or=document.getElementById("root");Gt(()=>I(sr,{}),or);export{ct as F,L as a,Q as b,gr as c,Ge as d,ur as e,z as f,R as g,I as h,O as i,fr as j,cr as k,pr as l,Rt as o,Ke as s,j as t,ar as u};
diff --git a/backend/internal/web/templates/header.html b/backend/internal/web/templates/header.html
index 1d2cd2a..ae1ee75 100644
--- a/backend/internal/web/templates/header.html
+++ b/backend/internal/web/templates/header.html
@@ -40,10 +40,10 @@
Home
- Config
+ Config
- History
+ History
diff --git a/backend/internal/web/webgui.go b/backend/internal/web/webgui.go
index 908fb6d..616c3e4 100644
--- a/backend/internal/web/webgui.go
+++ b/backend/internal/web/webgui.go
@@ -57,8 +57,8 @@ func Gui(dirPath, nodePath string) {
router.GET("/", indexHandler) // index.go
router.GET("/history/", historyHandler) // index.go
- router.GET("/host/:id", hostHandler) // host.go
- router.GET("/config/", configHandler) // config.go
+ // router.GET("/host/:id", hostHandler) // host.go
+ router.GET("/config/", configHandler) // config.go
router.POST("/config/", saveConfigHandler) // config.go
router.POST("/config_settings/", saveSettingsHandler) // config.go
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 93c91c4..a31590e 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -8,6 +8,7 @@
"name": "watchyourlan",
"version": "0.0.0",
"dependencies": {
+ "@solidjs/router": "^0.15.3",
"solid-js": "^1.9.5"
},
"devDependencies": {
@@ -963,6 +964,14 @@
"win32"
]
},
+ "node_modules/@solidjs/router": {
+ "version": "0.15.3",
+ "resolved": "https://registry.npmjs.org/@solidjs/router/-/router-0.15.3.tgz",
+ "integrity": "sha512-iEbW8UKok2Oio7o6Y4VTzLj+KFCmQPGEpm1fS3xixwFBdclFVBvaQVeibl1jys4cujfAK5Kn6+uG2uBm3lxOMw==",
+ "peerDependencies": {
+ "solid-js": "^1.8.6"
+ }
+ },
"node_modules/@types/babel__core": {
"version": "7.20.5",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index 742ba36..4f48039 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -9,6 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
+ "@solidjs/router": "^0.15.3",
"solid-js": "^1.9.5"
},
"devDependencies": {
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index f577cbb..10ce092 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -1,22 +1,26 @@
-import { onMount } from 'solid-js';
-import './App.css'
-import { apiGetAllHosts } from './functions/api';
-import { setAllHosts } from './functions/exports';
-import Body from './pages/Body'
+import { lazy, onMount } from 'solid-js';
+import { Router, Route } from "@solidjs/router";
+import './App.css';
+import { runAtStart } from './functions/atstart';
+
+import Body from './pages/Body';
function App() {
- onMount(async () => {
-
- const hosts = await apiGetAllHosts();
- setAllHosts(hosts);
+ onMount(() => {
+ runAtStart();
});
+ const HostPage = lazy(() => import("./pages/HostPage"));
+
return (
diff --git a/frontend/src/components/BodyCardHead.tsx b/frontend/src/components/BodyCardHead.tsx
new file mode 100644
index 0000000..7a6523b
--- /dev/null
+++ b/frontend/src/components/BodyCardHead.tsx
@@ -0,0 +1,28 @@
+import { Show } from "solid-js";
+import { editNames, setEditNames } from "../functions/exports";
+import Filter from "./Filter";
+import Search from "./Search";
+
+function BodyCardHead() {
+
+ return (
+
+
+
+
+
+
+
+ Edit names}
+ >
+ Edit names
+
+
+
+
+ )
+}
+
+export default BodyCardHead
diff --git a/frontend/src/components/CardHead.tsx b/frontend/src/components/CardHead.tsx
deleted file mode 100644
index 0e7cb88..0000000
--- a/frontend/src/components/CardHead.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { Show } from "solid-js";
-import { editNames, setEditNames } from "../functions/exports";
-
-function CardHead() {
-
- return (
-
-
- Edit names}
- >
- Edit names
-
-
-
- )
-}
-
-export default CardHead
diff --git a/frontend/src/components/Filter.tsx b/frontend/src/components/Filter.tsx
new file mode 100644
index 0000000..822fb3b
--- /dev/null
+++ b/frontend/src/components/Filter.tsx
@@ -0,0 +1,38 @@
+import { For } from "solid-js";
+import { Host, ifaces } from "../functions/exports";
+import { filterFunc } from "../functions/filter";
+
+
+function Filter() {
+
+ const handleFilter = (field: keyof Host, value: any) => {
+ filterFunc(field, value);
+ };
+
+ return (
+
+
+ Filter by
+
+ Iface
+ {(iface) =>
+ {handleFilter("Iface", iface)}}>{iface}
+ }
+
+
+ Known
+ {handleFilter("Known", 1)}}>Known
+ {handleFilter("Known", 0)}}>Unknown
+
+
+ Online
+ {handleFilter("Now", 1)}}>Online
+ {handleFilter("Now", 0)}}>Offline
+
+ {handleFilter("ID", 0)}} class="btn btn-outline-primary">Reset filter
+
+
+ )
+}
+
+export default Filter
diff --git a/frontend/src/components/HostPageHost.tsx b/frontend/src/components/HostPageHost.tsx
new file mode 100644
index 0000000..4ba0fa5
--- /dev/null
+++ b/frontend/src/components/HostPageHost.tsx
@@ -0,0 +1,101 @@
+import { apiDelHost, apiEditHost } from "../functions/api";
+import { currentHost } from "../functions/exports";
+
+function HostPageHost() {
+
+ let name:string = "";
+
+ const handleInput = async (n: string) => {
+
+ name = n;
+ await apiEditHost(currentHost().ID, name, '');
+ };
+
+ const handleToggle = async () => {
+
+ if (name == "") {
+ name = currentHost().Name;
+ }
+
+ await apiEditHost(currentHost().ID, name, 'toggle');
+ };
+
+ const handleDel = async () => {
+
+ await apiDelHost(currentHost().ID);
+ window.location.href = '/';
+ };
+
+ return (
+
+ )
+}
+
+export default HostPageHost
\ No newline at end of file
diff --git a/frontend/src/components/HostPagePing.tsx b/frontend/src/components/HostPagePing.tsx
new file mode 100644
index 0000000..0be37fd
--- /dev/null
+++ b/frontend/src/components/HostPagePing.tsx
@@ -0,0 +1,78 @@
+import { createSignal, For } from "solid-js";
+import { apiPortScan } from "../functions/api";
+import { currentHost } from "../functions/exports";
+
+
+function HostPagePing() {
+
+ let stop = false;
+
+ const [beginStr, setBegin] = createSignal("");
+ const [endStr, setEnd] = createSignal("");
+ const [curPort, setCurPort] = createSignal("");
+ const [foundPorts, setFoundPorts] = createSignal
([]);
+
+ const handleScan = async () => {
+ stop = false;
+
+ let begin = Number(beginStr());
+ if (Number.isNaN(begin) || begin < 1 || begin > 65535) {
+ begin = 1;
+ }
+ let end = Number(endStr());
+ if (Number.isNaN(end) || end < 1 || end > 65535) {
+ end = 65535;
+ }
+
+ let portOpened:boolean;
+ for (let i = begin ; i <= end; i++) {
+
+ if (stop) {
+ break;
+ }
+ setCurPort(i.toString());
+ portOpened = await apiPortScan(currentHost().IP, i);
+ if (portOpened) {
+ setFoundPorts([...foundPorts(), i]);
+ }
+ }
+ };
+
+ const handleStop = () => {
+ if (stop) {
+ setBegin(curPort());
+ handleScan();
+ } else {
+ stop = true;
+ }
+ }
+
+ return (
+
+
+
+
+ {curPort() != ""
+ ?
+
Stop/Continue
+
Scanning port: {curPort()}
+
+ : <>>
+ }
+
+
+
+ )
+}
+
+export default HostPagePing
\ No newline at end of file
diff --git a/frontend/src/components/Search.tsx b/frontend/src/components/Search.tsx
new file mode 100644
index 0000000..8b462e0
--- /dev/null
+++ b/frontend/src/components/Search.tsx
@@ -0,0 +1,14 @@
+import { searchFunc } from "../functions/search";
+
+function Search() {
+
+ const handleSearch = (s: string) => {
+ searchFunc(s);
+ };
+
+ return (
+ handleSearch(e.target.value)} class="form-control" placeholder="Search" style="max-width: 10em;">
+ )
+}
+
+export default Search
diff --git a/frontend/src/components/TableRow.tsx b/frontend/src/components/TableRow.tsx
index fdfa118..070ad10 100644
--- a/frontend/src/components/TableRow.tsx
+++ b/frontend/src/components/TableRow.tsx
@@ -7,6 +7,7 @@ function TableRow(_props: any) {
const [name, setName] = createSignal(_props.host.Name);
const link = "http://" + _props.host.IP;
+ const edit = "/host/" + _props.host.ID;
let now = ;
if (_props.host.Now == 1) {
@@ -51,7 +52,9 @@ function TableRow(_props: any) {
)
}
diff --git a/frontend/src/functions/api.ts b/frontend/src/functions/api.ts
index c79f743..4e679f0 100644
--- a/frontend/src/functions/api.ts
+++ b/frontend/src/functions/api.ts
@@ -12,5 +12,29 @@ export const apiEditHost = async (id:number, name:string, known:string) => {
const url = api+'/api/edit/'+id+'/'+name+'/'+known;
const res = await (await fetch(url)).json();
+ return res;
+};
+
+export const apiGetHost = async (id:string) => {
+
+ const url = api+'/api/host/'+id;
+ const res = await (await fetch(url)).json();
+
+ return res;
+};
+
+export const apiDelHost = async (id:number) => {
+
+ const url = api+'/api/host/del/'+id;
+ const res = await (await fetch(url)).json();
+
+ return res;
+};
+
+export const apiPortScan = async (ip:string, port:number) => {
+
+ const url = api+'/api/port/'+ip+'/'+port;
+ const res = await (await fetch(url)).json();
+
return res;
};
\ No newline at end of file
diff --git a/frontend/src/functions/atstart.ts b/frontend/src/functions/atstart.ts
new file mode 100644
index 0000000..2e9eefa
--- /dev/null
+++ b/frontend/src/functions/atstart.ts
@@ -0,0 +1,37 @@
+import { apiGetAllHosts } from "./api";
+import { allHosts, setAllHosts, setBkpHosts, setIfaces } from "./exports";
+import { filterAtStart, filterFunc } from "./filter";
+import { sortAtStart } from "./sort";
+
+export function runAtStart() {
+ getHosts();
+ filterFunc("ID", 0); // reset filter
+
+ setInterval(() => {
+ getHosts();
+ }, 60000); // 60000 ms = 1 minute
+}
+
+async function getHosts() {
+ const hosts = await apiGetAllHosts();
+ setAllHosts(hosts);
+ setBkpHosts(hosts);
+
+ sortAtStart();
+ filterAtStart();
+ listIfaces();
+ // console.log("UPD");
+}
+
+function listIfaces() {
+
+ let ifaces:string[] = [];
+
+ for (let host of allHosts()) {
+ if (!ifaces.includes(host.Iface)) {
+ ifaces.push(host.Iface);
+ }
+ }
+
+ setIfaces(ifaces);
+}
\ No newline at end of file
diff --git a/frontend/src/functions/exports.ts b/frontend/src/functions/exports.ts
index e1006a0..46f7d4a 100644
--- a/frontend/src/functions/exports.ts
+++ b/frontend/src/functions/exports.ts
@@ -13,17 +13,32 @@ export interface Host {
Now: number;
};
-export interface Conf {
- Color: string;
- Timeout: number;
+export const emptyHost:Host = {
+ ID: 0,
+ Name: "",
+ DNS: "",
+ Iface: "",
+ IP: "",
+ Mac: "",
+ Hw: "",
+ Date: "",
+ Known: 0,
+ Now: 0,
};
+export interface Conf {
+ Color: string;
+ Timeout: number;
+};
+
+
export const [allHosts, setAllHosts] = createSignal