|
|
|
@ -1,13 +1,14 @@
|
|
|
|
|
use crate::{Request, Result};
|
|
|
|
|
use gophermap::{GopherMenu, ItemType};
|
|
|
|
|
use std::{
|
|
|
|
|
fs::{self, File},
|
|
|
|
|
fs,
|
|
|
|
|
io::prelude::*,
|
|
|
|
|
io::{BufReader, Read, Write},
|
|
|
|
|
net::{TcpListener, TcpStream},
|
|
|
|
|
os::unix::fs::PermissionsExt,
|
|
|
|
|
path::Path,
|
|
|
|
|
process::Command,
|
|
|
|
|
str,
|
|
|
|
|
};
|
|
|
|
|
use threadpool::ThreadPool;
|
|
|
|
|
|
|
|
|
@ -187,7 +188,7 @@ where
|
|
|
|
|
let path = req.file_path();
|
|
|
|
|
|
|
|
|
|
let reader = if is_executable(&path) {
|
|
|
|
|
sh(&path, &[&req.selector, &req.host, &req.port.to_string()])?
|
|
|
|
|
shell(&path, &[&req.query, &req.host, &req.port.to_string()])?
|
|
|
|
|
} else {
|
|
|
|
|
fs::read_to_string(path)?
|
|
|
|
|
};
|
|
|
|
@ -247,11 +248,11 @@ fn is_executable(path: &str) -> bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Run a script and return its output.
|
|
|
|
|
fn sh(path: &str, args: &[&str]) -> Result<String> {
|
|
|
|
|
fn shell(path: &str, args: &[&str]) -> Result<String> {
|
|
|
|
|
let output = Command::new(path).args(args).output()?;
|
|
|
|
|
if output.status.success() {
|
|
|
|
|
Ok(std::str::from_utf8(&output.stdout)?.to_string())
|
|
|
|
|
Ok(str::from_utf8(&output.stdout)?.to_string())
|
|
|
|
|
} else {
|
|
|
|
|
Ok(std::str::from_utf8(&output.stderr)?.to_string())
|
|
|
|
|
Ok(str::from_utf8(&output.stderr)?.to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|