Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
8da3844f4b | |||
2aa1e2c02a | |||
b74271c014 | |||
741c53ddfe | |||
8bd3464b9b | |||
bd1a491e1c | |||
5c9d92523c | |||
9808133c38 |
4 changed files with 33 additions and 14 deletions
|
@ -1 +1 @@
|
|||
11
|
||||
13
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -10,7 +10,7 @@ checksum = "17cbf58e19f2bda088d8c4c95a46b41895375e15a2d63dd686a4273f8c43d46b"
|
|||
|
||||
[[package]]
|
||||
name = "herb"
|
||||
version = "0.8.0-binugs"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"frostwalker",
|
||||
"packeteer",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "herb"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -29,16 +29,17 @@ struct Settings {
|
|||
cgi: bool,
|
||||
index_generation: bool,
|
||||
address: String,
|
||||
logging: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn new() -> Settings {
|
||||
return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string()};
|
||||
return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string(), logging: false};
|
||||
}
|
||||
}
|
||||
|
||||
fn process_cgi(filename: String) -> Option<Vec<u8>> {
|
||||
// This is gonna be the boggiest implementation of CGI that anyone
|
||||
// This is gonna be the bodgiest implementation of CGI that anyone
|
||||
// has ever seen in the history of the fucking world
|
||||
|
||||
let query;
|
||||
|
@ -102,7 +103,6 @@ fn process_cgi_with_path(filename: String, segments: Vec<String>, location: i32)
|
|||
}
|
||||
|
||||
path = format!("{}/", path);
|
||||
println!("{}", path);
|
||||
let output;
|
||||
if query != "".to_string() {
|
||||
output = Command::new(format!("./{}", script))
|
||||
|
@ -218,7 +218,9 @@ fn get_page(filename: String, settings: Settings) -> GetPageResult {
|
|||
|
||||
let mut resultstruct = GetPageResult { is500: false, is502: false, is403: false, contents: vec![], iscgi: false };
|
||||
|
||||
println!("{} {} {}", path, checks, index);
|
||||
if settings.logging {
|
||||
println!("{} {} {}", path, checks, index);
|
||||
}
|
||||
|
||||
if checks == true && index == false {
|
||||
if path.contains(".") != true && path.contains(".cgi?") != true {
|
||||
|
@ -329,9 +331,15 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
|||
let output;
|
||||
|
||||
if &request.method == "GET" {
|
||||
println!("Stream sent GET request.");
|
||||
|
||||
if settings.logging {
|
||||
println!("Stream sent GET request.");
|
||||
}
|
||||
if request.location.segments.len() != 0 {
|
||||
if request.location.segments[0] == ".." || request.location.segments[0] == "." {
|
||||
let resource = Resource { contents: "<!DOCTYPE HTML><html><body><h1>400 Bad Request</h1><p>The request you sent appears to be malformed.</p></body></html>".to_string().into_bytes(), status_code: 400, mime: "text/html".to_string(), iscgi: false };
|
||||
return resource;
|
||||
}
|
||||
|
||||
let segclone = request.location.segments.clone();
|
||||
path = unwrap_url_into_segments(request.location);
|
||||
if path.contains(".cgi/") {
|
||||
|
@ -393,7 +401,9 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
|||
}
|
||||
} else {
|
||||
let resource = Resource { contents: "<!DOCTYPE HTML><html><body><h1>501 Not Implemented</h1><p>The request sent by your web browser cannot be handled by this server software.</p></body></html>".to_string().into_bytes(), status_code: 501, mime: "text/html".to_string(), iscgi: false };
|
||||
println!("Stream sent unhandlable request.");
|
||||
if settings.logging {
|
||||
println!("Stream sent unhandlable request.");
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
@ -425,7 +435,10 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
|||
|
||||
fn serve(mut stream: TcpStream, settings: Settings) {
|
||||
thread::spawn(move || {
|
||||
println!("Stream thread created.");
|
||||
if settings.logging {
|
||||
println!("Stream thread created.");
|
||||
}
|
||||
|
||||
let mut request = Vec::new();
|
||||
let mut reader = BufReader::new(&mut stream);
|
||||
reader
|
||||
|
@ -477,10 +490,14 @@ fn process_settings() -> Settings {
|
|||
}
|
||||
|
||||
if hashmap.get("index_generation").is_some() {
|
||||
println!("a");
|
||||
if hashmap.get("index_generation").unwrap_or(&"".to_string()).parse::<bool>().is_ok() {
|
||||
settings.index_generation = hashmap.get("index_generation").unwrap_or(&"true".to_string()).parse::<bool>().unwrap_or(true);
|
||||
println!("{}", settings.index_generation);
|
||||
}
|
||||
}
|
||||
|
||||
if hashmap.get("logging").is_some() {
|
||||
if hashmap.get("logging").unwrap_or(&"".to_string()).parse::<bool>().is_ok() {
|
||||
settings.logging = hashmap.get("logging").unwrap_or(&"false".to_string()).parse::<bool>().unwrap_or(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,7 +513,9 @@ fn main() -> std::io::Result<()> {
|
|||
let listen = TcpListener::bind(settings.address.clone())?;
|
||||
|
||||
for stream in listen.incoming() {
|
||||
println!("Serving incoming stream.");
|
||||
if settings.logging {
|
||||
println!("Serving incoming stream.");
|
||||
}
|
||||
serve(stream?, settings.clone());
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue