This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
215 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,80 @@ | ||
import YAML from 'yaml' | ||
import { ProxyServer, ShadowsocksProxyServer, ShadowsocksRProxyServer, VmessProxyServer } from "../ProxyServer" | ||
|
||
const PossibleKeys = ['proxies', 'Proxies', 'proxy', 'Proxy'] | ||
|
||
export default function GetProxyListFromClash(content: string): ProxyServer[] { | ||
const data = YAML.parse(content) | ||
let dataList = [] | ||
for (const key of PossibleKeys) { | ||
if (Array.isArray(data[key])) { | ||
dataList = data[key] | ||
break | ||
} | ||
} | ||
if (!dataList.length) { | ||
throw new Error('cannot find proxy list.') | ||
} | ||
return dataList.map((config: any) => { | ||
if (config.type === 'vmess') { | ||
const proxy: VmessProxyServer = { | ||
Cipher: config.cipher || 'auto', | ||
ClientAlterID: config.alterId || 0, | ||
ClientID: config.uuid, | ||
Name: config.name, | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
SupportUDP: config.udp, | ||
Transport: config.network || 'tcp', | ||
TransportSecurity: config.tls ? 'tls' : 'none', | ||
Type: 'vmess', | ||
} | ||
if (proxy.Transport === 'ws' && config['ws-path']) { | ||
proxy.WebSocketPath = config['ws-path'] | ||
} | ||
if (proxy.Transport === 'ws' && config['ws-headers']) { | ||
proxy.WebSocketHost = config['ws-headers']?.Host ?? config['ws-headers']?.host | ||
} | ||
return proxy | ||
} else if (config.type === 'ss') { | ||
const proxy: ShadowsocksProxyServer = { | ||
Cipher: config.cipher, | ||
Name: config.name, | ||
Password: config.password, | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
Type: 'ss', | ||
} | ||
return proxy | ||
} else if (config.type === 'ssr') { | ||
const proxy: ShadowsocksRProxyServer = { | ||
Cipher: config.cipher, | ||
Name: config.name, | ||
Obfs: config.obfs, | ||
ObfsParams: config['obfs-param'], | ||
Password: config.password, | ||
Protocol: config.protocol, | ||
ProtocolParams: config['protocol-param'], | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
SupportUDP: config.udp, | ||
Type: 'ssr', | ||
} | ||
return proxy | ||
} else { | ||
throw new Error(`unknown type: ${config.type}`) | ||
} | ||
}) | ||
} | ||
import YAML from 'yaml' | ||
import { ProxyServer, ShadowsocksProxyServer, ShadowsocksRProxyServer, TrojanProxyServer, VmessProxyServer } from "../ProxyServer" | ||
|
||
const PossibleKeys = ['proxies', 'Proxies', 'proxy', 'Proxy'] | ||
|
||
export default function GetProxyListFromClash(content: string): ProxyServer[] { | ||
const data = YAML.parse(content) | ||
let dataList = [] | ||
for (const key of PossibleKeys) { | ||
if (Array.isArray(data[key])) { | ||
dataList = data[key] | ||
break | ||
} | ||
} | ||
if (!dataList.length) { | ||
throw new Error('cannot find proxy list.') | ||
} | ||
return dataList.map((config: any) => { | ||
if (config.type === 'vmess') { | ||
const proxy: VmessProxyServer = { | ||
Cipher: config.cipher || 'auto', | ||
ClientAlterID: config.alterId || 0, | ||
ClientID: config.uuid, | ||
Name: config.name, | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
SupportUDP: config.udp, | ||
Transport: config.network || 'tcp', | ||
TransportSecurity: config.tls ? 'tls' : 'none', | ||
Type: 'vmess', | ||
} | ||
if (proxy.Transport === 'ws' && config['ws-path']) { | ||
proxy.WebSocketPath = config['ws-path'] | ||
} | ||
if (proxy.Transport === 'ws' && config['ws-headers']) { | ||
proxy.WebSocketHost = config['ws-headers']?.Host ?? config['ws-headers']?.host | ||
} | ||
return proxy | ||
} else if (config.type === 'ss') { | ||
const proxy: ShadowsocksProxyServer = { | ||
Cipher: config.cipher, | ||
Name: config.name, | ||
Password: config.password, | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
Type: 'ss', | ||
} | ||
return proxy | ||
} else if (config.type === 'ssr') { | ||
const proxy: ShadowsocksRProxyServer = { | ||
Cipher: config.cipher, | ||
Name: config.name, | ||
Obfs: config.obfs, | ||
ObfsParams: config['obfs-param'], | ||
Password: config.password, | ||
Protocol: config.protocol, | ||
ProtocolParams: config['protocol-param'], | ||
ServerAddress: config.server, | ||
ServerPort: config.port, | ||
SupportUDP: config.udp, | ||
Type: 'ssr', | ||
} | ||
return proxy | ||
} else if (config.type === 'trojan') { | ||
const proxy: TrojanProxyServer = { | ||
AllowInsecure: config['skip-cert-verify'], | ||
Name: config.name, | ||
Password: config.password, | ||
ServerAddress: config.server, | ||
ServerName: config.sni, | ||
ServerPort: config.port, | ||
SupportUDP: config.udp, | ||
Type: 'trojan', | ||
} | ||
return proxy | ||
} else { | ||
throw new Error(`unknown type: ${config.type}`) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
import { ProxyServer, ShadowsocksProxyServer, VmessProxyServer } from '../ProxyServer' | ||
|
||
export default function FormatProxyForSurge(ProxyList: ProxyServer[]): string { | ||
let result: string[] = [] | ||
for (let proxy of ProxyList) { | ||
let row: string[] = [] | ||
if (proxy.Type === 'vmess') { | ||
proxy = proxy as VmessProxyServer | ||
row.push(`${proxy.Name} = vmess`) | ||
row.push(proxy.ServerAddress) | ||
row.push(`${proxy.ServerPort}`) | ||
row.push(proxy.ClientID) | ||
if (proxy.Cipher !== "auto") { | ||
row.push(`encrypt-method=${proxy.Cipher}`) | ||
} | ||
if (proxy.TransportSecurity === 'tls') { | ||
row.push('tls=true') | ||
} | ||
if (proxy.Transport === 'ws') { | ||
row.push('ws=true') | ||
} else if (proxy.Transport !== 'tcp') { | ||
console.warn(`${proxy.Transport} is not supported in surge`) | ||
continue | ||
} | ||
if (proxy.Transport === 'ws' && proxy.WebSocketPath) { | ||
row.push(`ws-path=${encodeURI(proxy.WebSocketPath)}`) | ||
} | ||
if (proxy.Transport === 'ws' && proxy.WebSocketHost) { | ||
row.push(`ws-headers=host:${JSON.stringify(proxy.WebSocketHost)}`) | ||
} | ||
} else if (proxy.Type === 'ss') { | ||
proxy = proxy as ShadowsocksProxyServer | ||
row.push(`${proxy.Name} = ss`) | ||
row.push(proxy.ServerAddress) | ||
row.push(`${proxy.ServerPort}`) | ||
row.push(`encrypt-method=${proxy.Cipher}`) | ||
row.push(`password=${proxy.Password}`) | ||
} else { | ||
throw new Error(`unknown type: ${proxy.Type}`) | ||
} | ||
result.push(row.join(', ')) | ||
} | ||
return result.join('\n') | ||
} | ||
import { ProxyServer, ShadowsocksProxyServer, TrojanProxyServer, VmessProxyServer } from '../ProxyServer' | ||
|
||
export default function FormatProxyForSurge(ProxyList: ProxyServer[]): string { | ||
let result: string[] = [] | ||
for (let proxy of ProxyList) { | ||
let row: string[] = [] | ||
if (proxy.Type === 'vmess') { | ||
proxy = proxy as VmessProxyServer | ||
row.push(`${proxy.Name} = vmess`) | ||
row.push(proxy.ServerAddress) | ||
row.push(`${proxy.ServerPort}`) | ||
row.push(proxy.ClientID) | ||
if (proxy.Cipher !== "auto") { | ||
row.push(`encrypt-method=${proxy.Cipher}`) | ||
} | ||
if (proxy.TransportSecurity === 'tls') { | ||
row.push('tls=true') | ||
} | ||
if (proxy.Transport === 'ws') { | ||
row.push('ws=true') | ||
} else if (proxy.Transport !== 'tcp') { | ||
console.warn(`${proxy.Transport} is not supported in surge`) | ||
continue | ||
} | ||
if (proxy.Transport === 'ws' && proxy.WebSocketPath) { | ||
row.push(`ws-path=${encodeURI(proxy.WebSocketPath)}`) | ||
} | ||
if (proxy.Transport === 'ws' && proxy.WebSocketHost) { | ||
row.push(`ws-headers=host:${JSON.stringify(proxy.WebSocketHost)}`) | ||
} | ||
} else if (proxy.Type === 'ss') { | ||
proxy = proxy as ShadowsocksProxyServer | ||
row.push(`${proxy.Name} = ss`) | ||
row.push(proxy.ServerAddress) | ||
row.push(`${proxy.ServerPort}`) | ||
row.push(`encrypt-method=${proxy.Cipher}`) | ||
row.push(`password=${proxy.Password}`) | ||
} else if (proxy.Type === 'trojan') { | ||
proxy = proxy as TrojanProxyServer | ||
row.push(`${proxy.Name} = trojan`) | ||
row.push(proxy.ServerAddress) | ||
row.push(`${proxy.ServerPort}`) | ||
row.push(`password=${proxy.Password}`) | ||
if (proxy.ServerName) { | ||
row.push(`sni=${proxy.ServerName}`) | ||
} | ||
} else { | ||
throw new Error(`unknown type: ${proxy.Type}`) | ||
} | ||
result.push(row.join(', ')) | ||
} | ||
return result.join('\n') | ||
} |
Oops, something went wrong.