diff --git a/Filter/Shadowsocks.py b/Filter/Shadowsocks.py index 9b44301..a8001e7 100644 --- a/Filter/Shadowsocks.py +++ b/Filter/Shadowsocks.py @@ -36,6 +36,6 @@ ssObject = rulesFilter({ 'default': None, 'allowNone': True, 'type': pluginObject, - 'errMsg': 'Invalid pluginObject' + 'errMsg': 'Invalid plugin options' } }) diff --git a/Filter/TrojanGo.py b/Filter/TrojanGo.py new file mode 100644 index 0000000..123b4f4 --- /dev/null +++ b/Filter/TrojanGo.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from Basis.Filter import rulesFilter +from Filter.Plugin import pluginObject +from Basis.Constant import trojanGoMethods +from Basis.Functions import isHost, isPort +from Basis.Functions import toInt, toStr, toStrTidy, toBool + +ssObject = rulesFilter({ + 'method': { + 'optional': True, + 'default': 'aes-128-gcm', + 'type': str, + 'format': lambda s: toStrTidy(s).replace('_', '-'), + 'filter': lambda s: s in trojanGoMethods, + 'errMsg': 'Unknown Shadowsocks method' + }, + 'passwd': { + 'optional': True, + 'default': '', + 'type': str, + 'format': toStr, + 'errMsg': 'Invalid Shadowsocks password' + } +}) + +wsObject = rulesFilter({ + 'host': { + 'optional': True, + 'default': '', + 'type': str, + 'format': toStrTidy, + 'errMsg': 'Invalid WebSocket host' + }, + 'path': { + 'optional': True, + 'default': '/', + 'type': str, + 'format': lambda s: toStr(s).strip(), + 'errMsg': 'Invalid WebSocket path' + } +}) + +trojanGoObject = rulesFilter({ + 'server': { + 'type': str, + 'format': toStrTidy, + 'filter': isHost, + 'errMsg': 'Invalid server address' + }, + 'port': { + 'type': int, + 'format': toInt, + 'filter': isPort, + 'errMsg': 'Invalid port number' + }, + 'passwd': { + 'type': str, + 'format': toStr, + 'errMsg': 'Invalid password content' + }, + 'sni': { + 'optional': True, + 'default': '', + 'type': str, + 'format': toStrTidy, + 'errMsg': 'Invalid SNI content' + }, + 'alpn': { + 'optional': True, + 'default': None, + 'allowNone': True, + 'type': str, + 'format': lambda s: toStrTidy(s).replace(' ', ''), # remove space + 'filter': lambda s: s in ['h2', 'http/1.1', 'h2,http/1.1'], + 'errMsg': 'Invalid alpn option' + }, + 'verify': { + 'optional': True, + 'default': True, + 'type': bool, + 'format': toBool, + 'errMsg': 'Invalid verify option' + }, + 'ws': { + 'optional': True, + 'default': None, + 'allowNone': True, + 'type': wsObject, + 'errMsg': 'Invalid WebSocket options' + }, + 'ss': { + 'optional': True, + 'default': None, + 'allowNone': True, + 'type': ssObject, + 'errMsg': 'Invalid Shadowsocks options' + }, + 'plugin': { + 'optional': True, + 'default': None, + 'allowNone': True, + 'type': pluginObject, + 'errMsg': 'Invalid plugin options' + } +}) diff --git a/demo.py b/demo.py index 43d0124..0b3d3d0 100755 --- a/demo.py +++ b/demo.py @@ -8,12 +8,14 @@ from Filter.ShadowsocksR import ssrObject from Filter.VMess import vmessObject from Filter.VLESS import vlessObject from Filter.Trojan import trojanObject +from Filter.TrojanGo import trojanGoObject # pprint(ssObject, sort_dicts = False) # pprint(ssrObject, sort_dicts = False) # pprint(vmessObject, sort_dicts = False) # pprint(vlessObject, sort_dicts = False) # pprint(trojanObject, sort_dicts = False) +# pprint(trojanGoObject, sort_dicts = False) # pprint(filterObject, sort_dicts = False) ssProxy = { @@ -103,9 +105,31 @@ trojanProxy = { } } +trojanGoProxy = { + 'server': '1.1.1.1', + 'port': 12345, + 'passwd': 'dnomd343', + 'sni': '343.re', + 'alpn': ' h2', + 'verify': 'FALSE', + 'ws': { + 'host': 'dnomd343.top', + 'path': '/test', + }, + 'ss': { + 'method': 'chacha20-ietf-poly1305', + 'passwd': 'dnomd343', + }, + 'plugin': { + 'type': 'go-quiet', + 'param': 123 + } +} + # ret = Filter(ssProxy, ssObject) # ret = Filter(ssrProxy, ssrObject) # ret = Filter(vmessProxy, vmessObject) # ret = Filter(vlessProxy, vlessObject) -ret = Filter(trojanProxy, trojanObject) +# ret = Filter(trojanProxy, trojanObject) +ret = Filter(trojanGoProxy, trojanGoObject) pprint(ret, sort_dicts = False)