Configure cron to actually send to endpoint

This commit is contained in:
DaneEveritt
2022-07-09 15:47:24 -04:00
parent 28137c4c14
commit 49f3a61d16
4 changed files with 31 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/goccy/go-json"
"github.com/pterodactyl/wings/internal/database"
"github.com/xujiajun/nutsdb"
"regexp"
"time"
)
@@ -17,6 +18,8 @@ const (
ActivityConsoleCommand = Event("console_command")
)
var ipTrimRegex = regexp.MustCompile(`(:\d*)?$`)
type Activity struct {
// User is UUID of the user that triggered this event, or an empty string if the event
// cannot be tied to a specific user, in which case we will assume it was the system
@@ -89,6 +92,10 @@ func (a Activity) Save() error {
a.Timestamp = time.Now().UTC()
}
// Since the "RemoteAddr" field can often include a port on the end we need to
// trim that off, otherwise it'll fail validation when sent to the Panel.
a.IP = ipTrimRegex.ReplaceAllString(a.IP, "")
value, err := json.Marshal(a)
if err != nil {
return errors.Wrap(err, "database: failed to marshal activity into json bytes")