add ip param

This commit is contained in:
YouROK
2025-01-24 18:42:02 +03:00
parent d335016f05
commit f2ffd092ff
4 changed files with 11 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ import (
type args struct { type args struct {
Port string `arg:"-p" help:"web server port (default 8090)"` Port string `arg:"-p" help:"web server port (default 8090)"`
IP string `arg:"-i" help:"web server addr (default empty)"`
Ssl bool `help:"enables https"` Ssl bool `help:"enables https"`
SslPort string `help:"web server ssl port, If not set, will be set to default 8091 or taken from db(if stored previously). Accepted if --ssl enabled."` SslPort string `help:"web server ssl port, If not set, will be set to default 8091 or taken from db(if stored previously). Accepted if --ssl enabled."`
SslCert string `help:"path to ssl cert file. If not set, will be taken from db(if stored previously) or default self-signed certificate/key will be generated. Accepted if --ssl enabled."` SslCert string `help:"path to ssl cert file. If not set, will be taken from db(if stored previously) or default self-signed certificate/key will be generated. Accepted if --ssl enabled."`
@@ -115,7 +116,7 @@ func main() {
} }
} }
server.Start(params.Port, params.SslPort, params.SslCert, params.SslKey, params.Ssl, params.RDB, params.SearchWA) server.Start(params.Port, params.IP, params.SslPort, params.SslCert, params.SslKey, params.Ssl, params.RDB, params.SearchWA)
log.TLogln(server.WaitServer()) log.TLogln(server.WaitServer())
log.Close() log.Close()
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)

View File

@@ -11,7 +11,7 @@ import (
"server/web" "server/web"
) )
func Start(port, sslport, sslCert, sslKey string, sslEnabled, roSets, searchWA bool) { func Start(port, ip, sslport, sslCert, sslKey string, sslEnabled, roSets, searchWA bool) {
settings.InitSets(roSets, searchWA) settings.InitSets(roSets, searchWA)
// https checks // https checks
if sslEnabled { if sslEnabled {
@@ -50,8 +50,9 @@ func Start(port, sslport, sslCert, sslKey string, sslEnabled, roSets, searchWA b
if port == "" { if port == "" {
port = "8090" port = "8090"
} }
log.TLogln("Check web port", port) log.TLogln("Check web port", port)
l, err := net.Listen("tcp", ":"+port) l, err := net.Listen("tcp", ip+":"+port)
if l != nil { if l != nil {
l.Close() l.Close()
} }
@@ -64,6 +65,7 @@ func Start(port, sslport, sslCert, sslKey string, sslEnabled, roSets, searchWA b
// set settings http and https ports. Start web server. // set settings http and https ports. Start web server.
settings.Port = port settings.Port = port
settings.SslPort = sslport settings.SslPort = sslport
settings.IP = ip
web.Start() web.Start()
} }

View File

@@ -10,6 +10,7 @@ import (
var ( var (
tdb TorrServerDB tdb TorrServerDB
Path string Path string
IP string
Port string Port string
Ssl bool Ssl bool
SslPort string SslPort string

View File

@@ -103,14 +103,14 @@ func Start() {
settings.SetBTSets(settings.BTsets) settings.SetBTSets(settings.BTsets)
} }
go func() { go func() {
log.TLogln("Start https server at port", settings.SslPort) log.TLogln("Start https server at", settings.IP+":"+settings.SslPort)
waitChan <- route.RunTLS(":"+settings.SslPort, settings.BTsets.SslCert, settings.BTsets.SslKey) waitChan <- route.RunTLS(settings.IP+":"+settings.SslPort, settings.BTsets.SslCert, settings.BTsets.SslKey)
}() }()
} }
go func() { go func() {
log.TLogln("Start http server at port", settings.Port) log.TLogln("Start http server at", settings.IP+":"+settings.Port)
waitChan <- route.Run(":" + settings.Port) waitChan <- route.Run(settings.IP + ":" + settings.Port)
}() }()
} }