Compare commits

..

25 Commits

Author SHA1 Message Date
Henrique Dias
25c20aaeb2 Build assets
Former-commit-id: b00f47f672956abd67217d3bfcc9681c53a5cb21 [formerly 13efcc0784356df1eef3f85fc64637cf1a46ea23] [formerly 8f4a7fc9c6199c7454ab920deaf2eb50cdd80bbb [formerly 05a6ebe805]]
Former-commit-id: b09670b87308aad975716f56578964a28352171a [formerly 3e2909f91026e82933fd476ec571915211613df4]
Former-commit-id: 0622c1396b8c94ae2342c87263d3006dd80cba06
2017-07-28 10:04:46 +01:00
Henrique Dias
4c665ec69c Merge branch 'master' of https://github.com/hacdias/filemanager
Former-commit-id: 32ee5895db96495db099b05391ad775b64e91ec3 [formerly 4636b9d22f781d91167e45a39930448b10d85e43] [formerly 5ae6fd1b6b8894b85c0df81d7e53d8e787d4797c [formerly 537c839d9e]]
Former-commit-id: 99579a9a68807d7fa55e9abfa8b2881f509b4ce2 [formerly d48f9c64d5dddada4f0e71ce611fc75c93477ec4]
Former-commit-id: 5a20514a2e2d250796b271c14ec90de022beb725
2017-07-28 09:59:36 +01:00
Henrique Dias
75ed779b17 Use varutils instead
Former-commit-id: 454971910d12915f6668454ab00c0f92f9f80f40 [formerly 5fd29b6b99f57f9cd6be8a5c09151ef3feabbcc9] [formerly ac7480dcb9b5d3c240163f5f406f0ecebc842cee [formerly 2d83da4d7e]]
Former-commit-id: 77ec28f8a63a9b994059d28f467697cc6f03288b [formerly d031877a753306d0dd42c58686538a9eaf3211fc]
Former-commit-id: 818e4d03e50e4a04f1f38001c48dd45e71ed91ef
2017-07-28 09:59:31 +01:00
Henrique Dias
6c360ffc5c Update Dockerfile
Former-commit-id: ecae8322b52dc294e4926f542059b2a2f76d67e1 [formerly c0000943385ed1417a7e748d36f1cd25750d8217] [formerly 2a70f9a07f83e017b58f65c9dbe8583e7dc92227 [formerly 8117eb98d8]]
Former-commit-id: 992d5e311c66506d0e7ca90f49f38e4be7983afb [formerly 52ab26d2c1029266e6ddac201bc34bcb3271b984]
Former-commit-id: a4c5a02eee252ab728f4da55a6ed32d6470d7b81
2017-07-28 08:06:44 +01:00
Henrique Dias
f40731d3b4 Use fileutils instead
Former-commit-id: 2688c5dca3865614edaf7b159b7f0dcebad77171 [formerly b919610fb1d09db5e6b6308e5adc0d431ce6c139] [formerly b7c60fcf5771ec9d1854947dd89dc51ff414bdb7 [formerly ff034f7e8f]]
Former-commit-id: a63a598c5cef6c050a8a0d189bc5235a98d5457a [formerly cab7076a63efddbfb968c151c5ef1d34b00dac56]
Former-commit-id: f167b30eeea3a9c0b8fec43dc37ee95cd8c172e6
2017-07-27 21:39:23 +01:00
Henrique Dias
afb10cc02c Update and remove latest
Former-commit-id: 2585617bb0654bb6cfc32b7a64ebc8bf9a576ff0 [formerly 03a73d6f0ed0118e205e50ecab8d3bfc31a655b5] [formerly dddf658817bc25630be32647248d5e5533bcbc33 [formerly dac92eec8b]]
Former-commit-id: 77f85c483bf64ddc36013dd474100d459a6d599e [formerly ee7c07d1532d9bbd4c2d8e1428bb8a909f1f90b0]
Former-commit-id: b5b9dafcecc6990c70dfa0fffa071698736106b8
2017-07-27 18:15:51 +01:00
Henrique Dias
5d2e8864e5 A fix for #161
Former-commit-id: 73c31acfa1c812e896c57562338bd1fc27e3a3fb [formerly 15188c05c39a31691a875a57fadc2b397942146c] [formerly 6ad4d891a760572954b88383b41ced35bffc14c2 [formerly 97365f0e16]]
Former-commit-id: cb059d6f523e1f4a158bd504e04ce052ce32ae8b [formerly 945c4570eaa8478e7cea4dea8085a0ad69dfc063]
Former-commit-id: 138a1faefacab94f8ba14e0b72c75dd41fa9b965
2017-07-27 18:05:57 +01:00
Henrique Dias
d82f198b48 Delete _config.yml
Former-commit-id: 07bcc7620a718b01dfdbbe52d4ee0db6e20bd32e [formerly 1a0932293fabd2b19c0540fd6607c9bb9f68c153] [formerly 74ba54fee5c64ab93cd85720dd34c486a8a10a3a [formerly 703ee7daff]]
Former-commit-id: 14cbbe0ebe8a8ee0dd492c8b6b1035573a17dabf [formerly 4407d0442d0a32f8103ca86cb3f177b418b7cc84]
Former-commit-id: 6e4a79cb68099c567a42d75c95f2d8e912915893
2017-07-27 15:38:46 +01:00
Henrique Dias
bbbf2bac51 Set theme jekyll-theme-minimal
Former-commit-id: 9e9b72ead90fdd8f2cad943bd1cfe01c1a17d37e [formerly 14d56a8c62b54f0d2f90e2be62521aa4a34b220e] [formerly 041af3cd74e055fd89888c3406f59d92eb13117f [formerly 92c1a1622c]]
Former-commit-id: ae6bb20fb3fe17c430da8fd7e13a7e8f9194a228 [formerly 9eba2146635347aa33fcdde363bc81574a319ae3]
Former-commit-id: 421dd2e790dd8f0b647cd78685b16144e6ab1476
2017-07-27 15:28:39 +01:00
Henrique Dias
d87a8ee5ed Update README.md
Former-commit-id: f5d3de7a867ec129722eb713c96dc3c1a2dbd29d [formerly 13041237112a88c32a576965470f26829ef09e76] [formerly 1ec2ac3a1cb4ed8f851073c44bd1910478fe6600 [formerly bcd1f57836]]
Former-commit-id: 6ef873900c9a33aa180966237c801a540beaae3f [formerly 933ca735ad2ebb87dfbcd32c59b84586a962bf5c]
Former-commit-id: 85b221326e049dc2fd976681a5e93b0f01d1d8fd
2017-07-27 14:30:40 +01:00
Henrique Dias
a81cc1e4ca Add dockerignore
Former-commit-id: cd7095c90fda66881b8ce945f8392ab0a1f48a5b [formerly 767ddf6d86daf63eb6b02b5772ce389fbc6e1276] [formerly 0c5bfe13aaa28188a0e3c303b4cc06f148d5a5d7 [formerly c970227440]]
Former-commit-id: 60d4e4affdbd8d61d470f92328471b8867a2fae8 [formerly 0077bc004f73c8f626ff6566422374ab25d22a2e]
Former-commit-id: 99f9d4a4a5d038c5ad0174fd51acc3d0f3418dbc
2017-07-27 14:17:41 +01:00
Henrique Dias
6c5111fd6e Build assets
Former-commit-id: cc18830de1feb1bf095ee587c88650aef7e00eb6 [formerly ba8acc12a4d9efc42bb6d70d3fe64635a6e26474] [formerly 84bd969ed90d4adc2f1055edf432fb1b06590168 [formerly 42a3243113]]
Former-commit-id: 26ad676ccb988cbb75ed9737741bdc921310b9f6 [formerly 763d12b75f3ab22e3796e1f1c7b55ad83e3dbfc9]
Former-commit-id: c64850bca8bb9d473fc8de932a16bd379b867c88
2017-07-27 14:04:52 +01:00
Henrique Dias
e846c16336 Add Docker.json and update Dockerfile. See #157
Former-commit-id: 02381af5eb56c6d17416b187abac0c5b0067179b [formerly 4ee41157924a7ebbeefd31ddd55919317da6a4fe] [formerly 914325aefc9c3f622b3368289f3499c526943b56 [formerly 02c98905ae]]
Former-commit-id: 5c9112505577abeb82bb0e9f6f04081b63838dbf [formerly 82821dd7c2a3bd04d11148b43c45cbd8331e7138]
Former-commit-id: 121ad025499afafc25ca21e322783aa91ac6ebf2
2017-07-27 14:03:53 +01:00
Henrique Dias
dde01c6931 Make search reload the dir after closing itself
Former-commit-id: e9774417ce7c29eded0158ef18535fcad57ddc8a [formerly 1a644e3fd8e191aee49a12a660069b39b38e2c0b] [formerly c371da590eb27fbcf290e56933b279ea75384cee [formerly 9453e22559]]
Former-commit-id: aba05b88f61352b6e6afb5bf9af8c033ac8ba310 [formerly d011d5ee10fa055bc3ea35889dddb968b476eb83]
Former-commit-id: c1138ce78249872f442646d26807140a94824e0b
2017-07-27 14:03:14 +01:00
Henrique Dias
8b40dc9d19 Fix websockets on other ports than 80
Former-commit-id: 92fc9e1bd2c7590af98c5246a7e035a3ca8f3d6f [formerly 3cbab224088f675ab9474a78682db7956f90a39e] [formerly 395d28fc36802680a6a30065cad749101c256753 [formerly 736e7d6167]]
Former-commit-id: 5cfac7b10ccaf36c3969164df5af8dee4a27a9a5 [formerly 8e8283eba1ae1c5bf0da72927a775fdac2e3ef79]
Former-commit-id: 9a89cbe037984be71de125da051a92aa0d1636ab
2017-07-27 14:02:50 +01:00
Henrique Dias
63fb4c0c52 Fix other commands not working
Former-commit-id: aeff50d7041e0e411380db06789d431ccfcd849f [formerly 80fc2ef99d5bca4b98447d1218cea45178e973e9] [formerly 4b6b489ceefa94c96830439a1c3e2972641fe536 [formerly 01a9896b19]]
Former-commit-id: d16f51eff82db054324ac67d87d044ed040c680b [formerly 0b18874eeee9a6db3946113224593b431c44c0c8]
Former-commit-id: 65e557d6703ca9d621da083c56caa7bb80ae089d
2017-07-27 13:34:55 +01:00
Henrique Dias
76047f4146 Merge branch 'master' of https://github.com/hacdias/filemanager
Former-commit-id: 1643b508b73ce32c022df5135e76bab645c3e3c8 [formerly c07a0e73c64b358a659a2b5f9f4b94a40e1d488d] [formerly 61e888ede7349df3a40a6b3d83b3603459a5c7e7 [formerly 989b6a525d]]
Former-commit-id: 095032dc1c062ea090104fa1f4cd9d34332dc95f [formerly dd71906d3622b0a2b3763aca939be4e49c1160f6]
Former-commit-id: ef065a79e82a3f934925282b85bf4b4b45049668
2017-07-27 13:31:07 +01:00
Henrique Dias
fc4c6ec246 Don't throw error if it is not a draft
Former-commit-id: fb33f600de938ad16ac1c2f1ab6aaae30f5598a8 [formerly c98a595f1f9adb3fc9f792ef353fd09f2a93674d] [formerly bb7623d54853a8df0525313aafcf076c3114af26 [formerly 8a4e1b6520]]
Former-commit-id: 49ef204abe70d7b791260f589b9569a94c4cdca9 [formerly 9499193985f3b9d91a0e6fe25a028937df7e919b]
Former-commit-id: 7fdb34a388e878accf14ae24a7a53714c62eda06
2017-07-27 13:30:46 +01:00
Bitti
f5e93825d8 Fix link to github repo (#160)
Former-commit-id: 1bd1eaebb892163e93360f74a9321689dd3b0583 [formerly c5eea25d2d36a3f3f00f5eb5cd9e5b97f2498019] [formerly 2387782e054d0e1ffcc633bdafff5d6feef4e722 [formerly c90db487f7]]
Former-commit-id: 400ecf0884bc68fea1a1389236103013817959f7 [formerly f6dc144ea0b1fef8af13d519a13ce70aeedb66f4]
Former-commit-id: e9c3d71b1047a81b956407ceb36e8ee32b5b8c50
2017-07-27 13:17:16 +01:00
Henrique Dias
73d74394c8 Hopefully fix #159
Former-commit-id: fee7b5c6a519d5a6ff26b2a653a3c82984f1dead [formerly 7fee30ae26f6941db1b718b64adfa6250aaf82c3] [formerly 46a761a926a67c0d0f8f49e84369912eba1377ef [formerly fbd0cf0c14]]
Former-commit-id: 4bdbf9a31f827d8aa36bad9b89f27bd5a373b75c [formerly 7e747b4e27d6958ff8448b5e5e2fe6716821a9ff]
Former-commit-id: a30d3b204d318b1d84e8583d5bbdbc6761852e2a
2017-07-27 12:32:10 +01:00
Henrique Dias
3469d8c6e8 Update Dockerfile
Former-commit-id: e8e99ed19cabe5a571f279cb2441964cdb954da9 [formerly cdbfd41a0ac408328eed4dd4466f1a9e0736ed0b] [formerly 69fc163bec96cc39dd5f77d1a7620eb9b29be28a [formerly ef315082ed]]
Former-commit-id: f81fbaeeee62c3a6a1d554f9dfff514ca095cf31 [formerly e5728fe8be1bbf463bd0b6e1f9df04de70dc3f4d]
Former-commit-id: f250a6c9fff5f8f397d1f3a6d00cfe0e4be23862
2017-07-27 11:38:09 +01:00
田浩
be082c1075 Add Docker Support (#157)
* dep init

* add Dockerfile

* update Dockerfile: add rice

* remove npm build & rice

* remove dep

* remove dep in Dockerfile


Former-commit-id: 6e7595fdfd54ad0bd3284124b418ac90cd635b74 [formerly 4e07bdd0e28b5d9361465eeca41cf78480a5c9c6] [formerly 2440226e8514f0c7e249ff2476721f049e1c416e [formerly bfc4362ddc]]
Former-commit-id: 35123c0371d2f05834780f3a9586ebed062497a9 [formerly 45ab33769a72f70f6c6c2307cc16cecbe662d025]
Former-commit-id: 4da50772ad13e8caefd3fd9b0d21ff675e0f7c6a
2017-07-27 10:27:59 +01:00
Henrique Dias
f271b18d97 Update Travis file
Former-commit-id: f8ab226e6a2c6132038abf4ae4f1d36def9bbeaf [formerly e7cbe888773009190ac7f37e6e3793a098f8ce83] [formerly 3fee80d398724ad66ab9eef0276581b21e06ce7b [formerly 155b5c3c02]]
Former-commit-id: 693d10cfd6a6e7ad4e4b0b1eb5fedc2a5ffcd6b4 [formerly c63af660b310eb19349d686475e4c503303420ee]
Former-commit-id: ca8f8aff411eaad6271885e9d84ab3bfd42dcde8
2017-07-27 08:23:50 +01:00
Henrique Dias
a728d0352e UPDATE TRAVIS
Former-commit-id: ea054af3fd934aebe0c8e2eab55f49bea60b63b2 [formerly e33717ab8dfc9d4bb3f28bda09e4b946afc66772] [formerly 440ef03b98c191821bd41991e57014e121372078 [formerly ae06e99cd1]]
Former-commit-id: 45b1a7afbb504b58194658ee3c08d17c2ddd1c9d [formerly 30356885794a37ddd1ae497c3cc6bcb2d16c59ea]
Former-commit-id: a94890a592a8efc4b8b8824f27e9560c044d5c14
2017-07-27 08:12:02 +01:00
Henrique Dias
2096d7d048 Build assets
Former-commit-id: 55d3d4aefbe1b0c374b64cb9b43db04cc5e2917c [formerly cc1399c7d5c4f57c49bc63649161b0174ca6cff3] [formerly 415dd63cd4052b765cbe3e34623723cd5d016438 [formerly f4506d06db]]
Former-commit-id: d29bc22e2ca476bfad2b6af89a949988e32b2930 [formerly 5e093ef79c6ed70d88b2429598c65449f7ef3ffc]
Former-commit-id: e288357ab7acfa509de7ef1353761f7db03985c3
2017-07-26 18:36:48 +01:00
24 changed files with 92 additions and 464 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
assets/
testdata/
caddy/
.github/

View File

@@ -9,7 +9,6 @@ env:
install:
- go get ./...
- go get github.com/mitchellh/gox
- go get github.com/tcnksm/ghr
# Install gometalinter and certain linters
- go get github.com/alecthomas/gometalinter
- go get github.com/client9/misspell/cmd/misspell
@@ -20,11 +19,11 @@ install:
script:
- gometalinter --disable-all -E vet -E gofmt -E misspell -E ineffassign -E goimports -E deadcode --exclude="rice-box.go" --tests ./...
- go test ./... -timeout 30s
before_deploy:
- cd cmd/filemanager
- mkdir dist
- gox -output "dist/{{.OS}}-{{.Arch}}-{{.Dir}}"
- ls dist/
- ghr --username hacdias --token $GITHUB_TOKEN --replace --prerelease --debug latest dist/
deploy:
provider: releases

10
Docker.json Normal file
View File

@@ -0,0 +1,10 @@
{
"port": 80,
"address": "",
"database": "/etc/database.db",
"scope": "/srv",
"allowCommands": true,
"allowEdit": true,
"allowNew": true,
"commands": []
}

21
Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM golang:alpine
COPY . /go/src/github.com/hacdias/filemanager
WORKDIR /go/src/github.com/hacdias/filemanager
RUN apk add --no-cache git
RUN go get ./...
WORKDIR /go/src/github.com/hacdias/filemanager/cmd/filemanager
RUN go install
FROM alpine:latest
COPY --from=0 /go/bin/filemanager /usr/local/bin/filemanager
VOLUME /srv
EXPOSE 80
COPY Docker.json /etc/config.json
ENTRYPOINT ["/usr/local/bin/filemanager"]
CMD ["--config", "/etc/config.json"]

View File

@@ -34,7 +34,7 @@ The easiest way to get started is using this with Caddy web server. You just nee
## Standalone
You can use filemanager as a standalone executable. You just need to download it from the [releases page](https://github.com/hacdias/filemanager/releases), where you can find multiple releases. The 'latest' always corresponds to the latest commit made to the master branch so it might not be stable.
You can use filemanager as a standalone executable. You just need to download it from the [releases page](https://github.com/hacdias/filemanager/releases), where you can find multiple releases.
You can either use flags or a JSON configuration file, which should have the following appearance:
@@ -77,6 +77,10 @@ Otherwise, you may not want to use a configuration file, which can be done using
Default scope for new users (default ".")
```
## Docker
(TODO)
# Features
Easy login system.
@@ -127,18 +131,19 @@ this are keywords case:insensitive
# Contributing
If you want to contribute or want to build the code from source, you will need to have NodeJS and Go installed on your computer. You should start by doing the following:
If you want to contribute or want to build the code from source, you will need to have the most recent version of Go and, if you want to change the static assets (JS, CSS, ...), Node.js installed on your computer. To start developing, you just need to do the following:
```
go get github.com/hacdias/filemanager
```
1. `go get github.com/hacdias/filemanager`
2. `cd $GOPATH/src/github.com/hacdias/filemanager`
3. `npm install`
4. `npm start dev` - regenerates the static assets automatically
5. `go install gihthub.com/hacdias/filemanager/cmd/filemanager`
6. Execute `$GOPATH/bin/filemanager`
Then, you should navigate to `$GOPATH/src/github.com/hacdias/filemanager` and execute `npm install`. You can start the live build of static assets with the command `npm start dev`.
The steps 3 and 4 are only required **if you want to develop the front-end**. Otherwise, you can ignore them. Before pulling, if you made any change on assets folder, you must run the `build.sh` script on the root of this repository.
If you are using this as a Caddy plugin, you should use its [official instructions for plugins](https://github.com/mholt/caddy/wiki/Extending-Caddy#2-plug-in-your-plugin) and import `github.com/hacdias/filemanager/caddy/filemanager`.
Before pulling, and if you made any change on assets folder, you must run the `build.sh` script on the root of this repository.
# Donate
Enjoying this project? You can [donate to its creator](https://henriquedias.com/donate/). He will appreciate.

View File

@@ -47,7 +47,8 @@ export default {
ongoing: false,
scrollable: null,
search: [],
commands: []
commands: [],
reload: false
}
},
watch: {
@@ -57,12 +58,17 @@ export default {
// If the hover was search and now it's something else
// we should blur the input.
if (old === 'search' && val !== 'search') {
if (this.reload) {
this.$store.commit('setReload', true)
}
this.$refs.input.blur()
}
// If we are starting to show the search box, we should
// focus the input.
if (val === 'search') {
this.reload = false
this.$refs.input.focus()
}
}
@@ -129,7 +135,7 @@ export default {
let pieces = this.value.split(' ')
for (let i = 0; i < this.user.commands.length; i++) {
if (pieces[0] === this.user.commands[0]) {
if (pieces[0] === this.user.commands[i]) {
return true
}
}
@@ -166,9 +172,9 @@ export default {
this.scrollable.scrollTop = this.scrollable.scrollHeight
},
(event) => {
this.reload = true
this.ongoing = false
this.scrollable.scrollTop = this.scrollable.scrollHeight
this.$store.commit('setReload', true)
}
)

View File

@@ -37,7 +37,7 @@
</div>
<p class="credits">
<span>Served with <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>.</span>
<span>Served with <a rel="noopener noreferrer" href="https://github.com/hacdias/filemanager">File Manager</a>.</span>
<span v-for="plugin in plugins" :key="plugin.name" v-html="plugin.credits"><br></span>
<span><a @click="help">Help</a></span>
</p>

View File

@@ -163,7 +163,7 @@ function checksum (url, algo) {
function command (url, command, onmessage, onclose) {
let protocol = (ssl ? 'wss:' : 'ws:')
url = removePrefix(url)
url = `${protocol}//${window.location.hostname}${store.state.baseURL}/api/command${url}`
url = `${protocol}//${window.location.host}${store.state.baseURL}/api/command${url}`
let conn = new window.WebSocket(url)
conn.onopen = () => conn.send(command)
@@ -174,7 +174,7 @@ function command (url, command, onmessage, onclose) {
function search (url, search, onmessage, onclose) {
let protocol = (ssl ? 'wss:' : 'ws:')
url = removePrefix(url)
url = `${protocol}//${window.location.hostname}${store.state.baseURL}/api/search${url}`
url = `${protocol}//${window.location.host}${store.state.baseURL}/api/search${url}`
let conn = new window.WebSocket(url)
conn.onopen = () => conn.send(search)

View File

@@ -13,7 +13,7 @@ import (
"strings"
. "github.com/hacdias/filemanager"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
@@ -136,7 +136,7 @@ func parse(c *caddy.Controller) ([]*config, error) {
Regexp: &Regexp{Raw: "\\/\\..+"},
}},
CSS: "",
FileSystem: dir.Dir(baseScope),
FileSystem: fileutils.Dir(baseScope),
})
if err != nil {

View File

@@ -10,7 +10,7 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/hacdias/filemanager"
"github.com/hacdias/filemanager/variables"
"github.com/hacdias/varutils"
"github.com/robfig/cron"
)
@@ -71,7 +71,6 @@ func (h hugo) BeforeAPI(c *filemanager.RequestContext, w http.ResponseWriter, r
}
filename := filepath.Join(string(c.User.FileSystem), r.URL.Path)
filename = strings.TrimPrefix(filename, "/")
archetype := r.Header.Get("archetype")
ext := filepath.Ext(filename)
@@ -100,7 +99,6 @@ func (h hugo) BeforeAPI(c *filemanager.RequestContext, w http.ResponseWriter, r
}
filename := filepath.Join(string(c.User.FileSystem), r.URL.Path)
filename = strings.TrimPrefix(filename, "/")
// Before save command handler.
if err := c.FM.Runner("before_publish", filename); err != nil {
@@ -110,7 +108,7 @@ func (h hugo) BeforeAPI(c *filemanager.RequestContext, w http.ResponseWriter, r
// We only run undraft command if it is a file.
if !strings.HasSuffix(filename, "/") {
args := []string{"undraft", filename}
if err := Run(h.Exe, args, h.Root); err != nil {
if err := Run(h.Exe, args, h.Root); err != nil && !strings.Contains(err.Error(), "not a Draft") {
return http.StatusInternalServerError, err
}
}
@@ -142,7 +140,7 @@ func (h hugo) AfterAPI(c *filemanager.RequestContext, w http.ResponseWriter, r *
}
func (h hugo) JavaScript() string {
return rice.MustFindBox("./").MustString("hugo.js")
return rice.MustFindBox("./assets/").MustString("hugo.js")
}
// run runs Hugo with the define arguments.
@@ -153,7 +151,7 @@ func (h hugo) run(force bool) {
}
// Prevent running if watching is enabled
if b, pos := variables.StringInSlice("--watch", h.Args); b && !force {
if b, pos := varutils.StringInSlice("--watch", h.Args); b && !force {
if len(h.Args) > pos && h.Args[pos+1] != "false" {
return
}

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,7 @@ import (
"strings"
"github.com/hacdias/filemanager"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
@@ -52,7 +52,7 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) {
// Get the baseURL and baseScope
args := c.RemainingArgs()
if len(args) == 1 {
if len(args) >= 1 {
directory = args[0]
}
@@ -112,7 +112,7 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) {
Regexp: &filemanager.Regexp{Raw: "\\/\\..+"},
}},
CSS: "",
FileSystem: dir.Dir(directory),
FileSystem: fileutils.Dir(directory),
})
if err != nil {

View File

@@ -11,7 +11,7 @@ import (
"strings"
"github.com/hacdias/filemanager"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
)
// confFile contains the configuration file for this File Manager instance.
@@ -65,7 +65,7 @@ func main() {
Commands: strings.Split(strings.TrimSpace(commands), " "),
Rules: []*filemanager.Rule{},
CSS: "",
FileSystem: dir.Dir(scope),
FileSystem: fileutils.Dir(scope),
})
if err != nil {

View File

@@ -1,230 +0,0 @@
// Package dir implements a FileSystem interface using the native
// file system restricted to a specific directory tree. Originally from
// https://github.com/golang/net/blob/master/webdav/file.go#L68
package dir
import (
"errors"
"io"
"os"
"path"
"path/filepath"
"strings"
)
// A Dir uses the native file system restricted to a specific directory tree.
//
// While the FileSystem.OpenFile method takes '/'-separated paths, a Dir's
// string value is a filename on the native file system, not a URL, so it is
// separated by filepath.Separator, which isn't necessarily '/'.
//
// An empty Dir is treated as ".".
type Dir string
func (d Dir) resolve(name string) string {
// This implementation is based on Dir.Open's code in the standard net/http package.
if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 ||
strings.Contains(name, "\x00") {
return ""
}
dir := string(d)
if dir == "" {
dir = "."
}
return filepath.Join(dir, filepath.FromSlash(SlashClean(name)))
}
// Mkdir implements os.Mkdir in this directory context.
func (d Dir) Mkdir(name string, perm os.FileMode) error {
if name = d.resolve(name); name == "" {
return os.ErrNotExist
}
return os.Mkdir(name, perm)
}
// OpenFile implements os.OpenFile in this directory context.
func (d Dir) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
if name = d.resolve(name); name == "" {
return nil, os.ErrNotExist
}
f, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, err
}
return f, nil
}
// RemoveAll implements os.RemoveAll in this directory context.
func (d Dir) RemoveAll(name string) error {
if name = d.resolve(name); name == "" {
return os.ErrNotExist
}
if name == filepath.Clean(string(d)) {
// Prohibit removing the virtual root directory.
return os.ErrInvalid
}
return os.RemoveAll(name)
}
// Rename implements os.Rename in this directory context.
func (d Dir) Rename(oldName, newName string) error {
if oldName = d.resolve(oldName); oldName == "" {
return os.ErrNotExist
}
if newName = d.resolve(newName); newName == "" {
return os.ErrNotExist
}
if root := filepath.Clean(string(d)); root == oldName || root == newName {
// Prohibit renaming from or to the virtual root directory.
return os.ErrInvalid
}
return os.Rename(oldName, newName)
}
// Stat implements os.Stat in this directory context.
func (d Dir) Stat(name string) (os.FileInfo, error) {
if name = d.resolve(name); name == "" {
return nil, os.ErrNotExist
}
return os.Stat(name)
}
// Copy copies a file or directory from src to dst. If it is
// a directory, all of the files and sub-directories will be copied.
func (d Dir) Copy(src, dst string) error {
if src = d.resolve(src); src == "" {
return os.ErrNotExist
}
if dst = d.resolve(dst); dst == "" {
return os.ErrNotExist
}
if root := filepath.Clean(string(d)); root == src || root == dst {
// Prohibit copying from or to the virtual root directory.
return os.ErrInvalid
}
if dst == src {
return os.ErrInvalid
}
info, err := os.Stat(src)
if err != nil {
return err
}
if info.IsDir() {
return CopyDir(src, dst)
}
return CopyFile(src, dst)
}
// SlashClean is equivalent to but slightly more efficient than
// path.Clean("/" + name).
func SlashClean(name string) string {
if name == "" || name[0] != '/' {
name = "/" + name
}
return path.Clean(name)
}
// CopyFile copies a file from source to dest and returns
// an error if any.
func CopyFile(source string, dest string) error {
// Open the source file.
src, err := os.Open(source)
if err != nil {
return err
}
defer src.Close()
// Makes the directory needed to create the dst
// file.
err = os.MkdirAll(filepath.Dir(dest), 0666)
if err != nil {
return err
}
// Create the destination file.
dst, err := os.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 := os.Stat(source)
if err != nil {
err = os.Chmod(dest, info.Mode())
if err != nil {
return err
}
}
return nil
}
// 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(source string, dest string) error {
// Get properties of source.
srcinfo, err := os.Stat(source)
if err != nil {
return err
}
// Create the destination directory.
err = os.MkdirAll(dest, srcinfo.Mode())
if err != nil {
return err
}
dir, _ := os.Open(source)
obs, err := dir.Readdir(-1)
var errs []error
for _, obj := range obs {
fsource := source + "/" + obj.Name()
fdest := dest + "/" + obj.Name()
if obj.IsDir() {
// Create sub-directories, recursively.
err = CopyDir(fsource, fdest)
if err != nil {
errs = append(errs, err)
}
} else {
// Perform the file copy.
err = CopyFile(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
}

View File

@@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
"github.com/mholt/archiver"
)
@@ -45,7 +45,7 @@ func downloadHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
}
// Clean the slashes.
name = dir.SlashClean(name)
name = fileutils.SlashClean(name)
files = append(files, filepath.Join(c.FI.Path, name))
}
} else {

View File

@@ -11,7 +11,7 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/asdine/storm"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
"github.com/mholt/caddy"
)
@@ -76,7 +76,7 @@ type User struct {
Admin bool `json:"admin"`
// FileSystem is the virtual file system the user has access.
FileSystem dir.Dir `json:"filesystem"`
FileSystem fileutils.Dir `json:"filesystem"`
// Rules is an array of access and deny rules.
Rules []*Rule `json:"rules"`
@@ -136,7 +136,7 @@ var DefaultUser = User{
Rules: []*Rule{},
CSS: "",
Admin: true,
FileSystem: dir.Dir("."),
FileSystem: fileutils.Dir("."),
}
// New creates a new File Manager instance. If 'database' file already

View File

@@ -6,7 +6,7 @@ import (
"path/filepath"
"testing"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
)
type test struct {
@@ -28,13 +28,13 @@ func newTest(t *testing.T) *test {
scope := filepath.Join(temp, "scope")
database := filepath.Join(temp, "database.db")
err = dir.CopyDir("./testdata", scope)
err = fileutils.CopyDir("./testdata", scope)
if err != nil {
t.Fatalf("Error copying the test data: %v", err)
}
user := DefaultUser
user.FileSystem = dir.Dir(scope)
user.FileSystem = fileutils.Dir(scope)
fm, err := New(database, user)

View File

@@ -10,13 +10,13 @@ import (
"path/filepath"
"strings"
"github.com/hacdias/filemanager/dir"
"github.com/hacdias/fileutils"
)
// sanitizeURL sanitizes the URL to prevent path transversal
// using dir.SlashClean and adds the trailing slash bar.
// using fileutils.SlashClean and adds the trailing slash bar.
func sanitizeURL(url string) string {
path := dir.SlashClean(url)
path := fileutils.SlashClean(url)
if strings.HasSuffix(url, "/") && path != "/" {
return path + "/"
}

View File

@@ -1 +1 @@
be97c942365e7a765698a8c0175b4eec18cb4899
8868d0da70d74a9255e7fd2617e88a63ba160479

View File

@@ -1,13 +0,0 @@
package variables
import "reflect"
// IsMap checks if some variable is a map
func IsMap(sth interface{}) bool {
return reflect.ValueOf(sth).Kind() == reflect.Map
}
// IsSlice checks if some variable is a slice
func IsSlice(sth interface{}) bool {
return reflect.ValueOf(sth).Kind() == reflect.Slice
}

View File

@@ -1,49 +0,0 @@
package variables
import "testing"
type interfaceToBool struct {
Value interface{}
Result bool
}
var testIsMap = []*interfaceToBool{
{"teste", false},
{453478, false},
{-984512, false},
{true, false},
{map[string]bool{}, true},
{map[int]bool{}, true},
{map[interface{}]bool{}, true},
{[]string{}, false},
}
func TestIsMap(t *testing.T) {
for _, test := range testIsMap {
if IsMap(test.Value) != test.Result {
t.Errorf("Incorrect value on IsMap for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
}
}
}
var testIsSlice = []*interfaceToBool{
{"teste", false},
{453478, false},
{-984512, false},
{true, false},
{map[string]bool{}, false},
{map[int]bool{}, false},
{map[interface{}]bool{}, false},
{[]string{}, true},
{[]int{}, true},
{[]bool{}, true},
{[]interface{}{}, true},
}
func TestIsSlice(t *testing.T) {
for _, test := range testIsSlice {
if IsSlice(test.Value) != test.Result {
t.Errorf("Incorrect value on IsSlice for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
}
}
}

View File

@@ -1,47 +0,0 @@
package variables
import (
"errors"
"log"
"reflect"
)
// Dict allows to send more than one variable into a template.
func Dict(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
return nil, errors.New("invalid dict call")
}
dict := make(map[string]interface{}, len(values)/2)
for i := 0; i < len(values); i += 2 {
key, ok := values[i].(string)
if !ok {
return nil, errors.New("dict keys must be strings")
}
dict[key] = values[i+1]
}
return dict, nil
}
// FieldInStruct checks if variable is defined in a struct.
func FieldInStruct(data interface{}, field string) bool {
t := reflect.Indirect(reflect.ValueOf(data)).Type()
if t.Kind() != reflect.Struct {
log.Print("Non-struct type not allowed.")
return false
}
_, b := t.FieldByName(field)
return b
}
// StringInSlice checks if a slice contains a string.
func StringInSlice(a string, list []string) (bool, int) {
for i, b := range list {
if b == a {
return true, i
}
}
return false, 0
}

View File

@@ -1,41 +0,0 @@
package variables
import "testing"
type testFieldInStructData struct {
f1 string
f2 bool
f3 int
f4 func()
}
type testFieldInStruct struct {
data interface{}
field string
result bool
}
var testFieldInStructCases = []testFieldInStruct{
{testFieldInStructData{}, "f1", true},
{testFieldInStructData{}, "f2", true},
{testFieldInStructData{}, "f3", true},
{testFieldInStructData{}, "f4", true},
{testFieldInStructData{}, "f5", false},
{[]string{}, "", false},
{map[string]int{"oi": 4}, "", false},
{"asa", "", false},
{"int", "", false},
}
func TestFieldInStruct(t *testing.T) {
for _, pair := range testFieldInStructCases {
v := FieldInStruct(pair.data, pair.field)
if v != pair.result {
t.Error(
"For", pair.data,
"expected", pair.result,
"got", v,
)
}
}
}