Skip to content
This repository has been archived by the owner on Jan 17, 2021. It is now read-only.

Commit

Permalink
add XX-Mini features
Browse files Browse the repository at this point in the history
  • Loading branch information
xyuanmu committed Apr 3, 2016
1 parent d36df4c commit 02271bb
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 4,015 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* 双击 addto-startup.js 脚本可以添加开机启动项

### Linux:
* 下载 Linux 版本解压后,打开终端,定位到 XX-Mini 目录,输入 `python proxy.py` 等待一段时间扫描IP
* 下载 Linux 版本解压后,打开终端,定位到 XX-Mini 目录,输入 `python3 proxy.py` 等待一段时间扫描IP
* 之后设置浏览器代理为:127.0.0.1,端口:8087,支持pac自动代理的设置为 `http://127.0.0.1:8086/proxy.pac`
* 接下来即可使用浏览器翻墙,但公共appid不允许观看视频和下载
* 在 XX-Mini 目录,输入 `python addto-startup.py` 可以添加系统启动项
Expand All @@ -26,14 +26,21 @@
* 修改压缩包后缀 zip 为 egg 即可

### proxy.ini 配置文件说明:
建议大家在 data 目录新建一份 manual.ini 文件,优先级大于 proxy.ini 设置,避免升级的时候设置丢失。
```ini
[listen]
;监听地址,如果需要允许局域网/公网使用,设为0.0.0.0即可,若共享pac此项必须设置为 0.0.0.0
ip = 127.0.0.1
;默认使用8087作为代理端口,如有需要可以修改
port = 8087
;局域网代理认证用户名,留空不开启认证
username =
;代理认证密码
password =
;启动后是否隐藏 goagent 窗口,0为隐藏(最小化至托盘),1为显示
visible = 0
;是否显示详细debug信息
debuginfo = 0

[gae]
;添加你自己的appid,多个用竖线 | 分隔
Expand Down Expand Up @@ -111,7 +118,9 @@ https_connection_pool_min = 5
;最大连接池数值
https_connection_pool_max = 50

;设置成 1 会在data目录生成日志文件 local.log,便调试用
[system]
;设置成 1 会在data目录生成日志文件 local.log,便调试用
log_file = 0
;设置是否在data目录输出扫描IP日志 scan_ip.log,超过3000行会新建日志
log_scan = 1
```
27 changes: 11 additions & 16 deletions proxy.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[listen]
ip = 127.0.0.1
port = 8087
visible = 1
username =
password =
visible = 0
debuginfo = 0

[gae]
Expand All @@ -13,6 +15,8 @@ password =
[hosts]
scholar.google.com = direct
scholar.google.com.hk = direct
www.google.com.hk = direct
www.google.com.tw = direct
;code.google.com = direct
;clients5.google.com = direct
;clients6.google.com = direct
Expand Down Expand Up @@ -50,24 +54,23 @@ translate.google.com = gae
;.googlesyndication.com = direct
;.googlevideo.com = gvs #can't use directly, need gae forward.
;.googleadservices.com = direct
www.google.com.hk = direct
;.google.com.cn = direct
;.g.cn = direct

[autorange]
threads = 8
maxsize = 524288
waitsize = 1048576
bufsize = 65535
bufsize = 65536

[pac]
enable = 1
ip = 127.0.0.1
port = 8086
file = proxy.pac
admode = 1
adblock = https://easylist-downloads.adblockplus.org/easylistchina.txt
gfwlist = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
;adblock = http://adblock-chinalist.googlecode.com/svn/trunk/adblock.txt
; this project have stopped.
expired = 86400

;front proxy for connect to google ip
Expand All @@ -79,11 +82,6 @@ port = 8888
user =
passwd =

[control]
enable = 0
ip = 127.0.0.1
port = 8084

[google_ip]
use_ipv6 = 0
auto_adjust_scan_ip_thread_num = 1
Expand Down Expand Up @@ -111,14 +109,11 @@ https_keep_alive = 55

forward_max_connect_thread = 10

; limit interval for two tcp connect try.
; too frequently connect to google ip may make GFW block all google ip for you.
connect_interval = 40


[love]
enable = 0
enable = 1
tip = \u8bf7\u5173\u6ce8\u5317\u4eac\u5931\u5b66\u513f\u7ae5~~

[system]
log_file = 0
log_file = 0
log_scan = 1
3,596 changes: 0 additions & 3,596 deletions proxy.pac

This file was deleted.

144 changes: 60 additions & 84 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,37 @@
# cnfuyu <cnfuyu@gmail.com>
# cuixin <steven.cuixin@gmail.com>



__version__ = '1.0'

import sys
import os

sys.dont_write_bytecode = True

current_path = os.path.dirname(os.path.abspath(__file__))
data_path = os.path.join(current_path, 'data')
__file__ = os.path.abspath(__file__)
if os.path.islink(__file__):
__file__ = getattr(os, 'readlink', lambda x: x)(__file__)
work_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(work_path)
data_path = os.path.join(work_path, 'data')
if not os.path.isdir(data_path): os.mkdir(data_path)

# add python lib path
sys.path.append(os.path.join(current_path, 'pythonlib'))
sys.path.append(os.path.join(current_path, 'pythonlib', 'lib'))
sys.path.append(os.path.join(work_path, 'pythonlib'))
sys.path.append(os.path.join(work_path, 'pythonlib', 'lib'))
if sys.platform.startswith("linux"):
sys.path.append(os.path.join(current_path, 'pythonlib.egg'))
sys.path.append(os.path.join(current_path, 'pythonlib.egg', 'lib'))
sys.path.append(os.path.join(work_path, 'pythonlib.egg'))
sys.path.append(os.path.join(work_path, 'pythonlib.egg', 'lib'))
# reduce resource request for threading, for OpenWrt
import threading
threading.stack_size(128*1024)
elif sys.platform == "darwin":
sys.path.append(os.path.join(current_path, 'pythonlib.egg'))
sys.path.append(os.path.join(current_path, 'pythonlib.egg', 'lib'))

import time
import traceback
import platform
import random
import threading
import urllib.request, urllib.error, urllib.parse

__file__ = os.path.abspath(__file__)
if os.path.islink(__file__):
__file__ = getattr(os, 'readlink', lambda x: x)(__file__)
work_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(work_path)


def create_data_path():
if not os.path.isdir(data_path):
os.mkdir(data_path)
create_data_path()
sys.path.append(os.path.join(work_path, 'pythonlib.egg'))
sys.path.append(os.path.join(work_path, 'pythonlib.egg', 'lib'))


from local.config import config
from OpenSSL import version as openssl_version

from xlog import getLogger
xlog = getLogger("gae_proxy")
Expand All @@ -86,16 +72,46 @@ def create_data_path():
log_file = os.path.join(data_gae_proxy_path, "local.log")
xlog.set_file(log_file)

from local.cert_util import CertUtil
from local import pac_server

def summary():
appids = '|'.join(config.GAE_APPIDS) if config.GAE_APPIDS else 'Using Public APPID'
if len(appids) > 56:
appids = appids[:55] + '..'

pac_ip = config.PAC_IP
if config.PAC_IP != '127.0.0.1':
pac_ip = config.get_listen_ip()

info = '-'*80
info += '\nXX-Mini Version : %s (python/%s pyopenssl/%s)\n' % (__version__, sys.version.split()[0], openssl_version.__version__)
info += 'Listen Address : %s:%d\n' % (config.LISTEN_IP if config.LISTEN_IP == '127.0.0.1' else config.get_listen_ip(), config.LISTEN_PORT)
info += 'Setting File : %sproxy.ini\n' % (config.MANUAL_LOADED + '/' if config.MANUAL_LOADED else '')
info += '%s Proxy %s : %s:%s\n' % (config.PROXY_TYPE, ' '*(12-len(config.PROXY_TYPE)), config.PROXY_HOST, config.PROXY_PORT) if config.PROXY_ENABLE else ''
info += 'GAE APPID : %s\n' % appids
info += 'Pac Server : http://%s:%d/%s\n' % (pac_ip, config.PAC_PORT, config.PAC_FILE) if config.PAC_ENABLE else ''
info += 'CA File : http://%s:%d/%s\n' % (pac_ip, config.PAC_PORT, 'CA.crt') if config.PAC_ENABLE else ''
info += 'Pac File : file://%s\n' % os.path.abspath(os.path.join(data_path, config.PAC_FILE)) if config.PAC_ENABLE else ''
info += '-'*80
return info

xlog.info(summary())
xlog.set_time()
if config.LISTEN_DEBUGINFO:
xlog.set_debug()

import time
import random
import threading
import urllib.request, urllib.error, urllib.parse

import simple_http_server
from local import proxy_handler
from local import connect_control
from local import connect_manager
from local.cert_util import CertUtil
from local.gae_handler import spawn_later
from local.pac_server import PACServerHandler

# launcher/module_init will check this value for start/stop finished
ready = False

def pre_start():

Expand Down Expand Up @@ -157,12 +173,12 @@ def get_windows_running_process_list():
pass
elif os.name == 'nt':
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW('GoAgent ')
ctypes.windll.kernel32.SetConsoleTitleW('XX-Mini v%s' % __version__)
if not config.LISTEN_VISIBLE:
ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)
else:
ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 1)
if config.LOVE_ENABLE and random.randint(1, 100) <= 5:
if config.LOVE_ENABLE and random.randint(1, 100) <= 20:
title = ctypes.create_unicode_buffer(1024)
ctypes.windll.kernel32.GetConsoleTitleW(ctypes.byref(title), len(title)-1)
ctypes.windll.kernel32.SetConsoleTitleW('%s %s' % (title.value, random.choice(config.LOVE_TIP)))
Expand All @@ -173,8 +189,8 @@ def get_windows_running_process_list():
tasklist = '\n'.join(x.name for x in get_windows_running_process_list()).lower()
softwares = [x for x in softwares if x.lower() in tasklist]
if softwares:
title = 'GoAgent 建议'
error = '某些安全软件(如 %s)可能和本软件存在冲突,造成 CPU 占用过高。\n如有此现象建议暂时退出此安全软件来继续运行GoAgent' % ','.join(softwares)
title = 'XX-Mini 建议'
error = '某些安全软件(如 %s)可能和本软件存在冲突,造成 CPU 占用过高。\n如有此现象建议暂时退出此安全软件来继续运行XX-Mini' % ','.join(softwares)
ctypes.windll.user32.MessageBoxW(None, error, title, 0)
#sys.exit(0)
if config.PAC_ENABLE:
Expand All @@ -183,44 +199,12 @@ def get_windows_running_process_list():
spawn_later(600, urllib.request.build_opener(urllib.request.ProxyHandler({})).open, url)


def log_info():
xlog.info('------------------------------------------------------')
xlog.info('Python Version : %s', platform.python_version())
xlog.info('Listen Address : %s:%d', config.LISTEN_IP, config.LISTEN_PORT)
if config.CONTROL_ENABLE:
xlog.info('Control Address : %s:%d', config.CONTROL_IP, config.CONTROL_PORT)
if config.PROXY_ENABLE:
xlog.info('%s Proxy : %s:%s', config.PROXY_TYPE, config.PROXY_HOST, config.PROXY_PORT)
xlog.info('GAE APPID : %s', '|'.join(config.GAE_APPIDS))
if config.PAC_ENABLE:
xlog.info('Pac Server : http://%s:%d/%s', config.PAC_IP, config.PAC_PORT, config.PAC_FILE)
#info += 'Pac File : file://%s\n' % os.path.join(self.DATA_PATH, self.PAC_FILE)
xlog.info('------------------------------------------------------')


def main():
global ready
pre_start()

connect_control.keep_running = True
config.load()
connect_manager.https_manager.load_config()

xlog.debug("## GAEProxy set keep_running: %s", connect_control.keep_running)
# to profile gae_proxy, run proxy.py, visit some web by proxy, then visit http://127.0.0.1:8084/quit to quit and print result.
do_profile = False
if do_profile:
import cProfile, pstats
pr = cProfile.Profile()
pr.enable()

global __file__
__file__ = os.path.abspath(__file__)
if os.path.islink(__file__):
__file__ = getattr(os, 'readlink', lambda x: x)(__file__)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
#xlog.basicConfig(level=xlog.DEBUG if config.LISTEN_DEBUGINFO else xlog.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]')
pre_start()
log_info()

CertUtil.init_ca()

Expand All @@ -230,44 +214,36 @@ def main():
proxy_thread.start()

if config.PAC_ENABLE:
pac_daemon = simple_http_server.HTTPServer((config.PAC_IP, config.PAC_PORT), pac_server.PACServerHandler)
pac_daemon = simple_http_server.HTTPServer((config.PAC_IP, config.PAC_PORT), PACServerHandler)
pac_thread = threading.Thread(target=pac_daemon.serve_forever)
pac_thread.setDaemon(True)
pac_thread.start()

ready = True # checked by launcher.module_init
try:
urllib2.urlopen('http://127.0.0.1:%d/%s' % (config.PAC_PORT, config.PAC_FILE))
except:
pass

while connect_control.keep_running:
time.sleep(1)

xlog.info("Exiting gae_proxy module...")
proxy_daemon.shutdown()
proxy_daemon.server_close()
proxy_thread.join()
if config.PAC_ENABLE:
pac_daemon.shutdown()
pac_daemon.server_close()
pac_thread.join()
ready = False # checked by launcher.module_init
xlog.debug("## GAEProxy set keep_running: %s", connect_control.keep_running)

if do_profile:
pr.disable()
pr.print_stats()


# called by launcher/module/stop
def terminate():
xlog.info("start to terminate GAE_Proxy")
connect_control.keep_running = False
xlog.debug("## Set keep_running: %s", connect_control.keep_running)
sys.exit()


if __name__ == '__main__':
try:
main()
except Exception:
traceback.print_exc(file=sys.stdout)
except KeyboardInterrupt:
terminate()
sys.exit()
1 change: 0 additions & 1 deletion pythonlib/lib/simple_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import errno
import logging
import utils
import ssl


Expand Down
Loading

0 comments on commit 02271bb

Please sign in to comment.