type check improve

This commit is contained in:
Shawn
2021-11-01 11:17:22 +08:00
parent 62978a1296
commit 1829384f66
2 changed files with 59 additions and 50 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -1,5 +1,5 @@
/** /**
☑️ 资源解析器 ©𝐒𝐡𝐚𝐰𝐧 ⟦2021-10-22 21:35⟧ ☑️ 资源解析器 ©𝐒𝐡𝐚𝐰𝐧 ⟦2021-11-01 11:15⟧
---------------------------------------------------------- ----------------------------------------------------------
🛠 发现 𝐁𝐔𝐆 请反馈: @ShawnKOP_bot 🛠 发现 𝐁𝐔𝐆 请反馈: @ShawnKOP_bot
⛳️ 关注 🆃🅶 相关频道: https://t.me/QuanX_API ⛳️ 关注 🆃🅶 相关频道: https://t.me/QuanX_API
@@ -123,7 +123,7 @@ const rwrite_link = { "open-url": link1, "media-url": "https://shrtm.nu/x3o2" }
const rwhost_link = { "open-url": link1, "media-url": "https://shrtm.nu/0n5J" } // hostname filter link const rwhost_link = { "open-url": link1, "media-url": "https://shrtm.nu/0n5J" } // hostname filter link
const rule_link = { "open-url": link1, "media-url": "https://shrtm.nu/cpHD" } // rule filter link const rule_link = { "open-url": link1, "media-url": "https://shrtm.nu/cpHD" } // rule filter link
const nan_link = { "open-url": link1, "media-url": qxpng } // nan error link const nan_link = { "open-url": link1, "media-url": qxpng } // nan error link
const bug_link = { "open-url": "https://t.me/Shawn_KOP_bot", "media-url": "https://shrtm.nu/obcB" } // bug link const bug_link = { "open-url": "https://t.me/ShawnKOP_bot", "media-url": "https://shrtm.nu/obcB" } // bug link
const sub_link = { "open-url": link1, "media-url": "https://shrtm.nu/ebAr" } // server link const sub_link = { "open-url": link1, "media-url": "https://shrtm.nu/ebAr" } // server link
@@ -172,7 +172,9 @@ var Pdel = mark0 && para1.indexOf("del=") != -1 ? para1.split("del=")[1].split("
var typeU = para1.indexOf("type=") != -1 ? para1.split("type=")[1].split("&")[0] : ""; var typeU = para1.indexOf("type=") != -1 ? para1.split("type=")[1].split("&")[0] : "";
var Pfcr = para1.indexOf("fcr=") != -1 ? para1.split("fcr=")[1].split("&")[0] : ""; // force-cellular 参数 var Pfcr = para1.indexOf("fcr=") != -1 ? para1.split("fcr=")[1].split("&")[0] : ""; // force-cellular 参数
var typeQ = $resource.type //返回 field 类型参数 var typeQ = $resource.type? $resource.type:"unsupported" //返回 field 类型参数
//花漾字 pattern //花漾字 pattern
var pat=[] var pat=[]
@@ -205,7 +207,8 @@ var flag = 1
function Parser() { function Parser() {
type0 = Type_Check(content0); // 类型判断 type0 = Type_Check(content0); // 类型判断
if (type0 != "web"){ //$notify(type0)
if (type0 != "web" && type0 != "wrong-field"){
try { try {
//$notify(type0,"hh") //$notify(type0,"hh")
if (Pdbg){ if (Pdbg){
@@ -216,6 +219,10 @@ function Parser() {
} catch (err) { } catch (err) {
$notify("❌ 解析出现错误", "⚠️ 请点击发送链接反馈", err, bug_link); $notify("❌ 解析出现错误", "⚠️ 请点击发送链接反馈", err, bug_link);
} }
} else if (type0 == "wrong-field"){
//$notify(type0+"ss")
$notify("❌ 解析类型与目标类型"+" 「"+typeQ+" 」不符", "⚠️ 请自行检查链接内容,或点击通知反馈", $resource.link, bug_link)
total=""
} else { } else {
total="" total=""
} }
@@ -344,6 +351,7 @@ function ResourceParse() {
total = content0 total = content0
$done({ content: content0 }) $done({ content: content0 })
} }
if (Pcnt == 1 && flag !=1) {$notify("解析后最终返回内容" , "总数量: " +total.split("\n").length, total)}
return total return total
} }
@@ -420,37 +428,37 @@ function Type_Check(subs) {
if (subs.indexOf(html) != -1 && link0.indexOf("github.com" == -1)) { if (subs.indexOf(html) != -1 && link0.indexOf("github.com" == -1)) {
$notify("‼️ 该链接返回网页内容,无有效订阅"+ " ➟ " + "⟦" + subtag + "⟧", "⁉️ 点通知跳转以确认链接是否失效\n"+link0, subs, nan_link); $notify("‼️ 该链接返回网页内容,无有效订阅"+ " ➟ " + "⟦" + subtag + "⟧", "⁉️ 点通知跳转以确认链接是否失效\n"+link0, subs, nan_link);
type = "web"; type = "web";
} else if (typeU == "nodes") { } else if (typeU == "nodes" ) {
type = "Subs-B64Encode" type = (typeQ == "unsupported" || typeQ =="server")? "Subs-B64Encode":"wrong-field"
} else if (ClashK.some(NodeCheck) || typeU == "clash"){ // Clash 类型节点转换 } else if (ClashK.some(NodeCheck) || typeU == "clash"){ // Clash 类型节点转换
type = "Clash"; type = (typeQ == "unsupported" || typeQ =="server")? "Clash":"wrong-field";
content0 = Clash2QX(subs) content0 = Clash2QX(subs)
} else if ((/^hostname\s*\=|pattern\=/.test(subi) || RewriteK.some(RewriteCheck)) && !/\[(Proxy|filter_local)\]/.test(subs) && para1.indexOf("dst=filter")==-1 && subi.indexOf("securehostname") == -1 && !/module|nodes|rule/.test(typeU)) { } else if ((/^hostname\s*\=|pattern\=/.test(subi) || RewriteK.some(RewriteCheck)) && !/\[(Proxy|filter_local)\]/.test(subs) && para1.indexOf("dst=filter")==-1 && subi.indexOf("securehostname") == -1 && !/module|nodes|rule/.test(typeU) ) {
type = "rewrite" //Quantumult X 类型 rewrite/ Surge Script/ type = (typeQ == "unsupported" || typeQ =="rewrite")? "rewrite":"wrong-field" //Quantumult X 类型 rewrite/ Surge Script/
} else if ( (((ModuleK.some(RewriteCheck) || para1.indexOf("dst=rewrite") != -1) && (para1.indexOf("dst=filter") == -1) && subs.indexOf("[Proxy]") == -1) || typeU == "module") && typeU != "nodes" && typeU != "rule") { // Surge 类型 module /rule-set(含url-regex) 类型 } else if ( (((ModuleK.some(RewriteCheck) || para1.indexOf("dst=rewrite") != -1) && (para1.indexOf("dst=filter") == -1) && subs.indexOf("[Proxy]") == -1) || typeU == "module") && typeU != "nodes" && typeU != "rule" && typeQ !="filter") { // Surge 类型 module /rule-set(含url-regex) 类型
type = "sgmodule" type = (typeQ == "unsupported" || typeQ =="rewrite")? "sgmodule" : "wrong-field"
} else if (((RuleK.some(RuleCheck) && subs.indexOf(html) == -1 && !/\[(Proxy|server_local)\]/.test(subs)) || typeU == "rule" || para1.indexOf("dst=filter")!=-1) && typeU != "nodes") { } else if (((RuleK.some(RuleCheck) && subs.indexOf(html) == -1 && !/\[(Proxy|server_local)\]/.test(subs)) || typeU == "rule" || para1.indexOf("dst=filter")!=-1) && typeU != "nodes") {
type = "Rule"; type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
} else if ((DomainK.some(RuleCheck) || typeU == "domain-set") && subs.indexOf("[Proxy]") == -1 && typeU != "nodes") { } else if ((DomainK.some(RuleCheck) || typeU == "domain-set") && subs.indexOf("[Proxy]") == -1 && typeU != "nodes") {
type = "Rule"; type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
content0 = Domain2Rule(content0) // 转换 domain-set content0 = Domain2Rule(content0) // 转换 domain-set
} else if (subsn.length >= 1 && SubK2.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) { //未b64加密的多行URI 组合订阅 } else if (subsn.length >= 1 && SubK2.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) { //未b64加密的多行URI 组合订阅
type = "Subs" type = (typeQ == "unsupported" || typeQ =="server"||typeQ =="uri") ? "Subs":"wrong-field"
} else if (SubK.some(NodeCheck)) { //b64加密的订阅类型 } else if (SubK.some(NodeCheck)) { //b64加密的订阅类型
type = "Subs-B64Encode" type = (typeQ == "unsupported" || typeQ =="server")? "Subs-B64Encode":"wrong-field"
} else if ((subi.indexOf("tag=") != -1 && QuanXK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU =="list") { } else if ((subi.indexOf("tag=") != -1 && QuanXK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU =="list") {
type = "Subs" // QuanX list type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field" // QuanX list
} else if (subs.indexOf("[Proxy]") != -1) { } else if (subs.indexOf("[Proxy]") != -1) {
type = "Surge"; // Surge Profiles type = (typeQ == "unsupported" || typeQ =="server")? "Surge":"wrong-field"; // Surge Profiles
content0 = Surge2QX(content0).join("\n"); content0 = Surge2QX(content0).join("\n");
} else if ((SurgeK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU == "list") { } else if ((SurgeK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU == "list") {
type = "Subs" // Surge proxy list type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field" // Surge proxy list
} else if (subs.indexOf("[server_local]") != -1) { } else if (subs.indexOf("[server_local]") != -1) {
//type = "QuanX" // QuanX Profile //type = "QuanX" // QuanX Profile
type = "Subs" type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field"
} else if (content0.indexOf("server") !=-1 && content0.indexOf("server_port") !=-1) { //SIP008 } else if (content0.indexOf("server") !=-1 && content0.indexOf("server_port") !=-1) { //SIP008
//type = "QuanX" //type = "QuanX"
type = "Subs" type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field"
content0 = SIP2QuanX(content0) content0 = SIP2QuanX(content0)
} }
// 用于通知判断类型debug // 用于通知判断类型debug
@@ -930,7 +938,7 @@ function Rule_Handle(subs, Pout, Pin) {
const exclude = (item) => cc.indexOf(item) != -1; // 删除项 const exclude = (item) => cc.indexOf(item) != -1; // 删除项
const RuleCheck = (item) => cc.toLowerCase().indexOf(item) != -1; //无视注释行 const RuleCheck = (item) => cc.toLowerCase().indexOf(item) != -1; //无视注释行
if (Tout.some(exclude) && !RuleK.some(RuleCheck) && RuleK2.some(RuleCheck)) { if (Tout.some(exclude) && !RuleK.some(RuleCheck) && RuleK2.some(RuleCheck)) {
dlist.push("-" + Rule_Policy(cc)) dlist.push("-" + Rule_Policy(cc)) // 注释掉条目
} else if (!RuleK.some(RuleCheck) && cc) { //if Pout.some, 不操作注释项 } else if (!RuleK.some(RuleCheck) && cc) { //if Pout.some, 不操作注释项
dd = Rule_Policy(cc); dd = Rule_Policy(cc);
if (Tin != "" && Tin != null) { if (Tin != "" && Tin != null) {
@@ -1021,7 +1029,7 @@ function Rule_Policy(content) { //增加、替换 policy
nn = "" nn = ""
} else { nn = nn.replace("IP-CIDR6", "ip6-cidr") } } else { nn = nn.replace("IP-CIDR6", "ip6-cidr") }
return nn return nn
} else if (cnt.length == 1 && !RuleK.some(RuleCheck) && cnt[0]!="" && cnt[0].indexOf("payload:")==-1) { // 纯域名/ip 列表 } else if (cnt.length == 1 && !RuleK.some(RuleCheck) && cnt[0]!="" && cnt[0].indexOf("payload:")==-1) { // 纯域名/ip 列表
return rule_list_handle(cnt[0]) return rule_list_handle(cnt[0])
} else { return "" }//if RuleK1 check } else { return "" }//if RuleK1 check
} }
@@ -1032,14 +1040,15 @@ function rule_list_handle(cnt) {
if(cnt.indexOf("::")!=-1 && cnt.indexOf("/")!=-1) { // ip-v6? if(cnt.indexOf("::")!=-1 && cnt.indexOf("/")!=-1) { // ip-v6?
cnt = "ip6-cidr, " + cnt cnt = "ip6-cidr, " + cnt
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
} else if (cnt.split("/").length == 2) {//ip-cid } else if (cnt.split("/").length == 2) {//ip-cidr
cnt = "ip-cidr, " + cnt cnt = "ip-cidr, " + cnt
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
} else if (cnt) { //host - suffix } else if (cnt.indexOf("payload:")==-1) { //host - suffix
cnt = "host-suffix, " + cnt cnt = "host-suffix, " + cnt
cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy cnt = Ppolicy == "Shawn" ? cnt+", Shawn" : cnt+", "+Ppolicy
} }
return cnt} return cnt
}
} }
// Domain-Set // Domain-Set
@@ -1514,30 +1523,30 @@ function SSR2QX(subs, Pudp, Ptfo) {
//Trojan 类型 URI 转换成 QX //Trojan 类型 URI 转换成 QX
function TJ2QX(subs, Pudp, Ptfo, Pcert0, PTls13) { function TJ2QX(subs, Pudp, Ptfo, Pcert0, PTls13) {
var ntrojan = [] var ntrojan = []
var cnt = subs.split("trojan://")[1] var cnt = subs.split("trojan://")[1]
type = "trojan="; type = "trojan=";
if (cnt.indexOf(":443") != -1) { if (cnt.indexOf(":443") != -1) {
ip = cnt.split("@")[1].split(":443")[0] + ":443"; ip = cnt.split("@")[1].split(":443")[0] + ":443";
} else { } else {
ip = cnt.split("@")[1].split("?")[0].split("\n")[0].split("#")[0].trim(); //非 443 端口的奇葩机场? ip = cnt.split("@")[1].split("?")[0].split("\n")[0].split("#")[0].trim(); //非 443 端口的奇葩机场?
} }
pwd = cnt.split("@")[0]? "password=" + decodeURIComponent(cnt.split("@")[0]):""; pwd = cnt.split("@")[0]? "password=" + decodeURIComponent(cnt.split("@")[0]):"";
obfs = "over-tls=true"; obfs = "over-tls=true";
pcert = cnt.indexOf("allowInsecure=0") != -1 ? "tls-verification=true" : "tls-verification=false"; pcert = cnt.indexOf("allowInsecure=0") != -1 ? "tls-verification=true" : "tls-verification=false";
thost = cnt.indexOf("sni=") != -1? "tls-host="+cnt.split("sni=")[1].split(/&|#/)[0]:"" thost = cnt.indexOf("sni=") != -1? "tls-host="+cnt.split("sni=")[1].split(/&|#/)[0]:""
ptls13 = PTls13 == 1 ? "tls13=true" : "tls13=false" ptls13 = PTls13 == 1 ? "tls13=true" : "tls13=false"
if (Pcert0 == 0) { if (Pcert0 == 0) {
pcert = "tls-verification=false" pcert = "tls-verification=false"
} else if (Pcert0 == 1) { } else if (Pcert0 == 1) {
pcert = "tls-verification=true" pcert = "tls-verification=true"
} }
pudp = Pudp == 1 ? "udp-relay=false" : "udp-relay=false"; pudp = Pudp == 1 ? "udp-relay=false" : "udp-relay=false";
ptfo = Ptfo == 1 ? "fast-open=true" : "fast-open=false"; ptfo = Ptfo == 1 ? "fast-open=true" : "fast-open=false";
tag = cnt.indexOf("#") != -1 ? "tag=" + decodeURIComponent(cnt.split("#")[1]) : "tag= [trojan]" + ip tag = cnt.indexOf("#") != -1 ? "tag=" + decodeURIComponent(cnt.split("#")[1]) : "tag= [trojan]" + ip
ntrojan.push(type + ip, pwd, obfs, pcert, thost, ptls13, pudp, ptfo, tag) ntrojan.push(type + ip, pwd, obfs, pcert, thost, ptls13, pudp, ptfo, tag)
QX = ntrojan.filter(Boolean).join(", "); QX = ntrojan.filter(Boolean).join(", ");
return QX; return QX;
} }
//SS 类型 URI 转换 quanx 格式 //SS 类型 URI 转换 quanx 格式