feat: log incoming requests to the user's terminal

This commit is contained in:
2025-02-07 18:30:23 +07:00
parent dfc57cf542
commit d5829ffd0d
9 changed files with 105 additions and 5 deletions

View File

@ -57,7 +57,7 @@ func (s *Session) handleGlobalRequest() {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, uint32(portToBind))
log.Printf("Forwarding approved on port: %d", portToBind)
s.ConnChannels[0].Write([]byte(fmt.Sprintf("Forwarding your traffic to http://%s.tunnl.live", slug)))
s.ConnChannels[0].Write([]byte(fmt.Sprintf("Forwarding your traffic to http://%s.tunnl.live \r\n", slug)))
req.Reply(true, buf.Bytes())
} else {
s.TunnelType = TCP
@ -70,6 +70,7 @@ func (s *Session) handleGlobalRequest() {
continue
}
s.Listener = listener
s.ConnChannels[0].Write([]byte(fmt.Sprintf("Forwarding your traffic to tunnl.live:%d \r\n", portToBind)))
go func() {
for {
conn, err := listener.Accept()
@ -255,7 +256,7 @@ func (s *Session) HandleForwardedConnection(conn net.Conn, sshConn *ssh.ServerCo
}()
}
func (s *Session) GetForwardedConnection(conn net.Conn, host string, sshConn *ssh.ServerConn, payload []byte, originPort, port uint32) {
func (s *Session) GetForwardedConnection(conn net.Conn, host string, sshConn *ssh.ServerConn, payload []byte, originPort, port uint32, path, method, proto string) {
defer conn.Close()
channelPayload := createForwardedTCPIPPayload(host, originPort, port)
channel, reqs, err := sshConn.OpenChannel("forwarded-tcpip", channelPayload)
@ -277,6 +278,7 @@ func (s *Session) GetForwardedConnection(conn net.Conn, host string, sshConn *ss
s.ConnChannels[0].Write([]byte("Could not forward request to the tunnel addr\r\n"))
return
} else {
s.ConnChannels[0].Write([]byte(fmt.Sprintf("\033[32m %s -- [%s] \"%s %s %s\" \r\n \033[0m", host, time.Now().Format("02/Jan/2006 15:04:05"), method, path, proto)))
io.Copy(conn, reader)
}
go func() {

View File

@ -50,8 +50,9 @@ func New(conn *ssh.ServerConn, sshChannel <-chan ssh.NewChannel, req <-chan *ssh
func (session *Session) Close() {
session.Done <- true
session.Listener.Close()
if session.TunnelType != HTTP {
session.Listener.Close()
}
for _, ch := range session.ConnChannels {
if err := ch.Close(); err != nil {