Skip to content

Commit

Permalink
Add Addition Optional Flags (#54)
Browse files Browse the repository at this point in the history
* add local port & torrcfile option flags

* update README to reflect new flags
  • Loading branch information
ciehanski authored May 25, 2020
1 parent d4e745f commit 244a7f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ provided:
$ chmod +x onionbox
$ ./onionbox -port 8080 -debug

-port <int> : tell onionbox with port to make your onion service remotely
availble on.
-lport <int> : tell onionbox which port to make your onion service locally
run on.

-rport <int> : tell onionbox which port to make your onion service remotely
available on.

-torv3 <bool> : tell onionbox to run on torv3 or torv2.

-torrc <string> : utilize a custom Torrc file to run your onion service.

-debug <bool> : tell onionbox to print debug logs or silence logs.
```

Expand Down
4 changes: 3 additions & 1 deletion cmd/onionbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func main() {
// Init flags
flag.BoolVar(&ob.Debug, "debug", false, "run in debug mode")
flag.BoolVar(&ob.TorVersion3, "torv3", true, "use version 3 of the Tor circuit (recommended)")
flag.IntVar(&ob.RemotePort, "port", 80, "remote port used to host the onion service")
flag.IntVar(&ob.RemotePort, "rport", 80, "remote port used to host the onion service")
flag.IntVar(&ob.LocalPort, "lport", 0, "local port used to host the onion service")
flag.StringVar(&ob.TorrcFile, "torrc", "", "provide a custom torrc file for the onion service")
flag.Parse()

// Wait at most 3 minutes to publish the service
Expand Down
15 changes: 10 additions & 5 deletions onionbox/onionbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const (
type Onionbox struct {
OnionURL string
RemotePort int
LocalPort int
TorVersion3 bool
TorrcFile string
Store *onionstore.OnionStore
Logger *log.Logger
Server *http.Server
Expand All @@ -47,7 +49,7 @@ func (ob *Onionbox) Init(ctx context.Context) (*tor.Tor, *tor.OnionService, erro
if runtime.GOOS != "windows" {
lj = &lumberjack.Logger{
Filename: "/var/log/onionbox/onionbox.log",
MaxSize: 100, // megabytes
MaxSize: 10, // megabytes
MaxBackups: 3,
MaxAge: 28, // days
Compress: true,
Expand All @@ -57,7 +59,7 @@ func (ob *Onionbox) Init(ctx context.Context) (*tor.Tor, *tor.OnionService, erro
} else {
lj = &lumberjack.Logger{
Filename: "%APPDATA%/Local/onionbox/onionbox.log",
MaxSize: 100, // megabytes
MaxSize: 10, // megabytes
MaxBackups: 3,
MaxAge: 28, // days
Compress: true,
Expand All @@ -71,7 +73,7 @@ func (ob *Onionbox) Init(ctx context.Context) (*tor.Tor, *tor.OnionService, erro
}

// Start Tor
t, err := startTor(torLogger)
t, err := ob.startTor(torLogger)
if err != nil {
return nil, nil, err
}
Expand All @@ -97,7 +99,7 @@ func (ob *Onionbox) Init(ctx context.Context) (*tor.Tor, *tor.OnionService, erro
return t, onionSvc, nil
}

func startTor(logger io.Writer) (*tor.Tor, error) {
func (ob *Onionbox) startTor(logger io.Writer) (*tor.Tor, error) {
fmt.Println("Starting and registering onion service, please wait...")

var tempDataDir string
Expand All @@ -110,9 +112,11 @@ func startTor(logger io.Writer) (*tor.Tor, error) {
t, err := tor.Start(nil, &tor.StartConf{ // Start tor
ProcessCreator: libtor.Creator,
DebugWriter: logger,
UseEmbeddedControlConn: runtime.GOOS != "windows", // This option is not supported on Windows
UseEmbeddedControlConn: true, // Since we are using embedded tor via go-libtor
TempDataDirBase: tempDataDir,
RetainTempDataDir: false,
TorrcFile: ob.TorrcFile,
NoHush: ob.Debug,
})
if err != nil {
return nil, err
Expand All @@ -125,6 +129,7 @@ func (ob *Onionbox) listenTor(ctx context.Context, t *tor.Tor) (*tor.OnionServic
onionSvc, err := t.Listen(ctx, &tor.ListenConf{
Version3: ob.TorVersion3,
RemotePorts: []int{ob.RemotePort},
LocalPort: ob.LocalPort,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 244a7f6

Please sign in to comment.