listen at server; show warnings

This commit is contained in:
clowwindy
2013-07-04 23:16:10 +08:00
parent 4caa96586c
commit 29c4fd7de9
8 changed files with 174 additions and 155 deletions

View File

@ -178,32 +178,34 @@ def main():
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
config = json.load(f)
SERVER = config['server']
REMOTE_PORT = config['server_port']
PORT = config['local_port']
KEY = config['password']
METHOD = config.get('method', None)
LOCAL = config.get('local', '')
optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6')
for key, value in optlist:
if key == '-p':
REMOTE_PORT = int(value)
config['server_port'] = int(value)
elif key == '-k':
KEY = value
config['password'] = value
elif key == '-l':
PORT = int(value)
config['local_port'] = int(value)
elif key == '-s':
SERVER = value
config['server'] = value
elif key == '-m':
METHOD = value
config['method'] = value
elif key == '-b':
LOCAL = value
config['local'] = value
elif key == '-6':
IPv6 = True
SERVER = config['server']
REMOTE_PORT = config['server_port']
PORT = config['local_port']
KEY = config['password']
METHOD = config.get('method', None)
LOCAL = config.get('local', '')
if not KEY and not config_path:
sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks')
utils.check_config(config)
encrypt.init_table(KEY, METHOD)
@ -211,7 +213,7 @@ def main():
if IPv6:
ThreadingTCPServer.address_family = socket.AF_INET6
server = ThreadingTCPServer((LOCAL, PORT), Socks5Server)
logging.info("starting server at %s:%d" % tuple(server.server_address[:2]))
logging.info("starting local at %s:%d" % tuple(server.server_address[:2]))
server.serve_forever()
except socket.error, e:
logging.error(e)

View File

@ -144,7 +144,7 @@ def main():
IPv6 = False
config_path = utils.find_config()
optlist, args = getopt.getopt(sys.argv[1:], 'p:k:m:c:6')
optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6')
for key, value in optlist:
if key == '-c':
config_path = value
@ -153,31 +153,36 @@ def main():
with open(config_path, 'rb') as f:
config = json.load(f)
logging.info('loading config from %s' % config_path)
SERVER = config['server']
PORT = config['server_port']
KEY = config['password']
METHOD = config.get('method', None)
optlist, args = getopt.getopt(sys.argv[1:], 'p:k:m:c:6')
optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6')
for key, value in optlist:
if key == '-p':
PORT = int(value)
config['server_port'] = int(value)
elif key == '-k':
KEY = value
config['password'] = value
elif key == '-s':
config['server'] = value
elif key == '-m':
METHOD = value
config['method'] = value
elif key == '-6':
IPv6 = True
SERVER = config['server']
PORT = config['server_port']
KEY = config['password']
METHOD = config.get('method', None)
if not KEY and not config_path:
sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks')
utils.check_config(config)
encrypt.init_table(KEY, METHOD)
if IPv6:
ThreadingTCPServer.address_family = socket.AF_INET6
try:
server = ThreadingTCPServer(('', PORT), Socks5Server)
logging.info("starting server at port %d ..." % PORT)
server = ThreadingTCPServer((SERVER, PORT), Socks5Server)
logging.info("starting server at %s:%d" % tuple(server.server_address[:2]))
server.serve_forever()
except socket.error, e:
logging.error(e)

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
import logging
def find_config():
@ -12,3 +13,10 @@ def find_config():
if os.path.exists(config_path):
return config_path
return None
def check_config(config):
if config.get('server', '') in ['127.0.0.1', 'localhost']:
logging.warn('Server is set to "%s", maybe it\'s not correct' % config['server'])
logging.warn('Notice server will listen at %s:%s' % (config['server'], config['server_port']))
if (config.get('method', '') or '').lower() == 'rc4':
logging.warn('RC4 is not safe; please use a safer cipher, like AES-256-CFB')