|
|
|
// +build json
|
|
|
|
|
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ChinaSitesCondition struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ChinaSitesCondition) Apply(dest v2net.Destination) bool {
|
|
|
|
for _, cond := range chinaSitesConds {
|
|
|
|
if cond.Apply(dest) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseChinaSitesRule(data []byte) (*Rule, error) {
|
|
|
|
rawRule := new(JsonRule)
|
|
|
|
err := json.Unmarshal(data, rawRule)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Router: Invalid router rule: ", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Rule{
|
|
|
|
Tag: rawRule.OutboundTag,
|
|
|
|
Condition: &ChinaSitesCondition{},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
anySubDomain = "^(.*\\.)?"
|
|
|
|
dotAm = "\\.am$"
|
|
|
|
dotCc = "\\.cc$"
|
|
|
|
dotCn = "\\.cn$"
|
|
|
|
dotCom = "\\.com$"
|
|
|
|
dotIo = "\\.io$"
|
|
|
|
dotLa = "\\.la$"
|
|
|
|
dotMe = "\\.me$"
|
|
|
|
dotNet = "\\.net$"
|
|
|
|
dotOrg = "\\.org$"
|
|
|
|
dotTv = "\\.tv$"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
chinaSitesConds []Condition
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
regexpDomains := []string{
|
|
|
|
dotCn,
|
|
|
|
"\\.xn--fiqs8s$", /* .中国 */
|
|
|
|
|
|
|
|
anySubDomain + "10010" + dotCom,
|
|
|
|
anySubDomain + "115" + dotCom,
|
|
|
|
anySubDomain + "123juzi" + dotCom,
|
|
|
|
anySubDomain + "123juzi" + dotNet,
|
|
|
|
anySubDomain + "123u" + dotCom,
|
|
|
|
anySubDomain + "126" + dotCom,
|
|
|
|
anySubDomain + "126" + dotNet,
|
|
|
|
anySubDomain + "127" + dotNet,
|
|
|
|
anySubDomain + "163" + dotCom,
|
|
|
|
anySubDomain + "17173" + dotCom,
|
|
|
|
anySubDomain + "17cdn" + dotCom,
|
|
|
|
anySubDomain + "1905" + dotCom,
|
|
|
|
anySubDomain + "21cn" + dotCom,
|
|
|
|
anySubDomain + "2288" + dotOrg,
|
|
|
|
anySubDomain + "2345" + dotCom,
|
|
|
|
anySubDomain + "3322" + dotOrg,
|
|
|
|
anySubDomain + "35" + dotCom,
|
|
|
|
anySubDomain + "360doc" + dotCom,
|
|
|
|
anySubDomain + "360buy" + dotCom,
|
|
|
|
anySubDomain + "360buyimg" + dotCom,
|
|
|
|
anySubDomain + "360safe" + dotCom,
|
|
|
|
anySubDomain + "36kr" + dotCom,
|
|
|
|
anySubDomain + "39" + dotNet,
|
|
|
|
anySubDomain + "3dmgame" + dotCom,
|
|
|
|
anySubDomain + "4399" + dotCom,
|
|
|
|
anySubDomain + "50bang" + dotOrg,
|
|
|
|
anySubDomain + "51" + dotLa,
|
|
|
|
anySubDomain + "51cto" + dotCom,
|
|
|
|
anySubDomain + "51job" + dotCom,
|
|
|
|
anySubDomain + "51jobcdn" + dotCom,
|
|
|
|
anySubDomain + "55bbs" + dotCom,
|
|
|
|
anySubDomain + "58" + dotCom,
|
|
|
|
anySubDomain + "71" + dotAm,
|
|
|
|
anySubDomain + "7k7k" + dotCom,
|
|
|
|
anySubDomain + "9718" + dotCom,
|
|
|
|
anySubDomain + "abchina" + dotCom,
|
|
|
|
anySubDomain + "acfun" + dotTv,
|
|
|
|
anySubDomain + "aicdn" + dotCom,
|
|
|
|
anySubDomain + "alibaba" + dotCom,
|
|
|
|
anySubDomain + "alicdn" + dotCom,
|
|
|
|
anySubDomain + "aliimg.com" + dotCom,
|
|
|
|
anySubDomain + "alipay" + dotCom,
|
|
|
|
anySubDomain + "alipayobjects" + dotCom,
|
|
|
|
anySubDomain + "aliyun" + dotCom,
|
|
|
|
anySubDomain + "aliyuncdn" + dotCom,
|
|
|
|
anySubDomain + "aliyuncs" + dotCom,
|
|
|
|
anySubDomain + "allyes" + dotCom,
|
|
|
|
anySubDomain + "amap" + dotCom,
|
|
|
|
anySubDomain + "anjuke" + dotCom,
|
|
|
|
anySubDomain + "anquan" + dotOrg,
|
|
|
|
anySubDomain + "appinn" + dotCom,
|
|
|
|
anySubDomain + "babytree" + dotCom,
|
|
|
|
anySubDomain + "baidu" + dotCom,
|
|
|
|
anySubDomain + "baiducontent" + dotCom,
|
|
|
|
anySubDomain + "baidustatic" + dotCom,
|
|
|
|
anySubDomain + "baifendian" + dotCom,
|
|
|
|
anySubDomain + "baifubao" + dotCom,
|
|
|
|
anySubDomain + "baihe" + dotCom,
|
|
|
|
anySubDomain + "baike" + dotCom,
|
|
|
|
anySubDomain + "baixing" + dotCom,
|
|
|
|
anySubDomain + "baixing" + dotNet,
|
|
|
|
anySubDomain + "bankcomm" + dotCom,
|
|
|
|
anySubDomain + "bankofchina" + dotCom,
|
|
|
|
anySubDomain + "bcy" + dotNet,
|
|
|
|
anySubDomain + "bdimg" + dotCom,
|
|
|
|
anySubDomain + "bdstatic" + dotCom,
|
|
|
|
anySubDomain + "bilibili" + dotCom,
|
|
|
|
anySubDomain + "bitauto" + dotCom,
|
|
|
|
anySubDomain + "bitautoimg" + dotCom,
|
|
|
|
anySubDomain + "bobo" + dotCom,
|
|
|
|
anySubDomain + "btcfans" + dotCom,
|
|
|
|
anySubDomain + "ccb" + dotCom,
|
|
|
|
anySubDomain + "cctv" + dotCom,
|
|
|
|
anySubDomain + "cctvpic" + dotCom,
|
|
|
|
anySubDomain + "cdn20" + dotCom,
|
|
|
|
anySubDomain + "ch" + dotCom,
|
|
|
|
anySubDomain + "che168" + dotCom,
|
|
|
|
anySubDomain + "china" + dotCom,
|
|
|
|
anySubDomain + "chinacache" + dotCom,
|
|
|
|
anySubDomain + "chinacache" + dotNet,
|
|
|
|
anySubDomain + "chinahr" + dotCom,
|
|
|
|
anySubDomain + "chinamobile" + dotCom,
|
|
|
|
anySubDomain + "chinaz" + dotCom,
|
|
|
|
anySubDomain + "chouti" + dotCom,
|
|
|
|
anySubDomain + "chuangxin" + dotCom,
|
|
|
|
anySubDomain + "clouddn" + dotCom,
|
|
|
|
anySubDomain + "cloudxns" + dotCom,
|
|
|
|
anySubDomain + "cmbchina" + dotCom,
|
|
|
|
anySubDomain + "cnbeta" + dotCom,
|
|
|
|
anySubDomain + "cnbetacdn" + dotCom,
|
|
|
|
anySubDomain + "cnblogs" + dotCom,
|
|
|
|
anySubDomain + "cnepub" + dotCom,
|
|
|
|
anySubDomain + "cnzz" + dotCom,
|
|
|
|
anySubDomain + "coding" + dotNet,
|
|
|
|
anySubDomain + "csbew" + dotCom,
|
|
|
|
anySubDomain + "csdn" + dotNet,
|
|
|
|
anySubDomain + "ctrip" + dotCom,
|
|
|
|
anySubDomain + "cubead" + dotCom,
|
|
|
|
anySubDomain + "dangdang" + dotCom,
|
|
|
|
anySubDomain + "daocloud" + dotIo,
|
|
|
|
anySubDomain + "dedecms" + dotCom,
|
|
|
|
anySubDomain + "diandian" + dotCom,
|
|
|
|
anySubDomain + "dianping" + dotCom,
|
|
|
|
anySubDomain + "docin" + dotCom,
|
|
|
|
anySubDomain + "donews" + dotCom,
|
|
|
|
anySubDomain + "douban" + dotCom,
|
|
|
|
anySubDomain + "doubanio" + dotCom,
|
|
|
|
anySubDomain + "dpfile" + dotCom,
|
|
|
|
anySubDomain + "duoshuo" + dotCom,
|
|
|
|
anySubDomain + "duowan" + dotCom,
|
|
|
|
anySubDomain + "eastday" + dotCom,
|
|
|
|
anySubDomain + "ecitic" + dotCom,
|
|
|
|
anySubDomain + "emarbox" + dotCom,
|
|
|
|
anySubDomain + "etao" + dotCom,
|
|
|
|
anySubDomain + "fanli" + dotCom,
|
|
|
|
anySubDomain + "fengniao" + dotCom,
|
|
|
|
anySubDomain + "fhldns" + dotCom,
|
|
|
|
anySubDomain + "geekpark" + dotNet,
|
|
|
|
anySubDomain + "getui" + dotCom,
|
|
|
|
anySubDomain + "hao123" + dotCom,
|
|
|
|
anySubDomain + "hao123img" + dotCom,
|
|
|
|
anySubDomain + "haosou" + dotCom,
|
|
|
|
anySubDomain + "hdslb" + dotCom,
|
|
|
|
anySubDomain + "hexun" + dotCom,
|
|
|
|
anySubDomain + "hichina" + dotCom,
|
|
|
|
anySubDomain + "huanqiu" + dotCom,
|
|
|
|
anySubDomain + "hunantv" + dotCom,
|
|
|
|
anySubDomain + "huochepiao" + dotCom,
|
|
|
|
anySubDomain + "hupu" + dotCom,
|
|
|
|
anySubDomain + "huxiu" + dotCom,
|
|
|
|
anySubDomain + "iask" + dotCom,
|
|
|
|
anySubDomain + "iciba" + dotCom,
|
|
|
|
anySubDomain + "idqqimg" + dotCom,
|
|
|
|
anySubDomain + "ifanr" + dotCom,
|
|
|
|
anySubDomain + "ijinshan" + dotCom,
|
|
|
|
anySubDomain + "imedao" + dotCom,
|
|
|
|
anySubDomain + "imgo" + dotTv,
|
|
|
|
anySubDomain + "ipinyou" + dotCom,
|
|
|
|
anySubDomain + "ipip" + dotNet,
|
|
|
|
anySubDomain + "iqiyi" + dotCom,
|
|
|
|
anySubDomain + "it168" + dotCom,
|
|
|
|
anySubDomain + "itjuzi" + dotCom,
|
|
|
|
anySubDomain + "jandan" + dotNet,
|
|
|
|
anySubDomain + "jd" + dotCom,
|
|
|
|
anySubDomain + "jb51" + dotCom,
|
|
|
|
anySubDomain + "jia" + dotCom,
|
|
|
|
anySubDomain + "jianshu" + dotCom,
|
|
|
|
anySubDomain + "jiasuhui" + dotCom,
|
|
|
|
anySubDomain + "jiayuan" + dotCom,
|
|
|
|
anySubDomain + "jisuanke" + dotCom,
|
|
|
|
anySubDomain + "jstv" + dotCom,
|
|
|
|
anySubDomain + "jyimg" + dotCom,
|
|
|
|
anySubDomain + "kaixin001" + dotCom,
|
|
|
|
anySubDomain + "kanimg" + dotCom,
|
|
|
|
anySubDomain + "kankanews" + dotCom,
|
|
|
|
anySubDomain + "kf5" + dotCom,
|
|
|
|
anySubDomain + "kimiss" + dotCom,
|
|
|
|
anySubDomain + "kouclo" + dotCom,
|
|
|
|
anySubDomain + "koudai8" + dotCom,
|
|
|
|
anySubDomain + "ku6" + dotCom,
|
|
|
|
anySubDomain + "ku6cdn" + dotCom,
|
|
|
|
anySubDomain + "ku6img" + dotCom,
|
|
|
|
anySubDomain + "lady8844" + dotCom,
|
|
|
|
anySubDomain + "leiphone" + dotCom,
|
|
|
|
anySubDomain + "leju" + dotCom,
|
|
|
|
anySubDomain + "leturich" + dotOrg,
|
|
|
|
anySubDomain + "letv" + dotCom,
|
|
|
|
anySubDomain + "letvcdn" + dotCom,
|
|
|
|
anySubDomain + "letvimg" + dotCom,
|
|
|
|
anySubDomain + "lietou" + dotCom,
|
|
|
|
anySubDomain + "linkvans" + dotCom,
|
|
|
|
anySubDomain + "lightonus" + dotCom,
|
|
|
|
anySubDomain + "lofter" + dotCom,
|
|
|
|
anySubDomain + "lu" + dotCom,
|
|
|
|
anySubDomain + "lufax" + dotCom,
|
|
|
|
anySubDomain + "lufaxcdn" + dotCom,
|
|
|
|
anySubDomain + "lvmama" + dotCom,
|
|
|
|
anySubDomain + "lxdns" + dotCom,
|
|
|
|
anySubDomain + "ly" + dotCom,
|
|
|
|
anySubDomain + "mechina" + dotOrg,
|
|
|
|
anySubDomain + "mediav" + dotCom,
|
|
|
|
anySubDomain + "meika360" + dotCom,
|
|
|
|
anySubDomain + "meilishuo" + dotCom,
|
|
|
|
anySubDomain + "meishij" + dotNet,
|
|
|
|
anySubDomain + "meituan" + dotCom,
|
|
|
|
anySubDomain + "meizu" + dotCom,
|
|
|
|
anySubDomain + "mgtv" + dotCom,
|
|
|
|
anySubDomain + "mi" + dotCom,
|
|
|
|
anySubDomain + "miaozhen" + dotCom,
|
|
|
|
anySubDomain + "mmstat" + dotCom,
|
|
|
|
anySubDomain + "mop" + dotCom,
|
|
|
|
anySubDomain + "mydrivers" + dotCom,
|
|
|
|
anySubDomain + "netease" + dotCom,
|
|
|
|
anySubDomain + "ngacn" + dotCc,
|
|
|
|
anySubDomain + "ntalker" + dotCom,
|
|
|
|
anySubDomain + "oeeee" + dotCom,
|
|
|
|
anySubDomain + "ol-img" + dotCom,
|
|
|
|
anySubDomain + "onlinesjtu" + dotCom,
|
|
|
|
anySubDomain + "oschina" + dotNet,
|
|
|
|
anySubDomain + "paipai" + dotCom,
|
|
|
|
anySubDomain + "pchome" + dotNet,
|
|
|
|
anySubDomain + "pingan" + dotCom,
|
|
|
|
anySubDomain + "pingplusplus" + dotCom,
|
|
|
|
anySubDomain + "pps" + dotTv,
|
|
|
|
anySubDomain + "pubyun" + dotCom,
|
|
|
|
anySubDomain + "qbox" + dotMe,
|
|
|
|
anySubDomain + "qhimg" + dotCom,
|
|
|
|
anySubDomain + "qidian" + dotCom,
|
|
|
|
anySubDomain + "qingcloud" + dotCom,
|
|
|
|
anySubDomain + "qiniu" + dotCom,
|
|
|
|
anySubDomain + "qiniudn" + dotCom,
|
|
|
|
anySubDomain + "qiniudns" + dotCom,
|
|
|
|
anySubDomain + "qiyi" + dotCom,
|
|
|
|
anySubDomain + "qiyipic" + dotCom,
|
|
|
|
anySubDomain + "qtmojo" + dotCom,
|
|
|
|
anySubDomain + "qq" + dotCom,
|
|
|
|
anySubDomain + "qqmail" + dotCom,
|
|
|
|
anySubDomain + "qunar" + dotCom,
|
|
|
|
anySubDomain + "qunarzz" + dotCom,
|
|
|
|
anySubDomain + "qzone" + dotCom,
|
|
|
|
anySubDomain + "renren" + dotCom,
|
|
|
|
anySubDomain + "ruby-china" + dotOrg,
|
|
|
|
anySubDomain + "sandai" + dotNet,
|
|
|
|
anySubDomain + "sanguosha" + dotCom,
|
|
|
|
anySubDomain + "sanwen" + dotNet,
|
|
|
|
anySubDomain + "segmentfault" + dotCom,
|
|
|
|
anySubDomain + "shutcm" + dotCom,
|
|
|
|
anySubDomain + "sina" + dotCom,
|
|
|
|
anySubDomain + "sinaapp" + dotCom,
|
|
|
|
anySubDomain + "sinaedge" + dotCom,
|
|
|
|
anySubDomain + "sinaimg" + dotCom,
|
|
|
|
anySubDomain + "sinajs" + dotCom,
|
|
|
|
anySubDomain + "szzfgjj" + dotCom,
|
|
|
|
anySubDomain + "smzdm" + dotCom,
|
|
|
|
anySubDomain + "sohu" + dotCom,
|
|
|
|
anySubDomain + "sogou" + dotCom,
|
|
|
|
anySubDomain + "soso" + dotCom,
|
|
|
|
anySubDomain + "sspai" + dotCom,
|
|
|
|
anySubDomain + "staticfile" + dotOrg,
|
|
|
|
anySubDomain + "stockstar" + dotCom,
|
|
|
|
anySubDomain + "suning" + dotCom,
|
|
|
|
anySubDomain + "t1y5" + dotCom,
|
|
|
|
anySubDomain + "tanx" + dotCom,
|
|
|
|
anySubDomain + "tao123" + dotCom,
|
|
|
|
anySubDomain + "taobao" + dotCom,
|
|
|
|
anySubDomain + "taobaocdn" + dotCom,
|
|
|
|
anySubDomain + "tencent" + dotCom,
|
|
|
|
anySubDomain + "tenpay" + dotCom,
|
|
|
|
anySubDomain + "tiexue" + dotNet,
|
|
|
|
anySubDomain + "tmall" + dotCom,
|
|
|
|
anySubDomain + "tmcdn" + dotNet,
|
|
|
|
anySubDomain + "tudou" + dotCom,
|
|
|
|
anySubDomain + "tudouui" + dotCom,
|
|
|
|
anySubDomain + "tuicool" + dotCom,
|
|
|
|
anySubDomain + "u17" + dotCom,
|
|
|
|
anySubDomain + "unionpay" + dotCom,
|
|
|
|
anySubDomain + "unionpaysecure" + dotCom,
|
|
|
|
anySubDomain + "upyun" + dotCom,
|
|
|
|
anySubDomain + "upaiyun" + dotCom,
|
|
|
|
anySubDomain + "v2ex" + dotCom,
|
|
|
|
anySubDomain + "vamaker" + dotCom,
|
|
|
|
anySubDomain + "vancl" + dotCom,
|
|
|
|
anySubDomain + "vip" + dotCom,
|
|
|
|
anySubDomain + "wandoujia" + dotCom,
|
|
|
|
anySubDomain + "wdjimg" + dotCom,
|
|
|
|
anySubDomain + "webterren" + dotCom,
|
|
|
|
anySubDomain + "weibo" + dotCom,
|
|
|
|
anySubDomain + "weiyun" + dotCom,
|
|
|
|
anySubDomain + "wonnder" + dotCom,
|
|
|
|
anySubDomain + "wrating" + dotCom,
|
|
|
|
anySubDomain + "wscdns" + dotCom,
|
|
|
|
anySubDomain + "xiachufang" + dotCom,
|
|
|
|
anySubDomain + "xiami" + dotCom,
|
|
|
|
anySubDomain + "xiaomi" + dotCom,
|
|
|
|
anySubDomain + "xinhuanet" + dotCom,
|
|
|
|
anySubDomain + "xinshipu" + dotCom,
|
|
|
|
anySubDomain + "xnpic" + dotCom,
|
|
|
|
anySubDomain + "xueqiu" + dotCom,
|
|
|
|
anySubDomain + "xunlei" + dotCom,
|
|
|
|
anySubDomain + "xywy" + dotCom,
|
|
|
|
anySubDomain + "yaolan" + dotCom,
|
|
|
|
anySubDomain + "yccdn" + dotCom,
|
|
|
|
anySubDomain + "yesky" + dotCom,
|
|
|
|
anySubDomain + "yigao" + dotCom,
|
|
|
|
anySubDomain + "yihaodian" + dotCom,
|
|
|
|
anySubDomain + "yihaodianimg" + dotCom,
|
|
|
|
anySubDomain + "yingjiesheng" + dotCom,
|
|
|
|
anySubDomain + "yhd" + dotCom,
|
|
|
|
anySubDomain + "youboy" + dotCom,
|
|
|
|
anySubDomain + "youku" + dotCom,
|
|
|
|
anySubDomain + "yunba" + dotIo,
|
|
|
|
anySubDomain + "yunshipei" + dotCom,
|
|
|
|
anySubDomain + "yupoo" + dotCom,
|
|
|
|
anySubDomain + "yy" + dotCom,
|
|
|
|
anySubDomain + "zastatic" + dotCom,
|
|
|
|
anySubDomain + "zbjimg" + dotCom,
|
|
|
|
anySubDomain + "zhenai" + dotCom,
|
|
|
|
anySubDomain + "zhanqi" + dotTv,
|
|
|
|
anySubDomain + "zhihu" + dotCom,
|
|
|
|
anySubDomain + "zhimg" + dotCom,
|
|
|
|
anySubDomain + "zjstv" + dotCom,
|
|
|
|
anySubDomain + "zhubajie" + dotCom,
|
|
|
|
}
|
|
|
|
|
|
|
|
chinaSitesConds = make([]Condition, len(regexpDomains))
|
|
|
|
for idx, pattern := range regexpDomains {
|
|
|
|
matcher, err := NewRegexpDomainMatcher(pattern)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
chinaSitesConds[idx] = matcher
|
|
|
|
}
|
|
|
|
}
|