mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 00:38:33 +02:00
improved default port selection
This commit is contained in:
79
internal/route/port_selection.go
Normal file
79
internal/route/port_selection.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package route
|
||||
|
||||
var (
|
||||
ImageNamePortMapTCP = map[string]int{
|
||||
"mssql": 1433,
|
||||
"mysql": 3306,
|
||||
"mariadb": 3306,
|
||||
"postgres": 5432,
|
||||
"rabbitmq": 5672,
|
||||
"redis": 6379,
|
||||
"memcached": 11211,
|
||||
"mongo": 27017,
|
||||
"minecraft-server": 25565,
|
||||
}
|
||||
|
||||
ImageNamePortMapHTTP = map[string]int{
|
||||
"adguardhome": 3000,
|
||||
"bazarr": 6767,
|
||||
"calibre-web": 8083,
|
||||
"changedetection.io": 3000,
|
||||
"dockge": 5001,
|
||||
"gitea": 3000,
|
||||
"gogs": 3000,
|
||||
"grafana": 3000,
|
||||
"home-assistant": 8123,
|
||||
"homebridge": 8581,
|
||||
"httpd": 80,
|
||||
"immich": 3001,
|
||||
"jellyfin": 8096,
|
||||
"lidarr": 8686,
|
||||
"microbin": 8080,
|
||||
"nginx": 80,
|
||||
"nginx-proxy-manager": 81,
|
||||
"open-webui": 8080,
|
||||
"plex": 32400,
|
||||
"prometheus": 9090,
|
||||
"prowlarr": 9696,
|
||||
"radarr": 7878,
|
||||
"radarr-sma": 7878,
|
||||
"rsshub": 1200,
|
||||
"rss-bridge": 80,
|
||||
"sonarr": 8989,
|
||||
"sonarr-sma": 8989,
|
||||
"uptime-kuma": 3001,
|
||||
"whisparr": 6969,
|
||||
}
|
||||
ImageNamePortMapHTTPS = map[string]int{
|
||||
"portainer-be": 9443,
|
||||
"portainer-ce": 9443,
|
||||
}
|
||||
AliasPortMapHTTP = map[string]int{}
|
||||
AliasPortMapHTTPS = map[string]int{
|
||||
"portainer": 9443,
|
||||
"crafty": 8080,
|
||||
}
|
||||
)
|
||||
|
||||
func getSchemePortByImageName(imageName string, port int) (scheme string, portNum int, ok bool) {
|
||||
if port, ok := ImageNamePortMapHTTP[imageName]; ok {
|
||||
return "http", port, true
|
||||
}
|
||||
if port, ok := ImageNamePortMapHTTPS[imageName]; ok {
|
||||
return "https", port, true
|
||||
}
|
||||
if port, ok := ImageNamePortMapTCP[imageName]; ok {
|
||||
return "tcp", port, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getSchemePortByAlias(alias string, port int) (scheme string, portNum int, ok bool) {
|
||||
if port, ok := AliasPortMapHTTP[alias]; ok {
|
||||
return "http", port, true
|
||||
}
|
||||
if port, ok := AliasPortMapHTTPS[alias]; ok {
|
||||
return "https", port, true
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package route
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yusing/go-proxy/agent/pkg/agent"
|
||||
@@ -262,20 +261,23 @@ func (r *Route) Finalize() {
|
||||
lp, pp := r.Port.Listening, r.Port.Proxy
|
||||
|
||||
if isDocker {
|
||||
if port, ok := common.ImageNamePortMapTCP[cont.ImageName]; ok {
|
||||
scheme, port, ok := getSchemePortByImageName(cont.ImageName, pp)
|
||||
if ok {
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = types.Scheme(scheme)
|
||||
}
|
||||
if pp == 0 {
|
||||
pp = port
|
||||
}
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = "tcp"
|
||||
}
|
||||
} else if port, ok := common.ImageNamePortMapHTTP[cont.ImageName]; ok {
|
||||
if pp == 0 {
|
||||
pp = port
|
||||
}
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = "http"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if scheme, port, ok := getSchemePortByAlias(r.Alias, pp); ok {
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = types.Scheme(scheme)
|
||||
}
|
||||
if pp == 0 {
|
||||
pp = port
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +296,14 @@ func (r *Route) Finalize() {
|
||||
}
|
||||
|
||||
if isDocker {
|
||||
if r.Scheme == "" {
|
||||
for _, p := range cont.PublicPortMapping {
|
||||
if p.PrivatePort == uint16(pp) && p.Type == "udp" {
|
||||
r.Scheme = "udp"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// replace private port with public port if using public IP.
|
||||
if r.Host == cont.PublicHostname {
|
||||
if p, ok := cont.PrivatePortMapping[pp]; ok {
|
||||
@@ -305,21 +315,13 @@ func (r *Route) Finalize() {
|
||||
pp = int(p.PrivatePort)
|
||||
}
|
||||
}
|
||||
if r.Scheme == "" {
|
||||
for _, p := range cont.PublicPortMapping {
|
||||
if p.Type == "udp" {
|
||||
r.Scheme = "udp"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if r.Scheme == "" {
|
||||
switch {
|
||||
case lp != 0:
|
||||
r.Scheme = "tcp"
|
||||
case strings.HasSuffix(strconv.Itoa(pp), "443"):
|
||||
case pp%1000 == 443:
|
||||
r.Scheme = "https"
|
||||
default: // assume its http
|
||||
r.Scheme = "http"
|
||||
|
||||
Reference in New Issue
Block a user