Skip to content

Commit

Permalink
生成的节点中添加订阅地址的域名
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdhs committed Sep 23, 2023
1 parent 7e5c74f commit ddc1fbf
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 75 deletions.
143 changes: 79 additions & 64 deletions frontend.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,79 +36,90 @@
href="https://sing-box.sagernet.org/installation/clients/sfa/">SFA</a>,ios 版本的未测试。</p>
<p>在此页面粘贴由本工具生成的订阅链接(仅参数保存在链接内可用),可解析到下面的选项中</p>
<input placeholder="订阅链接,多个链接使用 | 分割" v-model="sub" />
<input placeholder="url test 中包含的节点名(可用正则)" v-model="include" />
<input placeholder="url test 中排除的节点名(可用正则)" v-model="exclude" />
<div class="grid">
<input placeholder="url test 中包含的节点名(可用正则)" v-model="include" />
<input placeholder="url test 中排除的节点名(可用正则)" v-model="exclude" />
</div>
<label for="switch">
<input type="checkbox" id="switch" name="switch" role="switch" v-model="saveType">
{{ saveTypeText }}
</label>
<label for="addTag">
<input type="checkbox" id="addTag" role="switch" v-model="addTag">
生成的节点中添加订阅地址的域名,用以区分不同订阅的节点
</label>
<br />
<details>
<summary>配置文件模板</summary>
<label>
<input type="checkbox" role="switch" v-model="checkbox">
配置文件模板直链
</label>
<textarea style="resize: none;height: 25em;" v-model="config" v-show="!checkbox"></textarea>
<input v-model="configurl" v-show="checkbox" />
</details>
<details>
<summary>自定义 urltest / selector</summary>
<div class="grid">
<label>
tag
<input type="text" placeholder="xxx分组" v-model.trim="customValue.tag" required>
</label>
<label>
tolerance
<input type="text" placeholder="50" v-model.trim="customValue.tolerance" required>
</label>
<summary>更多设置</summary>
<br />
<details>
<summary>配置文件模板</summary>
<label>
include
<input type="text" placeholder="可用正则" v-model.trim="customValue.include" required>
<input type="checkbox" role="switch" v-model="checkbox">
配置文件模板直链
</label>
<label>
exclude
<input type="text" placeholder="" v-model.trim="customValue.exclude" required>
</label>
<label>
type
<select required v-model="customValue.type">
<option value="urltest" selected>urltest</option>
<option value="selector">selector</option>
</select>
</label>
<label style="display: flex;flex-direction:column-reverse">
<button @click="addUrlTables(customValue)" style="height: min-content;">Add</button>
</label>
</div>
<table role="grid" v-show="customTables.length != 0">
<thead>
<tr>
<th scope="col">tag</th>
<th scope="col">tolerance</th>
<th scope="col">include</th>
<th scope="col">exclude</th>
<th scope="col">type</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr v-for="(v,index) in customTables" :key="index">
<th scope="row">{{ v.tag }}</th>
<td>{{ v.tolerance }}</td>
<td>{{ v.include }}</td>
<td>{{ v.exclude }}</td>
<td>{{ v.type }}</td>
<td>
<button @click="customTables.splice(index,1)" style="height: min-content;">Del</button>
</td>
</tr>
</table>
<textarea style="resize: none;height: 25em;" v-model="config" v-show="!checkbox"></textarea>
<input v-model="configurl" v-show="checkbox" />
</details>
<details>
<summary>自定义 urltest / selector</summary>
<div class="grid">
<label>
tag
<input type="text" placeholder="xxx分组" v-model.trim="customValue.tag" required>
</label>
<label>
tolerance
<input type="text" placeholder="50" v-model.trim="customValue.tolerance" required>
</label>
<label>
include
<input type="text" placeholder="可用正则" v-model.trim="customValue.include" required>
</label>
<label>
exclude
<input type="text" placeholder="" v-model.trim="customValue.exclude" required>
</label>
<label>
type
<select required v-model="customValue.type">
<option value="urltest" selected>urltest</option>
<option value="selector">selector</option>
</select>
</label>
<label style="display: flex;flex-direction:column-reverse">
<button @click="addUrlTables(customValue)" style="height: min-content;">Add</button>
</label>
</div>
<table role="grid" v-show="customTables.length != 0">
<thead>
<tr>
<th scope="col">tag</th>
<th scope="col">tolerance</th>
<th scope="col">include</th>
<th scope="col">exclude</th>
<th scope="col">type</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr v-for="(v,index) in customTables" :key="index">
<th scope="row">{{ v.tag }}</th>
<td>{{ v.tolerance }}</td>
<td>{{ v.include }}</td>
<td>{{ v.exclude }}</td>
<td>{{ v.type }}</td>
<td>
<button @click="customTables.splice(index,1)"
style="height: min-content;">Del</button>
</td>
</tr>
</table>
</details>
</details>
<progress v-show="inFetch"></progress>
<button v-show="!inFetch" @click="click">获取 sing-box 格式订阅链接</button>
<input type="text" ref="inputRef" v-if="newsub" placeholder="可用正则" v-model="newsub">
<input type="text" ref="inputRef" v-if="newsub" placeholder="" v-model="newsub">
</main>
</div>
</body>
Expand All @@ -131,6 +142,7 @@
const customTables = Vue.ref([]);
const inFetch = Vue.ref(false)
const inputRef = Vue.ref(null)
const addTag = Vue.ref(false)

Vue.watch(saveType, v => {
if (v) {
Expand Down Expand Up @@ -175,6 +187,7 @@
configurl.value && subUrl.searchParams.set("configurl", configurl.value)
include.value && subUrl.searchParams.set("include", include.value)
exclude.value && subUrl.searchParams.set("exclude", exclude.value)
addTag.value && subUrl.searchParams.set("addTag", "true")
subUrl.searchParams.set("sub", sub.value)
return subUrl.toString()
}
Expand All @@ -197,6 +210,7 @@
"Config": c,
"ConfigUrl": configurl.value,
"UrlTest": customTables.value,
"AddTag": addTag.value,
})
})).text()
const subUrl = new URL(new URL(location.href).origin)
Expand Down Expand Up @@ -298,7 +312,7 @@
include.value = u.searchParams.get("include") || include.value
exclude.value = u.searchParams.get("exclude") || exclude.value
sub.value = u.searchParams.get("sub") || sub.value

addTag.value = u.searchParams.get("addTag") === "true"
} catch (error) {
console.log(error)
return
Expand All @@ -324,7 +338,8 @@
customTables,
addUrlTables,
inFetch,
inputRef
inputRef,
addTag
}

},
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ module github.com/xmdhs/clash2sfa

go 1.21

toolchain go1.21.0

require (
github.com/samber/lo v1.38.1
github.com/tidwall/gjson v1.16.0
github.com/tidwall/gjson v1.17.0
github.com/tidwall/sjson v1.2.5
github.com/xmdhs/clash2singbox v0.0.0-20230906141725-5eb3ac39d572
github.com/xmdhs/clash2singbox v0.0.0-20230923074746-2ac2b5c4eda1
go.etcd.io/bbolt v1.3.7
lukechampine.com/blake3 v1.2.1
)
Expand Down
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg=
github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/xmdhs/clash2singbox v0.0.0-20230901181217-b2d94de8a5f3 h1:gQqCj8c+rfDzv3veF2lpxYGE3cv3xvhngdR8NBkArEg=
github.com/xmdhs/clash2singbox v0.0.0-20230901181217-b2d94de8a5f3/go.mod h1:LaCPpH9WkYgPzWSd8RIUHC5Mp0LYCV7LDmCx66VM1tE=
github.com/xmdhs/clash2singbox v0.0.0-20230906134934-d5af231d8b31 h1:18Z1g1FCkii18ciYPYbZ8dHjF1ks/uFovENHTL7XzYQ=
github.com/xmdhs/clash2singbox v0.0.0-20230906134934-d5af231d8b31/go.mod h1:LaCPpH9WkYgPzWSd8RIUHC5Mp0LYCV7LDmCx66VM1tE=
github.com/xmdhs/clash2singbox v0.0.0-20230906141725-5eb3ac39d572 h1:YYGsvVa6m0fJVC0TX8sZSyv4vHuonUbEmscrQV0HzcM=
github.com/xmdhs/clash2singbox v0.0.0-20230906141725-5eb3ac39d572/go.mod h1:LaCPpH9WkYgPzWSd8RIUHC5Mp0LYCV7LDmCx66VM1tE=
github.com/xmdhs/clash2singbox v0.0.0-20230923072355-f598ffe75395 h1:TwjDa2fyGgnwW+oPH7+EKdciT4fAMzab+NBuXtMzvPY=
github.com/xmdhs/clash2singbox v0.0.0-20230923072355-f598ffe75395/go.mod h1:s8ADgXev99az3CUg5BfuCx5pyvyUqUlqNfnlIEcMHP4=
github.com/xmdhs/clash2singbox v0.0.0-20230923074208-d4342b538b81 h1:fFVHq9cL7cfuOtfM9+VAh6XjC9vQrQH1Jf1BGxiaPrI=
github.com/xmdhs/clash2singbox v0.0.0-20230923074208-d4342b538b81/go.mod h1:s8ADgXev99az3CUg5BfuCx5pyvyUqUlqNfnlIEcMHP4=
github.com/xmdhs/clash2singbox v0.0.0-20230923074746-2ac2b5c4eda1 h1:hIUgda22rPxvWSWbDStKH1ZGb7ja9z8htkLf3cvmgMI=
github.com/xmdhs/clash2singbox v0.0.0-20230923074746-2ac2b5c4eda1/go.mod h1:s8ADgXev99az3CUg5BfuCx5pyvyUqUlqNfnlIEcMHP4=
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
Expand Down
7 changes: 7 additions & 0 deletions handle/handel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ func Sub(c *http.Client, db db.DB, frontendByte []byte, l *slog.Logger) http.Han
include := r.FormValue("include")
exclude := r.FormValue("exclude")
urltest := r.FormValue("urltest")
addTag := r.FormValue("addTag")
addTagb := false

if id == "" && sub == "" {
l.DebugContext(ctx, "id 不得为空")
http.Error(w, "id 不得为空", 400)
return
}
if addTag == "true" {
addTagb = true
}

rc := http.NewResponseController(w)
rc.SetWriteDeadline(time.Now().Add(1 * time.Minute))
Expand All @@ -87,6 +92,8 @@ func Sub(c *http.Client, db db.DB, frontendByte []byte, l *slog.Logger) http.Han
Exclude: exclude,
Config: config,
ConfigUrl: curl,
AddTag: addTagb,
UrlTest: []model.UrlTestArg{},
}
if urltest != "" {
b, err := zlibDecode(urltest)
Expand Down
1 change: 1 addition & 0 deletions model/arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type ConvertArg struct {
Exclude string
Config string
ConfigUrl string
AddTag bool
UrlTest []UrlTestArg
}

Expand Down
2 changes: 1 addition & 1 deletion service/arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func MakeConfig(cxt context.Context, c *http.Client, frontendByte []byte, l *slo
}
arg.Config = string(b)
}
b, err := convert2sing(cxt, c, arg.Config, arg.Sub, arg.Include, arg.Exclude, l)
b, err := convert2sing(cxt, c, arg.Config, arg.Sub, arg.Include, arg.Exclude, arg.AddTag, l)
if err != nil {
return nil, fmt.Errorf("MakeConfig: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/xmdhs/clash2singbox/httputils"
)

func convert2sing(cxt context.Context, client *http.Client, config, sub string, include, exclude string, l *slog.Logger) ([]byte, error) {
c, err := httputils.GetClash(cxt, client, sub)
func convert2sing(cxt context.Context, client *http.Client, config, sub string, include, exclude string, addTag bool, l *slog.Logger) ([]byte, error) {
c, err := httputils.GetClash(cxt, client, sub, addTag)
if err != nil {
return nil, fmt.Errorf("convert2sing: %w", err)
}
Expand Down

0 comments on commit ddc1fbf

Please sign in to comment.