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

Commit 11ea091

Browse files
author
icymind
committed
log more infomation to file
1 parent e018a5a commit 11ea091

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

js/manage.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ const myApp = new Vue({
228228
this.profiles.activedProfile -= 1
229229
}
230230
await vrouter.saveCfg2File()
231+
winston.info(`delete profile: ${index}`)
231232
$('#profiles .ui.message.dimmed').dimmer('hide')
232233
},
233234
editProfile (index) {
@@ -243,6 +244,7 @@ const myApp = new Vue({
243244
$('#profiles .ui.message.dimmed').dimmer('hide')
244245
this.ui.activeLoader = true
245246
this.profiles.activedProfile = index
247+
winston.info(`active profile: ${index}`)
246248
await vrouter.saveCfg2File()
247249
await this.remote.applyProfile(index)
248250
await this.refreshInfos()
@@ -257,6 +259,7 @@ const myApp = new Vue({
257259
},
258260
importProfile () {
259261
const uri = document.querySelector('#importProfileModal input').value
262+
winston.info(`import profile: ${uri}`)
260263
try {
261264
this.editingProfile = vrouter.parseProfileURI(uri)
262265
this.toggleProfileEditor('show')
@@ -303,6 +306,7 @@ const myApp = new Vue({
303306
} else {
304307
this.profiles.profiles[id] = JSON.parse(JSON.stringify(this.editingProfile))
305308
}
309+
winston.info(`save profile: ${this.editingProfile}`)
306310
await vrouter.saveCfg2File()
307311
this.toggleProfileEditor('hide')
308312

@@ -338,6 +342,7 @@ const myApp = new Vue({
338342
this.status.currentGW = 'default'
339343
this.status.currentDns = 'default'
340344
}
345+
winston.info(`checkTrafficStatus: currentGW=${this.status.currentGW}, currentDns=${this.status.currentDns}`)
341346
const isGWVRouter = this.status.currentGW === 'vrouter'
342347
this.ui.btnToggleRouterPopup = isGWVRouter ? '停止接管流量' : '开始接管流量'
343348
// this.toggleBlink(isGWVRouter)
@@ -631,19 +636,6 @@ document.addEventListener('DOMContentLoaded', async () => {
631636
$('.tabular.menu .item').tab()
632637
$('.dropdown').dropdown()
633638
$('*[data-content]').popup()
634-
// $('#profileModal').modal({
635-
// dimmerSettings: {
636-
// opacity: 0.2
637-
// },
638-
// detachable: false,
639-
// closable: false
640-
// })
641-
// $('#importProfileModal').modal({
642-
// dimmerSettings: {
643-
// opacity: 0.2
644-
// },
645-
// detachable: false
646-
// })
647639
$('#profiles .ui.message').dimmer({
648640
opacity: 0,
649641
on: 'hover',

js/vrouter-local.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,19 @@ class VRouter {
6969
return new Promise((resolve, reject) => {
7070
sudo.exec(cmd, option, (err, stdout, stderr) => {
7171
if (err) {
72-
// console.log(err)
7372
reject(err)
7473
} else {
75-
// stderr && console.log(stderr)
7674
resolve(stdout || stderr)
7775
}
7876
})
7977
})
8078
}
8179
localExec (cmd) {
82-
// const specialCmd = [
83-
// /^VBoxManage hostonlyif .*$/ig,
84-
// /^VBoxManage startvm/ig,
85-
// /^VBoxManage controlvm .* poweroff/ig,
86-
// /^VBoxManage convertfromraw .ig
87-
// ]
88-
8980
return new Promise((resolve, reject) => {
9081
exec(cmd, (err, stdout, stderr) => {
9182
if (err) {
92-
// console.log(err)
9383
reject(err)
9484
} else {
95-
// stderr && console.log(stderr)
9685
resolve(stdout || stderr)
9786
}
9887
})
@@ -116,6 +105,7 @@ class VRouter {
116105
return this.localExec(cmd)
117106
}
118107
async getOSXNetworkService (inf) {
108+
// 返回 en{0-9} 对应的网络服务
119109
const cmd = `/usr/sbin/networksetup -listnetworkserviceorder`
120110
const output = await this.localExec(cmd)
121111
const reg = /\(\d+\) (.*)\n\(Hardware Port: .*?, Device: (.*)\)/g
@@ -446,37 +436,42 @@ EOF`
446436
}
447437
async startvm (type = 'headless', waitTime = 100) {
448438
const state = await this.getvmState()
449-
if (state !== 'running') {
450-
const cmd = `${VBoxManage} startvm --type ${type} ${this.config.vrouter.name}`
451-
await this.localExec(cmd)
452-
await this.wait(1000)
453-
await this.sendKeystrokes()
454-
// skip grub's waiting time
455-
await this.wait(500)
456-
await this.sendKeystrokes()
457-
await this.wait(waitTime)
439+
if (state === 'running') {
440+
return
458441
}
442+
const cmd = `${VBoxManage} startvm --type ${type} ${this.config.vrouter.name}`
443+
await this.localExec(cmd)
444+
await this.wait(1000)
445+
await this.sendKeystrokes()
446+
// skip grub's waiting time
447+
await this.wait(500)
448+
await this.sendKeystrokes()
449+
await this.wait(waitTime)
459450
}
460451
async stopvm (action = 'savestate', waitTime = 100) {
461452
const serialPortState = await this.isSerialPortOn()
462453
const vmState = await this.getvmState()
463454
if (vmState === 'running') {
464455
winston.debug(`about to stop vm. current State: ${vmState}. action: ${action}`)
465456
if (action === 'force') {
457+
winston.debug('vrouter poweroff by controlvm')
466458
const cmd = `${VBoxManage} controlvm ${this.config.vrouter.name} poweroff`
467459
await this.localExec(cmd)
468460
return this.wait(waitTime)
469461
} else if (action === 'poweroff') {
470462
if (serialPortState) {
471463
// poweroff from inside openwrt is more safer.
464+
winston.debug('poweroff by serialExec')
472465
await this.serialExec('poweroff', 'poweroff')
473466
return this.wait(8000)
474467
} else {
468+
winston.debug('vrouter poweroff by controlvm')
475469
const cmd = `${VBoxManage} controlvm ${this.config.vrouter.name} poweroff`
476470
await this.localExec(cmd)
477471
return this.wait(waitTime)
478472
}
479473
} else if (action === 'savestate') {
474+
winston.debug('vrouter savestate')
480475
const cmd = `${VBoxManage} controlvm ${this.config.vrouter.name} savestate`
481476
await this.localExec(cmd)
482477
return this.wait(waitTime)
@@ -524,9 +519,6 @@ EOF`
524519
return state
525520
}
526521
async isVRouterRunning () {
527-
// State: running (since 2017-06-16T02:13:09.066000000)
528-
// VBoxManage showvminfo com.icymind.test --machinereadable | grep vmState
529-
// vmState="running"
530522
const cmd = `${VBoxManage} list runningvms`
531523
const stdout = await this.localExec(cmd)
532524
const vms = stdout
@@ -551,7 +543,6 @@ EOF`
551543
return this.localExec(cmd)
552544
}
553545
async getHostonlyInf () {
554-
// return [correspondingInf, firstAvailableInf]
555546
const infs = await this.getAllInf()
556547
const reg = /^vboxnet\d+.*\n(?:\t.*\n)*/img
557548
let correspondingInf = null

js/vrouter-remote.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const winston = require('winston')
12
const path = require('path')
23
class VRouterRemote {
34
// todo: reconnect
@@ -7,6 +8,17 @@ class VRouterRemote {
78
this.config = config
89
this.local = local
910
this.sftp = sftp
11+
winston.configure({
12+
transports: [
13+
new (winston.transports.File)({
14+
filename: path.join(this.config.host.configDir, 'vrouter.log'),
15+
level: 'info'
16+
}),
17+
new (winston.transports.Console)({
18+
level: 'debug'
19+
})
20+
]
21+
})
1022
}
1123

1224
// vm
@@ -40,6 +52,7 @@ class VRouterRemote {
4052
})
4153
}
4254
async scp (src, dest) {
55+
winston.info(`scp ${src} to vrouter:${dest}`)
4356
let isDestDir = false
4457
if (dest.endsWith('/')) {
4558
isDestDir = true
@@ -180,6 +193,7 @@ class VRouterRemote {
180193
})
181194
}
182195
service (name, action) {
196+
winston.info(`${action} service: ${name}`)
183197
const cmd = `/etc/init.d/${name} ${action}`
184198
return this.remoteExec(cmd)
185199
}

0 commit comments

Comments
 (0)