|
|
@ -1,6 +1,6 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
|
|
# Copyright (c) 2012 clowwindy |
|
|
|
# Copyright (c) 2013 clowwindy |
|
|
|
# |
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
|
|
# of this software and associated documentation files (the "Software"), to deal |
|
|
@ -43,6 +43,7 @@ import os |
|
|
|
import logging |
|
|
|
import getopt |
|
|
|
import encrypt |
|
|
|
import utils |
|
|
|
|
|
|
|
|
|
|
|
def send_all(sock, data): |
|
|
@ -142,28 +143,48 @@ class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
|
logging.warn(e) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
def main(): |
|
|
|
global SERVER, REMOTE_PORT, PORT, KEY, METHOD, LOCAL, IPv6 |
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG, |
|
|
|
format='%(asctime)s %(levelname)-8s %(message)s', |
|
|
|
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') |
|
|
|
|
|
|
|
# fix py2exe |
|
|
|
if hasattr(sys, "frozen") and sys.frozen in \ |
|
|
|
("windows_exe", "console_exe"): |
|
|
|
p = os.path.dirname(os.path.abspath(sys.executable)) |
|
|
|
os.chdir(p) |
|
|
|
version = '' |
|
|
|
try: |
|
|
|
os.chdir(os.path.dirname(__file__) or '.') |
|
|
|
except NameError: |
|
|
|
# fix py2exe |
|
|
|
if hasattr(sys, "frozen") and sys.frozen in \ |
|
|
|
("windows_exe", "console_exe"): |
|
|
|
p = os.path.dirname(os.path.abspath(sys.executable)) |
|
|
|
os.chdir(p) |
|
|
|
print 'shadowsocks v1.2.3' |
|
|
|
|
|
|
|
with open('config.json', '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', '') |
|
|
|
import pkg_resources |
|
|
|
version = pkg_resources.get_distribution('shadowsocks').version |
|
|
|
except ImportError: |
|
|
|
pass |
|
|
|
print 'shadowsocks %s' % version |
|
|
|
|
|
|
|
METHOD = None |
|
|
|
LOCAL = '' |
|
|
|
IPv6 = False |
|
|
|
|
|
|
|
optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:6') |
|
|
|
|
|
|
|
config_path = utils.find_config() |
|
|
|
optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') |
|
|
|
for key, value in optlist: |
|
|
|
if key == '-c': |
|
|
|
config_path = value |
|
|
|
|
|
|
|
if config_path: |
|
|
|
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) |
|
|
@ -180,10 +201,6 @@ if __name__ == '__main__': |
|
|
|
elif key == '-6': |
|
|
|
IPv6 = True |
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG, |
|
|
|
format='%(asctime)s %(levelname)-8s %(message)s', |
|
|
|
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') |
|
|
|
|
|
|
|
encrypt.init_table(KEY, METHOD) |
|
|
|
|
|
|
|
try: |
|
|
@ -197,3 +214,6 @@ if __name__ == '__main__': |
|
|
|
except KeyboardInterrupt: |
|
|
|
server.shutdown() |
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
main() |