Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 9e3a797

Browse files
committed
Add error logging, config and documentation
1 parent aed1264 commit 9e3a797

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

Readme.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ It perfectly fits if you would like to give some people the possibility to uploa
3232

3333
## Configuration
3434

35-
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:
35+
The configuration is done in form of a yaml file. _swd_ will scan the
36+
following locations for the presence of a `config.yaml` in the following
37+
order:
3638

3739
- The directory `./config`
3840
- The directory `$HOME/.swd`
@@ -45,17 +47,21 @@ Here an example of a very simple but functional configuration:
4547
address: "127.0.0.1" # the bind address
4648
port: "8000" # the listening port
4749
dir: "/home/webdav" # the provided base dir
50+
prefix: "/webdav" # the url-prefix of the original url
4851
users:
4952
user: # with password 'foo' and jailed access to '/home/webdav/user'
5053
password: "$2a$10$yITzSSNJZAdDZs8iVBQzkuZCzZ49PyjTiPIrmBUKUpB0pwX7eySvW"
5154
subdir: "/user"
5255
admin: # with password 'foo' and access to '/home/webdav'
5356
password: "$2a$10$DaWhagZaxWnWAOXY0a55.eaYccgtMOL3lGlqI3spqIBGyM0MD.EN6"
5457

58+
With this configuration you'll grant access for two users and the webdav
59+
server is available under `http://127.0.0.1:8000/webdav`.
5560

5661
### TLS
5762

58-
At first, use your favorite toolchain to obtain a SSL certificate and keyfile (if you don't already have some).
63+
At first, use your favorite toolchain to obtain a SSL certificate and
64+
keyfile (if you don't already have some).
5965

6066
Here an example with `openssl`:
6167

@@ -75,21 +81,21 @@ Now you can reference your keypair in the configuration via:
7581
users:
7682
...
7783

78-
The presence of the `tls` section is completely enough to let the server start with a TLS secured https connection.
84+
The presence of the `tls` section is completely enough to let the server
85+
start with a TLS secured https connection.
7986

80-
In the current release version you must take care, that the private key doesn't need a passphrase. Otherwise starting the server will fail.
87+
In the current release version you must take care, that the private key
88+
doesn't need a passphrase. Otherwise starting the server will fail.
8189

8290
### Behind a proxy
8391

84-
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.
85-
86-
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`.
92+
_swd_ will also work behind a reverse proxy. Here is an example
93+
configuration with `apache2 httpd`'s `mod_proxy`:
8794

88-
address: "127.0.0.1" # the bind address
89-
port: "8000" # the listening port
90-
prefix: "/webdav" # the url-prefix of the original url
91-
dir: "/home/webdav" # the provided base directory
92-
...
95+
<Location /webdav>
96+
ProxyPass https://webdav-host:8000/
97+
ProxyPassReverse https://webdav-host:8000/
98+
</Location>
9399

94100
### User management
95101

@@ -108,22 +114,27 @@ You can enable / disable logging for the following operations:
108114
- **U**pdating of files or directories
109115
- **D**eletion of files or directories
110116

111-
All logs are disabled per default until you will turn it on via the following config entries:
117+
You can also enable or disable the error log.
112118

113-
address: "127.0.0.1" # the bind address
114-
port: "8000" # the listening port
115-
dir: "/home/webdav" # the provided base directory
116-
log:
117-
create: true
118-
read: true
119-
update: true
120-
delete: true
121-
...
119+
All file-operation logs are disabled per default until you will turn it on via the following config entries:
120+
121+
```yaml
122+
address: "127.0.0.1" # the bind address
123+
port: "8000" # the listening port
124+
dir: "/home/webdav" # the provided base directory
125+
log:
126+
error: true
127+
create: true
128+
read: true
129+
update: true
130+
delete: true
131+
...
132+
```
122133

123134
Be aware, that the log pattern of an attached tty differs from the log pattern of a detached tty.
124135

125136
Example of an attached tty:
126-
137+
127138
INFO[0000] Server is starting and listening address=0.0.0.0 port=8000 security=none
128139

129140
Example of a detached tty:

app/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Config struct {
2222

2323
// Logging allows definition for logging each CRUD method.
2424
type Logging struct {
25+
Error bool
2526
Create bool
2627
Read bool
2728
Update bool
@@ -84,6 +85,7 @@ func setDefaults() {
8485
viper.SetDefault("Prefix", "")
8586
viper.SetDefault("Dir", "/tmp")
8687
viper.SetDefault("TLS", nil)
88+
viper.SetDefault("Log.Error", true)
8789
viper.SetDefault("Log.Create", false)
8890
viper.SetDefault("Log.Read", false)
8991
viper.SetDefault("Log.Update", false)

cmd/swd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func main() {
2020
},
2121
LockSystem: webdav.NewMemLS(),
2222
Logger: func(request *http.Request, err error) {
23-
if err != nil {
23+
if config.Log.Error && err != nil {
2424
log.Error(err)
2525
}
2626
},

examples/config-sample.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ users:
4848
# ---------------------------------- Logging -----------------------------------
4949
#
5050
# Seperated loglevels for file / directory operations. All set to false per
51-
# default.
51+
# default instead of error log. The error log is set to true per default.
5252
#
5353
#log:
54-
# create: true
55-
# read: true
56-
# update: true
57-
# delete: true
54+
# error: true
55+
# create: false
56+
# read: false
57+
# update: false
58+
# delete: falst

0 commit comments

Comments
 (0)