Add registered client enabled/disabled check

This commit is contained in:
Moises P. Sena 2018-10-15 10:28:44 -03:00
parent 0cccde7a29
commit 57ab154a65
2 changed files with 14 additions and 1 deletions

View file

@ -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
}

View file

@ -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