mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 07:11:15 +00:00
chore: cleanup code formatting
This commit is contained in:
@@ -37,15 +37,15 @@ type OauthAuthenticator interface {
|
||||
GetType() AuthenticatorType
|
||||
AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
|
||||
Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
|
||||
GetUserInfo(ctx context.Context, token *oauth2.Token, nonce string) (map[string]interface{}, error)
|
||||
ParseUserInfo(raw map[string]interface{}) (*AuthenticatorUserInfo, error)
|
||||
GetUserInfo(ctx context.Context, token *oauth2.Token, nonce string) (map[string]any, error)
|
||||
ParseUserInfo(raw map[string]any) (*AuthenticatorUserInfo, error)
|
||||
RegistrationEnabled() bool
|
||||
}
|
||||
|
||||
type LdapAuthenticator interface {
|
||||
GetName() string
|
||||
PlaintextAuthentication(userId UserIdentifier, plainPassword string) error
|
||||
GetUserInfo(ctx context.Context, username UserIdentifier) (map[string]interface{}, error)
|
||||
ParseUserInfo(raw map[string]interface{}) (*AuthenticatorUserInfo, error)
|
||||
GetUserInfo(ctx context.Context, username UserIdentifier) (map[string]any, error)
|
||||
ParseUserInfo(raw map[string]any) (*AuthenticatorUserInfo, error)
|
||||
RegistrationEnabled() bool
|
||||
}
|
||||
|
@@ -15,22 +15,25 @@ type BaseModel struct {
|
||||
|
||||
type PrivateString string
|
||||
|
||||
func (PrivateString) MarshalJSON() ([]byte, error) {
|
||||
func (ps *PrivateString) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`""`), nil
|
||||
}
|
||||
|
||||
func (PrivateString) String() string {
|
||||
func (ps *PrivateString) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (ps PrivateString) Value() (driver.Value, error) {
|
||||
if len(ps) == 0 {
|
||||
func (ps *PrivateString) Value() (driver.Value, error) {
|
||||
if ps == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ps), nil
|
||||
if len(*ps) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return string(*ps), nil
|
||||
}
|
||||
|
||||
func (ps *PrivateString) Scan(value interface{}) error {
|
||||
func (ps *PrivateString) Scan(value any) error {
|
||||
if value == nil {
|
||||
*ps = ""
|
||||
return nil
|
||||
|
@@ -4,9 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const CtxUserInfo = "userInfo"
|
||||
|
@@ -54,10 +54,6 @@ func NewPreSharedKey() (PreSharedKey, error) {
|
||||
return PreSharedKey(preSharedKey.String()), nil
|
||||
}
|
||||
|
||||
func KeyBytesToString(key []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(key)
|
||||
}
|
||||
|
||||
func PublicKeyFromPrivateKey(key string) string {
|
||||
privKey, err := wgtypes.ParseKey(key)
|
||||
if err != nil {
|
||||
|
@@ -9,8 +9,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,6 +20,8 @@ const (
|
||||
InterfaceTypeAny InterfaceType = "any"
|
||||
)
|
||||
|
||||
var allowedFileNameRegex = regexp.MustCompile("[^a-zA-Z0-9-_]+")
|
||||
|
||||
type InterfaceIdentifier string
|
||||
type InterfaceType string
|
||||
|
||||
@@ -119,10 +122,8 @@ func (i *Interface) CopyCalculatedAttributes(src *Interface) {
|
||||
}
|
||||
|
||||
func (i *Interface) GetConfigFileName() string {
|
||||
reg := regexp.MustCompile("[^a-zA-Z0-9-_]+")
|
||||
|
||||
filename := internal.TruncateString(string(i.Identifier), 8)
|
||||
filename = reg.ReplaceAllString(filename, "")
|
||||
filename = allowedFileNameRegex.ReplaceAllString(filename, "")
|
||||
filename += ".conf"
|
||||
|
||||
return filename
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"github.com/vishvananda/netlink"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
type Cidr struct {
|
||||
@@ -48,14 +49,6 @@ func CidrsFromString(str string) ([]Cidr, error) {
|
||||
return cidrs, nil
|
||||
}
|
||||
|
||||
func CidrsMust(cidrs []Cidr, err error) []Cidr {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return cidrs
|
||||
}
|
||||
|
||||
func CidrsFromArray(strs []string) ([]Cidr, error) {
|
||||
cidrs := make([]Cidr, len(strs))
|
||||
|
||||
|
@@ -7,9 +7,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
)
|
||||
|
||||
type PeerIdentifier string
|
||||
|
@@ -83,8 +83,7 @@ func (u *User) EditAllowed(new *User) error {
|
||||
}
|
||||
|
||||
// for users which are not database users, only the notes field and the disabled flag can be updated
|
||||
updateOk := true
|
||||
updateOk = updateOk && u.Identifier == new.Identifier
|
||||
updateOk := u.Identifier == new.Identifier
|
||||
updateOk = updateOk && u.Source == new.Source
|
||||
updateOk = updateOk && u.IsAdmin == new.IsAdmin
|
||||
updateOk = updateOk && u.Email == new.Email
|
||||
|
Reference in New Issue
Block a user