Initial commit: docker compose config
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"server/proxy"
|
||||
"sort"
|
||||
|
||||
"server/torrfs/fuse"
|
||||
"server/torrfs/webdav"
|
||||
|
||||
"server/rutor"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/location/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/wlynxg/anet"
|
||||
|
||||
"server/dlna"
|
||||
"server/settings"
|
||||
"server/web/msx"
|
||||
|
||||
"server/log"
|
||||
"server/torr"
|
||||
"server/version"
|
||||
"server/web/api"
|
||||
"server/web/auth"
|
||||
"server/web/blocker"
|
||||
"server/web/pages"
|
||||
"server/web/sslcerts"
|
||||
|
||||
swaggerFiles "github.com/swaggo/files" // swagger embed files
|
||||
ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||
)
|
||||
|
||||
var (
|
||||
BTS = torr.NewBTS()
|
||||
waitChan = make(chan error)
|
||||
)
|
||||
|
||||
// @title Swagger Torrserver API
|
||||
// @version {version.Version}
|
||||
// @description Torrent streaming server.
|
||||
|
||||
// @license.name GPL 3.0
|
||||
|
||||
// @BasePath /
|
||||
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
|
||||
// @externalDocs.description OpenAPI
|
||||
// @externalDocs.url https://swagger.io/resources/open-api/
|
||||
func Start() {
|
||||
log.TLogln("Start TorrServer " + version.Version + " torrent " + version.GetTorrentVersion())
|
||||
ips := GetLocalIps()
|
||||
if len(ips) > 0 {
|
||||
log.TLogln("Local IPs:", ips)
|
||||
}
|
||||
err := BTS.Connect()
|
||||
if err != nil {
|
||||
log.TLogln("BTS.Connect() error!", err) // waitChan <- err
|
||||
os.Exit(1) // return
|
||||
}
|
||||
rutor.Start()
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
// corsCfg := cors.DefaultConfig()
|
||||
// corsCfg.AllowAllOrigins = true
|
||||
// corsCfg.AllowHeaders = []string{"*"}
|
||||
// corsCfg.AllowMethods = []string{"*"}
|
||||
corsCfg := cors.DefaultConfig()
|
||||
corsCfg.AllowAllOrigins = true
|
||||
corsCfg.AllowPrivateNetwork = true
|
||||
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
|
||||
|
||||
route := gin.New()
|
||||
route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.New(corsCfg), location.Default())
|
||||
auth.SetupAuth(route)
|
||||
|
||||
route.GET("/echo", echo)
|
||||
|
||||
api.SetupRoute(route)
|
||||
msx.SetupRoute(route)
|
||||
pages.SetupRoute(route)
|
||||
if settings.Args.WebDAV {
|
||||
webdav.MountWebDAV(route)
|
||||
}
|
||||
|
||||
if settings.BTsets.EnableDLNA {
|
||||
dlna.Start()
|
||||
}
|
||||
|
||||
// Auto-mount FUSE filesystem if enabled
|
||||
fuse.FuseAutoMount()
|
||||
|
||||
route.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// check if https enabled
|
||||
if settings.Ssl {
|
||||
// if no cert and key files set in db/settings, generate new self-signed cert and key files
|
||||
if settings.BTsets.SslCert == "" || settings.BTsets.SslKey == "" {
|
||||
settings.BTsets.SslCert, settings.BTsets.SslKey = sslcerts.MakeCertKeyFiles(ips)
|
||||
log.TLogln("Saving path to ssl cert and key in db", settings.BTsets.SslCert, settings.BTsets.SslKey)
|
||||
settings.SetBTSets(settings.BTsets)
|
||||
}
|
||||
// verify if cert and key files are valid
|
||||
err = sslcerts.VerifyCertKeyFiles(settings.BTsets.SslCert, settings.BTsets.SslKey, settings.SslPort)
|
||||
// if not valid, generate new self-signed cert and key files
|
||||
if err != nil {
|
||||
log.TLogln("Error checking certificate and private key files:", err)
|
||||
settings.BTsets.SslCert, settings.BTsets.SslKey = sslcerts.MakeCertKeyFiles(ips)
|
||||
log.TLogln("Saving path to ssl cert and key in db", settings.BTsets.SslCert, settings.BTsets.SslKey)
|
||||
settings.SetBTSets(settings.BTsets)
|
||||
}
|
||||
go func() {
|
||||
log.TLogln("Start https server at", settings.IP+":"+settings.SslPort)
|
||||
waitChan <- route.RunTLS(settings.IP+":"+settings.SslPort, settings.BTsets.SslCert, settings.BTsets.SslKey)
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
addr := settings.IP + ":" + settings.Port
|
||||
if settings.Args != nil && settings.Args.ForceHTTPS && settings.Ssl {
|
||||
waitChan <- runHTTPRedirectToHTTPS(addr)
|
||||
return
|
||||
}
|
||||
log.TLogln("Start http server at", addr)
|
||||
waitChan <- route.Run(addr)
|
||||
}()
|
||||
}
|
||||
|
||||
func Wait() error {
|
||||
return <-waitChan
|
||||
}
|
||||
|
||||
func Stop() {
|
||||
dlna.Stop()
|
||||
// Unmount FUSE filesystem if mounted
|
||||
fuse.FuseCleanup()
|
||||
BTS.Disconnect()
|
||||
proxy.Stop()
|
||||
waitChan <- nil
|
||||
}
|
||||
|
||||
// echo godoc
|
||||
//
|
||||
// @Summary Tests server status
|
||||
// @Description Tests whether server is alive or not
|
||||
//
|
||||
// @Tags API
|
||||
//
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "Server version"
|
||||
// @Router /echo [get]
|
||||
func echo(c *gin.Context) {
|
||||
c.String(200, "%v", version.Version)
|
||||
}
|
||||
|
||||
func GetLocalIps() []string {
|
||||
ifaces, err := anet.Interfaces()
|
||||
if err != nil {
|
||||
log.TLogln("Error get local IPs")
|
||||
return nil
|
||||
}
|
||||
var list []string
|
||||
for _, i := range ifaces {
|
||||
addrs, _ := anet.InterfaceAddrsByInterface(&i)
|
||||
if i.Flags&net.FlagUp == net.FlagUp {
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsLinkLocalMulticast() {
|
||||
list = append(list, ip.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(list)
|
||||
return list
|
||||
}
|
||||
Reference in New Issue
Block a user