Browse Source

feat: Trojan config build for xray-core

master
dnomd343 2 years ago
parent
commit
e4ab4ce9ce
  1. 21
      Builder/Trojan.py
  2. 1
      Builder/VLESS.py
  3. 2
      Builder/Xray.py
  4. 4
      Builder/__init__.py
  5. 20
      demo.py

21
Builder/Trojan.py

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from Builder import Xray
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
outboundConfig = {
'protocol': 'trojan',
'settings': {
'servers': [{**{
'address': proxyInfo['server'],
'port': proxyInfo['port'],
'password': proxyInfo['passwd'],
}, **Xray.xtlsFlow(proxyInfo['stream'])}]
},
'streamSettings': Xray.loadStream(proxyInfo['stream'])
}
trojanConfig = Xray.loadConfig(socksInfo, outboundConfig) # load config file for xray-core
return ['xray', '-c', configFile], json.dumps(trojanConfig), {}

1
Builder/VLESS.py

@ -4,6 +4,7 @@
import json
from Builder import Xray
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
outboundConfig = {
'protocol': 'vless',

2
Builder/Xray.py

@ -61,7 +61,7 @@ def loadStream(streamInfo: dict) -> dict:
def xtlsFlow(streamInfo: dict or None) -> dict:
if streamInfo['secure'] is not None: # without TLS / XTLS options
if streamInfo['secure'] is None: # without TLS / XTLS options
return {}
if streamInfo['secure']['type'] != 'xtls': # not XTLS secure type
return {}

4
Builder/__init__.py

@ -6,6 +6,7 @@ import copy
from Builder import VMess
from Builder import VLESS
from Builder import Trojan
from Builder import Shadowsocks
from Builder import ShadowsocksR
@ -18,7 +19,8 @@ clientEntry = {
'ss': [Shadowsocks.load, '.json'],
'ssr': [ShadowsocksR.load, '.json'],
'vmess': [VMess.load, '.json'],
'vless': [VLESS.load, '.json']
'vless': [VLESS.load, '.json'],
'trojan': [Trojan.load, '.json'],
}

20
demo.py

@ -46,7 +46,6 @@ proxyVLESS = {
'port': 12345,
'method': 'none',
'id': '614d3a56-8a04-4c65-88a2-45896f0bd13c',
'aid': 0,
'stream': {
'type': 'tcp',
'obfs': None,
@ -61,10 +60,27 @@ proxyVLESS = {
}
}
proxyTrojan = {
'server': '127.0.0.1',
'port': 12345,
'passwd': 'dnomd343',
'stream': {
'type': 'tcp',
'obfs': None,
'secure': {
'type': 'tls',
'sni': '343.re',
'alpn': None,
'verify': True,
},
}
}
# client = Builder('ss', proxySS)
# client = Builder('ssr', proxySSR)
# client = Builder('vmess', proxyVMess)
client = Builder('vless', proxyVLESS)
# client = Builder('vless', proxyVLESS)
client = Builder('trojan', proxyTrojan)
logging.critical(client.id)
logging.critical(client.proxyType)

Loading…
Cancel
Save