gohttpserver/README.md

307 lines
8.7 KiB
Markdown
Raw Permalink Normal View History

2016-07-26 04:43:08 +02:00
# gohttpserver
This is a fork from [codeskyblue/gohttpserver](https://github.com/codeskyblue/gohttpserver/) without google-analytics.
- Goal: Make the best HTTP File Server.
- Features: Human-friendly UI, file uploading support, direct QR-code generation for Apple & Android install package.
2016-07-29 10:49:42 +02:00
2016-07-30 05:00:04 +02:00
[Demo site](https://gohttpserver.herokuapp.com/)
2016-07-30 04:39:23 +02:00
- 目标: 做最好的HTTP文件服务器
- 功能: 人性化的UI体验文件的上传支持安卓和苹果安装包的二维码直接生成。
2016-07-21 11:03:45 +02:00
2016-08-01 05:19:50 +02:00
2018-09-25 08:35:41 +02:00
## Requirements
2021-03-26 08:41:28 +01:00
Tested with go-1.16
2016-07-21 11:03:45 +02:00
2016-07-29 14:37:39 +02:00
## Screenshots
2016-08-02 08:43:15 +02:00
![screen](testdata/filetypes/gohttpserver.gif)
2016-07-29 14:37:39 +02:00
2016-07-24 11:25:38 +02:00
## Features
2016-07-24 17:18:49 +02:00
1. [x] Support QRCode code generate
2016-07-26 04:38:41 +02:00
1. [x] Breadcrumb path quick change
2016-07-26 08:06:01 +02:00
1. [x] All assets package to Standalone binary
2016-07-25 16:51:11 +02:00
1. [x] Different file type different icon
2016-07-26 11:26:12 +02:00
1. [x] Support show or hide hidden files
1. [x] Upload support (auth by token or session)
2016-07-27 04:50:18 +02:00
1. [x] README.md preview
2016-07-24 11:25:38 +02:00
1. [x] HTTP Basic Auth
2016-07-26 04:38:41 +02:00
1. [x] Partial reload pages when directory change
2016-07-26 13:30:59 +02:00
1. [x] When only one dir under dir, path will combine two together
1. [x] Directory zip download
2016-07-28 09:29:21 +02:00
1. [x] Apple ipa auto generate .plist file, qrcode can be recognized by iphone (Require https)
1. [x] Plist proxy
2016-07-24 11:25:38 +02:00
1. [ ] Download count statistics
2016-07-26 07:27:36 +02:00
1. [x] CORS enabled
2016-07-24 11:25:38 +02:00
1. [ ] Offline download
2016-07-30 04:39:23 +02:00
1. [ ] Code file preview
2016-07-24 11:25:38 +02:00
1. [ ] Edit file support
2016-07-31 05:47:02 +02:00
1. [x] Global file search
2016-07-26 04:43:08 +02:00
1. [x] Hidden work `download` and `qrcode` in small screen
2016-07-26 16:00:22 +02:00
1. [x] Theme select support
2016-07-27 13:31:51 +02:00
1. [x] OK to working behide Nginx
2016-08-03 03:41:38 +02:00
1. [x] \.ghs.yml support (like \.htaccess)
2016-07-28 02:28:46 +02:00
1. [ ] Calculate md5sum and sha
2016-07-27 16:27:13 +02:00
1. [ ] Folder upload
2016-07-28 02:28:46 +02:00
1. [ ] Support sort by size or modified time
1. [x] Add version info into index page
1. [ ] Add api `/-/info/some.(apk|ipa)` to get detail info
2017-05-09 10:36:40 +02:00
1. [x] Add api `/-/apk/info/some.apk` to get android package info
2016-07-31 04:19:32 +02:00
1. [x] Auto tag version
1. [x] Custom title support
1. [x] Support setting from conf file
2016-08-05 07:42:52 +02:00
1. [x] Quick copy download link
2017-05-17 04:28:00 +02:00
1. [x] Show folder size
2018-09-14 15:03:27 +02:00
1. [x] Create folder
2018-09-25 09:59:38 +02:00
1. [x] Skip delete confirm when alt pressed
2019-02-15 10:28:46 +01:00
1. [x] Support unzip zip file when upload(with form: unzip=true)
2016-07-24 11:25:38 +02:00
2016-07-21 11:03:45 +02:00
## Installation
```
2016-07-26 04:43:08 +02:00
go get -v github.com/codeskyblue/gohttpserver
2016-07-29 14:37:39 +02:00
cd $GOPATH/src/github.com/codeskyblue/gohttpserver
go build && ./gohttpserver
2016-07-21 11:03:45 +02:00
```
2018-09-25 08:35:41 +02:00
## Usage
Listen on port 8000 of all interfaces, and enable file uploading.
```
./gohttpserver -r ./ --port 8000 --upload
```
Use command `gohttpserver --help` to see more usage.
2021-04-01 11:31:01 +02:00
## Docker Usage
share current directory
```bash
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver registry.hhhammer.de/gohttpserver
```
Share current directory with http basic auth
```bash
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver \
registry.hhhammer.de/gohttpserver \
--auth-type http --auth-http username:password
```
Share current directory with openid auth. (Works only in netease company.)
```bash
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver \
registry.hhhammer.de/gohttpserver \
--auth-type openid
```
To build image yourself, please change the PWD to the root of this repo.
```bash
cd gohttpserver/
docker build -t registry.hhhhammer.de/gohttpserver -f docker/Dockerfile .
```
## Authentication options
- Enable basic http authentication
2016-12-22 04:46:29 +01:00
```sh
$ gohttpserver --auth-type http --auth-http username:password
```
- Use openid auth
2016-12-22 04:46:29 +01:00
```sh
$ gohttpserver --auth-type openid --auth-openid https://login.example-hostname.com/openid/
```
2019-02-22 03:54:37 +01:00
- Use oauth2-proxy with
2019-02-21 08:41:09 +01:00
```sh
$ gohttpserver --auth-type oauth2-proxy
```
2019-02-22 03:54:37 +01:00
You can configure to let a http reverse proxy handling authentication.
When using oauth2-proxy, the backend will use identification info from request headers `X-Auth-Request-Email` as userId and `X-Auth-Request-Fullname` as user's display name.
Please config your oauth2 reverse proxy yourself.
2021-04-01 05:16:51 +02:00
More about [oauth2-proxy](https://github.com/oauth2-proxy/oauth2-proxy).
2019-02-22 03:54:37 +01:00
All required headers list as following.
|header|value|
|---|---|
|X-Auth-Request-Email| userId |
|X-Auth-Request-Fullname| user's display name(urlencoded) |
|X-Auth-Request-User| user's nickname (mostly email prefix) |
2019-02-21 08:41:09 +01:00
- Enable upload
```sh
$ gohttpserver --upload
```
- Enable delete and Create folder
```sh
$ gohttpserver --delete
```
2016-08-02 07:34:02 +02:00
## Advanced usage
Add access rule by creating a `.ghs.yml` file under a sub-directory. An example:
2016-08-02 07:34:02 +02:00
```yaml
---
upload: false
2016-12-22 04:46:29 +01:00
delete: false
users:
- email: "codeskyblue@codeskyblue.com"
delete: true
upload: true
token: 4567gf8asydhf293r23r
2016-08-02 07:34:02 +02:00
```
In this case, if openid auth is enabled and user "codeskyblue@codeskyblue.com" has logged in, he/she can delete/upload files under the directory where the `.ghs.yml` file exits.
2016-12-22 04:46:29 +01:00
`token` is used for upload. see [upload with curl](#upload-with-curl)
For example, in the following directory hierarchy, users can delete/uploade files in directory `foo`, but he/she cannot do this in directory `bar`.
2016-08-02 07:34:02 +02:00
```
root -
|-- foo
| |-- .ghs.yml
| `-- world.txt
`-- bar
`-- hello.txt
```
User can specify config file name with `--conf`, see [example config.yml](testdata/config.yml).
To specify which files is hidden and which file is visible, add the following lines to `.ghs.yml`
2016-12-21 08:47:03 +01:00
```yaml
accessTables:
- regex: block.file
allow: false
- regex: visual.file
allow: true
```
2016-07-28 09:29:21 +02:00
### ipa plist proxy
This is used for server on which https is enabled. default use <https://plistproxy.herokuapp.com/plist>
2016-07-28 09:29:21 +02:00
```
./gohttpserver --plistproxy=https://someproxyhost.com/
```
Test if proxy works:
2016-08-01 08:02:24 +02:00
```sh
2018-09-25 08:35:41 +02:00
$ http POST https://someproxyhost.com/plist < app.plist
2016-08-01 08:02:24 +02:00
{
"key": "18f99211"
}
2018-09-25 08:35:41 +02:00
$ http GET https://someproxyhost.com/plist/18f99211
2016-08-01 08:02:24 +02:00
# show the app.plist content
```
2016-07-28 09:29:21 +02:00
If your ghs running behide nginx server and have https configed. plistproxy will be disabled automaticly.
2016-07-27 16:22:16 +02:00
### Upload with CURL
For example, upload a file named `foo.txt` to directory `somedir`
```sh
$ curl -F file=@foo.txt localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}
# upload with token
$ curl -F file=@foo.txt -F token=12312jlkjafs localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}
2018-09-26 14:06:09 +02:00
# upload and change filename
$ curl -F file=@foo.txt -F filename=hi.txt localhost:8000/somedir
{"destination":"somedir/hi.txt","success":true}
2016-07-21 11:03:45 +02:00
```
2016-07-21 11:13:40 +02:00
2019-02-15 10:28:46 +01:00
Upload zip file and unzip it (zip file will be delete when finished unzip)
```
$ curl -F file=@pkg.zip -F unzip=true localhost:8000/somedir
{"success": true}
```
2018-09-28 05:29:11 +02:00
Note: `\/:*<>|` are not allowed in filenames.
2018-09-26 14:06:09 +02:00
2018-09-25 08:35:41 +02:00
### Deploy with nginx
Recommended configuration, assume your gohttpserver listening on `127.0.0.1:8200`
```
server {
listen 80;
server_name your-domain-name.com;
location / {
proxy_pass http://127.0.0.1:8200; # here need to change
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0; # disable upload limit
}
}
```
gohttpserver should started with `--xheaders` argument when behide nginx.
2018-09-25 08:35:41 +02:00
Refs: <http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size>
2016-07-24 10:51:57 +02:00
## FAQ
- [How to generate self signed certificate with openssl](http://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl)
### How the query is formated
The search query follows common format rules just like Google. Keywords are seperated with space(s), keywords with prefix `-` will be excluded in search results.
2016-08-01 03:37:59 +02:00
1. `hello world` means must contains `hello` and `world`
1. `hello -world` means must contains `hello` but not contains `world`
2016-07-21 11:13:40 +02:00
## Developer Guide
2018-09-25 08:35:41 +02:00
Depdencies are managed by [govendor](https://github.com/kardianos/govendor)
2016-07-21 11:13:40 +02:00
2018-09-25 08:35:41 +02:00
1. Build develop version. **assets** directory must exists
2016-07-26 08:06:01 +02:00
2018-09-25 08:35:41 +02:00
```sh
go build
./gohttpserver
```
2. Build single binary release
```sh
go generate .
go build -tags vfs
```
Theme are defined in [assets/themes](assets/themes) directory. Now only two themes are available, "black" and "green".
2016-07-26 16:00:22 +02:00
2016-07-21 11:13:40 +02:00
2016-07-26 08:06:01 +02:00
## Reference Web sites
2016-07-21 11:13:40 +02:00
2016-08-03 03:41:38 +02:00
* Core lib Vue <https://vuejs.org.cn/>
2016-07-24 12:32:57 +02:00
* Icon from <http://www.easyicon.net/558394-file_explorer_icon.html>
2016-07-26 11:26:12 +02:00
* Code Highlight <https://craig.is/making/rainbows>
2016-08-03 03:41:38 +02:00
* Markdown Parser <https://github.com/showdownjs/showdown>
* Markdown CSS <https://github.com/sindresorhus/github-markdown-css>
* Upload support <http://www.dropzonejs.com/>
* ScrollUp <https://markgoodyear.com/2013/01/scrollup-jquery-plugin/>
2016-08-05 11:36:13 +02:00
* Clipboard <https://clipboardjs.com/>
* Underscore <http://underscorejs.org/>
2016-08-03 03:41:38 +02:00
**Go Libraries**
2018-09-14 15:03:27 +02:00
* [vfsgen](https://github.com/shurcooL/vfsgen)
* [go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs) Not using now
2016-07-27 08:10:03 +02:00
* <http://www.gorillatoolkit.org/pkg/handlers>
2016-07-26 08:06:01 +02:00
2016-07-30 04:39:23 +02:00
## History
The old version is hosted at <https://github.com/codeskyblue/gohttp>
2016-07-30 04:39:23 +02:00
2016-07-21 11:03:45 +02:00
## LICENSE
This project is licensed under [MIT](LICENSE).