mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Show correct secrets
This commit is contained in:
+23
-3
@@ -20,6 +20,7 @@ const (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
|
SecureMode bool
|
||||||
|
|
||||||
BindPort uint16
|
BindPort uint16
|
||||||
PublicIPv4Port uint16
|
PublicIPv4Port uint16
|
||||||
@@ -47,6 +48,7 @@ type URLs struct {
|
|||||||
type IPURLs struct {
|
type IPURLs struct {
|
||||||
IPv4 URLs `json:"ipv4"`
|
IPv4 URLs `json:"ipv4"`
|
||||||
IPv6 URLs `json:"ipv6"`
|
IPv6 URLs `json:"ipv6"`
|
||||||
|
BotSecret string `json:"secret_for_mtproxybot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindAddr returns connection for this server to bind to.
|
// BindAddr returns connection for this server to bind to.
|
||||||
@@ -65,15 +67,29 @@ func (c *Config) UseMiddleProxy() bool {
|
|||||||
return len(c.AdTag) > 0
|
return len(c.AdTag) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) SecretString() string {
|
||||||
|
return hex.EncodeToString(c.Secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) BotSecretString() string {
|
||||||
|
secret := c.SecretString()
|
||||||
|
if c.SecureMode {
|
||||||
|
return "dd" + secret
|
||||||
|
}
|
||||||
|
return secret
|
||||||
|
}
|
||||||
|
|
||||||
// GetURLs returns configured IPURLs instance with links to this server.
|
// GetURLs returns configured IPURLs instance with links to this server.
|
||||||
func (c *Config) GetURLs() IPURLs {
|
func (c *Config) GetURLs() IPURLs {
|
||||||
urls := IPURLs{}
|
urls := IPURLs{}
|
||||||
|
secret := c.SecretString()
|
||||||
if c.PublicIPv4 != nil {
|
if c.PublicIPv4 != nil {
|
||||||
urls.IPv4 = getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret)
|
urls.IPv4 = getURLs(c.PublicIPv4, c.PublicIPv4Port, secret)
|
||||||
}
|
}
|
||||||
if c.PublicIPv6 != nil {
|
if c.PublicIPv6 != nil {
|
||||||
urls.IPv6 = getURLs(c.PublicIPv6, c.PublicIPv6Port, c.Secret)
|
urls.IPv6 = getURLs(c.PublicIPv6, c.PublicIPv6Port, secret)
|
||||||
}
|
}
|
||||||
|
urls.BotSecret = c.BotSecretString()
|
||||||
|
|
||||||
return urls
|
return urls
|
||||||
}
|
}
|
||||||
@@ -91,8 +107,11 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
|
|||||||
publicIPv6 net.IP, publicIPv6Port uint16,
|
publicIPv6 net.IP, publicIPv6Port uint16,
|
||||||
statsIP net.IP, statsPort uint16,
|
statsIP net.IP, statsPort uint16,
|
||||||
secret, adtag string) (*Config, error) {
|
secret, adtag string) (*Config, error) {
|
||||||
|
secureMode := false
|
||||||
|
if strings.HasPrefix(secret, "dd") && len(secret) == 34 {
|
||||||
|
secureMode = true
|
||||||
secret = strings.TrimPrefix(secret, "dd")
|
secret = strings.TrimPrefix(secret, "dd")
|
||||||
if len(secret) != 32 {
|
} else if len(secret) != 32 {
|
||||||
return nil, errors.New("Telegram demands secret of length 32")
|
return nil, errors.New("Telegram demands secret of length 32")
|
||||||
}
|
}
|
||||||
secretBytes, err := hex.DecodeString(secret)
|
secretBytes, err := hex.DecodeString(secret)
|
||||||
@@ -149,6 +168,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
|
|||||||
StatsPort: statsPort,
|
StatsPort: statsPort,
|
||||||
Secret: secretBytes,
|
Secret: secretBytes,
|
||||||
AdTag: adTagBytes,
|
AdTag: adTagBytes,
|
||||||
|
SecureMode: secureMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|||||||
+2
-3
@@ -1,17 +1,16 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getURLs(addr net.IP, port uint16, secret []byte) (urls URLs) {
|
func getURLs(addr net.IP, port uint16, secret string) (urls URLs) {
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Set("server", addr.String())
|
values.Set("server", addr.String())
|
||||||
values.Set("port", strconv.Itoa(int(port)))
|
values.Set("port", strconv.Itoa(int(port)))
|
||||||
values.Set("secret", hex.EncodeToString(secret))
|
values.Set("secret", secret)
|
||||||
|
|
||||||
urls.TG = makeTGURL(values)
|
urls.TG = makeTGURL(values)
|
||||||
urls.TMe = makeTMeURL(values)
|
urls.TMe = makeTMeURL(values)
|
||||||
|
|||||||
Reference in New Issue
Block a user