chore: update cli help message and reamde

This commit is contained in:
sigoden 2022-06-20 19:40:09 +08:00
parent 68139c6263
commit c85ea06785
5 changed files with 72 additions and 64 deletions

14
Cargo.lock generated
View file

@ -423,6 +423,7 @@ dependencies = [
"bitflags", "bitflags",
"clap_lex", "clap_lex",
"indexmap", "indexmap",
"terminal_size",
"textwrap", "textwrap",
] ]
@ -2146,6 +2147,16 @@ dependencies = [
"utf-8", "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]] [[package]]
name = "termtree" name = "termtree"
version = "0.2.4" version = "0.2.4"
@ -2157,6 +2168,9 @@ name = "textwrap"
version = "0.15.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [
"terminal_size",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"

View file

@ -3,7 +3,7 @@ name = "dufs"
version = "0.19.0" version = "0.19.0"
edition = "2021" edition = "2021"
authors = ["sigoden <sigoden@gmail.com>"] authors = ["sigoden <sigoden@gmail.com>"]
description = "Dufs is a simple file server." description = "Dufs is a distinctive utility file server"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
homepage = "https://github.com/sigoden/dufs" homepage = "https://github.com/sigoden/dufs"
repository = "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"] keywords = ["static", "file", "server", "webdav", "cli"]
[dependencies] [dependencies]
clap = { version = "3", default-features = false, features = ["std"] } clap = { version = "3", default-features = false, features = ["std", "wrap_help"] }
chrono = "0.4" chrono = "0.4"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]} tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]}
tokio-rustls = "0.23" tokio-rustls = "0.23"

102
README.md
View file

@ -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) [![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) [![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) ![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 ## 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: USAGE:
dufs [OPTIONS] [--] [path] dufs [OPTIONS] [--] [path]
ARGS: ARGS:
<path> Path to a root directory for serving files [default: .] <path> Specific path to serve [default: .]
OPTIONS: OPTIONS:
-b, --bind <addr>... Specify bind address -b, --bind <addr>... Specify bind address
-p, --port <port> Specify port to listen on [default: 5000] -p, --port <port> Specify port to listen on [default: 5000]
--path-prefix <path> Specify an url path prefix --path-prefix <path> Specify an path prefix
-a, --auth <rule>... Add auth for path -a, --auth <rule>... Add auth for path
--auth-method <value> Select auth method [default: digest] [possible values: basic, --auth-method <value> Select auth method [default: digest] [possible values: basic, digest]
digest]
-A, --allow-all Allow all operations -A, --allow-all Allow all operations
--allow-upload Allow upload files/folders --allow-upload Allow upload files/folders
--allow-delete Allow delete files/folders --allow-delete Allow delete files/folders
--allow-symlink Allow symlink to files/folders outside root directory --allow-symlink Allow symlink to files/folders outside root directory
--enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *` --enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *`
--render-index Render index.html when requesting a directory --render-index Serve index.html when requesting a directory, returns 404 if not found index.html
--render-try-index Render index.html if it exists when requesting a directory --render-try-index Serve index.html when requesting a directory, returns file listing if not found index.html
--render-spa Render for single-page application --render-spa Serve SPA(Single Page Application)
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS --tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
--tls-key <path> Path to the SSL/TLS certificate's private key --tls-key <path> Path to the SSL/TLS certificate's private key
-h, --help Print help information -h, --help Print help information
@ -71,30 +70,60 @@ OPTIONS:
## Examples ## Examples
Serve current working directory, no upload/delete Serve current working directory
``` ```
dufs dufs
``` ```
Allow upload/delete Explicitly allow all operations including upload/delete
``` ```
dufs -A 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 Listen on a specific port
``` ```
dufs -p 80 dufs -p 80
``` ```
For a single page application (SPA)
```
dufs --render-spa
```
Use https Use https
``` ```
@ -126,36 +155,9 @@ Delete a file/folder
curl -X DELETE http://127.0.0.1:5000/path-to-file curl -X DELETE http://127.0.0.1:5000/path-to-file
``` ```
## Details ## Access Control
<details> Dufs implements path level access control through http authentication.
<summary>
#### 1. Control render logic
</summary>
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`
</details>
<details>
<summary>
#### 2. Path level access control
</summary>
``` ```
dufs -a <path>@<readwrite>[@<readonly>] dufs -a <path>@<readwrite>[@<readonly>]
@ -176,14 +178,6 @@ dufs -a /@admin:pass@* -a /ui@designer:pass1 -A
- Account `admin:pass` can upload/delete/download any files/folders. - Account `admin:pass` can upload/delete/download any files/folders.
- Account `designer:pass1` can upload/delete/download any files/folders in the `ui` folder. - 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
```
</details>
## License ## License
Copyright (c) 2022 dufs-developers. Copyright (c) 2022 dufs-developers.

View file

@ -40,13 +40,13 @@ fn app() -> Command<'static> {
Arg::new("path") Arg::new("path")
.default_value(".") .default_value(".")
.allow_invalid_utf8(true) .allow_invalid_utf8(true)
.help("Path to a root directory for serving files"), .help("Specific path to serve"),
) )
.arg( .arg(
Arg::new("path-prefix") Arg::new("path-prefix")
.long("path-prefix") .long("path-prefix")
.value_name("path") .value_name("path")
.help("Specify an url path prefix"), .help("Specify an path prefix"),
) )
.arg( .arg(
Arg::new("auth") Arg::new("auth")
@ -94,17 +94,17 @@ fn app() -> Command<'static> {
.arg( .arg(
Arg::new("render-index") Arg::new("render-index")
.long("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(
Arg::new("render-try-index") Arg::new("render-try-index")
.long("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(
Arg::new("render-spa") Arg::new("render-spa")
.long("render-spa") .long("render-spa")
.help("Render for single-page application"), .help("Serve SPA(Single Page Application)"),
) )
.arg( .arg(
Arg::new("tls-cert") Arg::new("tls-cert")
@ -124,7 +124,7 @@ pub fn matches() -> ArgMatches {
app().get_matches() app().get_matches()
} }
#[derive(Debug, Clone)] #[derive(Debug)]
pub struct Args { pub struct Args {
pub addrs: Vec<IpAddr>, pub addrs: Vec<IpAddr>,
pub port: u16, pub port: u16,

View file

@ -22,12 +22,12 @@ lazy_static! {
}; };
} }
#[derive(Debug, Clone)] #[derive(Debug)]
pub struct AccessControl { pub struct AccessControl {
rules: HashMap<String, PathControl>, rules: HashMap<String, PathControl>,
} }
#[derive(Debug, Clone)] #[derive(Debug)]
pub struct PathControl { pub struct PathControl {
readwrite: Account, readwrite: Account,
readonly: Option<Account>, readonly: Option<Account>,