mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-03 12:14:29 +02:00
Merge branch 'master' of github.com:shazow/ssh-chat
This commit is contained in:
commit
5ef97705fc
@ -1,3 +1,5 @@
|
|||||||
|
[](https://travis-ci.org/shazow/ssh-chat)
|
||||||
|
|
||||||
# ssh-chat
|
# ssh-chat
|
||||||
|
|
||||||
Custom SSH server written in Go. Instead of a shell, you get a chat prompt.
|
Custom SSH server written in Go. Instead of a shell, you get a chat prompt.
|
||||||
@ -57,6 +59,7 @@ See notes in the header of our Dockerfile for details on building your own image
|
|||||||
If you're developing on this repo, there is a handy Makefile that should set
|
If you're developing on this repo, there is a handy Makefile that should set
|
||||||
things up with `make run`.
|
things up with `make run`.
|
||||||
|
|
||||||
|
Additionally, `make debug` runs the server with an http `pprof` server. This allows you to open [http://localhost:6060/debug/pprof/]() and view profiling data. See [net/http/pprof](http://golang.org/pkg/net/http/pprof/) for more information about `pprof`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
11
cmd.go
11
cmd.go
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -61,7 +62,15 @@ func main() {
|
|||||||
logLevel := logLevels[numVerbose]
|
logLevel := logLevels[numVerbose]
|
||||||
logger = golog.New(os.Stderr, logLevel)
|
logger = golog.New(os.Stderr, logLevel)
|
||||||
|
|
||||||
privateKey, err := ioutil.ReadFile(options.Identity)
|
privateKeyPath := options.Identity
|
||||||
|
if strings.HasPrefix(privateKeyPath, "~") {
|
||||||
|
user, err := user.Current()
|
||||||
|
if err == nil {
|
||||||
|
privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
privateKey, err := ioutil.ReadFile(privateKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to load identity: %v", err)
|
logger.Errorf("Failed to load identity: %v", err)
|
||||||
return
|
return
|
||||||
|
24
server.go
24
server.go
@ -120,7 +120,7 @@ func (s *Server) Broadcast(msg string, except *Client) {
|
|||||||
// Privmsg sends a message to a particular nick, if it exists
|
// Privmsg sends a message to a particular nick, if it exists
|
||||||
func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
||||||
// Get the recipient
|
// Get the recipient
|
||||||
target, ok := s.clients[nick]
|
target, ok := s.clients[strings.ToLower(nick)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("no client with that nick")
|
return fmt.Errorf("no client with that nick")
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func (s *Server) Add(client *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.Rename(newName)
|
client.Rename(newName)
|
||||||
s.clients[client.Name] = client
|
s.clients[strings.ToLower(client.Name)] = client
|
||||||
num := len(s.clients)
|
num := len(s.clients)
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ func (s *Server) Add(client *Client) {
|
|||||||
// Remove removes the given client from the list of clients
|
// Remove removes the given client from the list of clients
|
||||||
func (s *Server) Remove(client *Client) {
|
func (s *Server) Remove(client *Client) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
delete(s.clients, client.Name)
|
delete(s.clients, strings.ToLower(client.Name))
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
s.SysMsg("%s left.", client.ColoredName())
|
s.SysMsg("%s left.", client.ColoredName())
|
||||||
@ -197,7 +197,7 @@ func (s *Server) proposeName(name string) (string, error) {
|
|||||||
name = fmt.Sprintf("Guest%d", s.count)
|
name = fmt.Sprintf("Guest%d", s.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, collision := s.clients[name]
|
_, collision := s.clients[strings.ToLower(name)]
|
||||||
if collision {
|
if collision {
|
||||||
err = fmt.Errorf("%s is not available", name)
|
err = fmt.Errorf("%s is not available", name)
|
||||||
name = fmt.Sprintf("Guest%d", s.count)
|
name = fmt.Sprintf("Guest%d", s.count)
|
||||||
@ -209,7 +209,11 @@ func (s *Server) proposeName(name string) (string, error) {
|
|||||||
// Rename renames the given client (user)
|
// Rename renames the given client (user)
|
||||||
func (s *Server) Rename(client *Client, newName string) {
|
func (s *Server) Rename(client *Client, newName string) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
|
var oldName string
|
||||||
|
if strings.ToLower(newName) == strings.ToLower(client.Name) {
|
||||||
|
oldName = client.Name
|
||||||
|
client.Rename(newName)
|
||||||
|
} else {
|
||||||
newName, err := s.proposeName(newName)
|
newName, err := s.proposeName(newName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.SysMsg("%s", err)
|
client.SysMsg("%s", err)
|
||||||
@ -218,12 +222,12 @@ func (s *Server) Rename(client *Client, newName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use a channel/goroutine for adding clients, rather than locks?
|
// TODO: Use a channel/goroutine for adding clients, rather than locks?
|
||||||
delete(s.clients, client.Name)
|
delete(s.clients, strings.ToLower(client.Name))
|
||||||
oldName := client.Name
|
oldName = client.Name
|
||||||
client.Rename(newName)
|
client.Rename(newName)
|
||||||
s.clients[client.Name] = client
|
s.clients[strings.ToLower(client.Name)] = client
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
}
|
||||||
s.SysMsg("%s is now known as %s.", ColorString(client.Color, oldName), ColorString(client.Color, newName))
|
s.SysMsg("%s is now known as %s.", ColorString(client.Color, oldName), ColorString(client.Color, newName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +247,7 @@ func (s *Server) List(prefix *string) []string {
|
|||||||
|
|
||||||
// Who returns the client with a given name
|
// Who returns the client with a given name
|
||||||
func (s *Server) Who(name string) *Client {
|
func (s *Server) Who(name string) *Client {
|
||||||
return s.clients[name]
|
return s.clients[strings.ToLower(name)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Op adds the given fingerprint to the list of admins
|
// Op adds the given fingerprint to the list of admins
|
||||||
|
Loading…
x
Reference in New Issue
Block a user