Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edb7b4dc17 | ||
|
|
85ee63af43 | ||
|
|
74b23a0bc5 | ||
|
|
be6c0bb850 | ||
|
|
ddb670ae1e | ||
|
|
4752758cf7 | ||
|
|
bd8aab4cba | ||
|
|
c61ede4153 | ||
|
|
efd46d6bd3 | ||
|
|
f2a8abb264 | ||
|
|
978aadc9b1 | ||
|
|
0626f07270 | ||
|
|
0afc8c9e5c | ||
|
|
28480c6acd | ||
|
|
826cdddca7 | ||
|
|
ec92ad9f47 | ||
|
|
ce97b9b9fd | ||
|
|
bbd93e111d | ||
|
|
f7c7d50e54 | ||
|
|
854d8bb705 | ||
|
|
7c0f261a97 | ||
|
|
7b9861b2c6 | ||
|
|
3a8fcbf4bc | ||
|
|
83d9247df6 | ||
|
|
d32286a13d | ||
|
|
621936f461 | ||
|
|
802e715fae | ||
|
|
adcafff384 | ||
|
|
a5ce1cf1e1 | ||
|
|
87d18a3089 | ||
|
|
e7fc0e97d6 | ||
|
|
34bdb8fcfc | ||
|
|
13b04f7672 | ||
|
|
76b9b2fa37 | ||
|
|
896d7cfbed | ||
|
|
0fb1b0840f | ||
|
|
1c0250075b | ||
|
|
cf2af817b9 | ||
|
|
ec24f79204 | ||
|
|
be902be453 | ||
|
|
888e08792e | ||
|
|
adc6ef22d9 | ||
|
|
0318d39112 | ||
|
|
abcfa0a05b | ||
|
|
a4b5c99ebb | ||
|
|
546e61a403 | ||
|
|
dcb68bd7a8 | ||
|
|
d411720234 | ||
|
|
1ae887d77c | ||
|
|
30465a771e | ||
|
|
f004b48b99 | ||
|
|
fc5e2247f6 | ||
|
|
5956647bd0 | ||
|
|
87eaf3ce5c | ||
|
|
73eba60210 | ||
|
|
4597ceb3a6 | ||
|
|
c0c25344c8 | ||
|
|
5efb36103f | ||
|
|
c0575a68ee | ||
|
|
ffd8a3a637 | ||
|
|
425ec275e9 | ||
|
|
3b9f336634 | ||
|
|
f792c31046 | ||
|
|
55a54ff89e | ||
|
|
78a40c9b14 | ||
|
|
17f32d16cc | ||
|
|
d57a0f2ae1 | ||
|
|
d6fdfef243 | ||
|
|
62d28dc89e | ||
|
|
57c65156f7 | ||
|
|
6e54dff40d | ||
|
|
0e722c8df1 | ||
|
|
f05479865c | ||
|
|
4e4055e7a8 | ||
|
|
7414ca10b3 | ||
|
|
1e17dfa6cb | ||
|
|
64d6d9e93b | ||
|
|
68902312cc | ||
|
|
a52b50b706 | ||
|
|
2527bdbfe1 | ||
|
|
473aaf13be | ||
|
|
0844b597f8 | ||
|
|
d45d7f92fb | ||
|
|
b3a822b4e8 | ||
|
|
788fadbd5e | ||
|
|
40f29e1e9b | ||
|
|
a036a25e1d | ||
|
|
abed362dc5 | ||
|
|
ce78299464 | ||
|
|
030f6607f0 | ||
|
|
c3a4e33245 | ||
|
|
aabf0843ab | ||
|
|
748e4acfb6 | ||
|
|
6e48a6b512 | ||
|
|
88500ab219 | ||
|
|
d0f8c141e1 | ||
|
|
34a1bf1380 | ||
|
|
b87ba12a7d | ||
|
|
bb0d048235 | ||
|
|
b991c65d8b | ||
|
|
b3b5db351f | ||
|
|
9562e06b92 | ||
|
|
7fc4899507 | ||
|
|
d649ae6ff7 | ||
|
|
633579e738 | ||
|
|
a65cb32d70 | ||
|
|
f1a7bc54ea | ||
|
|
8e1815944b | ||
|
|
db924c475a | ||
|
|
d970bb7de7 | ||
|
|
1fa91adae4 | ||
|
|
604487920d | ||
|
|
72e74d421c | ||
|
|
df5fc427ef | ||
|
|
12088154fe | ||
|
|
8ec27734bb | ||
|
|
1e6a0939a2 | ||
|
|
e58daaac83 | ||
|
|
7d0f25e530 | ||
|
|
cba41a1a32 | ||
|
|
997f21fc55 | ||
|
|
ead7fb4233 | ||
|
|
4590884a34 | ||
|
|
cc6689ac3a | ||
|
|
3ab225a101 | ||
|
|
31b70a7736 | ||
|
|
bbeadee98e | ||
|
|
b8169b6ebe | ||
|
|
e5b8684e7f | ||
|
|
912c4b4eee | ||
|
|
b8dfd79dfe | ||
|
|
579f3ccd7d | ||
|
|
f5b3ab8db6 | ||
|
|
51f34eaadb | ||
|
|
6699993088 | ||
|
|
4257a775c8 | ||
|
|
331c7bf387 | ||
|
|
4c64aa7d11 | ||
|
|
df42e352f7 | ||
|
|
1f8ec36eef | ||
|
|
586bb63ee7 | ||
|
|
1f985fe72f | ||
|
|
575296d7fc | ||
|
|
b93dc9f200 | ||
|
|
6255f737ba | ||
|
|
2ca921b01b | ||
|
|
61cf3eb11a | ||
|
|
a1573b2b64 | ||
|
|
de2c2021d7 | ||
|
|
243b12d4c2 | ||
|
|
fa86894550 | ||
|
|
4a1e21baec | ||
|
|
3ed2144a0e | ||
|
|
0607e0df2d | ||
|
|
a437761d03 | ||
|
|
b432e1bf46 | ||
|
|
8dd59e3e67 | ||
|
|
fd5543407a | ||
|
|
48d012ff92 | ||
|
|
2c4eae5ca2 | ||
|
|
629646122f | ||
|
|
d4f284f1a3 | ||
|
|
ff3b5b39a5 | ||
|
|
9667980f2d | ||
|
|
188a34f835 | ||
|
|
f9cd5f11d9 | ||
|
|
adedf0178b | ||
|
|
4e15b82896 | ||
|
|
ed0ea34161 | ||
|
|
e2ffd36073 | ||
|
|
6bd2a1852f | ||
|
|
371236e364 | ||
|
|
6cbdc9d7c5 | ||
|
|
a94125f3f2 | ||
|
|
2f5f5d75a7 | ||
|
|
02f2284f3b | ||
|
|
2b1305a315 | ||
|
|
ec78f67abd | ||
|
|
25c04af500 | ||
|
|
c2f1d07abc | ||
|
|
0d1074b6d9 | ||
|
|
c0391d866e | ||
|
|
dcb97be587 | ||
|
|
c6eb98aef2 | ||
|
|
1c6e15c064 | ||
|
|
711a3a30b0 | ||
|
|
e203ca14f4 | ||
|
|
0f1b69b625 | ||
|
|
65a53514d5 | ||
|
|
176eaad70b | ||
|
|
486dfe4e63 | ||
|
|
81cf4bab99 | ||
|
|
ce68f48fb4 | ||
|
|
5a03c75dc3 | ||
|
|
20d80bb054 | ||
|
|
cbdf3cafb6 | ||
|
|
9c3f563f83 | ||
|
|
6b42781c21 | ||
|
|
1259fc1bbc | ||
|
|
891a0d1bd0 | ||
|
|
3b9063dc63 | ||
|
|
2bfdffb9c4 | ||
|
|
4cf1f2f6b4 | ||
|
|
9f8685bf10 | ||
|
|
b58bc414bf | ||
|
|
0b81723118 | ||
|
|
a90bb28cae | ||
|
|
e86dfbe8ff | ||
|
|
66418ec064 | ||
|
|
d87640a4f1 | ||
|
|
e5580ac0c4 | ||
|
|
b92c800e00 | ||
|
|
437a238aca | ||
|
|
e5fa0772c6 | ||
|
|
ba5c67d9da | ||
|
|
e370fbe500 | ||
|
|
f3d007025e | ||
|
|
89d4d828b9 | ||
|
|
e7a39808dd | ||
|
|
2b7aa7a0c9 | ||
|
|
4d8f0c532b | ||
|
|
367e251a0e | ||
|
|
d004015f03 | ||
|
|
ba5b5fbfe3 | ||
|
|
cc6f2f8bec | ||
|
|
dd29a87107 | ||
|
|
007fde8186 | ||
|
|
552f8168ea | ||
|
|
b394540f53 | ||
|
|
3ed5f8c0bd | ||
|
|
5d5cef2a87 | ||
|
|
9264e344d7 | ||
|
|
0a46ac3e1b | ||
|
|
a438fc746f | ||
|
|
0c8ffaf73e | ||
|
|
6c1bbb3248 | ||
|
|
e663c60a89 | ||
|
|
e1e8979e0b | ||
|
|
de53b24536 | ||
|
|
bc518a0e82 | ||
|
|
42426e3e69 | ||
|
|
e706391934 | ||
|
|
58ff28f84d | ||
|
|
74a1ecbb89 | ||
|
|
5fa1711a30 | ||
|
|
4bc6a23143 | ||
|
|
b578e2196a | ||
|
|
866375141f | ||
|
|
a3b9807717 | ||
|
|
d47774c828 | ||
|
|
bc4ac5eb9b | ||
|
|
f16ec4b45c | ||
|
|
f8da8bc985 | ||
|
|
0ec589ca74 | ||
|
|
4e4ac88cbe | ||
|
|
0762516a18 | ||
|
|
41272e67a3 | ||
|
|
da7d1db06c | ||
|
|
cc428d3cd6 | ||
|
|
9a54abfe62 | ||
|
|
c50a9b29bd | ||
|
|
3396218ff0 | ||
|
|
04392a7328 | ||
|
|
e1026a1fb4 | ||
|
|
4703e0d36f | ||
|
|
2e1553542b | ||
|
|
438371fc9a | ||
|
|
6712fa580b | ||
|
|
b660404bfe | ||
|
|
6ab8779948 | ||
|
|
dd16a2e836 | ||
|
|
2ed87febcb | ||
|
|
870b5b4079 | ||
|
|
ee169b3a46 | ||
|
|
90d690c187 | ||
|
|
66d485f639 | ||
|
|
684366e050 | ||
|
|
01929c72ea | ||
|
|
802318f903 | ||
|
|
b9acd275a2 | ||
|
|
1809a3638b | ||
|
|
5a83d6736b | ||
|
|
77e1fe83db | ||
|
|
1133f0f826 | ||
|
|
981b42fb5c | ||
|
|
c59d42b601 | ||
|
|
f70fc2d954 | ||
|
|
1aec3744d7 | ||
|
|
25792232e6 | ||
|
|
2869570a20 | ||
|
|
3a4ff6dbb2 | ||
|
|
42134a4849 | ||
|
|
e5c150e83f | ||
|
|
f1a89f5ec4 | ||
|
|
f2d952bf0e | ||
|
|
70733ff846 | ||
|
|
94619341f2 | ||
|
|
36bd2907f8 | ||
|
|
f879944346 | ||
|
|
d821418bca | ||
|
|
0e7d4ef110 | ||
|
|
a21198be11 | ||
|
|
7a6397af22 | ||
|
|
ac512612e7 | ||
|
|
70042f4489 | ||
|
|
3890a9a416 | ||
|
|
a58b64085d | ||
|
|
90b7f4aaf6 | ||
|
|
2def76df83 | ||
|
|
1db210a24f | ||
|
|
b0586d985c | ||
|
|
a52374e288 | ||
|
|
277f13a350 | ||
|
|
ea434ffc04 | ||
|
|
12b2c21522 | ||
|
|
53a4601361 | ||
|
|
4c7c507830 | ||
|
|
bc8d19feff | ||
|
|
95fc3dfdfb | ||
|
|
39be89780e | ||
|
|
f77009365f | ||
|
|
74e93b8df0 | ||
|
|
901dc2c160 | ||
|
|
b5ee82c943 | ||
|
|
8e4805ba69 | ||
|
|
694c750561 | ||
|
|
efa3b3f198 | ||
|
|
998dd9430d | ||
|
|
c8b5728743 | ||
|
|
2642333928 | ||
|
|
7e1d745435 | ||
|
|
218e638f88 | ||
|
|
fab33e3ed1 | ||
|
|
cad2a989c1 | ||
|
|
f844aeb2b4 | ||
|
|
7847763a31 | ||
|
|
3f49bc382e | ||
|
|
5079f405fc | ||
|
|
b85a07536d | ||
|
|
7e3a15e073 | ||
|
|
3ae9e518a3 | ||
|
|
aeb4e2aab3 | ||
|
|
bd65bc9e44 | ||
|
|
59468830bb | ||
|
|
d7c3665e2b | ||
|
|
679b0f0f4e | ||
|
|
7d912dd257 | ||
|
|
a92d7aab8e | ||
|
|
0536d8342c | ||
|
|
1e5ced6737 | ||
|
|
93acf4a6f7 | ||
|
|
fa67652ba4 | ||
|
|
62106cc0a4 | ||
|
|
dd8f47fade | ||
|
|
3f4db6b81e | ||
|
|
e471e79d50 | ||
|
|
6b4bce5daf | ||
|
|
99740e3eab | ||
|
|
c12adbb594 | ||
|
|
157b2da133 | ||
|
|
208f21728f | ||
|
|
0377080da6 | ||
|
|
f5c48c9679 | ||
|
|
99ef1308ea | ||
|
|
9f075c16c5 | ||
|
|
2f17f19425 | ||
|
|
06f00e9664 | ||
|
|
c681174adf | ||
|
|
4a12ce1888 | ||
|
|
4e39f2387a | ||
|
|
e354098b96 | ||
|
|
9086720c3c | ||
|
|
2bb9171e32 | ||
|
|
294efef38c | ||
|
|
4f1d25fba7 | ||
|
|
d3e363a4d5 | ||
|
|
a10f286f0f | ||
|
|
390c53097f | ||
|
|
4c30b2c665 | ||
|
|
325e6e0904 | ||
|
|
56ec440272 | ||
|
|
0af5e07eed | ||
|
|
8a764ceb67 | ||
|
|
fe829aa850 | ||
|
|
2ca22656d6 | ||
|
|
cb7fa99fd3 | ||
|
|
441639a8d5 | ||
|
|
a78e1d504b | ||
|
|
02f6b0ec61 | ||
|
|
8c60cc7084 | ||
|
|
a7e4596e97 | ||
|
|
97d53ceb2e | ||
|
|
a49fb20885 | ||
|
|
2d5e97e140 | ||
|
|
ebdf5a0601 | ||
|
|
9ca02c90ed | ||
|
|
0595638228 | ||
|
|
1f4d0cc3cd | ||
|
|
e6c0d1c28a |
No files matched your search
@@ -0,0 +1,79 @@
|
|||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
docker:
|
||||||
|
- image: golangci/golangci-lint:v1.16
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: golangci-lint run -v -D errcheck
|
||||||
|
build-node:
|
||||||
|
docker:
|
||||||
|
- image: circleci/node
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: "Build"
|
||||||
|
command: ./wizard.sh -a
|
||||||
|
- run:
|
||||||
|
name: "Cleanup"
|
||||||
|
command: rm -rf frontend/node_modules
|
||||||
|
- persist_to_workspace:
|
||||||
|
root: .
|
||||||
|
paths:
|
||||||
|
- '*'
|
||||||
|
build-go:
|
||||||
|
docker:
|
||||||
|
- image: circleci/golang:1.12
|
||||||
|
steps:
|
||||||
|
- attach_workspace:
|
||||||
|
at: '~/project'
|
||||||
|
- run:
|
||||||
|
name: "Compile"
|
||||||
|
command: GOOS=linux GOARCH=amd64 ./wizard.sh -c
|
||||||
|
- run:
|
||||||
|
name: "Cleanup"
|
||||||
|
command: |
|
||||||
|
rm -rf frontend/build
|
||||||
|
git checkout -- go.sum # TODO: why is it being changed?
|
||||||
|
- persist_to_workspace:
|
||||||
|
root: .
|
||||||
|
paths:
|
||||||
|
- '*'
|
||||||
|
release:
|
||||||
|
docker:
|
||||||
|
- image: circleci/golang:1.12
|
||||||
|
steps:
|
||||||
|
- attach_workspace:
|
||||||
|
at: '~/project'
|
||||||
|
- setup_remote_docker
|
||||||
|
- run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
|
||||||
|
- run: curl -sL https://git.io/goreleaser | bash
|
||||||
|
- run: docker logout
|
||||||
|
workflows:
|
||||||
|
version: 2
|
||||||
|
build-workflow:
|
||||||
|
jobs:
|
||||||
|
- lint:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
- build-node:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
- build-go:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
requires:
|
||||||
|
- build-node
|
||||||
|
- lint
|
||||||
|
- release:
|
||||||
|
context: deploy
|
||||||
|
requires:
|
||||||
|
- build-go
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /^v.*/
|
||||||
|
branches:
|
||||||
|
ignore: /.*/
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"port": 80,
|
||||||
|
"baseURL": "",
|
||||||
|
"address": "",
|
||||||
|
"log": "stdout",
|
||||||
|
"database": "/database.db",
|
||||||
|
"root": "/srv"
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
name: Caddy related bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
---
|
|
||||||
|
|
||||||
**Are you asking for help with using Caddy or File Browser?**
|
|
||||||
Please use our forum instead: https://forum.caddyserver.com.
|
|
||||||
|
|
||||||
**When did you download File Browser from caddyserver.com?**
|
|
||||||
|
|
||||||
**What is your entire Caddyfile?**
|
|
||||||
|
|
||||||
```text
|
|
||||||
(Put Caddyfile here)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Description**
|
|
||||||
A clear and concise description of what the issue is about. What are you trying to do?
|
|
||||||
|
|
||||||
**Expected behaviour**
|
|
||||||
What did you expect to happen?
|
|
||||||
|
|
||||||
**What is happening instead?**
|
|
||||||
Please, give full error messages and/or log.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here. If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**How to reproduce?**
|
|
||||||
Tell us how to reproduce this issue. How can someone who is starting from scratch reproduce this behaviour as minimally as possible?
|
|
||||||
|
|
||||||
**Files**
|
|
||||||
A list of relevant files for this issue. Large files can be uploaded one-by-one or in a tarball/zipfile.
|
|
||||||
@@ -1,15 +1,29 @@
|
|||||||
.DS_Store
|
|
||||||
*/dist/*
|
|
||||||
*.db
|
*.db
|
||||||
*.db.lock
|
*.lock
|
||||||
.idea
|
*.bak
|
||||||
.vscode
|
_old
|
||||||
Dockerfile
|
|
||||||
filebrowser
|
|
||||||
rice-box.go
|
rice-box.go
|
||||||
vendor
|
.idea/
|
||||||
|
filebrowser
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/frontend/dist
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
package-lock.json
|
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
yarn.lock
|
|
||||||
|
# Editor directories and files
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw*
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[submodule "frontend"]
|
|
||||||
path = frontend
|
|
||||||
url = https://github.com/filebrowser/frontend
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"Enable": [
|
|
||||||
"deadcode",
|
|
||||||
"gotype",
|
|
||||||
"gotypex",
|
|
||||||
"ineffassign",
|
|
||||||
"interfacer",
|
|
||||||
"maligned",
|
|
||||||
"megacheck",
|
|
||||||
"structcheck",
|
|
||||||
"unconvert",
|
|
||||||
"varcheck",
|
|
||||||
"vet"
|
|
||||||
],
|
|
||||||
"Disable": [
|
|
||||||
"dupl",
|
|
||||||
"errcheck",
|
|
||||||
"gochecknoglobals",
|
|
||||||
"gochecknoinits",
|
|
||||||
"goconst",
|
|
||||||
"gocyclo",
|
|
||||||
"gofmt",
|
|
||||||
"goimports",
|
|
||||||
"golint",
|
|
||||||
"gosec",
|
|
||||||
"gosimple",
|
|
||||||
"lll",
|
|
||||||
"misspell",
|
|
||||||
"nakedret",
|
|
||||||
"safesql",
|
|
||||||
"staticcheck",
|
|
||||||
"test",
|
|
||||||
"testify",
|
|
||||||
"unparam",
|
|
||||||
"unused",
|
|
||||||
"vetshadow"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
project_name: filebrowser
|
project_name: filebrowser
|
||||||
|
|
||||||
|
env:
|
||||||
|
- GO111MODULE=on
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod download
|
||||||
|
|
||||||
build:
|
build:
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
main: cmd/filebrowser/main.go
|
ldflags:
|
||||||
|
- -s -w -X github.com/filebrowser/filebrowser/v2/version.Version={{ .Version }} -X github.com/filebrowser/filebrowser/v2/version.CommitSHA={{ .ShortCommit }}
|
||||||
|
main: main.go
|
||||||
binary: filebrowser
|
binary: filebrowser
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
@@ -35,25 +44,22 @@ build:
|
|||||||
- goos: solaris
|
- goos: solaris
|
||||||
goarch: arm
|
goarch: arm
|
||||||
|
|
||||||
archive:
|
archives:
|
||||||
name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}"
|
-
|
||||||
format: tar.gz
|
name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}"
|
||||||
format_overrides:
|
format: tar.gz
|
||||||
- goos: windows
|
format_overrides:
|
||||||
format: zip
|
- goos: windows
|
||||||
|
format: zip
|
||||||
release:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
dockers:
|
dockers:
|
||||||
-
|
-
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
goarm: ''
|
goarm: ''
|
||||||
image: filebrowser/filebrowser
|
image_templates:
|
||||||
skip_push: true
|
- "filebrowser/filebrowser:latest"
|
||||||
tag_templates:
|
- "filebrowser/filebrowser:{{ .Tag }}"
|
||||||
- "{{ .Tag }}"
|
- "filebrowser/filebrowser:v{{ .Major }}"
|
||||||
- latest
|
|
||||||
extra_files:
|
extra_files:
|
||||||
- Docker.json
|
- .docker.json
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
os: linux
|
|
||||||
services: docker
|
|
||||||
language: minimal
|
|
||||||
install: skip
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- docker-ce
|
|
||||||
- pass
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- USE_DOCKER="true"
|
|
||||||
- WDIR=/go/src/github.com/filebrowser/filebrowser
|
|
||||||
stages:
|
|
||||||
- lint
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- vendor
|
|
||||||
- rice-box.go
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
- stage: lint
|
|
||||||
script: "./build/run_gometalinter.sh"
|
|
||||||
- stage: test
|
|
||||||
script: "./build/build_all.sh"
|
|
||||||
deploy:
|
|
||||||
provider: script
|
|
||||||
skip_cleanup: true
|
|
||||||
script: docker build -t filebrowser/filebrowser . && ./build/docker_login.sh && docker push filebrowser/filebrowser && docker logout
|
|
||||||
on:
|
|
||||||
tags: false
|
|
||||||
repo: filebrowser/filebrowser
|
|
||||||
branch: master
|
|
||||||
- stage: release
|
|
||||||
script:
|
|
||||||
- docker run --rm -itv $(pwd):$WDIR -v /var/run/docker.sock:/var/run/docker.sock filebrowser/dev goreleaser
|
|
||||||
- ./build/push_images.sh
|
|
||||||
- ./build/push_ricebox.sh
|
|
||||||
if: tag IS present
|
|
||||||
deploy:
|
|
||||||
provider: releases
|
|
||||||
skip_cleanup: true
|
|
||||||
api_key:
|
|
||||||
secure: GCURbl9xmjOmeNc7cYSvfSwbEp46cacWmJRczcsU6rQa0aWqzjELYdyIsl6HWW+o0dzuZvbWRD6muxYqIud92oPLYDuXSnra9tM3mCjswrjiPCJ57bksWkSPBfFQcxIyB6c3o+A/FMnX3nnSE/2r5HYZnPNFbEcBbC7WSgwx9ejXUuyWn1PUFK9YQWANdl6J7b7EKsk+9MxS9Pmw6M2ycBwX8ScUQdofkUPvR/nqlXISm+3hs30VubqQi9Ha6DM9Bw3aFK3/Ts/ujCOxP1ZoMCBZ6tfnaQOElIG96WTwnt77eDYlZezBOLym3Z18iif+Qny+XndFKDbexaiUT06VlWFXCKtt3iLs6HJwRcjmiHmB0Z3v+W4cKPl3cEyxxrU2aal54k1PBhU+5L0Xc8ileKbDMYg5tps88zWHNefeZVfaxYSVrmUHkuygMe481oaBLacDXTxs4t6XEpStREuLmvx9NLTwTFAbWjMNM0PqlueDMxO4bdwNvzXg/TcKLWV9FezqAlre8lFNZK5wX6lKFVSZ3hFjxCfwrJL2cPwg5A8Yd5EOC4Nh81WdgYuFGOxZzMAoSJlaVRvQS1trCUP/++ONnDep3ExSxvw4B7vijGZWeXUhrOMiPQHXu+t6BnrlnDjQ4gi44QTW0y/iM2WC2DBKfgYjAKwyHx13hFrmOCg=
|
|
||||||
file: "dist/*.*"
|
|
||||||
file_glob: true
|
|
||||||
on:
|
|
||||||
repo: filebrowser/filebrowser
|
|
||||||
all_branches: true
|
|
||||||
tags: true
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[main]
|
||||||
|
host = https://www.transifex.com
|
||||||
|
lang_map = pt_BR: pt-br, zh_CN: zh-cn, zh_HK: zh-hk, zh_TW: zh-tw, nl_BE: nl-be, sv_SE: sv-se
|
||||||
|
|
||||||
|
[file-browser.file-browser]
|
||||||
|
file_filter = frontend/src/i18n/<lang>.json
|
||||||
|
minimum_perc = 50
|
||||||
|
source_file = frontend/src/i18n/en.json
|
||||||
|
source_lang = en
|
||||||
|
type = KEYVALUEJSON
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"port": 80,
|
|
||||||
"address": "",
|
|
||||||
"database": "/database.db",
|
|
||||||
"scope": "/srv",
|
|
||||||
"allowCommands": true,
|
|
||||||
"allowEdit": true,
|
|
||||||
"allowNew": true,
|
|
||||||
"commands": []
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
|
FROM alpine:latest as certs
|
||||||
|
RUN apk --update add ca-certificates
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
|
||||||
COPY --from=filebrowser/dev /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
|
|
||||||
VOLUME /tmp
|
|
||||||
VOLUME /srv
|
VOLUME /srv
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
|
COPY .docker.json /.filebrowser.json
|
||||||
COPY filebrowser /filebrowser
|
COPY filebrowser /filebrowser
|
||||||
COPY Docker.json /config.json
|
|
||||||
|
|
||||||
ENTRYPOINT ["/filebrowser", "--config", "/config.json"]
|
ENTRYPOINT [ "/filebrowser" ]
|
||||||
@@ -1,429 +0,0 @@
|
|||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/BurntSushi/toml"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "a368813c5e648fee92e5f6c30e3944ff9d5e8895"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/GeertJohan/go.rice"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"embedded"
|
|
||||||
]
|
|
||||||
revision = "c02ca9a983da5807ddf7d796784928f5be4afd09"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/aead/chacha20"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"chacha"
|
|
||||||
]
|
|
||||||
revision = "c8d29375923a8e1d2a0f0dc0fc1d8a0aba5b97ba"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/asdine/storm"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"codec",
|
|
||||||
"codec/json",
|
|
||||||
"index",
|
|
||||||
"internal",
|
|
||||||
"q"
|
|
||||||
]
|
|
||||||
revision = "68fc73b635f890fe7ba2f3b15ce80c85b28a744f"
|
|
||||||
version = "v2.0.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/bifurcation/mint"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"syntax"
|
|
||||||
]
|
|
||||||
revision = "340be3ae8c0ff8edce24cf59e7acdb1432bd5ce5"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/chaseadamsio/goorgeous"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "dcf1ef873b8987bf12596fe6951c48347986eb2f"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/codahale/aesnicheck"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "349fcc471aaccc29cd074e1275f1a494323826cd"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/coreos/bbolt"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "583e8937c61f1af6513608ccc75c97b6abdf4ff9"
|
|
||||||
version = "v1.3.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/daaku/go.zipexe"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "a5fe2436ffcb3236e175e5149162b41cd28bd27d"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/dgrijalva/jwt-go"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"request"
|
|
||||||
]
|
|
||||||
revision = "dbeaa9332f19a944acb5736b4456cfcc02140e29"
|
|
||||||
version = "v3.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/dsnet/compress"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"bzip2",
|
|
||||||
"bzip2/internal/sais",
|
|
||||||
"internal",
|
|
||||||
"internal/errors",
|
|
||||||
"internal/prefix"
|
|
||||||
]
|
|
||||||
revision = "cc9eb1d7ad760af14e8f918698f745e80377af4f"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/flynn/go-shlex"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "3f9db97f856818214da2e1057f8ad84803971cff"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/fsnotify/fsnotify"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
|
|
||||||
version = "v1.4.7"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/gohugoio/hugo"
|
|
||||||
packages = ["parser"]
|
|
||||||
revision = "25e88ccabe9b04c42ffb43528c86743f623fac46"
|
|
||||||
version = "v0.36.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/golang/snappy"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "553a641470496b2327abcac10b36396bd98e45c9"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/gorilla/websocket"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
|
|
||||||
version = "v1.2.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hacdias/fileutils"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "76b1c6ab906773727a1ce2f7fb22830685166f85"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hacdias/varutils"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "82d3b57f667a756cfc4b1535951b46878881f3e1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hashicorp/go-syslog"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "326bf4a7f709d263f964a6a96558676b103f3534"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hashicorp/golang-lru"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"simplelru"
|
|
||||||
]
|
|
||||||
revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hashicorp/hcl"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"hcl/ast",
|
|
||||||
"hcl/parser",
|
|
||||||
"hcl/scanner",
|
|
||||||
"hcl/strconv",
|
|
||||||
"hcl/token",
|
|
||||||
"json/parser",
|
|
||||||
"json/scanner",
|
|
||||||
"json/token"
|
|
||||||
]
|
|
||||||
revision = "23c074d0eceb2b8a5bfdbb271ab780cde70f05a8"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/kardianos/osext"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "ae77be60afb1dcacde03767a8c37337fad28ac14"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/lucas-clemente/aes12"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "cd47fb39b79f867c6e4e5cd39cf7abd799f71670"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/lucas-clemente/fnv128a"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "393af48d391698c6ae4219566bfbdfef67269997"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/lucas-clemente/quic-go"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"h2quic",
|
|
||||||
"internal/ackhandler",
|
|
||||||
"internal/congestion",
|
|
||||||
"internal/crypto",
|
|
||||||
"internal/flowcontrol",
|
|
||||||
"internal/handshake",
|
|
||||||
"internal/protocol",
|
|
||||||
"internal/utils",
|
|
||||||
"internal/wire",
|
|
||||||
"qerr"
|
|
||||||
]
|
|
||||||
revision = "30851b9a3b4e958490b476fe72adafa67641361a"
|
|
||||||
version = "v0.7.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/lucas-clemente/quic-go-certificates"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "d2f86524cced5186554df90d92529757d22c1cb6"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/magiconair/properties"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6"
|
|
||||||
version = "v1.7.6"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/maruel/natural"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "dbcb3e2e8cf10eb839718ba666ef1e21b1c8b847"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/mholt/archiver"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "26cf5bb32d07aa4e8d0de15f56ce516f4641d7df"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/mholt/caddy"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"caddyfile",
|
|
||||||
"caddyhttp/httpserver",
|
|
||||||
"caddyhttp/staticfiles",
|
|
||||||
"caddytls"
|
|
||||||
]
|
|
||||||
revision = "d3f338ddab9ee24b376b5c9c51e202581e2d43ba"
|
|
||||||
version = "v0.10.11"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/miekg/dns"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "5364553f1ee9cddc7ac8b62dce148309c386695b"
|
|
||||||
version = "v1.0.4"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mitchellh/mapstructure"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "00c29f56e2386353d58c599509e8dc3801b0d716"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/nwaples/rardecode"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "e06696f847aeda6f39a8f0b7cdff193b7690aef6"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pelletier/go-toml"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pierrec/lz4"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "2fcda4cb7018ce05a25959d2fe08c83e3329f169"
|
|
||||||
version = "v1.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pierrec/xxHash"
|
|
||||||
packages = ["xxHash32"]
|
|
||||||
revision = "f051bb7f1d1aaf1b5a665d74fb6b0217712c69f7"
|
|
||||||
version = "v0.1.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/robfig/cron"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "b024fc5ea0e34bc3f83d9941c8d60b0622bfaca4"
|
|
||||||
version = "v1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/russross/blackfriday"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "4048872b16cc0fc2c5fd9eacf0ed2c2fedaa0c8c"
|
|
||||||
version = "v1.5"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/shurcooL/sanitized_anchor_name"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "86672fcb3f950f35f2e675df2240550f2a50762f"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/spf13/afero"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"mem"
|
|
||||||
]
|
|
||||||
revision = "bb8f1927f2a9d3ab41c9340aa034f6b803f4359c"
|
|
||||||
version = "v1.0.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/spf13/cast"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "8965335b8c7107321228e3e3702cab9832751bac"
|
|
||||||
version = "v1.2.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/spf13/jwalterweatherman"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/spf13/pflag"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/spf13/viper"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "25b30aa063fc18e48662b86996252eabdcf2f0c7"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/ulikunitz/xz"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"internal/hash",
|
|
||||||
"internal/xlog",
|
|
||||||
"lzma"
|
|
||||||
]
|
|
||||||
revision = "0c6b41e72360850ca4f98dc341fd999726ea007f"
|
|
||||||
version = "v0.5.4"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/xenolf/lego"
|
|
||||||
packages = ["acme"]
|
|
||||||
revision = "67c86d860a797ce2483f50d9174d4ed24984bef2"
|
|
||||||
version = "v0.4.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
packages = [
|
|
||||||
"bcrypt",
|
|
||||||
"blowfish",
|
|
||||||
"curve25519",
|
|
||||||
"ed25519",
|
|
||||||
"ed25519/internal/edwards25519",
|
|
||||||
"hkdf",
|
|
||||||
"ocsp"
|
|
||||||
]
|
|
||||||
revision = "49796115aa4b964c318aad4f3084fdb41e9aa067"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/net"
|
|
||||||
packages = [
|
|
||||||
"bpf",
|
|
||||||
"http2",
|
|
||||||
"http2/hpack",
|
|
||||||
"idna",
|
|
||||||
"internal/iana",
|
|
||||||
"internal/socket",
|
|
||||||
"ipv4",
|
|
||||||
"ipv6",
|
|
||||||
"lex/httplex",
|
|
||||||
"publicsuffix"
|
|
||||||
]
|
|
||||||
revision = "cbe0f9307d0156177f9dd5dc85da1a31abc5f2fb"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
packages = ["unix"]
|
|
||||||
revision = "88d2dcc510266da9f7f8c7f34e1940716cab5f5c"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "golang.org/x/text"
|
|
||||||
packages = [
|
|
||||||
"collate",
|
|
||||||
"collate/build",
|
|
||||||
"internal/colltab",
|
|
||||||
"internal/gen",
|
|
||||||
"internal/tag",
|
|
||||||
"internal/triegen",
|
|
||||||
"internal/ucd",
|
|
||||||
"language",
|
|
||||||
"secure/bidirule",
|
|
||||||
"transform",
|
|
||||||
"unicode/bidi",
|
|
||||||
"unicode/cldr",
|
|
||||||
"unicode/norm",
|
|
||||||
"unicode/rangetable"
|
|
||||||
]
|
|
||||||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
|
||||||
version = "v0.3.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
|
|
||||||
version = "v2.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "gopkg.in/square/go-jose.v1"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"cipher",
|
|
||||||
"json"
|
|
||||||
]
|
|
||||||
revision = "aa2e30fdd1fe9dd3394119af66451ae790d50e0d"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "gopkg.in/yaml.v2"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5"
|
|
||||||
version = "v2.1.1"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "1f68bed4490068370884abaa296aa651c27b3f2e0d0451a1ab567f059d44f820"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/GeertJohan/go.rice"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/asdine/storm"
|
|
||||||
version = "2.0.2"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/dgrijalva/jwt-go"
|
|
||||||
version = "3.1.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/gohugoio/hugo"
|
|
||||||
version = "0.36.1"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/gorilla/websocket"
|
|
||||||
version = "1.2.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hacdias/fileutils"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/hacdias/varutils"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/mholt/archiver"
|
|
||||||
# TODO: switch to version when it's available
|
|
||||||
# this is for Archiver.Write() which was introduced in 548c791
|
|
||||||
revision = "26cf5bb32d07aa4e8d0de15f56ce516f4641d7df"
|
|
||||||
# version = "2.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/mholt/caddy"
|
|
||||||
version = "0.10.11"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mitchellh/mapstructure"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/robfig/cron"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/spf13/pflag"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/spf13/viper"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
version = "2.1.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/maruel/natural"
|
|
||||||
|
|
||||||
[[override]]
|
|
||||||
name = "github.com/russross/blackfriday"
|
|
||||||
version = "^1.0.0"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
@@ -1,16 +1,12 @@
|
|||||||
**In Q2 2018, this project was renamed from `filemanager` to `filebrowser`, a new GitHub organization was created and the main repo was moved from [hacdias/filemanager](https://github.com/hacdias/filemanager) to [filebrowser/filebrowser](https://github.com/filebrowser/filebrowser). Old refs will work, because permanent redirects are set up. However, we suggest every contributor to update the remote URLs in their local clones. See [Changing a remote's URL](https://help.github.com/articles/changing-a-remote-s-url/).**
|
|
||||||
|
|
||||||
**Moreover, the previously unique repo was split into multiple pieces: frontend, logo, caddy... At the same time, the official docker image was changed to [`filebrowser/filebrowser`](https://hub.docker.com/r/filebrowser/filebrowser/). Users are encouraged to check their sources and update them accordingly.**
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://raw.githubusercontent.com/filebrowser/logo/master/banner.png" width="550"/>
|
<img src="https://raw.githubusercontent.com/filebrowser/logo/master/banner.png" width="550"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||

|
> ⚠️ WARN: **This project is not under active development ATM. A small group of developers keeps the project alive, but due to lack of time, we can't continue adding new features or doing deep changes. Please read [#532](https://github.com/filebrowser/filebrowser/issues/532) for more info!**
|
||||||
|
|
||||||
# filebrowser
|

|
||||||
|
|
||||||
[](https://circleci.com/gh/filebrowser/filebrowser)
|
[](https://travis-ci.com/filebrowser/filebrowser)
|
||||||
[](https://goreportcard.com/report/github.com/filebrowser/filebrowser)
|
[](https://goreportcard.com/report/github.com/filebrowser/filebrowser)
|
||||||
[](http://godoc.org/github.com/filebrowser/filebrowser)
|
[](http://godoc.org/github.com/filebrowser/filebrowser)
|
||||||
[](https://github.com/filebrowser/filebrowser/releases/latest)
|
[](https://github.com/filebrowser/filebrowser/releases/latest)
|
||||||
@@ -18,67 +14,18 @@
|
|||||||
|
|
||||||
filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app or as a middleware.
|
filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app or as a middleware.
|
||||||
|
|
||||||
# Table of contents
|
## Features
|
||||||
|
|
||||||
+ [Getting started](#getting-started)
|
Please refer to our docs at [filebrowser.xyz/features](https://filebrowser.xyz/features)
|
||||||
+ [Features](#features)
|
|
||||||
- [Users](#users)
|
|
||||||
- [Search](#search)
|
|
||||||
+ [Contributing](#contributing)
|
|
||||||
+ [Donate](#donate)
|
|
||||||
|
|
||||||
# Getting started
|
## Install
|
||||||
|
|
||||||
You can find the Getting Started guide on the [documentation](https://filebrowser.github.io/quick-start/).
|
Please refer to our docs at [filebrowser.xyz](https://filebrowser.xyz/).
|
||||||
|
|
||||||
# Features
|
## Usage
|
||||||
|
|
||||||
Easy login system.
|
Please refer to our docs at [filebrowser.xyz/usage](https://filebrowser.xyz/usage).
|
||||||
|
|
||||||

|
## Contributing
|
||||||
|
|
||||||
Listings of your files, available in two styles: mosaic and list. You can delete, move, rename, upload and create new files, as well as directories. Single files can be downloaded directly, and multiple files as *.zip*, *.tar*, *.tar.gz*, *.tar.bz2* or *.tar.xz*.
|
Please refer to our docs at [filebrowser.xyz/contributing](https://filebrowser.xyz/contributing).
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
File Browser editor is powered by [Codemirror](https://codemirror.net/) and if you're working with markdown files with metadata, both parts will be separated from each other so you can focus on the content.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
On the settings page, a regular user can set its own custom CSS to personalize the experience and change its password. For admins, they can manage the permissions of each user, set commands which can be executed when certain events are triggered (such as before saving and after saving) and change plugin's settings.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
We also allow the users to search in the directories and execute commands if allowed.
|
|
||||||
|
|
||||||
## Users
|
|
||||||
|
|
||||||
We support multiple users and each user can have its own scope and custom stylesheet. The administrator is able to choose which permissions should be given to the users, as well as the commands they can execute. Each user also have a set of rules, in which he can be prevented or allowed to access some directories (regular expressions included!).
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Search
|
|
||||||
|
|
||||||
File Browser allows you to search through your files and it has some options. By default, your search will be something like this:
|
|
||||||
|
|
||||||
```
|
|
||||||
this are keywords
|
|
||||||
```
|
|
||||||
|
|
||||||
If you search for that it will look at every file that contains "this", "are" or "keywords" on their name. If you want to search for an exact term, you should surround your search by double quotes:
|
|
||||||
|
|
||||||
```
|
|
||||||
"this is the name"
|
|
||||||
```
|
|
||||||
|
|
||||||
That will search for any file that contains "this is the name" on its name. It won't search for each separated term this time.
|
|
||||||
|
|
||||||
By default, every search will be case insensitive. Although, you can make a case sensitive search by adding `case:sensitive` to the search terms, like this:
|
|
||||||
|
|
||||||
```
|
|
||||||
this are keywords case:sensitive
|
|
||||||
```
|
|
||||||
|
|
||||||
# Contributing
|
|
||||||
|
|
||||||
The contributing guidelines can be found [here](https://github.com/filebrowser/community).
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Auther is the authentication interface.
|
||||||
|
type Auther interface {
|
||||||
|
// Auth is called to authenticate a request.
|
||||||
|
Auth(r *http.Request, s *users.Storage, root string) (*users.User, error)
|
||||||
|
// LoginPage indicates if this auther needs a login page.
|
||||||
|
LoginPage() bool
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MethodJSONAuth is used to identify json auth.
|
||||||
|
const MethodJSONAuth settings.AuthMethod = "json"
|
||||||
|
|
||||||
|
type jsonCred struct {
|
||||||
|
Password string `json:"password"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
ReCaptcha string `json:"recaptcha"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONAuth is a json implementaion of an Auther.
|
||||||
|
type JSONAuth struct {
|
||||||
|
ReCaptcha *ReCaptcha `json:"recaptcha" yaml:"recaptcha"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth authenticates the user via a json in content body.
|
||||||
|
func (a JSONAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users.User, error) {
|
||||||
|
var cred jsonCred
|
||||||
|
|
||||||
|
if r.Body == nil {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&cred)
|
||||||
|
if err != nil {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
// If ReCaptcha is enabled, check the code.
|
||||||
|
if a.ReCaptcha != nil && len(a.ReCaptcha.Secret) > 0 {
|
||||||
|
ok, err := a.ReCaptcha.Ok(cred.ReCaptcha)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := sto.Get(root, cred.Username)
|
||||||
|
if err != nil || !users.CheckPwd(cred.Password, u.Password) {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
return u, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that json auth doesn't require a login page.
|
||||||
|
func (a JSONAuth) LoginPage() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const reCaptchaAPI = "/recaptcha/api/siteverify"
|
||||||
|
|
||||||
|
// ReCaptcha identifies a recaptcha conenction.
|
||||||
|
type ReCaptcha struct {
|
||||||
|
Host string `json:"host"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ok checks if a reCaptcha responde is correct.
|
||||||
|
func (r *ReCaptcha) Ok(response string) (bool, error) {
|
||||||
|
body := url.Values{}
|
||||||
|
body.Set("secret", r.Secret)
|
||||||
|
body.Add("response", response)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
resp, err := client.Post(
|
||||||
|
r.Host+reCaptchaAPI,
|
||||||
|
"application/x-www-form-urlencoded",
|
||||||
|
strings.NewReader(body.Encode()),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var data struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&data)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.Success, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MethodNoAuth is used to identify no auth.
|
||||||
|
const MethodNoAuth settings.AuthMethod = "noauth"
|
||||||
|
|
||||||
|
// NoAuth is no auth implementation of auther.
|
||||||
|
type NoAuth struct{}
|
||||||
|
|
||||||
|
// Auth uses authenticates user 1.
|
||||||
|
func (a NoAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users.User, error) {
|
||||||
|
return sto.Get(root, uint(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that no auth doesn't require a login page.
|
||||||
|
func (a NoAuth) LoginPage() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/errors"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MethodProxyAuth is used to identify no auth.
|
||||||
|
const MethodProxyAuth settings.AuthMethod = "proxy"
|
||||||
|
|
||||||
|
// ProxyAuth is a proxy implementation of an auther.
|
||||||
|
type ProxyAuth struct {
|
||||||
|
Header string `json:"header"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth authenticates the user via an HTTP header.
|
||||||
|
func (a ProxyAuth) Auth(r *http.Request, sto *users.Storage, root string) (*users.User, error) {
|
||||||
|
username := r.Header.Get(a.Header)
|
||||||
|
user, err := sto.Get(root, username)
|
||||||
|
if err == errors.ErrNotExist {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
return user, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginPage tells that proxy auth doesn't require a login page.
|
||||||
|
func (a ProxyAuth) LoginPage() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StorageBackend is a storage backend for auth storage.
|
||||||
|
type StorageBackend interface {
|
||||||
|
Get(settings.AuthMethod) (Auther, error)
|
||||||
|
Save(Auther) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage is a auth storage.
|
||||||
|
type Storage struct {
|
||||||
|
back StorageBackend
|
||||||
|
users *users.Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewStorage creates a auth storage from a backend.
|
||||||
|
func NewStorage(back StorageBackend, users *users.Storage) *Storage {
|
||||||
|
return &Storage{back: back, users: users}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get wraps a StorageBackend.Get.
|
||||||
|
func (s *Storage) Get(t settings.AuthMethod) (Auther, error) {
|
||||||
|
return s.back.Get(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save wraps a StorageBackend.Save.
|
||||||
|
func (s *Storage) Save(a Auther) error {
|
||||||
|
return s.back.Save(a)
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package bolt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
fb "github.com/filebrowser/filebrowser"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ConfigStore is a configuration store.
|
|
||||||
type ConfigStore struct {
|
|
||||||
DB *storm.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets a configuration from the database to an interface.
|
|
||||||
func (c ConfigStore) Get(name string, to interface{}) error {
|
|
||||||
err := c.DB.Get("config", name, to)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return fb.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save saves a configuration from an interface to the database.
|
|
||||||
func (c ConfigStore) Save(name string, from interface{}) error {
|
|
||||||
return c.DB.Set("config", name, from)
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package bolt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
"github.com/asdine/storm/q"
|
|
||||||
fb "github.com/filebrowser/filebrowser"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ShareStore is a shareable links store.
|
|
||||||
type ShareStore struct {
|
|
||||||
DB *storm.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets a Share Link from an hash.
|
|
||||||
func (s ShareStore) Get(hash string) (*fb.ShareLink, error) {
|
|
||||||
var v fb.ShareLink
|
|
||||||
err := s.DB.One("Hash", hash, &v)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return nil, fb.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPermanent gets the permanent link from a path.
|
|
||||||
func (s ShareStore) GetPermanent(path string) (*fb.ShareLink, error) {
|
|
||||||
var v fb.ShareLink
|
|
||||||
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return nil, fb.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetByPath gets all the links for a specific path.
|
|
||||||
func (s ShareStore) GetByPath(hash string) ([]*fb.ShareLink, error) {
|
|
||||||
var v []*fb.ShareLink
|
|
||||||
err := s.DB.Find("Path", hash, &v)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return v, fb.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets retrieves all the shareable links.
|
|
||||||
func (s ShareStore) Gets() ([]*fb.ShareLink, error) {
|
|
||||||
var v []*fb.ShareLink
|
|
||||||
err := s.DB.All(&v)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return v, fb.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save stores a Share Link on the database.
|
|
||||||
func (s ShareStore) Save(l *fb.ShareLink) error {
|
|
||||||
return s.DB.Save(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes a Share Link from the database.
|
|
||||||
func (s ShareStore) Delete(hash string) error {
|
|
||||||
return s.DB.DeleteStruct(&fb.ShareLink{Hash: hash})
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package bolt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
fm "github.com/filebrowser/filebrowser"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UsersStore is a users store.
|
|
||||||
type UsersStore struct {
|
|
||||||
DB *storm.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets a user with a certain id from the database.
|
|
||||||
func (u UsersStore) Get(id int, builder fm.FSBuilder) (*fm.User, error) {
|
|
||||||
var us fm.User
|
|
||||||
err := u.DB.One("ID", id, &us)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return nil, fm.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
us.FileSystem = builder(us.Scope)
|
|
||||||
return &us, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetByUsername gets a user with a certain username from the database.
|
|
||||||
func (u UsersStore) GetByUsername(username string, builder fm.FSBuilder) (*fm.User, error) {
|
|
||||||
var us fm.User
|
|
||||||
err := u.DB.One("Username", username, &us)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return nil, fm.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
us.FileSystem = builder(us.Scope)
|
|
||||||
return &us, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets gets all the users from the database.
|
|
||||||
func (u UsersStore) Gets(builder fm.FSBuilder) ([]*fm.User, error) {
|
|
||||||
var us []*fm.User
|
|
||||||
err := u.DB.All(&us)
|
|
||||||
if err == storm.ErrNotFound {
|
|
||||||
return nil, fm.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return us, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, user := range us {
|
|
||||||
user.FileSystem = builder(user.Scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
return us, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update updates the whole user object or only certain fields.
|
|
||||||
func (u UsersStore) Update(us *fm.User, fields ...string) error {
|
|
||||||
if len(fields) == 0 {
|
|
||||||
return u.Save(us)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, field := range fields {
|
|
||||||
val := reflect.ValueOf(us).Elem().FieldByName(field).Interface()
|
|
||||||
if err := u.DB.UpdateField(us, field, val); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save saves a user to the database.
|
|
||||||
func (u UsersStore) Save(us *fm.User) error {
|
|
||||||
return u.DB.Save(us)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes a user from the database.
|
|
||||||
func (u UsersStore) Delete(id int) error {
|
|
||||||
return u.DB.DeleteStruct(&fm.User{ID: id})
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
dep ensure -vendor-only
|
|
||||||
|
|
||||||
cd cmd/filebrowser
|
|
||||||
CGO_ENABLED=0 go build -a
|
|
||||||
cd ../..
|
|
||||||
cp cmd/filebrowser/filebrowser ./
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
if [ -d "rice-box.go" ]; then
|
|
||||||
rm -rf rice-box.go
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$USE_DOCKER" != "" ]; then
|
|
||||||
if [ -d "frontend/dist" ]; then
|
|
||||||
rm -rf frontend/dist
|
|
||||||
fi;
|
|
||||||
|
|
||||||
if [ "$WDIR" = "" ]; then
|
|
||||||
WDIR="/go/src/github.com/filebrowser/filebrowser"
|
|
||||||
fi;
|
|
||||||
|
|
||||||
$(command -v winpty) docker run -it \
|
|
||||||
--name filebrowser-tmp \
|
|
||||||
-v /$(pwd):/src:z \
|
|
||||||
-w /${WDIR} \
|
|
||||||
filebrowser/dev \
|
|
||||||
sh -c "\
|
|
||||||
cp -r //src/* /$WDIR && \
|
|
||||||
cd build && \
|
|
||||||
dos2unix build_assets.sh && \
|
|
||||||
dos2unix build.sh && \
|
|
||||||
./build_assets.sh && \
|
|
||||||
./build.sh \
|
|
||||||
"
|
|
||||||
exitcode=$?
|
|
||||||
|
|
||||||
if [ $exitcode -eq 0 ]; then
|
|
||||||
for d in "dist/" "node_modules/"; do
|
|
||||||
docker cp filebrowser-tmp:/$WDIR/frontend/$d frontend
|
|
||||||
done
|
|
||||||
for d in "vendor/" "rice-box.go" "filebrowser"; do
|
|
||||||
docker cp filebrowser-tmp:/$WDIR/$d ./
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
docker rm -f filebrowser-tmp
|
|
||||||
else
|
|
||||||
./build/build_assets.sh
|
|
||||||
./build/build.sh
|
|
||||||
fi
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
# Clean the dist folder and build the assets
|
|
||||||
cd frontend
|
|
||||||
if [ -d "dist" ]; then
|
|
||||||
rm -rf dist/*
|
|
||||||
fi;
|
|
||||||
yarn install
|
|
||||||
yarn build
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# Install rice tool if not present
|
|
||||||
if ! [ -x "$(command -v rice)" ]; then
|
|
||||||
go get github.com/GeertJohan/go.rice/rice
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Embed the assets using rice
|
|
||||||
rice embed-go
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# init key for pass
|
|
||||||
gpg --batch --gen-key <<-EOF
|
|
||||||
%echo Generating a standard key
|
|
||||||
Key-Type: DSA
|
|
||||||
Key-Length: 1024
|
|
||||||
Subkey-Type: ELG-E
|
|
||||||
Subkey-Length: 1024
|
|
||||||
Name-Real: Meshuggah Rocks
|
|
||||||
Name-Email: meshuggah@example.com
|
|
||||||
Expire-Date: 0
|
|
||||||
# Do a commit here, so that we can later print "done" :-)
|
|
||||||
%commit
|
|
||||||
%echo done
|
|
||||||
EOF
|
|
||||||
|
|
||||||
key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1)
|
|
||||||
pass init $key
|
|
||||||
|
|
||||||
if [ "$(command -v docker-credential-pass)" = "" ]; then
|
|
||||||
docker run --rm -itv /usr/local/bin:/src filebrowser/dev sh -c "cp /go/bin/docker-credential-pass /src"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#! /bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)
|
|
||||||
|
|
||||||
./docker_login.sh
|
|
||||||
|
|
||||||
for tag in `echo $(docker images filebrowser/filebrowser* | awk -F ' ' '{print $1 ":" $2}') | cut -d ' ' -f2-`; do
|
|
||||||
if [ "$tag" = "REPOSITORY:TAG" ]; then break; fi
|
|
||||||
docker push $tag
|
|
||||||
done
|
|
||||||
|
|
||||||
docker logout
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)
|
|
||||||
|
|
||||||
COMMIT_SHA="$(git rev-parse --verify HEAD | cut -c1-8)"
|
|
||||||
|
|
||||||
eval `ssh-agent -s`
|
|
||||||
openssl aes-256-cbc -K $encrypted_9ca81b5594f5_key -iv $encrypted_9ca81b5594f5_iv -in ./deploy_key.enc -d | ssh-add -
|
|
||||||
|
|
||||||
git clone git@github.com:filebrowser/caddy caddy
|
|
||||||
cd caddy
|
|
||||||
cp ../../rice-box.go assets/
|
|
||||||
git checkout -b update-rice-box origin/master
|
|
||||||
git commit -am "update rice-box $COMMIT_SHA"
|
|
||||||
|
|
||||||
if [ $(git tag | grep "$TRAVIS_TAG" | wc -l) -ne 0 ]; then
|
|
||||||
git tag -d "$TRAVIS_TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
git tag "$TRAVIS_TAG"
|
|
||||||
|
|
||||||
if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then
|
|
||||||
git push -u origin update-rice-box
|
|
||||||
else
|
|
||||||
git push origin +update-rice-box
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then
|
|
||||||
git push origin "$TRAVIS_TAG"
|
|
||||||
else
|
|
||||||
git push origin :"$TRAVIS_TAG"
|
|
||||||
git push origin "$TRAVIS_TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
echo "> Checking semver format"
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "This release script requires a single argument corresponding to the semver to be released. See semver.org"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
semver=$(grep -P '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' <<< "$1")
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Not valid semver format. See semver.org"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "> Checking matching $semver in frontend submodule"
|
|
||||||
|
|
||||||
cd frontend
|
|
||||||
git fetch --all
|
|
||||||
|
|
||||||
if [ $(git tag | grep "$semver" | wc -l) -eq 0 ]; then
|
|
||||||
echo "Tag $semver does not exist in submodule 'frontend'. Tag it and run this script again."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
git rev-parse --verify --quiet release
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
git checkout -b release "$semver"
|
|
||||||
else
|
|
||||||
git checkout release
|
|
||||||
git reset --hard "$semver"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
echo "> Updating submodule ref to $semver"
|
|
||||||
|
|
||||||
sed -i "s|(untracked)|$1|g" filebrowser.go
|
|
||||||
git commit -am "chore: version $semver"
|
|
||||||
git tag "$1"
|
|
||||||
git push
|
|
||||||
git push --tags
|
|
||||||
|
|
||||||
echo "> Commiting untracked version notice..."
|
|
||||||
|
|
||||||
sed -i "s|$1|(untracked)|g" filebrowser.go
|
|
||||||
git commit -am "chore: setting untracked version [ci skip]"
|
|
||||||
git push
|
|
||||||
|
|
||||||
echo "> Done!"
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
dolint='gometalinter --exclude="rice-box.go" --exclude="vendor" --deadline=300s ./...'
|
|
||||||
|
|
||||||
if [ "$USE_DOCKER" != "" ]; then
|
|
||||||
docker run --rm -itv $(pwd):/src filebrowser/dev sh -c "\
|
|
||||||
cp -r /src/. ./ && dep ensure -v -vendor-only && \
|
|
||||||
CGO_ENABLED=0 $dolint"
|
|
||||||
else
|
|
||||||
$dolint
|
|
||||||
fi
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Execute executes the commands.
|
||||||
|
func Execute() {
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(cmdsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdsCmd = &cobra.Command{
|
||||||
|
Use: "cmds",
|
||||||
|
Short: "Command runner management utility",
|
||||||
|
Long: `Command runner management utility.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
func printEvents(m map[string][]string) {
|
||||||
|
for evt, cmds := range m {
|
||||||
|
for i, cmd := range cmds {
|
||||||
|
fmt.Printf("%s(%d): %s\n", evt, i, cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmdsCmd.AddCommand(cmdsAddCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdsAddCmd = &cobra.Command{
|
||||||
|
Use: "add <event> <command>",
|
||||||
|
Short: "Add a command to run on a specific event",
|
||||||
|
Long: `Add a command to run on a specific event.`,
|
||||||
|
Args: cobra.MinimumNArgs(2),
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
s, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
command := strings.Join(args[1:], " ")
|
||||||
|
s.Commands[args[0]] = append(s.Commands[args[0]], command)
|
||||||
|
err = d.store.Settings.Save(s)
|
||||||
|
checkErr(err)
|
||||||
|
printEvents(s.Commands)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmdsCmd.AddCommand(cmdsLsCmd)
|
||||||
|
cmdsLsCmd.Flags().StringP("event", "e", "", "event name, without 'before' or 'after'")
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdsLsCmd = &cobra.Command{
|
||||||
|
Use: "ls",
|
||||||
|
Short: "List all commands for each event",
|
||||||
|
Long: `List all commands for each event.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
s, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
evt := mustGetString(cmd.Flags(), "event")
|
||||||
|
|
||||||
|
if evt == "" {
|
||||||
|
printEvents(s.Commands)
|
||||||
|
} else {
|
||||||
|
show := map[string][]string{}
|
||||||
|
show["before_"+evt] = s.Commands["before_"+evt]
|
||||||
|
show["after_"+evt] = s.Commands["after_"+evt]
|
||||||
|
printEvents(show)
|
||||||
|
}
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmdsCmd.AddCommand(cmdsRmCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdsRmCmd = &cobra.Command{
|
||||||
|
Use: "rm <event> <index> [index_end]",
|
||||||
|
Short: "Removes a command from an event hooker",
|
||||||
|
Long: `Removes a command from an event hooker. The provided index
|
||||||
|
is the same that's printed when you run 'cmds ls'. Note
|
||||||
|
that after each removal/addition, the index of the
|
||||||
|
commands change. So be careful when removing them after each
|
||||||
|
other.
|
||||||
|
|
||||||
|
You can also specify an optional parameter (index_end) so
|
||||||
|
you can remove all commands from 'index' to 'index_end',
|
||||||
|
including 'index_end'.`,
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if err := cobra.RangeArgs(2, 3)(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, arg := range args[1:] {
|
||||||
|
if _, err := strconv.Atoi(arg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
s, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
evt := args[0]
|
||||||
|
|
||||||
|
i, err := strconv.Atoi(args[1])
|
||||||
|
checkErr(err)
|
||||||
|
f := i
|
||||||
|
if len(args) == 3 {
|
||||||
|
f, err = strconv.Atoi(args[2])
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Commands[evt] = append(s.Commands[evt][:i], s.Commands[evt][f+1:]...)
|
||||||
|
err = d.store.Settings.Save(s)
|
||||||
|
checkErr(err)
|
||||||
|
printEvents(s.Commands)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
nerrors "errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/auth"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/errors"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(configCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var configCmd = &cobra.Command{
|
||||||
|
Use: "config",
|
||||||
|
Short: "Configuration management utility",
|
||||||
|
Long: `Configuration management utility.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
func addConfigFlags(flags *pflag.FlagSet) {
|
||||||
|
addServerFlags(flags)
|
||||||
|
addUserFlags(flags)
|
||||||
|
flags.BoolP("signup", "s", false, "allow users to signup")
|
||||||
|
flags.String("shell", "", "shell command to which other commands should be appended")
|
||||||
|
|
||||||
|
flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
|
||||||
|
flags.String("auth.header", "", "HTTP header for auth.method=proxy")
|
||||||
|
|
||||||
|
flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
|
||||||
|
flags.String("recaptcha.key", "", "ReCaptcha site key")
|
||||||
|
flags.String("recaptcha.secret", "", "ReCaptcha secret")
|
||||||
|
|
||||||
|
flags.String("branding.name", "", "replace 'File Browser' by this name")
|
||||||
|
flags.String("branding.files", "", "path to directory with images and custom styles")
|
||||||
|
flags.Bool("branding.disableExternal", false, "disable external links such as GitHub links")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.AuthMethod, auth.Auther) {
|
||||||
|
method := settings.AuthMethod(mustGetString(flags, "auth.method"))
|
||||||
|
|
||||||
|
var defaultAuther map[string]interface{}
|
||||||
|
if len(defaults) > 0 {
|
||||||
|
if hasAuth := defaults[0]; hasAuth != true {
|
||||||
|
for _, arg := range defaults {
|
||||||
|
switch def := arg.(type) {
|
||||||
|
case *settings.Settings:
|
||||||
|
method = settings.AuthMethod(def.AuthMethod)
|
||||||
|
case auth.Auther:
|
||||||
|
ms, err := json.Marshal(def)
|
||||||
|
checkErr(err)
|
||||||
|
json.Unmarshal(ms, &defaultAuther)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var auther auth.Auther
|
||||||
|
if method == auth.MethodProxyAuth {
|
||||||
|
header := mustGetString(flags, "auth.header")
|
||||||
|
|
||||||
|
if header == "" {
|
||||||
|
header = defaultAuther["header"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if header == "" {
|
||||||
|
checkErr(nerrors.New("you must set the flag 'auth.header' for method 'proxy'"))
|
||||||
|
}
|
||||||
|
|
||||||
|
auther = &auth.ProxyAuth{Header: header}
|
||||||
|
}
|
||||||
|
|
||||||
|
if method == auth.MethodNoAuth {
|
||||||
|
auther = &auth.NoAuth{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if method == auth.MethodJSONAuth {
|
||||||
|
jsonAuth := &auth.JSONAuth{}
|
||||||
|
host := mustGetString(flags, "recaptcha.host")
|
||||||
|
key := mustGetString(flags, "recaptcha.key")
|
||||||
|
secret := mustGetString(flags, "recaptcha.secret")
|
||||||
|
|
||||||
|
if key == "" {
|
||||||
|
if kmap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
|
||||||
|
key = kmap["key"].(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if secret == "" {
|
||||||
|
if smap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
|
||||||
|
secret = smap["secret"].(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if key != "" && secret != "" {
|
||||||
|
jsonAuth.ReCaptcha = &auth.ReCaptcha{
|
||||||
|
Host: host,
|
||||||
|
Key: key,
|
||||||
|
Secret: secret,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auther = jsonAuth
|
||||||
|
}
|
||||||
|
|
||||||
|
if auther == nil {
|
||||||
|
panic(errors.ErrInvalidAuthMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
return method, auther
|
||||||
|
}
|
||||||
|
|
||||||
|
func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Auther) {
|
||||||
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "Sign up:\t%t\n", set.Signup)
|
||||||
|
fmt.Fprintf(w, "Create User Dir:\t%t\n", set.CreateUserDir)
|
||||||
|
fmt.Fprintf(w, "Auth method:\t%s\n", set.AuthMethod)
|
||||||
|
fmt.Fprintf(w, "Shell:\t%s\t\n", strings.Join(set.Shell, " "))
|
||||||
|
fmt.Fprintln(w, "\nBranding:")
|
||||||
|
fmt.Fprintf(w, "\tName:\t%s\n", set.Branding.Name)
|
||||||
|
fmt.Fprintf(w, "\tFiles override:\t%s\n", set.Branding.Files)
|
||||||
|
fmt.Fprintf(w, "\tDisable external links:\t%t\n", set.Branding.DisableExternal)
|
||||||
|
fmt.Fprintln(w, "\nServer:")
|
||||||
|
fmt.Fprintf(w, "\tLog:\t%s\n", ser.Log)
|
||||||
|
fmt.Fprintf(w, "\tPort:\t%s\n", ser.Port)
|
||||||
|
fmt.Fprintf(w, "\tBase URL:\t%s\n", ser.BaseURL)
|
||||||
|
fmt.Fprintf(w, "\tRoot:\t%s\n", ser.Root)
|
||||||
|
fmt.Fprintf(w, "\tSocket:\t%s\n", ser.Socket)
|
||||||
|
fmt.Fprintf(w, "\tAddress:\t%s\n", ser.Address)
|
||||||
|
fmt.Fprintf(w, "\tTLS Cert:\t%s\n", ser.TLSCert)
|
||||||
|
fmt.Fprintf(w, "\tTLS Key:\t%s\n", ser.TLSKey)
|
||||||
|
fmt.Fprintln(w, "\nDefaults:")
|
||||||
|
fmt.Fprintf(w, "\tScope:\t%s\n", set.Defaults.Scope)
|
||||||
|
fmt.Fprintf(w, "\tLocale:\t%s\n", set.Defaults.Locale)
|
||||||
|
fmt.Fprintf(w, "\tView mode:\t%s\n", set.Defaults.ViewMode)
|
||||||
|
fmt.Fprintf(w, "\tCommands:\t%s\n", strings.Join(set.Defaults.Commands, " "))
|
||||||
|
fmt.Fprintf(w, "\tSorting:\n")
|
||||||
|
fmt.Fprintf(w, "\t\tBy:\t%s\n", set.Defaults.Sorting.By)
|
||||||
|
fmt.Fprintf(w, "\t\tAsc:\t%t\n", set.Defaults.Sorting.Asc)
|
||||||
|
fmt.Fprintf(w, "\tPermissions:\n")
|
||||||
|
fmt.Fprintf(w, "\t\tAdmin:\t%t\n", set.Defaults.Perm.Admin)
|
||||||
|
fmt.Fprintf(w, "\t\tExecute:\t%t\n", set.Defaults.Perm.Execute)
|
||||||
|
fmt.Fprintf(w, "\t\tCreate:\t%t\n", set.Defaults.Perm.Create)
|
||||||
|
fmt.Fprintf(w, "\t\tRename:\t%t\n", set.Defaults.Perm.Rename)
|
||||||
|
fmt.Fprintf(w, "\t\tModify:\t%t\n", set.Defaults.Perm.Modify)
|
||||||
|
fmt.Fprintf(w, "\t\tDelete:\t%t\n", set.Defaults.Perm.Delete)
|
||||||
|
fmt.Fprintf(w, "\t\tShare:\t%t\n", set.Defaults.Perm.Share)
|
||||||
|
fmt.Fprintf(w, "\t\tDownload:\t%t\n", set.Defaults.Perm.Download)
|
||||||
|
w.Flush()
|
||||||
|
|
||||||
|
b, err := json.MarshalIndent(auther, "", " ")
|
||||||
|
checkErr(err)
|
||||||
|
fmt.Printf("\nAuther configuration (raw):\n\n%s\n\n", string(b))
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
configCmd.AddCommand(configCatCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var configCatCmd = &cobra.Command{
|
||||||
|
Use: "cat",
|
||||||
|
Short: "Prints the configuration",
|
||||||
|
Long: `Prints the configuration.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
set, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
ser, err := d.store.Settings.GetServer()
|
||||||
|
checkErr(err)
|
||||||
|
auther, err := d.store.Auth.Get(set.AuthMethod)
|
||||||
|
checkErr(err)
|
||||||
|
printSettings(ser, set, auther)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
configCmd.AddCommand(configExportCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var configExportCmd = &cobra.Command{
|
||||||
|
Use: "export <path>",
|
||||||
|
Short: "Export the configuration to a file",
|
||||||
|
Long: `Export the configuration to a file. The path must be for a
|
||||||
|
json or yaml file. This exported configuration can be changed,
|
||||||
|
and imported again with 'config import' command.`,
|
||||||
|
Args: jsonYamlArg,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
settings, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
server, err := d.store.Settings.GetServer()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
auther, err := d.store.Auth.Get(settings.AuthMethod)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
data := &settingsFile{
|
||||||
|
Settings: settings,
|
||||||
|
Auther: auther,
|
||||||
|
Server: server,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = marshal(args[0], data)
|
||||||
|
checkErr(err)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/auth"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
configCmd.AddCommand(configImportCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type settingsFile struct {
|
||||||
|
Settings *settings.Settings `json:"settings"`
|
||||||
|
Server *settings.Server `json:"server"`
|
||||||
|
Auther interface{} `json:"auther"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var configImportCmd = &cobra.Command{
|
||||||
|
Use: "import <path>",
|
||||||
|
Short: "Import a configuration file",
|
||||||
|
Long: `Import a configuration file. This will replace all the existing
|
||||||
|
configuration. Can be used with or without unexisting databases.
|
||||||
|
|
||||||
|
If used with a nonexisting database, a key will be generated
|
||||||
|
automatically. Otherwise the key will be kept the same as in the
|
||||||
|
database.
|
||||||
|
|
||||||
|
The path must be for a json or yaml file.`,
|
||||||
|
Args: jsonYamlArg,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
var key []byte
|
||||||
|
if d.hadDB {
|
||||||
|
settings, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
key = settings.Key
|
||||||
|
} else {
|
||||||
|
key = generateKey()
|
||||||
|
}
|
||||||
|
|
||||||
|
file := settingsFile{}
|
||||||
|
err := unmarshal(args[0], &file)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
file.Settings.Key = key
|
||||||
|
err = d.store.Settings.Save(file.Settings)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
err = d.store.Settings.SaveServer(file.Server)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
var rawAuther interface{}
|
||||||
|
if filepath.Ext(args[0]) != ".json" {
|
||||||
|
rawAuther = cleanUpInterfaceMap(file.Auther.(map[interface{}]interface{}))
|
||||||
|
} else {
|
||||||
|
rawAuther = file.Auther
|
||||||
|
}
|
||||||
|
|
||||||
|
var auther auth.Auther
|
||||||
|
switch file.Settings.AuthMethod {
|
||||||
|
case auth.MethodJSONAuth:
|
||||||
|
auther = getAuther(auth.JSONAuth{}, rawAuther).(*auth.JSONAuth)
|
||||||
|
case auth.MethodNoAuth:
|
||||||
|
auther = getAuther(auth.NoAuth{}, rawAuther).(*auth.NoAuth)
|
||||||
|
case auth.MethodProxyAuth:
|
||||||
|
auther = getAuther(auth.ProxyAuth{}, rawAuther).(*auth.ProxyAuth)
|
||||||
|
default:
|
||||||
|
checkErr(errors.New("invalid auth method"))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.store.Auth.Save(auther)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
printSettings(file.Server, file.Settings, auther)
|
||||||
|
}, pythonConfig{allowNoDB: true}),
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAuther(sample auth.Auther, data interface{}) interface{} {
|
||||||
|
authType := reflect.TypeOf(sample)
|
||||||
|
auther := reflect.New(authType).Interface()
|
||||||
|
bytes, err := json.Marshal(data)
|
||||||
|
checkErr(err)
|
||||||
|
err = json.Unmarshal(bytes, &auther)
|
||||||
|
checkErr(err)
|
||||||
|
return auther
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
configCmd.AddCommand(configInitCmd)
|
||||||
|
addConfigFlags(configInitCmd.Flags())
|
||||||
|
}
|
||||||
|
|
||||||
|
var configInitCmd = &cobra.Command{
|
||||||
|
Use: "init",
|
||||||
|
Short: "Initialize a new database",
|
||||||
|
Long: `Initialize a new database to use with File Browser. All of
|
||||||
|
this options can be changed in the future with the command
|
||||||
|
'filebrowser config set'. The user related flags apply
|
||||||
|
to the defaults when creating new users and you don't
|
||||||
|
override the options.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
defaults := settings.UserDefaults{}
|
||||||
|
flags := cmd.Flags()
|
||||||
|
getUserDefaults(flags, &defaults, true)
|
||||||
|
authMethod, auther := getAuthentication(flags)
|
||||||
|
|
||||||
|
s := &settings.Settings{
|
||||||
|
Key: generateKey(),
|
||||||
|
Signup: mustGetBool(flags, "signup"),
|
||||||
|
Shell: strings.Split(strings.TrimSpace(mustGetString(flags, "shell")), " "),
|
||||||
|
AuthMethod: authMethod,
|
||||||
|
Defaults: defaults,
|
||||||
|
Branding: settings.Branding{
|
||||||
|
Name: mustGetString(flags, "branding.name"),
|
||||||
|
DisableExternal: mustGetBool(flags, "branding.disableExternal"),
|
||||||
|
Files: mustGetString(flags, "branding.files"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ser := &settings.Server{
|
||||||
|
Address: mustGetString(flags, "address"),
|
||||||
|
Socket: mustGetString(flags, "socket"),
|
||||||
|
Root: mustGetString(flags, "root"),
|
||||||
|
BaseURL: mustGetString(flags, "baseurl"),
|
||||||
|
TLSKey: mustGetString(flags, "key"),
|
||||||
|
TLSCert: mustGetString(flags, "cert"),
|
||||||
|
Port: mustGetString(flags, "port"),
|
||||||
|
Log: mustGetString(flags, "log"),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := d.store.Settings.Save(s)
|
||||||
|
checkErr(err)
|
||||||
|
err = d.store.Settings.SaveServer(ser)
|
||||||
|
checkErr(err)
|
||||||
|
err = d.store.Auth.Save(auther)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
fmt.Printf(`
|
||||||
|
Congratulations! You've set up your database to use with File Browser.
|
||||||
|
Now add your first user via 'filebrowser users new' and then you just
|
||||||
|
need to call the main command to boot up the server.
|
||||||
|
`)
|
||||||
|
printSettings(ser, s, auther)
|
||||||
|
}, pythonConfig{noDB: true}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
configCmd.AddCommand(configSetCmd)
|
||||||
|
addConfigFlags(configSetCmd.Flags())
|
||||||
|
}
|
||||||
|
|
||||||
|
var configSetCmd = &cobra.Command{
|
||||||
|
Use: "set",
|
||||||
|
Short: "Updates the configuration",
|
||||||
|
Long: `Updates the configuration. Set the flags for the options
|
||||||
|
you want to change. Other options will remain unchanged.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
flags := cmd.Flags()
|
||||||
|
set, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
ser, err := d.store.Settings.GetServer()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
hasAuth := false
|
||||||
|
flags.Visit(func(flag *pflag.Flag) {
|
||||||
|
switch flag.Name {
|
||||||
|
case "baseurl":
|
||||||
|
ser.BaseURL = mustGetString(flags, flag.Name)
|
||||||
|
case "root":
|
||||||
|
ser.Root = mustGetString(flags, flag.Name)
|
||||||
|
case "socket":
|
||||||
|
ser.Socket = mustGetString(flags, flag.Name)
|
||||||
|
case "cert":
|
||||||
|
ser.TLSCert = mustGetString(flags, flag.Name)
|
||||||
|
case "key":
|
||||||
|
ser.TLSKey = mustGetString(flags, flag.Name)
|
||||||
|
case "address":
|
||||||
|
ser.Address = mustGetString(flags, flag.Name)
|
||||||
|
case "port":
|
||||||
|
ser.Port = mustGetString(flags, flag.Name)
|
||||||
|
case "log":
|
||||||
|
ser.Log = mustGetString(flags, flag.Name)
|
||||||
|
case "signup":
|
||||||
|
set.Signup = mustGetBool(flags, flag.Name)
|
||||||
|
case "auth.method":
|
||||||
|
hasAuth = true
|
||||||
|
case "shell":
|
||||||
|
set.Shell = strings.Split(strings.TrimSpace(mustGetString(flags, flag.Name)), " ")
|
||||||
|
case "branding.name":
|
||||||
|
set.Branding.Name = mustGetString(flags, flag.Name)
|
||||||
|
case "branding.disableExternal":
|
||||||
|
set.Branding.DisableExternal = mustGetBool(flags, flag.Name)
|
||||||
|
case "branding.files":
|
||||||
|
set.Branding.Files = mustGetString(flags, flag.Name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
getUserDefaults(flags, &set.Defaults, false)
|
||||||
|
|
||||||
|
// read the defaults
|
||||||
|
auther, err := d.store.Auth.Get(set.AuthMethod)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
// check if there are new flags for existing auth method
|
||||||
|
set.AuthMethod, auther = getAuthentication(flags, hasAuth, set, auther)
|
||||||
|
|
||||||
|
err = d.store.Auth.Save(auther)
|
||||||
|
checkErr(err)
|
||||||
|
err = d.store.Settings.Save(set)
|
||||||
|
checkErr(err)
|
||||||
|
err = d.store.Settings.SaveServer(ser)
|
||||||
|
checkErr(err)
|
||||||
|
printSettings(ser, set, auther)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(docsCmd)
|
||||||
|
docsCmd.Flags().StringP("path", "p", "./docs", "path to save the docs")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printToc(names []string) {
|
||||||
|
for i, name := range names {
|
||||||
|
name = strings.TrimSuffix(name, filepath.Ext(name))
|
||||||
|
name = strings.Replace(name, "-", " ", -1)
|
||||||
|
names[i] = name
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(names)
|
||||||
|
|
||||||
|
toc := ""
|
||||||
|
for _, name := range names {
|
||||||
|
toc += "* [" + name + "](cli/" + strings.Replace(name, " ", "-", -1) + ".md)\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(toc)
|
||||||
|
}
|
||||||
|
|
||||||
|
var docsCmd = &cobra.Command{
|
||||||
|
Use: "docs",
|
||||||
|
Hidden: true,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
dir := mustGetString(cmd.Flags(), "path")
|
||||||
|
generateDocs(rootCmd, dir)
|
||||||
|
names := []string{}
|
||||||
|
|
||||||
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil || info.IsDir() {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(info.Name(), "filebrowser") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
names = append(names, info.Name())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
checkErr(err)
|
||||||
|
printToc(names)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateDocs(cmd *cobra.Command, dir string) {
|
||||||
|
for _, c := range cmd.Commands() {
|
||||||
|
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
generateDocs(c, dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
basename := strings.Replace(cmd.CommandPath(), " ", "-", -1) + ".md"
|
||||||
|
filename := filepath.Join(dir, basename)
|
||||||
|
f, err := os.Create(filename)
|
||||||
|
checkErr(err)
|
||||||
|
defer f.Close()
|
||||||
|
generateMarkdown(cmd, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateMarkdown(cmd *cobra.Command, w io.Writer) {
|
||||||
|
cmd.InitDefaultHelpCmd()
|
||||||
|
cmd.InitDefaultHelpFlag()
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
name := cmd.CommandPath()
|
||||||
|
|
||||||
|
short := cmd.Short
|
||||||
|
long := cmd.Long
|
||||||
|
if len(long) == 0 {
|
||||||
|
long = short
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.WriteString("---\ndescription: " + short + "\n---\n\n")
|
||||||
|
buf.WriteString("# " + name + "\n\n")
|
||||||
|
buf.WriteString("## Synopsis\n\n")
|
||||||
|
buf.WriteString(long + "\n\n")
|
||||||
|
|
||||||
|
if cmd.Runnable() {
|
||||||
|
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.UseLine()))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cmd.Example) > 0 {
|
||||||
|
buf.WriteString("## Examples\n\n")
|
||||||
|
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.Example))
|
||||||
|
}
|
||||||
|
|
||||||
|
printOptions(buf, cmd, name)
|
||||||
|
_, err := buf.WriteTo(w)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateFlagsTable(fs *pflag.FlagSet, buf io.StringWriter) {
|
||||||
|
buf.WriteString("| Name | Shorthand | Usage |\n")
|
||||||
|
buf.WriteString("|------|-----------|-------|\n")
|
||||||
|
|
||||||
|
fs.VisitAll(func(f *pflag.Flag) {
|
||||||
|
buf.WriteString("|" + f.Name + "|" + f.Shorthand + "|" + f.Usage + "|\n")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) {
|
||||||
|
flags := cmd.NonInheritedFlags()
|
||||||
|
flags.SetOutput(buf)
|
||||||
|
if flags.HasAvailableFlags() {
|
||||||
|
buf.WriteString("## Options\n\n")
|
||||||
|
generateFlagsTable(flags, buf)
|
||||||
|
buf.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
parentFlags := cmd.InheritedFlags()
|
||||||
|
parentFlags.SetOutput(buf)
|
||||||
|
if parentFlags.HasAvailableFlags() {
|
||||||
|
buf.WriteString("### Inherited\n\n")
|
||||||
|
generateFlagsTable(parentFlags, buf)
|
||||||
|
buf.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,279 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
"github.com/filebrowser/filebrowser"
|
|
||||||
"github.com/filebrowser/filebrowser/bolt"
|
|
||||||
h "github.com/filebrowser/filebrowser/http"
|
|
||||||
"github.com/filebrowser/filebrowser/staticgen"
|
|
||||||
"github.com/hacdias/fileutils"
|
|
||||||
flag "github.com/spf13/pflag"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings")
|
|
||||||
|
|
||||||
var (
|
|
||||||
addr string
|
|
||||||
config string
|
|
||||||
database string
|
|
||||||
scope string
|
|
||||||
commands string
|
|
||||||
logfile string
|
|
||||||
staticg string
|
|
||||||
locale string
|
|
||||||
baseurl string
|
|
||||||
prefixurl string
|
|
||||||
viewMode string
|
|
||||||
recaptchakey string
|
|
||||||
recaptchasecret string
|
|
||||||
port int
|
|
||||||
auth struct {
|
|
||||||
method string
|
|
||||||
loginHeader string
|
|
||||||
}
|
|
||||||
noAuth bool
|
|
||||||
allowCommands bool
|
|
||||||
allowEdit bool
|
|
||||||
allowNew bool
|
|
||||||
allowPublish bool
|
|
||||||
showVer bool
|
|
||||||
alterRecaptcha bool
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.StringVarP(&config, "config", "c", "", "Configuration file")
|
|
||||||
flag.IntVarP(&port, "port", "p", 0, "HTTP Port (default is random)")
|
|
||||||
flag.StringVarP(&addr, "address", "a", "", "Address to listen to (default is all of them)")
|
|
||||||
flag.StringVarP(&database, "database", "d", "./filebrowser.db", "Database file")
|
|
||||||
flag.StringVarP(&logfile, "log", "l", "stdout", "Errors logger; can use 'stdout', 'stderr' or file")
|
|
||||||
flag.StringVarP(&scope, "scope", "s", ".", "Default scope option for new users")
|
|
||||||
flag.StringVarP(&baseurl, "baseurl", "b", "", "Base URL")
|
|
||||||
flag.StringVar(&commands, "commands", "git svn hg", "Default commands option for new users")
|
|
||||||
flag.StringVar(&prefixurl, "prefixurl", "", "Prefix URL")
|
|
||||||
flag.StringVar(&viewMode, "view-mode", "mosaic", "Default view mode for new users")
|
|
||||||
flag.StringVar(&recaptchakey, "recaptcha-key", "", "ReCaptcha site key")
|
|
||||||
flag.StringVar(&recaptchasecret, "recaptcha-secret", "", "ReCaptcha secret")
|
|
||||||
flag.BoolVar(&allowCommands, "allow-commands", true, "Default allow commands option for new users")
|
|
||||||
flag.BoolVar(&allowEdit, "allow-edit", true, "Default allow edit option for new users")
|
|
||||||
flag.BoolVar(&allowPublish, "allow-publish", true, "Default allow publish option for new users")
|
|
||||||
flag.StringVar(&auth.method, "auth.method", "default", "Switch between 'none', 'default' and 'proxy' authentication.")
|
|
||||||
flag.StringVar(&auth.loginHeader, "auth.loginHeader", "X-Forwarded-User", "The header name used for proxy authentication.")
|
|
||||||
flag.BoolVar(&allowNew, "allow-new", true, "Default allow new option for new users")
|
|
||||||
flag.BoolVar(&noAuth, "no-auth", false, "Disables authentication")
|
|
||||||
flag.BoolVar(&alterRecaptcha, "alternative-recaptcha", false, "Use recaptcha.net for serving and handling, useful in China")
|
|
||||||
flag.StringVar(&locale, "locale", "", "Default locale for new users, set it empty to enable auto detect from browser")
|
|
||||||
flag.StringVar(&staticg, "staticgen", "", "Static Generator you want to enable")
|
|
||||||
flag.BoolVarP(&showVer, "version", "v", false, "Show version")
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupViper() {
|
|
||||||
viper.SetDefault("Address", "")
|
|
||||||
viper.SetDefault("Port", "0")
|
|
||||||
viper.SetDefault("Database", "./filebrowser.db")
|
|
||||||
viper.SetDefault("Scope", ".")
|
|
||||||
viper.SetDefault("Logger", "stdout")
|
|
||||||
viper.SetDefault("Commands", []string{"git", "svn", "hg"})
|
|
||||||
viper.SetDefault("AllowCommmands", true)
|
|
||||||
viper.SetDefault("AllowEdit", true)
|
|
||||||
viper.SetDefault("AllowNew", true)
|
|
||||||
viper.SetDefault("AllowPublish", true)
|
|
||||||
viper.SetDefault("StaticGen", "")
|
|
||||||
viper.SetDefault("Locale", "")
|
|
||||||
viper.SetDefault("AuthMethod", "default")
|
|
||||||
viper.SetDefault("LoginHeader", "X-Fowarded-User")
|
|
||||||
viper.SetDefault("NoAuth", false)
|
|
||||||
viper.SetDefault("BaseURL", "")
|
|
||||||
viper.SetDefault("PrefixURL", "")
|
|
||||||
viper.SetDefault("ViewMode", filebrowser.MosaicViewMode)
|
|
||||||
viper.SetDefault("AlternativeRecaptcha", false)
|
|
||||||
viper.SetDefault("ReCaptchaKey", "")
|
|
||||||
viper.SetDefault("ReCaptchaSecret", "")
|
|
||||||
|
|
||||||
viper.BindPFlag("Port", flag.Lookup("port"))
|
|
||||||
viper.BindPFlag("Address", flag.Lookup("address"))
|
|
||||||
viper.BindPFlag("Database", flag.Lookup("database"))
|
|
||||||
viper.BindPFlag("Scope", flag.Lookup("scope"))
|
|
||||||
viper.BindPFlag("Logger", flag.Lookup("log"))
|
|
||||||
viper.BindPFlag("Commands", flag.Lookup("commands"))
|
|
||||||
viper.BindPFlag("AllowCommands", flag.Lookup("allow-commands"))
|
|
||||||
viper.BindPFlag("AllowEdit", flag.Lookup("allow-edit"))
|
|
||||||
viper.BindPFlag("AllowNew", flag.Lookup("allow-new"))
|
|
||||||
viper.BindPFlag("AllowPublish", flag.Lookup("allow-publish"))
|
|
||||||
viper.BindPFlag("Locale", flag.Lookup("locale"))
|
|
||||||
viper.BindPFlag("StaticGen", flag.Lookup("staticgen"))
|
|
||||||
viper.BindPFlag("AuthMethod", flag.Lookup("auth.method"))
|
|
||||||
viper.BindPFlag("LoginHeader", flag.Lookup("auth.loginHeader"))
|
|
||||||
viper.BindPFlag("NoAuth", flag.Lookup("no-auth"))
|
|
||||||
viper.BindPFlag("BaseURL", flag.Lookup("baseurl"))
|
|
||||||
viper.BindPFlag("PrefixURL", flag.Lookup("prefixurl"))
|
|
||||||
viper.BindPFlag("ViewMode", flag.Lookup("view-mode"))
|
|
||||||
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
|
|
||||||
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
|
|
||||||
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))
|
|
||||||
|
|
||||||
viper.SetConfigName("filebrowser")
|
|
||||||
viper.AddConfigPath(".")
|
|
||||||
}
|
|
||||||
|
|
||||||
func printVersion() {
|
|
||||||
fmt.Println("filebrowser version", filebrowser.Version)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
setupViper()
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if showVer {
|
|
||||||
printVersion()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a configuration file if set.
|
|
||||||
if config != "" {
|
|
||||||
ext := filepath.Ext(config)
|
|
||||||
dir := filepath.Dir(config)
|
|
||||||
config = strings.TrimSuffix(config, ext)
|
|
||||||
|
|
||||||
if dir != "" {
|
|
||||||
viper.AddConfigPath(dir)
|
|
||||||
config = strings.TrimPrefix(config, dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.SetConfigName(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read configuration from a file if exists.
|
|
||||||
err := viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(viper.ConfigParseError); ok {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up process log before anything bad happens.
|
|
||||||
switch viper.GetString("Logger") {
|
|
||||||
case "stdout":
|
|
||||||
log.SetOutput(os.Stdout)
|
|
||||||
case "stderr":
|
|
||||||
log.SetOutput(os.Stderr)
|
|
||||||
case "":
|
|
||||||
log.SetOutput(ioutil.Discard)
|
|
||||||
default:
|
|
||||||
log.SetOutput(&lumberjack.Logger{
|
|
||||||
Filename: logfile,
|
|
||||||
MaxSize: 100,
|
|
||||||
MaxAge: 14,
|
|
||||||
MaxBackups: 10,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the provided config before moving forward
|
|
||||||
if viper.GetString("AuthMethod") != "none" && viper.GetString("AuthMethod") != "default" && viper.GetString("AuthMethod") != "proxy" {
|
|
||||||
log.Fatal("The property 'auth.method' needs to be set to 'default' or 'proxy'.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if viper.GetString("AuthMethod") == "proxy" {
|
|
||||||
if viper.GetString("LoginHeader") == "" {
|
|
||||||
log.Fatal("The 'loginHeader' needs to be specified when 'proxy' authentication is used.")
|
|
||||||
}
|
|
||||||
log.Println("[WARN] Filebrowser authentication is configured to 'proxy' authentication. This can cause a huge security issue if the infrastructure is not configured correctly.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builds the address and a listener.
|
|
||||||
laddr := viper.GetString("Address") + ":" + viper.GetString("Port")
|
|
||||||
listener, err := net.Listen("tcp", laddr)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the user the port in which is listening.
|
|
||||||
fmt.Println("Listening on", listener.Addr().String())
|
|
||||||
|
|
||||||
// Starts the server.
|
|
||||||
if err := http.Serve(listener, handler()); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handler() http.Handler {
|
|
||||||
db, err := storm.Open(viper.GetString("Database"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
recaptchaHost := "https://www.google.com"
|
|
||||||
if viper.GetBool("AlternativeRecaptcha") {
|
|
||||||
recaptchaHost = "https://recaptcha.net"
|
|
||||||
}
|
|
||||||
|
|
||||||
fm := &filebrowser.FileBrowser{
|
|
||||||
AuthMethod: viper.GetString("AuthMethod"),
|
|
||||||
LoginHeader: viper.GetString("LoginHeader"),
|
|
||||||
NoAuth: viper.GetBool("NoAuth"),
|
|
||||||
BaseURL: viper.GetString("BaseURL"),
|
|
||||||
PrefixURL: viper.GetString("PrefixURL"),
|
|
||||||
ReCaptchaHost: recaptchaHost,
|
|
||||||
ReCaptchaKey: viper.GetString("ReCaptchaKey"),
|
|
||||||
ReCaptchaSecret: viper.GetString("ReCaptchaSecret"),
|
|
||||||
DefaultUser: &filebrowser.User{
|
|
||||||
AllowCommands: viper.GetBool("AllowCommands"),
|
|
||||||
AllowEdit: viper.GetBool("AllowEdit"),
|
|
||||||
AllowNew: viper.GetBool("AllowNew"),
|
|
||||||
AllowPublish: viper.GetBool("AllowPublish"),
|
|
||||||
Commands: viper.GetStringSlice("Commands"),
|
|
||||||
Rules: []*filebrowser.Rule{},
|
|
||||||
Locale: viper.GetString("Locale"),
|
|
||||||
CSS: "",
|
|
||||||
Scope: viper.GetString("Scope"),
|
|
||||||
FileSystem: fileutils.Dir(viper.GetString("Scope")),
|
|
||||||
ViewMode: viper.GetString("ViewMode"),
|
|
||||||
},
|
|
||||||
Store: &filebrowser.Store{
|
|
||||||
Config: bolt.ConfigStore{DB: db},
|
|
||||||
Users: bolt.UsersStore{DB: db},
|
|
||||||
Share: bolt.ShareStore{DB: db},
|
|
||||||
},
|
|
||||||
NewFS: func(scope string) filebrowser.FileSystem {
|
|
||||||
return fileutils.Dir(scope)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err = fm.Setup()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch viper.GetString("StaticGen") {
|
|
||||||
case "hugo":
|
|
||||||
hugo := &staticgen.Hugo{
|
|
||||||
Root: viper.GetString("Scope"),
|
|
||||||
Public: filepath.Join(viper.GetString("Scope"), "public"),
|
|
||||||
Args: []string{},
|
|
||||||
CleanPublic: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = fm.Attach(hugo); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
case "jekyll":
|
|
||||||
jekyll := &staticgen.Jekyll{
|
|
||||||
Root: viper.GetString("Scope"),
|
|
||||||
Public: filepath.Join(viper.GetString("Scope"), "_site"),
|
|
||||||
Args: []string{"build"},
|
|
||||||
CleanPublic: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = fm.Attach(jekyll); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.Handler(fm)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(hashCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hashCmd = &cobra.Command{
|
||||||
|
Use: "hash <password>",
|
||||||
|
Short: "Hashes a password",
|
||||||
|
Long: `Hashes a password using bcrypt algorithm.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
pwd, err := users.HashPwd(args[0])
|
||||||
|
checkErr(err)
|
||||||
|
fmt.Println(pwd)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,352 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/auth"
|
||||||
|
fbhttp "github.com/filebrowser/filebrowser/v2/http"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
v "github.com/spf13/viper"
|
||||||
|
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cfgFile string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cobra.OnInitialize(initConfig)
|
||||||
|
|
||||||
|
rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n")
|
||||||
|
|
||||||
|
flags := rootCmd.Flags()
|
||||||
|
persistent := rootCmd.PersistentFlags()
|
||||||
|
|
||||||
|
persistent.StringVarP(&cfgFile, "config", "c", "", "config file path")
|
||||||
|
persistent.StringP("database", "d", "./filebrowser.db", "database path")
|
||||||
|
flags.Bool("noauth", false, "use the noauth auther when using quick setup")
|
||||||
|
flags.String("username", "admin", "username for the first user when using quick config")
|
||||||
|
flags.String("password", "", "hashed password for the first user when using quick config (default \"admin\")")
|
||||||
|
|
||||||
|
addServerFlags(flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addServerFlags(flags *pflag.FlagSet) {
|
||||||
|
flags.StringP("address", "a", "127.0.0.1", "address to listen on")
|
||||||
|
flags.StringP("log", "l", "stdout", "log output")
|
||||||
|
flags.StringP("port", "p", "8080", "port to listen on")
|
||||||
|
flags.StringP("cert", "t", "", "tls certificate")
|
||||||
|
flags.StringP("key", "k", "", "tls key")
|
||||||
|
flags.StringP("root", "r", ".", "root to prepend to relative paths")
|
||||||
|
flags.String("socket", "", "socket to listen to (cannot be used with address, port, cert nor key flags)")
|
||||||
|
flags.StringP("baseurl", "b", "", "base url")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "filebrowser",
|
||||||
|
Short: "A stylish web-based file browser",
|
||||||
|
Long: `File Browser CLI lets you create the database to use with File Browser,
|
||||||
|
manage your users and all the configurations without acessing the
|
||||||
|
web interface.
|
||||||
|
|
||||||
|
If you've never run File Browser, you'll need to have a database for
|
||||||
|
it. Don't worry: you don't need to setup a separate database server.
|
||||||
|
We're using Bolt DB which is a single file database and all managed
|
||||||
|
by ourselves.
|
||||||
|
|
||||||
|
For this specific command, all the flags you have available (except
|
||||||
|
"config" for the configuration file), can be given either through
|
||||||
|
environment variables or configuration files.
|
||||||
|
|
||||||
|
If you don't set "config", it will look for a configuration file called
|
||||||
|
.filebrowser.{json, toml, yaml, yml} in the following directories:
|
||||||
|
|
||||||
|
- ./
|
||||||
|
- $HOME/
|
||||||
|
- /etc/filebrowser/
|
||||||
|
|
||||||
|
The precedence of the configuration values are as follows:
|
||||||
|
|
||||||
|
- flags
|
||||||
|
- environment variables
|
||||||
|
- configuration file
|
||||||
|
- database values
|
||||||
|
- defaults
|
||||||
|
|
||||||
|
The environment variables are prefixed by "FB_" followed by the option
|
||||||
|
name in caps. So to set "database" via an env variable, you should
|
||||||
|
set FB_DATABASE.
|
||||||
|
|
||||||
|
Also, if the database path doesn't exist, File Browser will enter into
|
||||||
|
the quick setup mode and a new database will be bootstraped and a new
|
||||||
|
user created with the credentials from options "username" and "password".`,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
log.Println(cfgFile)
|
||||||
|
|
||||||
|
if !d.hadDB {
|
||||||
|
quickSetup(cmd.Flags(), d)
|
||||||
|
}
|
||||||
|
|
||||||
|
server := getRunParams(cmd.Flags(), d.store)
|
||||||
|
setupLog(server.Log)
|
||||||
|
|
||||||
|
root, err := filepath.Abs(server.Root)
|
||||||
|
checkErr(err)
|
||||||
|
server.Root = root
|
||||||
|
|
||||||
|
adr := server.Address + ":" + server.Port
|
||||||
|
|
||||||
|
var listener net.Listener
|
||||||
|
|
||||||
|
if server.Socket != "" {
|
||||||
|
listener, err = net.Listen("unix", server.Socket)
|
||||||
|
checkErr(err)
|
||||||
|
} else if server.TLSKey != "" && server.TLSCert != "" {
|
||||||
|
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey)
|
||||||
|
checkErr(err)
|
||||||
|
listener, err = tls.Listen("tcp", adr, &tls.Config{Certificates: []tls.Certificate{cer}})
|
||||||
|
checkErr(err)
|
||||||
|
} else {
|
||||||
|
listener, err = net.Listen("tcp", adr)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go cleanupHandler(listener, sigc)
|
||||||
|
|
||||||
|
handler, err := fbhttp.NewHandler(d.store, server)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
log.Println("Listening on", listener.Addr().String())
|
||||||
|
if err := http.Serve(listener, handler); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}, pythonConfig{allowNoDB: true}),
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupHandler(listener net.Listener, c chan os.Signal) {
|
||||||
|
sig := <-c
|
||||||
|
log.Printf("Caught signal %s: shutting down.", sig)
|
||||||
|
listener.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRunParams(flags *pflag.FlagSet, st *storage.Storage) *settings.Server {
|
||||||
|
server, err := st.Settings.GetServer()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "root"); set {
|
||||||
|
server.Root = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "baseurl"); set {
|
||||||
|
server.BaseURL = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "log"); set {
|
||||||
|
server.Log = val
|
||||||
|
}
|
||||||
|
|
||||||
|
isSocketSet := false
|
||||||
|
isAddrSet := false
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "address"); set {
|
||||||
|
server.Address = val
|
||||||
|
isAddrSet = isAddrSet || set
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "port"); set {
|
||||||
|
server.Port = val
|
||||||
|
isAddrSet = isAddrSet || set
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "key"); set {
|
||||||
|
server.TLSKey = val
|
||||||
|
isAddrSet = isAddrSet || set
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "cert"); set {
|
||||||
|
server.TLSCert = val
|
||||||
|
isAddrSet = isAddrSet || set
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, set := getParamB(flags, "socket"); set {
|
||||||
|
server.Socket = val
|
||||||
|
isSocketSet = isSocketSet || set
|
||||||
|
}
|
||||||
|
|
||||||
|
if isAddrSet && isSocketSet {
|
||||||
|
checkErr(errors.New("--socket flag cannot be used with --address, --port, --key nor --cert"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not use saved Socket if address was manually set.
|
||||||
|
if isAddrSet && server.Socket != "" {
|
||||||
|
server.Socket = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
// getParamB returns a parameter as a string and a boolean to tell if it is different from the default
|
||||||
|
//
|
||||||
|
// NOTE: we could simply bind the flags to viper and use IsSet.
|
||||||
|
// Although there is a bug on Viper that always returns true on IsSet
|
||||||
|
// if a flag is binded. Our alternative way is to manually check
|
||||||
|
// the flag and then the value from env/config/gotten by viper.
|
||||||
|
// https://github.com/spf13/viper/pull/331
|
||||||
|
func getParamB(flags *pflag.FlagSet, key string) (string, bool) {
|
||||||
|
value, _ := flags.GetString(key)
|
||||||
|
|
||||||
|
// If set on Flags, use it.
|
||||||
|
if flags.Changed(key) {
|
||||||
|
return value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// If set through viper (env, config), return it.
|
||||||
|
if v.IsSet(key) {
|
||||||
|
return v.GetString(key), true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise use default value on flags.
|
||||||
|
return value, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func getParam(flags *pflag.FlagSet, key string) string {
|
||||||
|
val, _ := getParamB(flags, key)
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupLog(logMethod string) {
|
||||||
|
switch logMethod {
|
||||||
|
case "stdout":
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
case "stderr":
|
||||||
|
log.SetOutput(os.Stderr)
|
||||||
|
case "":
|
||||||
|
log.SetOutput(ioutil.Discard)
|
||||||
|
default:
|
||||||
|
log.SetOutput(&lumberjack.Logger{
|
||||||
|
Filename: logMethod,
|
||||||
|
MaxSize: 100,
|
||||||
|
MaxAge: 14,
|
||||||
|
MaxBackups: 10,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
||||||
|
set := &settings.Settings{
|
||||||
|
Key: generateKey(),
|
||||||
|
Signup: false,
|
||||||
|
CreateUserDir: false,
|
||||||
|
Defaults: settings.UserDefaults{
|
||||||
|
Scope: ".",
|
||||||
|
Locale: "en",
|
||||||
|
Perm: users.Permissions{
|
||||||
|
Admin: false,
|
||||||
|
Execute: true,
|
||||||
|
Create: true,
|
||||||
|
Rename: true,
|
||||||
|
Modify: true,
|
||||||
|
Delete: true,
|
||||||
|
Share: true,
|
||||||
|
Download: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if _, noauth := getParamB(flags, "noauth"); noauth {
|
||||||
|
set.AuthMethod = auth.MethodNoAuth
|
||||||
|
err = d.store.Auth.Save(&auth.NoAuth{})
|
||||||
|
} else {
|
||||||
|
set.AuthMethod = auth.MethodJSONAuth
|
||||||
|
err = d.store.Auth.Save(&auth.JSONAuth{})
|
||||||
|
}
|
||||||
|
|
||||||
|
checkErr(err)
|
||||||
|
err = d.store.Settings.Save(set)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
ser := &settings.Server{
|
||||||
|
BaseURL: getParam(flags, "baseurl"),
|
||||||
|
Port: getParam(flags, "port"),
|
||||||
|
Log: getParam(flags, "log"),
|
||||||
|
TLSKey: getParam(flags, "key"),
|
||||||
|
TLSCert: getParam(flags, "cert"),
|
||||||
|
Address: getParam(flags, "address"),
|
||||||
|
Root: getParam(flags, "root"),
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.store.Settings.SaveServer(ser)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
username := getParam(flags, "username")
|
||||||
|
password := getParam(flags, "password")
|
||||||
|
|
||||||
|
if password == "" {
|
||||||
|
password, err = users.HashPwd("admin")
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if username == "" || password == "" {
|
||||||
|
log.Fatal("username and password cannot be empty during quick setup")
|
||||||
|
}
|
||||||
|
|
||||||
|
user := &users.User{
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
LockPassword: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
set.Defaults.Apply(user)
|
||||||
|
user.Perm.Admin = true
|
||||||
|
|
||||||
|
err = d.store.Users.Save(user)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initConfig() {
|
||||||
|
if cfgFile == "" {
|
||||||
|
home, err := homedir.Dir()
|
||||||
|
checkErr(err)
|
||||||
|
v.AddConfigPath(".")
|
||||||
|
v.AddConfigPath(home)
|
||||||
|
v.AddConfigPath("/etc/filebrowser/")
|
||||||
|
v.SetConfigName(".filebrowser")
|
||||||
|
} else {
|
||||||
|
v.SetConfigFile(cfgFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
v.SetEnvPrefix("FB")
|
||||||
|
v.AutomaticEnv()
|
||||||
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
|
||||||
|
if err := v.ReadInConfig(); err != nil {
|
||||||
|
if _, ok := err.(v.ConfigParseError); ok {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
cfgFile = "No config file used"
|
||||||
|
} else {
|
||||||
|
cfgFile = "Using config file: " + v.ConfigFileUsed()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rulesCmd.AddCommand(rulesRmCommand)
|
||||||
|
rulesRmCommand.Flags().Uint("index", 0, "index of rule to remove")
|
||||||
|
rulesRmCommand.MarkFlagRequired("index")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rulesRmCommand = &cobra.Command{
|
||||||
|
Use: "rm <index> [index_end]",
|
||||||
|
Short: "Remove a global rule or user rule",
|
||||||
|
Long: `Remove a global rule or user rule. The provided index
|
||||||
|
is the same that's printed when you run 'rules ls'. Note
|
||||||
|
that after each removal/addition, the index of the
|
||||||
|
commands change. So be careful when removing them after each
|
||||||
|
other.
|
||||||
|
|
||||||
|
You can also specify an optional parameter (index_end) so
|
||||||
|
you can remove all commands from 'index' to 'index_end',
|
||||||
|
including 'index_end'.`,
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if err := cobra.RangeArgs(1, 2)(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, arg := range args {
|
||||||
|
if _, err := strconv.Atoi(arg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
i, err := strconv.Atoi(args[0])
|
||||||
|
checkErr(err)
|
||||||
|
f := i
|
||||||
|
if len(args) == 2 {
|
||||||
|
f, err = strconv.Atoi(args[1])
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user := func(u *users.User) {
|
||||||
|
u.Rules = append(u.Rules[:i], u.Rules[f+1:]...)
|
||||||
|
err := d.store.Users.Save(u)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
global := func(s *settings.Settings) {
|
||||||
|
s.Rules = append(s.Rules[:i], s.Rules[f+1:]...)
|
||||||
|
err := d.store.Settings.Save(s)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runRules(d.store, cmd, user, global)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(rulesCmd)
|
||||||
|
rulesCmd.PersistentFlags().StringP("username", "u", "", "username of user to which the rules apply")
|
||||||
|
rulesCmd.PersistentFlags().UintP("id", "i", 0, "id of user to which the rules apply")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rulesCmd = &cobra.Command{
|
||||||
|
Use: "rules",
|
||||||
|
Short: "Rules management utility",
|
||||||
|
Long: `On each subcommand you'll have available at least two flags:
|
||||||
|
"username" and "id". You must either set only one of them
|
||||||
|
or none. If you set one of them, the command will apply to
|
||||||
|
an user, otherwise it will be applied to the global set or
|
||||||
|
rules.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
func runRules(st *storage.Storage, cmd *cobra.Command, users func(*users.User), global func(*settings.Settings)) {
|
||||||
|
id := getUserIdentifier(cmd.Flags())
|
||||||
|
if id != nil {
|
||||||
|
user, err := st.Users.Get("", id)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
if users != nil {
|
||||||
|
users(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
printRules(user.Rules, id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := st.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
if global != nil {
|
||||||
|
global(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
printRules(s.Rules, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUserIdentifier(flags *pflag.FlagSet) interface{} {
|
||||||
|
id := mustGetUint(flags, "id")
|
||||||
|
username := mustGetString(flags, "username")
|
||||||
|
|
||||||
|
if id != 0 {
|
||||||
|
return id
|
||||||
|
} else if username != "" {
|
||||||
|
return username
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printRules(rules []rules.Rule, id interface{}) {
|
||||||
|
if id == nil {
|
||||||
|
fmt.Printf("Global Rules:\n\n")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Rules for user %v:\n\n", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, rule := range rules {
|
||||||
|
fmt.Printf("(%d) ", id)
|
||||||
|
if rule.Regex {
|
||||||
|
if rule.Allow {
|
||||||
|
fmt.Printf("Allow Regex: \t%s\n", rule.Regexp.Raw)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Disallow Regex: \t%s\n", rule.Regexp.Raw)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if rule.Allow {
|
||||||
|
fmt.Printf("Allow Path: \t%s\n", rule.Path)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Disallow Path: \t%s\n", rule.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rulesCmd.AddCommand(rulesAddCmd)
|
||||||
|
rulesAddCmd.Flags().BoolP("allow", "a", false, "indicates this is an allow rule")
|
||||||
|
rulesAddCmd.Flags().BoolP("regex", "r", false, "indicates this is a regex rule")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rulesAddCmd = &cobra.Command{
|
||||||
|
Use: "add <path|expression>",
|
||||||
|
Short: "Add a global rule or user rule",
|
||||||
|
Long: `Add a global rule or user rule.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
allow := mustGetBool(cmd.Flags(), "allow")
|
||||||
|
regex := mustGetBool(cmd.Flags(), "regex")
|
||||||
|
exp := args[0]
|
||||||
|
|
||||||
|
if regex {
|
||||||
|
regexp.MustCompile(exp)
|
||||||
|
}
|
||||||
|
|
||||||
|
rule := rules.Rule{
|
||||||
|
Allow: allow,
|
||||||
|
Regex: regex,
|
||||||
|
}
|
||||||
|
|
||||||
|
if regex {
|
||||||
|
rule.Regexp = &rules.Regexp{Raw: exp}
|
||||||
|
} else {
|
||||||
|
rule.Path = exp
|
||||||
|
}
|
||||||
|
|
||||||
|
user := func(u *users.User) {
|
||||||
|
u.Rules = append(u.Rules, rule)
|
||||||
|
err := d.store.Users.Save(u)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
global := func(s *settings.Settings) {
|
||||||
|
s.Rules = append(s.Rules, rule)
|
||||||
|
err := d.store.Settings.Save(s)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runRules(d.store, cmd, user, global)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rulesCmd.AddCommand(rulesLsCommand)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rulesLsCommand = &cobra.Command{
|
||||||
|
Use: "ls",
|
||||||
|
Short: "List global rules or user specific rules",
|
||||||
|
Long: `List global rules or user specific rules.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
runRules(d.store, cmd, nil, nil)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filebrowser/filebrowser/v2/storage/bolt/importer"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(upgradeCmd)
|
||||||
|
|
||||||
|
upgradeCmd.Flags().String("old.database", "", "")
|
||||||
|
upgradeCmd.Flags().String("old.config", "", "")
|
||||||
|
upgradeCmd.MarkFlagRequired("old.database")
|
||||||
|
}
|
||||||
|
|
||||||
|
var upgradeCmd = &cobra.Command{
|
||||||
|
Use: "upgrade",
|
||||||
|
Short: "Upgrades an old configuration",
|
||||||
|
Long: `Upgrades an old configuration. This command DOES NOT
|
||||||
|
import share links because they are incompatible with
|
||||||
|
this version.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
flags := cmd.Flags()
|
||||||
|
oldDB := mustGetString(flags, "old.database")
|
||||||
|
oldConf := mustGetString(flags, "old.config")
|
||||||
|
err := importer.Import(oldDB, oldConf, getParam(flags, "database"))
|
||||||
|
checkErr(err)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(usersCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersCmd = &cobra.Command{
|
||||||
|
Use: "users",
|
||||||
|
Short: "Users management utility",
|
||||||
|
Long: `Users management utility.`,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
func printUsers(users []*users.User) {
|
||||||
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
|
fmt.Fprintln(w, "ID\tUsername\tScope\tLocale\tV. Mode\tAdmin\tExecute\tCreate\tRename\tModify\tDelete\tShare\tDownload\tPwd Lock")
|
||||||
|
|
||||||
|
for _, user := range users {
|
||||||
|
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t\n",
|
||||||
|
user.ID,
|
||||||
|
user.Username,
|
||||||
|
user.Scope,
|
||||||
|
user.Locale,
|
||||||
|
user.ViewMode,
|
||||||
|
user.Perm.Admin,
|
||||||
|
user.Perm.Execute,
|
||||||
|
user.Perm.Create,
|
||||||
|
user.Perm.Rename,
|
||||||
|
user.Perm.Modify,
|
||||||
|
user.Perm.Delete,
|
||||||
|
user.Perm.Share,
|
||||||
|
user.Perm.Download,
|
||||||
|
user.LockPassword,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseUsernameOrID(arg string) (string, uint) {
|
||||||
|
id, err := strconv.ParseUint(arg, 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return arg, 0
|
||||||
|
}
|
||||||
|
return "", uint(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addUserFlags(flags *pflag.FlagSet) {
|
||||||
|
flags.Bool("perm.admin", false, "admin perm for users")
|
||||||
|
flags.Bool("perm.execute", true, "execute perm for users")
|
||||||
|
flags.Bool("perm.create", true, "create perm for users")
|
||||||
|
flags.Bool("perm.rename", true, "rename perm for users")
|
||||||
|
flags.Bool("perm.modify", true, "modify perm for users")
|
||||||
|
flags.Bool("perm.delete", true, "delete perm for users")
|
||||||
|
flags.Bool("perm.share", true, "share perm for users")
|
||||||
|
flags.Bool("perm.download", true, "download perm for users")
|
||||||
|
flags.String("sorting.by", "name", "sorting mode (name, size or modified)")
|
||||||
|
flags.Bool("sorting.asc", false, "sorting by ascending order")
|
||||||
|
flags.Bool("lockPassword", false, "lock password")
|
||||||
|
flags.StringSlice("commands", nil, "a list of the commands a user can execute")
|
||||||
|
flags.String("scope", ".", "scope for users")
|
||||||
|
flags.String("locale", "en", "locale for users")
|
||||||
|
flags.String("viewMode", string(users.ListViewMode), "view mode for users")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getViewMode(flags *pflag.FlagSet) users.ViewMode {
|
||||||
|
viewMode := users.ViewMode(mustGetString(flags, "viewMode"))
|
||||||
|
if viewMode != users.ListViewMode && viewMode != users.MosaicViewMode {
|
||||||
|
checkErr(errors.New("view mode must be \"" + string(users.ListViewMode) + "\" or \"" + string(users.MosaicViewMode) + "\""))
|
||||||
|
}
|
||||||
|
return viewMode
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUserDefaults(flags *pflag.FlagSet, defaults *settings.UserDefaults, all bool) {
|
||||||
|
visit := func(flag *pflag.Flag) {
|
||||||
|
switch flag.Name {
|
||||||
|
case "scope":
|
||||||
|
defaults.Scope = mustGetString(flags, flag.Name)
|
||||||
|
case "locale":
|
||||||
|
defaults.Locale = mustGetString(flags, flag.Name)
|
||||||
|
case "viewMode":
|
||||||
|
defaults.ViewMode = getViewMode(flags)
|
||||||
|
case "perm.admin":
|
||||||
|
defaults.Perm.Admin = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.execute":
|
||||||
|
defaults.Perm.Execute = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.create":
|
||||||
|
defaults.Perm.Create = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.rename":
|
||||||
|
defaults.Perm.Rename = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.modify":
|
||||||
|
defaults.Perm.Modify = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.delete":
|
||||||
|
defaults.Perm.Delete = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.share":
|
||||||
|
defaults.Perm.Share = mustGetBool(flags, flag.Name)
|
||||||
|
case "perm.download":
|
||||||
|
defaults.Perm.Download = mustGetBool(flags, flag.Name)
|
||||||
|
case "commands":
|
||||||
|
commands, err := flags.GetStringSlice(flag.Name)
|
||||||
|
checkErr(err)
|
||||||
|
defaults.Commands = commands
|
||||||
|
case "sorting.by":
|
||||||
|
defaults.Sorting.By = mustGetString(flags, flag.Name)
|
||||||
|
case "sorting.asc":
|
||||||
|
defaults.Sorting.Asc = mustGetBool(flags, flag.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if all {
|
||||||
|
flags.VisitAll(visit)
|
||||||
|
} else {
|
||||||
|
flags.Visit(visit)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersAddCmd)
|
||||||
|
addUserFlags(usersAddCmd.Flags())
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersAddCmd = &cobra.Command{
|
||||||
|
Use: "add <username> <password>",
|
||||||
|
Short: "Create a new user",
|
||||||
|
Long: `Create a new user and add it to the database.`,
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
s, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
getUserDefaults(cmd.Flags(), &s.Defaults, false)
|
||||||
|
|
||||||
|
password, err := users.HashPwd(args[1])
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
user := &users.User{
|
||||||
|
Username: args[0],
|
||||||
|
Password: password,
|
||||||
|
LockPassword: mustGetBool(cmd.Flags(), "lockPassword"),
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Defaults.Apply(user)
|
||||||
|
|
||||||
|
servSettings, err := d.store.Settings.GetServer()
|
||||||
|
checkErr(err)
|
||||||
|
//since getUserDefaults() polluted s.Defaults.Scope
|
||||||
|
//which makes the Scope not the one saved in the db
|
||||||
|
//we need the right s.Defaults.Scope here
|
||||||
|
s2, err := d.store.Settings.Get()
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
userHome, err := s2.MakeUserDir(user.Username, user.Scope, servSettings.Root)
|
||||||
|
checkErr(err)
|
||||||
|
user.Scope = userHome
|
||||||
|
|
||||||
|
err = d.store.Users.Save(user)
|
||||||
|
checkErr(err)
|
||||||
|
printUsers([]*users.User{user})
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersExportCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersExportCmd = &cobra.Command{
|
||||||
|
Use: "export <path>",
|
||||||
|
Short: "Export all users to a file.",
|
||||||
|
Long: `Export all users to a json or yaml file. Please indicate the
|
||||||
|
path to the file where you want to write the users.`,
|
||||||
|
Args: jsonYamlArg,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
list, err := d.store.Users.Gets("")
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
err = marshal(args[0], list)
|
||||||
|
checkErr(err)
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersFindCmd)
|
||||||
|
usersCmd.AddCommand(usersLsCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersFindCmd = &cobra.Command{
|
||||||
|
Use: "find <id|username>",
|
||||||
|
Short: "Find a user by username or id",
|
||||||
|
Long: `Find a user by username or id. If no flag is set, all users will be printed.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: findUsers,
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersLsCmd = &cobra.Command{
|
||||||
|
Use: "ls",
|
||||||
|
Short: "List all users.",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: findUsers,
|
||||||
|
}
|
||||||
|
|
||||||
|
var findUsers = python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
var (
|
||||||
|
list []*users.User
|
||||||
|
user *users.User
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(args) == 1 {
|
||||||
|
username, id := parseUsernameOrID(args[0])
|
||||||
|
if username != "" {
|
||||||
|
user, err = d.store.Users.Get("", username)
|
||||||
|
} else {
|
||||||
|
user, err = d.store.Users.Get("", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
list = []*users.User{user}
|
||||||
|
} else {
|
||||||
|
list, err = d.store.Users.Gets("")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkErr(err)
|
||||||
|
printUsers(list)
|
||||||
|
}, pythonConfig{})
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersImportCmd)
|
||||||
|
usersImportCmd.Flags().Bool("overwrite", false, "overwrite users with the same id/username combo")
|
||||||
|
usersImportCmd.Flags().Bool("replace", false, "replace the entire user base")
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersImportCmd = &cobra.Command{
|
||||||
|
Use: "import <path>",
|
||||||
|
Short: "Import users from a file",
|
||||||
|
Long: `Import users from a file. The path must be for a json or yaml
|
||||||
|
file. You can use this command to import new users to your
|
||||||
|
installation. For that, just don't place their ID on the files
|
||||||
|
list or set it to 0.`,
|
||||||
|
Args: jsonYamlArg,
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
fd, err := os.Open(args[0])
|
||||||
|
checkErr(err)
|
||||||
|
defer fd.Close()
|
||||||
|
|
||||||
|
list := []*users.User{}
|
||||||
|
err = unmarshal(args[0], &list)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
for _, user := range list {
|
||||||
|
err = user.Clean("")
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mustGetBool(cmd.Flags(), "replace") {
|
||||||
|
oldUsers, err := d.store.Users.Gets("")
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
err = marshal("users.backup.json", list)
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
for _, user := range oldUsers {
|
||||||
|
err = d.store.Users.Delete(user.ID)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
overwrite := mustGetBool(cmd.Flags(), "overwrite")
|
||||||
|
|
||||||
|
for _, user := range list {
|
||||||
|
onDB, err := d.store.Users.Get("", user.ID)
|
||||||
|
|
||||||
|
// User exists in DB.
|
||||||
|
if err == nil {
|
||||||
|
if !overwrite {
|
||||||
|
checkErr(errors.New("user " + strconv.Itoa(int(user.ID)) + " is already registred"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the usernames mismatch, check if there is another one in the DB
|
||||||
|
// with the new username. If there is, print an error and cancel the
|
||||||
|
// operation
|
||||||
|
if user.Username != onDB.Username {
|
||||||
|
conflictuous, err := d.store.Users.Get("", user.Username)
|
||||||
|
if err == nil {
|
||||||
|
checkErr(usernameConflictError(user.Username, conflictuous.ID, user.ID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If it doesn't exist, set the ID to 0 to automatically get a new
|
||||||
|
// one that make sense in this DB.
|
||||||
|
user.ID = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.store.Users.Save(user)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
func usernameConflictError(username string, original, new uint) error {
|
||||||
|
return errors.New("can't import user with ID " + strconv.Itoa(int(new)) + " and username \"" + username + "\" because the username is already registred with the user " + strconv.Itoa(int(original)))
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersRmCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersRmCmd = &cobra.Command{
|
||||||
|
Use: "rm <id|username>",
|
||||||
|
Short: "Delete a user by username or id",
|
||||||
|
Long: `Delete a user by username or id`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
username, id := parseUsernameOrID(args[0])
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if username != "" {
|
||||||
|
err = d.store.Users.Delete(username)
|
||||||
|
} else {
|
||||||
|
err = d.store.Users.Delete(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkErr(err)
|
||||||
|
fmt.Println("user deleted successfully")
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
usersCmd.AddCommand(usersUpdateCmd)
|
||||||
|
|
||||||
|
usersUpdateCmd.Flags().StringP("password", "p", "", "new password")
|
||||||
|
usersUpdateCmd.Flags().StringP("username", "u", "", "new username")
|
||||||
|
addUserFlags(usersUpdateCmd.Flags())
|
||||||
|
}
|
||||||
|
|
||||||
|
var usersUpdateCmd = &cobra.Command{
|
||||||
|
Use: "update <id|username>",
|
||||||
|
Short: "Updates an existing user",
|
||||||
|
Long: `Updates an existing user. Set the flags for the
|
||||||
|
options you want to change.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
|
username, id := parseUsernameOrID(args[0])
|
||||||
|
flags := cmd.Flags()
|
||||||
|
password := mustGetString(flags, "password")
|
||||||
|
newUsername := mustGetString(flags, "username")
|
||||||
|
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
user *users.User
|
||||||
|
)
|
||||||
|
|
||||||
|
if id != 0 {
|
||||||
|
user, err = d.store.Users.Get("", id)
|
||||||
|
} else {
|
||||||
|
user, err = d.store.Users.Get("", username)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
defaults := settings.UserDefaults{
|
||||||
|
Scope: user.Scope,
|
||||||
|
Locale: user.Locale,
|
||||||
|
ViewMode: user.ViewMode,
|
||||||
|
Perm: user.Perm,
|
||||||
|
Sorting: user.Sorting,
|
||||||
|
Commands: user.Commands,
|
||||||
|
}
|
||||||
|
getUserDefaults(flags, &defaults, false)
|
||||||
|
user.Scope = defaults.Scope
|
||||||
|
user.Locale = defaults.Locale
|
||||||
|
user.ViewMode = defaults.ViewMode
|
||||||
|
user.Perm = defaults.Perm
|
||||||
|
user.Commands = defaults.Commands
|
||||||
|
user.Sorting = defaults.Sorting
|
||||||
|
user.LockPassword = mustGetBool(flags, "lockPassword")
|
||||||
|
|
||||||
|
if newUsername != "" {
|
||||||
|
user.Username = newUsername
|
||||||
|
}
|
||||||
|
|
||||||
|
if password != "" {
|
||||||
|
user.Password, err = users.HashPwd(password)
|
||||||
|
checkErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.store.Users.Update(user)
|
||||||
|
checkErr(err)
|
||||||
|
printUsers([]*users.User{user})
|
||||||
|
}, pythonConfig{}),
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/asdine/storm"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/storage/bolt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkErr(err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustGetString(flags *pflag.FlagSet, flag string) string {
|
||||||
|
s, err := flags.GetString(flag)
|
||||||
|
checkErr(err)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustGetBool(flags *pflag.FlagSet, flag string) bool {
|
||||||
|
b, err := flags.GetBool(flag)
|
||||||
|
checkErr(err)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustGetUint(flags *pflag.FlagSet, flag string) uint {
|
||||||
|
b, err := flags.GetUint(flag)
|
||||||
|
checkErr(err)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateKey() []byte {
|
||||||
|
k, err := settings.GenerateKey()
|
||||||
|
checkErr(err)
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
|
||||||
|
type cobraFunc func(cmd *cobra.Command, args []string)
|
||||||
|
type pythonFunc func(cmd *cobra.Command, args []string, data pythonData)
|
||||||
|
|
||||||
|
type pythonConfig struct {
|
||||||
|
noDB bool
|
||||||
|
allowNoDB bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type pythonData struct {
|
||||||
|
hadDB bool
|
||||||
|
store *storage.Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
func dbExists(path string) (bool, error) {
|
||||||
|
stat, err := os.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
return stat.Size() != 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
d := filepath.Dir(path)
|
||||||
|
_, err = os.Stat(d)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
os.MkdirAll(d, 0700)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
|
||||||
|
return func(cmd *cobra.Command, args []string) {
|
||||||
|
data := pythonData{hadDB: true}
|
||||||
|
|
||||||
|
path := getParam(cmd.Flags(), "database")
|
||||||
|
exists, err := dbExists(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else if exists && cfg.noDB {
|
||||||
|
log.Fatal(path + " already exists")
|
||||||
|
} else if !exists && !cfg.noDB && !cfg.allowNoDB {
|
||||||
|
log.Fatal(path + " does not exist. Please run 'filebrowser config init' first.")
|
||||||
|
}
|
||||||
|
|
||||||
|
data.hadDB = exists
|
||||||
|
db, err := storm.Open(path)
|
||||||
|
checkErr(err)
|
||||||
|
defer db.Close()
|
||||||
|
data.store, err = bolt.NewStorage(db)
|
||||||
|
checkErr(err)
|
||||||
|
fn(cmd, args, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func marshal(filename string, data interface{}) error {
|
||||||
|
fd, err := os.Create(filename)
|
||||||
|
checkErr(err)
|
||||||
|
defer fd.Close()
|
||||||
|
|
||||||
|
switch ext := filepath.Ext(filename); ext {
|
||||||
|
case ".json":
|
||||||
|
encoder := json.NewEncoder(fd)
|
||||||
|
encoder.SetIndent("", " ")
|
||||||
|
return encoder.Encode(data)
|
||||||
|
case ".yml", ".yaml":
|
||||||
|
encoder := yaml.NewEncoder(fd)
|
||||||
|
return encoder.Encode(data)
|
||||||
|
default:
|
||||||
|
return errors.New("invalid format: " + ext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmarshal(filename string, data interface{}) error {
|
||||||
|
fd, err := os.Open(filename)
|
||||||
|
checkErr(err)
|
||||||
|
defer fd.Close()
|
||||||
|
|
||||||
|
switch ext := filepath.Ext(filename); ext {
|
||||||
|
case ".json":
|
||||||
|
return json.NewDecoder(fd).Decode(data)
|
||||||
|
case ".yml", ".yaml":
|
||||||
|
return yaml.NewDecoder(fd).Decode(data)
|
||||||
|
default:
|
||||||
|
return errors.New("invalid format: " + ext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsonYamlArg(cmd *cobra.Command, args []string) error {
|
||||||
|
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ext := filepath.Ext(args[0]); ext {
|
||||||
|
case ".json", ".yml", ".yaml":
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return errors.New("invalid format: " + ext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{} {
|
||||||
|
result := make(map[string]interface{})
|
||||||
|
for k, v := range in {
|
||||||
|
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpInterfaceArray(in []interface{}) []interface{} {
|
||||||
|
result := make([]interface{}, len(in))
|
||||||
|
for i, v := range in {
|
||||||
|
result[i] = cleanUpMapValue(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpMapValue(v interface{}) interface{} {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case []interface{}:
|
||||||
|
return cleanUpInterfaceArray(v)
|
||||||
|
case map[interface{}]interface{}:
|
||||||
|
return cleanUpInterfaceMap(v)
|
||||||
|
default:
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/version"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print the version number",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("File Browser v" + version.Version + "/" + version.CommitSHA)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
Package filebrowser provides a web interface to access your files
|
|
||||||
wherever you are. To use this package as a middleware for your app,
|
|
||||||
you'll need to import both File Browser and File Browser HTTP packages.
|
|
||||||
|
|
||||||
import (
|
|
||||||
fm "github.com/filebrowser/filebrowser"
|
|
||||||
h "github.com/filebrowser/filebrowser/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
Then, you should create a new FileBrowser object with your options. In this
|
|
||||||
case, I'm using BoltDB (via Storm package) as a Store. So, you'll also need
|
|
||||||
to import "github.com/filebrowser/filebrowser/bolt".
|
|
||||||
|
|
||||||
db, _ := storm.Open("bolt.db")
|
|
||||||
|
|
||||||
m := &fm.FileBrowser{
|
|
||||||
NoAuth: false,
|
|
||||||
Auth: {
|
|
||||||
Method: "default",
|
|
||||||
LoginHeader: "X-Fowarded-User"
|
|
||||||
},
|
|
||||||
DefaultUser: &fm.User{
|
|
||||||
AllowCommands: true,
|
|
||||||
AllowEdit: true,
|
|
||||||
AllowNew: true,
|
|
||||||
AllowPublish: true,
|
|
||||||
Commands: []string{"git"},
|
|
||||||
Rules: []*fm.Rule{},
|
|
||||||
Locale: "en",
|
|
||||||
CSS: "",
|
|
||||||
Scope: ".",
|
|
||||||
FileSystem: fileutils.Dir("."),
|
|
||||||
},
|
|
||||||
Store: &fm.Store{
|
|
||||||
Config: bolt.ConfigStore{DB: db},
|
|
||||||
Users: bolt.UsersStore{DB: db},
|
|
||||||
Share: bolt.ShareStore{DB: db},
|
|
||||||
},
|
|
||||||
NewFS: func(scope string) fm.FileSystem {
|
|
||||||
return fileutils.Dir(scope)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
The credentials for the first user are always 'admin' for both the user and
|
|
||||||
the password, and they can be changed later through the settings. The first
|
|
||||||
user is always an Admin and has all of the permissions set to 'true'.
|
|
||||||
|
|
||||||
Then, you should set the Prefix URL and the Base URL, using the following
|
|
||||||
functions:
|
|
||||||
|
|
||||||
m.SetBaseURL("/")
|
|
||||||
m.SetPrefixURL("/")
|
|
||||||
|
|
||||||
The Prefix URL is a part of the path that is already stripped from the
|
|
||||||
r.URL.Path variable before the request arrives to File Browser's handler.
|
|
||||||
This is a function that will rarely be used. You can see one example on Caddy
|
|
||||||
filemanager plugin.
|
|
||||||
|
|
||||||
The Base URL is the URL path where you want File Browser to be available in. If
|
|
||||||
you want to be available at the root path, you should call:
|
|
||||||
|
|
||||||
m.SetBaseURL("/")
|
|
||||||
|
|
||||||
But if you want to access it at '/admin', you would call:
|
|
||||||
|
|
||||||
m.SetBaseURL("/admin")
|
|
||||||
|
|
||||||
Now, that you already have a File Browser instance created, you just need to
|
|
||||||
add it to your handlers using m.ServeHTTP which is compatible to http.Handler.
|
|
||||||
We also have a m.ServeWithErrorsHTTP that returns the status code and an error.
|
|
||||||
|
|
||||||
One simple implementation for this, at port 80, in the root of the domain, would be:
|
|
||||||
|
|
||||||
http.ListenAndServe(":80", h.Handler(m))
|
|
||||||
*/
|
|
||||||
package filebrowser
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package errors
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrEmptyKey = errors.New("empty key")
|
||||||
|
ErrExist = errors.New("the resource already exists")
|
||||||
|
ErrNotExist = errors.New("the resource does not exist")
|
||||||
|
ErrEmptyPassword = errors.New("password is empty")
|
||||||
|
ErrEmptyUsername = errors.New("username is empty")
|
||||||
|
ErrEmptyRequest = errors.New("empty request")
|
||||||
|
ErrScopeIsRelative = errors.New("scope is a relative path")
|
||||||
|
ErrInvalidDataType = errors.New("invalid data type")
|
||||||
|
ErrIsDirectory = errors.New("file is directory")
|
||||||
|
ErrInvalidOption = errors.New("invalid option")
|
||||||
|
ErrInvalidAuthMethod = errors.New("invalid auth method")
|
||||||
|
)
|
||||||
@@ -1,487 +0,0 @@
|
|||||||
package filebrowser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/md5"
|
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/sha512"
|
|
||||||
"encoding/hex"
|
|
||||||
"hash"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"mime"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/parser"
|
|
||||||
"github.com/maruel/natural"
|
|
||||||
)
|
|
||||||
|
|
||||||
// File contains the information about a particular file or directory.
|
|
||||||
type File struct {
|
|
||||||
// Indicates the Kind of view on the front-end (Listing, editor or preview).
|
|
||||||
Kind string `json:"kind"`
|
|
||||||
// The name of the file.
|
|
||||||
Name string `json:"name"`
|
|
||||||
// The Size of the file.
|
|
||||||
Size int64 `json:"size"`
|
|
||||||
// The absolute URL.
|
|
||||||
URL string `json:"url"`
|
|
||||||
// The extension of the file.
|
|
||||||
Extension string `json:"extension"`
|
|
||||||
// The last modified time.
|
|
||||||
ModTime time.Time `json:"modified"`
|
|
||||||
// The File Mode.
|
|
||||||
Mode os.FileMode `json:"mode"`
|
|
||||||
// Indicates if this file is a directory.
|
|
||||||
IsDir bool `json:"isDir"`
|
|
||||||
// Absolute path.
|
|
||||||
Path string `json:"path"`
|
|
||||||
// Relative path to user's virtual File System.
|
|
||||||
VirtualPath string `json:"virtualPath"`
|
|
||||||
// Indicates the file content type: video, text, image, music or blob.
|
|
||||||
Type string `json:"type"`
|
|
||||||
// Stores the content of a text file.
|
|
||||||
Content string `json:"content,omitempty"`
|
|
||||||
|
|
||||||
*Listing `json:",omitempty"`
|
|
||||||
|
|
||||||
Metadata string `json:"metadata,omitempty"`
|
|
||||||
Language string `json:"language,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Listing is the context used to fill out a template.
|
|
||||||
type Listing struct {
|
|
||||||
// The items (files and folders) in the path.
|
|
||||||
Items []*File `json:"items"`
|
|
||||||
// The number of directories in the Listing.
|
|
||||||
NumDirs int `json:"numDirs"`
|
|
||||||
// The number of files (items that aren't directories) in the Listing.
|
|
||||||
NumFiles int `json:"numFiles"`
|
|
||||||
// Which sorting order is used.
|
|
||||||
Sort string `json:"sort"`
|
|
||||||
// And which order.
|
|
||||||
Order string `json:"order"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInfo gets the file information and, in case of error, returns the
|
|
||||||
// respective HTTP error code
|
|
||||||
func GetInfo(url *url.URL, c *FileBrowser, u *User) (*File, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
i := &File{
|
|
||||||
URL: "/files" + url.String(),
|
|
||||||
VirtualPath: url.Path,
|
|
||||||
Path: filepath.Join(u.Scope, url.Path),
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := u.FileSystem.Stat(url.Path)
|
|
||||||
if err != nil {
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Name = info.Name()
|
|
||||||
i.ModTime = info.ModTime()
|
|
||||||
i.Mode = info.Mode()
|
|
||||||
i.IsDir = info.IsDir()
|
|
||||||
i.Size = info.Size()
|
|
||||||
i.Extension = filepath.Ext(i.Name)
|
|
||||||
|
|
||||||
if i.IsDir && !strings.HasSuffix(i.URL, "/") {
|
|
||||||
i.URL += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
return i, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetListing gets the information about a specific directory and its files.
|
|
||||||
func (i *File) GetListing(u *User, r *http.Request) error {
|
|
||||||
// Gets the directory information using the Virtual File System of
|
|
||||||
// the user configuration.
|
|
||||||
f, err := u.FileSystem.OpenFile(i.VirtualPath, os.O_RDONLY, 0)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
// Reads the directory and gets the information about the files.
|
|
||||||
files, err := f.Readdir(-1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
fileinfos []*File
|
|
||||||
dirCount, fileCount int
|
|
||||||
)
|
|
||||||
|
|
||||||
baseurl, err := url.PathUnescape(i.URL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, f := range files {
|
|
||||||
name := f.Name()
|
|
||||||
allowed := u.Allowed("/" + name)
|
|
||||||
|
|
||||||
if !allowed {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(f.Mode().String(), "L") {
|
|
||||||
// It's a symbolic link. We try to follow it. If it doesn't work,
|
|
||||||
// we stay with the link information instead if the target's.
|
|
||||||
info, err := os.Stat(f.Name())
|
|
||||||
if err == nil {
|
|
||||||
f = info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.IsDir() {
|
|
||||||
name += "/"
|
|
||||||
dirCount++
|
|
||||||
} else {
|
|
||||||
fileCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Absolute URL
|
|
||||||
url := url.URL{Path: baseurl + name}
|
|
||||||
|
|
||||||
i := &File{
|
|
||||||
Name: f.Name(),
|
|
||||||
Size: f.Size(),
|
|
||||||
ModTime: f.ModTime(),
|
|
||||||
Mode: f.Mode(),
|
|
||||||
IsDir: f.IsDir(),
|
|
||||||
URL: url.String(),
|
|
||||||
Extension: filepath.Ext(name),
|
|
||||||
VirtualPath: filepath.Join(i.VirtualPath, name),
|
|
||||||
Path: filepath.Join(i.Path, name),
|
|
||||||
}
|
|
||||||
|
|
||||||
i.GetFileType(false)
|
|
||||||
fileinfos = append(fileinfos, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Listing = &Listing{
|
|
||||||
Items: fileinfos,
|
|
||||||
NumDirs: dirCount,
|
|
||||||
NumFiles: fileCount,
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetEditor gets the editor based on a Info struct
|
|
||||||
func (i *File) GetEditor() error {
|
|
||||||
i.Language = editorLanguage(i.Extension)
|
|
||||||
// If the editor will hold only content, leave now.
|
|
||||||
if editorMode(i.Language) == "content" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the file doesn't have any kind of metadata, leave now.
|
|
||||||
if !hasRune(i.Content) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer := bytes.NewBuffer([]byte(i.Content))
|
|
||||||
page, err := parser.ReadFrom(buffer)
|
|
||||||
|
|
||||||
// If there is an error, just ignore it and return nil.
|
|
||||||
// This way, the file can be served for editing.
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Content = strings.TrimSpace(string(page.Content()))
|
|
||||||
i.Metadata = strings.TrimSpace(string(page.FrontMatter()))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFileType obtains the mimetype and converts it to a simple
|
|
||||||
// type nomenclature.
|
|
||||||
func (i *File) GetFileType(checkContent bool) error {
|
|
||||||
var content []byte
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Tries to get the file mimetype using its extension.
|
|
||||||
mimetype := mime.TypeByExtension(i.Extension)
|
|
||||||
|
|
||||||
if mimetype == "" && checkContent {
|
|
||||||
file, err := os.Open(i.Path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// Only the first 512 bytes are used to sniff the content type.
|
|
||||||
buffer := make([]byte, 512)
|
|
||||||
_, err = file.Read(buffer)
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tries to get the file mimetype using its first
|
|
||||||
// 512 bytes.
|
|
||||||
mimetype = http.DetectContentType(buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(mimetype, "video") {
|
|
||||||
i.Type = "video"
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(mimetype, "audio") {
|
|
||||||
i.Type = "audio"
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(mimetype, "image") {
|
|
||||||
i.Type = "image"
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(mimetype, "text") {
|
|
||||||
i.Type = "text"
|
|
||||||
goto End
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(mimetype, "application/javascript") {
|
|
||||||
i.Type = "text"
|
|
||||||
goto End
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the type isn't text (and is blob for example), it will check some
|
|
||||||
// common types that are mistaken not to be text.
|
|
||||||
if isInTextExtensions(i.Name) {
|
|
||||||
i.Type = "text"
|
|
||||||
} else {
|
|
||||||
i.Type = "blob"
|
|
||||||
}
|
|
||||||
|
|
||||||
End:
|
|
||||||
// If the file type is text, save its content.
|
|
||||||
if i.Type == "text" {
|
|
||||||
if len(content) == 0 {
|
|
||||||
content, err = ioutil.ReadFile(i.Path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Content = string(content)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checksum retrieves the checksum of a file.
|
|
||||||
func (i File) Checksum(algo string) (string, error) {
|
|
||||||
file, err := os.Open(i.Path)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
var h hash.Hash
|
|
||||||
|
|
||||||
switch algo {
|
|
||||||
case "md5":
|
|
||||||
h = md5.New()
|
|
||||||
case "sha1":
|
|
||||||
h = sha1.New()
|
|
||||||
case "sha256":
|
|
||||||
h = sha256.New()
|
|
||||||
case "sha512":
|
|
||||||
h = sha512.New()
|
|
||||||
default:
|
|
||||||
return "", ErrInvalidOption
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = io.Copy(h, file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return hex.EncodeToString(h.Sum(nil)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanBeEdited checks if the extension of a file is supported by the editor
|
|
||||||
func (i File) CanBeEdited() bool {
|
|
||||||
return i.Type == "text"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplySort applies the sort order using .Order and .Sort
|
|
||||||
func (l Listing) ApplySort() {
|
|
||||||
// Check '.Order' to know how to sort
|
|
||||||
if l.Order == "desc" {
|
|
||||||
switch l.Sort {
|
|
||||||
case "name":
|
|
||||||
sort.Sort(sort.Reverse(byName(l)))
|
|
||||||
case "size":
|
|
||||||
sort.Sort(sort.Reverse(bySize(l)))
|
|
||||||
case "modified":
|
|
||||||
sort.Sort(sort.Reverse(byModified(l)))
|
|
||||||
default:
|
|
||||||
// If not one of the above, do nothing
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else { // If we had more Orderings we could add them here
|
|
||||||
switch l.Sort {
|
|
||||||
case "name":
|
|
||||||
sort.Sort(byName(l))
|
|
||||||
case "size":
|
|
||||||
sort.Sort(bySize(l))
|
|
||||||
case "modified":
|
|
||||||
sort.Sort(byModified(l))
|
|
||||||
default:
|
|
||||||
sort.Sort(byName(l))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement sorting for Listing
|
|
||||||
type byName Listing
|
|
||||||
type bySize Listing
|
|
||||||
type byModified Listing
|
|
||||||
|
|
||||||
// By Name
|
|
||||||
func (l byName) Len() int {
|
|
||||||
return len(l.Items)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l byName) Swap(i, j int) {
|
|
||||||
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Treat upper and lower case equally
|
|
||||||
func (l byName) Less(i, j int) bool {
|
|
||||||
if l.Items[i].IsDir && !l.Items[j].IsDir {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !l.Items[i].IsDir && l.Items[j].IsDir {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return natural.Less(l.Items[i].Name, l.Items[j].Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// By Size
|
|
||||||
func (l bySize) Len() int {
|
|
||||||
return len(l.Items)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l bySize) Swap(i, j int) {
|
|
||||||
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
const directoryOffset = -1 << 31 // = math.MinInt32
|
|
||||||
func (l bySize) Less(i, j int) bool {
|
|
||||||
iSize, jSize := l.Items[i].Size, l.Items[j].Size
|
|
||||||
if l.Items[i].IsDir {
|
|
||||||
iSize = directoryOffset + iSize
|
|
||||||
}
|
|
||||||
if l.Items[j].IsDir {
|
|
||||||
jSize = directoryOffset + jSize
|
|
||||||
}
|
|
||||||
return iSize < jSize
|
|
||||||
}
|
|
||||||
|
|
||||||
// By Modified
|
|
||||||
func (l byModified) Len() int {
|
|
||||||
return len(l.Items)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l byModified) Swap(i, j int) {
|
|
||||||
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l byModified) Less(i, j int) bool {
|
|
||||||
iModified, jModified := l.Items[i].ModTime, l.Items[j].ModTime
|
|
||||||
return iModified.Sub(jModified) < 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// textExtensions is the sorted list of text extensions which
|
|
||||||
// can be edited.
|
|
||||||
var textExtensions = []string{
|
|
||||||
".ad", ".ada", ".adoc", ".asciidoc",
|
|
||||||
".bas", ".bash", ".bat",
|
|
||||||
".c", ".cc", ".cmd", ".conf", ".cpp", ".cr", ".cs", ".css", ".csv",
|
|
||||||
".d",
|
|
||||||
".f", ".f90",
|
|
||||||
".h", ".hh", ".hpp", ".htaccess", ".html",
|
|
||||||
".ini",
|
|
||||||
".java", ".js", ".json",
|
|
||||||
".markdown", ".md", ".mdown", ".mmark",
|
|
||||||
".nim",
|
|
||||||
".php", ".pl", ".ps1", ".py",
|
|
||||||
".rss", ".rst", ".rtf",
|
|
||||||
".sass", ".scss", ".sh", ".sty",
|
|
||||||
".tex", ".tml", ".toml", ".txt",
|
|
||||||
".vala", ".vapi",
|
|
||||||
".xml",
|
|
||||||
".yaml", ".yml",
|
|
||||||
"Caddyfile",
|
|
||||||
}
|
|
||||||
|
|
||||||
// isInTextExtensions checks if a file can be edited by its extensions.
|
|
||||||
func isInTextExtensions(name string) bool {
|
|
||||||
search := filepath.Ext(name)
|
|
||||||
if search == "" {
|
|
||||||
search = name
|
|
||||||
}
|
|
||||||
|
|
||||||
i := sort.SearchStrings(textExtensions, search)
|
|
||||||
return i < len(textExtensions) && textExtensions[i] == search
|
|
||||||
}
|
|
||||||
|
|
||||||
// hasRune checks if the file has the frontmatter rune
|
|
||||||
func hasRune(file string) bool {
|
|
||||||
return strings.HasPrefix(file, "---") ||
|
|
||||||
strings.HasPrefix(file, "+++") ||
|
|
||||||
strings.HasPrefix(file, "{")
|
|
||||||
}
|
|
||||||
|
|
||||||
func editorMode(language string) string {
|
|
||||||
switch language {
|
|
||||||
case "markdown", "asciidoc", "rst":
|
|
||||||
return "content+metadata"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "content"
|
|
||||||
}
|
|
||||||
|
|
||||||
func editorLanguage(mode string) string {
|
|
||||||
mode = strings.TrimPrefix(mode, ".")
|
|
||||||
|
|
||||||
switch mode {
|
|
||||||
case "md", "markdown", "mdown", "mmark":
|
|
||||||
mode = "markdown"
|
|
||||||
case "yml":
|
|
||||||
mode = "yaml"
|
|
||||||
case "asciidoc", "adoc", "ad":
|
|
||||||
mode = "asciidoc"
|
|
||||||
case "rst":
|
|
||||||
mode = "rst"
|
|
||||||
case "html", "htm", "xml":
|
|
||||||
mode = "htmlmixed"
|
|
||||||
case "js":
|
|
||||||
mode = "javascript"
|
|
||||||
case "go":
|
|
||||||
mode = "golang"
|
|
||||||
case "":
|
|
||||||
mode = "text"
|
|
||||||
}
|
|
||||||
|
|
||||||
return mode
|
|
||||||
}
|
|
||||||
@@ -1,568 +0,0 @@
|
|||||||
package filebrowser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"reflect"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
|
|
||||||
"github.com/GeertJohan/go.rice"
|
|
||||||
"github.com/hacdias/fileutils"
|
|
||||||
"github.com/mholt/caddy"
|
|
||||||
"github.com/robfig/cron"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Version is the current File Browser version.
|
|
||||||
Version = "v1.10.0"
|
|
||||||
|
|
||||||
ListViewMode = "list"
|
|
||||||
MosaicViewMode = "mosaic"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrExist = errors.New("the resource already exists")
|
|
||||||
ErrNotExist = errors.New("the resource does not exist")
|
|
||||||
ErrEmptyRequest = errors.New("request body is empty")
|
|
||||||
ErrEmptyPassword = errors.New("password is empty")
|
|
||||||
ErrEmptyUsername = errors.New("username is empty")
|
|
||||||
ErrEmptyScope = errors.New("scope is empty")
|
|
||||||
ErrWrongDataType = errors.New("wrong data type")
|
|
||||||
ErrInvalidUpdateField = errors.New("invalid field to update")
|
|
||||||
ErrInvalidOption = errors.New("invalid option")
|
|
||||||
)
|
|
||||||
|
|
||||||
// FileBrowser is a file manager instance. It should be creating using the
|
|
||||||
// 'New' function and not directly.
|
|
||||||
type FileBrowser struct {
|
|
||||||
// Cron job to manage schedulings.
|
|
||||||
Cron *cron.Cron
|
|
||||||
|
|
||||||
// The key used to sign the JWT tokens.
|
|
||||||
Key []byte
|
|
||||||
|
|
||||||
// The static assets.
|
|
||||||
Assets *rice.Box
|
|
||||||
|
|
||||||
// The Store is used to manage users, shareable links and
|
|
||||||
// other stuff that is saved on the database.
|
|
||||||
Store *Store
|
|
||||||
|
|
||||||
// PrefixURL is a part of the URL that is already trimmed from the request URL before it
|
|
||||||
// arrives to our handlers. It may be useful when using File Browser as a middleware
|
|
||||||
// such as in caddy-filemanager plugin. It is only useful in certain situations.
|
|
||||||
PrefixURL string
|
|
||||||
|
|
||||||
// BaseURL is the path where the GUI will be accessible. It musn't end with
|
|
||||||
// a trailing slash and mustn't contain PrefixURL, if set. It shouldn't be
|
|
||||||
// edited directly. Use SetBaseURL.
|
|
||||||
BaseURL string
|
|
||||||
|
|
||||||
// NoAuth disables the authentication. When the authentication is disabled,
|
|
||||||
// there will only exist one user, called "admin".
|
|
||||||
NoAuth bool
|
|
||||||
|
|
||||||
// Define if which of the following authentication mechansims should be used:
|
|
||||||
// - 'default', which requires a user and a password.
|
|
||||||
// - 'proxy', which requires a valid user and the user name has to be provided through an
|
|
||||||
// http header.
|
|
||||||
// - 'none', which allows anyone to access the filebrowser instance.
|
|
||||||
AuthMethod string
|
|
||||||
|
|
||||||
// When 'AuthMethod' is set to 'proxy' the header configured below is used to identify the user.
|
|
||||||
LoginHeader string
|
|
||||||
|
|
||||||
// ReCaptcha host, key and secret.
|
|
||||||
ReCaptchaHost string
|
|
||||||
ReCaptchaKey string
|
|
||||||
ReCaptchaSecret string
|
|
||||||
|
|
||||||
// StaticGen is the static websit generator handler.
|
|
||||||
StaticGen StaticGen
|
|
||||||
|
|
||||||
// The Default User needed to build the New User page.
|
|
||||||
DefaultUser *User
|
|
||||||
|
|
||||||
// A map of events to a slice of commands.
|
|
||||||
Commands map[string][]string
|
|
||||||
|
|
||||||
// Global stylesheet.
|
|
||||||
CSS string
|
|
||||||
|
|
||||||
// NewFS should build a new file system for a given path.
|
|
||||||
NewFS FSBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
var commandEvents = []string{
|
|
||||||
"before_save",
|
|
||||||
"after_save",
|
|
||||||
"before_publish",
|
|
||||||
"after_publish",
|
|
||||||
"before_copy",
|
|
||||||
"after_copy",
|
|
||||||
"before_rename",
|
|
||||||
"after_rename",
|
|
||||||
"before_upload",
|
|
||||||
"after_upload",
|
|
||||||
"before_delete",
|
|
||||||
"after_delete",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command is a command function.
|
|
||||||
type Command func(r *http.Request, m *FileBrowser, u *User) error
|
|
||||||
|
|
||||||
// FSBuilder is the File System Builder.
|
|
||||||
type FSBuilder func(scope string) FileSystem
|
|
||||||
|
|
||||||
// Setup loads the configuration from the database and configures
|
|
||||||
// the Assets and the Cron job. It must always be run after
|
|
||||||
// creating a File Browser object.
|
|
||||||
func (m *FileBrowser) Setup() error {
|
|
||||||
// Creates a new File Browser instance with the Users
|
|
||||||
// map and Assets box.
|
|
||||||
m.Assets = rice.MustFindBox("./frontend/dist")
|
|
||||||
m.Cron = cron.New()
|
|
||||||
|
|
||||||
// Tries to get the encryption key from the database.
|
|
||||||
// If it doesn't exist, create a new one of 256 bits.
|
|
||||||
err := m.Store.Config.Get("key", &m.Key)
|
|
||||||
if err != nil && err == ErrNotExist {
|
|
||||||
var bytes []byte
|
|
||||||
bytes, err = GenerateRandomBytes(64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Key = bytes
|
|
||||||
err = m.Store.Config.Save("key", m.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the global CSS.
|
|
||||||
err = m.Store.Config.Get("css", &m.CSS)
|
|
||||||
if err != nil && err == ErrNotExist {
|
|
||||||
err = m.Store.Config.Save("css", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tries to get the event commands from the database.
|
|
||||||
// If they don't exist, initialize them.
|
|
||||||
err = m.Store.Config.Get("commands", &m.Commands)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// Add hypothetically new command handlers.
|
|
||||||
for _, command := range commandEvents {
|
|
||||||
if _, ok := m.Commands[command]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Commands[command] = []string{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil && err == ErrNotExist {
|
|
||||||
m.Commands = map[string][]string{}
|
|
||||||
|
|
||||||
// Initialize the command handlers.
|
|
||||||
for _, command := range commandEvents {
|
|
||||||
m.Commands[command] = []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = m.Store.Config.Save("commands", m.Commands)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tries to fetch the users from the database.
|
|
||||||
users, err := m.Store.Users.Gets(m.NewFS)
|
|
||||||
if err != nil && err != ErrNotExist {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no users in the database, it creates a new one
|
|
||||||
// based on 'base' User that must be provided by the function caller.
|
|
||||||
if len(users) == 0 {
|
|
||||||
u := *m.DefaultUser
|
|
||||||
u.Username = "admin"
|
|
||||||
|
|
||||||
// Hashes the password.
|
|
||||||
u.Password, err = HashPassword("admin")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// The first user must be an administrator.
|
|
||||||
u.Admin = true
|
|
||||||
u.AllowCommands = true
|
|
||||||
u.AllowNew = true
|
|
||||||
u.AllowEdit = true
|
|
||||||
u.AllowPublish = true
|
|
||||||
|
|
||||||
// Saves the user to the database.
|
|
||||||
if err := m.Store.Users.Save(&u); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.DefaultUser.Username = ""
|
|
||||||
m.DefaultUser.Password = ""
|
|
||||||
|
|
||||||
m.Cron.AddFunc("@hourly", m.ShareCleaner)
|
|
||||||
m.Cron.Start()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RootURL returns the actual URL where
|
|
||||||
// File Browser interface can be accessed.
|
|
||||||
func (m FileBrowser) RootURL() string {
|
|
||||||
return m.PrefixURL + m.BaseURL
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPrefixURL updates the prefixURL of a File
|
|
||||||
// Manager object.
|
|
||||||
func (m *FileBrowser) SetPrefixURL(url string) {
|
|
||||||
url = strings.TrimPrefix(url, "/")
|
|
||||||
url = strings.TrimSuffix(url, "/")
|
|
||||||
url = "/" + url
|
|
||||||
m.PrefixURL = strings.TrimSuffix(url, "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBaseURL updates the baseURL of a File Browser
|
|
||||||
// object.
|
|
||||||
func (m *FileBrowser) SetBaseURL(url string) {
|
|
||||||
url = strings.TrimPrefix(url, "/")
|
|
||||||
url = strings.TrimSuffix(url, "/")
|
|
||||||
url = "/" + url
|
|
||||||
m.BaseURL = strings.TrimSuffix(url, "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attach attaches a static generator to the current File Browser.
|
|
||||||
func (m *FileBrowser) Attach(s StaticGen) error {
|
|
||||||
if reflect.TypeOf(s).Kind() != reflect.Ptr {
|
|
||||||
return errors.New("data should be a pointer to interface, not interface")
|
|
||||||
}
|
|
||||||
|
|
||||||
err := s.Setup()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
m.StaticGen = s
|
|
||||||
|
|
||||||
err = m.Store.Config.Get("staticgen_"+s.Name(), s)
|
|
||||||
if err == ErrNotExist {
|
|
||||||
return m.Store.Config.Save("staticgen_"+s.Name(), s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShareCleaner removes sharing links that are no longer active.
|
|
||||||
// This function is set to run periodically.
|
|
||||||
func (m FileBrowser) ShareCleaner() {
|
|
||||||
// Get all links.
|
|
||||||
links, err := m.Store.Share.Gets()
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the expired ones.
|
|
||||||
for i := range links {
|
|
||||||
if links[i].Expires && links[i].ExpireDate.Before(time.Now()) {
|
|
||||||
err = m.Store.Share.Delete(links[i].Hash)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Runner runs the commands for a certain event type.
|
|
||||||
func (m FileBrowser) Runner(event string, path string, destination string, user *User) error {
|
|
||||||
commands := []string{}
|
|
||||||
|
|
||||||
// Get the commands from the File Browser instance itself.
|
|
||||||
if val, ok := m.Commands[event]; ok {
|
|
||||||
commands = append(commands, val...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the commands.
|
|
||||||
for _, command := range commands {
|
|
||||||
args := strings.Split(command, " ")
|
|
||||||
nonblock := false
|
|
||||||
|
|
||||||
if len(args) > 1 && args[len(args)-1] == "&" {
|
|
||||||
// Run command in background; non-blocking
|
|
||||||
nonblock = true
|
|
||||||
args = args[:len(args)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
command, args, err := caddy.SplitCommandAndArgs(strings.Join(args, " "))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(command, args...)
|
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("FILE=%s", path))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("ROOT=%s", user.Scope))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("TRIGGER=%s", event))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("USERNAME=%s", user.Username))
|
|
||||||
|
|
||||||
if destination != "" {
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("DESTINATION=%s", destination))
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
|
|
||||||
if nonblock {
|
|
||||||
log.Printf("[INFO] Nonblocking Command:\"%s %s\"", command, strings.Join(args, " "))
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[INFO] Blocking Command:\"%s %s\"", command, strings.Join(args, " "))
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultUser is used on New, when no 'base' user is provided.
|
|
||||||
var DefaultUser = User{
|
|
||||||
AllowCommands: true,
|
|
||||||
AllowEdit: true,
|
|
||||||
AllowNew: true,
|
|
||||||
AllowPublish: true,
|
|
||||||
LockPassword: false,
|
|
||||||
Commands: []string{},
|
|
||||||
Rules: []*Rule{},
|
|
||||||
CSS: "",
|
|
||||||
Admin: true,
|
|
||||||
Locale: "",
|
|
||||||
Scope: ".",
|
|
||||||
FileSystem: fileutils.Dir("."),
|
|
||||||
ViewMode: "mosaic",
|
|
||||||
}
|
|
||||||
|
|
||||||
// User contains the configuration for each user.
|
|
||||||
type User struct {
|
|
||||||
// ID is the required primary key with auto increment0
|
|
||||||
ID int `storm:"id,increment"`
|
|
||||||
|
|
||||||
// Tells if this user is an admin.
|
|
||||||
Admin bool `json:"admin"`
|
|
||||||
|
|
||||||
// These indicate if the user can perform certain actions.
|
|
||||||
AllowCommands bool `json:"allowCommands"` // Execute commands
|
|
||||||
AllowEdit bool `json:"allowEdit"` // Edit/rename files
|
|
||||||
AllowNew bool `json:"allowNew"` // Create files and folders
|
|
||||||
AllowPublish bool `json:"allowPublish"` // Publish content (to use with static gen)
|
|
||||||
|
|
||||||
// Prevents the user to change its password.
|
|
||||||
LockPassword bool `json:"lockPassword"`
|
|
||||||
|
|
||||||
// Commands is the list of commands the user can execute.
|
|
||||||
Commands []string `json:"commands"`
|
|
||||||
|
|
||||||
// Custom styles for this user.
|
|
||||||
CSS string `json:"css"`
|
|
||||||
|
|
||||||
// FileSystem is the virtual file system the user has access.
|
|
||||||
FileSystem FileSystem `json:"-"`
|
|
||||||
|
|
||||||
// Locale is the language of the user.
|
|
||||||
Locale string `json:"locale"`
|
|
||||||
|
|
||||||
// The hashed password. This never reaches the front-end because it's temporarily
|
|
||||||
// emptied during JSON marshall.
|
|
||||||
Password string `json:"password"`
|
|
||||||
|
|
||||||
// Rules is an array of access and deny rules.
|
|
||||||
Rules []*Rule `json:"rules"`
|
|
||||||
|
|
||||||
// Scope is the path the user has access to.
|
|
||||||
Scope string `json:"filesystem"`
|
|
||||||
|
|
||||||
// Username is the user username used to login.
|
|
||||||
Username string `json:"username" storm:"index,unique"`
|
|
||||||
|
|
||||||
// User view mode for files and folders.
|
|
||||||
ViewMode string `json:"viewMode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allowed checks if the user has permission to access a directory/file.
|
|
||||||
func (u User) Allowed(url string) bool {
|
|
||||||
var rule *Rule
|
|
||||||
i := len(u.Rules) - 1
|
|
||||||
|
|
||||||
for i >= 0 {
|
|
||||||
rule = u.Rules[i]
|
|
||||||
|
|
||||||
if rule.Regex {
|
|
||||||
if rule.Regexp.MatchString(url) {
|
|
||||||
return rule.Allow
|
|
||||||
}
|
|
||||||
} else if strings.HasPrefix(url, rule.Path) {
|
|
||||||
return rule.Allow
|
|
||||||
}
|
|
||||||
|
|
||||||
i--
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rule is a dissalow/allow rule.
|
|
||||||
type Rule struct {
|
|
||||||
// Regex indicates if this rule uses Regular Expressions or not.
|
|
||||||
Regex bool `json:"regex"`
|
|
||||||
|
|
||||||
// Allow indicates if this is an allow rule. Set 'false' to be a disallow rule.
|
|
||||||
Allow bool `json:"allow"`
|
|
||||||
|
|
||||||
// Path is the corresponding URL path for this rule.
|
|
||||||
Path string `json:"path"`
|
|
||||||
|
|
||||||
// Regexp is the regular expression. Only use this when 'Regex' was set to true.
|
|
||||||
Regexp *Regexp `json:"regexp"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regexp is a regular expression wrapper around native regexp.
|
|
||||||
type Regexp struct {
|
|
||||||
Raw string `json:"raw"`
|
|
||||||
regexp *regexp.Regexp
|
|
||||||
}
|
|
||||||
|
|
||||||
// MatchString checks if this string matches the regular expression.
|
|
||||||
func (r *Regexp) MatchString(s string) bool {
|
|
||||||
if r.regexp == nil {
|
|
||||||
r.regexp = regexp.MustCompile(r.Raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.regexp.MatchString(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShareLink is the information needed to build a shareable link.
|
|
||||||
type ShareLink struct {
|
|
||||||
Hash string `json:"hash" storm:"id,index"`
|
|
||||||
Path string `json:"path" storm:"index"`
|
|
||||||
Expires bool `json:"expires"`
|
|
||||||
ExpireDate time.Time `json:"expireDate"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store is a collection of the stores needed to get
|
|
||||||
// and save information.
|
|
||||||
type Store struct {
|
|
||||||
Users UsersStore
|
|
||||||
Config ConfigStore
|
|
||||||
Share ShareStore
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsersStore is the interface to manage users.
|
|
||||||
type UsersStore interface {
|
|
||||||
Get(id int, builder FSBuilder) (*User, error)
|
|
||||||
GetByUsername(username string, builder FSBuilder) (*User, error)
|
|
||||||
Gets(builder FSBuilder) ([]*User, error)
|
|
||||||
Save(u *User) error
|
|
||||||
Update(u *User, fields ...string) error
|
|
||||||
Delete(id int) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigStore is the interface to manage configuration.
|
|
||||||
type ConfigStore interface {
|
|
||||||
Get(name string, to interface{}) error
|
|
||||||
Save(name string, from interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShareStore is the interface to manage share links.
|
|
||||||
type ShareStore interface {
|
|
||||||
Get(hash string) (*ShareLink, error)
|
|
||||||
GetPermanent(path string) (*ShareLink, error)
|
|
||||||
GetByPath(path string) ([]*ShareLink, error)
|
|
||||||
Gets() ([]*ShareLink, error)
|
|
||||||
Save(s *ShareLink) error
|
|
||||||
Delete(hash string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// StaticGen is a static website generator.
|
|
||||||
type StaticGen interface {
|
|
||||||
SettingsPath() string
|
|
||||||
Name() string
|
|
||||||
Setup() error
|
|
||||||
|
|
||||||
Hook(c *Context, w http.ResponseWriter, r *http.Request) (int, error)
|
|
||||||
Preview(c *Context, w http.ResponseWriter, r *http.Request) (int, error)
|
|
||||||
Publish(c *Context, w http.ResponseWriter, r *http.Request) (int, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileSystem is the interface to work with the file system.
|
|
||||||
type FileSystem interface {
|
|
||||||
Mkdir(name string, perm os.FileMode) error
|
|
||||||
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
|
|
||||||
RemoveAll(name string) error
|
|
||||||
Rename(oldName, newName string) error
|
|
||||||
Stat(name string) (os.FileInfo, error)
|
|
||||||
Copy(src, dst string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Context contains the needed information to make handlers work.
|
|
||||||
type Context struct {
|
|
||||||
*FileBrowser
|
|
||||||
User *User
|
|
||||||
File *File
|
|
||||||
// On API handlers, Router is the APi handler we want.
|
|
||||||
Router string
|
|
||||||
}
|
|
||||||
|
|
||||||
// HashPassword generates an hash from a password using bcrypt.
|
|
||||||
func HashPassword(password string) (string, error) {
|
|
||||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
||||||
return string(bytes), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckPasswordHash compares a password with an hash to check if they match.
|
|
||||||
func CheckPasswordHash(password, hash string) bool {
|
|
||||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateRandomBytes returns securely generated random bytes.
|
|
||||||
// It will return an fm.Error if the system's secure random
|
|
||||||
// number generator fails to function correctly, in which
|
|
||||||
// case the caller should not continue.
|
|
||||||
func GenerateRandomBytes(n int) ([]byte, error) {
|
|
||||||
b := make([]byte, n)
|
|
||||||
_, err := rand.Read(b)
|
|
||||||
// Note that err == nil only if we read len(b) bytes.
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
|
"hash"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"mime"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/errors"
|
||||||
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileInfo describes a file.
|
||||||
|
type FileInfo struct {
|
||||||
|
*Listing
|
||||||
|
Fs afero.Fs `json:"-"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Extension string `json:"extension"`
|
||||||
|
ModTime time.Time `json:"modified"`
|
||||||
|
Mode os.FileMode `json:"mode"`
|
||||||
|
IsDir bool `json:"isDir"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Subtitles []string `json:"subtitles,omitempty"`
|
||||||
|
Content string `json:"content,omitempty"`
|
||||||
|
Checksums map[string]string `json:"checksums,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileOptions are the options when getting a file info.
|
||||||
|
type FileOptions struct {
|
||||||
|
Fs afero.Fs
|
||||||
|
Path string
|
||||||
|
Modify bool
|
||||||
|
Expand bool
|
||||||
|
Checker rules.Checker
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFileInfo creates a File object from a path and a given user. This File
|
||||||
|
// object will be automatically filled depending on if it is a directory
|
||||||
|
// or a file. If it's a video file, it will also detect any subtitles.
|
||||||
|
func NewFileInfo(opts FileOptions) (*FileInfo, error) {
|
||||||
|
if !opts.Checker.Check(opts.Path) {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := opts.Fs.Stat(opts.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
file := &FileInfo{
|
||||||
|
Fs: opts.Fs,
|
||||||
|
Path: opts.Path,
|
||||||
|
Name: info.Name(),
|
||||||
|
ModTime: info.ModTime(),
|
||||||
|
Mode: info.Mode(),
|
||||||
|
IsDir: info.IsDir(),
|
||||||
|
Size: info.Size(),
|
||||||
|
Extension: filepath.Ext(info.Name()),
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Expand {
|
||||||
|
if file.IsDir {
|
||||||
|
return file, file.readListing(opts.Checker)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = file.detectType(opts.Modify, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return file, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checksum checksums a given File for a given User, using a specific
|
||||||
|
// algorithm. The checksums data is saved on File object.
|
||||||
|
func (i *FileInfo) Checksum(algo string) error {
|
||||||
|
if i.IsDir {
|
||||||
|
return errors.ErrIsDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.Checksums == nil {
|
||||||
|
i.Checksums = map[string]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reader, err := i.Fs.Open(i.Path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
var h hash.Hash
|
||||||
|
|
||||||
|
switch algo {
|
||||||
|
case "md5":
|
||||||
|
h = md5.New()
|
||||||
|
case "sha1":
|
||||||
|
h = sha1.New()
|
||||||
|
case "sha256":
|
||||||
|
h = sha256.New()
|
||||||
|
case "sha512":
|
||||||
|
h = sha512.New()
|
||||||
|
default:
|
||||||
|
return errors.ErrInvalidOption
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(h, reader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Checksums[algo] = hex.EncodeToString(h.Sum(nil))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *FileInfo) detectType(modify, saveContent bool) error {
|
||||||
|
// failing to detect the type should not return error.
|
||||||
|
// imagine the situation where a file in a dir with thousands
|
||||||
|
// of files couldn't be opened: we'd have immediately
|
||||||
|
// a 500 even though it doesn't matter. So we just log it.
|
||||||
|
reader, err := i.Fs.Open(i.Path)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
i.Type = "blob"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
buffer := make([]byte, 512)
|
||||||
|
n, err := reader.Read(buffer)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
log.Print(err)
|
||||||
|
i.Type = "blob"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mimetype := mime.TypeByExtension(i.Extension)
|
||||||
|
if mimetype == "" {
|
||||||
|
mimetype = http.DetectContentType(buffer[:n])
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(mimetype, "video"):
|
||||||
|
i.Type = "video"
|
||||||
|
i.detectSubtitles()
|
||||||
|
return nil
|
||||||
|
case strings.HasPrefix(mimetype, "audio"):
|
||||||
|
i.Type = "audio"
|
||||||
|
return nil
|
||||||
|
case strings.HasPrefix(mimetype, "image"):
|
||||||
|
i.Type = "image"
|
||||||
|
return nil
|
||||||
|
case isBinary(buffer[:n], n) || i.Size > 10*1024*1024: // 10 MB
|
||||||
|
i.Type = "blob"
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
i.Type = "text"
|
||||||
|
|
||||||
|
if !modify {
|
||||||
|
i.Type = "textImmutable"
|
||||||
|
}
|
||||||
|
|
||||||
|
if saveContent {
|
||||||
|
afs := &afero.Afero{Fs: i.Fs}
|
||||||
|
content, err := afs.ReadFile(i.Path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Content = string(content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *FileInfo) detectSubtitles() {
|
||||||
|
if i.Type != "video" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Subtitles = []string{}
|
||||||
|
ext := filepath.Ext(i.Path)
|
||||||
|
|
||||||
|
// TODO: detect multiple languages. Base.Lang.vtt
|
||||||
|
|
||||||
|
path := strings.TrimSuffix(i.Path, ext) + ".vtt"
|
||||||
|
if _, err := i.Fs.Stat(path); err == nil {
|
||||||
|
i.Subtitles = append(i.Subtitles, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *FileInfo) readListing(checker rules.Checker) error {
|
||||||
|
afs := &afero.Afero{Fs: i.Fs}
|
||||||
|
dir, err := afs.ReadDir(i.Path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
listing := &Listing{
|
||||||
|
Items: []*FileInfo{},
|
||||||
|
NumDirs: 0,
|
||||||
|
NumFiles: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range dir {
|
||||||
|
name := f.Name()
|
||||||
|
path := path.Join(i.Path, name)
|
||||||
|
|
||||||
|
if !checker.Check(path) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(f.Mode().String(), "L") {
|
||||||
|
// It's a symbolic link. We try to follow it. If it doesn't work,
|
||||||
|
// we stay with the link information instead if the target's.
|
||||||
|
info, err := i.Fs.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
f = info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file := &FileInfo{
|
||||||
|
Fs: i.Fs,
|
||||||
|
Name: name,
|
||||||
|
Size: f.Size(),
|
||||||
|
ModTime: f.ModTime(),
|
||||||
|
Mode: f.Mode(),
|
||||||
|
IsDir: f.IsDir(),
|
||||||
|
Extension: filepath.Ext(name),
|
||||||
|
Path: path,
|
||||||
|
}
|
||||||
|
|
||||||
|
if file.IsDir {
|
||||||
|
listing.NumDirs++
|
||||||
|
} else {
|
||||||
|
listing.NumFiles++
|
||||||
|
|
||||||
|
err := file.detectType(true, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listing.Items = append(listing.Items, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Listing = listing
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/maruel/natural"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Listing is a collection of files.
|
||||||
|
type Listing struct {
|
||||||
|
Items []*FileInfo `json:"items"`
|
||||||
|
NumDirs int `json:"numDirs"`
|
||||||
|
NumFiles int `json:"numFiles"`
|
||||||
|
Sorting Sorting `json:"sorting"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplySort applies the sort order using .Order and .Sort
|
||||||
|
func (l Listing) ApplySort() {
|
||||||
|
// Check '.Order' to know how to sort
|
||||||
|
if !l.Sorting.Asc {
|
||||||
|
switch l.Sorting.By {
|
||||||
|
case "name":
|
||||||
|
sort.Sort(sort.Reverse(byName(l)))
|
||||||
|
case "size":
|
||||||
|
sort.Sort(sort.Reverse(bySize(l)))
|
||||||
|
case "modified":
|
||||||
|
sort.Sort(sort.Reverse(byModified(l)))
|
||||||
|
default:
|
||||||
|
// If not one of the above, do nothing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else { // If we had more Orderings we could add them here
|
||||||
|
switch l.Sorting.By {
|
||||||
|
case "name":
|
||||||
|
sort.Sort(byName(l))
|
||||||
|
case "size":
|
||||||
|
sort.Sort(bySize(l))
|
||||||
|
case "modified":
|
||||||
|
sort.Sort(byModified(l))
|
||||||
|
default:
|
||||||
|
sort.Sort(byName(l))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement sorting for Listing
|
||||||
|
type byName Listing
|
||||||
|
type bySize Listing
|
||||||
|
type byModified Listing
|
||||||
|
|
||||||
|
// By Name
|
||||||
|
func (l byName) Len() int {
|
||||||
|
return len(l.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l byName) Swap(i, j int) {
|
||||||
|
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Treat upper and lower case equally
|
||||||
|
func (l byName) Less(i, j int) bool {
|
||||||
|
if l.Items[i].IsDir && !l.Items[j].IsDir {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !l.Items[i].IsDir && l.Items[j].IsDir {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return natural.Less(strings.ToLower(l.Items[j].Name), strings.ToLower(l.Items[i].Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// By Size
|
||||||
|
func (l bySize) Len() int {
|
||||||
|
return len(l.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l bySize) Swap(i, j int) {
|
||||||
|
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
const directoryOffset = -1 << 31 // = math.MinInt32
|
||||||
|
func (l bySize) Less(i, j int) bool {
|
||||||
|
iSize, jSize := l.Items[i].Size, l.Items[j].Size
|
||||||
|
if l.Items[i].IsDir {
|
||||||
|
iSize = directoryOffset + iSize
|
||||||
|
}
|
||||||
|
if l.Items[j].IsDir {
|
||||||
|
jSize = directoryOffset + jSize
|
||||||
|
}
|
||||||
|
return iSize < jSize
|
||||||
|
}
|
||||||
|
|
||||||
|
// By Modified
|
||||||
|
func (l byModified) Len() int {
|
||||||
|
return len(l.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l byModified) Swap(i, j int) {
|
||||||
|
l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l byModified) Less(i, j int) bool {
|
||||||
|
iModified, jModified := l.Items[i].ModTime, l.Items[j].ModTime
|
||||||
|
return iModified.Sub(jModified) < 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package files
|
||||||
|
|
||||||
|
// Sorting contains a sorting order.
|
||||||
|
type Sorting struct {
|
||||||
|
By string `json:"by"`
|
||||||
|
Asc bool `json:"asc"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
func isBinary(content []byte, n int) bool {
|
||||||
|
maybeStr := string(content)
|
||||||
|
runeCnt := utf8.RuneCount(content)
|
||||||
|
runeIndex := 0
|
||||||
|
gotRuneErrCnt := 0
|
||||||
|
firstRuneErrIndex := -1
|
||||||
|
|
||||||
|
for _, b := range maybeStr {
|
||||||
|
// 8 and below are control chars (e.g. backspace, null, eof, etc)
|
||||||
|
if b <= 8 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0xFFFD(65533) is the "error" Rune or "Unicode replacement character"
|
||||||
|
// see https://golang.org/pkg/unicode/utf8/#pkg-constants
|
||||||
|
if b == 0xFFFD {
|
||||||
|
//if it is not the last (utf8.UTFMax - x) rune
|
||||||
|
if runeCnt > utf8.UTFMax && runeIndex < runeCnt-utf8.UTFMax {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
//else it is the last (utf8.UTFMax - x) rune
|
||||||
|
//there maybe Vxxx, VVxx, VVVx, thus, we may got max 3 0xFFFD rune (asume V is the byte we got)
|
||||||
|
//for Chinese, it can only be Vxx, VVx, we may got max 2 0xFFFD rune
|
||||||
|
gotRuneErrCnt++
|
||||||
|
|
||||||
|
//mark the first time
|
||||||
|
if firstRuneErrIndex == -1 {
|
||||||
|
firstRuneErrIndex = runeIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runeIndex++
|
||||||
|
}
|
||||||
|
|
||||||
|
//if last (utf8.UTFMax - x ) rune has the "error" Rune, but not all
|
||||||
|
if firstRuneErrIndex != -1 && gotRuneErrCnt != runeCnt-firstRuneErrIndex {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package fileutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Copy copies a file or folder from one place to another.
|
||||||
|
func Copy(fs afero.Fs, src, dst string) error {
|
||||||
|
if src = path.Clean("/" + src); src == "" {
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
if dst = path.Clean("/" + dst); dst == "" {
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
if src == "/" || dst == "/" {
|
||||||
|
// Prohibit copying from or to the virtual root directory.
|
||||||
|
return os.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
if dst == src {
|
||||||
|
return os.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := fs.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
return CopyDir(fs, src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
return CopyFile(fs, src, dst)
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package fileutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CopyDir copies a directory from source to dest and all
|
||||||
|
// of its sub-directories. It doesn't stop if it finds an error
|
||||||
|
// during the copy. Returns an error if any.
|
||||||
|
func CopyDir(fs afero.Fs, source string, dest string) error {
|
||||||
|
// Get properties of source.
|
||||||
|
srcinfo, err := fs.Stat(source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the destination directory.
|
||||||
|
err = fs.MkdirAll(dest, srcinfo.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, _ := fs.Open(source)
|
||||||
|
obs, err := dir.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var errs []error
|
||||||
|
|
||||||
|
for _, obj := range obs {
|
||||||
|
fsource := source + "/" + obj.Name()
|
||||||
|
fdest := dest + "/" + obj.Name()
|
||||||
|
|
||||||
|
if obj.IsDir() {
|
||||||
|
// Create sub-directories, recursively.
|
||||||
|
err = CopyDir(fs, fsource, fdest)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Perform the file copy.
|
||||||
|
err = CopyFile(fs, fsource, fdest)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errString string
|
||||||
|
for _, err := range errs {
|
||||||
|
errString += err.Error() + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
if errString != "" {
|
||||||
|
return errors.New(errString)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package fileutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CopyFile copies a file from source to dest and returns
|
||||||
|
// an error if any.
|
||||||
|
func CopyFile(fs afero.Fs, source string, dest string) error {
|
||||||
|
// Open the source file.
|
||||||
|
src, err := fs.Open(source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
// Makes the directory needed to create the dst
|
||||||
|
// file.
|
||||||
|
err = fs.MkdirAll(filepath.Dir(dest), 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the destination file.
|
||||||
|
dst, err := fs.Create(dest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dst.Close()
|
||||||
|
|
||||||
|
// Copy the contents of the file.
|
||||||
|
_, err = io.Copy(dst, src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the mode if the user can't
|
||||||
|
// open the file.
|
||||||
|
info, err := fs.Stat(source)
|
||||||
|
if err != nil {
|
||||||
|
err = fs.Chmod(dest, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/app'
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"name": "filebrowser-frontend",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"serve": "vue-cli-service serve",
|
||||||
|
"build": "vue-cli-service build",
|
||||||
|
"watch": "vue-cli-service build --watch",
|
||||||
|
"lint": "vue-cli-service lint --fix"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ace-builds": "^1.4.6",
|
||||||
|
"clipboard": "^2.0.4",
|
||||||
|
"js-base64": "^2.5.1",
|
||||||
|
"lodash.clonedeep": "^4.5.0",
|
||||||
|
"material-design-icons": "^3.0.1",
|
||||||
|
"moment": "^2.24.0",
|
||||||
|
"normalize.css": "^8.0.1",
|
||||||
|
"noty": "^3.2.0-beta",
|
||||||
|
"qrcode.vue": "^1.6.3",
|
||||||
|
"vue": "^2.6.10",
|
||||||
|
"vue-i18n": "^8.14.1",
|
||||||
|
"vue-router": "^3.1.3",
|
||||||
|
"vuex": "^3.1.1",
|
||||||
|
"vuex-router-sync": "^5.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vue/cli-plugin-babel": "^3.11.0",
|
||||||
|
"@vue/cli-plugin-eslint": "^3.11.0",
|
||||||
|
"@vue/cli-service": "^3.12.0",
|
||||||
|
"babel-eslint": "^10.0.3",
|
||||||
|
"eslint": "^5.16.0",
|
||||||
|
"eslint-plugin-vue": "^5.2.3",
|
||||||
|
"vue-template-compiler": "^2.6.10"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:vue/essential",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"rules": {},
|
||||||
|
"parserOptions": {
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postcss": {
|
||||||
|
"plugins": {
|
||||||
|
"autoprefixer": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions",
|
||||||
|
"not ie <= 8"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<browserconfig>
|
||||||
|
<msapplication>
|
||||||
|
<tile>
|
||||||
|
<square150x150logo src="/mstile-150x150.png"/>
|
||||||
|
<TileColor>#455a64</TileColor>
|
||||||
|
</tile>
|
||||||
|
</msapplication>
|
||||||
|
</browserconfig>
|
||||||
|
After Width: | Height: | Size: 843 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||||
|
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||||
|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="700.000000pt" height="700.000000pt" viewBox="0 0 700.000000 700.000000"
|
||||||
|
preserveAspectRatio="xMidYMid meet">
|
||||||
|
<metadata>
|
||||||
|
Created by potrace 1.11, written by Peter Selinger 2001-2013
|
||||||
|
</metadata>
|
||||||
|
<g transform="translate(0.000000,700.000000) scale(0.100000,-0.100000)"
|
||||||
|
fill="#000000" stroke="none">
|
||||||
|
<path d="M3245 6989 c-522 -39 -1042 -197 -1480 -449 -849 -488 -1459 -1308
|
||||||
|
-1673 -2250 -177 -776 -89 -1582 250 -2301 368 -778 1052 -1418 1857 -1739
|
||||||
|
903 -359 1927 -325 2812 92 778 368 1418 1052 1739 1857 359 903 325 1927 -92
|
||||||
|
2812 -296 627 -806 1175 -1423 1529 -587 338 -1308 500 -1990 449z m555 -580
|
||||||
|
c519 -51 1018 -245 1446 -565 788 -588 1229 -1526 1174 -2496 -16 -277 -58
|
||||||
|
-500 -145 -763 -144 -440 -378 -819 -710 -1150 -452 -452 -1005 -730 -1655
|
||||||
|
-832 -91 -14 -175 -18 -405 -18 -304 0 -369 6 -595 51 -1105 223 -1999 1092
|
||||||
|
-2259 2197 -52 221 -73 412 -73 667 0 397 64 732 204 1080 304 752 886 1334
|
||||||
|
1638 1638 431 174 895 238 1380 191z"/>
|
||||||
|
<path d="M2670 5215 c0 -13 -44 -15 -335 -15 -352 0 -383 -3 -399 -45 -3 -9
|
||||||
|
-6 -758 -6 -1663 0 -1168 -3 -1643 -11 -1632 -8 11 -9 8 -4 -15 3 -16 17 -41
|
||||||
|
31 -55 l24 -25 1530 0 1530 0 24 25 c14 14 26 36 27 50 1 14 1 711 1 1550 l-2
|
||||||
|
1526 -228 142 -229 142 -136 0 -137 0 0 -600 0 -600 -705 0 -705 0 0 615 0
|
||||||
|
615 -135 0 c-113 0 -135 -2 -135 -15z m-264 -190 c57 -29 89 -71 103 -137 35
|
||||||
|
-154 -98 -282 -258 -247 -55 12 -122 62 -148 113 -36 69 -12 186 49 243 62 58
|
||||||
|
170 70 254 28z m2316 -1702 c17 -15 18 -49 18 -670 l0 -653 -1245 0 -1245 0 0
|
||||||
|
654 c0 582 2 656 16 670 14 14 139 16 1226 16 1113 0 1213 -1 1230 -17z
|
||||||
|
m-2602 -1363 c40 -40 13 -100 -43 -100 -60 0 -88 59 -47 100 11 11 31 20 45
|
||||||
|
20 14 0 34 -9 45 -20z m2840 0 c41 -41 11 -100 -52 -100 -35 0 -58 24 -58 60
|
||||||
|
0 54 71 79 110 40z"/>
|
||||||
|
<path d="M2431 3091 c-7 -13 -7 -23 2 -35 11 -15 97 -16 1067 -14 l1055 3 0
|
||||||
|
30 0 30 -1057 3 c-1023 2 -1058 1 -1067 -17z"/>
|
||||||
|
<path d="M2436 2675 c-19 -19 -11 -41 17 -49 41 -11 2067 -7 2088 4 23 13 25
|
||||||
|
46 3 54 -9 3 -483 6 -1054 6 -919 0 -1040 -2 -1054 -15z"/>
|
||||||
|
<path d="M2447 2273 c-14 -4 -17 -13 -15 -36 l3 -32 1049 -3 c767 -1 1052 1
|
||||||
|
1062 9 20 16 17 47 -5 59 -20 10 -2055 13 -2094 3z"/>
|
||||||
|
<path d="M3822 5027 c-21 -23 -22 -30 -22 -293 0 -258 1 -271 20 -292 27 -29
|
||||||
|
56 -35 140 -30 56 3 75 8 93 26 22 22 22 26 22 298 l0 276 -24 19 c-19 16 -40
|
||||||
|
19 -115 19 -84 0 -95 -2 -114 -23z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,147 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xml:space="preserve"
|
||||||
|
width="560"
|
||||||
|
height="560"
|
||||||
|
version="1.1"
|
||||||
|
style="clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision"
|
||||||
|
viewBox="0 0 560 560"
|
||||||
|
id="svg44"
|
||||||
|
sodipodi:docname="icon_raw.svg"
|
||||||
|
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||||
|
inkscape:export-filename="/home/umarcor/filebrowser/logo/icon_raw.svg.png"
|
||||||
|
inkscape:export-xdpi="96"
|
||||||
|
inkscape:export-ydpi="96"><metadata
|
||||||
|
id="metadata48"><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1366"
|
||||||
|
inkscape:window-height="711"
|
||||||
|
id="namedview46"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="0.33714286"
|
||||||
|
inkscape:cx="-172.33051"
|
||||||
|
inkscape:cy="280"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="20"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg44" />
|
||||||
|
<defs
|
||||||
|
id="defs4">
|
||||||
|
<style
|
||||||
|
type="text/css"
|
||||||
|
id="style2">
|
||||||
|
<![CDATA[
|
||||||
|
.fil1 {fill:#FEFEFE}
|
||||||
|
.fil6 {fill:#006498}
|
||||||
|
.fil7 {fill:#0EA5EB}
|
||||||
|
.fil8 {fill:#2979FF}
|
||||||
|
.fil3 {fill:#2BBCFF}
|
||||||
|
.fil0 {fill:#455A64}
|
||||||
|
.fil4 {fill:#53C6FC}
|
||||||
|
.fil5 {fill:#BDEAFF}
|
||||||
|
.fil2 {fill:#332C2B;fill-opacity:0.149020}
|
||||||
|
]]>
|
||||||
|
</style>
|
||||||
|
</defs>
|
||||||
|
<g
|
||||||
|
id="g85"
|
||||||
|
transform="translate(-70,-70)"><path
|
||||||
|
class="fil1"
|
||||||
|
d="M 350,71 C 504,71 629,196 629,350 629,504 504,629 350,629 196,629 71,504 71,350 71,196 196,71 350,71 Z"
|
||||||
|
id="path9"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#fefefe" /><path
|
||||||
|
class="fil2"
|
||||||
|
d="M 475,236 593,387 C 596,503 444,639 301,585 L 225,486 339,330 c 0,0 138,-95 136,-94 z"
|
||||||
|
id="path11"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#332c2b;fill-opacity:0.14902003" /><path
|
||||||
|
class="fil3"
|
||||||
|
d="m 231,211 h 208 l 38,24 v 246 c 0,5 -3,8 -8,8 H 231 c -5,0 -8,-3 -8,-8 V 219 c 0,-5 3,-8 8,-8 z"
|
||||||
|
id="path13"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#2bbcff" /><path
|
||||||
|
class="fil4"
|
||||||
|
d="m 231,211 h 208 l 38,24 v 2 L 440,214 H 231 c -4,0 -7,3 -7,7 v 263 c -1,-1 -1,-2 -1,-3 V 219 c 0,-5 3,-8 8,-8 z"
|
||||||
|
id="path15"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#53c6fc" /><polygon
|
||||||
|
class="fil5"
|
||||||
|
points="305,212 418,212 418,310 305,310 "
|
||||||
|
id="polygon17"
|
||||||
|
style="fill:#bdeaff" /><path
|
||||||
|
class="fil5"
|
||||||
|
d="m 255,363 h 189 c 3,0 5,2 5,4 V 483 H 250 V 367 c 0,-2 2,-4 5,-4 z"
|
||||||
|
id="path19"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#bdeaff" /><polygon
|
||||||
|
class="fil6"
|
||||||
|
points="250,470 449,470 449,483 250,483 "
|
||||||
|
id="polygon21"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil6"
|
||||||
|
d="m 380,226 h 10 c 3,0 6,2 6,5 v 40 c 0,3 -3,6 -6,6 h -10 c -3,0 -6,-3 -6,-6 v -40 c 0,-3 3,-5 6,-5 z"
|
||||||
|
id="path23"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil1"
|
||||||
|
d="m 254,226 c 10,0 17,7 17,17 0,9 -7,16 -17,16 -9,0 -17,-7 -17,-16 0,-10 8,-17 17,-17 z"
|
||||||
|
id="path25"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#fefefe" /><path
|
||||||
|
class="fil6"
|
||||||
|
d="m 267,448 h 165 c 2,0 3,1 3,3 v 0 c 0,1 -1,3 -3,3 H 267 c -2,0 -3,-2 -3,-3 v 0 c 0,-2 1,-3 3,-3 z"
|
||||||
|
id="path27"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil6"
|
||||||
|
d="m 267,415 h 165 c 2,0 3,1 3,3 v 0 c 0,1 -1,2 -3,2 H 267 c -2,0 -3,-1 -3,-2 v 0 c 0,-2 1,-3 3,-3 z"
|
||||||
|
id="path29"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil6"
|
||||||
|
d="m 267,381 h 165 c 2,0 3,2 3,3 v 0 c 0,2 -1,3 -3,3 H 267 c -2,0 -3,-1 -3,-3 v 0 c 0,-1 1,-3 3,-3 z"
|
||||||
|
id="path31"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil1"
|
||||||
|
d="m 236,472 c 3,0 5,2 5,5 0,2 -2,4 -5,4 -3,0 -5,-2 -5,-4 0,-3 2,-5 5,-5 z"
|
||||||
|
id="path33"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#fefefe" /><path
|
||||||
|
class="fil1"
|
||||||
|
d="m 463,472 c 3,0 5,2 5,5 0,2 -2,4 -5,4 -3,0 -5,-2 -5,-4 0,-3 2,-5 5,-5 z"
|
||||||
|
id="path35"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#fefefe" /><polygon
|
||||||
|
class="fil6"
|
||||||
|
points="305,212 284,212 284,310 305,310 "
|
||||||
|
id="polygon37"
|
||||||
|
style="fill:#006498" /><path
|
||||||
|
class="fil7"
|
||||||
|
d="m 477,479 v 2 c 0,5 -3,8 -8,8 H 231 c -5,0 -8,-3 -8,-8 v -2 c 0,4 3,8 8,8 h 238 c 5,0 8,-4 8,-8 z"
|
||||||
|
id="path39"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#0ea5eb" /><path
|
||||||
|
class="fil8"
|
||||||
|
d="M 350,70 C 505,70 630,195 630,350 630,505 505,630 350,630 195,630 70,505 70,350 70,195 195,70 350,70 Z m 0,46 C 479,116 584,221 584,350 584,479 479,584 350,584 221,584 116,479 116,350 116,221 221,116 350,116 Z"
|
||||||
|
id="path41"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#2979ff" /></g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 5.4 KiB |
@@ -0,0 +1,111 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||||
|
|
||||||
|
[{[ if .ReCaptcha -]}]
|
||||||
|
<script src="[{[ .ReCaptchaHost ]}]/recaptcha/api.js?render=explicit"></script>
|
||||||
|
[{[ end ]}]
|
||||||
|
|
||||||
|
<title>[{[ if .Name -]}][{[ .Name ]}][{[ else ]}]File Browser[{[ end ]}]</title>
|
||||||
|
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="/[{[ .StaticURL ]}]/img/icons/favicon-32x32.png">
|
||||||
|
<link rel="icon" type="image/png" sizes="16x16" href="/[{[ .StaticURL ]}]/img/icons/favicon-16x16.png">
|
||||||
|
<!-- Add to home screen for Android and modern mobile browsers -->
|
||||||
|
<link rel="manifest" href="/[{[ .StaticURL ]}]/manifest.json">
|
||||||
|
<meta name="theme-color" content="#2979ff">
|
||||||
|
|
||||||
|
<!-- Add to home screen for Safari on iOS -->
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
|
<meta name="apple-mobile-web-app-title" content="assets">
|
||||||
|
<link rel="apple-touch-icon" href="/[{[ .StaticURL ]}]/img/icons/apple-touch-icon-152x152.png">
|
||||||
|
|
||||||
|
<!-- Add to home screen for Windows -->
|
||||||
|
<meta name="msapplication-TileImage" content="/[{[ .StaticURL ]}]/img/icons/msapplication-icon-144x144.png">
|
||||||
|
<meta name="msapplication-TileColor" content="#2979ff">
|
||||||
|
|
||||||
|
<!-- Inject Some Variables -->
|
||||||
|
<script>window.FileBrowser = JSON.parse(`[{[ .Json ]}]`)</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#loading {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: #fff;
|
||||||
|
z-index: 9999;
|
||||||
|
transition: .1s ease opacity;
|
||||||
|
-webkit-transition: .1s ease opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loading.done {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 70px;
|
||||||
|
text-align: center;
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
-webkit-transform: translate(-50%, -50%);
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner > div {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
background-color: #333;
|
||||||
|
border-radius: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
||||||
|
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner .bounce1 {
|
||||||
|
-webkit-animation-delay: -0.32s;
|
||||||
|
animation-delay: -0.32s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner .bounce2 {
|
||||||
|
-webkit-animation-delay: -0.16s;
|
||||||
|
animation-delay: -0.16s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@-webkit-keyframes sk-bouncedelay {
|
||||||
|
0%, 80%, 100% { -webkit-transform: scale(0) }
|
||||||
|
40% { -webkit-transform: scale(1.0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes sk-bouncedelay {
|
||||||
|
0%, 80%, 100% {
|
||||||
|
-webkit-transform: scale(0);
|
||||||
|
transform: scale(0);
|
||||||
|
} 40% {
|
||||||
|
-webkit-transform: scale(1.0);
|
||||||
|
transform: scale(1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
|
||||||
|
<div id="loading">
|
||||||
|
<div class="spinner">
|
||||||
|
<div class="bounce1"></div>
|
||||||
|
<div class="bounce2"></div>
|
||||||
|
<div class="bounce3"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
[{[ if .CSS -]}]
|
||||||
|
<link rel="stylesheet" href="/[{[ .StaticURL ]}]/custom.css" />
|
||||||
|
[{[ end ]}]
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "File Browser",
|
||||||
|
"short_name": "File Browser",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "./img/icons/android-chrome-192x192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./static/img/icons/android-chrome-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#ffffff",
|
||||||
|
"theme_color": "#455a64"
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<router-view></router-view>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'app',
|
||||||
|
mounted () {
|
||||||
|
const loading = document.getElementById('loading')
|
||||||
|
loading.classList.add('done')
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
loading.parentNode.removeChild(loading)
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import './css/styles.css';
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { removePrefix } from './utils'
|
||||||
|
import { baseURL } from '@/utils/constants'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
|
const ssl = (window.location.protocol === 'https:')
|
||||||
|
const protocol = (ssl ? 'wss:' : 'ws:')
|
||||||
|
|
||||||
|
export default function command(url, command, onmessage, onclose) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
url = `${protocol}//${window.location.host}${baseURL}/api/command${url}?auth=${store.state.jwt}`
|
||||||
|
|
||||||
|
let conn = new window.WebSocket(url)
|
||||||
|
conn.onopen = () => conn.send(command)
|
||||||
|
conn.onmessage = onmessage
|
||||||
|
conn.onclose = onclose
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import { fetchURL, removePrefix } from './utils'
|
||||||
|
import { baseURL } from '@/utils/constants'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
|
export async function fetch (url) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
|
||||||
|
const res = await fetchURL(`/api/resources${url}`, {})
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
let data = await res.json()
|
||||||
|
data.url = `/files${url}`
|
||||||
|
|
||||||
|
if (data.isDir) {
|
||||||
|
if (!data.url.endsWith('/')) data.url += '/'
|
||||||
|
data.items = data.items.map((item, index) => {
|
||||||
|
item.index = index
|
||||||
|
item.url = `${data.url}${encodeURIComponent(item.name)}`
|
||||||
|
|
||||||
|
if (item.isDir) {
|
||||||
|
item.url += '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
} else {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resourceAction (url, method, content) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
|
||||||
|
let opts = { method }
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
opts.body = content
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetchURL(`/api/resources${url}`, opts)
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(res.responseText)
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function remove (url) {
|
||||||
|
return resourceAction(url, 'DELETE')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function put (url, content = '') {
|
||||||
|
return resourceAction(url, 'PUT', content)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function download (format, ...files) {
|
||||||
|
let url = `${baseURL}/api/raw`
|
||||||
|
|
||||||
|
if (files.length === 1) {
|
||||||
|
url += removePrefix(files[0]) + '?'
|
||||||
|
} else {
|
||||||
|
let arg = ''
|
||||||
|
|
||||||
|
for (let file of files) {
|
||||||
|
arg += removePrefix(file) + ','
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = arg.substring(0, arg.length - 1)
|
||||||
|
arg = encodeURIComponent(arg)
|
||||||
|
url += `/?files=${arg}&`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format !== null) {
|
||||||
|
url += `algo=${format}&`
|
||||||
|
}
|
||||||
|
|
||||||
|
url += `auth=${store.state.jwt}`
|
||||||
|
window.open(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function post (url, content = '', overwrite = false, onupload) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let request = new XMLHttpRequest()
|
||||||
|
request.open('POST', `${baseURL}/api/resources${url}?override=${overwrite}`, true)
|
||||||
|
request.setRequestHeader('X-Auth', store.state.jwt)
|
||||||
|
|
||||||
|
if (typeof onupload === 'function') {
|
||||||
|
request.upload.onprogress = onupload
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a message to user before closing the tab during file upload
|
||||||
|
window.onbeforeunload = () => "Files are being uploaded."
|
||||||
|
|
||||||
|
request.onload = () => {
|
||||||
|
if (request.status === 200) {
|
||||||
|
resolve(request.responseText)
|
||||||
|
} else if (request.status === 409) {
|
||||||
|
reject(request.status)
|
||||||
|
} else {
|
||||||
|
reject(request.responseText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.onerror = (error) => {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
request.send(content)
|
||||||
|
// Upload is done no more message before closing the tab
|
||||||
|
}).finally(() => { window.onbeforeunload = null })
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveCopy (items, copy = false) {
|
||||||
|
let promises = []
|
||||||
|
|
||||||
|
for (let item of items) {
|
||||||
|
const from = removePrefix(item.from)
|
||||||
|
const to = encodeURIComponent(removePrefix(item.to))
|
||||||
|
const url = `${from}?action=${copy ? 'copy' : 'rename'}&destination=${to}`
|
||||||
|
promises.push(resourceAction(url, 'PATCH'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function move (items) {
|
||||||
|
return moveCopy(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function copy (items) {
|
||||||
|
return moveCopy(items, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checksum (url, algo) {
|
||||||
|
const data = await resourceAction(`${url}?checksum=${algo}`, 'GET')
|
||||||
|
return (await data.json()).checksums[algo]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import * as files from './files'
|
||||||
|
import * as share from './share'
|
||||||
|
import * as users from './users'
|
||||||
|
import * as settings from './settings'
|
||||||
|
import search from './search'
|
||||||
|
import commands from './commands'
|
||||||
|
|
||||||
|
export {
|
||||||
|
files,
|
||||||
|
share,
|
||||||
|
users,
|
||||||
|
settings,
|
||||||
|
commands,
|
||||||
|
search
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { fetchJSON, removePrefix } from './utils'
|
||||||
|
|
||||||
|
export default async function search (url, query) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
query = encodeURIComponent(query)
|
||||||
|
|
||||||
|
return fetchJSON(`/api/search${url}?query=${query}`, {})
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { fetchURL, fetchJSON } from './utils'
|
||||||
|
|
||||||
|
export function get () {
|
||||||
|
return fetchJSON(`/api/settings`, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function update (settings) {
|
||||||
|
const res = await fetchURL(`/api/settings`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(settings)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { fetchURL, fetchJSON, removePrefix } from './utils'
|
||||||
|
|
||||||
|
export async function getHash(hash) {
|
||||||
|
return fetchJSON(`/api/public/share/${hash}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(url) {
|
||||||
|
url = removePrefix(url)
|
||||||
|
return fetchJSON(`/api/share${url}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function remove(hash) {
|
||||||
|
const res = await fetchURL(`/api/share/${hash}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function create(url, expires = '', unit = 'hours') {
|
||||||
|
url = removePrefix(url)
|
||||||
|
url = `/api/share${url}`
|
||||||
|
if (expires !== '') {
|
||||||
|
url += `?expires=${expires}&unit=${unit}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return fetchJSON(url, {
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { fetchURL, fetchJSON } from './utils'
|
||||||
|
|
||||||
|
export async function getAll () {
|
||||||
|
return fetchJSON(`/api/users`, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get (id) {
|
||||||
|
return fetchJSON(`/api/users/${id}`, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function create (user) {
|
||||||
|
const res = await fetchURL(`/api/users`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
what: 'user',
|
||||||
|
which: [],
|
||||||
|
data: user
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status === 201) {
|
||||||
|
return res.headers.get('Location')
|
||||||
|
} else {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function update (user, which = ['all']) {
|
||||||
|
const res = await fetchURL(`/api/users/${user.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
what: 'user',
|
||||||
|
which: which,
|
||||||
|
data: user
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function remove (id) {
|
||||||
|
const res = await fetchURL(`/api/users/${id}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import store from '@/store'
|
||||||
|
import { renew } from '@/utils/auth'
|
||||||
|
import { baseURL } from '@/utils/constants'
|
||||||
|
|
||||||
|
export async function fetchURL (url, opts) {
|
||||||
|
opts = opts || {}
|
||||||
|
opts.headers = opts.headers || {}
|
||||||
|
|
||||||
|
let { headers, ...rest } = opts
|
||||||
|
|
||||||
|
const res = await fetch(`${baseURL}${url}`, {
|
||||||
|
headers: {
|
||||||
|
'X-Auth': store.state.jwt,
|
||||||
|
...headers
|
||||||
|
},
|
||||||
|
...rest
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.headers.get('X-Renew-Token') === 'true') {
|
||||||
|
await renew(store.state.jwt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchJSON (url, opts) {
|
||||||
|
const res = await fetchURL(url, opts)
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
return res.json()
|
||||||
|
} else {
|
||||||
|
throw new Error(res.status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removePrefix (url) {
|
||||||
|
if (url.startsWith('/files')) {
|
||||||
|
url = url.slice(6)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url === '') url = '/'
|
||||||
|
if (url[0] !== '/') url = '/' + url
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||