@@ -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