Beispiel #1
0
def Shadowsocks_Process(logpath):
    logging.getLogger('').handlers = []
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filename=logpath,
                        filemode="a")
    new_self_method(logging, "basicConfig", new_basicConfig, logpath)
    ss_local.main()
Beispiel #2
0
def Shadowsocks_Process(logpath):
    logging.getLogger('').handlers = []
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filename=logpath,
                        filemode="a")
    new_self_method(logging, "basicConfig", new_basicConfig, logpath)
    if sys.platform.startswith('win'):
        if "32bit" in platform.architecture():
            libpath = 'lib'
        else:
            libpath = os.path.join('lib', 'x64')
        os.environ['path'] = '%s;%s' % (libpath, os.environ['path'])
    ss_local.main()
Beispiel #3
0
def ssr(run):
    config = {}
    from shadowsocks import local
    if run:
        file_path = run
    else:
        file_path = 'ssr.json'
    with open(file_path, 'rb') as f:
        try:
            config = parse_json_in_str(remove_comment(f.read().decode('utf8')))
            config['password'] = to_bytes(config.get('password', b''))
            config['method'] = to_str(config.get('method', 'aes-256-cfb'))
            config['protocol'] = to_str(config.get('protocol', 'origin'))
            config['protocol_param'] = to_str(config.get('protocol_param', ''))
            config['obfs'] = to_str(config.get('obfs', 'plain'))
            config['obfs_param'] = to_str(config.get('obfs_param', ''))
            config['port_password'] = config.get('port_password', None)
            config['additional_ports'] = config.get('additional_ports', {})
            config['additional_ports_only'] = config.get(
                'additional_ports_only', False)
            config['timeout'] = int(config.get('timeout', 300))
            config['udp_timeout'] = int(config.get('udp_timeout', 120))
            config['udp_cache'] = int(config.get('udp_cache', 64))
            config['fast_open'] = config.get('fast_open', False)
            config['workers'] = config.get('workers', 1)
            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)
            config['connect_verbose_info'] = config.get(
                'connect_verbose_info', 0)
            config['local_address'] = to_str(
                config.get('local_address', '127.0.0.1'))
            config['local_port'] = config.get('local_port', 1080)

        except Exception as e:
            with open('kiyo.log', 'a', encoding='utf-8') as f:
                f.write(
                    time.strftime("%Y-%m-%d %H:%M:%S") + '    ' + str(e) +
                    '\n')
                f.close()

    local.main(config=config)
Beispiel #4
0
def main_task():
    '''
    功能为根据指定的 ss-qrcode-url 获取ss配置信息并输出为config文件

    1. 获取SS-QRCode的png文件
    2. 通过Image获取ss-url信息 
    3. 使用base64解析ss-url信息
    4. 解析解码后的ss配置信息
    5. 根据解析后的配置生成json配置文件config.json
    '''

    args = get_parser()
    print args

    try:
        ss_filename = wget.download(args.ss_qrcode_url)
        print ss_filename
        image = decode_qrcode(ss_filename)

        for symbol in image:
            # do something useful with results
            if symbol.data.startswith("ss://"):
                result = base64.decodestring(symbol.data[5:])
            server_info = result.split(':')
            server_user = server_info[1].split('@')
            method, password, server_ip, server_port = server_info[
                0], server_user[0], server_user[1], server_info[2]
            print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
            print 'result:[' + result + "]"
            print method, password, server_ip, server_port
            server_port = int(server_port)

    finally:
        # clean up
        os.remove(ss_filename)

    ## 5.generate config.json file
    args.config = os.path.realpath(args.config)

    file_obj = open(args.config, 'w')
    #print jsonfile
    conf_json = dict()
    conf_json['fast_open'] = False
    conf_json['local_address'] = '0.0.0.0'
    conf_json['local_port'] = 1080
    conf_json['method'] = method
    conf_json['password'] = password
    conf_json['server'] = server_ip
    conf_json['server_port'] = server_port
    conf_json['timeout'] = 600
    conf_json['workers'] = 1

    #print conf_json
    jsonfile = json.dumps(conf_json, sort_keys=True, indent=4)
    print jsonfile
    file_obj.write(jsonfile)
    file_obj.close()

    sys.argv = [
        sys.argv[0], "-c", args.config, '-d', args.daemon, '-q', '--pid-file',
        args.pid_file, '--log-file', args.log_file
    ]
    if args.quiet_mode:
        sys.argv += "-q"
    print sys.argv
    sys.exit(main())