mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2026-04-12 14:16:57 +08:00
Reworked QX producer
This commit is contained in:
@@ -1,115 +1,21 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
import { Result } from './utils';
|
||||
const targetPlatform = 'QX';
|
||||
|
||||
export default function QX_Producer() {
|
||||
const targetPlatform = 'QX';
|
||||
const produce = (proxy) => {
|
||||
let obfs_opts;
|
||||
let tls_opts;
|
||||
switch (proxy.type) {
|
||||
case 'ss':
|
||||
obfs_opts = '';
|
||||
if (proxy.plugin === 'obfs') {
|
||||
const { host, mode } = proxy['plugin-opts'];
|
||||
obfs_opts = `,obfs=${mode}${
|
||||
host ? ',obfs-host=' + host : ''
|
||||
}`;
|
||||
}
|
||||
if (proxy.plugin === 'v2ray-plugin') {
|
||||
const { tls, host, path } = proxy['plugin-opts'];
|
||||
obfs_opts = `,obfs=${tls ? 'wss' : 'ws'}${
|
||||
host ? ',obfs-host=' + host : ''
|
||||
}${path ? ',obfs-uri=' + path : ''}`;
|
||||
}
|
||||
return `shadowsocks=${proxy.server}:${proxy.port},method=${
|
||||
proxy.cipher
|
||||
},password=${proxy.password}${obfs_opts}${
|
||||
proxy.tfo ? ',fast-open=true' : ',fast-open=false'
|
||||
}${proxy.udp ? ',udp-relay=true' : ',udp-relay=false'},tag=${
|
||||
proxy.name
|
||||
}`;
|
||||
return shadowsocks(proxy);
|
||||
case 'ssr':
|
||||
return `shadowsocks=${proxy.server}:${proxy.port},method=${
|
||||
proxy.cipher
|
||||
},password=${proxy.password},ssr-protocol=${proxy.protocol}${
|
||||
proxy['protocol-param']
|
||||
? ',ssr-protocol-param=' + proxy['protocol-param']
|
||||
: ''
|
||||
}${proxy.obfs ? ',obfs=' + proxy.obfs : ''}${
|
||||
proxy['obfs-param']
|
||||
? ',obfs-host=' + proxy['obfs-param']
|
||||
: ''
|
||||
},fast-open=${proxy.tfo || false}${
|
||||
proxy.udp ? ',udp-relay=true' : ',udp-relay=false'
|
||||
},tag=${proxy.name}`;
|
||||
case 'vmess':
|
||||
obfs_opts = '';
|
||||
if (proxy.network === 'ws') {
|
||||
// websocket
|
||||
if (proxy.tls) {
|
||||
// ws-tls
|
||||
obfs_opts = `,obfs=wss${
|
||||
proxy.sni ? ',obfs-host=' + proxy.sni : ''
|
||||
}${
|
||||
proxy['ws-opts'].path
|
||||
? ',obfs-uri=' + proxy['ws-opts'].path
|
||||
: ''
|
||||
},tls-verification=${
|
||||
proxy['skip-cert-verify'] ? 'false' : 'true'
|
||||
}`;
|
||||
} else {
|
||||
// ws
|
||||
obfs_opts = `,obfs=ws${
|
||||
proxy['ws-opts'].headers.Host
|
||||
? ',obfs-host=' + proxy['ws-opts'].headers.Host
|
||||
: ''
|
||||
}${
|
||||
proxy['ws-opts'].path
|
||||
? ',obfs-uri=' + proxy['ws-opts'].path
|
||||
: ''
|
||||
}`;
|
||||
}
|
||||
} else {
|
||||
// tcp
|
||||
if (proxy.tls) {
|
||||
obfs_opts = `,obfs=over-tls${
|
||||
proxy.sni ? ',obfs-host=' + proxy.sni : ''
|
||||
},tls-verification=${
|
||||
proxy['skip-cert-verify'] ? 'false' : 'true'
|
||||
}`;
|
||||
}
|
||||
}
|
||||
let result = `vmess=${proxy.server}:${proxy.port},method=${
|
||||
proxy.cipher === 'auto' ? 'none' : proxy.cipher
|
||||
},password=${proxy.uuid}${obfs_opts},fast-open=${
|
||||
proxy.tfo || false
|
||||
}${proxy.udp ? ',udp-relay=true' : ',udp-relay=false'}`;
|
||||
if (proxy.alterId === 0) proxy['vmess-aead'] = true;
|
||||
if (typeof proxy['vmess-aead'] !== 'undefined') {
|
||||
result += `,aead=${proxy['vmess-aead']}`;
|
||||
}
|
||||
result += `,tag=${proxy.name}`;
|
||||
return result;
|
||||
return shadowsocksr(proxy);
|
||||
case 'trojan':
|
||||
return `trojan=${proxy.server}:${proxy.port},password=${
|
||||
proxy.password
|
||||
}${
|
||||
proxy.sni ? ',tls-host=' + proxy.sni : ''
|
||||
},over-tls=true,tls-verification=${
|
||||
proxy['skip-cert-verify'] ? 'false' : 'true'
|
||||
},fast-open=${proxy.tfo || false}${
|
||||
proxy.udp ? ',udp-relay=true' : ',udp-relay=false'
|
||||
},tag=${proxy.name}`;
|
||||
return trojan(proxy);
|
||||
case 'vmess':
|
||||
return vmess(proxy);
|
||||
case 'http':
|
||||
tls_opts = '';
|
||||
if (proxy.tls) {
|
||||
tls_opts = `,over-tls=true,tls-verification=${
|
||||
proxy['skip-cert-verify'] ? 'false' : 'true'
|
||||
}${proxy.sni ? ',tls-host=' + proxy.sni : ''}`;
|
||||
}
|
||||
return `http=${proxy.server}:${proxy.port},username=${
|
||||
proxy.username
|
||||
},password=${proxy.password}${tls_opts},fast-open=${
|
||||
proxy.tfo || false
|
||||
},tag=${proxy.name}`;
|
||||
return http(proxy);
|
||||
case 'socks5':
|
||||
return socks5(proxy);
|
||||
}
|
||||
throw new Error(
|
||||
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`,
|
||||
@@ -117,3 +23,241 @@ export default function QX_Producer() {
|
||||
};
|
||||
return { produce };
|
||||
}
|
||||
|
||||
function shadowsocks(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`shadowsocks=${proxy.server}:${proxy.port}`);
|
||||
append(`,method=${proxy.cipher}`);
|
||||
append(`,password=${proxy.password}`);
|
||||
|
||||
// obfs
|
||||
if (proxy.plugin) {
|
||||
if (proxy.plugin === 'obfs') {
|
||||
const opts = proxy['plugin-opts'];
|
||||
append(`,obfs=${opts.mode}`);
|
||||
} else if (
|
||||
proxy.plugin === 'v2ray-plugin' &&
|
||||
proxy['plugin-opts'].mode === 'websocket'
|
||||
) {
|
||||
const opts = proxy['plugin-opts'];
|
||||
if (opts.tls) append(`,obfs=wss`);
|
||||
else append(`,obfs=ws`);
|
||||
}
|
||||
appendIfPresent(
|
||||
`,obfs-host=${proxy['plugin-opts'].host}`,
|
||||
'plugin-opts.host',
|
||||
);
|
||||
appendIfPresent(
|
||||
`,obfs-uri=${proxy['plugin-opts'].path}`,
|
||||
'plugin-opts.path',
|
||||
);
|
||||
}
|
||||
|
||||
// tls verification
|
||||
appendIfPresent(
|
||||
`,tls-verification=${!proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function shadowsocksr(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`shadowsocksr=${proxy.server}:${proxy.port}`);
|
||||
append(`,method=${proxy.cipher}`);
|
||||
append(`,password=${proxy.password}`);
|
||||
|
||||
// ssr protocol
|
||||
append(`,ssr-protocol=${proxy.protocol}`);
|
||||
appendIfPresent(
|
||||
`,ssr-proctol-param=${proxy['proctol-param']}`,
|
||||
'proctol-param',
|
||||
);
|
||||
|
||||
// obfs
|
||||
appendIfPresent(`,obfs=${proxy.obfs}`, 'obfs');
|
||||
appendIfPresent(`,obfs-host=${proxy['obfs-param']}`, 'obfs-param');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function trojan(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`trojan=${proxy.server}:${proxy.port}`);
|
||||
append(`,password=${proxy.password}`);
|
||||
|
||||
// obfs ws
|
||||
if (proxy.network === 'ws') {
|
||||
if (proxy.tls) append(`,obfs=wss`);
|
||||
else append(`,obfs=ws`);
|
||||
appendIfPresent(`,obfs-uri=${proxy['ws-opts'].path}`, 'ws-opts.path');
|
||||
appendIfPresent(
|
||||
`,obfs-host=${proxy['ws-opts'].headers.Host}`,
|
||||
'ws-opts.headers.Host',
|
||||
);
|
||||
}
|
||||
|
||||
// tls
|
||||
appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
|
||||
// tls verification
|
||||
appendIfPresent(
|
||||
`,tls-verification=${!proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function vmess(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`vmess=${proxy.server}:${proxy.port}`);
|
||||
append(`,method=${proxy.cipher}`);
|
||||
append(`,password=${proxy.uuid}`);
|
||||
|
||||
// obfs
|
||||
if (proxy.network === 'ws') {
|
||||
if (proxy.tls) append(`,obfs=wss`);
|
||||
else append(`,obfs=ws`);
|
||||
appendIfPresent(`,obfs-uri=${proxy['ws-opts'].path}`, 'ws-opts.path');
|
||||
appendIfPresent(
|
||||
`,obfs-host=${proxy['ws-opts'].headers.Host}`,
|
||||
'ws-opts.headers.Host',
|
||||
);
|
||||
} else if (proxy.network === 'http') {
|
||||
append(`,obfs=http`);
|
||||
appendIfPresent(
|
||||
`,obfs-uri=${proxy['http-opts'].path}`,
|
||||
'http-opts.path',
|
||||
);
|
||||
appendIfPresent(
|
||||
`,obfs-host=${proxy['http-opts'].headers.Host}`,
|
||||
'http-opts.headers.Host',
|
||||
);
|
||||
}
|
||||
|
||||
// tls verification
|
||||
appendIfPresent(
|
||||
`,tls-verification=${!proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
|
||||
// AEAD
|
||||
appendIfPresent(`,aead=${proxy.alterId === 0}`, 'alterId');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function http(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`http=${proxy.server}:${proxy.port}`);
|
||||
appendIfPresent(`,username=${proxy.username}`, 'username');
|
||||
appendIfPresent(`,password=${proxy.password}`, 'password');
|
||||
|
||||
// tls
|
||||
appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
|
||||
// tls verification
|
||||
appendIfPresent(
|
||||
`,tls-verification=${!proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function socks5(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
const appendIfPresent = result.appendIfPresent.bind(result);
|
||||
|
||||
append(`socks5=${proxy.server}:${proxy.port}`);
|
||||
appendIfPresent(`,username=${proxy.username}`, 'username');
|
||||
appendIfPresent(`,password=${proxy.password}`, 'password');
|
||||
|
||||
// tls
|
||||
appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
|
||||
// tls verification
|
||||
appendIfPresent(
|
||||
`,tls-verification=${!proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
|
||||
// tfo
|
||||
appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo');
|
||||
|
||||
// udp
|
||||
appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
|
||||
// tag
|
||||
append(`,tag=${proxy.name}`);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
22
backend/src/core/proxy-utils/producers/utils.js
Normal file
22
backend/src/core/proxy-utils/producers/utils.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export class Result {
|
||||
constructor(proxy) {
|
||||
this.proxy = proxy;
|
||||
this.output = [];
|
||||
}
|
||||
|
||||
append(data) {
|
||||
this.output.push(data);
|
||||
}
|
||||
|
||||
appendIfPresent(data, attr) {
|
||||
if (typeof _.get(this.proxy, attr) !== 'undefined') {
|
||||
this.append(data);
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.output.join('');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user