mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 00:11:56 +03:00
More reasonable cli for access
This commit is contained in:
+8
-5
@@ -36,9 +36,12 @@ type accessResponseURLs struct {
|
|||||||
type Access struct {
|
type Access struct {
|
||||||
base `kong:"-"`
|
base `kong:"-"`
|
||||||
|
|
||||||
ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
|
PublicIPv4 net.IP `kong:"help='Public IPv4 address for proxy. By default it is resolved via remote website',name='ipv4',short='i'"` // nolint: lll
|
||||||
Port uint `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint'"` // nolint: lll
|
PublicIPv6 net.IP `kong:"help='Public IPv6 address for proxy. By default it is resolved via remote website',name='ipv6',short='I'"` // nolint: lll
|
||||||
Hex bool `kong:"help='Print secret in hex encoding.'"`
|
Port uint `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
|
||||||
|
Hex bool `kong:"help='Print secret in hex encoding.',short='x'"`
|
||||||
|
|
||||||
|
ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Access) Run(cli *CLI, version string) error {
|
func (c *Access) Run(cli *CLI, version string) error {
|
||||||
@@ -60,7 +63,7 @@ func (c *Access) Execute(cli *CLI) error {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
ip := c.Config.Network.PublicIP.IPv4.Value(nil)
|
ip := cli.Access.PublicIPv4
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
ip = c.getIP("tcp4")
|
ip = c.getIP("tcp4")
|
||||||
}
|
}
|
||||||
@@ -75,7 +78,7 @@ func (c *Access) Execute(cli *CLI) error {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
ip := c.Config.Network.PublicIP.IPv6.Value(nil)
|
ip := cli.Access.PublicIPv6
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
ip = c.getIP("tcp6")
|
ip = c.getIP("tcp6")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-12
@@ -1,6 +1,7 @@
|
|||||||
package cli_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -122,12 +123,8 @@ func (suite *AccessTestSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *AccessTestSuite) TestGenerateNoCalls() {
|
func (suite *AccessTestSuite) TestGenerateNoCalls() {
|
||||||
suite.NoError(
|
suite.cli.Access.PublicIPv4 = net.ParseIP("10.0.0.10")
|
||||||
suite.cli.Access.Config.Network.PublicIP.IPv4.UnmarshalText(
|
suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
||||||
[]byte("10.0.0.10")))
|
|
||||||
suite.NoError(
|
|
||||||
suite.cli.Access.Config.Network.PublicIP.IPv6.UnmarshalText(
|
|
||||||
[]byte("2001:0db8:85a3:0000:0000:8a2e:0370:7334")))
|
|
||||||
|
|
||||||
output := suite.CaptureStdout(func() {
|
output := suite.CaptureStdout(func() {
|
||||||
suite.NoError(suite.cli.Access.Execute(suite.cli))
|
suite.NoError(suite.cli.Access.Execute(suite.cli))
|
||||||
@@ -148,9 +145,7 @@ func (suite *AccessTestSuite) TestGenerateNoCalls() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *AccessTestSuite) TestGenerateIPv4Call() {
|
func (suite *AccessTestSuite) TestGenerateIPv4Call() {
|
||||||
suite.NoError(
|
suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
||||||
suite.cli.Access.Config.Network.PublicIP.IPv6.UnmarshalText(
|
|
||||||
[]byte("2001:0db8:85a3:0000:0000:8a2e:0370:7334")))
|
|
||||||
|
|
||||||
httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
|
httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
|
||||||
httpmock.NewStringResponder(http.StatusOK, "10.11.12.13"))
|
httpmock.NewStringResponder(http.StatusOK, "10.11.12.13"))
|
||||||
@@ -174,9 +169,7 @@ func (suite *AccessTestSuite) TestGenerateIPv4Call() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *AccessTestSuite) TestIPv4CallFail() {
|
func (suite *AccessTestSuite) TestIPv4CallFail() {
|
||||||
suite.NoError(
|
suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
||||||
suite.cli.Access.Config.Network.PublicIP.IPv6.UnmarshalText(
|
|
||||||
[]byte("2001:0db8:85a3:0000:0000:8a2e:0370:7334")))
|
|
||||||
|
|
||||||
httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
|
httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
|
||||||
httpmock.NewStringResponder(http.StatusForbidden, ""))
|
httpmock.NewStringResponder(http.StatusForbidden, ""))
|
||||||
|
|||||||
+1
-1
@@ -5,5 +5,5 @@ import "github.com/alecthomas/kong"
|
|||||||
type CLI struct {
|
type CLI struct {
|
||||||
GenerateSecret GenerateSecret `kong:"cmd,help='Generate new proxy secret'"`
|
GenerateSecret GenerateSecret `kong:"cmd,help='Generate new proxy secret'"`
|
||||||
Access Access `kong:"cmd,help='Print access information.'"`
|
Access Access `kong:"cmd,help='Print access information.'"`
|
||||||
Version kong.VersionFlag `kong:"help='Print version.'"`
|
Version kong.VersionFlag `kong:"help='Print version.',short='v'"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type GenerateSecret struct {
|
|||||||
base `kong:"-"`
|
base `kong:"-"`
|
||||||
|
|
||||||
HostName string `kong:"arg,required,help='Hostname to use for domain fronting.',name='hostname'"`
|
HostName string `kong:"arg,required,help='Hostname to use for domain fronting.',name='hostname'"`
|
||||||
Hex bool `kong:"help='Print secret in hex encoding.'"`
|
Hex bool `kong:"help='Print secret in hex encoding.',short='x'"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GenerateSecret) Run(cli *CLI, _ string) error {
|
func (c *GenerateSecret) Run(cli *CLI, _ string) error {
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ type Config struct {
|
|||||||
} `json:"blocklist"`
|
} `json:"blocklist"`
|
||||||
} `json:"defense"`
|
} `json:"defense"`
|
||||||
Network struct {
|
Network struct {
|
||||||
PublicIP struct {
|
|
||||||
IPv4 TypeIP `json:"ipv4"`
|
|
||||||
IPv6 TypeIP `json:"ipv6"`
|
|
||||||
} `json:"public-ip"`
|
|
||||||
Timeout struct {
|
Timeout struct {
|
||||||
TCP TypeDuration `json:"tcp"`
|
TCP TypeDuration `json:"tcp"`
|
||||||
HTTP TypeDuration `json:"http"`
|
HTTP TypeDuration `json:"http"`
|
||||||
@@ -113,10 +109,6 @@ type configRaw struct {
|
|||||||
} `toml:"blocklist" json:"blocklist,omitempty"`
|
} `toml:"blocklist" json:"blocklist,omitempty"`
|
||||||
} `toml:"defense" json:"defense,omitempty"`
|
} `toml:"defense" json:"defense,omitempty"`
|
||||||
Network struct {
|
Network struct {
|
||||||
PublicIP struct {
|
|
||||||
IPv4 string `toml:"ipv4" json:"ipv4,omitempty"`
|
|
||||||
IPv6 string `toml:"ipv6" json:"ipv6,omitempty"`
|
|
||||||
} `toml:"public-ip" json:"public-ip,omitempty"`
|
|
||||||
Timeout struct {
|
Timeout struct {
|
||||||
TCP string `toml:"tcp" json:"tcp,omitempty"`
|
TCP string `toml:"tcp" json:"tcp,omitempty"`
|
||||||
HTTP string `toml:"http" json:"http,omitempty"`
|
HTTP string `toml:"http" json:"http,omitempty"`
|
||||||
|
|||||||
+1
-8
@@ -98,13 +98,6 @@ proxies = [
|
|||||||
# "socks5://user:password@host:port?open_threshold=5&half_open_timeout=1m&reset_failures_timeout=10s"
|
# "socks5://user:password@host:port?open_threshold=5&half_open_timeout=1m&reset_failures_timeout=10s"
|
||||||
]
|
]
|
||||||
|
|
||||||
# public ip addresses of the server. Actually, it is required only to
|
|
||||||
# generate a correct access file. if you use default values here, mtg
|
|
||||||
# will try to resolve these IPs on its own.
|
|
||||||
[network.public-ip]
|
|
||||||
ipv4 = ""
|
|
||||||
ipv6 = ""
|
|
||||||
|
|
||||||
# network timeouts define different settings for timeouts. tcp timeout
|
# network timeouts define different settings for timeouts. tcp timeout
|
||||||
# define a global timeout on establishing of network connections. idle
|
# define a global timeout on establishing of network connections. idle
|
||||||
# means a timeout on pumping data between sockset when nothing is
|
# means a timeout on pumping data between sockset when nothing is
|
||||||
@@ -171,7 +164,7 @@ urls = [
|
|||||||
# "/local.file"
|
# "/local.file"
|
||||||
]
|
]
|
||||||
# How often do we need to update a blocklist set.
|
# How often do we need to update a blocklist set.
|
||||||
update-each = "1d"
|
update-each = "24h"
|
||||||
|
|
||||||
# statsd statistics integration.
|
# statsd statistics integration.
|
||||||
[stats.statsd]
|
[stats.statsd]
|
||||||
|
|||||||
Reference in New Issue
Block a user