mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-21 18:29:13 +03:00
mitm: Refactor & Add url
This commit is contained in:
@@ -17,11 +17,22 @@ type TLSDecryptionOptions struct {
|
||||
}
|
||||
|
||||
type MITMRouteOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Print bool `json:"print,omitempty"`
|
||||
Script badoption.Listable[string] `json:"script,omitempty"`
|
||||
SurgeURLRewrite badoption.Listable[SurgeURLRewriteLine] `json:"sg_url_rewrite,omitempty"`
|
||||
SurgeHeaderRewrite badoption.Listable[SurgeHeaderRewriteLine] `json:"sg_header_rewrite,omitempty"`
|
||||
SurgeBodyRewrite badoption.Listable[SurgeBodyRewriteLine] `json:"sg_body_rewrite,omitempty"`
|
||||
SurgeMapLocal badoption.Listable[SurgeMapLocalLine] `json:"sg_map_local,omitempty"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Print bool `json:"print,omitempty"`
|
||||
Script badoption.Listable[MITMRouteSurgeScriptOptions] `json:"sg_script,omitempty"`
|
||||
SurgeURLRewrite badoption.Listable[SurgeURLRewriteLine] `json:"sg_url_rewrite,omitempty"`
|
||||
SurgeHeaderRewrite badoption.Listable[SurgeHeaderRewriteLine] `json:"sg_header_rewrite,omitempty"`
|
||||
SurgeBodyRewrite badoption.Listable[SurgeBodyRewriteLine] `json:"sg_body_rewrite,omitempty"`
|
||||
SurgeMapLocal badoption.Listable[SurgeMapLocalLine] `json:"sg_map_local,omitempty"`
|
||||
}
|
||||
|
||||
type MITMRouteSurgeScriptOptions struct {
|
||||
Tag string `json:"tag"`
|
||||
Type badoption.Listable[string] `json:"type"`
|
||||
Pattern badoption.Listable[*badoption.Regexp] `json:"pattern"`
|
||||
Timeout badoption.Duration `json:"timeout,omitempty"`
|
||||
RequiresBody bool `json:"requires_body,omitempty"`
|
||||
MaxSize int64 `json:"max_size,omitempty"`
|
||||
BinaryBodyMode bool `json:"binary_body_mode,omitempty"`
|
||||
Arguments badoption.Listable[string] `json:"arguments,omitempty"`
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ type ScriptSourceOptions _ScriptSourceOptions
|
||||
func (o ScriptSourceOptions) MarshalJSON() ([]byte, error) {
|
||||
var source any
|
||||
switch o.Source {
|
||||
case C.ScriptSourceLocal:
|
||||
case C.ScriptSourceTypeLocal:
|
||||
source = o.LocalOptions
|
||||
case C.ScriptSourceRemote:
|
||||
case C.ScriptSourceTypeRemote:
|
||||
source = o.RemoteOptions
|
||||
default:
|
||||
return nil, E.New("unknown script source: ", o.Source)
|
||||
@@ -46,9 +46,9 @@ func (o *ScriptSourceOptions) UnmarshalJSON(bytes []byte) error {
|
||||
}
|
||||
var source any
|
||||
switch o.Source {
|
||||
case C.ScriptSourceLocal:
|
||||
case C.ScriptSourceTypeLocal:
|
||||
source = &o.LocalOptions
|
||||
case C.ScriptSourceRemote:
|
||||
case C.ScriptSourceTypeRemote:
|
||||
source = &o.RemoteOptions
|
||||
default:
|
||||
return E.New("unknown script source: ", o.Source)
|
||||
@@ -75,12 +75,9 @@ func (s *Script) UnmarshalJSON(bytes []byte) error {
|
||||
}
|
||||
|
||||
type _ScriptOptions struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag"`
|
||||
Timeout badoption.Duration `json:"timeout,omitempty"`
|
||||
Arguments []any `json:"arguments,omitempty"`
|
||||
HTTPOptions HTTPScriptOptions `json:"-"`
|
||||
CronOptions CronScriptOptions `json:"-"`
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag"`
|
||||
SurgeOptions SurgeScriptOptions `json:"-"`
|
||||
}
|
||||
|
||||
type ScriptOptions _ScriptOptions
|
||||
@@ -88,12 +85,8 @@ type ScriptOptions _ScriptOptions
|
||||
func (o ScriptOptions) MarshalJSON() ([]byte, error) {
|
||||
var v any
|
||||
switch o.Type {
|
||||
case C.ScriptTypeSurgeGeneric:
|
||||
v = nil
|
||||
case C.ScriptTypeSurgeHTTPRequest, C.ScriptTypeSurgeHTTPResponse:
|
||||
v = o.HTTPOptions
|
||||
case C.ScriptTypeSurgeCron:
|
||||
v = o.CronOptions
|
||||
case C.ScriptTypeSurge:
|
||||
v = &o.SurgeOptions
|
||||
default:
|
||||
return nil, E.New("unknown script type: ", o.Type)
|
||||
}
|
||||
@@ -110,12 +103,10 @@ func (o *ScriptOptions) UnmarshalJSON(bytes []byte) error {
|
||||
}
|
||||
var v any
|
||||
switch o.Type {
|
||||
case C.ScriptTypeSurgeGeneric:
|
||||
v = nil
|
||||
case C.ScriptTypeSurgeHTTPRequest, C.ScriptTypeSurgeHTTPResponse:
|
||||
v = &o.HTTPOptions
|
||||
case C.ScriptTypeSurgeCron:
|
||||
v = &o.CronOptions
|
||||
case C.ScriptTypeSurge:
|
||||
v = &o.SurgeOptions
|
||||
case "":
|
||||
return E.New("missing script type")
|
||||
default:
|
||||
return E.New("unknown script type: ", o.Type)
|
||||
}
|
||||
@@ -126,13 +117,12 @@ func (o *ScriptOptions) UnmarshalJSON(bytes []byte) error {
|
||||
return badjson.UnmarshallExcluded(bytes, (*_ScriptOptions)(o), v)
|
||||
}
|
||||
|
||||
type HTTPScriptOptions struct {
|
||||
Pattern string `json:"pattern"`
|
||||
RequiresBody bool `json:"requires_body,omitempty"`
|
||||
MaxSize int64 `json:"max_size,omitempty"`
|
||||
BinaryBodyMode bool `json:"binary_body_mode,omitempty"`
|
||||
type SurgeScriptOptions struct {
|
||||
CronOptions *CronScriptOptions `json:"cron,omitempty"`
|
||||
}
|
||||
|
||||
type CronScriptOptions struct {
|
||||
Expression string `json:"expression"`
|
||||
Expression string `json:"expression"`
|
||||
Arguments []string `json:"arguments,omitempty"`
|
||||
Timeout badoption.Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user