mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 06:25:35 +08:00
1. Database Enhancements (db/repositories.go): - Added ConfigRepository interface and implementations for PostgreSQL and SQLite - Updated Repositories struct to include ConfigRepository - Modified NewRepositories to initialize both UserRepo and ConfigRepo 2. FSD Server Improvements: - Removed hardcoded jwtSecret, now retrieved from ConfigRepository (fsd/conn.go, web/auth.go) - Added dynamic welcome message retrieval from ConfigRepository (fsd/conn.go) - Optimized METAR buffer size from 4096 to 512 bytes (fsd/metar.go) - Reduced minimum fields for DeleteATC and DeletePilot packets (fsd/packet.go) - Improved Haversine distance calculation with constants (fsd/postoffice.go) - Added thread-safety documentation for sendError (fsd/client.go) 3. Server Configuration (fsd/server.go): - Added NewDefaultServer to initialize server with environment-based config - Implemented automatic database migration and default admin user creation - Added configurable METAR worker count - Improved logging with slog and environment-based debug level 4. Web Interface Enhancements: - Added user and config editor frontend routes (web/frontend.go, web/routes.go) - Improved JWT handling by retrieving secret from ConfigRepository (web/auth.go) - Enhanced user management API endpoints (web/user.go) - Updated dashboard to display CID and conditional admin links (web/templates/dashboard.html) - Embedded templates using go:embed (web/templates.go) 5. Frontend JavaScript Improvements: - Added networkRatingFromInt helper for readable ratings (web/static/js/openfsd/dashboard.js) - Improved API request handling with auth/no-auth variants (web/static/js/openfsd/api.js) 6. Miscellaneous: - Added sethvargo/go-envconfig dependency for environment variable parsing - Fixed parseVisRange to use 64-bit float parsing (fsd/util.go) - Added strPtr utility function (fsd/util.go, web/main.go) - Improved SVG logo rendering in layout (web/templates/layout.html)
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
type ConfigRepository interface {
|
|
// InitDefault initializes the default state of the Config if one does not already exist.
|
|
InitDefault() (err error)
|
|
|
|
// Set sets a value for a given key
|
|
Set(key string, value string) (err error)
|
|
|
|
// Get gets a value for a given key.
|
|
//
|
|
// Returns ErrConfigKeyNotFound if no key/value pair is found.
|
|
Get(key string) (value string, err error)
|
|
}
|
|
|
|
const (
|
|
ConfigJwtSecretKey = "JWT_SECRET_KEY"
|
|
ConfigWelcomeMessage = "WELCOME_MESSAGE"
|
|
)
|
|
|
|
var ErrConfigKeyNotFound = errors.New("config: key not found")
|
|
|
|
const secretKeyBits = 256
|
|
|
|
func GenerateJwtSecretKey() (key [secretKeyBits / 8]byte, err error) {
|
|
secretKey := make([]byte, (secretKeyBits/8)/2)
|
|
if _, err = io.ReadFull(rand.Reader, secretKey); err != nil {
|
|
return
|
|
}
|
|
|
|
hex.Encode(key[:], secretKey)
|
|
|
|
return
|
|
}
|
|
|
|
// GetWelcomeMessage returns any configured welcome message.
|
|
// Returns an empty string if no message is found.
|
|
func GetWelcomeMessage(r *ConfigRepository) (msg string) {
|
|
msg, _ = (*r).Get(ConfigWelcomeMessage)
|
|
return
|
|
}
|