Skip to content

Commit

Permalink
Attempt to show ipv6 user information
Browse files Browse the repository at this point in the history
  • Loading branch information
maxf committed Mar 29, 2024
1 parent 6f4a6bf commit 368760e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/controller/DiscordController.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (dc *DiscordController) GetDiscordUserCard(searchString string, buttonsEnab
Value: user.IP.String(),
Inline: true,
},
{
Name: "IPv6",
Value: user.IP6.String(),
Inline: true,
},
{
Name: "Username",
Value: user.Name,
Expand Down
19 changes: 19 additions & 0 deletions pkg/database/KeaQueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ func (h *Handler) FindMACByIP(ip string) (mac string, err error) {
return
}

// FindMACByIPv6 finds a client's MAC from it's DHCPv6 lease
func (h *Handler) FindMACByIPv6(ip string) (mac string, err error) {
rows, err := h.connection.Query("SELECT hex(hwaddr) FROM lease6 WHERE INET6_NTOA(address)=?;", ip)
defer Close(rows)
if err != nil {
return
}
if !rows.Next() {
return
}
err = rows.Scan(&mac)
return
}

func (h *Handler) ClearLeasesForMAC(tx *sql.Tx, mac string) (string, *net.IP, error) {
res, err := tx.Query("SELECT hostname, INET_NTOA(address) FROM lease4 WHERE hwaddr = UNHEX(?) ORDER BY expire DESC limit 1;", mac)
if err != nil {
Expand All @@ -41,5 +55,10 @@ func (h *Handler) ClearLeasesForMAC(tx *sql.Tx, mac string) (string, *net.IP, er
Close(res)

_, err = tx.Exec("DELETE FROM lease4 WHERE hwaddr = UNHEX(?);", mac)
if err != nil {
return hostname, &ip, err
}

_, err = tx.Exec("DELETE FROM lease6 WHERE hwaddr = UNHEX(?);", mac)
return hostname, &ip, err
}
20 changes: 20 additions & 0 deletions pkg/database/Queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type User struct {
Mac string
IP net.IP
IP6 net.IP
Hostname string
Name string
Email string
Expand Down Expand Up @@ -100,6 +101,25 @@ func (h *Handler) LoadUser(mac string) (*User, error) {
}
}

res, err = h.connection.Query("SELECT INET6_NTOA(address) FROM lease6 WHERE hwaddr=UNHEX(?)", mac)
if err != nil {
Close(res)
return nil, err
}

if res.Next() {
var ip6Str string
err = res.Scan(&ip6Str)
if err != nil {
Close(res)
return nil, err
}
user.IP6 = net.ParseIP(ip6Str)
if user.IP6 == nil {
user.IP6 = net.IP{}
}
}

user.Sessions, err = h.FindSessionsForMAC(mac)
Close(res)
return user, err
Expand Down

0 comments on commit 368760e

Please sign in to comment.