Skip to content

Commit

Permalink
Merge pull request #2 from XX-net/master
Browse files Browse the repository at this point in the history
update to 2829b7
  • Loading branch information
Emphasia authored Dec 21, 2017
2 parents 710dd29 + 2829b73 commit f2ac031
Show file tree
Hide file tree
Showing 80 changed files with 9,011 additions and 6,231 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@


### 最新状态:
2017-12-09
* X-Tunnel 请升级到3.8.5 ([使用教程](https://github.com/XX-net/XX-Net/wiki/x-tunnel%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)
2017-12-20
* 新版 3.9.0 Smart-Router 模块发布,请使用 8086 通用代理端口

* X-Tunnel 请升级到3.9.0 ([使用教程](https://github.com/XX-net/XX-Net/wiki/x-tunnel%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)

* GAE: 扫不到ip,请开启ipv6,请参考:
[如何开启IPv6](https://github.com/XX-net/XX-Net/wiki/%E5%A6%82%E4%BD%95%E5%BC%80%E5%90%AFIPv6)
Expand Down
2 changes: 1 addition & 1 deletion SwitchyOmega/OmegaOptions.bak
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"-confirmDeletion":false,"-downloadInterval":720,"-enableQuickSwitch":false,"-quickSwitchProfiles":["direct"],"-refreshOnProfileChange":false,"-revertProxyChanges":false,"-startupProfileName":"","schemaVersion":2,"-showInspectMenu":true,"-monitorWebRequests":true,"+GAE-Proxy":{"bypassList":[{"conditionType":"BypassCondition","pattern":"<local>"}],"color":"#d42d09","fallbackProxy":{"host":"127.0.0.1","port":8087,"scheme":"http"},"name":"GAE-Proxy","profileType":"FixedProfile","revision":"15383570633"},"+GAE-Proxy自动切换":{"color":"#55bb55","defaultProfileName":"__ruleListOf_GAE-Proxy自动切换","name":"GAE-Proxy自动切换","profileType":"SwitchProfile","revision":"15383578bce","rules":[{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.ggpht.com"},"profileName":"GAE-Proxy"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.google.com.*"},"profileName":"GAE-Proxy"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.google*.com"},"profileName":"GAE-Proxy"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.wikipedia.org"},"profileName":"GAE-Proxy"}]},"+__ruleListOf_GAE-Proxy自动切换":{"color":"#dd6633","defaultProfileName":"direct","format":"AutoProxy","matchProfileName":"GAE-Proxy","name":"__ruleListOf_GAE-Proxy自动切换","profileType":"RuleListProfile","revision":"1538357da4c","ruleList":"","sourceUrl":"https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"},"+X-Tunnel":{"profileType":"FixedProfile","name":"X-Tunnel","bypassList":[{"conditionType":"BypassCondition","pattern":"<local>"}],"color":"#092dba","revision":"1538358c83c","fallbackProxy":{"scheme":"socks5","port":1080,"host":"127.0.0.1"}},"+X-Tunnel自动切换":{"profileType":"SwitchProfile","name":"X-Tunnel自动切换","defaultProfileName":"__ruleListOf_X-Tunnel自动切换","rules":[{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.ggpht.com"},"profileName":"X-Tunnel"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.google.com.*"},"profileName":"X-Tunnel"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.google*.com"},"profileName":"X-Tunnel"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"*.wikipedia.org"},"profileName":"X-Tunnel"}],"color":"#7c05ae","revision":"153835abfe0"},"+__ruleListOf_X-Tunnel自动切换":{"name":"__ruleListOf_X-Tunnel自动切换","defaultProfileName":"direct","profileType":"RuleListProfile","color":"#7c05ae","format":"Switchy","matchProfileName":"X-Tunnel","ruleList":"","revision":"153835b3117","sourceUrl":"https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"}}
{"+X-Tunnel": {"name": "X-Tunnel", "color": "#092dba", "fallbackProxy": {"host": "127.0.0.1", "scheme": "socks5", "port": 1080}, "bypassList": [{"pattern": "<local>", "conditionType": "BypassCondition"}], "profileType": "FixedProfile", "revision": "1538358c83c"}, "+GAE-Proxy\u81ea\u52a8\u5207\u6362": {"name": "GAE-Proxy\u81ea\u52a8\u5207\u6362", "color": "#55bb55", "rules": [{"profileName": "GAE-Proxy", "condition": {"pattern": "*.ggpht.com", "conditionType": "HostWildcardCondition"}}, {"profileName": "GAE-Proxy", "condition": {"pattern": "*.google.com.*", "conditionType": "HostWildcardCondition"}}, {"profileName": "GAE-Proxy", "condition": {"pattern": "*.google*.com", "conditionType": "HostWildcardCondition"}}, {"profileName": "GAE-Proxy", "condition": {"pattern": "*.wikipedia.org", "conditionType": "HostWildcardCondition"}}], "profileType": "SwitchProfile", "defaultProfileName": "__ruleListOf_GAE-Proxy\u81ea\u52a8\u5207\u6362", "revision": "15383578bce"}, "+__ruleListOf_GAE-Proxy\u81ea\u52a8\u5207\u6362": {"sourceUrl": "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt", "name": "__ruleListOf_GAE-Proxy\u81ea\u52a8\u5207\u6362", "format": "AutoProxy", "color": "#dd6633", "matchProfileName": "GAE-Proxy", "profileType": "RuleListProfile", "defaultProfileName": "direct", "ruleList": "", "revision": "1538357da4c"}, "+__ruleListOf_X-Tunnel\u81ea\u52a8\u5207\u6362": {"sourceUrl": "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt", "name": "__ruleListOf_X-Tunnel\u81ea\u52a8\u5207\u6362", "format": "Switchy", "color": "#7c05ae", "matchProfileName": "X-Tunnel", "profileType": "RuleListProfile", "defaultProfileName": "direct", "ruleList": "", "revision": "153835b3117"}, "-monitorWebRequests": true, "-startupProfileName": "", "-showInspectMenu": true, "+Smart-Router": {"name": "Smart-Router", "color": "#096dba", "fallbackProxy": {"host": "127.0.0.1", "scheme": "socks5", "port": 8086}, "bypassList": [{"pattern": "<local>", "conditionType": "BypassCondition"}], "profileType": "FixedProfile", "revision": "1538358c83c"}, "+GAE-Proxy": {"name": "GAE-Proxy", "color": "#d42d09", "fallbackProxy": {"host": "127.0.0.1", "scheme": "http", "port": 8087}, "bypassList": [{"pattern": "<local>", "conditionType": "BypassCondition"}], "profileType": "FixedProfile", "revision": "15383570633"}, "-confirmDeletion": false, "-revertProxyChanges": false, "+X-Tunnel\u81ea\u52a8\u5207\u6362": {"name": "X-Tunnel\u81ea\u52a8\u5207\u6362", "rules": [{"profileName": "X-Tunnel", "condition": {"pattern": "*.ggpht.com", "conditionType": "HostWildcardCondition"}}, {"profileName": "X-Tunnel", "condition": {"pattern": "*.google.com.*", "conditionType": "HostWildcardCondition"}}, {"profileName": "X-Tunnel", "condition": {"pattern": "*.google*.com", "conditionType": "HostWildcardCondition"}}, {"profileName": "X-Tunnel", "condition": {"pattern": "*.wikipedia.org", "conditionType": "HostWildcardCondition"}}], "color": "#7c05ae", "profileType": "SwitchProfile", "defaultProfileName": "__ruleListOf_X-Tunnel\u81ea\u52a8\u5207\u6362", "revision": "153835abfe0"}, "-refreshOnProfileChange": false, "-quickSwitchProfiles": ["direct"], "schemaVersion": 2, "-enableQuickSwitch": false, "-downloadInterval": 720}
2 changes: 1 addition & 1 deletion code/default/download.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## 下载(Download):
稳定版(Stable):
https://codeload.github.com/XX-net/XX-Net/zip/3.8.5
https://codeload.github.com/XX-net/XX-Net/zip/3.8.7


测试版(Test):
Expand Down
26 changes: 25 additions & 1 deletion code/default/gae_proxy/local/apis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from web_control import user_config
import check_ip
from connect_manager import https_manager
from http_dispatcher import http_dispatch
from config import config
from xlog import getLogger
xlog = getLogger("gae_proxy")
Expand All @@ -22,4 +24,26 @@ def set_proxy(args):
user_config.save()
config.load()

check_ip.load_proxy_config()
check_ip.load_proxy_config()


def is_workable():
if http_dispatch.is_idle():
return True

num = len(https_manager.new_conn_pool.pool) +\
len(https_manager.gae_conn_pool.pool) + \
http_dispatch.h1_num + \
http_dispatch.h2_num

if num > 0:
return True
else:
return False


def set_bind_ip(args):
xlog.info("set_bind_ip:%s", args)

user_config.LISTEN_IP = args["ip"]
user_config.save()
6 changes: 3 additions & 3 deletions code/default/gae_proxy/local/cert_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import threading
import subprocess

from ip_utils import check_ip_valid

current_path = os.path.dirname(os.path.abspath(__file__))
python_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, 'python27', '1.0'))
Expand All @@ -39,6 +38,7 @@
xlog = getLogger("gae_proxy")

import OpenSSL
from utils import check_ip_valid

import ssl, datetime
from pyasn1.type import univ, constraint, char, namedtype, tag
Expand Down Expand Up @@ -409,7 +409,7 @@ def import_linux_firefox_ca(common_name, ca_file):
return False

if not any(os.path.isfile('%s/certutil' % x) for x in os.environ['PATH'].split(os.pathsep)):
xlog.warning('please install *libnss3-tools* package to import GoAgent root ca')
xlog.warn('please install *libnss3-tools* package to import GoAgent root ca')
return False

xlog.info("Removing old cert to Firefox in %s", firefox_config_path)
Expand Down Expand Up @@ -452,7 +452,7 @@ def get_linux_ca_sha1(nss_path):
return False

if not any(os.path.isfile('%s/certutil' % x) for x in os.environ['PATH'].split(os.pathsep)):
xlog.warning('please install *libnss3-tools* package to import GoAgent root ca')
xlog.info('please install *libnss3-tools* package to import GoAgent root ca')
return False

sha1 = get_linux_ca_sha1(nss_path)
Expand Down
5 changes: 3 additions & 2 deletions code/default/gae_proxy/local/check_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __repr__(self):

def load_proxy_config():
global default_socket
if config.PROXY_ENABLE:
if int(config.PROXY_ENABLE):

if config.PROXY_TYPE == "HTTP":
proxy_type = socks.HTTP
Expand All @@ -139,6 +139,7 @@ def load_proxy_config():
import threading
network_fail_lock = threading.Lock()


def connect_ssl(ip, port=443, timeout=5, check_cert=True, close_cb=None):
if not check_local_network.is_ok(ip):
with network_fail_lock:
Expand All @@ -148,7 +149,7 @@ def connect_ssl(ip, port=443, timeout=5, check_cert=True, close_cb=None):

sni = sni_generater.get()

if config.PROXY_ENABLE:
if int(config.PROXY_ENABLE):
sock = socks.socksocket(socket.AF_INET if ':' not in ip else socket.AF_INET6)
else:
sock = socket.socket(socket.AF_INET if ':' not in ip else socket.AF_INET6)
Expand Down
16 changes: 6 additions & 10 deletions code/default/gae_proxy/local/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ def load(self):
self.HOSTS_GAE = tuple(gae_hosts)

br_sites = []
br_endswith = []
for k, v in self.CONFIG.items('br_sites'):
br_sites.append(k)
if k.startswith("."):
br_endswith.append(k)
else:
br_sites.append(k)
self.br_sites = tuple(br_sites)
self.br_endswith = tuple(br_endswith)

# hack here:
# 2.x.x version save host mode to direct in data/gae_proxy/config.ini
Expand All @@ -118,15 +123,6 @@ def load(self):
self.AUTORANGE_MAXSIZE = self.CONFIG.getint('autorange', 'maxsize')
self.AUTORANGE_THREADS = self.CONFIG.getint('autorange', 'threads')

self.PAC_ENABLE = self.CONFIG.getint('pac', 'enable')
self.PAC_IP = self.CONFIG.get('pac', 'ip')
self.PAC_PORT = self.CONFIG.getint('pac', 'port')
self.PAC_FILE = self.CONFIG.get('pac', 'file').lstrip('/')
self.PAC_GFWLIST = self.CONFIG.get('pac', 'gfwlist')
self.PAC_ADBLOCK = self.CONFIG.get('pac', 'adblock') if self.CONFIG.has_option('pac', 'adblock') else ''
self.PAC_EXPIRED = self.CONFIG.getint('pac', 'expired')
self.pac_url = 'http://%s:%d/%s\n' % (self.PAC_IP, self.PAC_PORT, self.PAC_FILE)

self.PROXY_ENABLE = self.CONFIG.getint('proxy', 'enable')
self.PROXY_TYPE = self.CONFIG.get('proxy', 'type')
self.PROXY_HOST = self.CONFIG.get('proxy', 'host')
Expand Down
7 changes: 4 additions & 3 deletions code/default/gae_proxy/local/gae_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def request_gae_proxy(method, url, headers, body, timeout=60, retry=True):
accept_encoding = headers.get("Accept-Encoding", "")
if "br" in accept_encoding:
accept_br_encoding = True
xlog.debug("accept_br_encoding for %s", url)
# xlog.debug("accept_br_encoding for %s", url)
else:
accept_br_encoding = False

Expand All @@ -341,8 +341,9 @@ def request_gae_proxy(method, url, headers, body, timeout=60, retry=True):

accept_codes = accept_encoding.replace(" ", "").split(",")
if not accept_br_encoding:
if "gzip" in accept_encoding and host in config.br_sites:
accept_codes.remove("gzip")
if "gzip" in accept_encoding:
if host in config.br_sites or host.endswith(config.br_endswith):
accept_codes.remove("gzip")

if "br" not in accept_codes:
accept_codes.append("br")
Expand Down
74 changes: 2 additions & 72 deletions code/default/gae_proxy/local/ip_utils.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = '[email protected]'

import re

def ip_string_to_num(s):
"""Convert dotted IPv4 address to integer."""
return reduce(lambda a, b: a << 8 | b, map(int, s.split(".")))
from utils import *

def get_ip_maskc(ip_str):
head = ".".join(ip_str.split(".")[:-1])
return head + ".0"

def ip_num_to_string(ip):
"""Convert 32-bit integer to dotted IPv4 address."""
return ".".join(map(lambda n: str(ip >> n & 0xFF), [24, 16, 8, 0]))



g_ip_check = re.compile(r'^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$')

def check_ip_valid4(ip):
"""检查ipv4地址的合法性"""
ret = g_ip_check.match(ip)
if ret is not None:
"each item range: [0,255]"
for item in ret.groups():
if int(item) > 255:
return 0
return 1
else:
return 0


def is_valid_ipv6(ip):
"""Copied from http://stackoverflow.com/a/319293/2755602"""
"""Validates IPv6 addresses.
"""
pattern = re.compile(r"""
^
\s* # Leading whitespace
(?!.*::.*::) # Only a single whildcard allowed
(?:(?!:)|:(?=:)) # Colon iff it would be part of a wildcard
(?: # Repeat 6 times:
[0-9a-f]{0,4} # A group of at most four hexadecimal digits
(?:(?<=::)|(?<!::):) # Colon unless preceeded by wildcard
){6} #
(?: # Either
[0-9a-f]{0,4} # Another group
(?:(?<=::)|(?<!::):) # Colon unless preceeded by wildcard
[0-9a-f]{0,4} # Last group
(?: (?<=::) # Colon iff preceeded by exacly one colon
| (?<!:) #
| (?<=:) (?<!::) : #
) # OR
| # A v4 address with NO leading zeros
(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)
(?: \.
(?:25[0-4]|2[0-4]\d|1\d\d|[1-9]?\d)
){3}
)
\s* # Trailing whitespace
$
""", re.VERBOSE | re.IGNORECASE | re.DOTALL)
return pattern.match(ip) is not None

def check_ip_valid6(ip):
"""检查ipv6地址的合法性"""
if is_valid_ipv6(ip):
return 1
else:
return 0

def check_ip_valid(ip):
if ':' in ip:
return check_ip_valid6(ip)
else:
return check_ip_valid4(ip)

def split_ip(strline):
"""从每组地址中分离出起始IP以及结束IP"""
Expand Down Expand Up @@ -113,7 +43,7 @@ def split_ip(strline):
elif "/" in strline:
"xxx.xxx.xxx.xxx/xx"
(ip, bits) = strline.split("/")
if check_ip_valid(ip) and (0 <= int(bits) <= 32):
if check_ip_valid4(ip) and (0 <= int(bits) <= 32):
orgip = ip_string_to_num(ip)
end_bits = (1 << (32 - int(bits))) - 1
begin_bits = 0xFFFFFFFF ^ end_bits
Expand Down
Loading

0 comments on commit f2ac031

Please sign in to comment.