Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package plus
import (
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
plusutils "github.com/TeaOSLab/EdgePlus/pkg/utils"
"github.com/iwind/TeaGo/lists"
"net"
"sync"
)
// 已经开通的组件
var plusLocker = sync.Mutex{}
var plusComponents = []string{}
var PlusEdition = ""
// UpdateComponents 修改开通的组件
func UpdateComponents(edition string, components []string) {
plusLocker.Lock()
PlusEdition = edition
plusComponents = components
plusLocker.Unlock()
}
// AllowComponent 检查是否允许使用某个组件
func AllowComponent(component ComponentCode) bool {
if !teaconst.IsPlus {
return false
}
// 允许不指定组件表示只要是plus用户就可以
if len(component) == 0 {
return true
}
plusLocker.Lock()
defer plusLocker.Unlock()
if len(plusComponents) == 0 {
return false
}
for _, c := range plusComponents {
if c == "*" || c == component {
// 如果不是最新版本的授权,则忽略一些权限
if c == "*" && (len(PlusEdition) == 0 || plusutils.CompareEdition(PlusEdition, plusutils.EditionPro) < 0) && component == ComponentCodeAntiDDoS {
continue
}
return true
}
}
return false
}
// ValidateMac 校验MAC地址
func ValidateMac(mac string) bool {
if len(mac) == 0 || mac == "*" {
return true
}
for _, addr := range FindAllMacAddresses() {
if addr == mac {
return true
}
}
return false
}
// FindAllMacAddresses 获取MAC地址
func FindAllMacAddresses() []string {
var macAddresses = []string{}
interfaces, _ := net.Interfaces()
for _, i := range interfaces {
var addr = i.HardwareAddr.String()
if len(addr) == 0 {
continue
}
if lists.ContainsString(macAddresses, addr) {
continue
}
if i.Flags&net.FlagLoopback == 1 {
continue
}
if i.Flags&net.FlagUp == 0 {
continue
}
ipAddrs, _ := i.Addrs()
if len(ipAddrs) == 0 {
continue
}
macAddresses = append(macAddresses, addr)
}
return macAddresses
}