domotz-remote-pawn
Version:
Domotz Agent
83 lines (73 loc) • 2.85 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
**/
/**
*
* Created by Andrea Azzarà <a.azzara@domotz.com> on 10/01/17.
*/
var mod = require('../../../commands/network/vlanConfig');
module.exports.post = function (resourceLocator, onException, onSuccess) {
/*
* Creates a new VLAN on Domotz Agent
* Required JSON attributes in request body (type string): tag, ip_address
* */
return function (req, res) {
var payload = req.body;
var helpers = require('../helpers');
if (!helpers.checkParameters(payload, ['tag', 'ip_address', 'netmask'], res, onException)) {
return;
}
payload.type = 'add';
var command = mod.command({ payload: payload }, resourceLocator);
command.execute(helpers.commandToWeb(onException, onSuccess, res));
};
};
module.exports.get = function (resourceLocator, onException, onSuccess) {
/*
* Retrieves the list of currently configure VLANs. Returns an array
* Example: [{"tag": "231", "ip_address": "192.168.1.100"}]
* */
return function (req, res) {
var payload = {
type: 'list',
};
var command = mod.command({ payload: payload }, resourceLocator);
command.describe();
command.execute(require('../helpers').commandToWeb(onException, onSuccess, res));
};
};
module.exports.delete = function (resourceLocator, onException, onSuccess) {
/*
* If tag parameter is passed (e.g., DELETE /vlan-config/123) the VLAN associated with the tag is removed.
* If tag parameter is missing (e.g., DELETE /vlan-config) the default VLAN configuration is restored.
* */
return function (req, res) {
var payload;
if (req.params && req.params.tag) {
payload = {
type: 'del',
tag: req.params.tag,
};
} else {
payload = {
type: 'reset',
};
}
var command = mod.command({ payload: payload }, resourceLocator);
command.describe();
command.execute(require('../helpers').commandToWeb(onException, onSuccess, res));
};
};