Skip to content

Commit

Permalink
refine detect
Browse files Browse the repository at this point in the history
  • Loading branch information
esdeathlove committed May 19, 2017
1 parent 2f3e983 commit 2df1205
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ssserver.log
ssshell.asc
user-config.json
userapiconfig.py
user-detect.html

# Packages
*.egg
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"connect_verbose_info": 0,
"connect_hex_data": 0,
"redirect": "",
"fast_open": false
"fast_open": false,
"friendly_detect": 1
}
1 change: 1 addition & 0 deletions detect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
由于碰撞到了审计规则,您的连接已经被阻断。
27 changes: 27 additions & 0 deletions shadowsocks/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ def find_config():
return config_path
return None

def find_custom_detect():
config_path = 'user-detect.html'
if os.path.exists(config_path):
return config_path
config_path = os.path.join(
os.path.dirname(__file__),
'../',
'user-detect.html')
if os.path.exists(config_path):
return config_path

config_path = 'detect.html'
if os.path.exists(config_path):
return config_path
config_path = os.path.join(os.path.dirname(__file__), '../', 'detect.html')
if os.path.exists(config_path):
return config_path
return None


def check_config(config, is_local):
if config.get('daemon', None) == 'stop':
Expand Down Expand Up @@ -179,6 +198,13 @@ def get_config(is_local):
else:
config = {}

if config.get('friendly_detect', 0):
detect_path = find_custom_detect()
config['detect_block_html'] = ''
with open(detect_path, 'rb') as f:
config['detect_block_html'] = bytes(f.read())


v_count = 0
for key, value in optlist:
if key == '-p':
Expand Down Expand Up @@ -257,6 +283,7 @@ def get_config(is_local):
config['udp_cache'] = int(config.get('udp_cache', 64))
config['fast_open'] = config.get('fast_open', False)
config['workers'] = config.get('workers', 1)
config['friendly_detect'] = config.get('friendly_detect', 0)
config['pid-file'] = config.get('pid-file', '/var/run/shadowsocksr.pid')
config['log-file'] = config.get('log-file', '/var/log/shadowsocksr.log')
config['verbose'] = config.get('verbose', False)
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks/tcprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ def _get_read_size(self, sock, recv_buffer_size, up):
return buffer_size

def _handle_detect_rule_match(self, port):
if port == 80:
backdata = b'HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n由于碰撞到审计规则,连接已经中断。'
if port == 80 and self._config['friendly_detect']:
backdata = b'HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n' + self._config['detect_block_html']
backdata = self._protocol.server_pre_encrypt(backdata)
backdata = self._encryptor.encrypt(backdata)
backdata = self._obfs.server_encode(backdata)
Expand Down

0 comments on commit 2df1205

Please sign in to comment.