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 import json
from Builder import Xray from Builder import Xray
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]: def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
outboundConfig = { outboundConfig = {
'protocol': 'vless', 'protocol': 'vless',

2
Builder/Xray.py

@ -61,7 +61,7 @@ def loadStream(streamInfo: dict) -> dict:
def xtlsFlow(streamInfo: dict or None) -> 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 {} return {}
if streamInfo['secure']['type'] != 'xtls': # not XTLS secure type if streamInfo['secure']['type'] != 'xtls': # not XTLS secure type
return {} return {}

4
Builder/__init__.py

@ -6,6 +6,7 @@ import copy
from Builder import VMess from Builder import VMess
from Builder import VLESS from Builder import VLESS
from Builder import Trojan
from Builder import Shadowsocks from Builder import Shadowsocks
from Builder import ShadowsocksR from Builder import ShadowsocksR
@ -18,7 +19,8 @@ clientEntry = {
'ss': [Shadowsocks.load, '.json'], 'ss': [Shadowsocks.load, '.json'],
'ssr': [ShadowsocksR.load, '.json'], 'ssr': [ShadowsocksR.load, '.json'],
'vmess': [VMess.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, 'port': 12345,
'method': 'none', 'method': 'none',
'id': '614d3a56-8a04-4c65-88a2-45896f0bd13c', 'id': '614d3a56-8a04-4c65-88a2-45896f0bd13c',
'aid': 0,
'stream': { 'stream': {
'type': 'tcp', 'type': 'tcp',
'obfs': None, '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('ss', proxySS)
# client = Builder('ssr', proxySSR) # client = Builder('ssr', proxySSR)
# client = Builder('vmess', proxyVMess) # client = Builder('vmess', proxyVMess)
client = Builder('vless', proxyVLESS) # client = Builder('vless', proxyVLESS)
client = Builder('trojan', proxyTrojan)
logging.critical(client.id) logging.critical(client.id)
logging.critical(client.proxyType) logging.critical(client.proxyType)

Loading…
Cancel
Save