mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 22:19:00 +08:00
Fixed Trojan issue
This commit is contained in:
parent
8504738ee1
commit
a0d8e79d3c
@ -59,7 +59,6 @@ $app.route("/api/sub/:name").get(getSub).patch(updateSub).delete(deleteSub);
|
||||
|
||||
$app.route("/api/sub").get(getAllSubs).post(newSub).delete(deleteAllSubs);
|
||||
|
||||
|
||||
// refresh
|
||||
$app.post("/api/refresh", refreshResource);
|
||||
|
||||
@ -85,7 +84,9 @@ $app.start();
|
||||
|
||||
async function IP_API(req, res) {
|
||||
const server = decodeURIComponent(req.params.server);
|
||||
const result = await $.http.get(`http://ip-api.com/json/${server}?lang=zh-CN`).then(resp => JSON.parse(resp.body));
|
||||
const result = await $.http
|
||||
.get(`http://ip-api.com/json/${server}?lang=zh-CN`)
|
||||
.then((resp) => JSON.parse(resp.body));
|
||||
res.json(result);
|
||||
}
|
||||
|
||||
@ -147,7 +148,7 @@ async function downloadSub(req, res) {
|
||||
async function parseSub(sub, platform) {
|
||||
let raw;
|
||||
const key = new Base64Code().safeEncode(sub.url);
|
||||
if (platform === "Raw" || platform === 'URI') {
|
||||
if (platform === "Raw" || platform === "URI") {
|
||||
const cache = $.read(`#${key}`);
|
||||
if (!cache) {
|
||||
raw = await downloadResource(sub.url);
|
||||
@ -239,12 +240,9 @@ async function parseSub(sub, platform) {
|
||||
$filter.setFilter(filter(item.args));
|
||||
}
|
||||
try {
|
||||
|
||||
proxies = $filter.process(proxies);
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Failed to apply filter "${item.type}"!\n REASON: ${err}`
|
||||
);
|
||||
$.error(`Failed to apply filter "${item.type}"!\n REASON: ${err}`);
|
||||
}
|
||||
}
|
||||
} else if (item.type.indexOf("Operator") !== -1) {
|
||||
@ -263,7 +261,7 @@ async function parseSub(sub, platform) {
|
||||
try {
|
||||
proxies = $operator.process(proxies);
|
||||
} catch (err) {
|
||||
`Failed to apply operator "${item.type}"!\n REASON: ${err}`
|
||||
`Failed to apply operator "${item.type}"!\n REASON: ${err}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -275,7 +273,7 @@ async function parseSub(sub, platform) {
|
||||
Loon_Producer,
|
||||
Surge_Producer,
|
||||
Raw_Producer,
|
||||
URI_Producer
|
||||
URI_Producer,
|
||||
]);
|
||||
return $parser.produce(proxies);
|
||||
}
|
||||
@ -601,7 +599,8 @@ function ProxyParser(targetPlatform) {
|
||||
}
|
||||
// skip unsupported proxies
|
||||
// if proxy.supported is undefined, assume that all platforms are supported.
|
||||
if (proxy.supported && proxy.supported[targetPlatform] === false) continue;
|
||||
if (proxy.supported && proxy.supported[targetPlatform] === false)
|
||||
continue;
|
||||
result.push(proxy);
|
||||
break;
|
||||
} catch (err) {
|
||||
@ -634,7 +633,7 @@ function ProxyParser(targetPlatform) {
|
||||
return "";
|
||||
}
|
||||
})
|
||||
.filter(v => v.length > 0) // discard empty lines
|
||||
.filter((v) => v.length > 0) // discard empty lines
|
||||
.join("\n");
|
||||
}
|
||||
}
|
||||
@ -658,15 +657,20 @@ function ProxyParser(targetPlatform) {
|
||||
raw = raw
|
||||
.replace(/ - /g, " - ")
|
||||
.replace(/:(?!\s)/g, ": ")
|
||||
.replace(/\,\"/g, ", \"")
|
||||
.replace(/\,\"/g, ', "')
|
||||
.replace(/: {/g, ": {, ")
|
||||
.replace(/, (host|path|tls|mux|skip)/g, ", $1")
|
||||
.replace(/{name: /g, "{name: \"")
|
||||
.replace(/, server:/g, "\", server:")
|
||||
.replace(/{name: /g, '{name: "')
|
||||
.replace(/, server:/g, '", server:')
|
||||
.replace(/{|}/g, "")
|
||||
.replace(/,/g, "\n ")
|
||||
.replace(/,/g, "\n ");
|
||||
}
|
||||
raw = raw.replace(/ -\n.*name/g, " - name").replace(/\$|\`/g, "").split("proxy-providers:")[0].split("proxy-groups:")[0].replace(/\"(name|type|server|port|cipher|password|)\"/g, "$1")
|
||||
raw = raw
|
||||
.replace(/ -\n.*name/g, " - name")
|
||||
.replace(/\$|\`/g, "")
|
||||
.split("proxy-providers:")[0]
|
||||
.split("proxy-groups:")[0]
|
||||
.replace(/\"(name|type|server|port|cipher|password|)\"/g, "$1");
|
||||
const proxies = YAML.eval(raw).proxies;
|
||||
output = proxies.map((p) => JSON.stringify(p));
|
||||
} else if (raw.indexOf("ssd://") === 0) {
|
||||
@ -693,8 +697,12 @@ function ProxyParser(targetPlatform) {
|
||||
let hostname = server.server;
|
||||
port = server.port ? server.port : port;
|
||||
let tag = server.remarks ? server.remarks : i;
|
||||
let plugin = server.plugin_options ? "/?plugin=" + encodeURIComponent(server.plugin + ";" + server.plugin_options) : ""
|
||||
output[i] = "ss://" + userinfo + "@" + hostname + ":" + port + plugin + "#" + tag
|
||||
let plugin = server.plugin_options
|
||||
? "/?plugin=" +
|
||||
encodeURIComponent(server.plugin + ";" + server.plugin_options)
|
||||
: "";
|
||||
output[i] =
|
||||
"ss://" + userinfo + "@" + hostname + ":" + port + plugin + "#" + tag;
|
||||
}
|
||||
} else {
|
||||
// check if content is based64 encoded
|
||||
@ -836,7 +844,7 @@ function URI_SS() {
|
||||
mode: "websocket",
|
||||
host: params["obfs-host"],
|
||||
path: params.path || "",
|
||||
tls: params.tls
|
||||
tls: params.tls,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
@ -1608,7 +1616,7 @@ function QX_Producer() {
|
||||
case "trojan":
|
||||
return `trojan=${proxy.server}:${proxy.port},password=${
|
||||
proxy.password
|
||||
},tls-host=${proxy.sni},tls-verification=${
|
||||
}${proxy.sni ? ",tls-host=" + proxy.sni : ""},tls-verification=${
|
||||
proxy.scert ? "false" : "true"
|
||||
}${proxy.tfo ? ",fast-open=true" : ",fast-open=false"}${
|
||||
proxy.udp ? ",udp-relay=true" : ",udp-relay=false"
|
||||
@ -1671,7 +1679,11 @@ function Loon_Producer() {
|
||||
proxy.cipher === "auto" ? "none" : proxy.cipher
|
||||
},"${proxy.uuid}",over-tls:${proxy.tls}${obfs_opts}`;
|
||||
case "trojan":
|
||||
return `${proxy.name}=trojan,${proxy.server},${proxy.port},"${proxy.password}",tls-name:${proxy.sni},skip-cert-verify:${proxy.scert}`;
|
||||
return `${proxy.name}=trojan,${proxy.server},${proxy.port},"${
|
||||
proxy.password
|
||||
}"${proxy.sni ? ",tls-name:" + proxy.sni : ""},skip-cert-verify:${
|
||||
proxy.scert || "false"
|
||||
}`;
|
||||
case "http":
|
||||
tls_opts = "";
|
||||
const base = `${proxy.name}=${proxy.tls ? "http" : "https"},${
|
||||
@ -1730,7 +1742,7 @@ function Surge_Producer() {
|
||||
case "trojan":
|
||||
return `${proxy.name}=trojan,${proxy.server},${proxy.port},password=${
|
||||
proxy.password
|
||||
},sni=${proxy.sni},tfo=${proxy.tfo || "false"}`;
|
||||
}${proxy.sni ? ",sni=" + proxy.sni : ""},tfo=${proxy.tfo || "false"}`;
|
||||
case "http":
|
||||
tls_opts = ",tls=false";
|
||||
if (proxy.tls) {
|
||||
@ -1765,29 +1777,49 @@ function URI_Producer() {
|
||||
switch (proxy.type) {
|
||||
case "ss":
|
||||
const userinfo = `${proxy.cipher}:${proxy.password}`;
|
||||
result = `ss://${Base64.safeEncode(userinfo)}@${proxy.server}:${proxy.port}/`;
|
||||
result = `ss://${Base64.safeEncode(userinfo)}@${proxy.server}:${
|
||||
proxy.port
|
||||
}/`;
|
||||
if (proxy.plugin) {
|
||||
result += "?plugin=";
|
||||
const opts = proxy['plugin-opts'];
|
||||
const opts = proxy["plugin-opts"];
|
||||
switch (proxy.plugin) {
|
||||
case "obfs":
|
||||
result += encodeURIComponent(`simple-obfs;obfs=${opts.mode}${opts.host ? ";obfs-host=" + opts.host : ""}`);
|
||||
break
|
||||
result += encodeURIComponent(
|
||||
`simple-obfs;obfs=${opts.mode}${
|
||||
opts.host ? ";obfs-host=" + opts.host : ""
|
||||
}`
|
||||
);
|
||||
break;
|
||||
case "v2ray-plugin":
|
||||
result += encodeURIComponent(`v2ray-plugin;obfs=${opts.mode}${opts.host ? ";obfs-host" + opts.host : ""}${opts.tls ? ";tls" : ""}`);
|
||||
break
|
||||
result += encodeURIComponent(
|
||||
`v2ray-plugin;obfs=${opts.mode}${
|
||||
opts.host ? ";obfs-host" + opts.host : ""
|
||||
}${opts.tls ? ";tls" : ""}`
|
||||
);
|
||||
break;
|
||||
default:
|
||||
console.log(`FUCK`);
|
||||
throw new Error(`Unsupported plugin option: ${proxy.plugin}`);
|
||||
}
|
||||
}
|
||||
result += `#${encodeURIComponent(proxy.name)}`;
|
||||
break
|
||||
break;
|
||||
case "ssr":
|
||||
result = `${proxy.server}:${proxy.port}:${proxy.protocol}:${proxy.cipher}:${proxy.obfs}:${Base64.safeEncode(proxy.password)}/`;
|
||||
result += `?remarks=${proxy.name}${proxy['obfs-param'] ? "&obfsparam=" + Base64.safeEncode(proxy['obfs-param']) : ""}${proxy['protocol-param'] ? "&protocolparam=" + Base64.safeEncode(proxy['protocol-param']) : ""}`;
|
||||
result = `${proxy.server}:${proxy.port}:${proxy.protocol}:${
|
||||
proxy.cipher
|
||||
}:${proxy.obfs}:${Base64.safeEncode(proxy.password)}/`;
|
||||
result += `?remarks=${proxy.name}${
|
||||
proxy["obfs-param"]
|
||||
? "&obfsparam=" + Base64.safeEncode(proxy["obfs-param"])
|
||||
: ""
|
||||
}${
|
||||
proxy["protocol-param"]
|
||||
? "&protocolparam=" + Base64.safeEncode(proxy["protocol-param"])
|
||||
: ""
|
||||
}`;
|
||||
result = "vmess://" + Base64.safeEncode(result);
|
||||
break
|
||||
break;
|
||||
case "vmess":
|
||||
// V2RayN URI format
|
||||
result = {
|
||||
@ -1798,18 +1830,18 @@ function URI_Producer() {
|
||||
type: "",
|
||||
aid: 0,
|
||||
net: proxy.network || "tcp",
|
||||
tls: proxy.tls ? "tls" : ""
|
||||
}
|
||||
tls: proxy.tls ? "tls" : "",
|
||||
};
|
||||
// obfs
|
||||
if (proxy.network === 'ws') {
|
||||
result.path = proxy['ws-path'] || "/";
|
||||
result.host = proxy['ws-headers'].Host || proxy.server;
|
||||
if (proxy.network === "ws") {
|
||||
result.path = proxy["ws-path"] || "/";
|
||||
result.host = proxy["ws-headers"].Host || proxy.server;
|
||||
}
|
||||
result = Base64.safeEncode(JSON.stringify(result));
|
||||
break
|
||||
break;
|
||||
case "trojan":
|
||||
result = `trojan://${proxy.password}@${proxy.server}:${proxy.port}#${proxy.name}`;
|
||||
break
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Cannot handle proxy type: ${proxy.type}`);
|
||||
}
|
||||
@ -2401,16 +2433,16 @@ function HTTP(defaultOptions = {}) {
|
||||
|
||||
function send(method, options) {
|
||||
options = options.hasOwnProperty("url") ? options : { url: options };
|
||||
options.url = defaultOptions.baseURL ? defaultOptions.baseURL + options.url : options.url;
|
||||
options.url = defaultOptions.baseURL
|
||||
? defaultOptions.baseURL + options.url
|
||||
: options.url;
|
||||
options = { ...defaultOptions, ...options };
|
||||
const timeout = options.timeout;
|
||||
const events = {
|
||||
...{
|
||||
onRequest: () => {
|
||||
},
|
||||
onRequest: () => {},
|
||||
onResponse: (resp) => resp,
|
||||
onTimeout: () => {
|
||||
},
|
||||
onTimeout: () => {},
|
||||
},
|
||||
...options.events,
|
||||
};
|
||||
@ -2630,7 +2662,7 @@ function API(name = "untitled", debug = false) {
|
||||
let opts = {};
|
||||
if (openURL) opts["openUrl"] = openURL;
|
||||
if (mediaURL) opts["mediaUrl"] = mediaURL;
|
||||
if (JSON.stringify(opts) === '{}') {
|
||||
if (JSON.stringify(opts) === "{}") {
|
||||
$notification.post(title, subtitle, content);
|
||||
} else {
|
||||
$notification.post(title, subtitle, content, opts);
|
||||
|
2
backend/sub-store.min.js
vendored
2
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user