feat(app): add WGRplane web UI and backend features
- Add Vue 3 frontend with glassmorphism design (Tailwind CSS) - Add Go backend handlers: auth, webhooks, stats, scheduler, validation - Add i18n support (EN, ID, ZH) - Add Swagger docs and API handlers - Add nftables integration and plugins support - Remove deprecated go.mod (migrated to wgrplane)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net"
|
||||
)
|
||||
|
||||
// ValidateIP returns true if the input is a valid IPv4 or IPv6 address.
|
||||
func ValidateIP(ip string) bool {
|
||||
if ip == "" {
|
||||
return false
|
||||
}
|
||||
return net.ParseIP(ip) != nil
|
||||
}
|
||||
|
||||
// ValidateCIDR returns true if the input is a valid CIDR notation (e.g., 10.0.0.0/24).
|
||||
func ValidateCIDR(cidr string) bool {
|
||||
if cidr == "" {
|
||||
return false
|
||||
}
|
||||
// net.ParseCIDR validates CIDR; it also returns an IP, which we don't need here.
|
||||
if _, _, err := net.ParseCIDR(cidr); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidatePublicKey returns true if the provided WireGuard public key is a valid base64-encoded 32-byte value.
|
||||
func ValidatePublicKey(key string) bool {
|
||||
if key == "" {
|
||||
return false
|
||||
}
|
||||
// Try to decode as base64 without padding (RawStdEncoding).
|
||||
if b, err := base64.RawStdEncoding.DecodeString(key); err == nil && len(b) == 32 {
|
||||
return true
|
||||
}
|
||||
// Fallback to standard base64 decoding with padding if present.
|
||||
if b, err := base64.StdEncoding.DecodeString(key); err == nil && len(b) == 32 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user