mirror of
https://github.com/dalbodeule/sshchat.git
synced 2025-12-08 07:05:44 +09:00
chat and debugs.
This commit is contained in:
28
main.go
28
main.go
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@@ -11,6 +11,28 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func sessionHandler(s ssh.Session) {
|
||||
ptyReq, _, isPty := s.Pty()
|
||||
if !isPty {
|
||||
_, _ = fmt.Fprintln(s, "Err: PTY requires. Reconnect with -t option.")
|
||||
_ = s.Exit(1)
|
||||
return
|
||||
}
|
||||
|
||||
remote := s.RemoteAddr().String()
|
||||
username := s.User()
|
||||
|
||||
log.Printf("[sshchat] %s connected. %s", username, remote)
|
||||
client := utils.NewClient(s, ptyReq.Window.Height, ptyReq.Window.Width, username, remote)
|
||||
|
||||
defer func() {
|
||||
client.Close()
|
||||
log.Printf("[sshchat] %s disconnected. %s", username, remote)
|
||||
}()
|
||||
|
||||
client.EventLoop()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
@@ -33,10 +55,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
sessionHandler := func(s ssh.Session) {
|
||||
_, _ = io.WriteString(s, "Hello World\n")
|
||||
}
|
||||
|
||||
s := &ssh.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: sessionHandler,
|
||||
|
||||
Reference in New Issue
Block a user