mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-15 12:55:41 +01:00
feature (tor): cooking some onions - Unstable
This commit is contained in:
parent
3d9fa49698
commit
2ae2673df9
2 changed files with 36 additions and 1 deletions
|
|
@ -2,7 +2,6 @@ package plugin
|
|||
|
||||
import (
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_http"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tor"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_light"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav"
|
||||
|
|
|
|||
36
server/plugin/plg_starter_tor/index.go
Normal file
36
server/plugin/plg_starter_tor/index.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package plg_start_tor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cretz/bine/tor"
|
||||
"github.com/gorilla/mux"
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Hooks.Register.Starter(func (r *mux.Router) {
|
||||
Log.Info("[tor] starting ...")
|
||||
t, err := tor.Start(nil, nil)
|
||||
if err != nil {
|
||||
Log.Error("[tor] Unable to start Tor: %v", err)
|
||||
return
|
||||
}
|
||||
defer t.Close()
|
||||
listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer listenCancel()
|
||||
onion, err := t.Listen(listenCtx, &tor.ListenConf{Version3: true, RemotePorts: []int{80}})
|
||||
if err != nil {
|
||||
Log.Error("[tor] Unable to create onion service: %v", err)
|
||||
return
|
||||
}
|
||||
defer onion.Close()
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: r,
|
||||
}
|
||||
Log.Info("[tor] started on http://%v.onion\n", onion.ID)
|
||||
srv.Serve(onion)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue