porta-rs 0.1.1

Zero-trust CGNAT bypass via WireGuard tunnel
use anyhow::Result;
use clap::Args;

use crate::config::{load_config, Role};

#[derive(Args)]
pub struct StatusArgs {}

pub fn execute(_args: &StatusArgs) -> Result<()> {
    let config = load_config()?;

    println!("\n\x1b[1;36m╔══════════════════════════════════════════════════════════════╗\x1b[0m");
    println!("\x1b[1;36m║                     PORTA STATUS                             ║\x1b[0m");
    println!("\x1b[1;36m╚══════════════════════════════════════════════════════════════╝\x1b[0m\n");

    println!("\x1b[1;33mRole:\x1b[0m       {:?}", config.role());
    println!("\x1b[1;33mInterface:\x1b[0m  {}", config.interface());

    match config.role() {
        Role::Client => {
            println!("\x1b[1;33mServer:\x1b[0m     {}:{}", config.server_address(), config.server_port());
        }
        Role::Server => {
            println!("\x1b[1;33mListen:\x1b[0m     port {}", config.listen_port());
            println!("\x1b[1;33mClients:\x1b[0m    {}", config.allowed_clients_count());
        }
    }

    println!("\n\x1b[1;33mPort Forwardings:\x1b[0m\n");

    if config.ports().is_empty() {
        println!("  No port forwarding rules configured.\n");
        return Ok(());
    }

    println!("  {:<15} {:<15} {:<10} {:<10} {:<20}", "Remote", "Local", "Protocol", "Status", "Description");
    println!("  {:<15} {:<15} {:<10} {:<10} {:<20}", "------", "-----", "--------", "------", "-----------");

    for port in config.ports() {
        let status = if port.enabled { "\x1b[1;32mActive\x1b[0m" } else { "\x1b[1;31mDisabled\x1b[0m" };
        println!(
            "  {:<15} {:<15} {:<10} {:<21} {:<20}",
            format!(":{}", port.remote_port),
            format!(":{}", port.local_port),
            port.protocol,
            status,
            port.description
        );
    }

    println!();
    Ok(())
}