Compare commits
111 Commits
1
...
dev-bodycl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d8627db50 | ||
|
|
c42caf78a2 | ||
|
|
341db84788 | ||
|
|
b51247bb2c | ||
|
|
3f8721cd4b | ||
|
|
adba8dc051 | ||
|
|
2f2cda4122 | ||
|
|
73a7f0bf37 | ||
|
|
aff231de53 | ||
|
|
e5dd1e70b1 | ||
|
|
29e74efa70 | ||
|
|
741fdbda3d | ||
|
|
a3a86976a1 | ||
|
|
a2cbdfa976 | ||
|
|
9a1ba21162 | ||
|
|
7ff61aa87b | ||
|
|
86f8378cf1 | ||
|
|
4145fa842c | ||
|
|
8244b5a5f5 | ||
|
|
d02a1ebcd2 | ||
|
|
3ed042db71 | ||
|
|
bdacfab947 | ||
|
|
617404b525 | ||
|
|
9380631c29 | ||
|
|
a93005d73c | ||
|
|
321978fa73 | ||
|
|
c4c707907d | ||
|
|
9f625b1b8e | ||
|
|
e53b818e1b | ||
|
|
ff7f737904 | ||
|
|
38f79aeaf1 | ||
|
|
6c32839dbd | ||
|
|
4d70d7ea28 | ||
|
|
8bcb1b383c | ||
|
|
cba565a9dc | ||
|
|
425530b55e | ||
|
|
7493d8befb | ||
|
|
e29bc0f031 | ||
|
|
c8fc9ca590 | ||
|
|
a68e21e92b | ||
|
|
02aa9bdaeb | ||
|
|
8de8ce169b | ||
|
|
3cd755d6c4 | ||
|
|
83e3d1e31e | ||
|
|
28039fda22 | ||
|
|
45a56c2115 | ||
|
|
f821ab73e9 | ||
|
|
ec1263db2f | ||
|
|
95706c0747 | ||
|
|
f43a0a4cf8 | ||
|
|
68824ef55e | ||
|
|
6ca20e2a70 | ||
|
|
790397514e | ||
|
|
4ca2f77e2b | ||
|
|
008b27eb0f | ||
|
|
d1ebcbebf2 | ||
|
|
4f450cfd02 | ||
|
|
876ef52924 | ||
|
|
21d86ab356 | ||
|
|
97a0b83aeb | ||
|
|
1fe9163c92 | ||
|
|
8bab650703 | ||
|
|
c4c24955e1 | ||
|
|
2593a81bf0 | ||
|
|
b45378c08f | ||
|
|
aebc3ef9d2 | ||
|
|
9ff8e33634 | ||
|
|
a33240e4ab | ||
|
|
fbcb29d33e | ||
|
|
6d8c168f72 | ||
|
|
5bedad6f1e | ||
|
|
31e0b57e53 | ||
|
|
ba3a71318b | ||
|
|
fa51555f16 | ||
|
|
e0b778960b | ||
|
|
a98da9745e | ||
|
|
1786d37966 | ||
|
|
32d5561fb6 | ||
|
|
d6b82df09a | ||
|
|
c16034adb0 | ||
|
|
1e4b7a5554 | ||
|
|
3993494db0 | ||
|
|
34368960d0 | ||
|
|
375f391c8a | ||
|
|
c49c91989e | ||
|
|
7ea52a8e4f | ||
|
|
0e7fe90d28 | ||
|
|
0120c3c3c4 | ||
|
|
410e447c49 | ||
|
|
65a34986d4 | ||
|
|
73b90bf27e | ||
|
|
9c695fe0df | ||
|
|
732590873e | ||
|
|
5a1a85f622 | ||
|
|
056ad2c4d5 | ||
|
|
8a7d0f4982 | ||
|
|
beeefa572c | ||
|
|
b290410ef9 | ||
|
|
af17afdfdc | ||
|
|
76d61cc2bc | ||
|
|
06583fe483 | ||
|
|
49e0e45d8f | ||
|
|
a3c4dbab4a | ||
|
|
f60c73fbb4 | ||
|
|
a11466bd13 | ||
|
|
e3cd1f98e7 | ||
|
|
e3a31466a7 | ||
|
|
2b5dab74d3 | ||
|
|
79a29f3ad5 | ||
|
|
a03a0a3645 | ||
|
|
12fe295146 |
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello Collaborators,
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A short description of what you think the bug is.
|
||||||
|
|
||||||
|
**Software**
|
||||||
|
- OS:
|
||||||
|
- Golang:
|
||||||
|
- Version:
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected**
|
||||||
|
A short description of what you expected to happen.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
46
.github/workflows/artifacts.yml
vendored
Normal file
46
.github/workflows/artifacts.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Build Artifacts
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- "**.md"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_artifacts:
|
||||||
|
name: Build Artifcats
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: "^1.17"
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Get dependencies
|
||||||
|
run: go get ./...
|
||||||
|
- name: Build Client (${{ matrix.goos }}-${{ matrix.goarch }})
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
run: go build -v -o ./bin/gowebdav-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/gowebdav/main.go
|
||||||
|
- name: Rename Windows Binary
|
||||||
|
if: ${{ matrix.goos == 'windows' }}
|
||||||
|
env:
|
||||||
|
FNAME: ./bin/gowebdav-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
run: mv ${{ env.FNAME }} ${{ env.FNAME }}.exe
|
||||||
|
- name: Upload Artifcats
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
path: ./bin/
|
||||||
30
.github/workflows/tests.yml
vendored
Normal file
30
.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
name: Unit Tests
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
paths-ignore:
|
||||||
|
- "**.md"
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit_tests:
|
||||||
|
name: Unit Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
goversion:
|
||||||
|
- "1.17"
|
||||||
|
- "1.16"
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.goversion }}
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Get dependencies
|
||||||
|
run: go get ./...
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run: go test -v -cover -race ./...
|
||||||
23
.gitignore
vendored
23
.gitignore
vendored
@@ -1,2 +1,21 @@
|
|||||||
src
|
# Folders to ignore
|
||||||
bin
|
/src
|
||||||
|
/bin
|
||||||
|
/pkg
|
||||||
|
/gowebdav
|
||||||
|
/.idea
|
||||||
|
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
.vscode/
|
||||||
10
.travis.yml
Normal file
10
.travis.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- "1.x"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go get ./...
|
||||||
|
|
||||||
|
script:
|
||||||
|
- go test -v --short ./...
|
||||||
38
Makefile
38
Makefile
@@ -1,21 +1,33 @@
|
|||||||
SRC := $(wildcard *.go) main/client.go
|
BIN := gowebdav
|
||||||
BIN := bin
|
SRC := $(wildcard *.go) cmd/gowebdav/main.go
|
||||||
CLIENT := ${BIN}/client
|
|
||||||
GOPATH ?= ${PWD}
|
|
||||||
|
|
||||||
all: test client
|
all: test cmd
|
||||||
|
|
||||||
client: ${CLIENT}
|
cmd: ${BIN}
|
||||||
|
|
||||||
${CLIENT}: ${SRC}
|
${BIN}: ${SRC}
|
||||||
@echo build $@
|
go build -o $@ ./cmd/gowebdav
|
||||||
@GOPATH=${GOPATH} go build -o $@ -- main/client.go
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@GOPATH=${GOPATH} go test
|
go test -v --short ./...
|
||||||
|
|
||||||
|
api:
|
||||||
|
@sed '/^## API$$/,$$d' -i README.md
|
||||||
|
@echo '## API' >> README.md
|
||||||
|
@godoc2md github.com/studio-b12/gowebdav | sed '/^$$/N;/^\n$$/D' |\
|
||||||
|
sed '2d' |\
|
||||||
|
sed 's/\/src\/github.com\/studio-b12\/gowebdav\//https:\/\/github.com\/studio-b12\/gowebdav\/blob\/master\//g' |\
|
||||||
|
sed 's/\/src\/target\//https:\/\/github.com\/studio-b12\/gowebdav\/blob\/master\//g' |\
|
||||||
|
sed 's/^#/##/g' >> README.md
|
||||||
|
|
||||||
|
check:
|
||||||
|
gofmt -w -s $(SRC)
|
||||||
|
@echo
|
||||||
|
gocyclo -over 15 .
|
||||||
|
@echo
|
||||||
|
golint ./...
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo clean ${BIN}
|
@rm -f ${BIN}
|
||||||
@rm -f ${BIN}/*
|
|
||||||
|
|
||||||
.PHONY: all client clean
|
.PHONY: all cmd clean test api check
|
||||||
|
|||||||
552
README.md
552
README.md
@@ -1,10 +1,550 @@
|
|||||||
# GOWEBDAV - WebDAV Client for golang
|
# GoWebDAV
|
||||||
|
|
||||||
## LINKS
|
[](https://travis-ci.org/studio-b12/gowebdav)
|
||||||
|
[](https://godoc.org/github.com/studio-b12/gowebdav)
|
||||||
|
[](https://goreportcard.com/report/github.com/studio-b12/gowebdav)
|
||||||
|
|
||||||
* [rfc2518](http://asg.andrew.cmu.edu/rfc/rfc2518.html)
|
A golang WebDAV client library.
|
||||||
* [rfc2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
|
|
||||||
|
|
||||||
## Books
|
## Main features
|
||||||
|
`gowebdav` library allows to perform following actions on the remote WebDAV server:
|
||||||
|
* [create path](#create-path-on-a-webdav-server)
|
||||||
|
* [get files list](#get-files-list)
|
||||||
|
* [download file](#download-file-to-byte-array)
|
||||||
|
* [upload file](#upload-file-from-byte-array)
|
||||||
|
* [get information about specified file/folder](#get-information-about-specified-filefolder)
|
||||||
|
* [move file to another location](#move-file-to-another-location)
|
||||||
|
* [copy file to another location](#copy-file-to-another-location)
|
||||||
|
* [delete file](#delete-file)
|
||||||
|
|
||||||
* [WebDav: Next Gen](https://books.google.de/books?isbn=0130652083 "WebDav: Next Generation Collaborative Web Authoring By Lisa Dusseault")
|
## Usage
|
||||||
|
|
||||||
|
First of all you should create `Client` instance using `NewClient()` function:
|
||||||
|
|
||||||
|
```go
|
||||||
|
root := "https://webdav.mydomain.me"
|
||||||
|
user := "user"
|
||||||
|
password := "password"
|
||||||
|
|
||||||
|
c := gowebdav.NewClient(root, user, password)
|
||||||
|
```
|
||||||
|
|
||||||
|
After you can use this `Client` to perform actions, described below.
|
||||||
|
|
||||||
|
**NOTICE:** we will not check errors in examples, to focus you on the `gowebdav` library's code, but you should do it in your code!
|
||||||
|
|
||||||
|
### Create path on a WebDAV server
|
||||||
|
```go
|
||||||
|
err := c.Mkdir("folder", 0644)
|
||||||
|
```
|
||||||
|
In case you want to create several folders you can use `c.MkdirAll()`:
|
||||||
|
```go
|
||||||
|
err := c.MkdirAll("folder/subfolder/subfolder2", 0644)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get files list
|
||||||
|
```go
|
||||||
|
files, _ := c.ReadDir("folder/subfolder")
|
||||||
|
for _, file := range files {
|
||||||
|
//notice that [file] has os.FileInfo type
|
||||||
|
fmt.Println(file.Name())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Download file to byte array
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
localFilePath := "/tmp/webdav/file.txt"
|
||||||
|
|
||||||
|
bytes, _ := c.Read(webdavFilePath)
|
||||||
|
ioutil.WriteFile(localFilePath, bytes, 0644)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Download file via reader
|
||||||
|
Also you can use `c.ReadStream()` method:
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
localFilePath := "/tmp/webdav/file.txt"
|
||||||
|
|
||||||
|
reader, _ := c.ReadStream(webdavFilePath)
|
||||||
|
|
||||||
|
file, _ := os.Create(localFilePath)
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
io.Copy(file, reader)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Upload file from byte array
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
localFilePath := "/tmp/webdav/file.txt"
|
||||||
|
|
||||||
|
bytes, _ := ioutil.ReadFile(localFilePath)
|
||||||
|
|
||||||
|
c.Write(webdavFilePath, bytes, 0644)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Upload file via writer
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
localFilePath := "/tmp/webdav/file.txt"
|
||||||
|
|
||||||
|
file, _ := os.Open(localFilePath)
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
c.WriteStream(webdavFilePath, file, 0644)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get information about specified file/folder
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
|
||||||
|
info := c.Stat(webdavFilePath)
|
||||||
|
//notice that [info] has os.FileInfo type
|
||||||
|
fmt.Println(info)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Move file to another location
|
||||||
|
```go
|
||||||
|
oldPath := "folder/subfolder/file.txt"
|
||||||
|
newPath := "folder/subfolder/moved.txt"
|
||||||
|
isOverwrite := true
|
||||||
|
|
||||||
|
c.Rename(oldPath, newPath, isOverwrite)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Copy file to another location
|
||||||
|
```go
|
||||||
|
oldPath := "folder/subfolder/file.txt"
|
||||||
|
newPath := "folder/subfolder/file-copy.txt"
|
||||||
|
isOverwrite := true
|
||||||
|
|
||||||
|
c.Copy(oldPath, newPath, isOverwrite)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete file
|
||||||
|
```go
|
||||||
|
webdavFilePath := "folder/subfolder/file.txt"
|
||||||
|
|
||||||
|
c.Remove(webdavFilePath)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
More details about WebDAV server you can read from following resources:
|
||||||
|
|
||||||
|
* [RFC 4918 - HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)](https://tools.ietf.org/html/rfc4918)
|
||||||
|
* [RFC 5689 - Extended MKCOL for Web Distributed Authoring and Versioning (WebDAV)](https://tools.ietf.org/html/rfc5689)
|
||||||
|
* [RFC 2616 - HTTP/1.1 Status Code Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html "HTTP/1.1 Status Code Definitions")
|
||||||
|
* [WebDav: Next Generation Collaborative Web Authoring By Lisa Dusseaul](https://books.google.de/books?isbn=0130652083 "WebDav: Next Generation Collaborative Web Authoring By Lisa Dusseault")
|
||||||
|
|
||||||
|
**NOTICE**: RFC 2518 is obsoleted by RFC 4918 in June 2007
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
All contributing are welcome. If you have any suggestions or find some bug - please create an Issue to let us make this project better. We appreciate your help!
|
||||||
|
|
||||||
|
## License
|
||||||
|
This library is distributed under the BSD 3-Clause license found in the [LICENSE](https://github.com/studio-b12/gowebdav/blob/master/LICENSE) file.
|
||||||
|
## API
|
||||||
|
|
||||||
|
`import "github.com/studio-b12/gowebdav"`
|
||||||
|
|
||||||
|
* [Overview](#pkg-overview)
|
||||||
|
* [Index](#pkg-index)
|
||||||
|
* [Examples](#pkg-examples)
|
||||||
|
* [Subdirectories](#pkg-subdirectories)
|
||||||
|
|
||||||
|
### <a name="pkg-overview">Overview</a>
|
||||||
|
Package gowebdav is a WebDAV client library with a command line tool
|
||||||
|
included.
|
||||||
|
|
||||||
|
### <a name="pkg-index">Index</a>
|
||||||
|
* [func FixSlash(s string) string](#FixSlash)
|
||||||
|
* [func FixSlashes(s string) string](#FixSlashes)
|
||||||
|
* [func Join(path0 string, path1 string) string](#Join)
|
||||||
|
* [func PathEscape(path string) string](#PathEscape)
|
||||||
|
* [func ReadConfig(uri, netrc string) (string, string)](#ReadConfig)
|
||||||
|
* [func String(r io.Reader) string](#String)
|
||||||
|
* [type Authenticator](#Authenticator)
|
||||||
|
* [type BasicAuth](#BasicAuth)
|
||||||
|
* [func (b *BasicAuth) Authorize(req *http.Request, method string, path string)](#BasicAuth.Authorize)
|
||||||
|
* [func (b *BasicAuth) Pass() string](#BasicAuth.Pass)
|
||||||
|
* [func (b *BasicAuth) Type() string](#BasicAuth.Type)
|
||||||
|
* [func (b *BasicAuth) User() string](#BasicAuth.User)
|
||||||
|
* [type Client](#Client)
|
||||||
|
* [func NewClient(uri, user, pw string) *Client](#NewClient)
|
||||||
|
* [func (c *Client) Connect() error](#Client.Connect)
|
||||||
|
* [func (c *Client) Copy(oldpath, newpath string, overwrite bool) error](#Client.Copy)
|
||||||
|
* [func (c *Client) Mkdir(path string, _ os.FileMode) error](#Client.Mkdir)
|
||||||
|
* [func (c *Client) MkdirAll(path string, _ os.FileMode) error](#Client.MkdirAll)
|
||||||
|
* [func (c *Client) Read(path string) ([]byte, error)](#Client.Read)
|
||||||
|
* [func (c *Client) ReadDir(path string) ([]os.FileInfo, error)](#Client.ReadDir)
|
||||||
|
* [func (c *Client) ReadStream(path string) (io.ReadCloser, error)](#Client.ReadStream)
|
||||||
|
* [func (c *Client) Remove(path string) error](#Client.Remove)
|
||||||
|
* [func (c *Client) RemoveAll(path string) error](#Client.RemoveAll)
|
||||||
|
* [func (c *Client) Rename(oldpath, newpath string, overwrite bool) error](#Client.Rename)
|
||||||
|
* [func (c *Client) SetHeader(key, value string)](#Client.SetHeader)
|
||||||
|
* [func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))](#Client.SetInterceptor)
|
||||||
|
* [func (c *Client) SetTimeout(timeout time.Duration)](#Client.SetTimeout)
|
||||||
|
* [func (c *Client) SetTransport(transport http.RoundTripper)](#Client.SetTransport)
|
||||||
|
* [func (c *Client) Stat(path string) (os.FileInfo, error)](#Client.Stat)
|
||||||
|
* [func (c *Client) Write(path string, data []byte, _ os.FileMode) error](#Client.Write)
|
||||||
|
* [func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error](#Client.WriteStream)
|
||||||
|
* [type DigestAuth](#DigestAuth)
|
||||||
|
* [func (d *DigestAuth) Authorize(req *http.Request, method string, path string)](#DigestAuth.Authorize)
|
||||||
|
* [func (d *DigestAuth) Pass() string](#DigestAuth.Pass)
|
||||||
|
* [func (d *DigestAuth) Type() string](#DigestAuth.Type)
|
||||||
|
* [func (d *DigestAuth) User() string](#DigestAuth.User)
|
||||||
|
* [type File](#File)
|
||||||
|
* [func (f File) ContentType() string](#File.ContentType)
|
||||||
|
* [func (f File) ETag() string](#File.ETag)
|
||||||
|
* [func (f File) IsDir() bool](#File.IsDir)
|
||||||
|
* [func (f File) ModTime() time.Time](#File.ModTime)
|
||||||
|
* [func (f File) Mode() os.FileMode](#File.Mode)
|
||||||
|
* [func (f File) Name() string](#File.Name)
|
||||||
|
* [func (f File) Path() string](#File.Path)
|
||||||
|
* [func (f File) Size() int64](#File.Size)
|
||||||
|
* [func (f File) String() string](#File.String)
|
||||||
|
* [func (f File) Sys() interface{}](#File.Sys)
|
||||||
|
* [type NoAuth](#NoAuth)
|
||||||
|
* [func (n *NoAuth) Authorize(req *http.Request, method string, path string)](#NoAuth.Authorize)
|
||||||
|
* [func (n *NoAuth) Pass() string](#NoAuth.Pass)
|
||||||
|
* [func (n *NoAuth) Type() string](#NoAuth.Type)
|
||||||
|
* [func (n *NoAuth) User() string](#NoAuth.User)
|
||||||
|
|
||||||
|
##### <a name="pkg-examples">Examples</a>
|
||||||
|
* [PathEscape](#example_PathEscape)
|
||||||
|
|
||||||
|
##### <a name="pkg-files">Package files</a>
|
||||||
|
[basicAuth.go](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go) [client.go](https://github.com/studio-b12/gowebdav/blob/master/client.go) [digestAuth.go](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go) [doc.go](https://github.com/studio-b12/gowebdav/blob/master/doc.go) [file.go](https://github.com/studio-b12/gowebdav/blob/master/file.go) [netrc.go](https://github.com/studio-b12/gowebdav/blob/master/netrc.go) [requests.go](https://github.com/studio-b12/gowebdav/blob/master/requests.go) [utils.go](https://github.com/studio-b12/gowebdav/blob/master/utils.go)
|
||||||
|
|
||||||
|
### <a name="FixSlash">func</a> [FixSlash](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=707:737#L45)
|
||||||
|
``` go
|
||||||
|
func FixSlash(s string) string
|
||||||
|
```
|
||||||
|
FixSlash appends a trailing / to our string
|
||||||
|
|
||||||
|
### <a name="FixSlashes">func</a> [FixSlashes](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=859:891#L53)
|
||||||
|
``` go
|
||||||
|
func FixSlashes(s string) string
|
||||||
|
```
|
||||||
|
FixSlashes appends and prepends a / if they are missing
|
||||||
|
|
||||||
|
### <a name="Join">func</a> [Join](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=976:1020#L61)
|
||||||
|
``` go
|
||||||
|
func Join(path0 string, path1 string) string
|
||||||
|
```
|
||||||
|
Join joins two paths
|
||||||
|
|
||||||
|
### <a name="PathEscape">func</a> [PathEscape](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=506:541#L36)
|
||||||
|
``` go
|
||||||
|
func PathEscape(path string) string
|
||||||
|
```
|
||||||
|
PathEscape escapes all segemnts of a given path
|
||||||
|
|
||||||
|
### <a name="ReadConfig">func</a> [ReadConfig](https://github.com/studio-b12/gowebdav/blob/master/netrc.go?s=428:479#L27)
|
||||||
|
``` go
|
||||||
|
func ReadConfig(uri, netrc string) (string, string)
|
||||||
|
```
|
||||||
|
ReadConfig reads login and password configuration from ~/.netrc
|
||||||
|
machine foo.com login username password 123456
|
||||||
|
|
||||||
|
### <a name="String">func</a> [String](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=1150:1181#L66)
|
||||||
|
``` go
|
||||||
|
func String(r io.Reader) string
|
||||||
|
```
|
||||||
|
String pulls a string out of our io.Reader
|
||||||
|
|
||||||
|
### <a name="Authenticator">type</a> [Authenticator](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=381:500#L28)
|
||||||
|
``` go
|
||||||
|
type Authenticator interface {
|
||||||
|
Type() string
|
||||||
|
User() string
|
||||||
|
Pass() string
|
||||||
|
Authorize(*http.Request, string, string)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Authenticator stub
|
||||||
|
|
||||||
|
### <a name="BasicAuth">type</a> [BasicAuth](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=106:157#L9)
|
||||||
|
``` go
|
||||||
|
type BasicAuth struct {
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
BasicAuth structure holds our credentials
|
||||||
|
|
||||||
|
#### <a name="BasicAuth.Authorize">func</a> (\*BasicAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=473:549#L30)
|
||||||
|
``` go
|
||||||
|
func (b *BasicAuth) Authorize(req *http.Request, method string, path string)
|
||||||
|
```
|
||||||
|
Authorize the current request
|
||||||
|
|
||||||
|
#### <a name="BasicAuth.Pass">func</a> (\*BasicAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=388:421#L25)
|
||||||
|
``` go
|
||||||
|
func (b *BasicAuth) Pass() string
|
||||||
|
```
|
||||||
|
Pass holds the BasicAuth password
|
||||||
|
|
||||||
|
#### <a name="BasicAuth.Type">func</a> (\*BasicAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=201:234#L15)
|
||||||
|
``` go
|
||||||
|
func (b *BasicAuth) Type() string
|
||||||
|
```
|
||||||
|
Type identifies the BasicAuthenticator
|
||||||
|
|
||||||
|
#### <a name="BasicAuth.User">func</a> (\*BasicAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=297:330#L20)
|
||||||
|
``` go
|
||||||
|
func (b *BasicAuth) User() string
|
||||||
|
```
|
||||||
|
User holds the BasicAuth username
|
||||||
|
|
||||||
|
### <a name="Client">type</a> [Client](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=165:357#L17)
|
||||||
|
``` go
|
||||||
|
type Client struct {
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Client defines our structure
|
||||||
|
|
||||||
|
#### <a name="NewClient">func</a> [NewClient](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1012:1056#L61)
|
||||||
|
``` go
|
||||||
|
func NewClient(uri, user, pw string) *Client
|
||||||
|
```
|
||||||
|
NewClient creates a new instance of client
|
||||||
|
|
||||||
|
#### <a name="Client.Connect">func</a> (\*Client) [Connect](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1836:1868#L86)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Connect() error
|
||||||
|
```
|
||||||
|
Connect connects to our dav server
|
||||||
|
|
||||||
|
#### <a name="Client.Copy">func</a> (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6695:6763#L312)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Copy(oldpath, newpath string, overwrite bool) error
|
||||||
|
```
|
||||||
|
Copy copies a file from A to B
|
||||||
|
|
||||||
|
#### <a name="Client.Mkdir">func</a> (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5786:5842#L271)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Mkdir(path string, _ os.FileMode) error
|
||||||
|
```
|
||||||
|
Mkdir makes a directory
|
||||||
|
|
||||||
|
#### <a name="Client.MkdirAll">func</a> (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6021:6080#L282)
|
||||||
|
``` go
|
||||||
|
func (c *Client) MkdirAll(path string, _ os.FileMode) error
|
||||||
|
```
|
||||||
|
MkdirAll like mkdir -p, but for webdav
|
||||||
|
|
||||||
|
#### <a name="Client.Read">func</a> (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6869:6919#L317)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Read(path string) ([]byte, error)
|
||||||
|
```
|
||||||
|
Read reads the contents of a remote file
|
||||||
|
|
||||||
|
#### <a name="Client.ReadDir">func</a> (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=2862:2922#L129)
|
||||||
|
``` go
|
||||||
|
func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
|
||||||
|
```
|
||||||
|
ReadDir reads the contents of a remote directory
|
||||||
|
|
||||||
|
#### <a name="Client.ReadStream">func</a> (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7230:7293#L335)
|
||||||
|
``` go
|
||||||
|
func (c *Client) ReadStream(path string) (io.ReadCloser, error)
|
||||||
|
```
|
||||||
|
ReadStream reads the stream for a given path
|
||||||
|
|
||||||
|
#### <a name="Client.Remove">func</a> (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5292:5334#L248)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Remove(path string) error
|
||||||
|
```
|
||||||
|
Remove removes a remote file
|
||||||
|
|
||||||
|
#### <a name="Client.RemoveAll">func</a> (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5400:5445#L253)
|
||||||
|
``` go
|
||||||
|
func (c *Client) RemoveAll(path string) error
|
||||||
|
```
|
||||||
|
RemoveAll removes remote files
|
||||||
|
|
||||||
|
#### <a name="Client.Rename">func</a> (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6529:6599#L307)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Rename(oldpath, newpath string, overwrite bool) error
|
||||||
|
```
|
||||||
|
Rename moves a file from A to B
|
||||||
|
|
||||||
|
#### <a name="Client.SetHeader">func</a> (\*Client) [SetHeader](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1228:1273#L66)
|
||||||
|
``` go
|
||||||
|
func (c *Client) SetHeader(key, value string)
|
||||||
|
```
|
||||||
|
SetHeader lets us set arbitrary headers for a given client
|
||||||
|
|
||||||
|
#### <a name="Client.SetInterceptor">func</a> (\*Client) [SetInterceptor](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1380:1462#L71)
|
||||||
|
``` go
|
||||||
|
func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))
|
||||||
|
```
|
||||||
|
SetInterceptor lets us set an arbitrary interceptor for a given client
|
||||||
|
|
||||||
|
#### <a name="Client.SetTimeout">func</a> (\*Client) [SetTimeout](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1564:1614#L76)
|
||||||
|
``` go
|
||||||
|
func (c *Client) SetTimeout(timeout time.Duration)
|
||||||
|
```
|
||||||
|
SetTimeout exposes the ability to set a time limit for requests
|
||||||
|
|
||||||
|
#### <a name="Client.SetTransport">func</a> (\*Client) [SetTransport](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1707:1765#L81)
|
||||||
|
``` go
|
||||||
|
func (c *Client) SetTransport(transport http.RoundTripper)
|
||||||
|
```
|
||||||
|
SetTransport exposes the ability to define custom transports
|
||||||
|
|
||||||
|
#### <a name="Client.Stat">func</a> (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4248:4303#L196)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Stat(path string) (os.FileInfo, error)
|
||||||
|
```
|
||||||
|
Stat returns the file stats for a specified path
|
||||||
|
|
||||||
|
#### <a name="Client.Write">func</a> (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7584:7653#L350)
|
||||||
|
``` go
|
||||||
|
func (c *Client) Write(path string, data []byte, _ os.FileMode) error
|
||||||
|
```
|
||||||
|
Write writes data to a given path
|
||||||
|
|
||||||
|
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=8009:8089#L373)
|
||||||
|
``` go
|
||||||
|
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
|
||||||
|
```
|
||||||
|
WriteStream writes a stream
|
||||||
|
|
||||||
|
### <a name="DigestAuth">type</a> [DigestAuth](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=157:254#L14)
|
||||||
|
``` go
|
||||||
|
type DigestAuth struct {
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
DigestAuth structure holds our credentials
|
||||||
|
|
||||||
|
#### <a name="DigestAuth.Authorize">func</a> (\*DigestAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=577:654#L36)
|
||||||
|
``` go
|
||||||
|
func (d *DigestAuth) Authorize(req *http.Request, method string, path string)
|
||||||
|
```
|
||||||
|
Authorize the current request
|
||||||
|
|
||||||
|
#### <a name="DigestAuth.Pass">func</a> (\*DigestAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=491:525#L31)
|
||||||
|
``` go
|
||||||
|
func (d *DigestAuth) Pass() string
|
||||||
|
```
|
||||||
|
Pass holds the DigestAuth password
|
||||||
|
|
||||||
|
#### <a name="DigestAuth.Type">func</a> (\*DigestAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=299:333#L21)
|
||||||
|
``` go
|
||||||
|
func (d *DigestAuth) Type() string
|
||||||
|
```
|
||||||
|
Type identifies the DigestAuthenticator
|
||||||
|
|
||||||
|
#### <a name="DigestAuth.User">func</a> (\*DigestAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=398:432#L26)
|
||||||
|
``` go
|
||||||
|
func (d *DigestAuth) User() string
|
||||||
|
```
|
||||||
|
User holds the DigestAuth username
|
||||||
|
|
||||||
|
### <a name="File">type</a> [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:253#L10)
|
||||||
|
``` go
|
||||||
|
type File struct {
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
File is our structure for a given file
|
||||||
|
|
||||||
|
#### <a name="File.ContentType">func</a> (File) [ContentType](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=476:510#L31)
|
||||||
|
``` go
|
||||||
|
func (f File) ContentType() string
|
||||||
|
```
|
||||||
|
ContentType returns the content type of a file
|
||||||
|
|
||||||
|
#### <a name="File.ETag">func</a> (File) [ETag](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=929:956#L56)
|
||||||
|
``` go
|
||||||
|
func (f File) ETag() string
|
||||||
|
```
|
||||||
|
ETag returns the ETag of a file
|
||||||
|
|
||||||
|
#### <a name="File.IsDir">func</a> (File) [IsDir](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1035:1061#L61)
|
||||||
|
``` go
|
||||||
|
func (f File) IsDir() bool
|
||||||
|
```
|
||||||
|
IsDir let us see if a given file is a directory or not
|
||||||
|
|
||||||
|
#### <a name="File.ModTime">func</a> (File) [ModTime](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=836:869#L51)
|
||||||
|
``` go
|
||||||
|
func (f File) ModTime() time.Time
|
||||||
|
```
|
||||||
|
ModTime returns the modified time of a file
|
||||||
|
|
||||||
|
#### <a name="File.Mode">func</a> (File) [Mode](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=665:697#L41)
|
||||||
|
``` go
|
||||||
|
func (f File) Mode() os.FileMode
|
||||||
|
```
|
||||||
|
Mode will return the mode of a given file
|
||||||
|
|
||||||
|
#### <a name="File.Name">func</a> (File) [Name](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=378:405#L26)
|
||||||
|
``` go
|
||||||
|
func (f File) Name() string
|
||||||
|
```
|
||||||
|
Name returns the name of a file
|
||||||
|
|
||||||
|
#### <a name="File.Path">func</a> (File) [Path](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=295:322#L21)
|
||||||
|
``` go
|
||||||
|
func (f File) Path() string
|
||||||
|
```
|
||||||
|
Path returns the full path of a file
|
||||||
|
|
||||||
|
#### <a name="File.Size">func</a> (File) [Size](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=573:599#L36)
|
||||||
|
``` go
|
||||||
|
func (f File) Size() int64
|
||||||
|
```
|
||||||
|
Size returns the size of a file
|
||||||
|
|
||||||
|
#### <a name="File.String">func</a> (File) [String](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1183:1212#L71)
|
||||||
|
``` go
|
||||||
|
func (f File) String() string
|
||||||
|
```
|
||||||
|
String lets us see file information
|
||||||
|
|
||||||
|
#### <a name="File.Sys">func</a> (File) [Sys](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1095:1126#L66)
|
||||||
|
``` go
|
||||||
|
func (f File) Sys() interface{}
|
||||||
|
```
|
||||||
|
Sys ????
|
||||||
|
|
||||||
|
### <a name="NoAuth">type</a> [NoAuth](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=544:592#L36)
|
||||||
|
``` go
|
||||||
|
type NoAuth struct {
|
||||||
|
// contains filtered or unexported fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
NoAuth structure holds our credentials
|
||||||
|
|
||||||
|
#### <a name="NoAuth.Authorize">func</a> (\*NoAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=887:960#L57)
|
||||||
|
``` go
|
||||||
|
func (n *NoAuth) Authorize(req *http.Request, method string, path string)
|
||||||
|
```
|
||||||
|
Authorize the current request
|
||||||
|
|
||||||
|
#### <a name="NoAuth.Pass">func</a> (\*NoAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=805:835#L52)
|
||||||
|
``` go
|
||||||
|
func (n *NoAuth) Pass() string
|
||||||
|
```
|
||||||
|
Pass returns the current password
|
||||||
|
|
||||||
|
#### <a name="NoAuth.Type">func</a> (\*NoAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=631:661#L42)
|
||||||
|
``` go
|
||||||
|
func (n *NoAuth) Type() string
|
||||||
|
```
|
||||||
|
Type identifies the authenticator
|
||||||
|
|
||||||
|
#### <a name="NoAuth.User">func</a> (\*NoAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=717:747#L47)
|
||||||
|
``` go
|
||||||
|
func (n *NoAuth) User() string
|
||||||
|
```
|
||||||
|
User returns the current user
|
||||||
|
|
||||||
|
- - -
|
||||||
|
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
|
||||||
|
|||||||
34
basicAuth.go
Normal file
34
basicAuth.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package gowebdav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BasicAuth structure holds our credentials
|
||||||
|
type BasicAuth struct {
|
||||||
|
user string
|
||||||
|
pw string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type identifies the BasicAuthenticator
|
||||||
|
func (b *BasicAuth) Type() string {
|
||||||
|
return "BasicAuth"
|
||||||
|
}
|
||||||
|
|
||||||
|
// User holds the BasicAuth username
|
||||||
|
func (b *BasicAuth) User() string {
|
||||||
|
return b.user
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass holds the BasicAuth password
|
||||||
|
func (b *BasicAuth) Pass() string {
|
||||||
|
return b.pw
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authorize the current request
|
||||||
|
func (b *BasicAuth) Authorize(req *http.Request, method string, path string) {
|
||||||
|
a := b.user + ":" + b.pw
|
||||||
|
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
|
||||||
|
req.Header.Set("Authorization", auth)
|
||||||
|
}
|
||||||
231
client.go
231
client.go
@@ -2,49 +2,104 @@ package gowebdav
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
pathpkg "path"
|
pathpkg "path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Client defines our structure
|
||||||
type Client struct {
|
type Client struct {
|
||||||
root string
|
root string
|
||||||
headers http.Header
|
headers http.Header
|
||||||
|
interceptor func(method string, rq *http.Request)
|
||||||
c *http.Client
|
c *http.Client
|
||||||
|
|
||||||
|
authMutex sync.Mutex
|
||||||
|
auth Authenticator
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(uri string, user string, pw string) *Client {
|
// Authenticator stub
|
||||||
c := &Client{uri, make(http.Header), &http.Client{}}
|
type Authenticator interface {
|
||||||
|
Type() string
|
||||||
if len(user) > 0 && len(pw) > 0 {
|
User() string
|
||||||
a := user + ":" + pw
|
Pass() string
|
||||||
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
|
Authorize(*http.Request, string, string)
|
||||||
c.headers.Add("Authorization", auth)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.root = FixSlash(c.root)
|
// NoAuth structure holds our credentials
|
||||||
|
type NoAuth struct {
|
||||||
return c
|
user string
|
||||||
|
pw string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type identifies the authenticator
|
||||||
|
func (n *NoAuth) Type() string {
|
||||||
|
return "NoAuth"
|
||||||
|
}
|
||||||
|
|
||||||
|
// User returns the current user
|
||||||
|
func (n *NoAuth) User() string {
|
||||||
|
return n.user
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass returns the current password
|
||||||
|
func (n *NoAuth) Pass() string {
|
||||||
|
return n.pw
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authorize the current request
|
||||||
|
func (n *NoAuth) Authorize(req *http.Request, method string, path string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new instance of client
|
||||||
|
func NewClient(uri, user, pw string) *Client {
|
||||||
|
return &Client{FixSlash(uri), make(http.Header), nil, &http.Client{}, sync.Mutex{}, &NoAuth{user, pw}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHeader lets us set arbitrary headers for a given client
|
||||||
|
func (c *Client) SetHeader(key, value string) {
|
||||||
|
c.headers.Add(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInterceptor lets us set an arbitrary interceptor for a given client
|
||||||
|
func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request)) {
|
||||||
|
c.interceptor = interceptor
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimeout exposes the ability to set a time limit for requests
|
||||||
|
func (c *Client) SetTimeout(timeout time.Duration) {
|
||||||
|
c.c.Timeout = timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTransport exposes the ability to define custom transports
|
||||||
|
func (c *Client) SetTransport(transport http.RoundTripper) {
|
||||||
|
c.c.Transport = transport
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect connects to our dav server
|
||||||
func (c *Client) Connect() error {
|
func (c *Client) Connect() error {
|
||||||
rs, err := c.options("/")
|
rs, err := c.options("/")
|
||||||
if err == nil {
|
if err != nil {
|
||||||
rs.Body.Close()
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if rs.StatusCode != 200 || (rs.Header.Get("Dav") == "" && rs.Header.Get("DAV") == "") {
|
err = rs.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.StatusCode != 200 {
|
||||||
return newPathError("Connect", c.root, rs.StatusCode)
|
return newPathError("Connect", c.root, rs.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.ReadDir("/")
|
return nil
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type props struct {
|
type props struct {
|
||||||
@@ -52,8 +107,11 @@ type props struct {
|
|||||||
Name string `xml:"DAV: prop>displayname,omitempty"`
|
Name string `xml:"DAV: prop>displayname,omitempty"`
|
||||||
Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"`
|
Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"`
|
||||||
Size string `xml:"DAV: prop>getcontentlength,omitempty"`
|
Size string `xml:"DAV: prop>getcontentlength,omitempty"`
|
||||||
|
ContentType string `xml:"DAV: prop>getcontenttype,omitempty"`
|
||||||
|
ETag string `xml:"DAV: prop>getetag,omitempty"`
|
||||||
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
|
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
Href string `xml:"DAV: href"`
|
Href string `xml:"DAV: href"`
|
||||||
Props []props `xml:"DAV: propstat"`
|
Props []props `xml:"DAV: propstat"`
|
||||||
@@ -61,13 +119,14 @@ type response struct {
|
|||||||
|
|
||||||
func getProps(r *response, status string) *props {
|
func getProps(r *response, status string) *props {
|
||||||
for _, prop := range r.Props {
|
for _, prop := range r.Props {
|
||||||
if strings.Index(prop.Status, status) != -1 {
|
if strings.Contains(prop.Status, status) {
|
||||||
return &prop
|
return &prop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadDir reads the contents of a remote directory
|
||||||
func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
||||||
path = FixSlashes(path)
|
path = FixSlashes(path)
|
||||||
files := make([]os.FileInfo, 0)
|
files := make([]os.FileInfo, 0)
|
||||||
@@ -86,13 +145,15 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
|
|
||||||
if p := getProps(r, "200"); p != nil {
|
if p := getProps(r, "200"); p != nil {
|
||||||
f := new(File)
|
f := new(File)
|
||||||
if ps, err := url.QueryUnescape(r.Href); err == nil {
|
if ps, err := url.PathUnescape(r.Href); err == nil {
|
||||||
f.name = pathpkg.Base(ps)
|
f.name = pathpkg.Base(ps)
|
||||||
} else {
|
} else {
|
||||||
f.name = p.Name
|
f.name = p.Name
|
||||||
}
|
}
|
||||||
f.path = path + f.name
|
f.path = path + f.name
|
||||||
f.modified = parseModified(&p.Modified)
|
f.modified = parseModified(&p.Modified)
|
||||||
|
f.etag = p.ETag
|
||||||
|
f.contentType = p.ContentType
|
||||||
|
|
||||||
if p.Type.Local == "collection" {
|
if p.Type.Local == "collection" {
|
||||||
f.path += "/"
|
f.path += "/"
|
||||||
@@ -116,6 +177,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
<d:displayname/>
|
<d:displayname/>
|
||||||
<d:resourcetype/>
|
<d:resourcetype/>
|
||||||
<d:getcontentlength/>
|
<d:getcontentlength/>
|
||||||
|
<d:getcontenttype/>
|
||||||
|
<d:getetag/>
|
||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
@@ -124,20 +187,23 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*os.PathError); !ok {
|
if _, ok := err.(*os.PathError); !ok {
|
||||||
err = &os.PathError{"ReadDir", path, err}
|
err = newPathErrorErr("ReadDir", path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return files, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stat returns the file stats for a specified path
|
||||||
func (c *Client) Stat(path string) (os.FileInfo, error) {
|
func (c *Client) Stat(path string) (os.FileInfo, error) {
|
||||||
var f *File = nil
|
var f *File
|
||||||
parse := func(resp interface{}) error {
|
parse := func(resp interface{}) error {
|
||||||
r := resp.(*response)
|
r := resp.(*response)
|
||||||
if p := getProps(r, "200"); p != nil && f == nil {
|
if p := getProps(r, "200"); p != nil && f == nil {
|
||||||
f = new(File)
|
f = new(File)
|
||||||
f.name = p.Name
|
f.name = p.Name
|
||||||
f.path = path
|
f.path = path
|
||||||
|
f.etag = p.ETag
|
||||||
|
f.contentType = p.ContentType
|
||||||
|
|
||||||
if p.Type.Local == "collection" {
|
if p.Type.Local == "collection" {
|
||||||
if !strings.HasSuffix(f.path, "/") {
|
if !strings.HasSuffix(f.path, "/") {
|
||||||
@@ -163,6 +229,8 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
|
|||||||
<d:displayname/>
|
<d:displayname/>
|
||||||
<d:resourcetype/>
|
<d:resourcetype/>
|
||||||
<d:getcontentlength/>
|
<d:getcontentlength/>
|
||||||
|
<d:getcontenttype/>
|
||||||
|
<d:getetag/>
|
||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
@@ -171,40 +239,47 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*os.PathError); !ok {
|
if _, ok := err.(*os.PathError); !ok {
|
||||||
err = &os.PathError{"ReadDir", path, err}
|
err = newPathErrorErr("ReadDir", path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return f, err
|
return f, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove removes a remote file
|
||||||
func (c *Client) Remove(path string) error {
|
func (c *Client) Remove(path string) error {
|
||||||
return c.RemoveAll(path)
|
return c.RemoveAll(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveAll removes remote files
|
||||||
func (c *Client) RemoveAll(path string) error {
|
func (c *Client) RemoveAll(path string) error {
|
||||||
rs, err := c.req("DELETE", path, nil, nil)
|
rs, err := c.req("DELETE", path, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newPathError("Remove", path, 400)
|
return newPathError("Remove", path, 400)
|
||||||
}
|
}
|
||||||
rs.Body.Close()
|
err = rs.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if rs.StatusCode == 200 || rs.StatusCode == 404 {
|
if rs.StatusCode == 200 || rs.StatusCode == 204 || rs.StatusCode == 404 {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return newPathError("Remove", path, rs.StatusCode)
|
return newPathError("Remove", path, rs.StatusCode)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Mkdir makes a directory
|
||||||
func (c *Client) Mkdir(path string, _ os.FileMode) error {
|
func (c *Client) Mkdir(path string, _ os.FileMode) error {
|
||||||
path = FixSlashes(path)
|
path = FixSlashes(path)
|
||||||
status := c.mkcol(path)
|
status := c.mkcol(path)
|
||||||
if status == 201 {
|
if status == 201 {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return newPathError("Mkdir", path, status)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newPathError("Mkdir", path, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MkdirAll like mkdir -p, but for webdav
|
||||||
func (c *Client) MkdirAll(path string, _ os.FileMode) error {
|
func (c *Client) MkdirAll(path string, _ os.FileMode) error {
|
||||||
path = FixSlashes(path)
|
path = FixSlashes(path)
|
||||||
status := c.mkcol(path)
|
status := c.mkcol(path)
|
||||||
@@ -229,61 +304,121 @@ func (c *Client) MkdirAll(path string, _ os.FileMode) error {
|
|||||||
return newPathError("MkdirAll", path, status)
|
return newPathError("MkdirAll", path, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error {
|
// Rename moves a file from A to B
|
||||||
|
func (c *Client) Rename(oldpath, newpath string, overwrite bool) error {
|
||||||
return c.copymove("MOVE", oldpath, newpath, overwrite)
|
return c.copymove("MOVE", oldpath, newpath, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error {
|
// Copy copies a file from A to B
|
||||||
|
func (c *Client) Copy(oldpath, newpath string, overwrite bool) error {
|
||||||
return c.copymove("COPY", oldpath, newpath, overwrite)
|
return c.copymove("COPY", oldpath, newpath, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read reads the contents of a remote file
|
||||||
func (c *Client) Read(path string) ([]byte, error) {
|
func (c *Client) Read(path string) ([]byte, error) {
|
||||||
if stream, err := c.ReadStream(path); err == nil {
|
var stream io.ReadCloser
|
||||||
defer stream.Close()
|
var err error
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
buf.ReadFrom(stream)
|
if stream, err = c.ReadStream(path); err != nil {
|
||||||
return buf.Bytes(), nil
|
|
||||||
} else {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer stream.Close()
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
_, err = buf.ReadFrom(stream)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadStream reads the stream for a given path
|
||||||
func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
|
func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
|
||||||
rs, err := c.req("GET", path, nil, nil)
|
rs, err := c.req("GET", path, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newPathErrorErr("ReadStream", path, err)
|
return nil, newPathErrorErr("ReadStream", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rs.StatusCode == 200 {
|
||||||
return rs.Body, nil
|
return rs.Body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rs.Body.Close()
|
||||||
|
return nil, newPathError("ReadStream", path, rs.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadStreamRange reads the stream representing a subset of bytes for a given path,
|
||||||
|
// utilizing HTTP Range Requests if the server supports it.
|
||||||
|
// The range is expressed as offset from the start of the file and length, for example
|
||||||
|
// offset=10, length=10 will return bytes 10 through 19.
|
||||||
|
//
|
||||||
|
// If the server does not support partial content requests and returns full content instead,
|
||||||
|
// this function will emulate the behavior by skipping `offset` bytes and limiting the result
|
||||||
|
// to `length`.
|
||||||
|
func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) {
|
||||||
|
rs, err := c.req("GET", path, nil, func(r *http.Request) {
|
||||||
|
r.Header.Add("Range", fmt.Sprintf("bytes=%v-%v", offset, offset+length-1))
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, newPathErrorErr("ReadStreamRange", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.StatusCode == http.StatusPartialContent {
|
||||||
|
// server supported partial content, return as-is.
|
||||||
|
return rs.Body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// server returned success, but did not support partial content, so we have the whole
|
||||||
|
// stream in rs.Body
|
||||||
|
if rs.StatusCode == 200 {
|
||||||
|
// discard first 'offset' bytes.
|
||||||
|
if _, err := io.Copy(io.Discard, io.LimitReader(rs.Body, offset)); err != nil {
|
||||||
|
return nil, newPathErrorErr("ReadStreamRange", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a io.ReadCloser that is limited to `length` bytes.
|
||||||
|
return &limitedReadCloser{rs.Body, int(length)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.Body.Close()
|
||||||
|
return nil, newPathError("ReadStream", path, rs.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write writes data to a given path
|
||||||
func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
||||||
s := c.put(path, bytes.NewReader(data))
|
s := c.put(path, bytes.NewReader(data))
|
||||||
switch s {
|
switch s {
|
||||||
|
|
||||||
case 200, 201:
|
case 200, 201, 204:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case 409:
|
case 409:
|
||||||
if idx := strings.LastIndex(path, "/"); idx == -1 {
|
err := c.createParentCollection(path)
|
||||||
// faulty root
|
if err != nil {
|
||||||
return newPathError("Write", path, 500)
|
return err
|
||||||
} else {
|
}
|
||||||
if err := c.MkdirAll(path[0:idx+1], 0755); err == nil {
|
|
||||||
s = c.put(path, bytes.NewReader(data))
|
s = c.put(path, bytes.NewReader(data))
|
||||||
if s == 200 || s == 201 {
|
if s == 200 || s == 201 || s == 204 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return newPathError("Write", path, s)
|
return newPathError("Write", path, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteStream writes a stream
|
||||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error {
|
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error {
|
||||||
// TODO check if parent collection exists
|
|
||||||
|
err := c.createParentCollection(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
s := c.put(path, stream)
|
s := c.put(path, stream)
|
||||||
|
|
||||||
switch s {
|
switch s {
|
||||||
case 200, 201:
|
case 200, 201, 204:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
103
cmd/gowebdav/README.md
Normal file
103
cmd/gowebdav/README.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
# Description
|
||||||
|
Command line tool for [gowebdav](https://github.com/studio-b12/gowebdav) library.
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
## Software
|
||||||
|
* **OS**: all, which are supported by `Golang`
|
||||||
|
* **Golang**: version 1.x
|
||||||
|
* **Git**: version 2.14.2 at higher (required to install via `go get`)
|
||||||
|
|
||||||
|
# Install
|
||||||
|
```sh
|
||||||
|
go get -u github.com/studio-b12/gowebdav/cmd/gowebdav
|
||||||
|
```
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
It is recommended to set following environment variables to improve your experience with this tool:
|
||||||
|
* `ROOT` is an URL of target WebDAV server (e.g. `https://webdav.mydomain.me/user_root_folder`)
|
||||||
|
* `USER` is a login to connect to specified server (e.g. `user`)
|
||||||
|
* `PASSWORD` is a password to connect to specified server (e.g. `p@s$w0rD`)
|
||||||
|
|
||||||
|
In following examples we suppose that:
|
||||||
|
* environment variable `ROOT` is set to `https://webdav.mydomain.me/ufolder`
|
||||||
|
* environment variable `USER` is set to `user`
|
||||||
|
* environment variable `PASSWORD` is set `p@s$w0rD`
|
||||||
|
* folder `/ufolder/temp` exists on the server
|
||||||
|
* file `/ufolder/temp/file.txt` exists on the server
|
||||||
|
* file `/ufolder/temp/document.rtf` exists on the server
|
||||||
|
* file `/tmp/webdav/to_upload.txt` exists on the local machine
|
||||||
|
* folder `/tmp/webdav/` is used to download files from the server
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
#### Get content of specified folder
|
||||||
|
```sh
|
||||||
|
gowebdav -X LS temp
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get info about file/folder
|
||||||
|
```sh
|
||||||
|
gowebdav -X STAT temp
|
||||||
|
gowebdav -X STAT temp/file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create folder on the remote server
|
||||||
|
```sh
|
||||||
|
gowebdav -X MKDIR temp2
|
||||||
|
gowebdav -X MKDIRALL all/folders/which-you-want/to_create
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Download file
|
||||||
|
```sh
|
||||||
|
gowebdav -X GET temp/document.rtf /tmp/webdav/document.rtf
|
||||||
|
```
|
||||||
|
|
||||||
|
You may do not specify target local path, in this case file will be downloaded to the current folder with the
|
||||||
|
|
||||||
|
#### Upload file
|
||||||
|
```sh
|
||||||
|
gowebdav -X PUT temp/uploaded.txt /tmp/webdav/to_upload.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Move file on the remote server
|
||||||
|
```sh
|
||||||
|
gowebdav -X MV temp/file.txt temp/moved_file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Copy file to another location
|
||||||
|
```sh
|
||||||
|
gowebdav -X MV temp/file.txt temp/file-copy.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete file from the remote server
|
||||||
|
```sh
|
||||||
|
gowebdav -X DEL temp/file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
# Wrapper script
|
||||||
|
|
||||||
|
You can create wrapper script for your server (via `$EDITOR ./dav && chmod a+x ./dav`) and add following content to it:
|
||||||
|
```sh
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
ROOT="https://my.dav.server/" \
|
||||||
|
USER="foo" \
|
||||||
|
PASSWORD="$(pass dav/foo@my.dav.server)" \
|
||||||
|
gowebdav $@
|
||||||
|
```
|
||||||
|
|
||||||
|
It allows you to use [pass](https://www.passwordstore.org/ "the standard unix password manager") or similar tools to retrieve the password.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Using the `dav` wrapper:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ ./dav -X LS /
|
||||||
|
|
||||||
|
$ echo hi dav! > hello && ./dav -X PUT /hello
|
||||||
|
$ ./dav -X STAT /hello
|
||||||
|
$ ./dav -X PUT /hello_dav hello
|
||||||
|
$ ./dav -X GET /hello_dav
|
||||||
|
$ ./dav -X GET /hello_dav hello.txt
|
||||||
|
```
|
||||||
250
cmd/gowebdav/main.go
Normal file
250
cmd/gowebdav/main.go
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
d "github.com/studio-b12/gowebdav"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
root := flag.String("root", os.Getenv("ROOT"), "WebDAV Endpoint [ENV.ROOT]")
|
||||||
|
user := flag.String("user", os.Getenv("USER"), "User [ENV.USER]")
|
||||||
|
password := flag.String("pw", os.Getenv("PASSWORD"), "Password [ENV.PASSWORD]")
|
||||||
|
netrc := flag.String("netrc-file", filepath.Join(getHome(), ".netrc"), "read login from netrc file")
|
||||||
|
method := flag.String("X", "", `Method:
|
||||||
|
LS <PATH>
|
||||||
|
STAT <PATH>
|
||||||
|
|
||||||
|
MKDIR <PATH>
|
||||||
|
MKDIRALL <PATH>
|
||||||
|
|
||||||
|
GET <PATH> [<FILE>]
|
||||||
|
PUT <PATH> [<FILE>]
|
||||||
|
|
||||||
|
MV <OLD> <NEW>
|
||||||
|
CP <OLD> <NEW>
|
||||||
|
|
||||||
|
DEL <PATH>
|
||||||
|
`)
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *root == "" {
|
||||||
|
fail("Set WebDAV ROOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
if argsLength := len(flag.Args()); argsLength == 0 || argsLength > 2 {
|
||||||
|
fail("Unsupported arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *password == "" {
|
||||||
|
if u, p := d.ReadConfig(*root, *netrc); u != "" && p != "" {
|
||||||
|
user = &u
|
||||||
|
password = &p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := d.NewClient(*root, *user, *password)
|
||||||
|
|
||||||
|
cmd := getCmd(*method)
|
||||||
|
|
||||||
|
if e := cmd(c, flag.Arg(0), flag.Arg(1)); e != nil {
|
||||||
|
fail(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fail(err interface{}) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHome() string {
|
||||||
|
u, e := user.Current()
|
||||||
|
if e != nil {
|
||||||
|
return os.Getenv("HOME")
|
||||||
|
}
|
||||||
|
|
||||||
|
if u != nil {
|
||||||
|
return u.HomeDir
|
||||||
|
}
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
return ""
|
||||||
|
default:
|
||||||
|
return "~/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCmd(method string) func(c *d.Client, p0, p1 string) error {
|
||||||
|
switch strings.ToUpper(method) {
|
||||||
|
case "LS", "LIST", "PROPFIND":
|
||||||
|
return cmdLs
|
||||||
|
|
||||||
|
case "STAT":
|
||||||
|
return cmdStat
|
||||||
|
|
||||||
|
case "GET", "PULL", "READ":
|
||||||
|
return cmdGet
|
||||||
|
|
||||||
|
case "DELETE", "RM", "DEL":
|
||||||
|
return cmdRm
|
||||||
|
|
||||||
|
case "MKCOL", "MKDIR":
|
||||||
|
return cmdMkdir
|
||||||
|
|
||||||
|
case "MKCOLALL", "MKDIRALL", "MKDIRP":
|
||||||
|
return cmdMkdirAll
|
||||||
|
|
||||||
|
case "RENAME", "MV", "MOVE":
|
||||||
|
return cmdMv
|
||||||
|
|
||||||
|
case "COPY", "CP":
|
||||||
|
return cmdCp
|
||||||
|
|
||||||
|
case "PUT", "PUSH", "WRITE":
|
||||||
|
return cmdPut
|
||||||
|
|
||||||
|
default:
|
||||||
|
return func(c *d.Client, p0, p1 string) (err error) {
|
||||||
|
return errors.New("Unsupported method: " + method)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdLs(c *d.Client, p0, _ string) (err error) {
|
||||||
|
files, err := c.ReadDir(p0)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println(fmt.Sprintf("ReadDir: '%s' entries: %d ", p0, len(files)))
|
||||||
|
for _, f := range files {
|
||||||
|
fmt.Println(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdStat(c *d.Client, p0, _ string) (err error) {
|
||||||
|
file, err := c.Stat(p0)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println(file)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdGet(c *d.Client, p0, p1 string) (err error) {
|
||||||
|
bytes, err := c.Read(p0)
|
||||||
|
if err == nil {
|
||||||
|
if p1 == "" {
|
||||||
|
p1 = filepath.Join(".", p0)
|
||||||
|
}
|
||||||
|
err = writeFile(p1, bytes, 0644)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println(fmt.Sprintf("Written %d bytes to: %s", len(bytes), p1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdRm(c *d.Client, p0, _ string) (err error) {
|
||||||
|
if err = c.Remove(p0); err == nil {
|
||||||
|
fmt.Println("Remove: " + p0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdMkdir(c *d.Client, p0, _ string) (err error) {
|
||||||
|
if err = c.Mkdir(p0, 0755); err == nil {
|
||||||
|
fmt.Println("Mkdir: " + p0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdMkdirAll(c *d.Client, p0, _ string) (err error) {
|
||||||
|
if err = c.MkdirAll(p0, 0755); err == nil {
|
||||||
|
fmt.Println("MkdirAll: " + p0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdMv(c *d.Client, p0, p1 string) (err error) {
|
||||||
|
if err = c.Rename(p0, p1, true); err == nil {
|
||||||
|
fmt.Println("Rename: " + p0 + " -> " + p1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdCp(c *d.Client, p0, p1 string) (err error) {
|
||||||
|
if err = c.Copy(p0, p1, true); err == nil {
|
||||||
|
fmt.Println("Copy: " + p0 + " -> " + p1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdPut(c *d.Client, p0, p1 string) (err error) {
|
||||||
|
if p1 == "" {
|
||||||
|
p1 = filepath.Join(".", p0)
|
||||||
|
}
|
||||||
|
stream, err := getStream(p1)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer stream.Close()
|
||||||
|
|
||||||
|
if err = c.WriteStream(p0, stream, 0644); err == nil {
|
||||||
|
fmt.Println("Put: " + p1 + " -> " + p0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeFile(path string, bytes []byte, mode os.FileMode) error {
|
||||||
|
parent := filepath.Dir(path)
|
||||||
|
if _, e := os.Stat(parent); os.IsNotExist(e) {
|
||||||
|
if e := os.MkdirAll(parent, os.ModePerm); e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
_, err = f.Write(bytes)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStream(pathOrString string) (io.ReadCloser, error) {
|
||||||
|
|
||||||
|
fi, err := os.Stat(pathOrString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.IsDir() {
|
||||||
|
return nil, &os.PathError{
|
||||||
|
Op: "Open",
|
||||||
|
Path: pathOrString,
|
||||||
|
Err: errors.New("Path: '" + pathOrString + "' is a directory"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(pathOrString)
|
||||||
|
if err == nil {
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, &os.PathError{
|
||||||
|
Op: "Open",
|
||||||
|
Path: pathOrString,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
146
digestAuth.go
Normal file
146
digestAuth.go
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package gowebdav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DigestAuth structure holds our credentials
|
||||||
|
type DigestAuth struct {
|
||||||
|
user string
|
||||||
|
pw string
|
||||||
|
digestParts map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type identifies the DigestAuthenticator
|
||||||
|
func (d *DigestAuth) Type() string {
|
||||||
|
return "DigestAuth"
|
||||||
|
}
|
||||||
|
|
||||||
|
// User holds the DigestAuth username
|
||||||
|
func (d *DigestAuth) User() string {
|
||||||
|
return d.user
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass holds the DigestAuth password
|
||||||
|
func (d *DigestAuth) Pass() string {
|
||||||
|
return d.pw
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authorize the current request
|
||||||
|
func (d *DigestAuth) Authorize(req *http.Request, method string, path string) {
|
||||||
|
d.digestParts["uri"] = path
|
||||||
|
d.digestParts["method"] = method
|
||||||
|
d.digestParts["username"] = d.user
|
||||||
|
d.digestParts["password"] = d.pw
|
||||||
|
req.Header.Set("Authorization", getDigestAuthorization(d.digestParts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func digestParts(resp *http.Response) map[string]string {
|
||||||
|
result := map[string]string{}
|
||||||
|
if len(resp.Header["Www-Authenticate"]) > 0 {
|
||||||
|
wantedHeaders := []string{"nonce", "realm", "qop", "opaque", "algorithm", "entityBody"}
|
||||||
|
responseHeaders := strings.Split(resp.Header["Www-Authenticate"][0], ",")
|
||||||
|
for _, r := range responseHeaders {
|
||||||
|
for _, w := range wantedHeaders {
|
||||||
|
if strings.Contains(r, w) {
|
||||||
|
result[w] = strings.Trim(
|
||||||
|
strings.SplitN(r, `=`, 2)[1],
|
||||||
|
`"`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMD5(text string) string {
|
||||||
|
hasher := md5.New()
|
||||||
|
hasher.Write([]byte(text))
|
||||||
|
return hex.EncodeToString(hasher.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCnonce() string {
|
||||||
|
b := make([]byte, 8)
|
||||||
|
io.ReadFull(rand.Reader, b)
|
||||||
|
return fmt.Sprintf("%x", b)[:16]
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDigestAuthorization(digestParts map[string]string) string {
|
||||||
|
d := digestParts
|
||||||
|
// These are the correct ha1 and ha2 for qop=auth. We should probably check for other types of qop.
|
||||||
|
|
||||||
|
var (
|
||||||
|
ha1 string
|
||||||
|
ha2 string
|
||||||
|
nonceCount = 00000001
|
||||||
|
cnonce = getCnonce()
|
||||||
|
response string
|
||||||
|
)
|
||||||
|
|
||||||
|
// 'ha1' value depends on value of "algorithm" field
|
||||||
|
switch d["algorithm"] {
|
||||||
|
case "MD5", "":
|
||||||
|
ha1 = getMD5(d["username"] + ":" + d["realm"] + ":" + d["password"])
|
||||||
|
case "MD5-sess":
|
||||||
|
ha1 = getMD5(
|
||||||
|
fmt.Sprintf("%s:%v:%s",
|
||||||
|
getMD5(d["username"]+":"+d["realm"]+":"+d["password"]),
|
||||||
|
nonceCount,
|
||||||
|
cnonce,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'ha2' value depends on value of "qop" field
|
||||||
|
switch d["qop"] {
|
||||||
|
case "auth", "":
|
||||||
|
ha2 = getMD5(d["method"] + ":" + d["uri"])
|
||||||
|
case "auth-int":
|
||||||
|
if d["entityBody"] != "" {
|
||||||
|
ha2 = getMD5(d["method"] + ":" + d["uri"] + ":" + getMD5(d["entityBody"]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'response' value depends on value of "qop" field
|
||||||
|
switch d["qop"] {
|
||||||
|
case "":
|
||||||
|
response = getMD5(
|
||||||
|
fmt.Sprintf("%s:%s:%s",
|
||||||
|
ha1,
|
||||||
|
d["nonce"],
|
||||||
|
ha2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
case "auth", "auth-int":
|
||||||
|
response = getMD5(
|
||||||
|
fmt.Sprintf("%s:%s:%v:%s:%s:%s",
|
||||||
|
ha1,
|
||||||
|
d["nonce"],
|
||||||
|
nonceCount,
|
||||||
|
cnonce,
|
||||||
|
d["qop"],
|
||||||
|
ha2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
authorization := fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", nc=%v, cnonce="%s", response="%s"`,
|
||||||
|
d["username"], d["realm"], d["nonce"], d["uri"], nonceCount, cnonce, response)
|
||||||
|
|
||||||
|
if d["qop"] != "" {
|
||||||
|
authorization += fmt.Sprintf(`, qop=%s`, d["qop"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if d["opaque"] != "" {
|
||||||
|
authorization += fmt.Sprintf(`, opaque="%s"`, d["opaque"])
|
||||||
|
}
|
||||||
|
|
||||||
|
return authorization
|
||||||
|
}
|
||||||
3
doc.go
Normal file
3
doc.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Package gowebdav is a WebDAV client library with a command line tool
|
||||||
|
// included.
|
||||||
|
package gowebdav
|
||||||
35
file.go
35
file.go
@@ -6,47 +6,72 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// File is our structure for a given file
|
||||||
type File struct {
|
type File struct {
|
||||||
path string
|
path string
|
||||||
name string
|
name string
|
||||||
|
contentType string
|
||||||
size int64
|
size int64
|
||||||
modified time.Time
|
modified time.Time
|
||||||
|
etag string
|
||||||
isdir bool
|
isdir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Path returns the full path of a file
|
||||||
|
func (f File) Path() string {
|
||||||
|
return f.path
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name returns the name of a file
|
||||||
func (f File) Name() string {
|
func (f File) Name() string {
|
||||||
return f.name
|
return f.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentType returns the content type of a file
|
||||||
|
func (f File) ContentType() string {
|
||||||
|
return f.contentType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the size of a file
|
||||||
func (f File) Size() int64 {
|
func (f File) Size() int64 {
|
||||||
return f.size
|
return f.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mode will return the mode of a given file
|
||||||
func (f File) Mode() os.FileMode {
|
func (f File) Mode() os.FileMode {
|
||||||
// TODO check webdav perms
|
// TODO check webdav perms
|
||||||
if f.isdir {
|
if f.isdir {
|
||||||
return 0775 | os.ModeDir
|
return 0775 | os.ModeDir
|
||||||
} else {
|
|
||||||
return 0664
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0664
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModTime returns the modified time of a file
|
||||||
func (f File) ModTime() time.Time {
|
func (f File) ModTime() time.Time {
|
||||||
return f.modified
|
return f.modified
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ETag returns the ETag of a file
|
||||||
|
func (f File) ETag() string {
|
||||||
|
return f.etag
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDir let us see if a given file is a directory or not
|
||||||
func (f File) IsDir() bool {
|
func (f File) IsDir() bool {
|
||||||
return f.isdir
|
return f.isdir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sys ????
|
||||||
func (f File) Sys() interface{} {
|
func (f File) Sys() interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String lets us see file information
|
||||||
func (f File) String() string {
|
func (f File) String() string {
|
||||||
if f.isdir {
|
if f.isdir {
|
||||||
return fmt.Sprintf("Dir : '%s' - '%s'", f.path, f.name)
|
return fmt.Sprintf("Dir : '%s' - '%s'", f.path, f.name)
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s", f.path, f.size, f.modified.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s ETAG: %s CTYPE: %s", f.path, f.size, f.modified.String(), f.etag, f.contentType)
|
||||||
}
|
}
|
||||||
|
|||||||
181
main/client.go
181
main/client.go
@@ -1,181 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
d "gowebdav"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Fail(err interface{}) {
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Usage: client FLAGS ARGS")
|
|
||||||
fmt.Println("Flags:")
|
|
||||||
flag.PrintDefaults()
|
|
||||||
fmt.Println("Method <ARGS>")
|
|
||||||
fmt.Println(" LS | LIST | PROPFIND <PATH>")
|
|
||||||
fmt.Println(" RM | DELETE | DEL <PATH>")
|
|
||||||
fmt.Println(" MKDIR | MKCOL <PATH>")
|
|
||||||
fmt.Println(" MKDIRALL | MKCOLALL <PATH>")
|
|
||||||
fmt.Println(" MV | MOVE | RENAME <OLD_PATH> <NEW_PATH>")
|
|
||||||
fmt.Println(" CP | COPY <OLD_PATH> <NEW_PATH>")
|
|
||||||
fmt.Println(" GET | PULL | READ <PATH>")
|
|
||||||
fmt.Println(" PUT | PUSH | WRITE <PATH> <FILE>")
|
|
||||||
fmt.Println(" STAT <PATH>")
|
|
||||||
}
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeFile(path string, bytes []byte, mode os.FileMode) error {
|
|
||||||
f, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
_, err = f.Write(bytes)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
root := flag.String("root", "URL", "WebDAV Endpoint")
|
|
||||||
usr := flag.String("user", "", "user")
|
|
||||||
pw := flag.String("pw", "", "password")
|
|
||||||
m := flag.String("X", "GET", "Method ...")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *root == "URL" {
|
|
||||||
Fail(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
M := strings.ToUpper(*m)
|
|
||||||
m = &M
|
|
||||||
|
|
||||||
c := d.NewClient(*root, *usr, *pw)
|
|
||||||
if err := c.Connect(); err != nil {
|
|
||||||
Fail(fmt.Sprintf("Failed to connect due to: %s", err.Error()))
|
|
||||||
}
|
|
||||||
alen := len(flag.Args())
|
|
||||||
if alen == 1 {
|
|
||||||
path := flag.Args()[0]
|
|
||||||
switch *m {
|
|
||||||
case "LS", "LIST", "PROPFIND":
|
|
||||||
if files, err := c.ReadDir(path); err == nil {
|
|
||||||
fmt.Println(fmt.Sprintf("ReadDir: '%s' entries: %d ", path, len(files)))
|
|
||||||
for _, f := range files {
|
|
||||||
fmt.Println(f)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "STAT":
|
|
||||||
if file, err := c.Stat(path); err == nil {
|
|
||||||
fmt.Println(file)
|
|
||||||
} else {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "GET", "PULL", "READ":
|
|
||||||
if bytes, err := c.Read(path); err == nil {
|
|
||||||
if lidx := strings.LastIndex(path, "/"); lidx != -1 {
|
|
||||||
path = path[lidx+1:]
|
|
||||||
}
|
|
||||||
if err := writeFile(path, bytes, 0644); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println(fmt.Sprintf("Written %d bytes to: %s", len(bytes), path))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "DELETE", "RM", "DEL":
|
|
||||||
if err := c.Remove(path); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Remove: " + path)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "MKCOL", "MKDIR":
|
|
||||||
if err := c.Mkdir(path, 0); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("MkDir: " + path)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "MKCOLALL", "MKDIRALL":
|
|
||||||
if err := c.MkdirAll(path, 0); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("MkDirAll: " + path)
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
Fail(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if alen == 2 {
|
|
||||||
a0 := flag.Args()[0]
|
|
||||||
a1 := flag.Args()[1]
|
|
||||||
switch *m {
|
|
||||||
case "RENAME", "MV", "MOVE":
|
|
||||||
if err := c.Rename(a0, a1, true); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Rename: " + a0 + " -> " + a1)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "COPY", "CP":
|
|
||||||
if err := c.Copy(a0, a1, true); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Copy: " + a0 + " -> " + a1)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "PUT", "PUSH", "WRITE":
|
|
||||||
stream, err := getStream(a1)
|
|
||||||
if err != nil {
|
|
||||||
Fail(err)
|
|
||||||
}
|
|
||||||
if err := c.WriteStream(a0, stream, 0644); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println(fmt.Sprintf("Written: '%s' -> %s", a1, a0))
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
Fail(nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Fail(nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStream(pathOrString string) (io.ReadCloser, error) {
|
|
||||||
fi, err := os.Stat(pathOrString)
|
|
||||||
if err == nil {
|
|
||||||
if fi.IsDir() {
|
|
||||||
return nil, &os.PathError{"Open", pathOrString, errors.New("Path: '" + pathOrString + "' is a directory")}
|
|
||||||
}
|
|
||||||
f, err := os.Open(pathOrString)
|
|
||||||
if err == nil {
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
return nil, &os.PathError{"Open", pathOrString, err}
|
|
||||||
} else {
|
|
||||||
return nopCloser{strings.NewReader(pathOrString)}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type nopCloser struct {
|
|
||||||
io.Reader
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nopCloser) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
54
netrc.go
Normal file
54
netrc.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package gowebdav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseLine(s string) (login, pass string) {
|
||||||
|
fields := strings.Fields(s)
|
||||||
|
for i, f := range fields {
|
||||||
|
if f == "login" {
|
||||||
|
login = fields[i+1]
|
||||||
|
}
|
||||||
|
if f == "password" {
|
||||||
|
pass = fields[i+1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return login, pass
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadConfig reads login and password configuration from ~/.netrc
|
||||||
|
// machine foo.com login username password 123456
|
||||||
|
func ReadConfig(uri, netrc string) (string, string) {
|
||||||
|
u, err := url.Parse(uri)
|
||||||
|
if err != nil {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(netrc)
|
||||||
|
if err != nil {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
re := fmt.Sprintf(`^.*machine %s.*$`, u.Host)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
s := scanner.Text()
|
||||||
|
|
||||||
|
matched, err := regexp.MatchString(re, s)
|
||||||
|
if err != nil {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
if matched {
|
||||||
|
return parseLine(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
107
requests.go
107
requests.go
@@ -1,29 +1,103 @@
|
|||||||
package gowebdav
|
package gowebdav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) req(method string, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
|
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
|
||||||
r, err := http.NewRequest(method, Join(c.root, path), body)
|
var r *http.Request
|
||||||
|
var retryBuf io.Reader
|
||||||
|
|
||||||
|
if body != nil {
|
||||||
|
// Because Request#Do closes closable streams, Seeker#Seek
|
||||||
|
// will fail on retry because stream is already closed.
|
||||||
|
// This inhibits the closing of the passed stream on passing
|
||||||
|
// it to the RoundTripper and closes the stream after we
|
||||||
|
// are done with the body content.
|
||||||
|
if cl, ok := body.(io.Closer); ok {
|
||||||
|
body = closeInhibitor{body}
|
||||||
|
defer cl.Close()
|
||||||
|
}
|
||||||
|
// If the authorization fails, we will need to restart reading
|
||||||
|
// from the passed body stream.
|
||||||
|
// When body is seekable, use seek to reset the streams
|
||||||
|
// cursor to the start.
|
||||||
|
// Otherwise, copy the stream into a buffer while uploading
|
||||||
|
// and use the buffers content on retry.
|
||||||
|
if sk, ok := body.(io.Seeker); ok {
|
||||||
|
if _, err = sk.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
retryBuf = body
|
||||||
|
} else {
|
||||||
|
buff := &bytes.Buffer{}
|
||||||
|
retryBuf = buff
|
||||||
|
body = io.TeeReader(body, buff)
|
||||||
|
}
|
||||||
|
r, err = http.NewRequest(method, PathEscape(Join(c.root, path)), body)
|
||||||
|
} else {
|
||||||
|
r, err = http.NewRequest(method, PathEscape(Join(c.root, path)), nil)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, vals := range c.headers {
|
for k, vals := range c.headers {
|
||||||
for _, v := range vals {
|
for _, v := range vals {
|
||||||
r.Header.Add(k, v)
|
r.Header.Add(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure we read 'c.auth' only once since it will be substituted below
|
||||||
|
// and that is unsafe to do when multiple goroutines are running at the same time.
|
||||||
|
c.authMutex.Lock()
|
||||||
|
auth := c.auth
|
||||||
|
c.authMutex.Unlock()
|
||||||
|
|
||||||
|
auth.Authorize(r, method, path)
|
||||||
|
|
||||||
if intercept != nil {
|
if intercept != nil {
|
||||||
intercept(r)
|
intercept(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.c.Do(r)
|
if c.interceptor != nil {
|
||||||
|
c.interceptor(method, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
rs, err := c.c.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.StatusCode == 401 && auth.Type() == "NoAuth" {
|
||||||
|
wwwAuthenticateHeader := strings.ToLower(rs.Header.Get("Www-Authenticate"))
|
||||||
|
|
||||||
|
if strings.Index(wwwAuthenticateHeader, "digest") > -1 {
|
||||||
|
c.authMutex.Lock()
|
||||||
|
c.auth = &DigestAuth{auth.User(), auth.Pass(), digestParts(rs)}
|
||||||
|
c.authMutex.Unlock()
|
||||||
|
} else if strings.Index(wwwAuthenticateHeader, "basic") > -1 {
|
||||||
|
c.authMutex.Lock()
|
||||||
|
c.auth = &BasicAuth{auth.User(), auth.Pass()}
|
||||||
|
c.authMutex.Unlock()
|
||||||
|
} else {
|
||||||
|
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// retryBuf will be nil if body was nil initially so no check
|
||||||
|
// for body == nil is required here.
|
||||||
|
return c.req(method, path, retryBuf, intercept)
|
||||||
|
} else if rs.StatusCode == 401 {
|
||||||
|
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) mkcol(path string) int {
|
func (c *Client) mkcol(path string) int {
|
||||||
@@ -31,7 +105,7 @@ func (c *Client) mkcol(path string) int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 400
|
return 400
|
||||||
}
|
}
|
||||||
rs.Body.Close()
|
defer rs.Body.Close()
|
||||||
|
|
||||||
if rs.StatusCode == 201 || rs.StatusCode == 405 {
|
if rs.StatusCode == 201 || rs.StatusCode == 405 {
|
||||||
return 201
|
return 201
|
||||||
@@ -53,7 +127,7 @@ func (c *Client) propfind(path string, self bool, body string, resp interface{},
|
|||||||
} else {
|
} else {
|
||||||
rq.Header.Add("Depth", "1")
|
rq.Header.Add("Depth", "1")
|
||||||
}
|
}
|
||||||
rq.Header.Add("Content-Type", "text/xml;charset=UTF-8")
|
rq.Header.Add("Content-Type", "application/xml;charset=UTF-8")
|
||||||
rq.Header.Add("Accept", "application/xml,text/xml")
|
rq.Header.Add("Accept", "application/xml,text/xml")
|
||||||
rq.Header.Add("Accept-Charset", "utf-8")
|
rq.Header.Add("Accept-Charset", "utf-8")
|
||||||
// TODO add support for 'gzip,deflate;q=0.8,q=0.7'
|
// TODO add support for 'gzip,deflate;q=0.8,q=0.7'
|
||||||
@@ -65,7 +139,7 @@ func (c *Client) propfind(path string, self bool, body string, resp interface{},
|
|||||||
defer rs.Body.Close()
|
defer rs.Body.Close()
|
||||||
|
|
||||||
if rs.StatusCode != 207 {
|
if rs.StatusCode != 207 {
|
||||||
return errors.New(fmt.Sprintf("%s - %s %s", rs.Status, "PROPFIND", path))
|
return fmt.Errorf("%s - %s %s", rs.Status, "PROPFIND", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseXML(rs.Body, resp, parse)
|
return parseXML(rs.Body, resp, parse)
|
||||||
@@ -101,7 +175,12 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
|
|||||||
log(fmt.Sprintf(" TODO handle %s - %s multistatus result %s", method, oldpath, String(data)))
|
log(fmt.Sprintf(" TODO handle %s - %s multistatus result %s", method, oldpath, String(data)))
|
||||||
|
|
||||||
case 409:
|
case 409:
|
||||||
// TODO create dst path
|
err := c.createParentCollection(newpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.copymove(method, oldpath, newpath, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPathError(method, oldpath, s)
|
return newPathError(method, oldpath, s)
|
||||||
@@ -112,6 +191,16 @@ func (c *Client) put(path string, stream io.Reader) int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 400
|
return 400
|
||||||
}
|
}
|
||||||
rs.Body.Close()
|
defer rs.Body.Close()
|
||||||
|
|
||||||
return rs.StatusCode
|
return rs.StatusCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) createParentCollection(itemPath string) (err error) {
|
||||||
|
parentPath := path.Dir(itemPath)
|
||||||
|
if parentPath == "." || parentPath == "/" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.MkdirAll(parentPath, 0755)
|
||||||
|
}
|
||||||
|
|||||||
69
utils.go
69
utils.go
@@ -3,9 +3,9 @@ package gowebdav
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,13 +17,31 @@ func log(msg interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newPathError(op string, path string, statusCode int) error {
|
func newPathError(op string, path string, statusCode int) error {
|
||||||
return &os.PathError{op, path, errors.New(fmt.Sprintf("%d", statusCode))}
|
return &os.PathError{
|
||||||
|
Op: op,
|
||||||
|
Path: path,
|
||||||
|
Err: fmt.Errorf("%d", statusCode),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPathErrorErr(op string, path string, err error) error {
|
func newPathErrorErr(op string, path string, err error) error {
|
||||||
return &os.PathError{op, path, err}
|
return &os.PathError{
|
||||||
|
Op: op,
|
||||||
|
Path: path,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PathEscape escapes all segments of a given path
|
||||||
|
func PathEscape(path string) string {
|
||||||
|
s := strings.Split(path, "/")
|
||||||
|
for i, e := range s {
|
||||||
|
s[i] = url.PathEscape(e)
|
||||||
|
}
|
||||||
|
return strings.Join(s, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixSlash appends a trailing / to our string
|
||||||
func FixSlash(s string) string {
|
func FixSlash(s string) string {
|
||||||
if !strings.HasSuffix(s, "/") {
|
if !strings.HasSuffix(s, "/") {
|
||||||
s += "/"
|
s += "/"
|
||||||
@@ -31,20 +49,25 @@ func FixSlash(s string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FixSlashes appends and prepends a / if they are missing
|
||||||
func FixSlashes(s string) string {
|
func FixSlashes(s string) string {
|
||||||
if s[0] != '/' {
|
if !strings.HasPrefix(s, "/") {
|
||||||
s = "/" + s
|
s = "/" + s
|
||||||
}
|
}
|
||||||
|
|
||||||
return FixSlash(s)
|
return FixSlash(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join joins two paths
|
||||||
func Join(path0 string, path1 string) string {
|
func Join(path0 string, path1 string) string {
|
||||||
return strings.TrimSuffix(path0, "/") + "/" + strings.TrimPrefix(path1, "/")
|
return strings.TrimSuffix(path0, "/") + "/" + strings.TrimPrefix(path1, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String pulls a string out of our io.Reader
|
||||||
func String(r io.Reader) string {
|
func String(r io.Reader) string {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(r)
|
// TODO - make String return an error as well
|
||||||
|
_, _ = buf.ReadFrom(r)
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,3 +108,39 @@ func parseXML(data io.Reader, resp interface{}, parse func(resp interface{}) err
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// limitedReadCloser wraps a io.ReadCloser and limits the number of bytes that can be read from it.
|
||||||
|
type limitedReadCloser struct {
|
||||||
|
rc io.ReadCloser
|
||||||
|
remaining int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *limitedReadCloser) Read(buf []byte) (int, error) {
|
||||||
|
if l.remaining <= 0 {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(buf) > l.remaining {
|
||||||
|
buf = buf[0:l.remaining]
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := l.rc.Read(buf)
|
||||||
|
l.remaining -= n
|
||||||
|
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *limitedReadCloser) Close() error {
|
||||||
|
return l.rc.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// closeInhibitor implements io.Closer and
|
||||||
|
// wraps a Reader. When Close() is performed
|
||||||
|
// on it, it will simply be silently rejected.
|
||||||
|
type closeInhibitor struct {
|
||||||
|
io.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ci closeInhibitor) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package gowebdav
|
package gowebdav
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestJoin(t *testing.T) {
|
func TestJoin(t *testing.T) {
|
||||||
eq(t, "/", "", "")
|
eq(t, "/", "", "")
|
||||||
@@ -16,3 +20,48 @@ func eq(t *testing.T, expected string, s0 string, s1 string) {
|
|||||||
t.Error("For", "'"+s0+"','"+s1+"'", "expeted", "'"+expected+"'", "got", "'"+s+"'")
|
t.Error("For", "'"+s0+"','"+s1+"'", "expeted", "'"+expected+"'", "got", "'"+s+"'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExamplePathEscape() {
|
||||||
|
fmt.Println(PathEscape(""))
|
||||||
|
fmt.Println(PathEscape("/"))
|
||||||
|
fmt.Println(PathEscape("/web"))
|
||||||
|
fmt.Println(PathEscape("/web/"))
|
||||||
|
fmt.Println(PathEscape("/w e b/d a v/s%u&c#k:s/"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
//
|
||||||
|
// /
|
||||||
|
// /web
|
||||||
|
// /web/
|
||||||
|
// /w%20e%20b/d%20a%20v/s%25u&c%23k:s/
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEscapeURL(t *testing.T) {
|
||||||
|
ex := "https://foo.com/w%20e%20b/d%20a%20v/s%25u&c%23k:s/"
|
||||||
|
u, _ := url.Parse("https://foo.com" + PathEscape("/w e b/d a v/s%u&c#k:s/"))
|
||||||
|
if ex != u.String() {
|
||||||
|
t.Error("expected: " + ex + " got: " + u.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFixSlashes(t *testing.T) {
|
||||||
|
expected := "/"
|
||||||
|
|
||||||
|
if got := FixSlashes(""); got != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = "/path/"
|
||||||
|
|
||||||
|
if got := FixSlashes("path"); got != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := FixSlashes("/path"); got != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := FixSlashes("path/"); got != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user