feat(controller): add /getip command to retrieve server IP information
This commit is contained in:
@@ -183,6 +183,40 @@ func telegram_handleStart() (string, error) {
|
||||
return template.Render(cfg.ControllerMessage.Tg_BotStart, params), nil
|
||||
}
|
||||
|
||||
func handleGetIP(cmd Command) (string, error) {
|
||||
if len(cmd.Args) < 1 {
|
||||
return "Usage: /getip <uuid>", nil
|
||||
}
|
||||
|
||||
uuid := cmd.Args[0]
|
||||
tracker := node.GetTracker()
|
||||
n, exists := tracker.GetNode(uuid)
|
||||
if !exists {
|
||||
return fmt.Sprintf("Server with UUID %s not found", uuid), nil
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(fmt.Sprintf("Server: %s (%s)\n", n.Name, n.UUID))
|
||||
|
||||
if n.Info == nil {
|
||||
sb.WriteString("No IP info available for this server.\n")
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
if n.Info.IPv4 != "" {
|
||||
sb.WriteString(fmt.Sprintf("IPv4: %s\n", n.Info.IPv4))
|
||||
} else {
|
||||
sb.WriteString("IPv4: Not available\n")
|
||||
}
|
||||
if n.Info.IPv6 != "" {
|
||||
sb.WriteString(fmt.Sprintf("IPv6: %s\n", n.Info.IPv6))
|
||||
} else {
|
||||
sb.WriteString("IPv6: Not available\n")
|
||||
}
|
||||
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
// formatBytes renders a byte count in a human-readable form.
|
||||
func formatBytes(b int64) string {
|
||||
const (
|
||||
|
||||
@@ -64,6 +64,8 @@ func (m *Manager) RouteCommand(cmd Command) (string, error) {
|
||||
return handleRun(cmd)
|
||||
case "info":
|
||||
return handleInfo(cmd)
|
||||
case "getip":
|
||||
return handleGetIP(cmd)
|
||||
default:
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -249,6 +249,8 @@ func BuildNodeListData(nodes []NodeInfo) map[string]node.NodeListEntry {
|
||||
info.Price = n.Price
|
||||
info.Group = n.Group
|
||||
info.Tags = n.Tags
|
||||
info.IPv4 = n.IPv4
|
||||
info.IPv6 = n.IPv6
|
||||
|
||||
entries[n.UUID] = node.NodeListEntry{
|
||||
Name: n.Name,
|
||||
|
||||
@@ -69,6 +69,8 @@ type Info struct {
|
||||
Price float64 `json:"price"`
|
||||
Group string `json:"group"`
|
||||
Tags string `json:"tags"`
|
||||
IPv4 string `json:"ipv4"`
|
||||
IPv6 string `json:"ipv6"`
|
||||
}
|
||||
|
||||
// NodeListEntry is the static metadata of a node from the Komari node list,
|
||||
|
||||
Reference in New Issue
Block a user