adding bloat + use the copilot page this time
This commit is contained in:
@@ -159,6 +159,7 @@ impl FromStr for IpNeighLine {
|
|||||||
}
|
}
|
||||||
/// pls dont touch ts
|
/// pls dont touch ts
|
||||||
impl IpNeighLine {
|
impl IpNeighLine {
|
||||||
|
/* // these are some not needed fns
|
||||||
pub fn set_ip(&mut self, ip: IpAddr) {
|
pub fn set_ip(&mut self, ip: IpAddr) {
|
||||||
self.ip = ip;
|
self.ip = ip;
|
||||||
}
|
}
|
||||||
@@ -171,6 +172,20 @@ impl IpNeighLine {
|
|||||||
pub fn state(self, state: NUDState) -> Self {
|
pub fn state(self, state: NUDState) -> Self {
|
||||||
Self { state, ..self }
|
Self { state, ..self }
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
pub fn with_dev(dev: impl Into<String>) -> impl FnMut(Self) -> Self {
|
||||||
|
let dev = dev.into();
|
||||||
|
move |self_| Self {
|
||||||
|
dev: Some(dev.clone()),
|
||||||
|
..self_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn with_mac(mac: MacAddr) -> impl FnMut(Self) -> Self {
|
||||||
|
move |self_| Self {
|
||||||
|
mac: Some(mac),
|
||||||
|
..self_
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ideas from copilot:
|
// ideas from copilot:
|
||||||
|
|||||||
+4
-3
@@ -43,7 +43,7 @@ async fn home() -> Html<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn wake_handler(
|
async fn wake_handler(
|
||||||
Query(DeviceQuery { name }): Query<DeviceQuery>,
|
Query(DeviceQuery { name, .. }): Query<DeviceQuery>,
|
||||||
) -> axum::response::Result<impl IntoResponse> {
|
) -> axum::response::Result<impl IntoResponse> {
|
||||||
match wake(name.as_deref().unwrap_or(MACHINE_NAME)).await {
|
match wake(name.as_deref().unwrap_or(MACHINE_NAME)).await {
|
||||||
Ok(x) if x > 0 => Ok((StatusCode::ACCEPTED, format!("{x} packets sent!"))),
|
Ok(x) if x > 0 => Ok((StatusCode::ACCEPTED, format!("{x} packets sent!"))),
|
||||||
@@ -93,11 +93,12 @@ pub async fn status_build(machine_name: &str) -> String {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> color_eyre::Result<()> {
|
async fn main() -> color_eyre::Result<()> {
|
||||||
use crate::route::{api_status, get_status_2, home_2_route};
|
use crate::route::{api_status, get_status_2, home_2, home_2_route};
|
||||||
|
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(home))
|
.route("/home", get(home))
|
||||||
|
.route("/", get(home_2))
|
||||||
.merge(home_2_route())
|
.merge(home_2_route())
|
||||||
.route("/wake", post(wake_handler))
|
.route("/wake", post(wake_handler))
|
||||||
.route("/status", get(get_status_2))
|
.route("/status", get(get_status_2))
|
||||||
|
|||||||
+9
-6
@@ -1,3 +1,5 @@
|
|||||||
|
use std::net::IpAddr;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
Json, Router,
|
Json, Router,
|
||||||
extract::{Path, Query},
|
extract::{Path, Query},
|
||||||
@@ -5,10 +7,11 @@ use axum::{
|
|||||||
response::{Html, IntoResponse, Redirect},
|
response::{Html, IntoResponse, Redirect},
|
||||||
routing::get,
|
routing::get,
|
||||||
};
|
};
|
||||||
|
use macaddr::MacAddr;
|
||||||
|
|
||||||
use crate::{MACHINE_NAME, arpparse, status_build, utils::query::get_macs_1};
|
use crate::{MACHINE_NAME, arpparse::{self, des_opm}, status_build, utils::query::get_macs_1};
|
||||||
|
|
||||||
async fn home_2() -> Html<&'static str> {
|
pub async fn home_2() -> Html<&'static str> {
|
||||||
Html(include_str!("../static/home_2"))
|
Html(include_str!("../static/home_2"))
|
||||||
}
|
}
|
||||||
async fn home_2_css() -> impl IntoResponse {
|
async fn home_2_css() -> impl IntoResponse {
|
||||||
@@ -41,9 +44,9 @@ pub fn home_2_route() -> Router {
|
|||||||
#[derive(Debug, Default, Clone, Hash, serde::Deserialize)]
|
#[derive(Debug, Default, Clone, Hash, serde::Deserialize)]
|
||||||
pub struct DeviceQuery {
|
pub struct DeviceQuery {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
// ip: Option<IpAddr>,
|
ip: Option<IpAddr>,
|
||||||
// #[serde(deserialize_with = "des_opm")]
|
#[serde(deserialize_with = "des_opm")]
|
||||||
// mac: Option<MacAddr>,
|
mac: Option<MacAddr>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Default, Clone, Hash, serde::Deserialize)]
|
#[derive(Debug, Default, Clone, Hash, serde::Deserialize)]
|
||||||
pub struct NamePath {
|
pub struct NamePath {
|
||||||
@@ -64,7 +67,7 @@ pub struct StatusError {
|
|||||||
|
|
||||||
pub async fn get_status_json(
|
pub async fn get_status_json(
|
||||||
// p: Option<Path<NamePath>>,
|
// p: Option<Path<NamePath>>,
|
||||||
Query(DeviceQuery { name }): Query<DeviceQuery>,
|
Query(DeviceQuery { name, .. }): Query<DeviceQuery>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let name = /* p
|
let name = /* p
|
||||||
.map(|Path(n)| n.name)
|
.map(|Path(n)| n.name)
|
||||||
|
|||||||
+11
-7
@@ -38,15 +38,13 @@ pub async fn get_macs_2_mac(machine_name: &str) -> io::Result<HashSet<MacAddr>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_macs_1(machine_name: &str) -> io::Result<Vec<arpparse::IpNeighLine>> {
|
pub async fn get_macs_1(machine_name: &str) -> io::Result<Vec<arpparse::IpNeighLine>> {
|
||||||
|
let dev = "br-lan";
|
||||||
let ips = get_ips(machine_name).await?;
|
let ips = get_ips(machine_name).await?;
|
||||||
let futures = ips.iter().map(|ip| {
|
let futures = ips.iter().map(|ip| {
|
||||||
let ip = ip.to_canonical();
|
let ip = ip.to_canonical();
|
||||||
async move {
|
async move {
|
||||||
let o = exec_command(
|
let o =
|
||||||
"ip",
|
exec_command("ip", ["neigh", "show", "to", &ip.to_string(), "dev", dev]).await?;
|
||||||
["neigh", "show", "to", &ip.to_string(), "dev", "br-lan"],
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
if !o.status.success() {
|
if !o.status.success() {
|
||||||
return Err(io::Error::other(format!(
|
return Err(io::Error::other(format!(
|
||||||
"`ip neigh` failed for {ip} (status: {st}): {err}",
|
"`ip neigh` failed for {ip} (status: {st}): {err}",
|
||||||
@@ -56,14 +54,20 @@ pub async fn get_macs_1(machine_name: &str) -> io::Result<Vec<arpparse::IpNeighL
|
|||||||
};
|
};
|
||||||
Ok(String::from_utf8_lossy(&o.stdout)
|
Ok(String::from_utf8_lossy(&o.stdout)
|
||||||
.lines()
|
.lines()
|
||||||
.map(arpparse::parse_ip_neigh_line)
|
.flat_map(arpparse::parse_ip_neigh_line)
|
||||||
|
// .map(IpNeighLine::with_dev(dev)) // this could be after flatmap up there
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let res = futures::future::try_join_all(futures).await?; // async move block errs.
|
let res = futures::future::try_join_all(futures).await?; // async move block errs.
|
||||||
Ok(res
|
Ok(res
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
||||||
.flatten() /* resolve double vec */
|
.flatten() /* resolve double vec */
|
||||||
.flatten() /* drop parse errors */
|
// .flatten() /* drop parse errors (flat_map cleared) */
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_macs(machine_name: Option<&str>, ips: Option<impl IntoIterator<Item = IpAddr>>, dev: Option<&str>, state: Option<NUDState>) -> io::Result<Vec<IpNeighLine>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ function saveName(name) {
|
|||||||
function loadName() {
|
function loadName() {
|
||||||
return qs.get("name") || localStorage.getItem("wakey:name") || "";
|
return qs.get("name") || localStorage.getItem("wakey:name") || "";
|
||||||
}
|
}
|
||||||
|
/** @param {String} s NUD state */
|
||||||
function rankState(s) {
|
function rankState(s) {
|
||||||
return (
|
return (
|
||||||
{
|
{
|
||||||
@@ -43,12 +43,12 @@ function rankState(s) {
|
|||||||
Noarp: 2,
|
Noarp: 2,
|
||||||
None: 1,
|
None: 1,
|
||||||
Failed: 0,
|
Failed: 0,
|
||||||
}[s] ?? 0
|
}[s.toUpperCase()] ?? 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {{ name: String, table: Array<{ ip, dev, mac, state }>} | { name: String, error }} data from /api/status */
|
||||||
function renderStatus(data) {
|
function renderStatus(data) {
|
||||||
// data: { name: string, table: Array<{ ip, dev, mac, state }>} | { name, error }
|
|
||||||
const tbl = document.createElement("table");
|
const tbl = document.createElement("table");
|
||||||
tbl.innerHTML = `<tr><th>IP</th><th>MAC</th><th>State</th><th>IF</th></tr>`;
|
tbl.innerHTML = `<tr><th>IP</th><th>MAC</th><th>State</th><th>IF</th></tr>`;
|
||||||
for (const row of data.table || []) {
|
for (const row of data.table || []) {
|
||||||
|
|||||||
Reference in New Issue
Block a user