Skip to content

Commit

Permalink
[Release] 4.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jun 17, 2024
1 parent d6fcfd6 commit 7e27222
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 20 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [4.9.0] 6/16/2024

* **Local Users** Fix issue where a locally created user may not get associated to the default database connection synchronized from the `eqemu_config.json` file. This would cause the user to not be able to log in to Spire Admin.
* **Local Users** Add information banner that explains to operators to go to the `/connections` page to manage user permissions after user creation.
* **Database Connections** Fix issue where the database connection would not display if a user had bad injected database connections.
* **Database Connections** Fix issue where deleted users would display in the database connections page.
* **Audit Logging** Add audit logging to most eqemu server administrative actions. This means if you have Discord webhooks set up for audit logging, you will now see these actions in your Discord channel.
* **Discord Webhook** Fix issue where the webhook would not update if it was empty

## [4.8.8] 6/16/2024

**Updating** Potential fixes for certain windows users during automatic updating.
Expand Down
6 changes: 3 additions & 3 deletions boot/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions frontend/src/components/modals/AppUpdateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

<div v-if="reloading">
Spire has been updated, waiting for Spire to restart to reload the page.
<br><br>
If you are not running Spire under a process manager or akk-stack, you will need to restart it manually.
</div>

<div>
Expand All @@ -69,13 +71,15 @@
<b-button
@click="ignoreUpdate"
variant="outline-secondary"
v-if="!reloading"
>
<i class="fe fe-x"></i> Skip Update
</b-button>

<b-button
@click="updateSpire"
variant="primary"
v-if="!reloading"
>
<i class="fe fe-download"></i> Update
</b-button>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/connections/Connections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export default {
// user defined
const r = await SpireApi.v1().get('/connections')
if (r.data && r.data.data) {
this.connections = r.data.data
this.connections = r.data.data.filter(c => c.database_connection.id > 0)
let isDefaultActive = true
for (const c of r.data.data) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/connections/UserConnections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@

<b-avatar-group rounded="lg" overlap="0.05" class="d-inline-block mt-1">
<div
v-for="user in c.database_connection.user_server_database_connections"
v-for="user in c.database_connection.user_server_database_connections.
filter(u => u.user.deleted_at === null && u.user.id > 0)"
:key="user.user.id"
@click="manageUser(user.user, c)"
>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/views/user/UserManagement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

<hr>

<div class="alert alert-warning" role="alert">
<i class="fa fa-info-circle mr-1"></i> After user creation, you will need to set the users permissions in the <router-link to="/connections">connections</router-link> page. New users have no permissions by default.
</div>

<div class="mt-3">

<info-error-banner
Expand Down
13 changes: 12 additions & 1 deletion internal/auditlog/user_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ func NewUserEvent(
}
}

func (e UserEvent) LogUserEvent(c echo.Context, eventName string, description string) {
const (
EventServerLock = "SERVER_LOCK"
EventServerUpdateRelease = "SERVER_UPDATE_RELEASE"
EventServerStart = "SERVER_START"
EventServerStop = "SERVER_STOP"
EventServerRestart = "SERVER_RESTART"
EventServerCancelRestart = "SERVER_CANCEL_RESTART"
EventServerHotReload = "SERVER_HOT_RELOAD"
EventServerUpdateConfig = "SERVER_UPDATE_CONFIG"
)

func (e *UserEvent) LogUserEvent(c echo.Context, eventName string, description string) {
// request user context
user := request.GetUser(c)

Expand Down
4 changes: 4 additions & 0 deletions internal/env/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const (
AppEnvProduction = "production"
)

func GetAppEnv() string {
return os.Getenv("APP_ENV")
}

func IsAppEnvDev() bool {
return os.Getenv("APP_ENV") == AppEnvDev
}
Expand Down
30 changes: 30 additions & 0 deletions internal/eqemuserver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/md5"
"errors"
"fmt"
"github.com/Akkadius/spire/internal/auditlog"
"github.com/Akkadius/spire/internal/database"
"github.com/Akkadius/spire/internal/eqemuserverconfig"
"github.com/Akkadius/spire/internal/http/request"
Expand Down Expand Up @@ -37,6 +38,7 @@ type Controller struct {
serverconfig *eqemuserverconfig.Config
updater *Updater
launcher *Launcher
userevent *auditlog.UserEvent
}

func NewController(
Expand All @@ -47,6 +49,7 @@ func NewController(
settings *spire.Settings,
updater *Updater,
launcher *Launcher,
userevent *auditlog.UserEvent,
) *Controller {
return &Controller{
db: db,
Expand All @@ -56,6 +59,7 @@ func NewController(
updater: updater,
settings: settings,
launcher: launcher,
userevent: userevent,
}
}

Expand Down Expand Up @@ -116,6 +120,8 @@ func (a *Controller) reload(c echo.Context) error {
)
}

a.userevent.LogUserEvent(c, auditlog.EventServerHotReload, fmt.Sprintf("Reloaded server with type [%v]", reloadType))

return c.JSON(http.StatusOK, r)
}

Expand Down Expand Up @@ -309,6 +315,8 @@ func (a *Controller) installRelease(c echo.Context) error {
)
}

a.userevent.LogUserEvent(c, auditlog.EventServerUpdateRelease, fmt.Sprintf("Updated server to release [%v]", release))

return c.JSON(
http.StatusOK,
echo.Map{"message": "Installed successfully"},
Expand Down Expand Up @@ -1054,6 +1062,8 @@ func (a *Controller) toggleServerLock(c echo.Context) error {
lockedMessage = "locked"
}

a.userevent.LogUserEvent(c, auditlog.EventServerLock, fmt.Sprintf("Server is now %v", lockedMessage))

return c.JSON(
http.StatusOK,
echo.Map{
Expand Down Expand Up @@ -1081,6 +1091,8 @@ func (a *Controller) serverStart(c echo.Context) error {
)
}

a.userevent.LogUserEvent(c, auditlog.EventServerStart, "Server started")

return c.JSON(
http.StatusOK,
echo.Map{"message": "Server started successfully"},
Expand All @@ -1101,6 +1113,14 @@ func (a *Controller) serverStop(c echo.Context) error {
a.launcher.SetStopTimer(stop.Timer)
a.launcher.SetStopTypeStopping()

timeToStop := time.Now().Add(time.Duration(stop.Timer) * time.Second)
remainingMinutes := timeToStop.Sub(time.Now()).Round(time.Minute).Minutes()
if stop.Timer > 0 {
a.userevent.LogUserEvent(c, auditlog.EventServerStop, fmt.Sprintf("Server will stop in [%v] minutes", remainingMinutes))
} else {
a.userevent.LogUserEvent(c, auditlog.EventServerStop, "Server stopped")
}

err = a.launcher.Stop()
if err != nil {
return c.JSON(
Expand All @@ -1125,6 +1145,14 @@ func (a *Controller) serverRestart(c echo.Context) error {
a.launcher.SetStopTypeRestarting()
a.launcher.SetStopTimer(stop.Timer)

timeToStop := time.Now().Add(time.Duration(stop.Timer) * time.Second)
remainingMinutes := timeToStop.Sub(time.Now()).Round(time.Minute).Minutes()
if stop.Timer > 0 {
a.userevent.LogUserEvent(c, auditlog.EventServerRestart, fmt.Sprintf("Server will restart in [%v] minutes", remainingMinutes))
} else {
a.userevent.LogUserEvent(c, auditlog.EventServerRestart, "Server restarted")
}

err = a.launcher.Restart()
if err != nil {
return c.JSON(
Expand All @@ -1148,6 +1176,8 @@ func (a *Controller) serverStopCancel(c echo.Context) error {
)
}

a.userevent.LogUserEvent(c, auditlog.EventServerCancelRestart, "Server stop/restart cancelled")

return c.JSON(
http.StatusOK,
echo.Map{"message": "Server stop cancelled successfully"},
Expand Down
21 changes: 8 additions & 13 deletions internal/http/controllers/connections_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,22 +652,17 @@ func (cc *ConnectionsController) setDiscordWebhook(c echo.Context) error {
)
}

if len(webhookUrl.WebhookUrl) > 0 {
conn.DiscordWebhookUrl = webhookUrl.WebhookUrl
_ = cc.db.GetSpireDb().
Model(&conn).
Where("created_by = ? and id = ?", ctx.ID, connectionId).
Update("discord_webhook_url", webhookUrl.WebhookUrl)
conn.DiscordWebhookUrl = webhookUrl.WebhookUrl
_ = cc.db.GetSpireDb().
Model(&conn).
Where("created_by = ? and id = ?", ctx.ID, connectionId).
Update("discord_webhook_url", webhookUrl.WebhookUrl)

return c.JSON(
http.StatusOK,
"Webhook updated successfully!",
)
}
cc.db.PurgeUserDbCache(ctx.ID)

return c.JSON(
http.StatusInternalServerError,
echo.Map{"error": "Failed to update discord webhook"},
http.StatusOK,
"Webhook updated successfully!",
)
}

Expand Down
14 changes: 14 additions & 0 deletions internal/spire/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func NewInit(
spireuser: spireuser,
}

i.logger.Debug().
Any("env", env.GetAppEnv()).
Any("env.IsAppEnvLocal()", env.IsAppEnvLocal()).
Msg("Init")

if env.IsAppEnvLocal() {
i.Init()
}
Expand All @@ -70,6 +75,11 @@ func (o *Init) Init() {
o.settings.LoadSettings()
o.isInitialized = o.CheckIfAppInitialized()

o.logger.Debug().
Any("o.isInitialized", o.isInitialized).
Any("o.settings", o.settings.settings).
Msg("Init")

// if we've set the app up initially but new settings have been added
// let's automatically run them
// otherwise these settings get populated when a user first sets up their
Expand All @@ -82,6 +92,8 @@ func (o *Init) Init() {
var adminUser models.User
o.connections.SpireDbNoLog().Where("is_admin = 1").First(&adminUser)

o.logger.Debug().Any("adminUser", adminUser).Msg("o.isInitialized")

o.SyncDbName()

if adminUser.ID > 0 {
Expand Down Expand Up @@ -208,6 +220,8 @@ func (o *Init) CreateDefaultDatabaseConnectionFromConfig(user models.User) error
}
}

o.logger.Debug().Any("c", c).Msg("Connection exists, updating...")

db.Save(&c)

return nil
Expand Down
5 changes: 5 additions & 0 deletions internal/user/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (a *Controller) create(c echo.Context) error {
uc.UserId = newUser.ID
uc.Active = 1
uc.ServerDatabaseConnectionId = 1
var conn models.ServerDatabaseConnection
a.db.GetSpireDb().First(&conn)
if conn.ID > 0 {
uc.ServerDatabaseConnectionId = conn.ID
}
uc.CreatedBy = u.ID
err = a.db.GetSpireDb().Create(&uc).Error
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "4.8.8",
"version": "4.9.0",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
Expand Down

0 comments on commit 7e27222

Please sign in to comment.