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]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.1.5"
|
version = "1.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
|
checksum = "a2152dbcb980c05735e2a651d96011320a949eb31a0c8b38b72645ce97dec676"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"libz-rs-sys",
|
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
|
"zlib-rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1540,15 +1540,6 @@ version = "0.2.178"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
|
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]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.4.15"
|
version = "0.4.15"
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ pub async fn render_tui() {
|
||||||
f,
|
f,
|
||||||
stack[0],
|
stack[0],
|
||||||
"CPU".to_string(),
|
"CPU".to_string(),
|
||||||
|
"%".to_string(),
|
||||||
state.with_width(38).cpu,
|
state.with_width(38).cpu,
|
||||||
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
||||||
Color::Cyan,
|
Color::Cyan,
|
||||||
|
|
@ -164,6 +165,7 @@ pub async fn render_tui() {
|
||||||
f,
|
f,
|
||||||
stack[1],
|
stack[1],
|
||||||
"RAM".to_string(),
|
"RAM".to_string(),
|
||||||
|
"%".to_string(),
|
||||||
state.with_width(38).ram,
|
state.with_width(38).ram,
|
||||||
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
Borders::TOP.union(Borders::LEFT).union(Borders::RIGHT),
|
||||||
Color::Green,
|
Color::Green,
|
||||||
|
|
@ -178,6 +180,7 @@ pub async fn render_tui() {
|
||||||
f,
|
f,
|
||||||
stack[2],
|
stack[2],
|
||||||
"PING".to_string(),
|
"PING".to_string(),
|
||||||
|
"ms".to_string(),
|
||||||
state.with_width(38).ping,
|
state.with_width(38).ping,
|
||||||
Borders::ALL,
|
Borders::ALL,
|
||||||
Color::Magenta,
|
Color::Magenta,
|
||||||
|
|
@ -199,6 +202,7 @@ pub fn render_graphs(
|
||||||
f: &mut Frame<'_>,
|
f: &mut Frame<'_>,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
title: String,
|
title: String,
|
||||||
|
unit: String,
|
||||||
graph: Vec<(f64, f64)>,
|
graph: Vec<(f64, f64)>,
|
||||||
borders: Borders,
|
borders: Borders,
|
||||||
color: Color,
|
color: Color,
|
||||||
|
|
@ -214,9 +218,10 @@ pub fn render_graphs(
|
||||||
let max_y = graph.iter().map(|(_, y)| *y).fold(f64::MIN, f64::max);
|
let max_y = graph.iter().map(|(_, y)| *y).fold(f64::MIN, f64::max);
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
.title(format!(
|
.title(format!(
|
||||||
"{}: {}──{}/{} MIN/MAX ",
|
"─{}:─{}{}──{}/{}─MIN/MAX",
|
||||||
title,
|
title,
|
||||||
graph.last().unwrap_or(&(0.0 as f64, 0.0 as f64)).1 as i64,
|
graph.last().unwrap_or(&(0.0 as f64, 0.0 as f64)).1 as i64,
|
||||||
|
unit,
|
||||||
min_y as i64,
|
min_y as i64,
|
||||||
max_y as i64
|
max_y as i64
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ use tower::Service;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct HttpService {
|
struct HttpService {
|
||||||
peer_addr: SocketAddr,
|
peer_addr: SocketAddr,
|
||||||
|
ssl: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service<HttpRequest<Incoming>> for HttpService {
|
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 {
|
fn call(&mut self, req: HttpRequest<Incoming>) -> Self::Future {
|
||||||
let peer_ip = self.peer_addr.ip();
|
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();
|
let (parts, body) = req.into_parts();
|
||||||
|
|
||||||
|
|
@ -62,7 +64,7 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let is_websocket_upgrade = path.starts_with("/ws")
|
let is_websocket_upgrade = path.starts_with("/ws")
|
||||||
&& method == Method::GET // WebSocket upgrades use GET
|
&& method == Method::GET
|
||||||
&& headers
|
&& headers
|
||||||
.get("connection")
|
.get("connection")
|
||||||
.map(|v| v.to_str().unwrap_or("").contains("Upgrade"))
|
.map(|v| v.to_str().unwrap_or("").contains("Upgrade"))
|
||||||
|
|
@ -137,7 +139,7 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
||||||
Err(_) => None,
|
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 {
|
} else {
|
||||||
let mut path_parts: Vec<&str> = path.split("/").collect();
|
let mut path_parts: Vec<&str> = path.split("/").collect();
|
||||||
let name = path_parts.remove(path_parts.len() - 1);
|
let name = path_parts.remove(path_parts.len() - 1);
|
||||||
|
|
@ -202,10 +204,45 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_local_network(_addr: IpAddr) -> bool {
|
pub fn is_local_network(addr: IpAddr) -> bool {
|
||||||
// PLACEHOLDER
|
match addr {
|
||||||
|
IpAddr::V4(v4) => {
|
||||||
|
let octets = v4.octets();
|
||||||
|
if octets[0] == 10 {
|
||||||
return true;
|
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 {
|
async fn run_http_server(port: u16) -> bool {
|
||||||
let mut ip = "0.0.0.0".to_string();
|
let mut ip = "0.0.0.0".to_string();
|
||||||
|
|
@ -255,7 +292,7 @@ async fn run_http_server(port: u16) -> bool {
|
||||||
accepted = listener.accept() => {
|
accepted = listener.accept() => {
|
||||||
match accepted {
|
match accepted {
|
||||||
std::result::Result::Ok((stream, addr)) => {
|
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);
|
let io = TokioIo::new(stream);
|
||||||
|
|
||||||
// Subscribe to the shutdown signal for this specific connection
|
// 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() => {
|
accepted = listener.accept() => {
|
||||||
match accepted {
|
match accepted {
|
||||||
std::result::Result::Ok((stream, addr)) => {
|
std::result::Result::Ok((stream, addr)) => {
|
||||||
let service = HttpService { peer_addr: addr };
|
let service = HttpService { ssl: true, peer_addr: addr };
|
||||||
let acceptor = acceptor.clone();
|
let acceptor = acceptor.clone();
|
||||||
|
|
||||||
// Subscribe to the shutdown signal for this specific connection
|
// Subscribe to the shutdown signal for this specific connection
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue