fix(shutdown): Fix shutdown command
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@@ -69,13 +70,30 @@ func (s *UDPServer) Start(done chan bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
packetData := buffer[:n]
|
||||
|
||||
// Debug: Display packet content
|
||||
hexDump := hex.EncodeToString(packetData)
|
||||
// Also try to show as string (for auth part)
|
||||
stringPreview := ""
|
||||
if len(packetData) > 0 && packetData[0] < 128 {
|
||||
// Only show string preview if it looks like printable ASCII
|
||||
maxLen := len(packetData)
|
||||
if maxLen > 100 {
|
||||
maxLen = 100
|
||||
}
|
||||
stringPreview = string(packetData[:maxLen])
|
||||
}
|
||||
|
||||
masterlog.Info("Received UDP packet", map[string]interface{}{
|
||||
"bytes": n,
|
||||
"address": clientAddr,
|
||||
"bytes": n,
|
||||
"address": clientAddr,
|
||||
"hex": hexDump,
|
||||
"string_preview": stringPreview,
|
||||
})
|
||||
|
||||
// Check authentication and magic packet
|
||||
if s.isValidAuthenticatedMagicPacket(buffer[:n]) {
|
||||
if s.isValidAuthenticatedMagicPacket(packetData) {
|
||||
masterlog.Info("Authenticated Magic Packet detected! Shutting down system...", map[string]interface{}{
|
||||
"address": clientAddr,
|
||||
})
|
||||
@@ -94,14 +112,38 @@ func (s *UDPServer) Start(done chan bool) {
|
||||
func (s *UDPServer) isValidAuthenticatedMagicPacket(data []byte) bool {
|
||||
username, password, magicPacketData, ok := magicpacket.ExtractAuthFromPacket(data)
|
||||
if !ok {
|
||||
masterlog.Info("Packet does not contain valid auth format", map[string]interface{}{
|
||||
"packet_size": len(data),
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
masterlog.Info("Extracted authentication from packet", map[string]interface{}{
|
||||
"username": username,
|
||||
"password_length": len(password),
|
||||
"magic_packet_size": len(magicPacketData),
|
||||
})
|
||||
|
||||
// Verify authentication
|
||||
if !s.authenticator.Verify(username, password) {
|
||||
masterlog.Info("Authentication failed", map[string]interface{}{
|
||||
"username": username,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
masterlog.Info("Authentication successful", map[string]interface{}{
|
||||
"username": username,
|
||||
})
|
||||
|
||||
// Check if it's a valid magic packet
|
||||
return magicpacket.IsMagicPacket(magicPacketData)
|
||||
isValid := magicpacket.IsMagicPacket(magicPacketData)
|
||||
if !isValid {
|
||||
masterlog.Info("Magic packet validation failed", map[string]interface{}{
|
||||
"magic_packet_size": len(magicPacketData),
|
||||
"magic_packet_hex": hex.EncodeToString(magicPacketData),
|
||||
})
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user