mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
improved default port selection
This commit is contained in:
parent
409048c206
commit
0a8bb7eae5
2 changed files with 56 additions and 33 deletions
|
@ -1,15 +1,6 @@
|
||||||
//nolint:misspell
|
package route
|
||||||
package common
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
WellKnownHTTPPorts = map[string]bool{
|
|
||||||
"80": true,
|
|
||||||
"8000": true,
|
|
||||||
"8008": true,
|
|
||||||
"8080": true,
|
|
||||||
"3000": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageNamePortMapTCP = map[string]int{
|
ImageNamePortMapTCP = map[string]int{
|
||||||
"mssql": 1433,
|
"mssql": 1433,
|
||||||
"mysql": 3306,
|
"mysql": 3306,
|
||||||
|
@ -42,8 +33,6 @@ var (
|
||||||
"nginx-proxy-manager": 81,
|
"nginx-proxy-manager": 81,
|
||||||
"open-webui": 8080,
|
"open-webui": 8080,
|
||||||
"plex": 32400,
|
"plex": 32400,
|
||||||
"portainer-be": 9443,
|
|
||||||
"portainer-ce": 9443,
|
|
||||||
"prometheus": 9090,
|
"prometheus": 9090,
|
||||||
"prowlarr": 9696,
|
"prowlarr": 9696,
|
||||||
"radarr": 7878,
|
"radarr": 7878,
|
||||||
|
@ -55,4 +44,36 @@ var (
|
||||||
"uptime-kuma": 3001,
|
"uptime-kuma": 3001,
|
||||||
"whisparr": 6969,
|
"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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/agent/pkg/agent"
|
"github.com/yusing/go-proxy/agent/pkg/agent"
|
||||||
|
@ -262,21 +261,24 @@ func (r *Route) Finalize() {
|
||||||
lp, pp := r.Port.Listening, r.Port.Proxy
|
lp, pp := r.Port.Listening, r.Port.Proxy
|
||||||
|
|
||||||
if isDocker {
|
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 {
|
if pp == 0 {
|
||||||
pp = port
|
pp = port
|
||||||
}
|
}
|
||||||
if r.Scheme == "" {
|
|
||||||
r.Scheme = "tcp"
|
|
||||||
}
|
}
|
||||||
} else if port, ok := common.ImageNamePortMapHTTP[cont.ImageName]; ok {
|
}
|
||||||
|
|
||||||
|
if scheme, port, ok := getSchemePortByAlias(r.Alias, pp); ok {
|
||||||
|
if r.Scheme == "" {
|
||||||
|
r.Scheme = types.Scheme(scheme)
|
||||||
|
}
|
||||||
if pp == 0 {
|
if pp == 0 {
|
||||||
pp = port
|
pp = port
|
||||||
}
|
}
|
||||||
if r.Scheme == "" {
|
|
||||||
r.Scheme = "http"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pp == 0 {
|
if pp == 0 {
|
||||||
|
@ -294,6 +296,14 @@ func (r *Route) Finalize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if isDocker {
|
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.
|
// replace private port with public port if using public IP.
|
||||||
if r.Host == cont.PublicHostname {
|
if r.Host == cont.PublicHostname {
|
||||||
if p, ok := cont.PrivatePortMapping[pp]; ok {
|
if p, ok := cont.PrivatePortMapping[pp]; ok {
|
||||||
|
@ -305,21 +315,13 @@ func (r *Route) Finalize() {
|
||||||
pp = int(p.PrivatePort)
|
pp = int(p.PrivatePort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r.Scheme == "" {
|
|
||||||
for _, p := range cont.PublicPortMapping {
|
|
||||||
if p.Type == "udp" {
|
|
||||||
r.Scheme = "udp"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Scheme == "" {
|
if r.Scheme == "" {
|
||||||
switch {
|
switch {
|
||||||
case lp != 0:
|
case lp != 0:
|
||||||
r.Scheme = "tcp"
|
r.Scheme = "tcp"
|
||||||
case strings.HasSuffix(strconv.Itoa(pp), "443"):
|
case pp%1000 == 443:
|
||||||
r.Scheme = "https"
|
r.Scheme = "https"
|
||||||
default: // assume its http
|
default: // assume its http
|
||||||
r.Scheme = "http"
|
r.Scheme = "http"
|
||||||
|
|
Loading…
Add table
Reference in a new issue