51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use std::net::SocketAddr;
|
|
use tokio::net::TcpListener;
|
|
use tower_http::services::ServeDir;
|
|
use axum::{
|
|
middleware,
|
|
routing::{get, post},
|
|
Router
|
|
};
|
|
|
|
mod argparse;
|
|
mod print_interface;
|
|
mod config;
|
|
mod shells;
|
|
mod logging;
|
|
mod upload;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let args = argparse::parse_args();
|
|
let conf = config::load_config();
|
|
let port = match args.port {
|
|
Some(port) => port,
|
|
None => conf.web_port
|
|
};
|
|
|
|
println!("Files in current directory:");
|
|
print_interface::print_directory(&args.interface, &port, &args.directory, None).unwrap();
|
|
|
|
println!("\nFiles in persistent download directory:");
|
|
print_interface::print_directory(&args.interface, &port, &conf.get_download_path(), Some("download")).unwrap();
|
|
|
|
println!("\nConfigured shells:");
|
|
print_interface::print_interface(&args.interface, &port, &conf.get_shell_keys(), Some("shells"));
|
|
|
|
let app = Router::new()
|
|
.route("/upload", post(upload::upload_handler))
|
|
.route("/shells/:shell", get(shells::shells_handler))
|
|
.nest_service("/download", ServeDir::new(conf.get_download_path()))
|
|
.nest_service("/", ServeDir::new(&args.directory))
|
|
.layer(middleware::from_fn(logging::logging_middleware));
|
|
|
|
let listener = TcpListener::bind(format!("0.0.0.0:{}", port))
|
|
.await
|
|
.unwrap();
|
|
|
|
axum::serve(
|
|
listener,
|
|
app.into_make_service_with_connect_info::<SocketAddr>()
|
|
).await.unwrap();
|
|
}
|