Compare commits

..

No commits in common. "master" and "modular" have entirely different histories.

4 changed files with 14 additions and 33 deletions

View file

@ -1 +1 @@
13
11

2
Cargo.lock generated
View file

@ -10,7 +10,7 @@ checksum = "17cbf58e19f2bda088d8c4c95a46b41895375e15a2d63dd686a4273f8c43d46b"
[[package]]
name = "herb"
version = "0.8.2"
version = "0.8.0-binugs"
dependencies = [
"frostwalker",
"packeteer",

View file

@ -1,6 +1,6 @@
[package]
name = "herb"
version = "0.8.2"
version = "0.8.0"
edition = "2018"
[dependencies]

View file

@ -29,17 +29,16 @@ 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(), logging: false};
return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string()};
}
}
fn process_cgi(filename: String) -> Option<Vec<u8>> {
// This is gonna be the bodgiest implementation of CGI that anyone
// This is gonna be the boggiest implementation of CGI that anyone
// has ever seen in the history of the fucking world
let query;
@ -103,6 +102,7 @@ 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,9 +218,7 @@ fn get_page(filename: String, settings: Settings) -> GetPageResult {
let mut resultstruct = GetPageResult { is500: false, is502: false, is403: false, contents: vec![], iscgi: false };
if settings.logging {
println!("{} {} {}", path, checks, index);
}
if checks == true && index == false {
if path.contains(".") != true && path.contains(".cgi?") != true {
@ -331,15 +329,9 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
let output;
if &request.method == "GET" {
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;
}
if request.location.segments.len() != 0 {
let segclone = request.location.segments.clone();
path = unwrap_url_into_segments(request.location);
if path.contains(".cgi/") {
@ -401,9 +393,7 @@ 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 };
if settings.logging {
println!("Stream sent unhandlable request.");
}
return resource;
}
@ -435,10 +425,7 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
fn serve(mut stream: TcpStream, settings: Settings) {
thread::spawn(move || {
if settings.logging {
println!("Stream thread created.");
}
let mut request = Vec::new();
let mut reader = BufReader::new(&mut stream);
reader
@ -490,14 +477,10 @@ 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);
}
}
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);
println!("{}", settings.index_generation);
}
}
@ -513,9 +496,7 @@ fn main() -> std::io::Result<()> {
let listen = TcpListener::bind(settings.address.clone())?;
for stream in listen.incoming() {
if settings.logging {
println!("Serving incoming stream.");
}
serve(stream?, settings.clone());
}
Ok(())