From c85ea06785efbaa9bcdc961815a9b3021d5207fb Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 20 Jun 2022 19:40:09 +0800 Subject: [PATCH] chore: update cli help message and reamde --- Cargo.lock | 14 ++++++++ Cargo.toml | 4 +-- README.md | 102 +++++++++++++++++++++++++--------------------------- src/args.rs | 12 +++---- src/auth.rs | 4 +-- 5 files changed, 72 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 694f5a7..f60d619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,6 +423,7 @@ dependencies = [ "bitflags", "clap_lex", "indexmap", + "terminal_size", "textwrap", ] @@ -2146,6 +2147,16 @@ dependencies = [ "utf-8", ] +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "termtree" version = "0.2.4" @@ -2157,6 +2168,9 @@ name = "textwrap" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +dependencies = [ + "terminal_size", +] [[package]] name = "thiserror" diff --git a/Cargo.toml b/Cargo.toml index 8de3755..149fc84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "dufs" version = "0.19.0" edition = "2021" authors = ["sigoden "] -description = "Dufs is a simple file server." +description = "Dufs is a distinctive utility file server" license = "MIT OR Apache-2.0" homepage = "https://github.com/sigoden/dufs" repository = "https://github.com/sigoden/dufs" @@ -11,7 +11,7 @@ categories = ["command-line-utilities", "web-programming::http-server"] keywords = ["static", "file", "server", "webdav", "cli"] [dependencies] -clap = { version = "3", default-features = false, features = ["std"] } +clap = { version = "3", default-features = false, features = ["std", "wrap_help"] } chrono = "0.4" tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]} tokio-rustls = "0.23" diff --git a/README.md b/README.md index fd39687..9d34b58 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI](https://github.com/sigoden/dufs/actions/workflows/ci.yaml/badge.svg)](https://github.com/sigoden/dufs/actions/workflows/ci.yaml) [![Crates](https://img.shields.io/crates/v/dufs.svg)](https://crates.io/crates/dufs) -Dufs is a simple file server. Support static serve, search, upload, webdav... +Dufs is a distinctive utility file server that supports static serving, uploading, searching, accessing control, webdav... ![demo](https://user-images.githubusercontent.com/4012553/174486522-7af350e6-0195-4f4a-8480-d9464fc6452f.png) @@ -40,29 +40,28 @@ Download from [Github Releases](https://github.com/sigoden/dufs/releases), unzip ## CLI ``` -Dufs is a simple file server. - https://github.com/sigoden/dufs +Dufs is a distinctive utility file server - https://github.com/sigoden/dufs USAGE: dufs [OPTIONS] [--] [path] ARGS: - Path to a root directory for serving files [default: .] + Specific path to serve [default: .] OPTIONS: -b, --bind ... Specify bind address -p, --port Specify port to listen on [default: 5000] - --path-prefix Specify an url path prefix + --path-prefix Specify an path prefix -a, --auth ... Add auth for path - --auth-method Select auth method [default: digest] [possible values: basic, - digest] + --auth-method Select auth method [default: digest] [possible values: basic, digest] -A, --allow-all Allow all operations --allow-upload Allow upload files/folders --allow-delete Allow delete files/folders --allow-symlink Allow symlink to files/folders outside root directory --enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *` - --render-index Render index.html when requesting a directory - --render-try-index Render index.html if it exists when requesting a directory - --render-spa Render for single-page application + --render-index Serve index.html when requesting a directory, returns 404 if not found index.html + --render-try-index Serve index.html when requesting a directory, returns file listing if not found index.html + --render-spa Serve SPA(Single Page Application) --tls-cert Path to an SSL/TLS certificate to serve with HTTPS --tls-key Path to the SSL/TLS certificate's private key -h, --help Print help information @@ -71,30 +70,60 @@ OPTIONS: ## Examples -Serve current working directory, no upload/delete +Serve current working directory ``` dufs ``` -Allow upload/delete +Explicitly allow all operations including upload/delete ``` dufs -A ``` +Only allow upload operation + +``` +dufs --allow-upload +``` + +Serve a directory + +``` +dufs Downloads +``` + +Serve a single file + +``` +dufs linux-distro.iso +``` + +Serve index.html when requesting a directory + +``` +dufs --render-index +``` + +Serve SPA(Single Page Application) + +``` +dufs --render-spa +``` + +Require username/password + +``` +dufs -a /@admin:123 +``` + Listen on a specific port ``` dufs -p 80 ``` -For a single page application (SPA) - -``` -dufs --render-spa -``` - Use https ``` @@ -126,36 +155,9 @@ Delete a file/folder curl -X DELETE http://127.0.0.1:5000/path-to-file ``` -## Details +## Access Control -
- - -#### 1. Control render logic - - - - -The default render logic is: - -- If request for a folder, rendering the directory listing. -- If request for a file, rendering the file. -- If request target does not exist, returns 404. - -The `--render-*` options change the render logic: - -- `--render-index`: If request for a folder, rendering index.html in the folder. If the index.html file does not exist, return 404. -- `--render-try-index`: Like `--render-index`, rendering the directory listing if the index.html file does not exist, other than return 404. -- `--render-spa`: If request target does not exist, rendering `/index.html` - -
- -
- - -#### 2. Path level access control - - +Dufs implements path level access control through http authentication. ``` dufs -a @[@] @@ -176,14 +178,6 @@ dufs -a /@admin:pass@* -a /ui@designer:pass1 -A - Account `admin:pass` can upload/delete/download any files/folders. - Account `designer:pass1` can upload/delete/download any files/folders in the `ui` folder. -Curl with digest auth: - -``` -curl --digest -u designer:pass1 http://127.0.0.1:5000/ui/path-to-file -``` - -
- ## License Copyright (c) 2022 dufs-developers. diff --git a/src/args.rs b/src/args.rs index 662d440..e43d349 100644 --- a/src/args.rs +++ b/src/args.rs @@ -40,13 +40,13 @@ fn app() -> Command<'static> { Arg::new("path") .default_value(".") .allow_invalid_utf8(true) - .help("Path to a root directory for serving files"), + .help("Specific path to serve"), ) .arg( Arg::new("path-prefix") .long("path-prefix") .value_name("path") - .help("Specify an url path prefix"), + .help("Specify an path prefix"), ) .arg( Arg::new("auth") @@ -94,17 +94,17 @@ fn app() -> Command<'static> { .arg( Arg::new("render-index") .long("render-index") - .help("Render index.html when requesting a directory"), + .help("Serve index.html when requesting a directory, returns 404 if not found index.html"), ) .arg( Arg::new("render-try-index") .long("render-try-index") - .help("Render index.html if it exists when requesting a directory"), + .help("Serve index.html when requesting a directory, returns file listing if not found index.html"), ) .arg( Arg::new("render-spa") .long("render-spa") - .help("Render for single-page application"), + .help("Serve SPA(Single Page Application)"), ) .arg( Arg::new("tls-cert") @@ -124,7 +124,7 @@ pub fn matches() -> ArgMatches { app().get_matches() } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct Args { pub addrs: Vec, pub port: u16, diff --git a/src/auth.rs b/src/auth.rs index c3e6958..424d48e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -22,12 +22,12 @@ lazy_static! { }; } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct AccessControl { rules: HashMap, } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct PathControl { readwrite: Account, readonly: Option,