mirror of
https://github.com/mmatczuk/go-http-tunnel.git
synced 2026-05-15 14:16:17 -06:00
Add registered client enabled/disabled check
This commit is contained in:
parent
0cccde7a29
commit
57ab154a65
2 changed files with 14 additions and 1 deletions
|
|
@ -34,6 +34,7 @@ func IsNotRegistered(err error) (ok bool) {
|
|||
}
|
||||
|
||||
type RegisteredClientConfig struct {
|
||||
Disabled bool
|
||||
ID id.ID
|
||||
Name string
|
||||
Description string
|
||||
|
|
@ -51,7 +52,8 @@ type RegisteredClientsFileSystemProvider struct {
|
|||
}
|
||||
|
||||
func (p *RegisteredClientsFileSystemProvider) Get(clientID id.ID) (client *RegisteredClientConfig, err error) {
|
||||
pth := filepath.Join(p.StorageDir, clientID.String()+".yaml")
|
||||
base := filepath.Join(p.StorageDir, clientID.String())
|
||||
pth := filepath.Join(base, "config.yaml")
|
||||
var f io.ReadCloser
|
||||
if f, err = os.Open(pth); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
|
@ -72,5 +74,9 @@ func (p *RegisteredClientsFileSystemProvider) Get(clientID id.ID) (client *Regis
|
|||
if client.Tunnels == nil {
|
||||
client.Tunnels = map[string]*proto.Tunnel{}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(base, "disabled")); err == nil {
|
||||
client.Disabled = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,13 @@ func (s *Server) handleClient(conn net.Conn, main bool) {
|
|||
s.Subscribe(ID)
|
||||
} else if s.config.RegisteredClientsProvider != nil {
|
||||
if cfg, err = s.config.RegisteredClientsProvider.Get(ID); err == nil {
|
||||
if cfg.Disabled {
|
||||
logger.Log(
|
||||
"level", 2,
|
||||
"msg", "Client has be disabled",
|
||||
)
|
||||
goto Reject
|
||||
}
|
||||
if s.connPool.Has(ID) {
|
||||
if ccon, err = s.connPool.AddClientConnection(ID, conn); err != nil {
|
||||
goto Reject
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue