mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
Ghetto ip banning.
This commit is contained in:
parent
4ff000da42
commit
66d788b20b
@ -73,6 +73,7 @@ things up with `make run`.
|
|||||||
* [x] backfill chat history
|
* [x] backfill chat history
|
||||||
* [ ] tab completion
|
* [ ] tab completion
|
||||||
* [x] /ban
|
* [x] /ban
|
||||||
|
* [ ] /ban by ip
|
||||||
* [x] /help
|
* [x] /help
|
||||||
* [x] /about
|
* [x] /about
|
||||||
* [x] /list
|
* [x] /list
|
||||||
@ -80,6 +81,9 @@ things up with `make run`.
|
|||||||
* [x] pubkey fingerprint
|
* [x] pubkey fingerprint
|
||||||
* [x] truncate usernames
|
* [x] truncate usernames
|
||||||
* [ ] rename collision bug
|
* [ ] rename collision bug
|
||||||
|
* [ ] op ops on join
|
||||||
|
* [ ] piped stdout bug
|
||||||
|
* [ ] saner sanitizing of inputs (version string, allow space/period)
|
||||||
* [x] Some tests.
|
* [x] Some tests.
|
||||||
* [ ] More tests.
|
* [ ] More tests.
|
||||||
* [ ] Even more tests.
|
* [ ] Even more tests.
|
||||||
|
28
server.go
28
server.go
@ -28,7 +28,8 @@ type Server struct {
|
|||||||
count int
|
count int
|
||||||
history *History
|
history *History
|
||||||
admins map[string]struct{} // fingerprint lookup
|
admins map[string]struct{} // fingerprint lookup
|
||||||
banned map[string]*time.Time // fingerprint lookup
|
bannedPk map[string]*time.Time // fingerprint lookup
|
||||||
|
bannedIp map[net.Addr]*time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(privateKey []byte) (*Server, error) {
|
func NewServer(privateKey []byte) (*Server, error) {
|
||||||
@ -38,12 +39,13 @@ func NewServer(privateKey []byte) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server := Server{
|
server := Server{
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
clients: Clients{},
|
clients: Clients{},
|
||||||
count: 0,
|
count: 0,
|
||||||
history: NewHistory(HISTORY_LEN),
|
history: NewHistory(HISTORY_LEN),
|
||||||
admins: map[string]struct{}{},
|
admins: map[string]struct{}{},
|
||||||
banned: map[string]*time.Time{},
|
bannedPk: map[string]*time.Time{},
|
||||||
|
bannedIp: map[net.Addr]*time.Time{},
|
||||||
}
|
}
|
||||||
|
|
||||||
config := ssh.ServerConfig{
|
config := ssh.ServerConfig{
|
||||||
@ -54,6 +56,12 @@ func NewServer(privateKey []byte) (*Server, error) {
|
|||||||
if server.IsBanned(fingerprint) {
|
if server.IsBanned(fingerprint) {
|
||||||
return nil, fmt.Errorf("Banned.")
|
return nil, fmt.Errorf("Banned.")
|
||||||
}
|
}
|
||||||
|
ip := strings.Split(conn.RemoteAddr().String(), ":")[0]
|
||||||
|
logger.Infof(ip)
|
||||||
|
if ip == "73.3.250.197" {
|
||||||
|
// Can't believe I'm doing this...
|
||||||
|
return nil, fmt.Errorf("Banned.")
|
||||||
|
}
|
||||||
perm := &ssh.Permissions{Extensions: map[string]string{"fingerprint": fingerprint}}
|
perm := &ssh.Permissions{Extensions: map[string]string{"fingerprint": fingerprint}}
|
||||||
return perm, nil
|
return perm, nil
|
||||||
},
|
},
|
||||||
@ -181,7 +189,7 @@ func (s *Server) IsOp(client *Client) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) IsBanned(fingerprint string) bool {
|
func (s *Server) IsBanned(fingerprint string) bool {
|
||||||
ban, hasBan := s.banned[fingerprint]
|
ban, hasBan := s.bannedPk[fingerprint]
|
||||||
if !hasBan {
|
if !hasBan {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -202,13 +210,13 @@ func (s *Server) Ban(fingerprint string, duration *time.Duration) {
|
|||||||
when := time.Now().Add(*duration)
|
when := time.Now().Add(*duration)
|
||||||
until = &when
|
until = &when
|
||||||
}
|
}
|
||||||
s.banned[fingerprint] = until
|
s.bannedPk[fingerprint] = until
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Unban(fingerprint string) {
|
func (s *Server) Unban(fingerprint string) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
delete(s.banned, fingerprint)
|
delete(s.bannedPk, fingerprint)
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user