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

Commit b95eff9

Browse files
author
icymind
committed
add obfs-local support
1 parent 90109da commit b95eff9

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

src/main/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function setMenu () {
104104
click: async () => {
105105
logger.info('about to quit VRouter')
106106
await VRouter.toggleRouting(true, 'off')
107-
const cfg = await VRouter.getLatestCfg()
107+
const {cfg} = await VRouter.getLatestCfg()
108108
await VBox.saveState(cfg.virtualbox.vmName)
109109
app.quit()
110110
}
@@ -247,7 +247,7 @@ app.on('ready', () => {
247247
try {
248248
logger.info('about to quit VRouter')
249249
await VRouter.toggleRouting(true, 'off')
250-
const cfg = await VRouter.getLatestCfg()
250+
const {cfg} = await VRouter.getLatestCfg()
251251
await VBox.saveState(cfg.virtualbox.vmName)
252252
app.quit()
253253
} catch (err) {

src/renderer/components/Manage.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const templateProfile = {
110110
'method': 'chacha20',
111111
'fast_open': false,
112112
'plugin': 'obfs-local',
113-
'obfs_opts': ''
113+
'plugin_opts': 'obfs=http;obfs-host=www.bing.com'
114114
},
115115
'shadowsocksr': {
116116
'server': '123.123.123.123',
@@ -380,7 +380,12 @@ export default {
380380
}
381381
},
382382
created: async function () {
383-
this.vrouter = new VRouter(await VRouter.getLatestCfg())
383+
const {cfg, needUpdate} = await VRouter.getLatestCfg()
384+
this.vrouter = new VRouter(cfg)
385+
if (needUpdate) {
386+
await this.vrouter.saveCfg2File()
387+
await this.vrouter.installApkAfterUpdate(cfg.version)
388+
}
384389
this.profiles = this.vrouter.config.profiles
385390
386391
this.bus = new Vue()

src/renderer/components/Manage/ProfileEditor/ProxiesForm/SsForm.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
</div>
4141
</div>
4242

43-
<div class="inline field">
44-
<div class="ui checkbox">
43+
<div class="field">
44+
<div class="ui checkbox field">
4545
<input type="checkbox" value="obfs" v-model="enableObfs">
4646
<label>Obfuscating</label>
4747
</div>
48-
<input type="text" v-model="shadowsocks.obfs_opts">
48+
<div class="ui fluid input">
49+
<input type="text" v-model="shadowsocks.plugin_opts" v-bind:disabled="!enableObfs">
50+
</div>
4951
</div>
5052
</form>
5153
</template>
@@ -72,7 +74,7 @@ export default {
7274
return this.shadowsocks.plugin === 'obfs-local'
7375
},
7476
set: function (value) {
75-
this.shadowsocks.plugin = value ? 'obfs-local' : 'none'
77+
this.shadowsocks.plugin = value ? 'obfs-local' : ''
7678
}
7779
}
7880
}

src/renderer/lib/generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async function getSsCfgFrom (profile, proxiesInfo) {
6969
'timeout': parseInt(data.timeout),
7070
'method': data.method.toLowerCase(),
7171
'fast_open': data.fast_open,
72-
'mode': 'tcp_only'
72+
'mode': 'tcp_only',
73+
'plugin': data.plugin,
74+
'plugin_opts': data.plugin_opts
7375
}
7476
if (profile.proxies === 'ssKt') {
7577
cfg.server = '127.0.0.1'

src/renderer/lib/vrouter.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,53 @@ class VRouter extends Openwrt {
313313
} catch (error) {
314314
// appdircfg 不存在
315315
await fs.copy(templateCfgPath, appDirCfgPath)
316-
return templateCfg
316+
return {
317+
cfg: templateCfg,
318+
needUpdate: false
319+
}
317320
}
318321

319-
if (appDirCfg.version < 0.4) {
322+
if (parseFloat(appDirCfg.version) < 0.4) {
320323
// 对 0.4 以下版本不作兼容
321324
await fs.copy(templateCfgPath, appDirCfgPath)
322-
return templateCfg
325+
return {
326+
cfg: templateCfg,
327+
needUpdate: true
328+
}
329+
}
330+
331+
if (parseFloat(appDirCfg.version) === 0.4 && parseFloat(templateCfg.version) === 0.5) {
332+
logger.info('update config.json to version 0.5')
333+
appDirCfg.profiles.forEach(profile => {
334+
if (profile.shadowsocks) {
335+
profile.shadowsocks.plugin = profile.shadowsocks.plugin || ''
336+
profile.shadowsocks.plugin_opts = profile.shadowsocks.plugin_opts || 'obfs=http;obfs-host:www.bing.com'
337+
}
338+
})
339+
340+
appDirCfg.version = '0.5'
341+
return {
342+
cfg: appDirCfg,
343+
needUpdate: true
344+
}
323345
}
324346

325347
// appDirCfg 已经是最新版本的配置文件
326-
return appDirCfg
348+
return {
349+
cfg: appDirCfg,
350+
needUpdate: false
351+
}
352+
}
353+
async installApkAfterUpdate (version) {
354+
if (version === 0.5) {
355+
// install obfs-local.apk
356+
const targzFPath = path.join(__static, 'bin/shadowsocks.tar.gz')
357+
await this.installSs(targzFPath)
358+
}
327359
}
328360
static async toggleRouting (action = false, type = 'off') {
329361
logger.info('action', type)
330-
const config = await VRouter.getLatestCfg()
362+
const config = await VRouter.getLatestCfg().cfg
331363
const ip = config.openwrt.ip
332364
const hostonlyif = await VBox.getAssignedHostonlyInf(config.virtualbox.vmName)
333365
const hostonlyInfIP = config.virtualbox.hostonlyInfIP

static/config-templates/config.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.6",
2+
"version": "0.5",
33
"cfgDirName": "vrouter",
44
"virtualbox": {
55
"vmName": "vrouter",
@@ -38,8 +38,8 @@
3838
"timeout": 600,
3939
"method": "chacha20",
4040
"fast_open": false,
41-
"plugin": "none",
42-
"plugin_obfs": ""
41+
"plugin": "",
42+
"plugin_opts": ""
4343
}
4444
},
4545
{
@@ -62,8 +62,8 @@
6262
"timeout": 300,
6363
"method": "chacha20",
6464
"fast_open": false,
65-
"plugin": "none",
66-
"plugin_obfs": ""
65+
"plugin": "",
66+
"plugin_opts": ""
6767
},
6868
"kcptun": {
6969
"server": "123.123.123.123",

0 commit comments

Comments
 (0)