Coder Social home page Coder Social logo

codeskyblue / gohttpserver Goto Github PK

View Code? Open in Web Editor NEW
2.4K 56.0 510.0 3.47 MB

The best HTTP Static File Server, write with golang+vue

License: MIT License

Go 21.20% HTML 8.03% JavaScript 54.09% CSS 14.14% Python 1.26% Shell 1.03% Dockerfile 0.22% Procfile 0.04%
go httpserver

gohttpserver's Introduction

gohttpserver

Build Status Docker Automated build

  • Goal: Make the best HTTP File Server.
  • Features: Human-friendly UI, file uploading support, direct QR-code generation for Apple & Android install package.

Demo site

  • 目标: 做最好的HTTP文件服务器
  • 功能: 人性化的UI体验,文件的上传支持,安卓和苹果安装包的二维码直接生成。

Binaries can be downloaded from this repo releases

Requirements

Tested with go-1.16

Screenshots

screen

Features

  1. Support QRCode code generate
  2. Breadcrumb path quick change
  3. All assets package to Standalone binary
  4. Different file type different icon
  5. Support show or hide hidden files
  6. Upload support (auth by token or session)
  7. README.md preview
  8. HTTP Basic Auth
  9. Partial reload pages when directory change
  10. When only one dir under dir, path will combine two together
  11. Directory zip download
  12. Apple ipa auto generate .plist file, qrcode can be recognized by iphone (Require https)
  13. Plist proxy
  14. Download count statistics
  15. CORS enabled
  16. Offline download
  17. Code file preview
  18. Edit file support
  19. Global file search
  20. Hidden work download and qrcode in small screen
  21. Theme select support
  22. OK to working behide Nginx
  23. .ghs.yml support (like .htaccess)
  24. Calculate md5sum and sha
  25. Folder upload
  26. Support sort by size or modified time
  27. Add version info into index page
  28. Add api /-/info/some.(apk|ipa) to get detail info
  29. Add api /-/apk/info/some.apk to get android package info
  30. Auto tag version
  31. Custom title support
  32. Support setting from conf file
  33. Quick copy download link
  34. Show folder size
  35. Create folder
  36. Skip delete confirm when alt pressed
  37. Support unzip zip file when upload(with form: unzip=true)

Installation

$ go install github.com/codeskyblue/gohttpserver@latest

Or download binaries from github releases

If you are using Mac, simply run command

$ brew install codeskyblue/tap/gohttpserver

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.

Docker Usage

share current directory

$ docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver codeskyblue/gohttpserver

Share current directory with http basic auth

$ docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver \
  codeskyblue/gohttpserver \
  --auth-type http --auth-http username:password

Share current directory with openid auth. (Works only in netease company.)

$ docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver \
  codeskyblue/gohttpserver \
  --auth-type openid

To build image yourself, please change the PWD to the root of this repo.

$ cd gohttpserver/
$ docker build -t codeskyblue/gohttpserver -f docker/Dockerfile .

Authentication options

  • Enable basic http authentication

    $ gohttpserver --auth-type http --auth-http username:password
  • Use openid auth

    $ gohttpserver --auth-type openid --auth-openid https://login.example-hostname.com/openid/
  • Use oauth2-proxy with

    $ gohttpserver --auth-type oauth2-proxy

    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. More about oauth2-proxy.

    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)
  • Enable upload

    $ gohttpserver --upload
  • Enable delete and Create folder

    $ gohttpserver --delete

Advanced usage

Add access rule by creating a .ghs.yml file under a sub-directory. An example:

---
upload: false
delete: false
users:
- email: "[email protected]"
  delete: true
  upload: true
  token: 4567gf8asydhf293r23r

In this case, if openid auth is enabled and user "[email protected]" has logged in, he/she can delete/upload files under the directory where the .ghs.yml file exits.

token is used for upload. see 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.

root -
  |-- foo
  |    |-- .ghs.yml
  |    `-- world.txt 
  `-- bar
       `-- hello.txt

User can specify config file name with --conf, see example config.yml.

To specify which files is hidden and which file is visible, add the following lines to .ghs.yml

accessTables:
- regex: block.file
  allow: false
- regex: visual.file
  allow: true

ipa plist proxy

This is used for server on which https is enabled. default use https://plistproxy.herokuapp.com/plist

$ gohttpserver --plistproxy=https://someproxyhost.com/

Test if proxy works:

$ http POST https://someproxyhost.com/plist < app.plist
{
	"key": "18f99211"
}
$ http GET https://someproxyhost.com/plist/18f99211
# show the app.plist content

If your ghs running behide nginx server and have https configed. plistproxy will be disabled automaticly.

Upload with CURL

For example, upload a file named foo.txt to directory somedir

$ curl -F [email protected] localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}
# upload with token
$ curl -F [email protected] -F token=12312jlkjafs localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}

# upload and change filename
$ curl -F [email protected] -F filename=hi.txt localhost:8000/somedir
{"destination":"somedir/hi.txt","success":true}

Upload zip file and unzip it (zip file will be delete when finished unzip)

$ curl -F [email protected] -F unzip=true localhost:8000/somedir
{"success": true}

Note: \/:*<>| are not allowed in filenames.

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.

Refs: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

gohttpserver also support --prefix flag which will help to when meet / is occupied by other service. relative issue #105

Usage example:

# for gohttpserver
$ gohttpserver --prefix /foo --addr :8200 --xheaders

Nginx settigns

server {
  listen 80;
  server_name your-domain-name.com;

  location /foo {
    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
  }
}

FAQ

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.

  1. hello world means must contains hello and world
  2. hello -world means must contains hello but not contains world

Developer Guide

Depdencies are managed by govendor

  1. Build develop version. assets directory must exists
$ go build
$ ./gohttpserver
  1. Build single binary release
$ go build

Theme are defined in assets/themes directory. Now only two themes are available, "black" and "green".

Reference Web sites

Go Libraries

History

The old version is hosted at https://github.com/codeskyblue/gohttp

LICENSE

This project is licensed under MIT.

gohttpserver's People

Contributors

adolli avatar aeoluswing avatar altfoxie avatar codeskyblue avatar dependabot[bot] avatar fx-hao avatar gengjiawen avatar hathlife avatar kforeverisback avatar krypty avatar miguelnv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gohttpserver's Issues

Need user login sign up

Anybody can upload? That is huge risk.
Can you add user sign up and user login?
Only logined user can upload!

Add user management is MUST have feature, for it to be useful.
Super admin can disable other user, add, delete other users.

文件是否可以按文件名排序?

1、列表中的文件是否可以按文件夹和文件名进行排序?如:似windows的文件资源管理器中的显示。
2、文件夹内的总文件大小不正确(服务端在windows系统平台),有些显示“~ 0 B”实际文件夹内是有文件,且文件是有内容大小不为0B的。

can I search file by name?

I try to search file by file name, (NOT text contend inside file).
I want to find all file name, that have "xxxx", but nothing return.

How to use the search box on top right corner?

Can you wrote some details in READ ME, teach us how to use search function?

上传文件大于500k 时报 java.net.SocketException: Connection reset by peer: socket write error

        httpClient = HttpClients.custom().setDefaultCredentialsProvider(provider).build();

        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        File file=new File(fileName);
        builder.addBinaryBody("file",file,ContentType.APPLICATION_FORM_URLENCODED,file.getName());

        HttpEntity reqEntity = builder.build();
        httpPost = new HttpPost(serverUrl);
        httpPost.setEntity(reqEntity);
        response = httpClient.execute(httpPost);

why search file does not works for me?

I try the demon https://gohttpserver.herokuapp.com

on right top corner, search text box, I type 'readme' it only works one time.

then it stop working.

Then I try type 'image.jpg' in search box right top corner, then nothing. This file is under 'filetypes' folder, why it not find?

Can you advise, why, this happen to me?

Configure temp folder

Is there a way to configure the server to use a custom directory instead of /tmp for uploads?

希望加个分享码下载功能哈

增加分享功能,分享就生成一个临时的带有token(有有效期)的url。也可以设置永久token分享。随时可以取消分享。并且提供curl的方式来直接用。

How to setup https(ssl)?

I see your code support https, but I am not sure, how and where,
can you write more details how and where on README?
I know this is go and https question, should not be here,
but since your code already support https, your simple a few words will helps alot.

What I don't know is where to setup gcfg.Cert, gcfg.Key?

I have 2 files "public.cert" and "private.key"
where should I put these 2 files for https,

And does config.yml need to update?
how to connect gcfg.Cert, gcfg.Key to those 2 files?

I also try

    gcfg.Cert = "./public.cert"
gcfg.Key = "./private.key"

and put those 2 files at ./ , failed.

   var err error
if gcfg.Key != "" && gcfg.Cert != "" {
	err = http.ListenAndServeTLS(gcfg.Addr, gcfg.Cert, gcfg.Key, nil)
} else {
	err = http.ListenAndServe(gcfg.Addr, nil)
}
log.Fatal(err)

can you add support for Okta ? online authentication

www.okta.com

is a very popular online user management and online authentication, authorization management.

It is have open-id connect supported. ......

If gohttpserver and support okta, then you do NOT need write any code for user management

like sign up, sign in, forget password, retrieve password, reset password, add a new user, assign user a role, role management, etc........ okta can do it for you.

you only need to write a middle ware to connect to okta.

This is best choice for now to add user management to gohttpserver.

how to delete a file?

I know I can upload and download file,

But how to delete a file, I just uploaded?

how to run it on linux as background?

Lots of friends have same issue, I spend 5 hours to figure it out, just share with friends here.

// run it as background

// create file, save to where you call gohttpserver folder.

// create config file

// use nano to edit, or you can create it at windows, use winSCP to copy over
nano supervisord.conf

// type content
[program:supervisord] command=./gohttpserver -r ./fileRestAPI --cors

If you want to save the changes you've made, press Ctrl + O.
To exit nano, type Ctrl + X. If you ask nano to exit from a modified file, it will ask you if you want to save it.
Just press N in case you don't, or Y in case you do. It will then ask you for a filename.
Just type it in and press Enter.

//start supervisord

     supervisord -c supervisord.conf

//stop supervisord
// first switch to root user
sudo su
cd /home/hoogw/gowork/src/github.com/codeskyblue/gohttpserver

https://stackoverflow.com/questions/14479894/stopping-supervisord-shut-down
ps -ef | grep supervisord
kill -s SIGTERM 15923 ( only one number a line , line with 2 number are NOT right)
http://supervisord.org/running.html#signals

When you do this:
ps -ef | grep supervisord
//You will get some pid of supervisord just like these

//root 2641 12938 0 04:52 pts/1 00:00:00 grep --color=auto supervisord

//root 29646 1 0 04:45 ? 00:00:00 /usr/bin/python /usr/local/bin/supervisord

if you get output like that, your pid is the second one ( with only one number, it will not change if you run again again, but other number are changing. then if you want to shut down your supervisord you can do this

    kill -s SIGTERM 29646

Here is full supervisord.conf

                     [unix_http_server]
                        file=/tmp/supervisor.sock                       ; path to your socket file


              [supervisord]
              ;logfile=/var/log/supervisord/supervisord.log    ; supervisord log file
              ;logfile_maxbytes=50MB                           ; maximum size of logfile before rotation
              ;logfile_backups=10                              ; number of backed up logfiles
              ;loglevel=error                                  ; info, debug, warn, trace
                ;pidfile=/var/run/supervisord.pid                ; pidfile location
             nodaemon=false                                  ; run supervisord as a daemon
                minfds=1024                                     ; number of startup file descriptors
                minprocs=200                                    ; number of process descriptors
               user=root                                       ; default user
                   ;childlogdir=/var/log/supervisord/               ; where child log files will




                   [program:fileRestAPI]
                  command=./gohttpserver -r ./fileRestAPI --cors
                      ;command=gohttpserver -r ./fileRestAPI --port 8000 --upload --delete --cors


                      [supervisorctl]
                          serverurl=unix:///tmp/supervisor.sock         ; use a unix:// URL  for a unix socket

openid-login.go failed?????

Openid half way working, be able to login into yahoo.com,
but failed when opencallback.......

google openid, does not working.
--auth-openid https://www.google.com/accounts/o8/id

            // google not working
          ./gohttpserver -r ../../../../../fileRestAPI --cors --theme green  --auth-type openid --auth-openid https://www.google.com/accounts/o8/id

yahoo works
--auth-openid https://me.yahoo.com

               // yahoo
              ./gohttpserver -r ../../../../../fileRestAPI --conf ../../../../../fileRestAPI/config.yml --cors --theme green  --auth-type openid --auth-openid https://me.yahoo.com

But, when I successfully login to yahoo.com, when opencallback to gohttpserver, failed.....

                   http://localhost:8000/-/openidcallback?next=https://localhost:8000/&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.return_to=http%3A%2F%2Flocalhost%3A8000%2F-%2Fopenidcallback%3Fnext%3Dhttps%3A%2F%2Flocalhost%3A8000%2F&openid.claimed_id=https%3A%2F%2Fme.yahoo.com%2Fhoogw%23d0256&openid.identity=https%3A%2F%2Fme.yahoo.com%2Fhoogw&openid.assoc_handle=iLcVVWGjabUDODayEuijpKo3jpFxkVv9JI3xrIfcq3PxxWx0Sg3Ye4d7Hnd3BChYXWANhSEYTSfCaMMuaE.V5rDxZt3kSjJvzHtxzC6Qb3MXC3hkDE8fjvwn5jFWbXWIdj4z&openid.response_nonce=2018-12-21T22%3A44%3A55ZLJJRMAiKQCrRV8GGkWoFej0IGqDKnTzG2A--&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned%2Cpape.auth_level.nist&openid.op_endpoint=https%3A%2F%2Fopen.login.yahooapis.com%2Fopenid%2Fop%2Fauth&openid.pape.auth_level.nist=0&openid.sig=e5FBX8bstv7U9hVukR4r%2BjpDtLs%3D

I test openid-go, sample login on separate port 8080, it successfully login to yahoo.com and back.

If your project use same code as openid-go, why their sample login page work, but this login page only work half way, when opencallback, it fails.......

Can you try this
--auth-openid https://me.yahoo.com

Did you successfully login and back without error?

file name with '&', failed to load

some time, user just use special char, like &, #, @, etc.... as file name.

then failed to load those files.

Please advice a way to work around?

监听443端口和80端口

自己申请了个证书,然后启动的时候加上证书参数并监听443端口,浏览器直接用https加域名可以访问,但是如果直接域名访问浏览器会默认访问80端口,然后服务器只监听了443端口所以没办法自动跳转到443。能做一个https模式同时监听443和80吗?监听到80有链接就跳到443

godep go run main.go or go run main.go

.\main.go:140:8: undefined: NewHTTPStaticServer
.\main.go:170:3: undefined: handleOpenID
怎么打开看看效果
localhost:8000? localhost:8000/testdata?
空白和404

Run on android & ios

Could you provide some releases for windows, linux, mac or android & ios? And also, you can provide a qr code to help mobile phone to visit your file server.

rest api feature?

Is it possible add new feature as rest api?

for example:

http://localhost:8000/xxx?f=json

this url will response as a json instead of html.

` {
subfolder: {
{ folder: xxxx1},
{ folder: xxxx1}
},

file: {
{file: yyy1},
{file: yyy2}
.....
}

}`

you also can add other meta data info into this json.

Why do this, is because if you have this rest api, I can write page easy search file name(since all file name, file info are in Json format.)

I mean, you have build the website, if you add rest api for this web site, will be very useful for third party wrote apps to communicate with your site.

For example, twitter rest api, facebook rest api, flickr rest api. etc......

带中文路径生成二维码,扫描会出现乱码url

修正res/js/index.js
genQrcode: function(text, title) {
var urlPath = this.genInstallURL(text);
var str = urlPath;
var arr = str.split("/");
arr[arr.length - 1] = encodeURI(arr[arr.length - 1]);
var dir = arr.join("/");
$("#qrcode-title").html(title || text);
$("#qrcode-link").attr("href", urlPath);
$('#qrcodeCanvas').empty().qrcode({
text: dir
});
$("#qrcode-modal").modal("show");
},

View in Phone产生错误的URL

在本地启动服务,在根目录下点击View in Phone之后地址是这样的http://127.0.0.1:8000/http:/127.0.0.1:8000/

請問如何與 supervisor 整合?

感謝您提供的這個程式,非常簡單好用
不過我在嘗試著用 supervisor去啟動這個程式發生問題

2018/10/18 08:25:25 httpstaticserver.go:111: GET  /home/neonexus/center_yaml
2018/10/18 08:25:25 httpstaticserver.go:749: Hot load index.html
2018/10/18 08:25:25 server.go:2923: http: panic serving 192.168.11.34:43870: open assets/index.html: no such file or directory
goroutine 76 [running]:
net/http.(*conn).serve.func1(0xc420348280)
	/usr/lib/go-1.10/src/net/http/server.go:1726 +0xd0
panic(0x8b0e20, 0xc4204513e0)
	/usr/lib/go-1.10/src/runtime/panic.go:502 +0x229

我用底下的指令,在console下啟動沒有問題,可是丟到 supervisor 啟動就會發生上面的錯誤,找不到 assets 底下的內容?

/usr/local/bin/gohttpserver -r /home/neo/center_yaml/ --port 5000 --upload --delete --debug  --auth-type http --auth-http abc:abc123

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.