From 38bedc8ae7fd57f35703e9492fba28f0da7165d1 Mon Sep 17 00:00:00 2001 From: g1n Date: Fri, 23 Jul 2021 19:06:54 +0000 Subject: [PATCH] Add CGI functionality --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c7c78b6..b5a13b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::io::prelude::*; use std::io::ErrorKind; use std::net::TcpListener; use std::net::TcpStream; +use std::process::Command; extern crate argparse; use argparse::{ArgumentParser, StoreTrue, Store}; @@ -78,8 +79,12 @@ fn handle_connection(mut stream: TcpStream, root_dir: String) { let full_path = format!("{}{}", root_dir, _path); let mut exists = Path::new(&format!("{}{}", root_dir, _path).to_string()).exists(); if exists { - if Path::new(&full_path).is_file(){ + if Path::new(&full_path).is_file() { _contents = fs::read_to_string(format!("{}{}", root_dir, _path)).unwrap(); + if _path.contains(".sh") { + let command = Command::new(format!("{}", full_path)).output().unwrap(); + _contents = String::from_utf8(command.stdout).unwrap(); + } } else { exists = Path::new(&format!("{}{}/index.gmi", root_dir, _path).to_string()).exists(); if exists {