pub mod auth;
pub mod git;
pub mod http;
pub mod lfs;
pub mod ssh;
pub mod tui;
use std::net::IpAddr;
use std::path::PathBuf;
#[derive(Clone)]
pub struct Config {
pub root: PathBuf,
pub host: String,
pub port: u16,
pub ssh_port: u16,
pub user: Option<String>,
pub pass: Option<String>,
pub hooks_dir: Option<PathBuf>,
pub enable_ssh: bool,
pub recursive: bool,
}
pub fn local_ips() -> Vec<IpAddr> {
let mut ips = Vec::new();
if let Ok(interfaces) = std::net::TcpListener::bind("0.0.0.0:0") {
drop(interfaces);
}
ips.push(IpAddr::V4(std::net::Ipv4Addr::LOCALHOST));
if let Ok(sock) = std::net::UdpSocket::bind("0.0.0.0:0") {
if sock.connect("8.8.8.8:80").is_ok() {
if let Ok(addr) = sock.local_addr() {
let ip = addr.ip();
if !ips.contains(&ip) {
ips.push(ip);
}
}
}
}
if let Ok(content) = std::fs::read_to_string("/proc/net/fib_trie") {
let lines: Vec<&str> = content.lines().collect();
for (i, line) in lines.iter().enumerate() {
if line.contains("/32 host LOCAL") {
if i > 0 {
if let Some(ip_str) = lines[i - 1].trim().strip_prefix("|-- ") {
if let Ok(ip) = ip_str.parse::<std::net::Ipv4Addr>() {
let ip = IpAddr::V4(ip);
if !ips.contains(&ip) {
ips.push(ip);
}
}
}
}
}
}
}
ips
}