mostly licensing and docker stuff
This commit is contained in:
@@ -23,6 +23,8 @@ fn main() {
|
||||
}
|
||||
|
||||
if let Err(_) = server::run(root, port) {
|
||||
// shit out error if we have port already in use,
|
||||
// prevents panic
|
||||
log_error!("Port {} already in use!", port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Content-Type ; Mappings for the HTML headers, example 404
|
||||
*/
|
||||
use logger_rust::*;
|
||||
use std::fs::File;
|
||||
use std::io::{Cursor, Read};
|
||||
use std::path::Path;
|
||||
@@ -16,7 +20,10 @@ pub fn serve_file(path: &Path) -> BoxedResponse {
|
||||
|
||||
let mut file = match File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(_) => return not_found(),
|
||||
Err(e) => {
|
||||
log_error!("Serving a File failed with: {}", e);
|
||||
return not_found(); // bad, we need to serve properly ...
|
||||
}
|
||||
};
|
||||
|
||||
let mut content = Vec::new();
|
||||
|
||||
@@ -2,13 +2,27 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn resolve(root: &Path, url_path: &str) -> Option<PathBuf> {
|
||||
let rel = url_path.trim_start_matches('/');
|
||||
let rel = if rel.is_empty() { "index.html" } else { rel }; // default to index.html in . dir
|
||||
|
||||
//let rel = rel.split('?').next().unwrap_or(rel);
|
||||
let rel = if rel.is_empty() { "index.html" } else { rel };
|
||||
|
||||
let joined = root.join(rel);
|
||||
|
||||
// prevent escape essentially
|
||||
// directory, look for index file
|
||||
// CHANGE: 39bf977604
|
||||
let joined = if joined.is_dir() {
|
||||
let html = joined.join("index.html");
|
||||
let htm = joined.join("index.htm");
|
||||
if html.exists() {
|
||||
html
|
||||
} else if htm.exists() {
|
||||
htm
|
||||
} else {
|
||||
return None; // directory is there, but no index file is found
|
||||
}
|
||||
} else {
|
||||
joined
|
||||
};
|
||||
|
||||
// Prevent path traversal
|
||||
let canonical_root = root.canonicalize().ok()?;
|
||||
let canonical_file = joined.canonicalize().ok()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user