Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 2d1149c

Browse files
author
icymind
committed
rewrite test
1 parent da6e53a commit 2d1149c

17 files changed

+13416
-1011
lines changed

config/ss-over-kt.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"server": "127.0.0.1",
3-
"server_port": 1070,
4-
"local_address": "0.0.0.0",
5-
"local_port": 1090,
6-
"password": "demo",
7-
"timeout": 20,
8-
"method": "chacha20",
9-
"fast_open": false,
10-
"mode": "tcp_only"
2+
"server":"127.0.0.1",
3+
"server_port":1070,
4+
"local_address":"0.0.0.0",
5+
"local_port":1090,
6+
"password":"demo",
7+
"timeout":20,
8+
"method":"chacha20",
9+
"fast_open":false,
10+
"mode":"tcp_only"
1111
}

js/vrouter-local.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const crypto = require('crypto')
1414
const sudo = require('sudo-prompt')
1515
const { EventEmitter } = require('events')
1616
const os = require('os')
17+
const winston = require('winston')
1718

1819
let VBoxManage
1920

@@ -24,22 +25,37 @@ if (os.platform() === 'darwin') {
2425
}
2526

2627
class VRouter {
27-
constructor () {
28+
constructor (cfgObj) {
2829
let config
2930
let cfg = path.join(getAppDir(), packageJson.name, 'config.json')
30-
try {
31-
config = fs.readJsonSync(cfg)
32-
} catch (err) {
33-
const template = path.join(__dirname, '..', 'config', 'config.json')
34-
config = fs.readJsonSync(template)
35-
fs.copySync(template, cfg)
36-
}
37-
if (!config.host.configDir) {
38-
config.host.configDir = path.join(getAppDir(), packageJson.name)
31+
if (!cfgObj) {
32+
try {
33+
config = fs.readJsonSync(cfg)
34+
} catch (err) {
35+
const template = path.join(__dirname, '..', 'config', 'config.json')
36+
config = fs.readJsonSync(template)
37+
fs.copySync(template, cfg)
38+
}
39+
if (!config.host.configDir) {
40+
config.host.configDir = path.join(getAppDir(), packageJson.name)
41+
}
42+
} else {
43+
config = cfgObj
3944
}
4045
this.config = config
4146
this.process = new EventEmitter()
4247
this.remote = null
48+
winston.configure({
49+
transports: [
50+
new (winston.transports.File)({
51+
filename: path.join(this.config.host.configDir, 'vrouter.log'),
52+
level: 'info'
53+
}),
54+
new (winston.transports.Console)({
55+
level: 'debug'
56+
})
57+
]
58+
})
4359
}
4460

4561
// os
@@ -111,7 +127,7 @@ class VRouter {
111127
return match[1]
112128
}
113129
}
114-
return Error(`can not find NetworkService match ${inf}`)
130+
throw Error(`can not find NetworkService match ${inf}`)
115131
}
116132
async getCurrentGateway () {
117133
let networkService
@@ -162,7 +178,7 @@ class VRouter {
162178
if (match && match[1]) {
163179
ip = match[1]
164180
} else {
165-
return Error('can not get Router IP')
181+
throw Error('can not get Router IP')
166182
}
167183
}
168184
const cmd1 = `/sbin/route change default ${ip}`
@@ -604,15 +620,15 @@ class VRouter {
604620
infos.set(temp[0].replace(/"/g, ''), temp[1].replace(/"/g, ''))
605621
})
606622
if (infos.get('nic1') !== 'hostonly') {
607-
return Error("NIC1 isn't hostonly network")
623+
throw Error("NIC1 isn't hostonly network")
608624
}
609625
if (!/^vboxnet\d+$/ig.test(infos.get('hostonlyadapter1'))) {
610-
return Error("NIC1 doesn't specify host-only adapter")
626+
throw Error("NIC1 doesn't specify host-only adapter")
611627
}
612628
const inf = infos.get('hostonlyadapter1')
613629
const ip = await this.getInfIP(inf)
614630
if (ip !== this.config.host.ip) {
615-
return Error("host-only adapter doesn't config as hostIP")
631+
throw Error("host-only adapter doesn't config as hostIP")
616632
}
617633
return inf
618634
}
@@ -625,16 +641,16 @@ class VRouter {
625641
infos.set(temp[0].replace(/"/g, ''), temp[1].replace(/"/g, ''))
626642
})
627643
if (infos.get('nic2') !== 'bridged') {
628-
return Error("NIC2 isn't bridged network")
644+
throw Error("NIC2 isn't bridged network")
629645
}
630646
const inf = infos.get('bridgeadapter2')
631647
if (!inf) {
632-
return Error("NIC2 doesn't specify bridged adapter")
648+
throw Error("NIC2 doesn't specify bridged adapter")
633649
}
634650
cmd = `/sbin/ifconfig ${inf.trim().split(':')[0]}`
635651
const infConfig = await this.localExec(cmd)
636652
const statusMatch = /status: active/ig.exec(infConfig)
637-
if (!statusMatch) return Error("bridged adapter doesn't active")
653+
if (!statusMatch) throw Error("bridged adapter doesn't active")
638654
return inf
639655
}
640656

@@ -653,10 +669,12 @@ class VRouter {
653669
}
654670
await this.isNIC1ConfigedAsHostonly(this.config.vrouter.name, this.config.host.ip)
655671
.catch(() => {
672+
winston.debug(`isNIC1ConfigedAsHostonly return false. vrouter: ${this.config.vrouter.name}, hostip: ${this.config.host.ip}`)
656673
return this.specifyHostonlyAdapter()
657674
})
658675
await this.isNIC2ConfigedAsBridged(this.config.vrouter.name)
659676
.catch(() => {
677+
winston.debug(`isNIC2ConfigedAsBridged return false. vrouter: ${this.config.vrouter.name}, hostip: ${this.config.host.ip}`)
660678
return this.specifyBridgeAdapter()
661679
})
662680
}
@@ -721,7 +739,7 @@ class VRouter {
721739
}
722740
async changevmTZ () {
723741
const cc = String.raw`
724-
uci set system.@system[0].hostname='VRouter'
742+
uci set system.@system[0].hostname='${this.config.vrouter.name}'
725743
uci set system.@system[0].timezone='HKT-8'
726744
uci set system.@system[0].zonename='Asia/Hong Kong'
727745
uci commit system`
@@ -760,9 +778,11 @@ class VRouter {
760778
async getCfgContent (fileName) {
761779
const filePath = path.join(this.config.host.configDir, fileName)
762780
try {
763-
return fs.readFile(filePath, 'utf8')
781+
const content = await fs.readFile(filePath, 'utf8')
782+
return content
764783
} catch (error) {
765784
const template = path.join(__dirname, '../config', fileName)
785+
winston.debug(`can not find ${filePath}, copy template ${template} to appdir`)
766786
await fs.copy(template, filePath)
767787
return fs.readFile(filePath, 'utf8')
768788
}
@@ -772,7 +792,7 @@ class VRouter {
772792
const stats = await fs.stat(cfgPath)
773793
.catch(() => null)
774794
if (stats && stats.isFile() && !overwrite) {
775-
return Promise.resolve(cfgPath)
795+
return cfgPath
776796
}
777797
const ws = fs.createWriteStream(cfgPath)
778798
const promise = new Promise((resolve, reject) => {
@@ -792,6 +812,7 @@ class VRouter {
792812
// "selectedBL": {"gfwDomains":true, "extraBlackList":true},
793813
// "selectedWL": {"chinaIPs":true, "lanNetworks":true, "extraWhiteList":true},
794814
if (this.config.firewall.selectedWL.lanNetworks) {
815+
winston.debug(`getCfgContent: ${this.config.firewall.lanNetworks}`)
795816
const lan = await this.getCfgContent(this.config.firewall.lanNetworks)
796817
lan.split('\n').forEach((line) => {
797818
const trimLine = line.trim()
@@ -1508,7 +1529,7 @@ class VRouter {
15081529
await fs.stat(dest)
15091530
return dest
15101531
} catch (error) {
1511-
console.log(`${dest} not exist, copy template to it.`)
1532+
winston.debug(`copy template: ${fileName}`)
15121533
await fs.copy(template, dest)
15131534
return dest
15141535
}
@@ -1533,6 +1554,7 @@ class VRouter {
15331554
break
15341555
case 'ktService':
15351556
p = await this.generateService('kcptun')
1557+
winston.debug(`generateService-kcptun for proxies: ${this.config.firewall.currentProxies}`)
15361558
await this.scp(p, '/etc/init.d/')
15371559
await this.serialExec(`chmod +x /etc/init.d/${this.config.kcptun.service}`)
15381560
break
@@ -1551,6 +1573,7 @@ class VRouter {
15511573
break
15521574
case 'ipset':
15531575
p = await this.generateIPsets(overwrite)
1576+
winston.debug('generated ipset')
15541577
await this.scp(p, this.config.vrouter.configDir)
15551578
break
15561579
case 'firewall':
@@ -1599,7 +1622,7 @@ class VRouter {
15991622
async connect (startFirst) {
16001623
const state = await this.getvmState()
16011624
if (state !== 'running') {
1602-
return Error("vm doesn't running.")
1625+
throw Error("vm doesn't running.")
16031626
}
16041627
return new Promise((resolve, reject) => {
16051628
const conn = new Client()

js/vrouter-remote.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,6 @@ class VRouterRemote {
138138
return false
139139
}
140140
}
141-
getSsOverKtProcess () {
142-
const cmd = 'ps -w| grep "[s]s-redir -c .*ss-over-kt.json"'
143-
return this.remoteExec(cmd)
144-
}
145-
getSsProcess () {
146-
// const cmd = 'ps | grep "[s]s-redir -c .*ss-client.json"'
147-
const cmd = 'ps -w| grep "[s]s-redir -c .*ss-client.json"'
148-
return this.remoteExec(cmd)
149-
}
150141
// kcptun
151142
installKt () {
152143
// const cmd = `tar -xvzf ${this.config.vrouter.configDir}/third_party/kcptun*.tar.gz ` +

test/config/ad-domains.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#googleads.g.doubleclick.net
2+
#adclick.g.doubleclick.net
3+
#union.baidu.com
4+
#cb.baidu.com
5+
#a.baidu.com
6+
#baidutv.baidu.com
7+
#bar.baidu.com
8+
#c.baidu.com
9+
#cjhq.baidu.com
10+
#cpro.baidu.com
11+
#drmcmm.baidu.com
12+
#e.baidu.com
13+
#eiv.baidu.com
14+
#hc.baidu.com
15+
#hm.baidu.com
16+
#ma.baidu.com
17+
#nsclick.baidu.com
18+
#spcode.baidu.com
19+
#tk.baidu.com
20+
#union.baidu.com
21+
#ucstat.baidu.com
22+
#utility.baidu.com
23+
#utk.baidu.com
24+
#focusbaiduafp.allyes.com
25+
#afp.qiyi.com
26+
#focusbaiduafp.allyes.com
27+
#a.cctv.com
28+
#a.cntv.cn
29+
#ad.cctv.com
30+
#d.cntv.cn
31+
#adguanggao.eee114.com
32+
#cctv.adsunion.com
33+
#dcads.sina.com.cn
34+
#pp2.pptv.com
35+
#pro.letv.com
36+
#asimgs.pplive.cn
37+
#static.uuzu.com
38+
#v.behe.com
39+
#images.sohu.com
40+
#mcfg.sandai.net
41+
#biz5.sandai.net
42+
#server1.adpolestar.net
43+
#advstat.xunlei.com
44+
#mpv.sandai.net
45+
#mini.group.qq.com
46+
#18.dc.ftn.qq.com
47+
#group.store.qq.com
48+
#f.qstatic.com
49+
#wpkg.org
50+
#www.811115.com
51+
#www.ms-itsupport.com
52+
#ms-itsupport.com
53+
#lottosend.org
54+
#www.adnetworkperformance.com
55+
#www.russiawomendate.com
56+
#29bca6cb72a665c8.se
57+
#jsj565.gssd.pw
58+
#dxe.ashf.pw
59+
#ghjghjty.zz568-link4.top
60+
#www.quxiu358.com
61+
#rmek.binteresting.com
62+
#www.mohipaper.cn
63+
#tupian.bxg68.com
64+
#codo.cd828.com
65+
#www.3vcmdt.com
66+
#big.djkofew838.top
67+
#www.7quanba.com
68+
#www.66008008.com
69+
#hot.beiqisi.com
70+
#cs2.youyo.xyz
71+
#www.fsafa666.com
72+
#620.yoholne.xyz
73+
#qqq6.jzgbcw.com
74+
#www.jcw89.top
75+
#p.ns5n.com
76+
#big.ren883hd.pw
77+
#mm.seochuanmei.com
78+
#www.u17.com
79+
#tupian.bxg68.com
80+
#cfns.pelatoca.com
81+
#se.hzbzx.com
82+
#www.yaoguo.com
83+
#www.sdff2223.com
84+
#neky.504pk.com
85+
#g.29m4.com
86+
#www.xiniuda.space
87+
#youxi.baidu.com
88+
#p061015.y1510.com.ru
89+
#zxhs.f6ce.com
90+
#rwq.youle55.com
91+
#www.r76.de
92+
#img.zhuanfakong.com
93+
#vipse.win
94+
#googleadservices.com
95+
#click.aliyun.com
96+
#bes.baidu.com
97+
#simba.taobao.com
98+
#dj.1688.com
99+
#click.tanx.com

0 commit comments

Comments
 (0)