@ -1,28 +0,0 @@
|
||||
{ |
||||
server: { |
||||
port: 1181 |
||||
}, |
||||
"intercepts": { |
||||
'notify3.note.youdao.com': [ |
||||
{ |
||||
regexp: '.*', |
||||
redirect: 'https://localhost:99999' |
||||
} |
||||
] |
||||
}, |
||||
"dns": { |
||||
"mapping": { |
||||
//"avatars*.githubusercontent.com": "usa" |
||||
} |
||||
}, |
||||
// setting: { |
||||
// startup: { |
||||
// // 开机启动 |
||||
// server: true, |
||||
// proxy: { |
||||
// system: true, |
||||
// npm: true |
||||
// } |
||||
// } |
||||
// } |
||||
} |
@ -0,0 +1,10 @@
|
||||
const killByPort = require('./scripts/kill-by-port') |
||||
const setupCa = require('./scripts/setup-ca') |
||||
const getEnv = require('./scripts/get-env') |
||||
const setEnv = require('./scripts/set-env') |
||||
module.exports = { |
||||
killByPort, |
||||
setupCa, |
||||
getEnv, |
||||
setEnv |
||||
} |
@ -0,0 +1,31 @@
|
||||
/** |
||||
* 获取环境变量 |
||||
*/ |
||||
const Shell = require('../shell') |
||||
const execute = Shell.execute |
||||
const executor = { |
||||
async windows (exec) { |
||||
const ret = await exec(['set'], { type: 'cmd' }) |
||||
const map = {} |
||||
if (ret != null) { |
||||
const lines = ret.split('\r\n') |
||||
for (const item of lines) { |
||||
const kv = item.split('=') |
||||
if (kv.length > 1) { |
||||
map[kv[0]] = kv[1] |
||||
} |
||||
} |
||||
} |
||||
return map |
||||
}, |
||||
async linux (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
}, |
||||
async mac (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
} |
||||
} |
||||
|
||||
module.exports = async function (args) { |
||||
return execute(executor, args) |
||||
} |
@ -0,0 +1,21 @@
|
||||
const Shell = require('../shell') |
||||
const execute = Shell.execute |
||||
|
||||
const executor = { |
||||
async windows (exec, { port }) { |
||||
const cmds = [`for /f "tokens=5" %a in ('netstat -aon ^| find ":${port}" ^| find "LISTENING"') do taskkill /f /pid %a`] |
||||
// eslint-disable-next-line no-unused-vars
|
||||
const ret = await exec(cmds, { type: 'cmd' }) |
||||
return true |
||||
}, |
||||
async linux (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
}, |
||||
async mac (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
} |
||||
} |
||||
|
||||
module.exports = async function (args) { |
||||
return execute(executor, args) |
||||
} |
@ -0,0 +1,26 @@
|
||||
/** |
||||
* 设置环境变量 |
||||
*/ |
||||
const Shell = require('../shell') |
||||
const execute = Shell.execute |
||||
const executor = { |
||||
async windows (exec, { list }) { |
||||
const cmds = [] |
||||
for (const item of list) { |
||||
// [Environment]::SetEnvironmentVariable('FOO', 'bar', 'Machine')
|
||||
cmds.push(`[Environment]::SetEnvironmentVariable('${item.key} ', '${item.value}', 'Machine')`) |
||||
} |
||||
const ret = await exec(cmds, { type: 'ps' }) |
||||
return ret |
||||
}, |
||||
async linux (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
}, |
||||
async mac (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
} |
||||
} |
||||
|
||||
module.exports = async function (args) { |
||||
return execute(executor, args) |
||||
} |
@ -0,0 +1,21 @@
|
||||
const Shell = require('../shell') |
||||
const execute = Shell.execute |
||||
const proxyConfig = require('../../lib/proxy/common/config') |
||||
const executor = { |
||||
async windows (exec) { |
||||
const cmds = ['start ' + proxyConfig.getDefaultCACertPath()] |
||||
// eslint-disable-next-line no-unused-vars
|
||||
const ret = await exec(cmds, { type: 'cmd' }) |
||||
return true |
||||
}, |
||||
async linux (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
}, |
||||
async mac (exec, { port }) { |
||||
throw Error('暂未实现此功能') |
||||
} |
||||
} |
||||
|
||||
module.exports = async function (args) { |
||||
return execute(executor, args) |
||||
} |
@ -0,0 +1,111 @@
|
||||
const util = require('util') |
||||
const os = require('os') |
||||
const childProcess = require('child_process') |
||||
const _exec = childProcess.exec |
||||
const exec = util.promisify(_exec) |
||||
const Shell = require('node-powershell') |
||||
|
||||
class SystemShell { |
||||
static async exec (cmds, args) { |
||||
throw new Error('You have to implement the method exec!') |
||||
} |
||||
} |
||||
|
||||
class LinuxSystemShell extends SystemShell { |
||||
static async exec (cmds) { |
||||
if (cmds instanceof String) { |
||||
cmds = [cmds] |
||||
} |
||||
for (const cmd of cmds) { |
||||
await exec(cmd) |
||||
} |
||||
} |
||||
} |
||||
|
||||
class DarwinSystemShell extends SystemShell { |
||||
static async exec (cmds) { |
||||
if (cmds instanceof String) { |
||||
cmds = [cmds] |
||||
} |
||||
for (const cmd of cmds) { |
||||
await exec(cmd) |
||||
} |
||||
} |
||||
} |
||||
|
||||
class WindowsSystemShell extends SystemShell { |
||||
static async exec (cmds, { type = 'ps' }) { |
||||
if (cmds instanceof String) { |
||||
cmds = [cmds] |
||||
} |
||||
if (type === 'ps') { |
||||
const ps = new Shell({ |
||||
executionPolicy: 'Bypass', |
||||
noProfile: true |
||||
}) |
||||
|
||||
for (const cmd of cmds) { |
||||
console.log('ps:', cmd) |
||||
ps.addCommand(cmd) |
||||
} |
||||
|
||||
const ret = await ps.invoke() |
||||
console.log('ps complete:', ret) |
||||
return ret |
||||
} else { |
||||
let compose = 'chcp 65001 ' |
||||
for (const cmd of cmds) { |
||||
compose += ' && ' + cmd |
||||
} |
||||
return new Promise((resolve, reject) => { |
||||
childProcess.exec(compose, function (error, stdout, stderr) { |
||||
if (error) { |
||||
console.error('cmd 命令执行错误:', compose, error, stderr) |
||||
reject(error) |
||||
} else { |
||||
const data = stdout |
||||
resolve(data) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
function getSystemShell () { |
||||
switch (getSystemPlatform()) { |
||||
case 'mac': |
||||
return DarwinSystemShell |
||||
case 'linux': |
||||
return LinuxSystemShell |
||||
case 'windows': |
||||
return WindowsSystemShell |
||||
case 'unknown os': |
||||
default: |
||||
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`) |
||||
} |
||||
} |
||||
function getSystemPlatform () { |
||||
switch (os.platform()) { |
||||
case 'darwin': |
||||
return 'mac' |
||||
case 'linux': |
||||
return 'linux' |
||||
case 'win32': |
||||
case 'win64': |
||||
return 'windows' |
||||
case 'unknown os': |
||||
default: |
||||
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`) |
||||
} |
||||
} |
||||
|
||||
async function execute (executor, args) { |
||||
return executor[getSystemPlatform()](getSystemShell().exec, args) |
||||
} |
||||
|
||||
module.exports = { |
||||
getSystemShell, |
||||
getSystemPlatform, |
||||
execute |
||||
} |
@ -0,0 +1,20 @@
|
||||
const cmd1 = require('node-cmd') |
||||
cmd1.get('set', |
||||
function (err, data, stderr) { |
||||
console.log('cmd complete:', err, data, stderr) |
||||
if (err) { |
||||
console.error('cmd 命令执行错误:', err, stderr) |
||||
} else { |
||||
console.log('cmd 命令执行结果:', data) |
||||
} |
||||
} |
||||
) |
||||
|
||||
// var process = require('child_process')
|
||||
//
|
||||
// var cmd = 'set'
|
||||
// process.exec(cmd, function (error, stdout, stderr) {
|
||||
// console.log('error:' + error)
|
||||
// console.log('stdout:' + stdout)
|
||||
// console.log('stderr:' + stderr)
|
||||
// })
|
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 941 B |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 353 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 941 B |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 353 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 51 KiB |
@ -0,0 +1,61 @@
|
||||
<template> |
||||
<a-drawer |
||||
placement="right" |
||||
:closable="false" |
||||
:visible="visible" |
||||
:after-visible-change="afterVisibleChange" |
||||
@close="onClose" |
||||
width="650px" |
||||
height="100%" |
||||
:slots="{ title: 'title' }" |
||||
wrapClassName="json-wrapper" |
||||
> |
||||
<template slot="title"> |
||||
{{title}} |
||||
<a-button type="primary" style="float:right" @click="doSetup()">点此去安装</a-button> |
||||
</template> |
||||
<img width="100%" src="/setup.png" /> |
||||
|
||||
</a-drawer> |
||||
</template> |
||||
|
||||
<script> |
||||
import api from '../api' |
||||
export default { |
||||
name: 'setup-ca', |
||||
components: { |
||||
|
||||
}, |
||||
props: { |
||||
title: { |
||||
type: String, |
||||
default: '安装根证书' |
||||
}, |
||||
visible: { |
||||
type: Boolean |
||||
} |
||||
}, |
||||
data () { |
||||
return { |
||||
} |
||||
}, |
||||
created () { |
||||
}, |
||||
methods: { |
||||
afterVisibleChange (val) { |
||||
}, |
||||
showDrawer () { |
||||
this.$emit('update:visible', true) |
||||
}, |
||||
onClose () { |
||||
this.$emit('update:visible', false) |
||||
}, |
||||
doSetup () { |
||||
api.shell.setupCa() |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style> |
||||
</style> |
@ -0,0 +1,45 @@
|
||||
import api from './api' |
||||
import status from './status' |
||||
import lodash from 'lodash' |
||||
function register (app) { |
||||
api.on('status', (event, message) => { |
||||
console.log('view on status', event, message) |
||||
const value = message.value |
||||
const key = message.key |
||||
lodash.set(status, key, value) |
||||
}) |
||||
|
||||
api.on('error.core', (event, message) => { |
||||
console.error('view on error', message) |
||||
const key = message.key |
||||
if (key === 'server.start') { |
||||
handleServerStartError(message.error, app) |
||||
} |
||||
}) |
||||
api.on('error', (event, message) => { |
||||
console.error('error', event, message) |
||||
}) |
||||
} |
||||
|
||||
function handleServerStartError (err, app) { |
||||
if (err.message.indexOf('listen EADDRINUSE') >= 0) { |
||||
app.$confirm({ |
||||
title: '端口被占用,代理服务启动失败', |
||||
content: '是否要杀掉占用进程?', |
||||
onOk () { |
||||
// TODO 杀掉进程
|
||||
api.config.get().then(config => { |
||||
console.log('config', config) |
||||
api.shell.killByPort({ port: config.server.port }).then(ret => { |
||||
app.$message.info('杀掉进程成功,请重试开启代理服务') |
||||
}) |
||||
}) |
||||
}, |
||||
onCancel () { |
||||
console.log('Cancel') |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
export default register |
@ -1 +1,5 @@
|
||||
import './status' |
||||
import register from './event' |
||||
export default { |
||||
register |
||||
} |
||||
|