Merge branch 'main' of hiddify-github:hiddify/hiddify-next-core
This commit is contained in:
@@ -388,13 +388,13 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
|
|
||||||
var outbounds []option.Outbound
|
var outbounds []option.Outbound
|
||||||
var tags []string
|
var tags []string
|
||||||
if opt.WarpOptions != nil && (opt.WarpOptions.Mode == "proxy_over_warp" || opt.WarpOptions.Mode == "warp_over_proxy") {
|
if opt.Warp.EnableWarp && (opt.Warp.Mode == "proxy_over_warp" || opt.Warp.Mode == "warp_over_proxy") {
|
||||||
out, err := generateWarpSingbox(opt.WarpOptions.WireguardConfig, opt.WarpOptions.CleanIP, opt.WarpOptions.CleanPort, opt.WarpOptions.FakePackets, opt.WarpOptions.FakePacketSize, opt.WarpOptions.FakePacketDelay)
|
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||||
}
|
}
|
||||||
out.Tag = "Hiddify Warp Config"
|
out.Tag = "Hiddify Warp Config"
|
||||||
if opt.WarpOptions.Mode == "warp_over_proxy" {
|
if opt.Warp.Mode == "warp_over_proxy" {
|
||||||
out.WireGuardOptions.Detour = "select"
|
out.WireGuardOptions.Detour = "select"
|
||||||
}
|
}
|
||||||
outbounds = append(outbounds, *out)
|
outbounds = append(outbounds, *out)
|
||||||
@@ -515,7 +515,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||||
if opt.WarpOptions != nil && opt.WarpOptions.Mode == "proxy_over_warp" {
|
if opt.Warp.EnableWarp && opt.Warp.Mode == "proxy_over_warp" {
|
||||||
out.DirectOptions.Detour = "Hiddify Warp Config"
|
out.DirectOptions.Detour = "Hiddify Warp Config"
|
||||||
out.HTTPOptions.Detour = "Hiddify Warp Config"
|
out.HTTPOptions.Detour = "Hiddify Warp Config"
|
||||||
out.Hysteria2Options.Detour = "Hiddify Warp Config"
|
out.Hysteria2Options.Detour = "Hiddify Warp Config"
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bepass-org/wireguard-go/warp"
|
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigOptions struct {
|
type ConfigOptions struct {
|
||||||
LogLevel string `json:"log-level"`
|
LogLevel string `json:"log-level"`
|
||||||
EnableClashApi bool `json:"enable-clash-api"`
|
EnableClashApi bool `json:"enable-clash-api"`
|
||||||
ClashApiPort uint16 `json:"clash-api-port"`
|
ClashApiPort uint16 `json:"clash-api-port"`
|
||||||
GeoIPPath string `json:"geoip-path"`
|
GeoIPPath string `json:"geoip-path"`
|
||||||
GeoSitePath string `json:"geosite-path"`
|
GeoSitePath string `json:"geosite-path"`
|
||||||
Rules []Rule `json:"rules"`
|
Rules []Rule `json:"rules"`
|
||||||
|
Warp WarpOptions `json:"warp"`
|
||||||
DNSOptions
|
DNSOptions
|
||||||
InboundOptions
|
InboundOptions
|
||||||
URLTestOptions
|
URLTestOptions
|
||||||
RouteOptions
|
RouteOptions
|
||||||
MuxOptions
|
MuxOptions
|
||||||
TLSTricks
|
TLSTricks
|
||||||
*WarpOptions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DNSOptions struct {
|
type DNSOptions struct {
|
||||||
@@ -73,14 +72,15 @@ type MuxOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WarpOptions struct {
|
type WarpOptions struct {
|
||||||
Mode string `json:"mode"`
|
EnableWarp bool `json:"enable"`
|
||||||
WarpAccount
|
Mode string `json:"mode"`
|
||||||
warp.WireguardConfig
|
WireguardConfig WarpWireguardConfig `json:"wireguard-config"`
|
||||||
FakePackets string `json:"fake-packets"`
|
FakePackets string `json:"fake-packets"`
|
||||||
FakePacketSize string `json:"fake-packet-size"`
|
FakePacketSize string `json:"fake-packet-size"`
|
||||||
FakePacketDelay string `json:"fake-packet-delay"`
|
FakePacketDelay string `json:"fake-packet-delay"`
|
||||||
CleanIP string `json:"clean-ip"`
|
CleanIP string `json:"clean-ip"`
|
||||||
CleanPort uint16 `json:"clean-port"`
|
CleanPort uint16 `json:"clean-port"`
|
||||||
|
Account WarpAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfigOptions() *ConfigOptions {
|
func DefaultConfigOptions() *ConfigOptions {
|
||||||
|
|||||||
@@ -1,24 +1,59 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/bepass-org/wireguard-go/warp"
|
||||||
|
)
|
||||||
|
|
||||||
type WarpAccount struct {
|
type WarpAccount struct {
|
||||||
AccountID string `json:"account-id"`
|
AccountID string `json:"account-id"`
|
||||||
AccessToken string `json:"access-token"`
|
AccessToken string `json:"access-token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) {
|
type WarpWireguardConfig struct {
|
||||||
data, _, _, err := GenerateWarpInfo(licenseKey, accountId, accessToken)
|
PrivateKey string `json:"private-key"`
|
||||||
if err != nil {
|
LocalAddressIPv4 string `json:"local-address-ipv4"`
|
||||||
return "", err
|
LocalAddressIPv6 string `json:"local-address-ipv6"`
|
||||||
}
|
PeerPublicKey string `json:"peer-public-key"`
|
||||||
warpAccount := WarpAccount{
|
}
|
||||||
AccountID: data.AccountID,
|
|
||||||
AccessToken: data.AccessToken,
|
func (wg WarpWireguardConfig) ToWireguardConfig() warp.WireguardConfig {
|
||||||
}
|
return warp.WireguardConfig{
|
||||||
accountJson, err := json.Marshal(warpAccount)
|
PrivateKey: wg.PrivateKey,
|
||||||
if err != nil {
|
LocalAddressIPv4: wg.LocalAddressIPv4,
|
||||||
return "", err
|
LocalAddressIPv6: wg.LocalAddressIPv6,
|
||||||
}
|
PeerPublicKey: wg.PeerPublicKey,
|
||||||
return string(accountJson), nil
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type WarpGenerationResponse struct {
|
||||||
|
WarpAccount
|
||||||
|
Log string `json:"log"`
|
||||||
|
Config WarpWireguardConfig `json:"config"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) {
|
||||||
|
account, log, wg, err := GenerateWarpInfo(licenseKey, accountId, accessToken)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
warpAccount := WarpAccount{
|
||||||
|
AccountID: account.AccountID,
|
||||||
|
AccessToken: account.AccessToken,
|
||||||
|
}
|
||||||
|
warpConfig := WarpWireguardConfig{
|
||||||
|
PrivateKey: wg.PrivateKey,
|
||||||
|
LocalAddressIPv4: wg.LocalAddressIPv4,
|
||||||
|
LocalAddressIPv6: wg.LocalAddressIPv6,
|
||||||
|
PeerPublicKey: wg.PeerPublicKey,
|
||||||
|
}
|
||||||
|
response := WarpGenerationResponse{warpAccount, log, warpConfig}
|
||||||
|
|
||||||
|
responseJson, err := json.Marshal(response)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(responseJson), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user