Compare commits
16 Commits
feature/ac
...
feature/co
| Author | SHA1 | Date | |
|---|---|---|---|
| f2580b6de0 | |||
| f23f276ee5 | |||
| 180555c903 | |||
| efc6b72838 | |||
| 0e04da031b | |||
| 908adf4468 | |||
| 6c1e9b236e | |||
| f563d52396 | |||
| a490a73392 | |||
| 0ef47ef241 | |||
| ea2e871c9b | |||
| c2c6543068 | |||
| a6f67dd652 | |||
| e637b5e649 | |||
| 1100072245 | |||
| 49dfa38475 |
@@ -1,78 +1,26 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Use a display number derived from the server port to avoid conflicts
|
||||||
|
# between containers (each server gets its own unique display).
|
||||||
DISPLAY_NUM=$((SERVER_PORT % 1000 + 100))
|
DISPLAY_NUM=$((SERVER_PORT % 1000 + 100))
|
||||||
export DISPLAY=:${DISPLAY_NUM}
|
export DISPLAY=:${DISPLAY_NUM}
|
||||||
|
|
||||||
|
# Clean up any stale X lock from a previous container run.
|
||||||
rm -f /tmp/.X${DISPLAY_NUM}-lock /tmp/.X11-unix/X${DISPLAY_NUM} 2>/dev/null || true
|
rm -f /tmp/.X${DISPLAY_NUM}-lock /tmp/.X11-unix/X${DISPLAY_NUM} 2>/dev/null || true
|
||||||
|
|
||||||
Xvfb ${DISPLAY} -screen 0 1024x768x16 -nolisten tcp &
|
Xvfb ${DISPLAY} -screen 0 1024x768x16 -nolisten tcp &
|
||||||
XVFB_PID=$!
|
XVFB_PID=$!
|
||||||
|
|
||||||
TCPDUMP_PID=""
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo "Stopping ACC server..."
|
echo "Stopping ACC server..."
|
||||||
[ -n "${TCPDUMP_PID}" ] && kill "${TCPDUMP_PID}" 2>/dev/null || true
|
kill $XVFB_PID 2>/dev/null || true
|
||||||
kill "${XVFB_PID}" 2>/dev/null || true
|
|
||||||
}
|
}
|
||||||
trap cleanup SIGTERM SIGINT EXIT
|
trap cleanup SIGTERM SIGINT
|
||||||
|
|
||||||
# Initialize Wine prefix (no-op if already done)
|
|
||||||
wineboot -u 2>/dev/null
|
|
||||||
|
|
||||||
mkdir -p /acc/game/log
|
mkdir -p /acc/game/log
|
||||||
|
|
||||||
# ─── Debug mode ───────────────────────────────────────────────────────────────
|
echo "Starting ACC server on port ${SERVER_PORT}..."
|
||||||
# Set DEBUG_MODE=1 on the container to enable extra diagnostics:
|
|
||||||
#
|
|
||||||
# docker run -e DEBUG_MODE=1 ...
|
|
||||||
# or in docker-compose:
|
|
||||||
# environment:
|
|
||||||
# DEBUG_MODE: "1"
|
|
||||||
#
|
|
||||||
# Produces:
|
|
||||||
# /acc/game/log/tcpdump_<port>.pcap — raw packet capture (open in Wireshark)
|
|
||||||
# /acc/game/log/wine_debug.log — Wine debug output
|
|
||||||
# Stderr: Wine version, WINEDEBUG channel, prefix state
|
|
||||||
#
|
|
||||||
# You can also override which Wine debug channels are enabled:
|
|
||||||
# WINEDEBUG_CHANNELS="+loaddll,+seh,+relay" (relay is very verbose)
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
if [ "${DEBUG_MODE:-0}" = "1" ]; then
|
|
||||||
echo "[debug] Debug mode enabled for port ${SERVER_PORT}"
|
|
||||||
echo "[debug] Wine: $(wine --version 2>/dev/null || echo unknown)"
|
|
||||||
echo "[debug] WINEPREFIX: ${WINEPREFIX}"
|
|
||||||
|
|
||||||
# Configure Wine debug channels (default: loader + exception + module info)
|
cd /acc/game
|
||||||
export WINEDEBUG="${WINEDEBUG_CHANNELS:-+loaddll,+module,+seh,+ntdll}"
|
exec wine /acc/game/accServer.exe
|
||||||
echo "[debug] WINEDEBUG=${WINEDEBUG}"
|
|
||||||
|
|
||||||
# Start packet capture on the server port — captures both TCP and UDP.
|
|
||||||
# The pcap file records every byte Kunos sends/receives so you can inspect
|
|
||||||
# the 2-byte "pakSizeMax" packet and anything that follows.
|
|
||||||
#
|
|
||||||
# NOTE: requires CAP_NET_RAW capability on the container:
|
|
||||||
# docker-compose: cap_add: [NET_RAW]
|
|
||||||
# docker run: --cap-add=NET_RAW
|
|
||||||
# Without it tcpdump will be skipped (no crash, just no capture).
|
|
||||||
CAPTURE_FILE="/acc/game/log/tcpdump_${SERVER_PORT}.pcap"
|
|
||||||
echo "[debug] Starting packet capture → ${CAPTURE_FILE}"
|
|
||||||
echo "[debug] (requires cap_add: [NET_RAW] in docker-compose — will exit silently if missing)"
|
|
||||||
tcpdump -i any -nn -s 0 -w "${CAPTURE_FILE}" \
|
|
||||||
"port ${SERVER_PORT}" 2>/acc/game/log/tcpdump.err &
|
|
||||||
TCPDUMP_PID=$!
|
|
||||||
|
|
||||||
# Redirect Wine debug output to a log file (Wine writes to stderr).
|
|
||||||
WINE_LOG="/acc/game/log/wine_debug.log"
|
|
||||||
echo "[debug] Wine debug log → ${WINE_LOG}"
|
|
||||||
echo "Starting ACC server on port ${SERVER_PORT} (DEBUG)..."
|
|
||||||
cd /acc/game
|
|
||||||
exec wine /acc/game/accServer.exe 2>"${WINE_LOG}"
|
|
||||||
else
|
|
||||||
# Production: suppress all Wine debug output.
|
|
||||||
export WINEDEBUG=-all
|
|
||||||
echo "Starting ACC server on port ${SERVER_PORT}..."
|
|
||||||
cd /acc/game
|
|
||||||
exec wine /acc/game/accServer.exe
|
|
||||||
fi
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ func Init(di *dig.Container, app *fiber.App) {
|
|||||||
Steam: groups.Group("/steam"),
|
Steam: groups.Group("/steam"),
|
||||||
ActivityLog: serverIdGroup.Group("/activity-log"),
|
ActivityLog: serverIdGroup.Group("/activity-log"),
|
||||||
Groups: groups,
|
Groups: groups,
|
||||||
|
Log: serverIdGroup.Group("/log"),
|
||||||
|
Presets: groups.Group("/presets"),
|
||||||
}
|
}
|
||||||
|
|
||||||
accessKeyMiddleware := middleware.NewAccessKeyMiddleware()
|
accessKeyMiddleware := middleware.NewAccessKeyMiddleware()
|
||||||
|
|||||||
@@ -21,36 +21,12 @@ func NewActivityLogController(as *service.ActivityLogService, routeGroups *commo
|
|||||||
errorHandler: error_handler.NewControllerErrorHandler(),
|
errorHandler: error_handler.NewControllerErrorHandler(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per-server activity log: GET /server/:id/activity-log
|
|
||||||
routeGroups.ActivityLog.Use(auth.Authenticate)
|
|
||||||
routeGroups.ActivityLog.Get("/", ac.GetServerLogs)
|
|
||||||
|
|
||||||
// Global activity log: GET /activity-log (admin use)
|
// Global activity log: GET /activity-log (admin use)
|
||||||
routeGroups.Groups.Group("/activity-log").Use(auth.Authenticate).Get("/", ac.GetAllLogs)
|
routeGroups.Groups.Group("/activity-log").Use(auth.Authenticate).Get("/", ac.GetAllLogs)
|
||||||
|
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServerLogs returns activity logs for a specific server.
|
|
||||||
//
|
|
||||||
// @Summary Return activity logs for a server
|
|
||||||
// @Tags ActivityLog
|
|
||||||
// @Success 200 {array} model.ActivityLog
|
|
||||||
// @Router /server/{id}/activity-log [get]
|
|
||||||
func (ac *ActivityLogController) GetServerLogs(c *fiber.Ctx) error {
|
|
||||||
var filter model.ActivityLogFilter
|
|
||||||
if err := common.ParseQueryFilter(c, &filter); err != nil {
|
|
||||||
return ac.errorHandler.HandleValidationError(c, err, "query_filter")
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := ac.service.GetAll(c.UserContext(), &filter)
|
|
||||||
if err != nil {
|
|
||||||
return ac.errorHandler.HandleServiceError(c, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAllLogs returns activity logs across all servers (admin).
|
// GetAllLogs returns activity logs across all servers (admin).
|
||||||
//
|
//
|
||||||
// @Summary Return all activity logs
|
// @Summary Return all activity logs
|
||||||
|
|||||||
246
local/controller/config_preset.go
Normal file
246
local/controller/config_preset.go
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/middleware"
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
"acc-server-manager/local/service"
|
||||||
|
"acc-server-manager/local/utl/common"
|
||||||
|
"acc-server-manager/local/utl/error_handler"
|
||||||
|
"acc-server-manager/local/utl/logging"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigPresetController struct {
|
||||||
|
service *service.ConfigPresetService
|
||||||
|
apiService *service.ServiceControlService
|
||||||
|
errorHandler *error_handler.ControllerErrorHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewConfigPresetController initializes ConfigPresetController.
|
||||||
|
func NewConfigPresetController(s *service.ConfigPresetService, apiService *service.ServiceControlService, routeGroups *common.RouteGroups, auth *middleware.AuthMiddleware) *ConfigPresetController {
|
||||||
|
c := &ConfigPresetController{
|
||||||
|
service: s,
|
||||||
|
apiService: apiService,
|
||||||
|
errorHandler: error_handler.NewControllerErrorHandler(),
|
||||||
|
}
|
||||||
|
|
||||||
|
presetRoutes := routeGroups.Presets
|
||||||
|
presetRoutes.Use(auth.Authenticate)
|
||||||
|
presetRoutes.Get("/", auth.HasPermission(model.PresetView), c.ListPresets)
|
||||||
|
presetRoutes.Post("/", auth.HasPermission(model.PresetCreate), c.CreatePreset)
|
||||||
|
presetRoutes.Get("/:presetId", auth.HasPermission(model.PresetView), c.GetPreset)
|
||||||
|
presetRoutes.Put("/:presetId", auth.HasPermission(model.PresetUpdate), c.UpdatePreset)
|
||||||
|
presetRoutes.Delete("/:presetId", auth.HasPermission(model.PresetDelete), c.DeletePreset)
|
||||||
|
|
||||||
|
configRoutes := routeGroups.Config
|
||||||
|
configRoutes.Post("/presets/:presetId/apply", auth.HasPermission(model.ConfigUpdate), c.ApplyPreset)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListPresets returns all config presets.
|
||||||
|
//
|
||||||
|
// @Summary List config presets
|
||||||
|
// @Description Get a list of all saved configuration presets
|
||||||
|
// @Tags Config Presets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param name query string false "Filter by preset name (partial match)"
|
||||||
|
// @Success 200 {array} model.ConfigPreset "List of presets"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /presets [get]
|
||||||
|
func (c *ConfigPresetController) ListPresets(ctx *fiber.Ctx) error {
|
||||||
|
var filter model.ConfigPresetFilter
|
||||||
|
if err := common.ParseQueryFilter(ctx, &filter); err != nil {
|
||||||
|
return c.errorHandler.HandleParsingError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
presets, err := c.service.ListPresets(ctx.UserContext(), &filter)
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(presets)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPreset returns a single config preset by ID.
|
||||||
|
//
|
||||||
|
// @Summary Get config preset
|
||||||
|
// @Description Retrieve a single configuration preset by ID
|
||||||
|
// @Tags Config Presets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param presetId path string true "Preset ID (UUID format)"
|
||||||
|
// @Success 200 {object} model.ConfigPreset "Preset"
|
||||||
|
// @Failure 400 {object} error_handler.ErrorResponse "Invalid preset ID"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 404 {object} error_handler.ErrorResponse "Preset not found"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /presets/{presetId} [get]
|
||||||
|
func (c *ConfigPresetController) GetPreset(ctx *fiber.Ctx) error {
|
||||||
|
id, err := uuid.Parse(ctx.Params("presetId"))
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleUUIDError(ctx, "preset ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
preset, err := c.service.GetPreset(ctx.UserContext(), id)
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(preset)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePreset creates a new config preset.
|
||||||
|
//
|
||||||
|
// @Summary Create config preset
|
||||||
|
// @Description Save a new configuration preset with one or more ACC config sections
|
||||||
|
// @Tags Config Presets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param content body model.ConfigPresetCreateRequest true "Preset data"
|
||||||
|
// @Success 201 {object} model.ConfigPreset "Created preset"
|
||||||
|
// @Failure 400 {object} error_handler.ErrorResponse "Invalid request"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /presets [post]
|
||||||
|
func (c *ConfigPresetController) CreatePreset(ctx *fiber.Ctx) error {
|
||||||
|
var req model.ConfigPresetCreateRequest
|
||||||
|
if err := ctx.BodyParser(&req); err != nil {
|
||||||
|
return c.errorHandler.HandleParsingError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actorID, _ := ctx.Locals("userID").(string)
|
||||||
|
actorUsername, _ := ctx.Locals("actorUsername").(string)
|
||||||
|
if actorUsername == "" {
|
||||||
|
actorUsername = "system"
|
||||||
|
}
|
||||||
|
|
||||||
|
preset, err := c.service.CreatePreset(ctx.UserContext(), &req, actorID, actorUsername)
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
return ctx.Status(fiber.StatusCreated).JSON(preset)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePreset updates an existing config preset.
|
||||||
|
//
|
||||||
|
// @Summary Update config preset
|
||||||
|
// @Description Update name, description, or any config sections of an existing preset
|
||||||
|
// @Tags Config Presets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param presetId path string true "Preset ID (UUID format)"
|
||||||
|
// @Param content body model.ConfigPresetUpdateRequest true "Fields to update (omit to keep existing)"
|
||||||
|
// @Success 200 {object} model.ConfigPreset "Updated preset"
|
||||||
|
// @Failure 400 {object} error_handler.ErrorResponse "Invalid request or preset ID"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 404 {object} error_handler.ErrorResponse "Preset not found"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /presets/{presetId} [put]
|
||||||
|
func (c *ConfigPresetController) UpdatePreset(ctx *fiber.Ctx) error {
|
||||||
|
id, err := uuid.Parse(ctx.Params("presetId"))
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleUUIDError(ctx, "preset ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
var req model.ConfigPresetUpdateRequest
|
||||||
|
if err := ctx.BodyParser(&req); err != nil {
|
||||||
|
return c.errorHandler.HandleParsingError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
preset, err := c.service.UpdatePreset(ctx.UserContext(), id, &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(preset)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletePreset deletes a config preset.
|
||||||
|
//
|
||||||
|
// @Summary Delete config preset
|
||||||
|
// @Description Permanently delete a configuration preset
|
||||||
|
// @Tags Config Presets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param presetId path string true "Preset ID (UUID format)"
|
||||||
|
// @Success 204 "No Content"
|
||||||
|
// @Failure 400 {object} error_handler.ErrorResponse "Invalid preset ID"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /presets/{presetId} [delete]
|
||||||
|
func (c *ConfigPresetController) DeletePreset(ctx *fiber.Ctx) error {
|
||||||
|
id, err := uuid.Parse(ctx.Params("presetId"))
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleUUIDError(ctx, "preset ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.service.DeletePreset(ctx.UserContext(), id); err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
return ctx.SendStatus(fiber.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyPreset applies a saved preset to a server's config files.
|
||||||
|
//
|
||||||
|
// @Summary Apply config preset to server
|
||||||
|
// @Description Apply a saved configuration preset to an ACC server, writing only the sections stored in the preset
|
||||||
|
// @Tags Server Configuration
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Server ID (UUID format)"
|
||||||
|
// @Param presetId path string true "Preset ID (UUID format)"
|
||||||
|
// @Param restart query bool false "Restart the server after applying the preset"
|
||||||
|
// @Success 200 {array} model.Config "List of updated config audit records"
|
||||||
|
// @Failure 400 {object} error_handler.ErrorResponse "Invalid server or preset ID"
|
||||||
|
// @Failure 401 {object} error_handler.ErrorResponse "Unauthorized"
|
||||||
|
// @Failure 403 {object} error_handler.ErrorResponse "Insufficient permissions"
|
||||||
|
// @Failure 404 {object} error_handler.ErrorResponse "Server or preset not found"
|
||||||
|
// @Failure 500 {object} error_handler.ErrorResponse "Internal server error"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /server/{id}/config/presets/{presetId}/apply [post]
|
||||||
|
func (c *ConfigPresetController) ApplyPreset(ctx *fiber.Ctx) error {
|
||||||
|
restart := ctx.QueryBool("restart")
|
||||||
|
serverID := ctx.Params("id")
|
||||||
|
|
||||||
|
if _, err := uuid.Parse(serverID); err != nil {
|
||||||
|
return c.errorHandler.HandleUUIDError(ctx, "server ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Locals("serverId", serverID)
|
||||||
|
|
||||||
|
presetID, err := uuid.Parse(ctx.Params("presetId"))
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleUUIDError(ctx, "preset ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
actorID, _ := ctx.Locals("userID").(string)
|
||||||
|
actorUsername, _ := ctx.Locals("actorUsername").(string)
|
||||||
|
if actorUsername == "" {
|
||||||
|
actorUsername = "system"
|
||||||
|
}
|
||||||
|
|
||||||
|
configs, err := c.service.ApplyPreset(ctx.UserContext(), serverID, presetID, actorID, actorUsername)
|
||||||
|
if err != nil {
|
||||||
|
return c.errorHandler.HandleServiceError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if restart {
|
||||||
|
if _, err := c.apiService.ServiceControlRestartServer(ctx); err != nil {
|
||||||
|
logging.ErrorWithContext("PRESET_APPLY_RESTART", "Failed to restart server after preset apply: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.JSON(configs)
|
||||||
|
}
|
||||||
@@ -35,6 +35,11 @@ func InitializeControllers(c *dig.Container) {
|
|||||||
logging.Panic("unable to initialize config controller")
|
logging.Panic("unable to initialize config controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = c.Invoke(NewConfigPresetController)
|
||||||
|
if err != nil {
|
||||||
|
logging.Panic("unable to initialize config preset controller")
|
||||||
|
}
|
||||||
|
|
||||||
err = c.Invoke(NewServerController)
|
err = c.Invoke(NewServerController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panic("unable to initialize server controller")
|
logging.Panic("unable to initialize server controller")
|
||||||
@@ -74,4 +79,9 @@ func InitializeControllers(c *dig.Container) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panic("unable to initialize activity log controller")
|
logging.Panic("unable to initialize activity log controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = c.Invoke(NewLogController)
|
||||||
|
if err != nil {
|
||||||
|
logging.Panic("unable to initialize log controller")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
local/controller/log.go
Normal file
62
local/controller/log.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/middleware"
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
"acc-server-manager/local/service"
|
||||||
|
"acc-server-manager/local/utl/common"
|
||||||
|
"acc-server-manager/local/utl/error_handler"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogController struct {
|
||||||
|
service *service.ServerService
|
||||||
|
errorHandler *error_handler.ControllerErrorHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLogController(ss *service.ServerService, routeGroups *common.RouteGroups, auth *middleware.AuthMiddleware) *LogController {
|
||||||
|
lc := &LogController{
|
||||||
|
service: ss,
|
||||||
|
errorHandler: error_handler.NewControllerErrorHandler(),
|
||||||
|
}
|
||||||
|
|
||||||
|
logRoutes := routeGroups.Log
|
||||||
|
logRoutes.Use(auth.Authenticate)
|
||||||
|
logRoutes.Get("/", auth.HasPermission(model.ServerView), lc.GetLogLines)
|
||||||
|
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLogLines godoc
|
||||||
|
// @Summary Get last N lines of server log
|
||||||
|
// @Tags Server
|
||||||
|
// @Param id path string true "Server ID"
|
||||||
|
// @Param lines query int false "Number of lines to return (default 100)"
|
||||||
|
// @Success 200 {object} object{lines=[]string}
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Router /server/{id}/log [get]
|
||||||
|
func (lc *LogController) GetLogLines(c *fiber.Ctx) error {
|
||||||
|
serverIDStr := c.Params("id")
|
||||||
|
serverID, err := uuid.Parse(serverIDStr)
|
||||||
|
if err != nil {
|
||||||
|
return lc.errorHandler.HandleUUIDError(c, "server ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
n, _ := strconv.Atoi(c.Query("lines", "100"))
|
||||||
|
if n <= 0 {
|
||||||
|
n = 100
|
||||||
|
}
|
||||||
|
if n > 10000 {
|
||||||
|
n = 10000
|
||||||
|
}
|
||||||
|
|
||||||
|
lines, err := lc.service.GetLastLogLines(c, serverID, n)
|
||||||
|
if err != nil {
|
||||||
|
return lc.errorHandler.HandleServiceError(c, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(fiber.Map{"lines": lines})
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ func NewServiceControlController(as *service.ServiceControlService, routeGroups
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceRoutes := routeGroups.Server.Group("/:id/service")
|
serviceRoutes := routeGroups.Server.Group("/:id/service")
|
||||||
|
serviceRoutes.Use(auth.Authenticate)
|
||||||
serviceRoutes.Get("/:service", ac.getStatus)
|
serviceRoutes.Get("/:service", ac.getStatus)
|
||||||
serviceRoutes.Post("/start", ac.startServer)
|
serviceRoutes.Post("/start", ac.startServer)
|
||||||
serviceRoutes.Post("/stop", ac.stopServer)
|
serviceRoutes.Post("/stop", ac.stopServer)
|
||||||
|
|||||||
51
local/migrations/007_add_config_presets.go
Normal file
51
local/migrations/007_add_config_presets.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/utl/logging"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigPresetMigration struct {
|
||||||
|
ID uint `gorm:"primaryKey"`
|
||||||
|
Name string `gorm:"not null"`
|
||||||
|
Description string
|
||||||
|
Configuration string `gorm:"type:text"`
|
||||||
|
AssistRules string `gorm:"type:text"`
|
||||||
|
Event string `gorm:"type:text"`
|
||||||
|
EventRules string `gorm:"type:text"`
|
||||||
|
Settings string `gorm:"type:text"`
|
||||||
|
CreatedAt string
|
||||||
|
UpdatedAt string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ConfigPresetMigration) TableName() string {
|
||||||
|
return "config_presets"
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunAddConfigPresetsMigration(db *gorm.DB) error {
|
||||||
|
if err := db.AutoMigrate(&MigrationRecord{}); err != nil {
|
||||||
|
return fmt.Errorf("failed to ensure migration_records table: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var record MigrationRecord
|
||||||
|
if err := db.Where("migration_name = ?", "007_add_config_presets").First(&record).Error; err == nil {
|
||||||
|
logging.Info("Config presets migration already applied, skipping")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
record = MigrationRecord{
|
||||||
|
MigrationName: "007_add_config_presets",
|
||||||
|
AppliedAt: time.Now().UTC().Format(time.RFC3339),
|
||||||
|
Success: true,
|
||||||
|
Notes: "Added ConfigPreset table via GORM AutoMigrate",
|
||||||
|
}
|
||||||
|
if err := db.Create(&record).Error; err != nil {
|
||||||
|
return fmt.Errorf("failed to record migration 007: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logging.Info("Config presets migration recorded")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -15,11 +15,14 @@ const (
|
|||||||
ActionServerStop ActionType = "server_stop"
|
ActionServerStop ActionType = "server_stop"
|
||||||
ActionServerRestart ActionType = "server_restart"
|
ActionServerRestart ActionType = "server_restart"
|
||||||
ActionLeaderboardUpdate ActionType = "leaderboard_update"
|
ActionLeaderboardUpdate ActionType = "leaderboard_update"
|
||||||
|
ActionPresetCreate ActionType = "preset_create"
|
||||||
|
ActionPresetApply ActionType = "preset_apply"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActivityLog struct {
|
type ActivityLog struct {
|
||||||
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
||||||
ServerID uuid.UUID `json:"serverId" gorm:"not null;type:uuid;index"`
|
ServerID *uuid.UUID `json:"serverId" gorm:"type:uuid;index"`
|
||||||
|
Server *Server `json:"server,omitempty" gorm:"foreignKey:ServerID"`
|
||||||
UserID string `json:"userId" gorm:"not null"`
|
UserID string `json:"userId" gorm:"not null"`
|
||||||
Username string `json:"username" gorm:"not null"`
|
Username string `json:"username" gorm:"not null"`
|
||||||
Action ActionType `json:"action" gorm:"not null"`
|
Action ActionType `json:"action" gorm:"not null"`
|
||||||
@@ -39,10 +42,10 @@ func (a *ActivityLog) BeforeCreate(tx *gorm.DB) error {
|
|||||||
|
|
||||||
type ActivityLogFilter struct {
|
type ActivityLogFilter struct {
|
||||||
BaseFilter
|
BaseFilter
|
||||||
ServerBasedFilter
|
|
||||||
DateRangeFilter
|
DateRangeFilter
|
||||||
UserID string `query:"user_id"`
|
UserID string `query:"user_id"`
|
||||||
Action ActionType `query:"action"`
|
Action ActionType `query:"action"`
|
||||||
|
ServerID string `query:"server_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ActivityLogFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
func (f *ActivityLogFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
||||||
|
|||||||
48
local/model/config_preset.go
Normal file
48
local/model/config_preset.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigPreset struct {
|
||||||
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
||||||
|
Name string `json:"name" gorm:"not null"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Configuration string `json:"configuration" gorm:"type:text"`
|
||||||
|
AssistRules string `json:"assistRules" gorm:"type:text"`
|
||||||
|
Event string `json:"event" gorm:"type:text"`
|
||||||
|
EventRules string `json:"eventRules" gorm:"type:text"`
|
||||||
|
Settings string `json:"settings" gorm:"type:text"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ConfigPreset) BeforeCreate(tx *gorm.DB) error {
|
||||||
|
if p.ID == uuid.Nil {
|
||||||
|
p.ID = uuid.New()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConfigPresetCreateRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Configuration *map[string]interface{} `json:"configuration"`
|
||||||
|
AssistRules *map[string]interface{} `json:"assistRules"`
|
||||||
|
Event *map[string]interface{} `json:"event"`
|
||||||
|
EventRules *map[string]interface{} `json:"eventRules"`
|
||||||
|
Settings *map[string]interface{} `json:"settings"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConfigPresetUpdateRequest struct {
|
||||||
|
Name *string `json:"name"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
Configuration *map[string]interface{} `json:"configuration"`
|
||||||
|
AssistRules *map[string]interface{} `json:"assistRules"`
|
||||||
|
Event *map[string]interface{} `json:"event"`
|
||||||
|
EventRules *map[string]interface{} `json:"eventRules"`
|
||||||
|
Settings *map[string]interface{} `json:"settings"`
|
||||||
|
}
|
||||||
@@ -30,6 +30,18 @@ type ConfigFilter struct {
|
|||||||
ChangedAt time.Time `query:"changed_at" time_format:"2006-01-02T15:04:05Z07:00"`
|
ChangedAt time.Time `query:"changed_at" time_format:"2006-01-02T15:04:05Z07:00"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConfigPresetFilter struct {
|
||||||
|
BaseFilter
|
||||||
|
Name string `query:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *ConfigPresetFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
||||||
|
if f.Name != "" {
|
||||||
|
query = query.Where("name LIKE ?", "%"+f.Name+"%")
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
type ServiceControlFilter struct {
|
type ServiceControlFilter struct {
|
||||||
BaseFilter
|
BaseFilter
|
||||||
ServiceControl string `query:"serviceControl"`
|
ServiceControl string `query:"serviceControl"`
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ const (
|
|||||||
MembershipCreate = "membership.create"
|
MembershipCreate = "membership.create"
|
||||||
MembershipView = "membership.view"
|
MembershipView = "membership.view"
|
||||||
MembershipEdit = "membership.edit"
|
MembershipEdit = "membership.edit"
|
||||||
|
|
||||||
|
PresetView = "preset.view"
|
||||||
|
PresetCreate = "preset.create"
|
||||||
|
PresetUpdate = "preset.update"
|
||||||
|
PresetDelete = "preset.delete"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AllPermissions() []string {
|
func AllPermissions() []string {
|
||||||
@@ -47,5 +52,9 @@ func AllPermissions() []string {
|
|||||||
MembershipCreate,
|
MembershipCreate,
|
||||||
MembershipView,
|
MembershipView,
|
||||||
MembershipEdit,
|
MembershipEdit,
|
||||||
|
PresetView,
|
||||||
|
PresetCreate,
|
||||||
|
PresetUpdate,
|
||||||
|
PresetDelete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const (
|
|||||||
MessageTypeSteamOutput WebSocketMessageType = "steam_output"
|
MessageTypeSteamOutput WebSocketMessageType = "steam_output"
|
||||||
MessageTypeError WebSocketMessageType = "error"
|
MessageTypeError WebSocketMessageType = "error"
|
||||||
MessageTypeComplete WebSocketMessageType = "complete"
|
MessageTypeComplete WebSocketMessageType = "complete"
|
||||||
|
MessageTypeLogLine WebSocketMessageType = "log_line"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebSocketMessage struct {
|
type WebSocketMessage struct {
|
||||||
@@ -65,6 +66,10 @@ type CompleteMessage struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LogLineMessage struct {
|
||||||
|
Line string `json:"line"`
|
||||||
|
}
|
||||||
|
|
||||||
func GetStepDescription(step ServerCreationStep) string {
|
func GetStepDescription(step ServerCreationStep) string {
|
||||||
descriptions := map[ServerCreationStep]string{
|
descriptions := map[ServerCreationStep]string{
|
||||||
StepValidation: "Validating server configuration",
|
StepValidation: "Validating server configuration",
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ type FirewallManager interface {
|
|||||||
type LogStreamer interface {
|
type LogStreamer interface {
|
||||||
Start(ctx context.Context, server *model.Server, handleLine func(string)) error
|
Start(ctx context.Context, server *model.Server, handleLine func(string)) error
|
||||||
Stop(serverID uuid.UUID)
|
Stop(serverID uuid.UUID)
|
||||||
|
GetLastLines(ctx context.Context, server *model.Server, n int) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"acc-server-manager/local/model"
|
"acc-server-manager/local/model"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -24,7 +25,27 @@ func (r *ActivityLogRepository) Insert(ctx context.Context, entry *model.Activit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *ActivityLogRepository) GetAll(ctx context.Context, filter *model.ActivityLogFilter) (*[]model.ActivityLog, error) {
|
func (r *ActivityLogRepository) GetAll(ctx context.Context, filter *model.ActivityLogFilter) (*[]model.ActivityLog, error) {
|
||||||
return r.BaseRepository.GetAll(ctx, filter)
|
result := &[]model.ActivityLog{}
|
||||||
|
query := r.BaseRepository.db.WithContext(ctx).
|
||||||
|
Model(&model.ActivityLog{}).
|
||||||
|
Preload("Server")
|
||||||
|
|
||||||
|
query = filter.ApplyFilter(query)
|
||||||
|
|
||||||
|
offset, limit := filter.Pagination()
|
||||||
|
query = query.Offset(offset).Limit(limit)
|
||||||
|
|
||||||
|
field, desc := filter.GetSorting()
|
||||||
|
if desc {
|
||||||
|
query = query.Order(field + " DESC")
|
||||||
|
} else {
|
||||||
|
query = query.Order(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Find(result).Error; err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting activity logs: %w", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type lastActivityRow struct {
|
type lastActivityRow struct {
|
||||||
|
|||||||
17
local/repository/config_preset.go
Normal file
17
local/repository/config_preset.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigPresetRepository struct {
|
||||||
|
*BaseRepository[model.ConfigPreset, model.ConfigPresetFilter]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConfigPresetRepository(db *gorm.DB) *ConfigPresetRepository {
|
||||||
|
return &ConfigPresetRepository{
|
||||||
|
BaseRepository: NewBaseRepository[model.ConfigPreset, model.ConfigPresetFilter](db, model.ConfigPreset{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ func InitializeRepositories(c *dig.Container) {
|
|||||||
c.Provide(NewMembershipRepository)
|
c.Provide(NewMembershipRepository)
|
||||||
c.Provide(NewLeaderboardRepository)
|
c.Provide(NewLeaderboardRepository)
|
||||||
c.Provide(NewActivityLogRepository)
|
c.Provide(NewActivityLogRepository)
|
||||||
|
c.Provide(NewConfigPresetRepository)
|
||||||
|
|
||||||
if err := c.Provide(func() *model.Steam2FAManager {
|
if err := c.Provide(func() *model.Steam2FAManager {
|
||||||
manager := model.NewSteam2FAManager()
|
manager := model.NewSteam2FAManager()
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ func BuildConfigDetails(file string, oldJSON, newJSON []byte) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(changedKeys) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
keysJSON, _ := json.Marshal(changedKeys)
|
keysJSON, _ := json.Marshal(changedKeys)
|
||||||
return fmt.Sprintf(`{"file":%q,"changed_keys":%s}`, file, string(keysJSON))
|
return fmt.Sprintf(`{"file":%q,"changed_keys":%s}`, file, string(keysJSON))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,16 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if entry.fileName == SettingsJson {
|
||||||
|
if nameVal, ok := (*entry.body)["serverName"]; ok {
|
||||||
|
if nameStr, ok := nameVal.(string); ok && nameStr != "" && nameStr != server.Name {
|
||||||
|
server.Name = nameStr
|
||||||
|
if err := as.serverRepository.Update(ctx.UserContext(), server); err != nil {
|
||||||
|
logging.Error("Failed to update server name in DB: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
result := as.repository.UpdateConfig(ctx.UserContext(), &model.Config{
|
result := as.repository.UpdateConfig(ctx.UserContext(), &model.Config{
|
||||||
ServerID: serverUUID,
|
ServerID: serverUUID,
|
||||||
ConfigFile: entry.fileName,
|
ConfigFile: entry.fileName,
|
||||||
@@ -147,10 +157,10 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
|||||||
results = append(results, result)
|
results = append(results, result)
|
||||||
|
|
||||||
if as.activityLog != nil {
|
if as.activityLog != nil {
|
||||||
details := BuildConfigDetails(entry.fileName, oldDataUTF8, newData)
|
if details := BuildConfigDetails(entry.fileName, oldDataUTF8, newData); details != "" {
|
||||||
go func(details string) {
|
go func(details string) {
|
||||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: serverUUID,
|
ServerID: &serverUUID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionConfigUpdate,
|
Action: model.ActionConfigUpdate,
|
||||||
@@ -159,6 +169,7 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
|||||||
}(details)
|
}(details)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(results) > 0 {
|
if len(results) > 0 {
|
||||||
as.configCache.InvalidateServerCache(serverID)
|
as.configCache.InvalidateServerCache(serverID)
|
||||||
@@ -256,14 +267,25 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID stri
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if configFile == SettingsJson {
|
||||||
|
if nameVal, ok := (*body)["serverName"]; ok {
|
||||||
|
if nameStr, ok := nameVal.(string); ok && nameStr != "" && nameStr != server.Name {
|
||||||
|
server.Name = nameStr
|
||||||
|
if err := as.serverRepository.Update(ctx, server); err != nil {
|
||||||
|
logging.Error("Failed to update server name in DB: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
as.configCache.InvalidateServerCache(serverID)
|
as.configCache.InvalidateServerCache(serverID)
|
||||||
as.serverService.StartAccServerRuntime(server)
|
as.serverService.StartAccServerRuntime(server)
|
||||||
|
|
||||||
if as.activityLog != nil {
|
if as.activityLog != nil {
|
||||||
details := BuildConfigDetails(configFile, oldDataUTF8, newData)
|
if details := BuildConfigDetails(configFile, oldDataUTF8, newData); details != "" {
|
||||||
go func() {
|
go func() {
|
||||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: serverUUID,
|
ServerID: &serverUUID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionConfigUpdate,
|
Action: model.ActionConfigUpdate,
|
||||||
@@ -271,6 +293,7 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID stri
|
|||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return as.repository.UpdateConfig(ctx, &model.Config{
|
return as.repository.UpdateConfig(ctx, &model.Config{
|
||||||
ServerID: serverUUID,
|
ServerID: serverUUID,
|
||||||
@@ -537,3 +560,17 @@ func (as *ConfigService) SaveConfiguration(server *model.Server, config *model.C
|
|||||||
_, _, err = as.updateConfigFiles(context.Background(), server, ConfigurationJson, &configMap, true)
|
_, _, err = as.updateConfigFiles(context.Background(), server, ConfigurationJson, &configMap, true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplySection writes a single config section to the server's config file and
|
||||||
|
// records the change. It is used by ConfigPresetService to apply preset sections.
|
||||||
|
func (as *ConfigService) ApplySection(ctx context.Context, serverID, configFile string, body *map[string]interface{}, actorID, actorUsername string) (*model.Config, error) {
|
||||||
|
return as.updateConfigInternal(ctx, serverID, configFile, body, true, actorID, actorUsername)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (as *ConfigService) SetServerName(server *model.Server, name string) error {
|
||||||
|
configMap := map[string]interface{}{
|
||||||
|
"serverName": name,
|
||||||
|
}
|
||||||
|
_, _, err := as.updateConfigFiles(context.Background(), server, SettingsJson, &configMap, false)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
210
local/service/config_preset.go
Normal file
210
local/service/config_preset.go
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
"acc-server-manager/local/repository"
|
||||||
|
"acc-server-manager/local/utl/logging"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
presetMaxNameLen = 100
|
||||||
|
presetMaxDescLen = 500
|
||||||
|
presetMaxSectionBytes = 64 * 1024 // 64 KB per config section
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigPresetService struct {
|
||||||
|
repository *repository.ConfigPresetRepository
|
||||||
|
configService *ConfigService
|
||||||
|
activityLog *ActivityLogService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConfigPresetService(repo *repository.ConfigPresetRepository, configService *ConfigService, activityLog *ActivityLogService) *ConfigPresetService {
|
||||||
|
return &ConfigPresetService{
|
||||||
|
repository: repo,
|
||||||
|
configService: configService,
|
||||||
|
activityLog: activityLog,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) ListPresets(ctx context.Context, filter *model.ConfigPresetFilter) (*[]model.ConfigPreset, error) {
|
||||||
|
return s.repository.GetAll(ctx, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) GetPreset(ctx context.Context, id uuid.UUID) (*model.ConfigPreset, error) {
|
||||||
|
preset, err := s.repository.GetByID(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if preset == nil {
|
||||||
|
return nil, fmt.Errorf("preset not found")
|
||||||
|
}
|
||||||
|
return preset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) CreatePreset(ctx context.Context, req *model.ConfigPresetCreateRequest, actorID, actorUsername string) (*model.ConfigPreset, error) {
|
||||||
|
if req.Name == "" {
|
||||||
|
return nil, fmt.Errorf("preset name is required")
|
||||||
|
}
|
||||||
|
if len(req.Name) > presetMaxNameLen {
|
||||||
|
return nil, fmt.Errorf("preset name exceeds maximum length of %d characters", presetMaxNameLen)
|
||||||
|
}
|
||||||
|
if len(req.Description) > presetMaxDescLen {
|
||||||
|
return nil, fmt.Errorf("preset description exceeds maximum length of %d characters", presetMaxDescLen)
|
||||||
|
}
|
||||||
|
|
||||||
|
preset := &model.ConfigPreset{
|
||||||
|
Name: req.Name,
|
||||||
|
Description: req.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := marshalSections(req.Configuration, req.AssistRules, req.Event, req.EventRules, req.Settings, preset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.repository.Insert(ctx, preset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
details := fmt.Sprintf(`{"preset_id":%q,"preset_name":%q}`, preset.ID, preset.Name)
|
||||||
|
go func() {
|
||||||
|
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
|
UserID: actorID,
|
||||||
|
Username: actorUsername,
|
||||||
|
Action: model.ActionPresetCreate,
|
||||||
|
Details: details,
|
||||||
|
}); logErr != nil {
|
||||||
|
logging.Error("Failed to log preset create: %v", logErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return preset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) UpdatePreset(ctx context.Context, id uuid.UUID, req *model.ConfigPresetUpdateRequest) (*model.ConfigPreset, error) {
|
||||||
|
preset, err := s.GetPreset(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Name != nil {
|
||||||
|
if len(*req.Name) == 0 {
|
||||||
|
return nil, fmt.Errorf("preset name cannot be empty")
|
||||||
|
}
|
||||||
|
if len(*req.Name) > presetMaxNameLen {
|
||||||
|
return nil, fmt.Errorf("preset name exceeds maximum length of %d characters", presetMaxNameLen)
|
||||||
|
}
|
||||||
|
preset.Name = *req.Name
|
||||||
|
}
|
||||||
|
if req.Description != nil {
|
||||||
|
if len(*req.Description) > presetMaxDescLen {
|
||||||
|
return nil, fmt.Errorf("preset description exceeds maximum length of %d characters", presetMaxDescLen)
|
||||||
|
}
|
||||||
|
preset.Description = *req.Description
|
||||||
|
}
|
||||||
|
if err := marshalSections(req.Configuration, req.AssistRules, req.Event, req.EventRules, req.Settings, preset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.repository.Update(ctx, preset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return preset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) DeletePreset(ctx context.Context, id uuid.UUID) error {
|
||||||
|
return s.repository.Delete(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigPresetService) ApplyPreset(ctx context.Context, serverID string, presetID uuid.UUID, actorID, actorUsername string) ([]*model.Config, error) {
|
||||||
|
preset, err := s.GetPreset(ctx, presetID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
serverUUID, err := uuid.Parse(serverID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid server ID: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type sectionEntry struct {
|
||||||
|
fileName string
|
||||||
|
raw string
|
||||||
|
}
|
||||||
|
|
||||||
|
sections := []sectionEntry{
|
||||||
|
{ConfigurationJson, preset.Configuration},
|
||||||
|
{AssistRulesJson, preset.AssistRules},
|
||||||
|
{EventJson, preset.Event},
|
||||||
|
{EventRulesJson, preset.EventRules},
|
||||||
|
{SettingsJson, preset.Settings},
|
||||||
|
}
|
||||||
|
|
||||||
|
var results []*model.Config
|
||||||
|
for _, section := range sections {
|
||||||
|
if section.raw == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
if err := json.Unmarshal([]byte(section.raw), &body); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to unmarshal preset section %s: %v", section.fileName, err)
|
||||||
|
}
|
||||||
|
result, err := s.configService.ApplySection(ctx, serverID, section.fileName, &body, actorID, actorUsername)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to apply preset section %s: %v", section.fileName, err)
|
||||||
|
}
|
||||||
|
if result != nil {
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
details := fmt.Sprintf(`{"preset_id":%q,"preset_name":%q,"sections_applied":%d}`, presetID, preset.Name, len(results))
|
||||||
|
go func() {
|
||||||
|
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
|
ServerID: &serverUUID,
|
||||||
|
UserID: actorID,
|
||||||
|
Username: actorUsername,
|
||||||
|
Action: model.ActionPresetApply,
|
||||||
|
Details: details,
|
||||||
|
}); logErr != nil {
|
||||||
|
logging.Error("Failed to log preset apply: %v", logErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// marshalSections marshals each non-nil config section into the preset's JSON string fields,
|
||||||
|
// enforcing the per-section byte size limit.
|
||||||
|
func marshalSections(configuration, assistRules, event, eventRules, settings *map[string]interface{}, preset *model.ConfigPreset) error {
|
||||||
|
type entry struct {
|
||||||
|
src *map[string]interface{}
|
||||||
|
name string
|
||||||
|
dest *string
|
||||||
|
}
|
||||||
|
entries := []entry{
|
||||||
|
{configuration, "configuration", &preset.Configuration},
|
||||||
|
{assistRules, "assistRules", &preset.AssistRules},
|
||||||
|
{event, "event", &preset.Event},
|
||||||
|
{eventRules, "eventRules", &preset.EventRules},
|
||||||
|
{settings, "settings", &preset.Settings},
|
||||||
|
}
|
||||||
|
for _, e := range entries {
|
||||||
|
if e.src == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
b, err := json.Marshal(e.src)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to marshal %s: %v", e.name, err)
|
||||||
|
}
|
||||||
|
if len(b) > presetMaxSectionBytes {
|
||||||
|
return fmt.Errorf("%s section exceeds maximum size of %d bytes", e.name, presetMaxSectionBytes)
|
||||||
|
}
|
||||||
|
*e.dest = string(b)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -6,7 +6,9 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
dockerclient "github.com/docker/docker/client"
|
dockerclient "github.com/docker/docker/client"
|
||||||
@@ -24,14 +26,14 @@ func NewDockerLogStreamer(client *dockerclient.Client) *DockerLogStreamer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, handleLine func(string)) error {
|
func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, handleLine func(string)) error {
|
||||||
if _, exists := s.cancels.Load(server.ID); exists {
|
s.Stop(server.ID)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if server.ContainerID == "" {
|
if server.ContainerID == "" {
|
||||||
logging.Warn("DockerLogStreamer.Start: no container ID for server %s, skipping", server.ID)
|
logging.Warn("DockerLogStreamer.Start: no container ID for server %s, skipping", server.ID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
since := time.Now().UTC().Format(time.RFC3339)
|
||||||
streamCtx, cancel := context.WithCancel(ctx)
|
streamCtx, cancel := context.WithCancel(ctx)
|
||||||
s.cancels.Store(server.ID, cancel)
|
s.cancels.Store(server.ID, cancel)
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, han
|
|||||||
ShowStderr: true,
|
ShowStderr: true,
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Timestamps: false,
|
Timestamps: false,
|
||||||
|
Since: since,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Error("DockerLogStreamer: failed to attach to container %s: %v", server.ContainerID[:12], err)
|
logging.Error("DockerLogStreamer: failed to attach to container %s: %v", server.ContainerID[:12], err)
|
||||||
@@ -72,3 +75,34 @@ func (s *DockerLogStreamer) Stop(serverID uuid.UUID) {
|
|||||||
v.(context.CancelFunc)()
|
v.(context.CancelFunc)()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerLogStreamer) GetLastLines(ctx context.Context, server *model.Server, n int) ([]string, error) {
|
||||||
|
if n <= 0 || server.ContainerID == "" {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
rc, err := s.client.ContainerLogs(ctx, server.ContainerID, types.ContainerLogsOptions{
|
||||||
|
ShowStdout: true,
|
||||||
|
ShowStderr: true,
|
||||||
|
Tail: strconv.Itoa(n),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rc.Close()
|
||||||
|
|
||||||
|
pr, pw := io.Pipe()
|
||||||
|
go func() {
|
||||||
|
defer pw.Close()
|
||||||
|
if _, err := stdcopy.StdCopy(pw, pw, rc); err != nil && err != io.EOF {
|
||||||
|
logging.Warn("DockerLogStreamer.GetLastLines: stdcopy error for %s: %v", server.ServiceName, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var lines []string
|
||||||
|
scanner := bufio.NewScanner(pr)
|
||||||
|
for scanner.Scan() {
|
||||||
|
lines = append(lines, scanner.Text())
|
||||||
|
}
|
||||||
|
return lines, scanner.Err()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package service
|
|||||||
import (
|
import (
|
||||||
"acc-server-manager/local/model"
|
"acc-server-manager/local/model"
|
||||||
"acc-server-manager/local/utl/tracking"
|
"acc-server-manager/local/utl/tracking"
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -36,3 +38,40 @@ func (s *FileLogStreamer) Stop(serverID uuid.UUID) {
|
|||||||
v.(*tracking.LogTailer).Stop()
|
v.(*tracking.LogTailer).Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *FileLogStreamer) GetLastLines(_ context.Context, server *model.Server, n int) ([]string, error) {
|
||||||
|
if n <= 0 {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
logPath := filepath.Join(server.GetLogPath(), "server.log")
|
||||||
|
f, err := os.Open(logPath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
ring := make([]string, n)
|
||||||
|
head := 0
|
||||||
|
count := 0
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
ring[head] = scanner.Text()
|
||||||
|
head = (head + 1) % n
|
||||||
|
if count < n {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if count < n {
|
||||||
|
return ring[:count], nil
|
||||||
|
}
|
||||||
|
out := make([]string, n)
|
||||||
|
copy(out, ring[head:])
|
||||||
|
copy(out[n-head:], ring[:head])
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (s *LeaderboardService) Update(ctx context.Context, serverID uuid.UUID, lb
|
|||||||
details := fmt.Sprintf(`{"driver_count":%d,"race_count":%d}`, driverCount, raceCount)
|
details := fmt.Sprintf(`{"driver_count":%d,"race_count":%d}`, driverCount, raceCount)
|
||||||
go func() {
|
go func() {
|
||||||
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: serverID,
|
ServerID: &serverID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionLeaderboardUpdate,
|
Action: model.ActionLeaderboardUpdate,
|
||||||
|
|||||||
@@ -48,12 +48,27 @@ type pendingState struct {
|
|||||||
|
|
||||||
func (s *ServerService) ensureLogTailing(server *model.Server, instance *tracking.AccServerInstance) {
|
func (s *ServerService) ensureLogTailing(server *model.Server, instance *tracking.AccServerInstance) {
|
||||||
go func() {
|
go func() {
|
||||||
if err := s.logStreamer.Start(context.Background(), server, instance.HandleLogLine); err != nil {
|
handleFn := func(line string) {
|
||||||
|
instance.HandleLogLine(line)
|
||||||
|
s.webSocketService.BroadcastLogLine(server.ID, line)
|
||||||
|
}
|
||||||
|
if err := s.logStreamer.Start(context.Background(), server, handleFn); err != nil {
|
||||||
logging.Error("Failed to start log streaming for server %s: %v", server.ID, err)
|
logging.Error("Failed to start log streaming for server %s: %v", server.ID, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) GetLastLogLines(ctx *fiber.Ctx, serverID uuid.UUID, n int) ([]string, error) {
|
||||||
|
server, err := s.repository.GetByID(ctx.UserContext(), serverID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if n <= 0 {
|
||||||
|
n = 100
|
||||||
|
}
|
||||||
|
return s.logStreamer.GetLastLines(ctx.UserContext(), server, n)
|
||||||
|
}
|
||||||
|
|
||||||
func NewServerService(
|
func NewServerService(
|
||||||
repository *repository.ServerRepository,
|
repository *repository.ServerRepository,
|
||||||
stateHistoryRepo *repository.StateHistoryRepository,
|
stateHistoryRepo *repository.StateHistoryRepository,
|
||||||
@@ -421,6 +436,10 @@ func (s *ServerService) createServerBackground(ctx context.Context, server *mode
|
|||||||
return "", fmt.Errorf("failed to update server configuration: %v", err)
|
return "", fmt.Errorf("failed to update server configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := s.configService.SetServerName(server, server.Name); err != nil {
|
||||||
|
logging.Error("Failed to set server name in config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("Server configuration generated (Port: %d)", serverPort), nil
|
return fmt.Sprintf("Server configuration generated (Port: %d)", serverPort), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ func InitializeServices(c *dig.Container) {
|
|||||||
c.Provide(NewMembershipService)
|
c.Provide(NewMembershipService)
|
||||||
c.Provide(NewWebSocketService)
|
c.Provide(NewWebSocketService)
|
||||||
c.Provide(NewLeaderboardService)
|
c.Provide(NewLeaderboardService)
|
||||||
|
c.Provide(NewConfigPresetService)
|
||||||
|
|
||||||
// Always provide the PortPoolManager; in Windows mode it seeds from an
|
// Always provide the PortPoolManager; in Windows mode it seeds from an
|
||||||
// empty result set and sits idle.
|
// empty result set and sits idle.
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func (as *ServiceControlService) ServiceControlStartServer(ctx *fiber.Ctx) (stri
|
|||||||
actorID, actorUsername := extractActor(ctx)
|
actorID, actorUsername := extractActor(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: server.ID,
|
ServerID: &server.ID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionServerStart,
|
Action: model.ActionServerStart,
|
||||||
@@ -147,7 +147,7 @@ func (as *ServiceControlService) ServiceControlStopServer(ctx *fiber.Ctx) (strin
|
|||||||
actorID, actorUsername := extractActor(ctx)
|
actorID, actorUsername := extractActor(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: server.ID,
|
ServerID: &server.ID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionServerStop,
|
Action: model.ActionServerStop,
|
||||||
@@ -184,7 +184,7 @@ func (as *ServiceControlService) ServiceControlRestartServer(ctx *fiber.Ctx) (st
|
|||||||
actorID, actorUsername := extractActor(ctx)
|
actorID, actorUsername := extractActor(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||||
ServerID: server.ID,
|
ServerID: &server.ID,
|
||||||
UserID: actorID,
|
UserID: actorID,
|
||||||
Username: actorUsername,
|
Username: actorUsername,
|
||||||
Action: model.ActionServerRestart,
|
Action: model.ActionServerRestart,
|
||||||
|
|||||||
@@ -103,6 +103,16 @@ func (ws *WebSocketService) BroadcastError(serverID uuid.UUID, error string, det
|
|||||||
ws.broadcastToServer(serverID, wsMsg)
|
ws.broadcastToServer(serverID, wsMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ws *WebSocketService) BroadcastLogLine(serverID uuid.UUID, line string) {
|
||||||
|
msg := model.WebSocketMessage{
|
||||||
|
Type: model.MessageTypeLogLine,
|
||||||
|
ServerID: &serverID,
|
||||||
|
Timestamp: time.Now().Unix(),
|
||||||
|
Data: model.LogLineMessage{Line: line},
|
||||||
|
}
|
||||||
|
ws.broadcastToServer(serverID, msg)
|
||||||
|
}
|
||||||
|
|
||||||
func (ws *WebSocketService) BroadcastComplete(serverID uuid.UUID, success bool, message string) {
|
func (ws *WebSocketService) BroadcastComplete(serverID uuid.UUID, success bool, message string) {
|
||||||
completeMsg := model.CompleteMessage{
|
completeMsg := model.CompleteMessage{
|
||||||
ServerID: serverID,
|
ServerID: serverID,
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ type RouteGroups struct {
|
|||||||
Steam fiber.Router
|
Steam fiber.Router
|
||||||
ActivityLog fiber.Router
|
ActivityLog fiber.Router
|
||||||
Groups fiber.Router
|
Groups fiber.Router
|
||||||
|
Log fiber.Router
|
||||||
|
Presets fiber.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckError(err error) {
|
func CheckError(err error) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = "0.12.3"
|
Version = "0.13.0"
|
||||||
Prefix = "v1"
|
Prefix = "v1"
|
||||||
Secret string
|
Secret string
|
||||||
SecretCode string
|
SecretCode string
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func Migrate(db *gorm.DB) {
|
|||||||
&model.LeaderboardResult{},
|
&model.LeaderboardResult{},
|
||||||
&model.LeaderboardPointRow{},
|
&model.LeaderboardPointRow{},
|
||||||
&model.ActivityLog{},
|
&model.ActivityLog{},
|
||||||
|
&model.ConfigPreset{},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,6 +86,10 @@ func runMigrations(db *gorm.DB) {
|
|||||||
logging.Error("Failed to run activity log migration: %v", err)
|
logging.Error("Failed to run activity log migration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := migrations.RunAddConfigPresetsMigration(db); err != nil {
|
||||||
|
logging.Error("Failed to run config presets migration: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
logging.Info("Custom database migrations completed")
|
logging.Info("Custom database migrations completed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user