activity: fix IP parsing, drop all columns with malformed ips

This commit is contained in:
Matthew Penner
2023-01-24 14:36:18 -07:00
parent a36cab1783
commit 18de96d7b8
3 changed files with 39 additions and 39 deletions

View File

@@ -1,11 +1,11 @@
package models
import (
"net"
"strings"
"time"
"gorm.io/gorm"
"github.com/pterodactyl/wings/system"
)
type Event string
@@ -57,7 +57,9 @@ func (a Activity) SetUser(u string) *Activity {
// is trimmed down to remove any extraneous data, and the timestamp is set to the current
// system time and then stored as UTC.
func (a *Activity) BeforeCreate(_ *gorm.DB) error {
a.IP = system.TrimIPSuffix(a.IP)
if ip, _, err := net.SplitHostPort(strings.TrimSpace(a.IP)); err == nil {
a.IP = ip
}
if a.Timestamp.IsZero() {
a.Timestamp = time.Now()
}