7 Commits
13 changed files with 70 additions and 31 deletions

No files matched your search

+5 -2
View File
@@ -1,5 +1,8 @@
you can use block code as so: you should use block code to refence code, like so:
```rust ```rust
hello_world!(println); hello_world!(println);
// indented lines
``` ```
in the chat. in the chat. Else it fucks up formatting.
We work towards clean, maintainable design. im not the best at this thing.
Generated
+1 -1
View File
@@ -1179,7 +1179,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]] [[package]]
name = "wakey" name = "wakey"
version = "0.1.2" version = "0.1.4"
dependencies = [ dependencies = [
"axum", "axum",
"axum-extra", "axum-extra",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "wakey" name = "wakey"
version = "0.1.2" version = "0.1.4"
edition = "2024" edition = "2024"
publish = ["gitea"] publish = ["gitea"]
+5 -5
View File
@@ -2,12 +2,12 @@
START=66 START=66
start() { start() {
LOGFILE=/var/log/update_wakey.log LOGFILE=/var/log/update_wakey.log
MAX_RETRIES=10 MAX_RETRIES=10
RETRY_COUNT=0 RETRY_COUNT=0
# shellcheck disable=SC2016 # shellcheck disable=SC2016
nohup sh -c ' sh -c '
while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do
if /etc/ldlda_help/update_wakey.sh; then if /etc/ldlda_help/update_wakey.sh; then
echo "[update_wakey] Success at $(date)" >>"$LOGFILE" echo "[update_wakey] Success at $(date)" >>"$LOGFILE"
+4 -3
View File
@@ -1,6 +1,6 @@
use crate::{ use crate::{
arpparse::NUDState, arpparse::NUDState,
utils::parse::{de_many, serialize_macs}, utils::{parse::{de_many, serialize_macs}, query::get_macs},
}; };
use axum::{Json, http::StatusCode, response::IntoResponse}; use axum::{Json, http::StatusCode, response::IntoResponse};
use axum_extra::extract::Query; use axum_extra::extract::Query;
@@ -93,9 +93,10 @@ pub async fn get_status_json(
mac: mac.clone(), mac: mac.clone(),
}; };
let mut tasks = Vec::new(); let mut tasks = Vec::new();
// can we jus collect the whole table instead of doing this.
for d in &dev_opts { for d in &dev_opts {
for n in &nud_opts { for n in &nud_opts {
tasks.push(crate::utils::query::get_macs( tasks.push(get_macs( // this i hate sm
name.as_deref(), name.as_deref(),
ips_opt.as_deref(), ips_opt.as_deref(),
d.as_deref(), d.as_deref(),
@@ -109,7 +110,7 @@ pub async fn get_status_json(
.map(|v| v.into_iter().flatten().collect::<Vec<_>>()) .map(|v| v.into_iter().flatten().collect::<Vec<_>>())
{ {
Ok(mut table) => { Ok(mut table) => {
if !mac.is_empty() { if !mac.is_empty() { // mac here
let wanted: HashSet<MacAddr> = mac.into_iter().collect(); let wanted: HashSet<MacAddr> = mac.into_iter().collect();
table.retain(|row| row.mac.map(|m| wanted.contains(&m)).unwrap_or(false)); table.retain(|row| row.mac.map(|m| wanted.contains(&m)).unwrap_or(false));
} }
+6 -2
View File
@@ -7,9 +7,11 @@ use crate::route::api::Status; */
use crate::utils::parse::mac::{des_opm, ser_opm}; use crate::utils::parse::mac::{des_opm, ser_opm};
use crate::utils::wake::wake_one; use crate::utils::wake::wake_one;
use axum::{extract::Json, http::StatusCode, response::IntoResponse}; use axum::{extract::Json, http::StatusCode, response::IntoResponse};
use futures::TryFutureExt;
use macaddr::MacAddr; use macaddr::MacAddr;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use tokio::net::UdpSocket;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Default, Serialize, Clone)] #[derive(Debug, Default, Serialize, Clone)]
@@ -75,7 +77,9 @@ pub async fn wake_multi(Json(req): Json<Vec<WakeTarget>>) -> impl IntoResponse {
pub async fn wake_multi_split( pub async fn wake_multi_split(
targets: impl IntoIterator<Item = WakeTarget>, targets: impl IntoIterator<Item = WakeTarget>,
) -> io::Result<Vec<WakeTargetResult>> { ) -> io::Result<Vec<WakeTargetResult>> {
let sock = tokio::net::UdpSocket::bind("0.0.0.0:0").await?; let sock = UdpSocket::bind("[::]:0")
.or_else(|_| UdpSocket::bind(":0"))
.await?;
sock.set_broadcast(true)?; sock.set_broadcast(true)?;
Ok( Ok(
@@ -85,7 +89,7 @@ pub async fn wake_multi_split(
} else { } else {
wake_one( wake_one(
&sock, &sock,
c.try_into().expect("complete struct failed to try_into"), c.try_into().expect("complete struct failed to try_into"), // type state pattern?
) )
.await .await
.into() .into()
+12 -2
View File
@@ -1,10 +1,20 @@
use std::collections::HashSet; use std::{collections::HashSet, fs};
pub fn get_dev() -> HashSet<String> { pub fn get_dev() -> HashSet<String> {
let mut devs: HashSet<String> = HashSet::new(); let mut devs: HashSet<String> = HashSet::new();
if let Ok(rd) = std::fs::read_dir("/sys/class/net") { if let Ok(rd) = std::fs::read_dir("/sys/class/net") {
for e in rd.flatten() { for e in rd.flatten() {
if let Ok(name) = e.file_name().into_string() if e.file_type()
.map(|ft| {
if ft.is_symlink() {
// true
fs::metadata(e.path()).map(|m| m.is_dir()).unwrap_or(false)
} else {
ft.is_dir()
}
})
.unwrap_or(false)
&& let Ok(name) = e.file_name().into_string()
&& name != "lo" && name != "lo"
&& !name.is_empty() && !name.is_empty()
{ {
+4 -2
View File
@@ -81,7 +81,7 @@ pub async fn get_macs(
state: Option<NUDState>, state: Option<NUDState>,
) -> Result<Vec<IpNeighLine>> { ) -> Result<Vec<IpNeighLine>> {
let ip_list: Option<Vec<IpAddr>> = let ip_list: Option<Vec<IpAddr>> =
ips.map(|slice| slice.iter().copied().map(|ip| ip.to_canonical()).collect()); ips.map(|slice| slice.iter().map(|ip| ip.to_canonical()).collect());
let ip_list = match (ip_list, machine_name) { let ip_list = match (ip_list, machine_name) {
(Some(list), _) => list, (Some(list), _) => list,
(None, Some(name)) => get_ips(name).await?.collect(), (None, Some(name)) => get_ips(name).await?.collect(),
@@ -136,7 +136,9 @@ pub async fn get_mac(
Ok(rows) Ok(rows)
} }
/* pub async fn _get_macs_good( /*
/// get macs where you just run ip neigh then rust handles the filtering (faster than get mac)
pub async fn get_macs_rust(
machine_names: Option<&str>, machine_names: Option<&str>,
ips: Option<&[IpAddr]>, ips: Option<&[IpAddr]>,
devs: Option<&[&str]>, devs: Option<&[&str]>,
+2 -2
View File
@@ -58,12 +58,12 @@ pub async fn status_smart_redirect(q: String) -> DeviceQuery {
}; };
} }
// 5) Try DNS: if it resolves, treat as name // 5) Try DNS: if it resolves, treat as name
if tokio::net::lookup_host((s, 0)).await.is_ok() { /* if tokio::net::lookup_host((s, 0)).await.is_ok() {
return DeviceQuery { return DeviceQuery {
name: Some(s.to_string()), name: Some(s.to_string()),
..Default::default() ..Default::default()
}; };
} } */
// Default: name last // it will fail also // Default: name last // it will fail also
DeviceQuery { DeviceQuery {
name: Some(s.to_string()), name: Some(s.to_string()),
+4 -1
View File
@@ -1,6 +1,7 @@
pub mod impls; pub mod impls;
use std::{io, net::IpAddr}; use std::{io, net::IpAddr};
use futures::TryFutureExt;
use macaddr::MacAddr; use macaddr::MacAddr;
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
@@ -74,7 +75,9 @@ impl WakeTargetResult {
pub async fn _wake_multi( pub async fn _wake_multi(
targets: impl IntoIterator<Item = WakeTarget>, targets: impl IntoIterator<Item = WakeTarget>,
) -> io::Result<Vec<WakeTargetResult>> { ) -> io::Result<Vec<WakeTargetResult>> {
let sock = UdpSocket::bind(":0").await?; let sock = UdpSocket::bind("[::]:0")
.or_else(|_| UdpSocket::bind(":0"))
.await?;
sock.set_broadcast(true)?; sock.set_broadcast(true)?;
let fs = targets.into_iter().map(|t| wake_one(&sock, t)); let fs = targets.into_iter().map(|t| wake_one(&sock, t));
Ok(futures::future::join_all(fs).await) Ok(futures::future::join_all(fs).await)
+14 -4
View File
@@ -1,6 +1,8 @@
import { filter_array } from "./status.js";
export const qs = new URLSearchParams(location.search); export const qs = new URLSearchParams(location.search);
// not real cuh // $ is normally queryselector are we fr
export const $ = (id) => document.getElementById(id); export const $ = (id) => document.getElementById(id);
export const elName = $("name"); export const elName = $("name");
export const elCheck = $("check"); export const elCheck = $("check");
@@ -17,10 +19,18 @@ export function setPill(kind, text) {
pill.textContent = text; pill.textContent = text;
} }
export function setLink(name) { export function setLink(name, clear) {
const url = new URL(location.href); const url = new URL(location.href);
if (name) url.searchParams.set("name", name); if (clear) url.searchParams.forEach((_, k) => url.searchParams.delete(k)); // FUCK
else url.searchParams.delete("name"); /* const hasExtraFilters = filter_array.some(
(k) => url.searchParams.getAll(k).length
);
if (hasExtraFilters) {
// jus returns whatever; they are specifying further
} else */ {
if (name) url.searchParams.set("name", name);
else url.searchParams.delete("name");
}
history.replaceState(null, "", url); history.replaceState(null, "", url);
link.href = url.toString(); link.href = url.toString();
} }
+9 -3
View File
@@ -42,7 +42,7 @@ function pickTarget(value) {
elName.value = v; elName.value = v;
updatePreview(); updatePreview();
saveName(v); saveName(v);
setLink(v); setLink(v, true);
fetchStatus(v); fetchStatus(v);
fetchLeases(); fetchLeases();
} }
@@ -74,10 +74,16 @@ const initial = loadName(qs);
if (initial) { if (initial) {
elName.value = initial; elName.value = initial;
updatePreview(); updatePreview();
setLink(initial); if (qs.has("name")) {
fetchStatus(initial); setLink(initial);
fetchStatus(initial);
} else {
fetchStatus();
}
fetchLeases(); fetchLeases();
} else { } else {
setPill("warn", "unknown"); setPill("warn", "unknown");
updatePreview();
fetchStatus();
fetchLeases(); fetchLeases();
} }
+3 -3
View File
@@ -8,8 +8,8 @@ const status_map = {
state: "state", state: "state",
dev: "interface", dev: "interface",
}; };
export const status_array = Object.keys(status_map);
const filter_array = ["ip", "dev", "nud", "mac"]; export const filter_array = ["ip", "dev", "nud", "mac"];
function buildStatusUrl(name) { function buildStatusUrl(name) {
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length); const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
@@ -18,7 +18,7 @@ function buildStatusUrl(name) {
} }
const u = new URL("/api/status", location.origin); const u = new URL("/api/status", location.origin);
if (name) u.searchParams.set("name", name); if (name) u.searchParams.set("name", name);
for (const k of Object.keys(status_map)) { for (const k of filter_array) {
const vals = qs.getAll(k); const vals = qs.getAll(k);
for (const v of vals) u.searchParams.append(k, v); for (const v of vals) u.searchParams.append(k, v);
} }