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

Commit 590a1f7

Browse files
author
icymind
committed
add function: upgradeCfgV2
1 parent a58f426 commit 590a1f7

File tree

3 files changed

+76
-54
lines changed

3 files changed

+76
-54
lines changed

config/config.json

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,7 @@
4040
}
4141
},
4242
{
43-
"name": "vps 黑名单",
44-
"mode": "blacklist",
45-
"proxies": "ss",
46-
"relayUDP": false,
47-
"enableTunnelDns": true,
48-
"selectedBL": {"gfwDomains":true, "extraBlackList":true},
49-
"selectedWL": {"chinaIPs":true, "lanNetworks":true, "extraWhiteList":true},
50-
"shadowsocks": {
51-
"address": "123.123.123.123",
52-
"port": "8989",
53-
"password": "demo-paswd",
54-
"timeout": 300,
55-
"method": "chacha20",
56-
"fastopen": false
57-
}
58-
},
59-
{
60-
"name": "kcp 加速",
43+
"name": "kcp 加速ss",
6144
"mode": "whitelist",
6245
"proxies": "ssKt",
6346
"relayUDP": false,
@@ -102,28 +85,6 @@
10285
"others": "",
10386
"fastopen": false
10487
}
105-
},
106-
{
107-
"name": "ssr 白名单",
108-
"mode": "whitelist",
109-
"proxies": "ssr",
110-
"relayUDP": false,
111-
"enableTunnelDns": true,
112-
"selectedBL": {"gfwDomains":true, "extraBlackList":true},
113-
"selectedWL": {"chinaIPs":true, "lanNetworks":true, "extraWhiteList":true},
114-
"shadowsocksr": {
115-
"address": "123.123.123.123",
116-
"port": "9999",
117-
"password": "demo-paswd",
118-
"timeout": 300,
119-
"method": "chacha20",
120-
"protocol": "auth_aes128_md5",
121-
"protocol_param": "32",
122-
"obfs": "tls1.2_ticket_auth",
123-
"obfs_param": "",
124-
"others": "",
125-
"fastopen": false
126-
}
12788
}
12889

12990
],

js/prepare.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* global Vue */
33
const { app, getCurrentWindow } = require('electron').remote
44
const path = require('path')
5-
// const fs = require('fs-extra')
5+
const fs = require('fs-extra')
66
const url = require('url')
77
const { VRouter } = require('../js/vrouter-local.js')
88
// const { getAppDir } = require('../js/helper.js')
@@ -145,8 +145,9 @@ const vue = new Vue({
145145

146146
async function checkRequirement (vrouter) {
147147
let ret = await vrouter.isVBInstalled()
148-
winston.debug('virtualbox installed')
149-
if (!ret) {
148+
if (ret) {
149+
winston.debug('virtualbox installed')
150+
} else {
150151
winston.warn('no virtualbox installed')
151152
vue.data = {
152153
header: '检测 VirtualBox',
@@ -171,6 +172,7 @@ async function checkRequirement (vrouter) {
171172
vue.show()
172173
return false
173174
}
175+
174176
ret = await vrouter.isVRouterExisted()
175177
if (!ret) {
176178
// if (true) {
@@ -229,7 +231,11 @@ async function checkRequirement (vrouter) {
229231
// closable: false
230232
// }
231233
// vue.show()
232-
await vrouter.upgradeCfg()
234+
const template = path.join(__dirname, '..', 'config', 'config.json')
235+
const newCfg = fs.readJsonSync(template)
236+
await vrouter.upgradeCfgV1(newCfg)
237+
await vrouter.upgradeCfgV2(newCfg)
238+
await vrouter.saveCfg2File()
233239
redirect()
234240
}
235241

js/vrouter-local.js

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,12 +1620,14 @@ echo ""`
16201620

16211621
saveCfg2File () {
16221622
const cfgPath = path.join(this.config.host.configDir, 'config.json')
1623-
return fs.writeJson(cfgPath, this.config, {spaces: 2})
1624-
}
1625-
async upgradeCfg () {
1626-
const template = path.join(__dirname, '..', 'config', 'config.json')
1627-
const newCfg = fs.readJsonSync(template)
1628-
// const oldCfg = fs.readJsonSync(path.join(this.config.host.configDir, 'config.json'))
1623+
console.log(this.config.host.configDir)
1624+
console.log(cfgPath)
1625+
console.log(this.config)
1626+
// return fs.writeJson(cfgPath, this.config, {spaces: 2})
1627+
}
1628+
async upgradeCfgV1 (newCfg) {
1629+
// const template = path.join(__dirname, '..', 'config', 'config.json')
1630+
// const newCfg = fs.readJsonSync(template)
16291631
if (this.config.version === newCfg.version) {
16301632
return
16311633
}
@@ -1665,12 +1667,65 @@ echo ""`
16651667
await remote.service('shadowsocks', 'stop').catch(() => {})
16661668
await remote.service('kcptun', 'stop').catch(() => {})
16671669
await remote.remoteExec('rm /etc/com.icymind.vrouter/ss-dns.json').catch(() => {})
1668-
await remote.changeProxies()
1670+
// await remote.changeProxies()
16691671
await remote.closeConn()
1670-
} else if (this.config.version === '0.2') {
1671-
16721672
}
1673-
return this.saveCfg2File()
1673+
}
1674+
async upgradeCfgV2 (newCfg) {
1675+
// const template = path.join(__dirname, '..', 'config', 'config.json')
1676+
// const newCfg = fs.readJsonSync(template)
1677+
if (this.config.version === '0.2') {
1678+
const profiles = []
1679+
// 如果ss地址不是123123...拷贝到newCfg
1680+
// 同理ssr/kcptun
1681+
const oldSS = this.config.shadowsocks.server
1682+
const oldSSR = this.config.shadowsocksr.server
1683+
const oldKT = this.config.kcptun.server
1684+
if (oldSS.address && oldSS.address !== '123.123.123.123') {
1685+
const profile = {
1686+
'name': '配置oo',
1687+
'mode': 'whitelist',
1688+
'proxies': 'ss',
1689+
'relayUDP': false,
1690+
'enableTunnelDns': true,
1691+
'selectedBL': {'gfwDomains': true, 'extraBlackList': true},
1692+
'selectedWL': {'chinaIPs': true, 'lanNetworks': true, 'extraWhiteList': true},
1693+
'shadowsocks': oldSS
1694+
}
1695+
profiles.push(profile)
1696+
}
1697+
if (oldSSR.address && oldSSR.address !== '123.123.123.123') {
1698+
const profile = {
1699+
'name': '配置xx',
1700+
'mode': 'blacklist',
1701+
'proxies': 'ssr',
1702+
'relayUDP': false,
1703+
'enableTunnelDns': true,
1704+
'selectedBL': {'gfwDomains': true, 'extraBlackList': true},
1705+
'selectedWL': {'chinaIPs': true, 'lanNetworks': true, 'extraWhiteList': true},
1706+
'shadowsocksr': oldSSR
1707+
}
1708+
profiles.push(profile)
1709+
}
1710+
if (oldKT.address && oldKT.address !== '123.123.123.123') {
1711+
const profile = {
1712+
'name': '配置tt',
1713+
'mode': 'whitelist',
1714+
'proxies': 'ssKt',
1715+
'relayUDP': false,
1716+
'enableTunnelDns': true,
1717+
'selectedBL': {'gfwDomains': true, 'extraBlackList': true},
1718+
'selectedWL': {'chinaIPs': true, 'lanNetworks': true, 'extraWhiteList': true},
1719+
'shadowsocks': oldSS,
1720+
'kcptun': oldKT
1721+
}
1722+
profiles.push(profile)
1723+
}
1724+
if (profiles.length !== 0) {
1725+
newCfg.profiles.profiles = profiles
1726+
}
1727+
this.config = newCfg
1728+
}
16741729
}
16751730
async copyTemplate (fileName) {
16761731
const template = path.join(__dirname, '..', 'config', fileName)

0 commit comments

Comments
 (0)