mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Fix string type
This commit is contained in:
@@ -1,114 +0,0 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing-box/schema"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/json"
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
type OnDemandOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Rules []OnDemandRule `json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
type OnDemandRule struct {
|
||||
Action *OnDemandRuleAction `json:"action,omitempty"`
|
||||
DNSSearchDomainMatch badoption.Listable[string] `json:"dns_search_domain_match,omitempty"`
|
||||
DNSServerAddressMatch badoption.Listable[string] `json:"dns_server_address_match,omitempty"`
|
||||
InterfaceTypeMatch *OnDemandRuleInterfaceType `json:"interface_type_match,omitempty"`
|
||||
SSIDMatch badoption.Listable[string] `json:"ssid_match,omitempty"`
|
||||
ProbeURL string `json:"probe_url,omitempty"`
|
||||
}
|
||||
|
||||
type OnDemandRuleAction int
|
||||
|
||||
func (r *OnDemandRuleAction) MarshalJSON() ([]byte, error) {
|
||||
if r == nil {
|
||||
return nil, nil
|
||||
}
|
||||
value := *r
|
||||
var actionName string
|
||||
switch value {
|
||||
case 1:
|
||||
actionName = "connect"
|
||||
case 2:
|
||||
actionName = "disconnect"
|
||||
case 3:
|
||||
actionName = "evaluate_connection"
|
||||
default:
|
||||
return nil, E.New("unknown action: ", value)
|
||||
}
|
||||
return json.Marshal(actionName)
|
||||
}
|
||||
|
||||
func (r *OnDemandRuleAction) UnmarshalJSON(bytes []byte) error {
|
||||
var actionName string
|
||||
if err := json.Unmarshal(bytes, &actionName); err != nil {
|
||||
return err
|
||||
}
|
||||
var actionValue int
|
||||
switch actionName {
|
||||
case "connect":
|
||||
actionValue = 1
|
||||
case "disconnect":
|
||||
actionValue = 2
|
||||
case "evaluate_connection":
|
||||
actionValue = 3
|
||||
case "ignore":
|
||||
actionValue = 4
|
||||
default:
|
||||
return E.New("unknown action name: ", actionName)
|
||||
}
|
||||
*r = OnDemandRuleAction(actionValue)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r OnDemandRuleAction) DescribeSchema(builder schema.Builder) (*schema.Node, error) {
|
||||
return schema.StringEnum("connect", "disconnect", "evaluate_connection", "ignore"), nil
|
||||
}
|
||||
|
||||
type OnDemandRuleInterfaceType int
|
||||
|
||||
func (r *OnDemandRuleInterfaceType) MarshalJSON() ([]byte, error) {
|
||||
if r == nil {
|
||||
return nil, nil
|
||||
}
|
||||
value := *r
|
||||
var interfaceTypeName string
|
||||
switch value {
|
||||
case 1:
|
||||
interfaceTypeName = "any"
|
||||
case 2:
|
||||
interfaceTypeName = "wifi"
|
||||
case 3:
|
||||
interfaceTypeName = "cellular"
|
||||
default:
|
||||
return nil, E.New("unknown interface type: ", value)
|
||||
}
|
||||
return json.Marshal(interfaceTypeName)
|
||||
}
|
||||
|
||||
func (r *OnDemandRuleInterfaceType) UnmarshalJSON(bytes []byte) error {
|
||||
var interfaceTypeName string
|
||||
if err := json.Unmarshal(bytes, &interfaceTypeName); err != nil {
|
||||
return err
|
||||
}
|
||||
var interfaceTypeValue int
|
||||
switch interfaceTypeName {
|
||||
case "any":
|
||||
interfaceTypeValue = 1
|
||||
case "wifi":
|
||||
interfaceTypeValue = 2
|
||||
case "cellular":
|
||||
interfaceTypeValue = 3
|
||||
default:
|
||||
return E.New("unknown interface type name: ", interfaceTypeName)
|
||||
}
|
||||
*r = OnDemandRuleInterfaceType(interfaceTypeValue)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r OnDemandRuleInterfaceType) DescribeSchema(builder schema.Builder) (*schema.Node, error) {
|
||||
return schema.StringEnum("any", "wifi", "cellular"), nil
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func NewCertificateProvider(ctx context.Context, logger log.ContextLogger, tag s
|
||||
case option.ACMEKeyTypeRSA4096:
|
||||
keyType = certmagic.RSA4096
|
||||
default:
|
||||
return nil, E.New("unsupported ACME key type: ", options.KeyType)
|
||||
return nil, E.New("unsupported ACME key type: ", string(options.KeyType))
|
||||
}
|
||||
config.KeySource = certmagic.StandardKeyGenerator{KeyType: keyType}
|
||||
}
|
||||
@@ -231,13 +231,13 @@ func newDNSSolver(dnsOptions *option.ACMEProviderDNS01ChallengeOptions, logger *
|
||||
return nil, nil
|
||||
}
|
||||
if dnsOptions.TTL < 0 {
|
||||
return nil, E.New("invalid ACME DNS01 ttl: ", dnsOptions.TTL)
|
||||
return nil, E.New("invalid ACME DNS01 ttl: ", dnsOptions.TTL.Build())
|
||||
}
|
||||
if dnsOptions.PropagationDelay < 0 {
|
||||
return nil, E.New("invalid ACME DNS01 propagation_delay: ", dnsOptions.PropagationDelay)
|
||||
return nil, E.New("invalid ACME DNS01 propagation_delay: ", dnsOptions.PropagationDelay.Build())
|
||||
}
|
||||
if dnsOptions.PropagationTimeout < -1 {
|
||||
return nil, E.New("invalid ACME DNS01 propagation_timeout: ", dnsOptions.PropagationTimeout)
|
||||
return nil, E.New("invalid ACME DNS01 propagation_timeout: ", dnsOptions.PropagationTimeout.Build())
|
||||
}
|
||||
solver := &certmagic.DNS01Solver{
|
||||
DNSManager: certmagic.DNSManager{
|
||||
|
||||
@@ -338,7 +338,7 @@ func (s *Service) requestCertificate(ctx context.Context) ([]byte, []byte, *tls.
|
||||
}
|
||||
privateKey = ecKey
|
||||
default:
|
||||
return nil, nil, nil, nil, E.New("unsupported Cloudflare Origin CA request type: ", s.requestType)
|
||||
return nil, nil, nil, nil, E.New("unsupported Cloudflare Origin CA request type: ", string(s.requestType))
|
||||
}
|
||||
privateKeyDER, err := x509.MarshalPKCS8PrivateKey(privateKey)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user