Separate vpn connecting.

This commit is contained in:
Pagan Gazzard 2014-12-23 19:11:28 +00:00 committed by Pablo Carranza Vélez
parent a7f5689873
commit c5506d4566
2 changed files with 18 additions and 13 deletions

View File

@ -3,7 +3,6 @@ fs = Promise.promisifyAll(require('fs'))
os = require 'os'
knex = require './db'
utils = require './utils'
{spawn} = require 'child_process'
bootstrap = require './bootstrap'
config = require './config'
@ -32,19 +31,10 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
api = require './api'
application = require './application'
supervisor = require './supervisor-update'
vpn = require './lib/vpn'
console.log('Starting OpenVPN..')
openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data')
# Prefix and log all OpenVPN output
openvpn.stdout.on 'data', (data) ->
prefix = 'OPENVPN: '
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
# Prefix and log all OpenVPN output
openvpn.stderr.on 'data', (data) ->
prefix = 'OPENVPN: '
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
setImmediate(vpn.connect)
console.log('Starting API server..')
api.listen(80)

View File

@ -1,8 +1,10 @@
Promise = require 'bluebird'
_ = require 'lodash'
csrgen = Promise.promisify require 'csr-gen'
fs = Promise.promisifyAll require 'fs'
request = Promise.promisifyAll require 'request'
url = require 'url'
{spawn} = require 'child_process'
exports.generate = (apiEndpoint, userConfig) ->
# Generate SSL certificate
@ -49,4 +51,17 @@ exports.generate = (apiEndpoint, userConfig) ->
fs.writeFileAsync('/data/ca.crt', body.ca)
fs.writeFileAsync('/data/client.crt', body.cert)
vpnConf
])
])
exports.connect = ->
openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data')
# Prefix and log all OpenVPN output
openvpn.stdout.on 'data', (data) ->
prefix = 'OPENVPN: '
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
# Prefix and log all OpenVPN output
openvpn.stderr.on 'data', (data) ->
prefix = 'OPENVPN: '
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))