From f52b2e1249f3d92e4a7ef1ca76e01bcfd42a5941 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 21 Nov 2020 12:23:48 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dproxy=E4=BC=98?= =?UTF-8?q?=E9=80=89=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/yarn.lock | 14 ++++++++--- packages/gui/yarn.lock | 25 ++++++++++++------- .../src/lib/interceptor/impl/proxy.js | 3 +-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index 7ff4101b..d4093ba7 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -93,15 +93,16 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@docmirror/mitmproxy@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.1.0.tgz#d2dfa4c8047306c40105e0673365fdb4182be39b" - integrity sha512-KgNQ24o18G3Gnw9F9EkKKIKuEf3EnHh2uASMs72HvmuLobZo+D+0L+lL2xYPp+w5t8aXt0bgQeK8lRcz2C6wWw== +"@docmirror/mitmproxy@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e" + integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg== dependencies: agentkeepalive "^2.1.1" child_process "^1.0.2" colors "^1.1.2" commander "^2.9.0" + crypto-js "^4.0.0" debug "^4.1.1" dns-over-http "^0.2.0" dns-over-tls "^0.0.8" @@ -1199,6 +1200,11 @@ crypto-browserify@^3.11.0: randombytes "^2.0.0" randomfill "^1.0.3" +crypto-js@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc" + integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg== + cyclist@^1.0.1: version "1.0.1" resolved "https://registry.npm.taobao.org/cyclist/download/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" diff --git a/packages/gui/yarn.lock b/packages/gui/yarn.lock index 9b3ba948..eb52e516 100644 --- a/packages/gui/yarn.lock +++ b/packages/gui/yarn.lock @@ -901,12 +901,12 @@ ajv "^6.12.0" ajv-keywords "^3.4.1" -"@docmirror/dev-sidecar@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.1.0.tgz#a77fbbacceedd62202aea581712b13595629756f" - integrity sha512-Amh8m7nArLUvDL7QAfNV4rTaZIOOyS4/DY4+9h/1B9RXRFJ4oGePcBkH6QXO3p0msoutu87BtYXFTl0qvY4vQQ== +"@docmirror/dev-sidecar@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.0.tgz#2320c31f786afd495b8e12557bea396cb96e0985" + integrity sha512-i96YlPjQtrrAgDW52YOpuVFmQDl1A0Nx3x6/riv2yKVN4nGqAugdJvcAuhNi7BDrJfdLyls2jI35uzN5+bpYfQ== dependencies: - "@docmirror/mitmproxy" "^1.1.0" + "@docmirror/mitmproxy" "^1.2.0" agentkeepalive "^2.1.1" charset "^1.0.0" child_process "^1.0.2" @@ -920,6 +920,7 @@ jschardet "^1.4.1" json5 "^2.1.3" lodash "^4.7.0" + log4js "^6.3.0" lru-cache "^6.0.0" mkdirp "^0.5.1" node-cmd "^3.0.0" @@ -932,15 +933,16 @@ validator "^13.1.17" winreg "^1.2.4" -"@docmirror/mitmproxy@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.1.0.tgz#d2dfa4c8047306c40105e0673365fdb4182be39b" - integrity sha512-KgNQ24o18G3Gnw9F9EkKKIKuEf3EnHh2uASMs72HvmuLobZo+D+0L+lL2xYPp+w5t8aXt0bgQeK8lRcz2C6wWw== +"@docmirror/mitmproxy@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e" + integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg== dependencies: agentkeepalive "^2.1.1" child_process "^1.0.2" colors "^1.1.2" commander "^2.9.0" + crypto-js "^4.0.0" debug "^4.1.1" dns-over-http "^0.2.0" dns-over-tls "^0.0.8" @@ -3729,6 +3731,11 @@ crypto-browserify@^3.11.0: randombytes "^2.0.0" randomfill "^1.0.3" +crypto-js@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc" + integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg== + crypto-random-string@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/crypto-random-string/download/crypto-random-string-2.0.0.tgz?cache=0&sync_timestamp=1599139352103&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-random-string%2Fdownload%2Fcrypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" diff --git a/packages/mitmproxy/src/lib/interceptor/impl/proxy.js b/packages/mitmproxy/src/lib/interceptor/impl/proxy.js index b0b4f6c6..d9a70bbb 100644 --- a/packages/mitmproxy/src/lib/interceptor/impl/proxy.js +++ b/packages/mitmproxy/src/lib/interceptor/impl/proxy.js @@ -4,7 +4,7 @@ module.exports = { const { rOptions, log, RequestCounter } = context let proxyConf = interceptOpt.proxy - if (RequestCounter) { + if (RequestCounter && interceptOpt.backup) { // 优选逻辑 const backup = [proxyConf] if (interceptOpt.backup) { @@ -12,7 +12,6 @@ module.exports = { backup.push(bk) } } - backup.push(rOptions.hostname) const key = interceptOpt.key const count = RequestCounter.getOrCreate(key, backup) From abc725c42e78f6db4f23262c39ee8f1c43cfaab8 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 21 Nov 2020 12:28:44 +0800 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index f64f985a..d87718c7 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ ### 5、 npm加速 * 支持开启npm代理 -* 切换npm淘宝registry +* 官方与淘宝npm registry一键切换, * 某些npm install的时候,并且使用cnpm也无法安装时,可以尝试开启npm代理再试 ### 6、 更多加速配置 @@ -88,12 +88,6 @@ 建议遇到打开比较慢的国外网站,可以优先尝试将该域名添加到dns设置中(注意:被GFW封杀的无效) 如果还访问不了,就需要寻找镜像cdn进行拦截代理 -### npm加速 - 1. yarn 设置淘宝镜像registry - 2. npm设置官方registry。 - 3. 项目install使用yarn,发布包publish用npm,互不影响 - 4. 某些库用cnpm也下载不下来的话,可以试试打开dev-sidecar的npm加速 - ### 其他加速 1. git clone 加速 From 5fe5bc70a3d805b3430d3f1c0b849ac09a917c20 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 21 Nov 2020 12:29:11 +0800 Subject: [PATCH 3/8] v1.2.1 --- lerna.json | 2 +- packages/core/package-lock.json | 2 +- packages/core/package.json | 4 ++-- packages/gui/package.json | 6 +++--- packages/mitmproxy/package-lock.json | 2 +- packages/mitmproxy/package.json | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lerna.json b/lerna.json index 828569a2..a205513f 100644 --- a/lerna.json +++ b/lerna.json @@ -14,5 +14,5 @@ "ignore": [] } }, - "version": "1.2.0" + "version": "1.2.1" } diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index 96544c4a..2873ad73 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/core/package.json b/packages/core/package.json index 5af87047..9242539e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar", - "version": "1.2.0", + "version": "1.2.1", "description": "给开发者的加速代理工具", "main": "src/index.js", "keywords": [ @@ -16,7 +16,7 @@ "start": "node ./start" }, "dependencies": { - "@docmirror/mitmproxy": "^1.2.0", + "@docmirror/mitmproxy": "^1.2.1", "agentkeepalive": "^2.1.1", "charset": "^1.0.0", "child_process": "^1.0.2", diff --git a/packages/gui/package.json b/packages/gui/package.json index e3fc8668..f6d09cff 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar-gui", - "version": "1.2.0", + "version": "1.2.1", "private": false, "license": "MPL-2.0", "scripts": { @@ -14,8 +14,8 @@ }, "main": "background.js", "dependencies": { - "@docmirror/dev-sidecar": "^1.2.0", - "@docmirror/mitmproxy": "^1.2.0", + "@docmirror/dev-sidecar": "^1.2.1", + "@docmirror/mitmproxy": "^1.2.1", "ant-design-vue": "^1.6.5", "core-js": "^3.6.5", "electron-baidu-tongji": "^1.0.5", diff --git a/packages/mitmproxy/package-lock.json b/packages/mitmproxy/package-lock.json index d26b3dd6..db21126a 100644 --- a/packages/mitmproxy/package-lock.json +++ b/packages/mitmproxy/package-lock.json @@ -1,6 +1,6 @@ { "name": "@docmirror/mitmproxy", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json index ef9dbab4..760f6894 100644 --- a/packages/mitmproxy/package.json +++ b/packages/mitmproxy/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/mitmproxy", - "version": "1.2.0", + "version": "1.2.1", "description": "", "main": "src/index.js", "keywords": [ From 5bdeb1b65cf9c8967faa67d53f785799e0fbd6e4 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 23 Nov 2020 23:03:43 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dhome=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E8=AE=BE=E7=BD=AE=E4=B8=BAuserprofi?= =?UTF-8?q?le=E6=97=B6=E8=8E=B7=E5=8F=96=E5=88=B0=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=B2=A1=E6=9C=89=E5=86=99=E5=85=A5=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/utils/util.log.js | 2 +- packages/gui/src/bridge/index.js | 2 +- packages/gui/src/utils/util.log.js | 2 +- packages/mitmproxy/src/lib/proxy/common/config.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/utils/util.log.js b/packages/core/src/utils/util.log.js index fa03c416..484bd783 100644 --- a/packages/core/src/utils/util.log.js +++ b/packages/core/src/utils/util.log.js @@ -1,7 +1,7 @@ const log4js = require('log4js') const path = require('path') const getDefaultConfigBasePath = function () { - const userHome = process.env.HOME || process.env.USERPROFILE + const userHome = process.env.USERPROFILE return path.resolve(userHome, './.dev-sidecar') } log4js.configure({ diff --git a/packages/gui/src/bridge/index.js b/packages/gui/src/bridge/index.js index a359b974..9f19a817 100644 --- a/packages/gui/src/bridge/index.js +++ b/packages/gui/src/bridge/index.js @@ -8,7 +8,7 @@ const pk = require('../../package.json') const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') const log = require('../utils/util.log') const getDefaultConfigBasePath = function () { - const userHome = process.env.HOME || process.env.USERPROFILE + const userHome = process.env.USERPROFILE return path.resolve(userHome, './.dev-sidecar') } const localApi = { diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js index 3ca9d959..0a99b1cf 100644 --- a/packages/gui/src/utils/util.log.js +++ b/packages/gui/src/utils/util.log.js @@ -1,7 +1,7 @@ const log4js = require('log4js') const path = require('path') const getDefaultConfigBasePath = function () { - const userHome = process.env.HOME || process.env.USERPROFILE + const userHome = process.env.USERPROFILE return path.resolve(userHome, './.dev-sidecar') } log4js.configure({ diff --git a/packages/mitmproxy/src/lib/proxy/common/config.js b/packages/mitmproxy/src/lib/proxy/common/config.js index 77d508b9..ddd03fd1 100644 --- a/packages/mitmproxy/src/lib/proxy/common/config.js +++ b/packages/mitmproxy/src/lib/proxy/common/config.js @@ -10,7 +10,7 @@ config.defaultPort = 1181 config.caName = 'This certificate is generated locally' config.getDefaultCABasePath = function () { - const userHome = process.env.HOME || process.env.USERPROFILE + const userHome = process.env.USERPROFILE return path.resolve(userHome, './.dev-sidecar') } From 5e80350827dbd7ce77b4430fe4ef54c279d24a0e Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 23 Nov 2020 23:06:42 +0800 Subject: [PATCH 5/8] =?UTF-8?q?docs:=20=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d87718c7..75bf8ad2 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,14 @@ ## 快速开始 目前仅支持windows + ### DevSidecar桌面应用 #### 1 下载安装包 +下载安装包: + +[阿里云](https://dev-sidecar.docmirror.cn/update/DevSidecar-1.2.1.exe) -下载安装包: -[阿里云](https://dev-sidecar.docmirror.cn/update/DevSidecar-1.2.0.exe) [Gitee Release](https://gitee.com/docmirror/dev-sidecar/releases) [Github Release](https://github.com/docmirror/dev-sidecar/releases) @@ -92,7 +94,8 @@ 1. git clone 加速 方式1:快捷复制: - 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接 + > 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接 + 方式2: > 使用方式用实际的名称替换{}的内容,即可加速clone > https://hub.fastgit.org/{username}/{reponame}.git From 0c3be78ba3ac72a35c420785ddcc6318eea7c919 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 24 Nov 2020 00:24:57 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=BC=80=E5=85=B3=E7=8A=B6=E6=80=81=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E5=AE=9E=E6=97=B6=E6=98=BE=E7=A4=BA=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/modules/proxy/index.js | 2 +- packages/gui/package.json | 2 +- packages/gui/src/background.js | 4 +-- packages/gui/src/view/modules/update/index.js | 13 +++++-- packages/gui/src/view/pages/index.vue | 34 +++++++------------ 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/core/src/modules/proxy/index.js b/packages/core/src/modules/proxy/index.js index bc5d3181..56284e3a 100644 --- a/packages/core/src/modules/proxy/index.js +++ b/packages/core/src/modules/proxy/index.js @@ -21,7 +21,7 @@ const ProxyPlugin = function (context) { async unsetProxy () { try { await shell.setSystemProxy() - event.fire('status', { key: 'proxy.enabled', vlaue: false }) + event.fire('status', { key: 'proxy.enabled', value: false }) log.info('关闭系统代理成功') return true } catch (err) { diff --git a/packages/gui/package.json b/packages/gui/package.json index f6d09cff..7ac119fc 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar-gui", - "version": "1.2.1", + "version": "1.2.0", "private": false, "license": "MPL-2.0", "scripts": { diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index e5f22e28..531878c9 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -190,8 +190,8 @@ if (!isFirstInstance) { return true } }) - // updateUrl = 'https://dev-sidecar.docmirror.cn/update/' - updateUrl = 'http://localhost/dev-sidecar/' + updateUrl = 'https://dev-sidecar.docmirror.cn/update/' + // updateUrl = 'http://localhost/dev-sidecar/' } // 自动更新 updateHandle(app, win, beforeQuit, updateUrl) diff --git a/packages/gui/src/view/modules/update/index.js b/packages/gui/src/view/modules/update/index.js index f7eb6c9f..960f9db6 100644 --- a/packages/gui/src/view/modules/update/index.js +++ b/packages/gui/src/view/modules/update/index.js @@ -1,13 +1,16 @@ -let updateParams = { } + function install (app, api) { + const updateParams = app.$global.update = { fromUser: false, autoDownload: true, progress: 0, downloading: false, newVersion: false } api.ipc.on('update', (event, message) => { console.log('on message', event, message) handleUpdateMessage(message, app) }) api.update = { - checkForUpdate (params) { - updateParams = params || { fromUser: false, autoDownload: true, progress: 0 } + checkForUpdate (fromUser) { + if (fromUser != null) { + updateParams.fromUser = fromUser + } api.ipc.send('update', { key: 'checkForUpdate' }) }, downloadUpdate () { @@ -26,6 +29,8 @@ function install (app, api) { noNewVersion() } else if (type === 'downloaded') { // 更新包已下载完成,让用户确认是否更新 + updateParams.downloading = false + console.log('updateParams', updateParams) newUpdateIsReady(message.value) } else if (type === 'progress') { progressUpdate(message.value) @@ -50,6 +55,7 @@ function install (app, api) { if (updateParams.autoDownload !== false) { app.$message.info('发现新版本,正在下载中...') + updateParams.downloading = true api.update.downloadUpdate() return } @@ -70,6 +76,7 @@ function install (app, api) { } function newUpdateIsReady (value) { + updateParams.downloading = false app.$confirm({ title: '新版本已准备好', content: `是否立即升级安装v${value.version}?`, diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue index ad4369a3..14cda756 100644 --- a/packages/gui/src/view/pages/index.vue +++ b/packages/gui/src/view/pages/index.vue @@ -8,9 +8,9 @@ 安装根证书 - + - 检查更新 + {{update.progress}}%{{update.downloading?'新版本下载中':'检查更新'}} @@ -31,7 +31,7 @@ - + @@ -57,7 +57,6 @@ import lodash from 'lodash' import setupCa from '../components/setup-ca' import DsContainer from '../components/container' - export default { name: 'Index', components: { @@ -89,6 +88,7 @@ export default { } }, info: {}, + newVersionDownloading: false, setting: undefined, server: { key: '代理服务', @@ -102,30 +102,20 @@ export default { setupCa: { visible: false }, - update: {} + update: { downloading: false, progress: 0, newVersion: false } } }, async created () { this.doCheckRootCa() - console.log('index created', this.status, this.$status) await this.reloadConfig() - const status = await this.$api.status.get() - console.log('status', status) - this.$set(this, 'status', status) + this.$set(this, 'status', this.$status) this.switchBtns = this.createSwitchBtns() console.log('switchBtns', this.switchBtns) - if (this.$global.update == null) { - this.$global.update = { - fromUser: false, - autoDownload: true, - progress: 0, - newVersion: false - } - this.update = this.$global.update + this.$set(this, 'update', this.$global.update) + if (!this.update.autoChecked) { + this.update.autoChecked = true this.doCheckUpdate(false) } - this.update = this.$global.update - this.$api.info.get().then(ret => { this.info = ret }) @@ -190,7 +180,9 @@ export default { loading: false, key: key, label: label, - status: statusParent, + status: () => { + return statusParent[key].enabled + }, doClick: (checked) => { this.onSwitchClick(this.switchBtns[key], apiTarget.start, apiTarget.close, checked) } @@ -235,7 +227,7 @@ export default { }, doCheckUpdate (fromUser = true) { this.update.fromUser = fromUser - this.$api.update.checkForUpdate(this.update) + this.$api.update.checkForUpdate(this) }, openExternal (url) { this.$api.ipc.openExternal(url) From f085bfbbaf098af4f8369d9ccef71665764d9959 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 24 Nov 2020 00:25:28 +0800 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=20=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E6=94=B9=E5=9B=9E=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gui/package.json b/packages/gui/package.json index 7ac119fc..f6d09cff 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar-gui", - "version": "1.2.0", + "version": "1.2.1", "private": false, "license": "MPL-2.0", "scripts": { From c782d11816c30224fa2a39fe5e10a68e1cdfa04a Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 25 Nov 2020 01:25:47 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E9=87=8D=E6=9E=84=E5=8A=A0=E9=80=9F?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=BC=A0=E5=8F=82=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E5=90=8D=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E6=9C=89=E7=A9=BA=E6=A0=BC=E6=97=B6=E5=AE=89=E8=A3=85=E6=A0=B9?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E7=9B=AE=E5=BD=95=E4=BD=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config.js | 5 ++-- packages/core/src/config/index.js | 16 ++++++++++++ packages/core/src/expose.js | 6 ++--- .../core/src/modules/plugin/node/index.js | 9 ++++--- packages/core/src/modules/server/index.js | 8 ++++-- packages/core/src/shell/scripts/setup-ca.js | 9 +++---- packages/core/src/utils/util.log.js | 7 +++--- packages/core/src/utils/util.proxy.js | 3 +++ packages/core/start/mitmproxy.js | 5 +++- packages/core/start/user_config.json5 | 2 +- packages/gui/src/bridge/index.js | 3 +-- packages/gui/src/bridge/mitmproxy.js | 9 ++++--- packages/gui/src/utils/util.log.js | 5 ++-- packages/gui/src/view/components/setup-ca.vue | 2 -- packages/gui/src/view/pages/index.vue | 7 +++--- packages/gui/src/view/pages/server.vue | 4 +++ packages/mitmproxy/src/index.js | 19 ++++++++------ .../mitmproxy/src/lib/proxy/common/config.js | 8 ++++++ .../src/lib/proxy/mitmproxy/index.js | 25 +++++++++++-------- .../mitmproxy/src/lib/proxy/tls/tlsUtils.js | 5 +--- packages/mitmproxy/src/options.js | 11 ++++++-- packages/mitmproxy/src/utils/util.process.js | 8 ++++++ 22 files changed, 115 insertions(+), 61 deletions(-) create mode 100644 packages/core/src/utils/util.proxy.js create mode 100644 packages/mitmproxy/src/utils/util.process.js diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 1ca2911a..fd922103 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -1,7 +1,7 @@ const Shell = require('./shell') const lodash = require('lodash') const defConfig = require('./config/index.js') -const proxyServer = require('@docmirror/mitmproxy') + let configTarget = lodash.cloneDeep(defConfig) function _deleteDisabledItem (target) { lodash.forEach(target, (item, key) => { @@ -13,6 +13,7 @@ function _deleteDisabledItem (target) { } }) } + const configApi = { get () { return configTarget @@ -68,7 +69,7 @@ const configApi = { }) if (list.length > 0) { const context = { - ca_cert_path: proxyServer.config.getDefaultCACertPath() + root_ca_cert_path: configApi.get().server.setting.rootCaFile.certPath } for (const item of noSetList) { if (item.value.indexOf('${') >= 0) { diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index aeccb9ab..ad5aab56 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -1,3 +1,14 @@ +const path = require('path') +function getUserBasePath () { + const userHome = process.env.USERPROFILE + return path.resolve(userHome, './.dev-sidecar') +} +function getRootCaCertPath () { + return getUserBasePath() + '/dev-sidecar.ca.crt' +} +function getRootCaKeyPath () { + return getUserBasePath() + '/dev-sidecar.ca.key.pem' +} module.exports = { server: { enabled: true, @@ -7,6 +18,11 @@ module.exports = { script: { enabled: true, defaultDir: '../../../scripts/' + }, + userBasePath: getUserBasePath(), + rootCaFile: { + certPath: getRootCaCertPath(), + keyPath: getRootCaKeyPath() } }, intercepts: { diff --git a/packages/core/src/expose.js b/packages/core/src/expose.js index bcf633c6..a69396cc 100644 --- a/packages/core/src/expose.js +++ b/packages/core/src/expose.js @@ -4,15 +4,12 @@ const event = require('./event') const shell = require('./shell') const modules = require('./modules') const lodash = require('lodash') -const proxyServer = require('@docmirror/mitmproxy') -const proxyConfig = proxyServer.config const log = require('./utils/util.log') const context = { config, shell, status, event, - rootCaFile: proxyConfig.getDefaultCACertPath(), log } @@ -127,6 +124,7 @@ module.exports = { shell, server, proxy, - plugin + plugin, + log } } diff --git a/packages/core/src/modules/plugin/node/index.js b/packages/core/src/modules/plugin/node/index.js index 72b1c2fa..8bd62d82 100644 --- a/packages/core/src/modules/plugin/node/index.js +++ b/packages/core/src/modules/plugin/node/index.js @@ -1,6 +1,6 @@ const nodeConfig = require('./config') const NodePlugin = function (context) { - const { config, shell, event, rootCaFile, log } = context + const { config, shell, event, log } = context const nodeApi = { async start () { try { @@ -101,16 +101,17 @@ const NodePlugin = function (context) { NODE_TLS_REJECT_UNAUTHORIZED: false */ const nodeConfig = config.get().plugin.node + const rootCaCertFile = config.get().server.setting.rootCaFile.certPath if (nodeConfig.setting['strict-ssl']) { cmds.push('npm config set strict-ssl false') } if (nodeConfig.setting.cafile) { - cmds.push(`npm config set cafile "${rootCaFile}"`) + cmds.push(`npm config set cafile "${rootCaCertFile}"`) } if (nodeConfig.setting.NODE_EXTRA_CA_CERTS) { - cmds.push(`npm config set NODE_EXTRA_CA_CERTS "${rootCaFile}"`) - env.push({ key: 'NODE_EXTRA_CA_CERTS', value: rootCaFile }) + cmds.push(`npm config set NODE_EXTRA_CA_CERTS "${rootCaCertFile}"`) + env.push({ key: 'NODE_EXTRA_CA_CERTS', value: rootCaCertFile }) } if (nodeConfig.setting.NODE_TLS_REJECT_UNAUTHORIZED) { diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js index df6bd51b..ae042822 100644 --- a/packages/core/src/modules/server/index.js +++ b/packages/core/src/modules/server/index.js @@ -4,6 +4,7 @@ const status = require('../../status') const lodash = require('lodash') const fork = require('child_process').fork const log = require('../../utils/util.log') +const fs = require('fs') let server function fireStatus (status) { event.fire('status', { key: 'server.enabled', value: status }) @@ -45,7 +46,10 @@ const serverApi = { }) } // fireStatus('ing') // 启动中 - const serverProcess = fork(mitmproxyPath, [JSON.stringify(serverConfig)]) + const basePath = serverConfig.setting.userBasePath + const runningConfig = basePath + '/running.json' + fs.writeFileSync(runningConfig, JSON.stringify(serverConfig)) + const serverProcess = fork(mitmproxyPath, [runningConfig]) server = { id: serverProcess.pid, process: serverProcess, @@ -64,7 +68,7 @@ const serverApi = { event.fire('error', { key: 'server', value: 'EADDRINUSE', error: msg.event }) } }) - return { port: config.port } + return { port: runningConfig.port } }, async kill () { if (server) { diff --git a/packages/core/src/shell/scripts/setup-ca.js b/packages/core/src/shell/scripts/setup-ca.js index b9080856..d9ac5204 100644 --- a/packages/core/src/shell/scripts/setup-ca.js +++ b/packages/core/src/shell/scripts/setup-ca.js @@ -1,17 +1,16 @@ const Shell = require('../shell') const execute = Shell.execute -const proxyServer = require('@docmirror/mitmproxy') const executor = { - async windows (exec) { - const cmds = ['start ' + proxyServer.config.getDefaultCACertPath()] + async windows (exec, { certPath }) { + const cmds = ['start "" "' + certPath + '"'] // eslint-disable-next-line no-unused-vars const ret = await exec(cmds, { type: 'cmd' }) return true }, - async linux (exec, { port }) { + async linux (exec, { certPath }) { throw Error('暂未实现此功能') }, - async mac (exec, { port }) { + async mac (exec, { certPath }) { throw Error('暂未实现此功能') } } diff --git a/packages/core/src/utils/util.log.js b/packages/core/src/utils/util.log.js index 484bd783..04c8a5ae 100644 --- a/packages/core/src/utils/util.log.js +++ b/packages/core/src/utils/util.log.js @@ -1,8 +1,7 @@ const log4js = require('log4js') -const path = require('path') -const getDefaultConfigBasePath = function () { - const userHome = process.env.USERPROFILE - return path.resolve(userHome, './.dev-sidecar') +const config = require('../config/index') +function getDefaultConfigBasePath () { + return config.server.setting.userBasePath } log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/core.log' } }, diff --git a/packages/core/src/utils/util.proxy.js b/packages/core/src/utils/util.proxy.js new file mode 100644 index 00000000..8dd2cbd5 --- /dev/null +++ b/packages/core/src/utils/util.proxy.js @@ -0,0 +1,3 @@ +const proxyConfig = require('@docmirror/mitmproxy/config.js') +module.exports = { +} diff --git a/packages/core/start/mitmproxy.js b/packages/core/start/mitmproxy.js index b133da98..f0dc2c6a 100644 --- a/packages/core/start/mitmproxy.js +++ b/packages/core/start/mitmproxy.js @@ -1,7 +1,10 @@ // eslint-disable-next-line no-unused-vars const server = require('@docmirror/mitmproxy') -const config = JSON.parse(process.argv[2]) +const configPath = process.argv[2] +const fs = require('fs') const path = require('path') +const configJson = fs.readFileSync(configPath) +const config = JSON.parse(configJson) const scriptDir = '../../gui/extra/scripts/' config.setting.script.defaultDir = path.join(__dirname, scriptDir) server.start(config) diff --git a/packages/core/start/user_config.json5 b/packages/core/start/user_config.json5 index cbf61b09..4cdefd17 100644 --- a/packages/core/start/user_config.json5 +++ b/packages/core/start/user_config.json5 @@ -6,7 +6,7 @@ abort: true }, } - } + }, }, plugin: { node: { diff --git a/packages/gui/src/bridge/index.js b/packages/gui/src/bridge/index.js index 9f19a817..caa6fd4d 100644 --- a/packages/gui/src/bridge/index.js +++ b/packages/gui/src/bridge/index.js @@ -8,8 +8,7 @@ const pk = require('../../package.json') const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') const log = require('../utils/util.log') const getDefaultConfigBasePath = function () { - const userHome = process.env.USERPROFILE - return path.resolve(userHome, './.dev-sidecar') + return DevSidecar.api.config.get().server.setting.userBasePath } const localApi = { /** diff --git a/packages/gui/src/bridge/mitmproxy.js b/packages/gui/src/bridge/mitmproxy.js index 2d555fcc..acd487ac 100644 --- a/packages/gui/src/bridge/mitmproxy.js +++ b/packages/gui/src/bridge/mitmproxy.js @@ -1,12 +1,15 @@ // eslint-disable-next-line no-unused-vars const server = require('@docmirror/mitmproxy') -const config = JSON.parse(process.argv[2]) +const configPath = process.argv[2] + +const fs = require('fs') const path = require('path') -const log = require('../utils/util.log') +const configJson = fs.readFileSync(configPath) +const config = JSON.parse(configJson) + let scriptDir = '../extra/scripts/' if (process.env.NODE_ENV === 'development') { scriptDir = '../extra/scripts/' } config.setting.script.defaultDir = path.join(__dirname, scriptDir) -log.debug('scriptDir', config.setting.script.defaultDir) server.start(config) diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js index 0a99b1cf..8507a401 100644 --- a/packages/gui/src/utils/util.log.js +++ b/packages/gui/src/utils/util.log.js @@ -1,8 +1,7 @@ const log4js = require('log4js') -const path = require('path') +const DevSidecar = require('@docmirror/dev-sidecar') const getDefaultConfigBasePath = function () { - const userHome = process.env.USERPROFILE - return path.resolve(userHome, './.dev-sidecar') + return DevSidecar.api.config.get().server.setting.userBasePath } log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/gui.log' } }, diff --git a/packages/gui/src/view/components/setup-ca.vue b/packages/gui/src/view/components/setup-ca.vue index 8fccd76d..66867b22 100644 --- a/packages/gui/src/view/components/setup-ca.vue +++ b/packages/gui/src/view/components/setup-ca.vue @@ -24,7 +24,6 @@