mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-14 06:51:15 +00:00
chore: replace logrus with standard lib log/slog
This commit is contained in:
@@ -7,14 +7,13 @@ import (
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
ginlogrus "github.com/toorop/gin-logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
"github.com/h44z/wg-portal/internal/config"
|
||||
@@ -56,14 +55,39 @@ func NewServer(cfg *config.Config, endpoints ...ApiEndpointSetupFunc) (*Server,
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
gin.DefaultWriter = io.Discard
|
||||
s.server = gin.New()
|
||||
|
||||
if cfg.Web.RequestLogging {
|
||||
if logrus.GetLevel() == logrus.TraceLevel {
|
||||
if cfg.Advanced.LogLevel == "trace" {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
s.server.Use(ginlogrus.Logger(logrus.StandardLogger()))
|
||||
} else {
|
||||
s.server.Use(ginlogrus.Logger(logrus.StandardLogger()))
|
||||
}
|
||||
s.server.Use(func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.Request.URL.Path
|
||||
raw := c.Request.URL.RawQuery
|
||||
|
||||
c.Next()
|
||||
|
||||
if raw != "" {
|
||||
path = path + "?" + raw
|
||||
}
|
||||
|
||||
latency := time.Since(start)
|
||||
status := c.Writer.Status()
|
||||
clientIP := c.ClientIP()
|
||||
method := c.Request.Method
|
||||
errorMsg := c.Errors.ByType(gin.ErrorTypePrivate).String()
|
||||
|
||||
slog.Debug("HTTP Request",
|
||||
"status", status,
|
||||
"latency", latency,
|
||||
"client", clientIP,
|
||||
"method", method,
|
||||
"path", path,
|
||||
"error", errorMsg,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
s.server.Use(gin.Recovery()).Use(func(c *gin.Context) {
|
||||
c.Writer.Header().Set("X-Served-By", hostname)
|
||||
c.Next()
|
||||
@@ -112,22 +136,24 @@ func (s *Server) Run(ctx context.Context, listenAddress string) {
|
||||
err = srv.ListenAndServe()
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Infof("web service on %s exited: %v", listenAddress, err)
|
||||
slog.Info("web service exited",
|
||||
"address", listenAddress,
|
||||
"error", err)
|
||||
cancelFn()
|
||||
}
|
||||
}()
|
||||
logrus.Infof("started web service on %s", listenAddress)
|
||||
slog.Info("started web service", "address", listenAddress)
|
||||
|
||||
// Wait for the main context to end
|
||||
<-srvContext.Done()
|
||||
|
||||
logrus.Debug("web service shutting down, grace period: 5 seconds...")
|
||||
slog.Debug("web service shutting down, grace period: 5 seconds")
|
||||
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = srv.Shutdown(shutdownCtx)
|
||||
|
||||
logrus.Debug("web service shut down")
|
||||
slog.Debug("web service shut down")
|
||||
}
|
||||
|
||||
func (s *Server) setupRoutes(endpoints ...ApiEndpointSetupFunc) {
|
||||
|
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/config"
|
||||
@@ -81,7 +81,7 @@ func (a *App) Startup(ctx context.Context) error {
|
||||
|
||||
func (a *App) importNewInterfaces(ctx context.Context) error {
|
||||
if !a.Config.Core.ImportExisting {
|
||||
logrus.Trace("skipping interface import - feature disabled")
|
||||
slog.Debug("skipping interface import - feature disabled")
|
||||
return nil // feature disabled
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ func (a *App) importNewInterfaces(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if importedCount > 0 {
|
||||
logrus.Infof("%d new interfaces imported", importedCount)
|
||||
slog.Info("new interfaces imported", "count", importedCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) restoreInterfaceState(ctx context.Context) error {
|
||||
if !a.Config.Core.RestoreState {
|
||||
logrus.Trace("skipping interface state restore - feature disabled")
|
||||
slog.Debug("skipping interface state restore - feature disabled")
|
||||
return nil // feature disabled
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ func (a *App) restoreInterfaceState(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Info("interface state restored")
|
||||
slog.Info("interface state restored")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) createDefaultUser(ctx context.Context) error {
|
||||
adminUserId := domain.UserIdentifier(a.Config.Core.AdminUser)
|
||||
if adminUserId == "" {
|
||||
logrus.Trace("skipping default user creation - admin user is blank")
|
||||
slog.Debug("skipping default user creation - admin user is blank")
|
||||
return nil // empty admin user - do not create
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (a *App) createDefaultUser(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
logrus.Trace("skipping default user creation - admin user already exists")
|
||||
slog.Debug("skipping default user creation - admin user already exists")
|
||||
return nil // admin user already exists
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (a *App) createDefaultUser(ctx context.Context) error {
|
||||
}
|
||||
if a.Config.Core.AdminApiToken != "" {
|
||||
if len(a.Config.Core.AdminApiToken) < 18 {
|
||||
logrus.Warnf("[SECURITY WARNING] admin API token is too short, should be at least 18 characters long")
|
||||
slog.Warn("admin API token is too short, should be at least 18 characters long")
|
||||
}
|
||||
defaultAdmin.ApiToken = a.Config.Core.AdminApiToken
|
||||
defaultAdmin.ApiTokenCreated = &now
|
||||
@@ -165,7 +165,7 @@ func (a *App) createDefaultUser(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("admin user %s created", admin.Identifier)
|
||||
slog.Info("admin user created", "identifier", admin.Identifier)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ package audit
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
@@ -52,7 +52,7 @@ func (r *Recorder) StartBackgroundJobs(ctx context.Context) {
|
||||
// select blocks until one of the cases evaluate to true
|
||||
}
|
||||
|
||||
logrus.Tracef("registered %d audit message within the last hour", 0) // TODO: implement
|
||||
slog.Debug("audit status", "registered_messages", 0) // TODO: implement
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (r *Recorder) authLoginEvent(userIdentifier domain.UserIdentifier) {
|
||||
Message: fmt.Sprintf("user %s logged in", userIdentifier),
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to create audit entry for handleAuthLoginEvent: %v", err)
|
||||
slog.Error("failed to create audit entry for handleAuthLoginEvent", "error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@@ -7,13 +7,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
@@ -227,7 +227,7 @@ func (a *Authenticator) passwordAuthentication(
|
||||
rawUserInfo, err := ldapAuth.GetUserInfo(context.Background(), identifier)
|
||||
if err != nil {
|
||||
if !errors.Is(err, domain.ErrNotFound) {
|
||||
logrus.Warnf("failed to fetch ldap user info for %s: %v", identifier, err)
|
||||
slog.Warn("failed to fetch ldap user info", "identifier", identifier, "error", err)
|
||||
}
|
||||
continue // user not found / other ldap error
|
||||
}
|
||||
@@ -407,8 +407,10 @@ func (a *Authenticator) registerNewUser(
|
||||
return nil, fmt.Errorf("failed to register new user: %w", err)
|
||||
}
|
||||
|
||||
logrus.Tracef("registered user %s from external authentication provider, admin user: %t",
|
||||
user.Identifier, user.IsAdmin)
|
||||
slog.Debug("registered user from external authentication provider",
|
||||
"user", user.Identifier,
|
||||
"isAdmin", user.IsAdmin,
|
||||
"provider", source)
|
||||
|
||||
return user, nil
|
||||
}
|
||||
@@ -483,8 +485,10 @@ func (a *Authenticator) updateExternalUser(
|
||||
return fmt.Errorf("failed to update user: %w", err)
|
||||
}
|
||||
|
||||
logrus.Tracef("updated user %s with data from external authentication provider, admin user: %t",
|
||||
existingUser.Identifier, existingUser.IsAdmin)
|
||||
slog.Debug("updated user with data from external authentication provider",
|
||||
"user", existingUser.Identifier,
|
||||
"isAdmin", existingUser.IsAdmin,
|
||||
"provider", source)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
"github.com/h44z/wg-portal/internal/config"
|
||||
@@ -117,7 +117,10 @@ func (l LdapAuthenticator) GetUserInfo(_ context.Context, userId domain.UserIden
|
||||
|
||||
if l.cfg.LogUserInfo {
|
||||
contents, _ := json.Marshal(users[0])
|
||||
logrus.Tracef("User info from LDAP source %s for %s: %v", l.GetName(), userId, string(contents))
|
||||
slog.Debug("LDAP user info",
|
||||
"source", l.GetName(),
|
||||
"userId", userId,
|
||||
"info", string(contents))
|
||||
}
|
||||
|
||||
return users[0], nil
|
||||
|
@@ -5,10 +5,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
@@ -111,7 +111,9 @@ func (p PlainOauthAuthenticator) GetUserInfo(
|
||||
}
|
||||
|
||||
if p.userInfoLogging {
|
||||
logrus.Tracef("User info from OAuth source %s: %v", p.name, string(contents))
|
||||
slog.Debug("OAuth user info",
|
||||
"source", p.name,
|
||||
"info", string(contents))
|
||||
}
|
||||
|
||||
return userFields, nil
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/config"
|
||||
@@ -106,7 +106,9 @@ func (o OidcAuthenticator) GetUserInfo(ctx context.Context, token *oauth2.Token,
|
||||
|
||||
if o.userInfoLogging {
|
||||
contents, _ := json.Marshal(tokenFields)
|
||||
logrus.Tracef("User info from OIDC source %s: %v", o.name, string(contents))
|
||||
slog.Debug("OIDC user info",
|
||||
"source", o.name,
|
||||
"info", string(contents))
|
||||
}
|
||||
|
||||
return tokenFields, nil
|
||||
|
@@ -6,10 +6,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
"github.com/yeqown/go-qrcode/v2"
|
||||
"github.com/yeqown/go-qrcode/writer/compressed"
|
||||
@@ -82,18 +82,22 @@ func (m Manager) handleInterfaceUpdatedEvent(iface *domain.Interface) {
|
||||
return
|
||||
}
|
||||
|
||||
logrus.Debugf("handling interface updated event for %s", iface.Identifier)
|
||||
slog.Debug("handling interface updated event", "interface", iface.Identifier)
|
||||
|
||||
err := m.PersistInterfaceConfig(context.Background(), iface.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to automatically persist interface config for %s: %v", iface.Identifier, err)
|
||||
slog.Error("failed to automatically persist interface config",
|
||||
"interface", iface.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m Manager) handlePeerInterfaceUpdatedEvent(id domain.InterfaceIdentifier) {
|
||||
peerInterface, err := m.wg.GetInterface(context.Background(), id)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to load interface %s: %v", id, err)
|
||||
slog.Error("failed to load interface",
|
||||
"interface", id,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -101,11 +105,13 @@ func (m Manager) handlePeerInterfaceUpdatedEvent(id domain.InterfaceIdentifier)
|
||||
return
|
||||
}
|
||||
|
||||
logrus.Debugf("handling peer interface updated event for %s", id)
|
||||
slog.Debug("handling peer interface updated event", "interface", id)
|
||||
|
||||
err = m.PersistInterfaceConfig(context.Background(), peerInterface.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to automatically persist interface config for %s: %v", peerInterface.Identifier, err)
|
||||
slog.Error("failed to automatically persist interface config",
|
||||
"interface", peerInterface.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,8 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"log/slog"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/config"
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
@@ -57,18 +56,25 @@ func (m Manager) SendPeerEmail(ctx context.Context, linkOnly bool, peers ...doma
|
||||
}
|
||||
|
||||
if peer.UserIdentifier == "" {
|
||||
logrus.Debugf("skipping peer email for %s, no user linked", peerId)
|
||||
slog.Debug("skipping peer email",
|
||||
"peer", peerId,
|
||||
"reason", "no user linked")
|
||||
continue
|
||||
}
|
||||
|
||||
user, err := m.users.GetUser(ctx, peer.UserIdentifier)
|
||||
if err != nil {
|
||||
logrus.Debugf("skipping peer email for %s, unable to fetch user: %v", peerId, err)
|
||||
slog.Debug("skipping peer email",
|
||||
"peer", peerId,
|
||||
"reason", "unable to fetch user",
|
||||
"error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if user.Email == "" {
|
||||
logrus.Debugf("skipping peer email for %s, user has no mail address", peerId)
|
||||
slog.Debug("skipping peer email",
|
||||
"peer", peerId,
|
||||
"reason", "user has no mail address")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@@ -3,10 +3,10 @@ package app
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/adapters"
|
||||
@@ -50,7 +50,7 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
|
||||
return fmt.Errorf("unsupported old version, update to database version %s first: %w", latestVersion, err)
|
||||
}
|
||||
|
||||
logrus.Infof("Found valid V1 database with version: %s", lastVersion.Version)
|
||||
slog.Info("found valid V1 database", "version", lastVersion.Version)
|
||||
|
||||
if err := migrateV1Users(oldDb, db); err != nil {
|
||||
return fmt.Errorf("user migration failed: %w", err)
|
||||
@@ -64,7 +64,8 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
|
||||
return fmt.Errorf("peer migration failed: %w", err)
|
||||
}
|
||||
|
||||
logrus.Infof("Migrated V1 database with version %s, please restart WireGuard Portal", lastVersion.Version)
|
||||
slog.Info("migrated V1 database successfully, please restart WireGuard Portal",
|
||||
"version", lastVersion.Version)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -126,7 +127,7 @@ func migrateV1Users(oldDb, newDb *gorm.DB) error {
|
||||
return fmt.Errorf("failed to migrate user %s: %w", oldUser.Email, err)
|
||||
}
|
||||
|
||||
logrus.Debugf(" - User %s migrated", newUser.Identifier)
|
||||
slog.Debug("user migrated successfully", "identifier", newUser.Identifier)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -220,7 +221,7 @@ func migrateV1Interfaces(oldDb, newDb *gorm.DB) error {
|
||||
return fmt.Errorf("failed to migrate device %s: %w", oldDevice.DeviceName, err)
|
||||
}
|
||||
|
||||
logrus.Debugf(" - Interface %s migrated", newInterface.Identifier)
|
||||
slog.Debug("interface migrated successfully", "identifier", newInterface.Identifier)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -319,7 +320,7 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
|
||||
return fmt.Errorf("failed to migrate dummy user %s: %w", oldPeer.Email, err)
|
||||
}
|
||||
|
||||
logrus.Debugf(" - Dummy User %s migrated", user.Identifier)
|
||||
slog.Debug("dummy user migrated successfully", "identifier", user.Identifier)
|
||||
}
|
||||
newPeer := domain.Peer{
|
||||
BaseModel: domain.BaseModel{
|
||||
@@ -365,7 +366,7 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
|
||||
return fmt.Errorf("failed to migrate peer %s (%s): %w", oldPeer.Identifier, oldPeer.PublicKey, err)
|
||||
}
|
||||
|
||||
logrus.Debugf(" - Peer %s migrated", newPeer.Identifier)
|
||||
slog.Debug("peer migrated successfully", "identifier", newPeer.Identifier)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -3,8 +3,8 @@ package route
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
"github.com/vishvananda/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -67,31 +67,33 @@ func (m Manager) StartBackgroundJobs(_ context.Context) {
|
||||
}
|
||||
|
||||
func (m Manager) handleRouteUpdateEvent(srcDescription string) {
|
||||
logrus.Debugf("handling route update event: %s", srcDescription)
|
||||
slog.Debug("handling route update event", "source", srcDescription)
|
||||
|
||||
err := m.syncRoutes(context.Background())
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to synchronize routes for event %s: %v", srcDescription, err)
|
||||
slog.Error("failed to synchronize routes",
|
||||
"source", srcDescription,
|
||||
"error", err)
|
||||
}
|
||||
|
||||
logrus.Debugf("routes synchronized, event: %s", srcDescription)
|
||||
slog.Debug("routes synchronized", "source", srcDescription)
|
||||
}
|
||||
|
||||
func (m Manager) handleRouteRemoveEvent(info domain.RoutingTableInfo) {
|
||||
logrus.Debugf("handling route remove event for: %s", info.String())
|
||||
slog.Debug("handling route remove event", "info", info.String())
|
||||
|
||||
if !info.ManagementEnabled() {
|
||||
return // route management disabled
|
||||
}
|
||||
|
||||
if err := m.removeFwMarkRules(info.FwMark, info.GetRoutingTable(), netlink.FAMILY_V4); err != nil {
|
||||
logrus.Errorf("failed to remove v4 fwmark rules: %v", err)
|
||||
slog.Error("failed to remove v4 fwmark rules", "error", err)
|
||||
}
|
||||
if err := m.removeFwMarkRules(info.FwMark, info.GetRoutingTable(), netlink.FAMILY_V6); err != nil {
|
||||
logrus.Errorf("failed to remove v6 fwmark rules: %v", err)
|
||||
slog.Error("failed to remove v6 fwmark rules", "error", err)
|
||||
}
|
||||
|
||||
logrus.Debugf("routes removed, table: %s", info.String())
|
||||
slog.Debug("routes removed", "table", info.String())
|
||||
}
|
||||
|
||||
func (m Manager) syncRoutes(ctx context.Context) error {
|
||||
@@ -437,14 +439,18 @@ func (m Manager) getRoutingTableAndFwMark(iface *domain.Interface, link netlink.
|
||||
if fwmark == 0 {
|
||||
// generate a new (temporary) firewall mark based on the interface index
|
||||
fwmark = uint32(m.cfg.Advanced.RouteTableOffset + link.Attrs().Index)
|
||||
logrus.Debugf("%s: using fwmark %d to handle routes", iface.Identifier, table)
|
||||
slog.Debug("using fwmark to handle routes",
|
||||
"interface", iface.Identifier,
|
||||
"fwmark", fwmark)
|
||||
|
||||
// apply the temporary fwmark to the wireguard interface
|
||||
err = m.setFwMark(iface.Identifier, int(fwmark))
|
||||
}
|
||||
if table == 0 {
|
||||
table = int(fwmark) // generate a new routing table base on interface index
|
||||
logrus.Debugf("%s: using routing table %d to handle default routes", iface.Identifier, table)
|
||||
slog.Debug("using routing table to handle default routes",
|
||||
"interface", iface.Identifier,
|
||||
"table", table)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
@@ -419,7 +419,7 @@ func (m Manager) runLdapSynchronizationService(ctx context.Context) {
|
||||
go func(cfg config.LdapProvider) {
|
||||
syncInterval := cfg.SyncInterval
|
||||
if syncInterval == 0 {
|
||||
logrus.Debugf("sync disabled for LDAP server: %s", cfg.ProviderName)
|
||||
slog.Debug("sync disabled for LDAP server", "provider", cfg.ProviderName)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ func (m Manager) runLdapSynchronizationService(ctx context.Context) {
|
||||
|
||||
err := m.synchronizeLdapUsers(ctx, &cfg)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to synchronize LDAP users for %s: %v", cfg.ProviderName, err)
|
||||
slog.Error("failed to synchronize LDAP users", "provider", cfg.ProviderName, "error", err)
|
||||
}
|
||||
}
|
||||
}(ldapCfg)
|
||||
@@ -443,7 +443,7 @@ func (m Manager) runLdapSynchronizationService(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (m Manager) synchronizeLdapUsers(ctx context.Context, provider *config.LdapProvider) error {
|
||||
logrus.Tracef("starting to synchronize users for %s", provider.ProviderName)
|
||||
slog.Debug("starting to synchronize users", "provider", provider.ProviderName)
|
||||
|
||||
dn, err := ldap.ParseDN(provider.AdminGroupDN)
|
||||
if err != nil {
|
||||
@@ -462,7 +462,7 @@ func (m Manager) synchronizeLdapUsers(ctx context.Context, provider *config.Ldap
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Tracef("fetched %d raw ldap users from provider %s...", len(rawUsers), provider.ProviderName)
|
||||
slog.Debug("fetched raw ldap users", "count", len(rawUsers), "provider", provider.ProviderName)
|
||||
|
||||
// Update existing LDAP users
|
||||
err = m.updateLdapUsers(ctx, provider, rawUsers, &provider.FieldMap, provider.ParsedAdminGroupDN)
|
||||
@@ -504,7 +504,7 @@ func (m Manager) updateLdapUsers(
|
||||
|
||||
if existingUser == nil {
|
||||
// create new user
|
||||
logrus.Tracef("creating new user %s from provider %s...", user.Identifier, provider.ProviderName)
|
||||
slog.Debug("creating new user from provider", "user", user.Identifier, "provider", provider.ProviderName)
|
||||
|
||||
err := m.NewUser(tctx, user)
|
||||
if err != nil {
|
||||
@@ -588,7 +588,7 @@ func (m Manager) disableMissingLdapUsers(
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Tracef("user %s is missing in ldap provider %s, disabling", user.Identifier, providerName)
|
||||
slog.Debug("user is missing in ldap provider, disabling", "user", user.Identifier, "provider", providerName)
|
||||
|
||||
now := time.Now()
|
||||
user.Disabled = &now
|
||||
|
@@ -2,11 +2,11 @@ package wireguard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
probing "github.com/prometheus-community/pro-bing"
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
@@ -60,7 +60,7 @@ func (c *StatisticsCollector) startInterfaceDataFetcher(ctx context.Context) {
|
||||
|
||||
go c.collectInterfaceData(ctx)
|
||||
|
||||
logrus.Tracef("started interface data fetcher")
|
||||
slog.Debug("started interface data fetcher")
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
|
||||
@@ -74,14 +74,15 @@ func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
|
||||
case <-ticker.C:
|
||||
interfaces, err := c.db.GetAllInterfaces(ctx)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch all interfaces for data collection: %v", err)
|
||||
slog.Warn("failed to fetch all interfaces for data collection", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, in := range interfaces {
|
||||
physicalInterface, err := c.wg.GetInterface(ctx, in.Identifier)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to load physical interface %s for data collection: %v", in.Identifier, err)
|
||||
slog.Warn("failed to load physical interface for data collection", "interface", in.Identifier,
|
||||
"error", err)
|
||||
continue
|
||||
}
|
||||
err = c.db.UpdateInterfaceStatus(ctx, in.Identifier,
|
||||
@@ -96,9 +97,9 @@ func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
|
||||
return i, nil
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to update interface status for %s: %v", in.Identifier, err)
|
||||
slog.Warn("failed to update interface status", "interface", in.Identifier, "error", err)
|
||||
}
|
||||
logrus.Tracef("updated interface status for %s", in.Identifier)
|
||||
slog.Debug("updated interface status", "interface", in.Identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +112,7 @@ func (c *StatisticsCollector) startPeerDataFetcher(ctx context.Context) {
|
||||
|
||||
go c.collectPeerData(ctx)
|
||||
|
||||
logrus.Tracef("started peer data fetcher")
|
||||
slog.Debug("started peer data fetcher")
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) collectPeerData(ctx context.Context) {
|
||||
@@ -125,14 +126,14 @@ func (c *StatisticsCollector) collectPeerData(ctx context.Context) {
|
||||
case <-ticker.C:
|
||||
interfaces, err := c.db.GetAllInterfaces(ctx)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch all interfaces for peer data collection: %v", err)
|
||||
slog.Warn("failed to fetch all interfaces for peer data collection", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, in := range interfaces {
|
||||
peers, err := c.wg.GetPeers(ctx, in.Identifier)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch peers for data collection (interface %s): %v", in.Identifier, err)
|
||||
slog.Warn("failed to fetch peers for data collection", "interface", in.Identifier, "error", err)
|
||||
continue
|
||||
}
|
||||
for _, peer := range peers {
|
||||
@@ -158,9 +159,9 @@ func (c *StatisticsCollector) collectPeerData(ctx context.Context) {
|
||||
return p, nil
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to update peer status for %s: %v", peer.Identifier, err)
|
||||
slog.Warn("failed to update peer status", "peer", peer.Identifier, "error", err)
|
||||
} else {
|
||||
logrus.Tracef("updated peer status for %s", peer.Identifier)
|
||||
slog.Debug("updated peer status", "peer", peer.Identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,12 +222,12 @@ func (c *StatisticsCollector) startPingWorkers(ctx context.Context) {
|
||||
go func() {
|
||||
c.pingWaitGroup.Wait()
|
||||
|
||||
logrus.Tracef("stopped ping checks")
|
||||
slog.Debug("stopped ping checks")
|
||||
}()
|
||||
|
||||
go c.enqueuePingChecks(ctx)
|
||||
|
||||
logrus.Tracef("started ping checks")
|
||||
slog.Debug("started ping checks")
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) enqueuePingChecks(ctx context.Context) {
|
||||
@@ -242,14 +243,14 @@ func (c *StatisticsCollector) enqueuePingChecks(ctx context.Context) {
|
||||
case <-ticker.C:
|
||||
interfaces, err := c.db.GetAllInterfaces(ctx)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch all interfaces for ping checks: %v", err)
|
||||
slog.Warn("failed to fetch all interfaces for ping checks", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, in := range interfaces {
|
||||
peers, err := c.db.GetInterfacePeers(ctx, in.Identifier)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch peers for ping checks (interface %s): %v", in.Identifier, err)
|
||||
slog.Warn("failed to fetch peers for ping checks", "interface", in.Identifier, "error", err)
|
||||
continue
|
||||
}
|
||||
for _, peer := range peers {
|
||||
@@ -264,7 +265,7 @@ func (c *StatisticsCollector) pingWorker(ctx context.Context) {
|
||||
defer c.pingWaitGroup.Done()
|
||||
for peer := range c.pingJobs {
|
||||
peerPingable := c.isPeerPingable(ctx, peer)
|
||||
logrus.Tracef("peer %s pingable: %t", peer.Identifier, peerPingable)
|
||||
slog.Debug("peer ping check completed", "peer", peer.Identifier, "pingable", peerPingable)
|
||||
|
||||
now := time.Now()
|
||||
err := c.db.UpdatePeerStatus(ctx, peer.Identifier,
|
||||
@@ -283,9 +284,9 @@ func (c *StatisticsCollector) pingWorker(ctx context.Context) {
|
||||
return p, nil
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to update peer ping status for %s: %v", peer.Identifier, err)
|
||||
slog.Warn("failed to update peer ping status", "peer", peer.Identifier, "error", err)
|
||||
} else {
|
||||
logrus.Tracef("updated peer ping status for %s", peer.Identifier)
|
||||
slog.Debug("updated peer ping status", "peer", peer.Identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,7 +303,7 @@ func (c *StatisticsCollector) isPeerPingable(ctx context.Context, peer domain.Pe
|
||||
|
||||
pinger, err := probing.NewPinger(checkAddr)
|
||||
if err != nil {
|
||||
logrus.Tracef("failed to instatiate pinger for %s (%s): %v", peer.Identifier, checkAddr, err)
|
||||
slog.Debug("failed to instantiate pinger", "peer", peer.Identifier, "address", checkAddr, "error", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -312,7 +313,7 @@ func (c *StatisticsCollector) isPeerPingable(ctx context.Context, peer domain.Pe
|
||||
pinger.Timeout = 2 * time.Second
|
||||
err = pinger.RunWithContext(ctx) // Blocks until finished.
|
||||
if err != nil {
|
||||
logrus.Tracef("pinger for peer %s (%s) exited unexpectedly: %v", peer.Identifier, checkAddr, err)
|
||||
slog.Debug("pinger for peer exited unexpectedly", "peer", peer.Identifier, "address", checkAddr, "error", err)
|
||||
return false
|
||||
}
|
||||
stats := pinger.Statistics()
|
||||
@@ -327,7 +328,7 @@ func (c *StatisticsCollector) updatePeerMetrics(ctx context.Context, status doma
|
||||
// Fetch peer data from the database
|
||||
peer, err := c.db.GetPeer(ctx, status.PeerId)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch peer data for metrics %s: %v", status.PeerId, err)
|
||||
slog.Warn("failed to fetch peer data for metrics", "peer", status.PeerId, "error", err)
|
||||
return
|
||||
}
|
||||
c.ms.UpdatePeerMetrics(peer, status)
|
||||
@@ -343,7 +344,7 @@ func (c *StatisticsCollector) handlePeerIdentifierChangeEvent(oldIdentifier, new
|
||||
// remove potential left-over status data
|
||||
err := c.db.DeletePeerStatus(ctx, oldIdentifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to delete old peer status for migrated peer, %s -> %s: %v",
|
||||
oldIdentifier, newIdentifier, err)
|
||||
slog.Error("failed to delete old peer status for migrated peer", "oldIdentifier", oldIdentifier,
|
||||
"newIdentifier", newIdentifier, "error", err)
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@ package wireguard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
evbus "github.com/vardius/message-bus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
@@ -58,12 +58,12 @@ func (m Manager) handleUserCreationEvent(user *domain.User) {
|
||||
return
|
||||
}
|
||||
|
||||
logrus.Tracef("handling new user event for %s", user.Identifier)
|
||||
slog.Debug("handling new user event", "user", user.Identifier)
|
||||
|
||||
ctx := domain.SetUserInfo(context.Background(), domain.SystemAdminContextUserInfo())
|
||||
err := m.CreateDefaultPeer(ctx, user.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to create default peer for %s: %v", user.Identifier, err)
|
||||
slog.Error("failed to create default peer", "user", user.Identifier, "error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,9 @@ func (m Manager) handleUserLoginEvent(userId domain.UserIdentifier) {
|
||||
|
||||
userPeers, err := m.db.GetUserPeers(context.Background(), userId)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to retrieve existing peers for %s prior to default peer creation: %v", userId, err)
|
||||
slog.Error("failed to retrieve existing peers prior to default peer creation",
|
||||
"user", userId,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,12 +85,12 @@ func (m Manager) handleUserLoginEvent(userId domain.UserIdentifier) {
|
||||
return // user already has peers, skip creation
|
||||
}
|
||||
|
||||
logrus.Tracef("handling new user login for %s", userId)
|
||||
slog.Debug("handling new user login", "user", userId)
|
||||
|
||||
ctx := domain.SetUserInfo(context.Background(), domain.SystemAdminContextUserInfo())
|
||||
err = m.CreateDefaultPeer(ctx, userId)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to create default peer for %s: %v", userId, err)
|
||||
slog.Error("failed to create default peer", "user", userId, "error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -97,7 +99,9 @@ func (m Manager) handleUserDisabledEvent(user domain.User) {
|
||||
ctx := domain.SetUserInfo(context.Background(), domain.SystemAdminContextUserInfo())
|
||||
userPeers, err := m.db.GetUserPeers(ctx, user.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to retrieve peers for disabled user %s: %v", user.Identifier, err)
|
||||
slog.Error("failed to retrieve peers for disabled user",
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,15 +110,19 @@ func (m Manager) handleUserDisabledEvent(user domain.User) {
|
||||
continue // peer is already disabled
|
||||
}
|
||||
|
||||
logrus.Debugf("disabling peer %s due to user %s being disabled", peer.Identifier, user.Identifier)
|
||||
slog.Debug("disabling peer due to user being disabled",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier)
|
||||
|
||||
peer.Disabled = user.Disabled // set to user disabled timestamp
|
||||
peer.DisabledReason = domain.DisabledReasonUserDisabled
|
||||
|
||||
_, err := m.UpdatePeer(ctx, &peer)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to disable peer %s for disabled user %s: %v",
|
||||
peer.Identifier, user.Identifier, err)
|
||||
slog.Error("failed to disable peer for disabled user",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +135,9 @@ func (m Manager) handleUserEnabledEvent(user domain.User) {
|
||||
ctx := domain.SetUserInfo(context.Background(), domain.SystemAdminContextUserInfo())
|
||||
userPeers, err := m.db.GetUserPeers(ctx, user.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to retrieve peers for re-enabled user %s: %v", user.Identifier, err)
|
||||
slog.Error("failed to retrieve peers for re-enabled user",
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -140,15 +150,19 @@ func (m Manager) handleUserEnabledEvent(user domain.User) {
|
||||
continue // peer was disabled for another reason
|
||||
}
|
||||
|
||||
logrus.Debugf("enabling peer %s due to user %s being enabled", peer.Identifier, user.Identifier)
|
||||
slog.Debug("enabling peer due to user being enabled",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier)
|
||||
|
||||
peer.Disabled = nil
|
||||
peer.DisabledReason = ""
|
||||
|
||||
_, err := m.UpdatePeer(ctx, &peer)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to enable peer %s for enabled user %s: %v",
|
||||
peer.Identifier, user.Identifier, err)
|
||||
slog.Error("failed to enable peer for enabled user",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -158,7 +172,9 @@ func (m Manager) handleUserDeletedEvent(user domain.User) {
|
||||
ctx := domain.SetUserInfo(context.Background(), domain.SystemAdminContextUserInfo())
|
||||
userPeers, err := m.db.GetUserPeers(ctx, user.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to retrieve peers for deleted user %s: %v", user.Identifier, err)
|
||||
slog.Error("failed to retrieve peers for deleted user",
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,14 +185,20 @@ func (m Manager) handleUserDeletedEvent(user domain.User) {
|
||||
}
|
||||
|
||||
if m.cfg.Core.DeletePeerAfterUserDeleted {
|
||||
logrus.Debugf("deleting peer %s due to user %s being deleted", peer.Identifier, user.Identifier)
|
||||
slog.Debug("deleting peer due to user being deleted",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier)
|
||||
|
||||
if err := m.DeletePeer(ctx, peer.Identifier); err != nil {
|
||||
logrus.Errorf("failed to delete peer %s for deleted user %s: %v",
|
||||
peer.Identifier, user.Identifier, err)
|
||||
slog.Error("failed to delete peer for deleted user",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
} else {
|
||||
logrus.Debugf("disabling peer %s due to user %s being deleted", peer.Identifier, user.Identifier)
|
||||
slog.Debug("disabling peer due to user being deleted",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier)
|
||||
|
||||
peer.UserIdentifier = "" // remove user reference
|
||||
peer.Disabled = &deletionTime
|
||||
@@ -184,8 +206,10 @@ func (m Manager) handleUserDeletedEvent(user domain.User) {
|
||||
|
||||
_, err := m.UpdatePeer(ctx, &peer)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to disable peer %s for deleted user %s: %v",
|
||||
peer.Identifier, user.Identifier, err)
|
||||
slog.Error("failed to disable peer for deleted user",
|
||||
"peer", peer.Identifier,
|
||||
"user", user.Identifier,
|
||||
"error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,14 +230,16 @@ func (m Manager) runExpiredPeersCheck(ctx context.Context) {
|
||||
|
||||
interfaces, err := m.db.GetAllInterfaces(ctx)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to fetch all interfaces for expiry check: %v", err)
|
||||
slog.Error("failed to fetch all interfaces for expiry check", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, iface := range interfaces {
|
||||
peers, err := m.db.GetInterfacePeers(ctx, iface.Identifier)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to fetch all peers from interface %s for expiry check: %v", iface.Identifier, err)
|
||||
slog.Error("failed to fetch all peers from interface for expiry check",
|
||||
"interface", iface.Identifier,
|
||||
"error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -227,14 +253,14 @@ func (m Manager) checkExpiredPeers(ctx context.Context, peers []domain.Peer) {
|
||||
|
||||
for _, peer := range peers {
|
||||
if peer.IsExpired() && !peer.IsDisabled() {
|
||||
logrus.Infof("peer %s has expired, disabling...", peer.Identifier)
|
||||
slog.Info("peer has expired, disabling", "peer", peer.Identifier)
|
||||
|
||||
peer.Disabled = &now
|
||||
peer.DisabledReason = domain.DisabledReasonExpired
|
||||
|
||||
_, err := m.UpdatePeer(ctx, &peer)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to update expired peer %s: %v", peer.Identifier, err)
|
||||
slog.Error("failed to update expired peer", "peer", peer.Identifier, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
)
|
||||
@@ -130,7 +129,7 @@ func (m Manager) ImportNewInterfaces(ctx context.Context, filter ...domain.Inter
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Infof("importing new interface %s...", physicalInterface.Identifier)
|
||||
slog.Info("importing new interface", "interface", physicalInterface.Identifier)
|
||||
|
||||
physicalPeers, err := m.wg.GetPeers(ctx, physicalInterface.Identifier)
|
||||
if err != nil {
|
||||
@@ -142,7 +141,7 @@ func (m Manager) ImportNewInterfaces(ctx context.Context, filter ...domain.Inter
|
||||
return 0, fmt.Errorf("import of %s failed: %w", physicalInterface.Identifier, err)
|
||||
}
|
||||
|
||||
logrus.Infof("imported new interface %s and %d peers", physicalInterface.Identifier, len(physicalPeers))
|
||||
slog.Info("imported new interface", "interface", physicalInterface.Identifier, "peers", len(physicalPeers))
|
||||
imported++
|
||||
}
|
||||
|
||||
@@ -206,7 +205,7 @@ func (m Manager) RestoreInterfaceState(
|
||||
|
||||
_, err = m.wg.GetInterface(ctx, iface.Identifier)
|
||||
if err != nil && !iface.IsDisabled() {
|
||||
logrus.Debugf("creating missing interface %s...", iface.Identifier)
|
||||
slog.Debug("creating missing interface", "interface", iface.Identifier)
|
||||
|
||||
// try to create a new interface
|
||||
_, err = m.saveInterface(ctx, &iface)
|
||||
@@ -224,7 +223,7 @@ func (m Manager) RestoreInterfaceState(
|
||||
return fmt.Errorf("failed to create physical interface %s: %w", iface.Identifier, err)
|
||||
}
|
||||
} else {
|
||||
logrus.Debugf("restoring interface state for %s to disabled=%t", iface.Identifier, iface.IsDisabled())
|
||||
slog.Debug("restoring interface state", "interface", iface.Identifier, "disabled", iface.IsDisabled())
|
||||
|
||||
// try to move interface to stored state
|
||||
_, err = m.saveInterface(ctx, &iface)
|
||||
|
@@ -4,10 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal/app"
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
)
|
||||
@@ -49,7 +48,9 @@ func (m Manager) CreateDefaultPeer(ctx context.Context, userId domain.UserIdenti
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Infof("created %d default peers for user %s", len(newPeers), userId)
|
||||
slog.InfoContext(ctx, "created default peers for user",
|
||||
"user", userId,
|
||||
"count", len(newPeers))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user