-
Notifications
You must be signed in to change notification settings - Fork 2
/
vpnlist.js
35 lines (32 loc) · 1.04 KB
/
vpnlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const child_process = require('child_process')
const path = require('path')
const fuzzyfind = require('fuzzyfind')
const file = 'vpnlist'
module.exports = (pluginContext) => {
const { cwd } = pluginContext
return (query, env) => {
return new Promise((resolve, reject) => {
const cmd = 'scutil --nc list'
child_process.exec(cmd, (err, stdout, stderr) => {
if (err) { reject(err) }
const vpnlist = stdout.split('\n').filter(vpn => vpn.match(/ipsec/i))
.map((item) => {
const [_, connection, value] = item.match(/\((.*)\).*"(.*)"/)
const connected = connection === 'Connected'
return {
id: value,
title: value,
icon: (connected) ? 'fa-stop' : 'fa-play',
value: {
name: value,
connected: connected,
}
}
})
// Filter
const filteredVPN = fuzzyfind(query, vpnlist, {accessor: (item) => item.title})
resolve(filteredVPN)
})
})
}
}