diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index 9ef515c..b7ba710 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -236,7 +236,9 @@ module.exports = { '*github.com': 'quad9', '*.vuepress.vuejs.org': 'quad9', 'gh.docmirror.top': 'quad9', - '*v2ex.com': 'quad9' + '*v2ex.com': 'quad9', + '*pypi.org':'quad9', + '*jetbrains.com':'quad9' }, speedTest: { enabled: true, diff --git a/packages/core/src/modules/proxy/index.js b/packages/core/src/modules/proxy/index.js index 56284e3..3bc05e0 100644 --- a/packages/core/src/modules/proxy/index.js +++ b/packages/core/src/modules/proxy/index.js @@ -28,6 +28,12 @@ const ProxyPlugin = function (context) { log.error('关闭系统代理失败', err) return false } + }, + + async setEnableLoopback () { + await shell.enableLoopback() + log.info('打开EnableLoopback成功') + return true } } return api diff --git a/packages/core/src/shell/index.js b/packages/core/src/shell/index.js index c7cfec5..41355c0 100644 --- a/packages/core/src/shell/index.js +++ b/packages/core/src/shell/index.js @@ -6,6 +6,8 @@ const setSystemEnv = require('./scripts/set-system-env') const getNpmEnv = require('./scripts/get-npm-env') const setNpmEnv = require('./scripts/set-npm-env') const setSystemProxy = require('./scripts/set-system-proxy/index') +const enableLoopback = require('./scripts/enable-loopback') +const extraPath = require('./scripts/extra-path') module.exports = { killByPort, setupCa, @@ -14,6 +16,8 @@ module.exports = { getNpmEnv, setNpmEnv, setSystemProxy, + enableLoopback, + extraPath, async exec (cmds, args) { return shell.getSystemShell().exec(cmds, args) }, diff --git a/packages/core/src/shell/scripts/enable-loopback.js b/packages/core/src/shell/scripts/enable-loopback.js new file mode 100644 index 0000000..42d380d --- /dev/null +++ b/packages/core/src/shell/scripts/enable-loopback.js @@ -0,0 +1,22 @@ +/** + */ +const Shell = require('../shell') +const extraPath = require('./extra-path') +const execute = Shell.execute +const executor = { + async windows (exec) { + const loopbackPath = extraPath.getEnableLoopbackPath() + const execFile = Shell.execFile + await execFile(loopbackPath) + }, + async linux (exec, { port }) { + throw Error('不支持此操作') + }, + async mac (exec, { port }) { + throw Error('不支持此操作') + } +} + +module.exports = async function (args) { + return execute(executor, args) +} diff --git a/packages/core/src/shell/scripts/extra-path/EnableLoopback.exe b/packages/core/src/shell/scripts/extra-path/EnableLoopback.exe new file mode 100644 index 0000000..1dcac71 Binary files /dev/null and b/packages/core/src/shell/scripts/extra-path/EnableLoopback.exe differ diff --git a/packages/core/src/shell/scripts/set-system-proxy/clear.bat b/packages/core/src/shell/scripts/extra-path/clear.bat similarity index 100% rename from packages/core/src/shell/scripts/set-system-proxy/clear.bat rename to packages/core/src/shell/scripts/extra-path/clear.bat diff --git a/packages/core/src/shell/scripts/extra-path/index.js b/packages/core/src/shell/scripts/extra-path/index.js new file mode 100644 index 0000000..eb890d2 --- /dev/null +++ b/packages/core/src/shell/scripts/extra-path/index.js @@ -0,0 +1,31 @@ +const log = require('../../../utils/util.log') +const path = require('path') + +function getExtraPath () { + let extraPath = process.env.DS_EXTRA_PATH + log.info('extraPath', extraPath) + if (!extraPath) { + extraPath = __dirname + } + return extraPath +} + +function getProxyExePath () { + const extraPath = getExtraPath() + return path.join(extraPath, 'sysproxy.exe') +} + +function getClearBatPath () { + const extraPath = getExtraPath() + return path.join(extraPath, 'clear.bat') +} + +function getEnableLoopbackPath () { + const extraPath = getExtraPath() + return path.join(extraPath, 'EnableLoopback.exe') +} +module.exports = { + getProxyExePath, + getEnableLoopbackPath, + getClearBatPath +} diff --git a/packages/core/src/shell/scripts/set-system-proxy/sysproxy.exe b/packages/core/src/shell/scripts/extra-path/sysproxy.exe similarity index 100% rename from packages/core/src/shell/scripts/set-system-proxy/sysproxy.exe rename to packages/core/src/shell/scripts/extra-path/sysproxy.exe diff --git a/packages/core/src/shell/scripts/set-system-proxy/index.js b/packages/core/src/shell/scripts/set-system-proxy/index.js index 8cee8a8..a00713d 100644 --- a/packages/core/src/shell/scripts/set-system-proxy/index.js +++ b/packages/core/src/shell/scripts/set-system-proxy/index.js @@ -13,6 +13,7 @@ const childProcess = require('child_process') const util = require('util') const fs = require('fs') const _exec = util.promisify(childProcess.exec) +const extraPath = require('../extra-path/index') const _lanIP = [ 'localhost', '127.*', @@ -33,95 +34,13 @@ const _lanIP = [ '172.29.*', '172.30.*', '172.31.*', - '192.168.*' + '192.168.*', + '<-loopback>' ] -const logoffScriptPath = 'C:\\WINDOWS\\System32\\GroupPolicy\\User\\Scripts\\scripts.ini' - -function buildScriptBody (addHeader = true, index = 0) { - const batPath = getClearBatPath() - const header = addHeader ? '[Logoff]\r\n' : '' - return `${header}${index}CmdLine=${batPath} -${index}Parameters=` -} - -async function addClearScriptIni () { - const batPath = getClearBatPath() - let body - if (fs.existsSync(logoffScriptPath)) { - body = fs.readFileSync(logoffScriptPath) - if (body.indexOf(batPath) >= 0) { - return - } - let index = 0 - // 要加新的 - if (body.indexOf('[Logoff]') >= 0) { - // 如果有logoff了 - const list = body.trim().split('\n') - let lastParameters = -1 - for (const string of list) { - if (string.indexOf('Parameters') >= 0) { - lastParameters = parseInt(string.trim().charAt(0)) - } - } - index = lastParameters + 1 - body += '\r\n' + buildScriptBody(false, index) - } else { - body += '\r\n' + buildScriptBody(true, 0) - } - } else { - body = buildScriptBody(true, 0) - } - fs.writeFileSync(logoffScriptPath, body) -} - -async function removeClearScriptIni () { - if (!fs.existsSync(logoffScriptPath)) { - return - } - const batPath = getClearBatPath() - let body = fs.readFileSync(logoffScriptPath) - if (body.indexOf(batPath) === -1) { - return - } - - // 有就要删除 - body = body.trim() - const list = body.split('\n') - let lastParameters = -1 - for (const string of list) { - if (string.indexOf(batPath) >= 0) { - lastParameters = parseInt(string.trim().charAt(0)) - } - } - body = body.replace(`${lastParameters}CmdLine=${batPath}`, '') - body = body.replace(`${lastParameters}Parameters=`, '') - body = body.trim() - fs.writeFileSync(logoffScriptPath, body) -} - -function getExtraPath () { - let extraPath = process.env.DS_EXTRA_PATH - log.info('extraPath', extraPath) - if (!extraPath) { - extraPath = __dirname - } - return extraPath -} - -function getProxyExePath () { - const extraPath = getExtraPath() - return path.join(extraPath, 'sysproxy.exe') -} - -function getClearBatPath () { - const extraPath = getExtraPath() - return path.join(extraPath, 'clear.bat') -} - async function _winUnsetProxy (exec) { // eslint-disable-next-line no-constant-condition - const proxyPath = getProxyExePath() + const proxyPath = extraPath.getProxyExePath() await execFile(proxyPath, ['set', '1']) try { // await removeClearScriptIni() @@ -135,7 +54,7 @@ async function _winSetProxy (exec, ip, port) { for (const string of _lanIP) { lanIpStr += string + ';' } - const proxyPath = getProxyExePath() + const proxyPath = extraPath.getProxyExePath() await execFile(proxyPath, ['global', `${ip}:${port}`, lanIpStr]) try { // await addClearScriptIni() diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index 5c88eb2..8167af4 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -93,10 +93,10 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@docmirror/mitmproxy@^1.5.1": - version "1.5.1" - resolved "https://registry.nlark.com/@docmirror/mitmproxy/download/@docmirror/mitmproxy-1.5.1.tgz#357142a41b89266491c3519a7528b9b83dc30c85" - integrity sha1-NXFCpBuJJmSRw1GadSi5uD3DDIU= +"@docmirror/mitmproxy@^1.6.2": + version "1.6.2" + resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.6.2.tgz#51c7792d7d172820250822abbaacf148e629666c" + integrity sha512-JF/cJzHuV23TTN1oS+r32Qole/u37H8H36ycO06IjxmOfXx5pu0nqeOTMe3bWTXLI1YlnlktVNOH72xH73C1Fg== dependencies: agentkeepalive "^2.1.1" axios "^0.21.1" diff --git a/packages/gui/package.json b/packages/gui/package.json index e3a190b..9be3229 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -30,6 +30,7 @@ "electron-baidu-tongji": "^1.0.5", "electron-reload": "^1.5.0", "electron-store": "^6.0.1", + "electron-sudo": "^4.0.12", "electron-updater": "^4.3.5", "es-abstract": "^1.17.7", "extract-zip": "^2.0.1", diff --git a/packages/gui/public/loopback.png b/packages/gui/public/loopback.png new file mode 100644 index 0000000..c78eacd Binary files /dev/null and b/packages/gui/public/loopback.png differ diff --git a/packages/gui/src/bridge/api/open-enable-loopback.js b/packages/gui/src/bridge/api/open-enable-loopback.js new file mode 100644 index 0000000..666aa8d --- /dev/null +++ b/packages/gui/src/bridge/api/open-enable-loopback.js @@ -0,0 +1,12 @@ +import Sudoer from 'electron-sudo' +import DevSidecar from '@docmirror/dev-sidecar' +export default { + async open () { + const options = { name: '设置loopback' } + const sudoer = new Sudoer(options) + const exeFile = DevSidecar.api.shell.extraPath.getEnableLoopbackPath() + await sudoer.exec( + exeFile, { env: { PARAM: 'VALUE' } } + ) + } +} diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue index b81b0c5..d6847b8 100644 --- a/packages/gui/src/view/pages/index.vue +++ b/packages/gui/src/view/pages/index.vue @@ -86,8 +86,8 @@ 捐赠
-
如果它解决了你的问题,请不要吝啬你的star哟! - +
如果它解决了你的问题,请不要吝啬你的star哟!点这里 +
star diff --git a/packages/gui/src/view/pages/proxy.vue b/packages/gui/src/view/pages/proxy.vue index 76a90ff..afd5754 100644 --- a/packages/gui/src/view/pages/proxy.vue +++ b/packages/gui/src/view/pages/proxy.vue @@ -18,6 +18,10 @@ 当前未启动 + + 去设置 +
解决OneNote、微软应用商店、微软邮箱等大部分系统自带应用无法访问网络问题。点击去设置,然后按下图所示操作即可
+
+ + + +
+
解决OneNote、微软应用商店、微软邮箱等大部分系统自带应用无法访问网络问题。点击右上方按钮,然后按下图所示操作即可
+
注意:此操作需要DevSidecar以管理员身份启动,才能打开下面的EnableLoopback设置界面
+ +
+ +
@@ -36,7 +61,8 @@ export default { mixins: [Plugin], data () { return { - key: 'proxy' + key: 'proxy', + loopbackVisible: false } }, created () { @@ -45,7 +71,17 @@ export default { mounted () { }, methods: { - + async openEnableLoopback () { + try { + await this.$api.proxy.setEnableLoopback() + } catch (e) { + if (e.message.indexOf('EACCES') !== -1) { + this.$message.error('请将DevSidecar关闭后,以管理员身份重新打开,再尝试此操作') + return + } + this.$message.error('打开失败:' + e.message) + } + } } } diff --git a/packages/mitmproxy/yarn-error.log b/packages/mitmproxy/yarn-error.log index 7d21ab4..119ee30 100644 --- a/packages/mitmproxy/yarn-error.log +++ b/packages/mitmproxy/yarn-error.log @@ -1,25 +1,25 @@ Arguments: - /usr/bin/node /usr/local/bin/yarn install + D:\Soft\Development\nodejs\node.exe C:\Users\xiaojunnuo\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js install PATH: - /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + D:\Codes\open\dev-sidecar\node_modules\.bin;D:\Soft\Development\python\Scripts\;D:\Soft\Development\python\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Soft\Development\Git\cmd;D:\Soft\Development\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\xiaojunnuo\AppData\Local\Microsoft\WindowsApps;;D:\Soft\Development\IntelliJ IDEA 2021.2.3\bin;;C:\Users\xiaojunnuo\AppData\Roaming\npm;D:\Soft\Development\PyCharm 2021.2.3\bin; Yarn version: - 1.22.11 + 1.22.17 Node version: - 14.17.5 + 16.13.0 Platform: - linux x64 + win32 x64 Trace: - Error: ENOENT: no such file or directory, copyfile '/home/xiaojunnuo/.cache/yarn/v6/npm-webpack-4.44.2-6bfe2b0af055c8b2d1e90ed2cd9363f841266b72-integrity/node_modules/webpack/declarations/plugins/BannerPlugin.d.ts' -> '/home/xiaojunnuo/Codes/dev-sidecar/packages/mitmproxy/node_modules/webpack/declarations/plugins/BannerPlugin.d.ts' + Error: ENOENT: no such file or directory, copyfile 'C:\Users\xiaojunnuo\AppData\Local\Yarn\Cache\v6\npm-ms-2.0.0-5608aeadfc00be6c2901df5f9861788de0d597c8-integrity\node_modules\ms\index.js' -> 'D:\Codes\open\dev-sidecar\packages\mitmproxy\node_modules\eslint-plugin-import\node_modules\ms\index.js' npm manifest: { "name": "@docmirror/mitmproxy", - "version": "1.5.1", + "version": "1.6.2", "description": "", "main": "src/index.js", "keywords": [ @@ -85,7 +85,7 @@ npm manifest: "last 2 versions", "not dead" ], - "gitHead": "3566cd6d33cbe782d91e408d6f174dd826b2790f" + "gitHead": "9b027af3ee7e88975a54692ed83096802764a8dc" } yarn manifest: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..c1368ed --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,5 @@ +packages: + # all packages in subdirs of packages/ and components/ + - 'packages/**' + # exclude packages that are inside test directories + - '!**/test/**'