Add error logging, config and documentation
This commit is contained in:
parent
aed126482d
commit
9e3a7978a7
4 changed files with 43 additions and 29 deletions
57
Readme.md
57
Readme.md
|
@ -32,7 +32,9 @@ It perfectly fits if you would like to give some people the possibility to uploa
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
The configuration is done in form of a yaml file. _swd_ will scan the following locations for the presence of a `config.yaml` in the following order:
|
The configuration is done in form of a yaml file. _swd_ will scan the
|
||||||
|
following locations for the presence of a `config.yaml` in the following
|
||||||
|
order:
|
||||||
|
|
||||||
- The directory `./config`
|
- The directory `./config`
|
||||||
- The directory `$HOME/.swd`
|
- The directory `$HOME/.swd`
|
||||||
|
@ -45,6 +47,7 @@ Here an example of a very simple but functional configuration:
|
||||||
address: "127.0.0.1" # the bind address
|
address: "127.0.0.1" # the bind address
|
||||||
port: "8000" # the listening port
|
port: "8000" # the listening port
|
||||||
dir: "/home/webdav" # the provided base dir
|
dir: "/home/webdav" # the provided base dir
|
||||||
|
prefix: "/webdav" # the url-prefix of the original url
|
||||||
users:
|
users:
|
||||||
user: # with password 'foo' and jailed access to '/home/webdav/user'
|
user: # with password 'foo' and jailed access to '/home/webdav/user'
|
||||||
password: "$2a$10$yITzSSNJZAdDZs8iVBQzkuZCzZ49PyjTiPIrmBUKUpB0pwX7eySvW"
|
password: "$2a$10$yITzSSNJZAdDZs8iVBQzkuZCzZ49PyjTiPIrmBUKUpB0pwX7eySvW"
|
||||||
|
@ -52,10 +55,13 @@ Here an example of a very simple but functional configuration:
|
||||||
admin: # with password 'foo' and access to '/home/webdav'
|
admin: # with password 'foo' and access to '/home/webdav'
|
||||||
password: "$2a$10$DaWhagZaxWnWAOXY0a55.eaYccgtMOL3lGlqI3spqIBGyM0MD.EN6"
|
password: "$2a$10$DaWhagZaxWnWAOXY0a55.eaYccgtMOL3lGlqI3spqIBGyM0MD.EN6"
|
||||||
|
|
||||||
|
With this configuration you'll grant access for two users and the webdav
|
||||||
|
server is available under `http://127.0.0.1:8000/webdav`.
|
||||||
|
|
||||||
### TLS
|
### TLS
|
||||||
|
|
||||||
At first, use your favorite toolchain to obtain a SSL certificate and keyfile (if you don't already have some).
|
At first, use your favorite toolchain to obtain a SSL certificate and
|
||||||
|
keyfile (if you don't already have some).
|
||||||
|
|
||||||
Here an example with `openssl`:
|
Here an example with `openssl`:
|
||||||
|
|
||||||
|
@ -75,21 +81,21 @@ Now you can reference your keypair in the configuration via:
|
||||||
users:
|
users:
|
||||||
...
|
...
|
||||||
|
|
||||||
The presence of the `tls` section is completely enough to let the server start with a TLS secured https connection.
|
The presence of the `tls` section is completely enough to let the server
|
||||||
|
start with a TLS secured https connection.
|
||||||
|
|
||||||
In the current release version you must take care, that the private key doesn't need a passphrase. Otherwise starting the server will fail.
|
In the current release version you must take care, that the private key
|
||||||
|
doesn't need a passphrase. Otherwise starting the server will fail.
|
||||||
|
|
||||||
### Behind a proxy
|
### Behind a proxy
|
||||||
|
|
||||||
If you'd like to move your setup behind a proxy / gateway under a specific path, you can set the config variable `prefix` to match the url-prefix of your proxy configuration.
|
_swd_ will also work behind a reverse proxy. Here is an example
|
||||||
|
configuration with `apache2 httpd`'s `mod_proxy`:
|
||||||
|
|
||||||
For example: If you have a rule that proxies all requests of `https://domain.com/webdav` to `https://localhost:8000`, you have to set the prefix to `/webdav`.
|
<Location /webdav>
|
||||||
|
ProxyPass https://webdav-host:8000/
|
||||||
address: "127.0.0.1" # the bind address
|
ProxyPassReverse https://webdav-host:8000/
|
||||||
port: "8000" # the listening port
|
</Location>
|
||||||
prefix: "/webdav" # the url-prefix of the original url
|
|
||||||
dir: "/home/webdav" # the provided base directory
|
|
||||||
...
|
|
||||||
|
|
||||||
### User management
|
### User management
|
||||||
|
|
||||||
|
@ -108,22 +114,27 @@ You can enable / disable logging for the following operations:
|
||||||
- **U**pdating of files or directories
|
- **U**pdating of files or directories
|
||||||
- **D**eletion of files or directories
|
- **D**eletion of files or directories
|
||||||
|
|
||||||
All logs are disabled per default until you will turn it on via the following config entries:
|
You can also enable or disable the error log.
|
||||||
|
|
||||||
address: "127.0.0.1" # the bind address
|
All file-operation logs are disabled per default until you will turn it on via the following config entries:
|
||||||
port: "8000" # the listening port
|
|
||||||
dir: "/home/webdav" # the provided base directory
|
```yaml
|
||||||
log:
|
address: "127.0.0.1" # the bind address
|
||||||
create: true
|
port: "8000" # the listening port
|
||||||
read: true
|
dir: "/home/webdav" # the provided base directory
|
||||||
update: true
|
log:
|
||||||
delete: true
|
error: true
|
||||||
...
|
create: true
|
||||||
|
read: true
|
||||||
|
update: true
|
||||||
|
delete: true
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
Be aware, that the log pattern of an attached tty differs from the log pattern of a detached tty.
|
Be aware, that the log pattern of an attached tty differs from the log pattern of a detached tty.
|
||||||
|
|
||||||
Example of an attached tty:
|
Example of an attached tty:
|
||||||
|
|
||||||
INFO[0000] Server is starting and listening address=0.0.0.0 port=8000 security=none
|
INFO[0000] Server is starting and listening address=0.0.0.0 port=8000 security=none
|
||||||
|
|
||||||
Example of a detached tty:
|
Example of a detached tty:
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Config struct {
|
||||||
|
|
||||||
// Logging allows definition for logging each CRUD method.
|
// Logging allows definition for logging each CRUD method.
|
||||||
type Logging struct {
|
type Logging struct {
|
||||||
|
Error bool
|
||||||
Create bool
|
Create bool
|
||||||
Read bool
|
Read bool
|
||||||
Update bool
|
Update bool
|
||||||
|
@ -84,6 +85,7 @@ func setDefaults() {
|
||||||
viper.SetDefault("Prefix", "")
|
viper.SetDefault("Prefix", "")
|
||||||
viper.SetDefault("Dir", "/tmp")
|
viper.SetDefault("Dir", "/tmp")
|
||||||
viper.SetDefault("TLS", nil)
|
viper.SetDefault("TLS", nil)
|
||||||
|
viper.SetDefault("Log.Error", true)
|
||||||
viper.SetDefault("Log.Create", false)
|
viper.SetDefault("Log.Create", false)
|
||||||
viper.SetDefault("Log.Read", false)
|
viper.SetDefault("Log.Read", false)
|
||||||
viper.SetDefault("Log.Update", false)
|
viper.SetDefault("Log.Update", false)
|
||||||
|
|
|
@ -20,7 +20,7 @@ func main() {
|
||||||
},
|
},
|
||||||
LockSystem: webdav.NewMemLS(),
|
LockSystem: webdav.NewMemLS(),
|
||||||
Logger: func(request *http.Request, err error) {
|
Logger: func(request *http.Request, err error) {
|
||||||
if err != nil {
|
if config.Log.Error && err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -48,10 +48,11 @@ users:
|
||||||
# ---------------------------------- Logging -----------------------------------
|
# ---------------------------------- Logging -----------------------------------
|
||||||
#
|
#
|
||||||
# Seperated loglevels for file / directory operations. All set to false per
|
# Seperated loglevels for file / directory operations. All set to false per
|
||||||
# default.
|
# default instead of error log. The error log is set to true per default.
|
||||||
#
|
#
|
||||||
#log:
|
#log:
|
||||||
# create: true
|
# error: true
|
||||||
# read: true
|
# create: false
|
||||||
# update: true
|
# read: false
|
||||||
# delete: true
|
# update: false
|
||||||
|
# delete: falst
|
||||||
|
|
Loading…
Reference in a new issue