Skip to content

Commit

Permalink
Changed vpncmd param HUB to ADMINHUB
Browse files Browse the repository at this point in the history
Added hub commands hubStatus and hubUserList
  • Loading branch information
notisrac committed Sep 2, 2018
1 parent ad9188d commit aca72e5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
20 changes: 19 additions & 1 deletion modules/softEther.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const csvParseOptions_object = {


var softEther = {
/*
* SERVER COMMANDS
*/
about: function () {
return this.executeHeaderlessCommand('About');
},
Expand Down Expand Up @@ -100,6 +103,20 @@ var softEther = {
return this.executeCSVCommand('VpnAzureGetStatus');
},

/*
* HUB COMMANDS
*/
hubStatus: function (name) {
return this.executeCSVCommand('StatusGet', null, name, 0, 0, csvParseOptions_flat, true);
},
hubUserList: function (name) {
return this.executeCSVCommand('UserList', null, name);
},

/*
* HELPER FUNCTIONS
*/

flattenData: function (data) {
var retData = {};
data.forEach(element => {
Expand Down Expand Up @@ -192,7 +209,8 @@ var softEther = {
}
// select the hub
if (hubName) {
command += ' /HUB:' + hubName;
//command += ' /HUB:' + hubName; // this would require the hub password, and we only have the server pwd
command += ' /ADMINHUB:' + hubName;
}
// the command to execute on the server
command += ' /CMD ' + softEtherCommand;
Expand Down
32 changes: 30 additions & 2 deletions routes/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@ var express = require('express');
var router = express.Router();
var cache = require('../modules/cache');
var cors = require('cors');
var softEther = require('../modules/softEther');

router.use(cors());

router.get('/', function (req, res) {
res.send('hub');
router.get('/:hubName/status', cache(10), function (req, res) {
handleResponse(softEther.hubStatus(getHubName(req)), res);
});
router.get('/:hubName/userList', cache(10), function (req, res) {
handleResponse(softEther.hubUserList(getHubName(req)), res);
});

function getHubName(req) {
return req.params['hubName'];
}

function handleResponse(promise, res) {
promise
.then(function (data) {
sendResult(res, data);
})
.catch(function (err) {
handleError(res, err);
});
}

function sendResult(res, data) {
console.log(data);
res.status(200).send(data);
}

function handleError(res, err) {
console.log(err);
res.status(500);
}

module.exports = router;

0 comments on commit aca72e5

Please sign in to comment.