-
Notifications
You must be signed in to change notification settings - Fork 6
/
openvpn.js
82 lines (67 loc) · 1.54 KB
/
openvpn.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const EventEmitter = require('events')
const fs = require('fs')
const conf = require('./conf')
let log = require('./log')
let sjs = require('shelljs')
let ip = require('ip')
const OVPN = require('./openvpn2')
class OpenVPN extends EventEmitter
{
constructor()
{
super()
this.dir = sjs.pwd()
this._ip = ''
if (!sjs.test('-d',conf.dir))
sjs.mkdir(conf.dir)
this._ovpn = new OVPN(conf.dir)
}
async start()
{
log.success('Модуль OpenVPN запущен')
return null
}
async install()
{
return true
}
async createServer(srv,reinstall=false)
{
await this._ovpn.createServer(srv)
}
async destroyServer(code)
{
log.log(`удаляем сервер <${code}>`)
sjs.exec(`systemctl stop openvpn@${code}`)
sjs.exec(`systemctl disable openvpn@${code}`)
sjs.rm('-rf',`/etc/openvpn/${code}*`)
sjs.cd(conf.dir)
sjs.rm('-rf',`./${code}_*`)
log.success(`сервер <${code}> удалён`)
}
async startServer(code)
{
log.log(`запускаем сервер <${code}>`)
sjs.exec(`systemctl start openvpn@${code}`)
}
async stopServer(code)
{
log.log(`останавливаем сервер <${code}>`)
sjs.exec(`systemctl stop openvpn@${code}`)
}
async restartServer(code)
{
await this.stopServer(code)
await this.startServer(code)
}
async genCli(srv,cli)
{
await this._ovpn.createClient(srv,cli)
return null
}
async revokeCli(srv,cli)
{
await this._ovpn.dropClient(srv,cli)
}
}
module.exports = OpenVPN