mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-12 05:17:13 +03:00
Compare commits
5 Commits
v1.13.18-e
...
v1.13.18-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8f6936480 | ||
|
|
6126cc2158 | ||
|
|
4926a0cb91 | ||
|
|
f74146648e | ||
|
|
b900e3513c |
@@ -92,6 +92,32 @@ func (api *CloudflareApi) EnrollKey(ctx context.Context, authToken string, id st
|
|||||||
return profile, json.NewDecoder(response.Body).Decode(profile)
|
return profile, json.NewDecoder(response.Body).Decode(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *CloudflareApi) UpdateAccount(ctx context.Context, authToken string, id string, license string) (*Account, error) {
|
||||||
|
data := UpdateAccountRequest{License: license}
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal json: %v", err)
|
||||||
|
}
|
||||||
|
request, err := http.NewRequest("PUT", ApiUrl+"/"+ApiVersion+"/reg/"+id+"/account", bytes.NewBuffer(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for k, v := range Headers {
|
||||||
|
request.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
request.Header.Set("Authorization", "Bearer "+authToken)
|
||||||
|
response, err := api.client.Do(request.WithContext(ctx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
if response.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("failed to update account: %v", response.StatusCode)
|
||||||
|
}
|
||||||
|
account := new(Account)
|
||||||
|
return account, json.NewDecoder(response.Body).Decode(account)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *CloudflareApi) GetProfile(ctx context.Context, authToken string, id string) (*CloudflareProfile, error) {
|
func (api *CloudflareApi) GetProfile(ctx context.Context, authToken string, id string) (*CloudflareProfile, error) {
|
||||||
request, err := http.NewRequest("GET", ApiUrl+"/"+ApiVersion+"/reg/"+id, nil)
|
request, err := http.NewRequest("GET", ApiUrl+"/"+ApiVersion+"/reg/"+id, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ type DeviceUpdate struct {
|
|||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateAccountRequest struct {
|
||||||
|
License string `json:"license"`
|
||||||
|
}
|
||||||
|
|
||||||
type APIError struct {
|
type APIError struct {
|
||||||
Result interface{} `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
"detour": "direct",
|
"detour": "direct",
|
||||||
// For getting existing MASQUE device profile, else sing-box will create new profile
|
// For getting existing MASQUE device profile, else sing-box will create new profile
|
||||||
"id": "",
|
"id": "",
|
||||||
"auth_token": ""
|
"auth_token": "",
|
||||||
|
"license_key": ""
|
||||||
},
|
},
|
||||||
"udp_timeout": "5m0s",
|
"udp_timeout": "5m0s",
|
||||||
"udp_keepalive_period": "30s",
|
"udp_keepalive_period": "30s",
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
"id": "",
|
"id": "",
|
||||||
"private_key": "",
|
"private_key": "",
|
||||||
"auth_token": "",
|
"auth_token": "",
|
||||||
|
"license_key": "",
|
||||||
"recreate": false
|
"recreate": false
|
||||||
}
|
}
|
||||||
// Dial Fields
|
// Dial Fields
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func getGroupDelay(server *Server) func(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(r.Context(), time.Millisecond*time.Duration(timeout))
|
ctx, cancel := context.WithTimeout(server.ctx, time.Millisecond*time.Duration(timeout))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var result map[string]uint16
|
var result map[string]uint16
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ func getProxyDelay(server *Server) func(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
proxy := r.Context().Value(CtxKeyProxy).(adapter.Outbound)
|
proxy := r.Context().Value(CtxKeyProxy).(adapter.Outbound)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout))
|
ctx, cancel := context.WithTimeout(server.ctx, time.Millisecond*time.Duration(timeout))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
delay, err := urltest.URLTest(ctx, url, proxy)
|
delay, err := urltest.URLTest(ctx, url, proxy)
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -246,7 +246,7 @@ require (
|
|||||||
lukechampine.com/blake3 v1.4.1
|
lukechampine.com/blake3 v1.4.1
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/sagernet/wireguard-go => github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.1
|
replace github.com/sagernet/wireguard-go => github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.3
|
||||||
|
|
||||||
replace github.com/sagernet/tailscale => github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2
|
replace github.com/sagernet/tailscale => github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2
|
||||||
|
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -457,8 +457,8 @@ github.com/shtorm-7/sing-vmess v0.2.8-extended-1.0.0 h1:OjvqZOhYSi9eIJGYC0iPDPqv
|
|||||||
github.com/shtorm-7/sing-vmess v0.2.8-extended-1.0.0/go.mod h1:P11scgTxMxVVQ8dlM27yNm3Cro40mD0+gHbnqrNGDuY=
|
github.com/shtorm-7/sing-vmess v0.2.8-extended-1.0.0/go.mod h1:P11scgTxMxVVQ8dlM27yNm3Cro40mD0+gHbnqrNGDuY=
|
||||||
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2 h1:ho7bMq/aUFnNhFbdtrqlW3gyZAsnCtYMXEcyoSNo65Q=
|
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2 h1:ho7bMq/aUFnNhFbdtrqlW3gyZAsnCtYMXEcyoSNo65Q=
|
||||||
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2/go.mod h1:rPn4ZaNbMdbCNBRj3bYCTFCHqB2LcxDgJJrFoaTavTc=
|
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.9-extended-1.0.2/go.mod h1:rPn4ZaNbMdbCNBRj3bYCTFCHqB2LcxDgJJrFoaTavTc=
|
||||||
github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.1 h1:TJ8tinN4A2DRy33RiYiK3ST10Q93O2G/9ZabSUnb2iQ=
|
github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.3 h1:3lUfBaJQnJlhDUUrfBUU/AUy1wlqE6emQLkBUg0+7DI=
|
||||||
github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.1/go.mod h1:1VZmkU7yPAZVE0XKufUqqAhEY1RnWUcyZLmry85y+7A=
|
github.com/shtorm-7/wireguard-go v0.0.4-extended-1.5.3/go.mod h1:1VZmkU7yPAZVE0XKufUqqAhEY1RnWUcyZLmry85y+7A=
|
||||||
github.com/shtorm-7/workerpool v0.5.0 h1:NPZuNgyH0EUm4aQsTL09xR1iV+7GCFw6jX9Z4aAVp2s=
|
github.com/shtorm-7/workerpool v0.5.0 h1:NPZuNgyH0EUm4aQsTL09xR1iV+7GCFw6jX9Z4aAVp2s=
|
||||||
github.com/shtorm-7/workerpool v0.5.0/go.mod h1:NI0pUZgmGu0BdKO9j3mct1DNZmgXbyTS9foorljdH6E=
|
github.com/shtorm-7/workerpool v0.5.0/go.mod h1:NI0pUZgmGu0BdKO9j3mct1DNZmgXbyTS9foorljdH6E=
|
||||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ type CloudflareProfile struct {
|
|||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
AuthToken string `json:"auth_token,omitempty"`
|
AuthToken string `json:"auth_token,omitempty"`
|
||||||
PrivateKey string `json:"private_key,omitempty"`
|
PrivateKey string `json:"private_key,omitempty"`
|
||||||
|
LicenseKey string `json:"license_key,omitempty"`
|
||||||
Recreate bool `json:"recreate,omitempty"`
|
Recreate bool `json:"recreate,omitempty"`
|
||||||
Detour string `json:"detour,omitempty"`
|
Detour string `json:"detour,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,10 @@ func parseVLESSLink(link string) (option.Outbound, error) {
|
|||||||
case "xhttp":
|
case "xhttp":
|
||||||
Transport.Type = C.V2RayTransportTypeXHTTP
|
Transport.Type = C.V2RayTransportTypeXHTTP
|
||||||
if alpn, exists := proxy["alpn"]; exists && alpn != "" {
|
if alpn, exists := proxy["alpn"]; exists && alpn != "" {
|
||||||
TLSOptions.ALPN = []string{alpn}
|
TLSOptions.ALPN = strings.Split(alpn, ",")
|
||||||
|
} else {
|
||||||
|
TLSOptions.ALPN = []string{"h2", "http/1.1"}
|
||||||
}
|
}
|
||||||
TLSOptions.ALPN = []string{"h2", "http/1.1"}
|
|
||||||
if host, exists := proxy["host"]; exists && host != "" {
|
if host, exists := proxy["host"]; exists && host != "" {
|
||||||
Transport.XHTTPOptions.Host = host
|
Transport.XHTTPOptions.Host = host
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,6 +302,11 @@ func (w *Outbound) createConfig() (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if w.options.Profile.LicenseKey != "" && profile.Account.License != w.options.Profile.LicenseKey {
|
||||||
|
if _, err = api.UpdateAccount(w.ctx, profile.Token, profile.ID, w.options.Profile.LicenseKey); err != nil {
|
||||||
|
return nil, E.New("failed to apply license key: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
privateKey, publicKey, err := masque.GenerateEcKeyPair()
|
privateKey, publicKey, err := masque.GenerateEcKeyPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.New("failed to generate key pair: ", err)
|
return nil, E.New("failed to generate key pair: ", err)
|
||||||
|
|||||||
@@ -237,6 +237,11 @@ func (w *Endpoint) createConfig() (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if w.options.Profile.LicenseKey != "" && profile.Account.License != w.options.Profile.LicenseKey {
|
||||||
|
if _, err = api.UpdateAccount(w.ctx, profile.Token, profile.ID, w.options.Profile.LicenseKey); err != nil {
|
||||||
|
return nil, E.New("failed to apply license key: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return &Config{
|
return &Config{
|
||||||
PrivateKey: privateKey.String(),
|
PrivateKey: privateKey.String(),
|
||||||
Interface: profile.Config.Interface,
|
Interface: profile.Config.Interface,
|
||||||
|
|||||||
Reference in New Issue
Block a user