mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-02-20 02:29:12 +00:00
ports-mapping flag now reimplemented as a StringSliceFlag and renamed to port-map.
This commit is contained in:
parent
775979bfc8
commit
9be4344144
@ -61,32 +61,47 @@ func main() {
|
|||||||
Usage: "Target host address",
|
Usage: "Target host address",
|
||||||
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "ports-mapping",
|
Name: "port-map",
|
||||||
Usage: "Proxy and target ports (proxy:target)",
|
Usage: "Ports mapping in the format proxyPort:targetPort (e.g., 27950:27960)",
|
||||||
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
Sources: cli.EnvVars("Q3RCON_PORT_MAP"),
|
||||||
Required: true,
|
Required: true,
|
||||||
Action: func(_ context.Context, _ *cli.Command, v string) error {
|
Action: func(_ context.Context, cmd *cli.Command, v []string) error {
|
||||||
// Validate the ports mapping
|
// Validate the ports mapping format and values
|
||||||
for mapping := range strings.SplitSeq(v, ";") {
|
for _, mapping := range v {
|
||||||
ports := strings.Split(mapping, ":")
|
src, dst := func(m string) (string, string) {
|
||||||
if len(ports) != 2 {
|
parts := strings.Split(m, ":")
|
||||||
return fmt.Errorf("invalid ports mapping: %s", mapping)
|
if len(parts) != 2 {
|
||||||
|
return "", ""
|
||||||
}
|
}
|
||||||
proxyPort, err := strconv.Atoi(ports[0])
|
return parts[0], parts[1]
|
||||||
if err != nil || proxyPort < 1 || proxyPort > 65535 {
|
}(mapping)
|
||||||
return fmt.Errorf("invalid proxy port: %s", ports[0])
|
|
||||||
}
|
if src == "" || dst == "" {
|
||||||
targetPort, err := strconv.Atoi(ports[1])
|
|
||||||
if err != nil || targetPort < 1 || targetPort > 65535 {
|
|
||||||
return fmt.Errorf("invalid target port: %s", ports[1])
|
|
||||||
}
|
|
||||||
if proxyPort == targetPort {
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"proxy and target ports cannot be the same: %s",
|
"invalid ports mapping: %s (expected format: proxyPort:targetPort)",
|
||||||
mapping,
|
mapping,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
n, err := strconv.Atoi(src)
|
||||||
|
if err != nil || n <= 0 || n > 65535 {
|
||||||
|
return fmt.Errorf("invalid proxy port: %s", src)
|
||||||
|
}
|
||||||
|
n, err = strconv.Atoi(dst)
|
||||||
|
if err != nil || n <= 0 || n > 65535 {
|
||||||
|
return fmt.Errorf("invalid target port: %s", dst)
|
||||||
|
}
|
||||||
|
if src == dst {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"proxy port and target port cannot be the same: %s",
|
||||||
|
src,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
log.Debugf(
|
||||||
|
"Validated ports mapping: proxy port %s -> target port %s",
|
||||||
|
src,
|
||||||
|
dst,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -115,7 +130,7 @@ func main() {
|
|||||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
for mapping := range strings.SplitSeq(cmd.String("ports-mapping"), ";") {
|
for _, mapping := range cmd.StringSlice("port-map") {
|
||||||
cfg := proxyConfig{
|
cfg := proxyConfig{
|
||||||
proxyHost: cmd.String("proxy-host"),
|
proxyHost: cmd.String("proxy-host"),
|
||||||
targetHost: cmd.String("target-host"),
|
targetHost: cmd.String("target-host"),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user