HomeDisk/server/src/fs/mod.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2022-05-27 13:58:16 +00:00
pub mod create_dir;
pub mod delete;
pub mod download;
2022-04-24 20:07:41 +00:00
pub mod list;
2022-04-24 19:31:50 +00:00
pub mod upload;
pub fn app() -> axum::Router {
use axum::routing::{delete, get, post};
2022-04-24 19:31:50 +00:00
2022-04-24 20:07:41 +00:00
axum::Router::new()
.route("/list", post(list::handle))
.route("/upload", post(upload::handle))
.route("/delete", delete(upload::handle))
.route("/download", get(download::handle))
2022-05-27 13:58:16 +00:00
.route("/createdir", post(create_dir::handle))
2022-04-24 19:31:50 +00:00
}
2022-05-01 18:34:28 +00:00
2022-05-01 20:44:28 +00:00
pub fn validate_path(path: &str) -> Result<(), homedisk_types::errors::ServerError> {
use homedisk_types::errors::{FsError, ServerError};
2022-06-07 20:36:26 +00:00
// `path` can't contain `..`
2022-05-01 18:34:28 +00:00
// to prevent attack attempts because by using a `..` you can access the previous folder
if path.contains("..") {
return Err(ServerError::FsError(FsError::ReadDir(
"the `path` must not contain `..`".to_string(),
)));
}
2022-06-07 20:36:26 +00:00
// `path` can't contain `~`
// to prevent attack attempts because `~` can get up a directory on `$HOME`
if path.contains('~') {
return Err(ServerError::FsError(FsError::ReadDir(
"the `path` must not contain `~`".to_string(),
)));
}
2022-05-01 18:34:28 +00:00
Ok(())
}