Iota frontend
This commit is contained in:
parent
74613226d8
commit
bc441d44c9
3 changed files with 59 additions and 26 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -800,13 +800,13 @@ checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
|
|||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.5"
|
||||
version = "1.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
|
||||
checksum = "a2152dbcb980c05735e2a651d96011320a949eb31a0c8b38b72645ce97dec676"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"libz-rs-sys",
|
||||
"miniz_oxide",
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1540,15 +1540,6 @@ version = "0.2.178"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
|
||||
|
||||
[[package]]
|
||||
name = "libz-rs-sys"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b484ba8d4f775eeca644c452a56650e544bf7e617f1d170fe7298122ead5222"
|
||||
dependencies = [
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ pub async fn render_tui() {
|
|||
f,
|
||||
stack[0],
|
||||
"CPU".to_string(),
|
||||
"%".to_string(),
|
||||
state.with_width(38).cpu,
|
||||
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
||||
Color::Cyan,
|
||||
|
|
@ -164,6 +165,7 @@ pub async fn render_tui() {
|
|||
f,
|
||||
stack[1],
|
||||
"RAM".to_string(),
|
||||
"%".to_string(),
|
||||
state.with_width(38).ram,
|
||||
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
||||
Color::Green,
|
||||
|
|
@ -178,6 +180,7 @@ pub async fn render_tui() {
|
|||
f,
|
||||
stack[2],
|
||||
"PING".to_string(),
|
||||
"ms".to_string(),
|
||||
state.with_width(38).ping,
|
||||
Borders::ALL,
|
||||
Color::Magenta,
|
||||
|
|
@ -199,6 +202,7 @@ pub fn render_graphs(
|
|||
f: &mut Frame<'_>,
|
||||
area: Rect,
|
||||
title: String,
|
||||
unit: String,
|
||||
graph: Vec<(f64, f64)>,
|
||||
borders: Borders,
|
||||
color: Color,
|
||||
|
|
@ -214,9 +218,10 @@ pub fn render_graphs(
|
|||
let max_y = graph.iter().map(|(_, y)| *y).fold(f64::MIN, f64::max);
|
||||
let block = Block::default()
|
||||
.title(format!(
|
||||
"{}: {}──{}/{} MIN/MAX ",
|
||||
"─{}:─{}{}──{}/{}─MIN/MAX",
|
||||
title,
|
||||
graph.last().unwrap_or(&(0.0 as f64, 0.0 as f64)).1 as i64,
|
||||
unit,
|
||||
min_y as i64,
|
||||
max_y as i64
|
||||
))
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ use tower::Service;
|
|||
#[derive(Clone)]
|
||||
struct HttpService {
|
||||
peer_addr: SocketAddr,
|
||||
ssl: bool,
|
||||
}
|
||||
|
||||
impl Service<HttpRequest<Incoming>> for HttpService {
|
||||
|
|
@ -52,7 +53,8 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
|||
|
||||
fn call(&mut self, req: HttpRequest<Incoming>) -> Self::Future {
|
||||
let peer_ip = self.peer_addr.ip();
|
||||
let is_local = is_local_network(peer_ip);
|
||||
|
||||
let is_acceptable = is_local_network(peer_ip) || self.ssl;
|
||||
|
||||
let (parts, body) = req.into_parts();
|
||||
|
||||
|
|
@ -62,12 +64,12 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
|||
|
||||
let fut = async move {
|
||||
let is_websocket_upgrade = path.starts_with("/ws")
|
||||
&& method == Method::GET // WebSocket upgrades use GET
|
||||
&& headers
|
||||
.get("connection")
|
||||
.map(|v| v.to_str().unwrap_or("").contains("Upgrade"))
|
||||
.unwrap_or(false)
|
||||
&& headers.get("upgrade").map(|v| v.to_str().unwrap_or("")) == Some("websocket");
|
||||
&& method == Method::GET
|
||||
&& headers
|
||||
.get("connection")
|
||||
.map(|v| v.to_str().unwrap_or("").contains("Upgrade"))
|
||||
.unwrap_or(false)
|
||||
&& headers.get("upgrade").map(|v| v.to_str().unwrap_or("")) == Some("websocket");
|
||||
|
||||
if is_websocket_upgrade {
|
||||
log_message("Attempting WebSocket upgrade on /ws");
|
||||
|
|
@ -137,7 +139,7 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
|||
Err(_) => None,
|
||||
};
|
||||
|
||||
Ok(api::handle(&path, &is_local, headers.clone(), body_string).await)
|
||||
Ok(api::handle(&path, &is_acceptable, headers.clone(), body_string).await)
|
||||
} else {
|
||||
let mut path_parts: Vec<&str> = path.split("/").collect();
|
||||
let name = path_parts.remove(path_parts.len() - 1);
|
||||
|
|
@ -202,9 +204,44 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_local_network(_addr: IpAddr) -> bool {
|
||||
// PLACEHOLDER
|
||||
return true;
|
||||
pub fn is_local_network(addr: IpAddr) -> bool {
|
||||
match addr {
|
||||
IpAddr::V4(v4) => {
|
||||
let octets = v4.octets();
|
||||
if octets[0] == 10 {
|
||||
return true;
|
||||
}
|
||||
if octets[0] == 172 && (16..=31).contains(&octets[1]) {
|
||||
return true;
|
||||
}
|
||||
if octets[0] == 192 && octets[1] == 168 {
|
||||
return true;
|
||||
}
|
||||
if octets[0] == 127 {
|
||||
return true;
|
||||
}
|
||||
if octets[0] == 169 && octets[1] == 254 {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
IpAddr::V6(v6) => {
|
||||
let segments = v6.segments();
|
||||
if (segments[0] & 0xfe00) == 0xfc00 {
|
||||
return true;
|
||||
}
|
||||
if (segments[0] & 0xffc0) == 0xfe80 {
|
||||
return true;
|
||||
}
|
||||
if v6.is_loopback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_http_server(port: u16) -> bool {
|
||||
|
|
@ -255,7 +292,7 @@ async fn run_http_server(port: u16) -> bool {
|
|||
accepted = listener.accept() => {
|
||||
match accepted {
|
||||
std::result::Result::Ok((stream, addr)) => {
|
||||
let service = HttpService { peer_addr: addr };
|
||||
let service = HttpService { ssl: false, peer_addr: addr };
|
||||
let io = TokioIo::new(stream);
|
||||
|
||||
// Subscribe to the shutdown signal for this specific connection
|
||||
|
|
@ -359,7 +396,7 @@ async fn run_tls_server(port: u16, tls_config: Arc<ServerConfig>) -> bool {
|
|||
accepted = listener.accept() => {
|
||||
match accepted {
|
||||
std::result::Result::Ok((stream, addr)) => {
|
||||
let service = HttpService { peer_addr: addr };
|
||||
let service = HttpService { ssl: true, peer_addr: addr };
|
||||
let acceptor = acceptor.clone();
|
||||
|
||||
// Subscribe to the shutdown signal for this specific connection
|
||||
|
|
|
|||
Loading…
Reference in a new issue