Add CGI functionality

This commit is contained in:
g1n 2021-07-23 19:06:54 +00:00
parent ef99f445e0
commit 38bedc8ae7
1 changed files with 6 additions and 1 deletions

View File

@ -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 {