Skip to content

Commit

Permalink
v2.2.0: authetication mode refactored; requests management improved; …
Browse files Browse the repository at this point in the history
…LR update procedure; package manager added; provisioning system updated.
  • Loading branch information
npeditto committed Jul 26, 2018
1 parent d98dae9 commit f3cc008
Show file tree
Hide file tree
Showing 24 changed files with 2,581 additions and 649 deletions.
2 changes: 1 addition & 1 deletion docs/installation_ubuntu_14.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ during the installation the procedure asks the following information:

* ##### Install dependencies using npm
```
npm install -g --unsafe [email protected] requestify mysql nconf ip express node-uuid autobahn q body-parser ps-node nodemailer nodemailer-smtp-transport swagger-jsdoc cors bcrypt optimist jsonwebtoken md5
npm install -g --unsafe [email protected] requestify mysql nconf ip express node-uuid autobahn q body-parser ps-node nodemailer nodemailer-smtp-transport swagger-jsdoc cors bcrypt optimist jsonwebtoken md5 crypto
npm install -g --unsafe @mdslab/wstun
```
Expand Down
2 changes: 1 addition & 1 deletion docs/installation_ubuntu_16.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ during the installation the procedure asks the following information:

* ##### Install dependencies using npm
```
npm install -g --unsafe [email protected] requestify mysql nconf ip express node-uuid autobahn q body-parser ps-node nodemailer nodemailer-smtp-transport swagger-jsdoc cors bcrypt optimist jsonwebtoken md5
npm install -g --unsafe [email protected] requestify mysql nconf ip express node-uuid autobahn q body-parser ps-node nodemailer nodemailer-smtp-transport swagger-jsdoc cors bcrypt optimist jsonwebtoken md5 crypto
npm install -g --unsafe @mdslab/wstun
```
Expand Down
25 changes: 23 additions & 2 deletions docs/iotronic-docs-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ var genApiDocumentation = function (){

console.log("[API-DOCS] - Starting doc generation...");


if(port == undefined)
var swg_host = IoTronic_IP;
else
var swg_host = IoTronic_IP+':'+port;

// swagger definition
var swaggerDefinition = {
info: {
title: 'IoTronic API',
version: '2.1.0',
description: 'IoTronic-standalone API by Stack4Things.'
},
host: IoTronic_IP+':'+port,
//host: swg_host,
basePath: '/',
licence:{
name: 'Apache v2',
Expand Down Expand Up @@ -227,7 +233,22 @@ if (argv.i != undefined && argv.e != undefined){

IOTRONIC_CFG = process.env.IOTRONIC_HOME + "/settings.json";
nconf.file({file: IOTRONIC_CFG});
IoTronic_IP = nconf.get('config:server:public_ip');

// Set fronted IP address
public_ip = nconf.get('config:server:public_ip');

if (public_ip == "")
IoTronic_IP = utility.getIP(intr, 'IPv4');
else if(public_ip == "env"){
IoTronic_IP = process.env.IOTRONIC_PUB_IP;
}
else if(public_ip == undefined){
logger.error("[SYSTEM] - Iotronic public IP not defined: " + public_ip);
process.exit();
}
else
IoTronic_IP = public_ip;

https_enable = nconf.get('config:server:https:enable');
https_key = nconf.get('config:server:https:key');
https_cert = nconf.get('config:server:https:cert');
Expand Down
172 changes: 98 additions & 74 deletions lib/init_iotronic.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ server_rest_port = null;
iotronic_session = null;
reconnection = false;


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// LOGGING CONFIGURATION
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -119,6 +120,9 @@ var initIoTronicModules = function() {
// Load settings
intr = nconf.get('config:server:interface');
public_ip = nconf.get('config:server:public_ip');
api_ip = nconf.get('config:server:api_ip');
crossbar_pub_ip = nconf.get('config:wamp:crossbar_pub_ip');

topic_connection = nconf.get('config:wamp:topic_connection');
wamp_ssl = nconf.get('config:wamp:ssl');

Expand All @@ -141,36 +145,49 @@ var initIoTronicModules = function() {
docs_url_spec = nconf.get('config:server:docs:expose:url_spec');


if(nconf.get('config:wstun:ip') == "env"){
wstun_ip = process.env.WSTUN_IP;
logger.debug("[SYSTEM] - WSTUN public IP (env):",wstun_ip);
}else
wstun_ip = nconf.get('config:wstun:ip');
// Modules loading flags
vnet_enabled = nconf.get('config:modules:vnets_manager:enabled'); console.log("VNETs Manager: " + vnet_enabled);
service_enabled = nconf.get('config:modules:services_manager:enabled'); console.log("Services Manager: " + service_enabled);
nodered_enabled = nconf.get('config:modules:nodered_manager:enabled'); console.log("Node-RED Manager: " + nodered_enabled);
plugin_enabled = nconf.get('config:modules:plugins_manager:enabled'); console.log("Plugins Manager: " + plugin_enabled);
gpio_enabled = nconf.get('config:modules:gpio_manager:enabled'); console.log("GPIO Manager: " + gpio_enabled);
vfs_enabled = nconf.get('config:modules:vfs_manager:enabled'); console.log("VFS Manager: " + vfs_enabled);
driver_enabled = nconf.get('config:modules:drivers_manager:enabled'); console.log("Drivers Manager: " + driver_enabled);

if(nconf.get('config:wstun:port_range:high') == "env" && nconf.get('config:wstun:port_range:low') == "env"){
wstun_h_port = parseInt(process.env.WSTUN_H_PORT);
wstun_l_port = parseInt(process.env.WSTUN_L_PORT);
logger.debug("[SYSTEM] - WSTUN port range (env):",wstun_l_port, wstun_h_port);
}
else {
wstun_h_port = parseInt(nconf.get('config:wstun:port_range:high'));
wstun_l_port = parseInt(nconf.get('config:wstun:port_range:low'));
logger.debug("[SYSTEM] - WSTUN port range (conf):",wstun_l_port, wstun_h_port);

if(service_enabled){
if(nconf.get('config:modules:services_manager:wstun:public_ip') == "env"){
wstun_ip = process.env.WSTUN_IP;
logger.debug("[SYSTEM] - WSTUN public IP (env):", wstun_ip);
}else
wstun_ip = nconf.get('config:modules:services_manager:wstun:public_ip');

if(nconf.get('config:modules:services_manager:wstun:port_range:high') == "env" && nconf.get('config:modules:services_manager:wstun:port_range:low') == "env"){
wstun_h_port = parseInt(process.env.WSTUN_H_PORT);
wstun_l_port = parseInt(process.env.WSTUN_L_PORT);
logger.debug("[SYSTEM] - WSTUN port range (env):",wstun_l_port, wstun_h_port);
}
else {
wstun_h_port = parseInt(nconf.get('config:modules:services_manager:wstun:port_range:high'));
wstun_l_port = parseInt(nconf.get('config:modules:services_manager:wstun:port_range:low'));
logger.debug("[SYSTEM] - WSTUN port range (conf):",wstun_l_port, wstun_h_port);
}
}



// INIT IoTronic modules
db_utils = require('./management/mng_db');
plugin_utility = require('./modules/plugin_manager');
driver_utility = require('./modules/driver_manager');
vfs_utility = require('./modules/vfs_manager');
gpio_utility = require('./modules/gpio_manager');
nr_utility = require('./modules/nodered_manager');
if(plugin_enabled) plugin_utility = require('./modules/plugin_manager');
if(driver_enabled) driver_utility = require('./modules/driver_manager');
if(vfs_enabled) vfs_utility = require('./modules/vfs_manager');
if(gpio_enabled) gpio_utility = require('./modules/gpio_manager');
if(nodered_enabled) nr_utility = require('./modules/nodered_manager');
if(service_enabled) service_utility = require('./modules/service_manager');


db_utils = require('./management/mng_db');
board_utility = require('./management/mng_board');
utility = require('./management/utility');
service_utility = require('./modules/service_manager');
layout_utility = require('./management/mng_layout');
project_utility = require('./management/mng_project');
user_utility = require('./management/mng_user');
Expand All @@ -197,23 +214,50 @@ var initIoTronicModules = function() {
else if(public_ip == "env"){
IoTronic_IP = process.env.IOTRONIC_PUB_IP;
}
else if(public_ip == undefined){
logger.error("[SYSTEM] - Iotronic public IP not defined: " + public_ip);
process.exit();
}
else
IoTronic_IP = public_ip;


// Init IoTronic Manager
if (net_backend == 'iotronic') {
net_utility = require('./modules/vnet_iotronic_manager');
net_utility.initVNET();
}
/*
else if(net_backend == 'neutron'){
net_utility = require('./modules/vnet_neutron_manager');

if(api_ip == "env")
API_IP = process.env.API_PUB_IP;
else if(api_ip == undefined || api_ip == ""){
logger.error("[SYSTEM] - API IP not defined: " + api_ip);
process.exit();
}
*/
else {
logger.warn("[SYSTEM] - IoTronic does not support this network backend: " + net_backend)
else
API_IP = api_ip;


if(crossbar_pub_ip == "env")
CROSSBAR_IP = process.env.CROSSBAR_PUB_IP;
else if(crossbar_pub_ip == undefined || crossbar_pub_ip == ""){
logger.error("[SYSTEM] - Crossbar IP not defined: " + crossbar_pub_ip);
process.exit();
}
else
CROSSBAR_IP = crossbar_ip;


logger.info("[SYSTEM] - Iotronic public endpoints:\n - WEB_IP: "+IoTronic_IP + "\n - CROSSBAR_IP: "+ CROSSBAR_IP + "\n - API_IP: " + API_IP)


if(vnet_enabled)
// Init IoTronic Manager
if (net_backend == 'iotronic') {
net_utility = require('./modules/vnet_iotronic_manager');
net_utility.initVNET();
}
/*
else if(net_backend == 'neutron'){
net_utility = require('./modules/vnet_neutron_manager');
}
*/
else {
logger.warn("[SYSTEM] - IoTronic does not support this network backend: " + net_backend)
}


// CHECK WSTUN PROCESS STATUS
Expand Down Expand Up @@ -242,6 +286,7 @@ var initIoTronicModules = function() {

var loadIoTronicModules = function(session, rest) {

logger.info("[SYSTEM] -------------------------------------------------------");
logger.info("[SYSTEM] - IoTronic modules loading...");

var d = Q.defer();
Expand All @@ -252,22 +297,30 @@ var loadIoTronicModules = function(session, rest) {
};

try {

// Loading IoTronic modules

logger.info("[SYSTEM] -------------------------------------------------------");
logger.info("[SYSTEM] --> Loading Iotronic libraries:");
board_utils = new board_utility(session, rest);
plugin_utils = new plugin_utility(session, rest);
driver_utils = new driver_utility(session, rest);
net_utils = new net_utility(session, rest);
vfs_utils = new vfs_utility(session, rest);
gpio_utils = new gpio_utility(session, rest);
services_utils = new service_utility(session, rest);
layouts_utils = new layout_utility(session, rest);
projects_utils = new project_utility(session, rest);
users_utils = new user_utility(session, rest);
nr_utils = new nr_utility(session, rest);
requests_utils = new request_utility(session, rest);
logger.info("[SYSTEM] -------------------------------------------------------");


response.message = "IoTronic modules successfully loaded.";

logger.info("[SYSTEM] --> Loading Iotronic modules:");
if(plugin_enabled) plugin_utils = new plugin_utility(session, rest);
if(driver_enabled) driver_utils = new driver_utility(session, rest);
if(vnet_enabled) net_utils = new net_utility(session, rest);
if(vfs_enabled) vfs_utils = new vfs_utility(session, rest);
if(gpio_enabled) gpio_utils = new gpio_utility(session, rest);
if(service_enabled) services_utils = new service_utility(session, rest);
if(nodered_enabled) nr_utils = new nr_utility(session, rest);
logger.info("[SYSTEM] -------------------------------------------------------");


response.message = "IoTronic components successfully loaded.";
response.result = "SUCCESS";
d.resolve(response);

Expand All @@ -291,35 +344,6 @@ var subscribeTopics = function(session, topic_connection, onBoardConnected) {
session.publish(topic_connection, ['Iotronic-connected', session._id]);
};

// NO USED ANYMORE
/*
var mngRpcRegister = function(session){
logger.debug("[SYSTEM] - " + "Registering IoTronic RPCs:");
// CHECK IF IOTRONIC IS ALIVE-------------------------------------------------------------------------------------------------------------------
session.register('s4t.iotronic.isAlive', board_utils.isAlive);
logger.debug('[SYSTEM] --> s4t.iotronic.isAlive');
// ---------------------------------------------------------------------------------------------------------------------------------------------
// PROVISIONING OF A NEW BOARD------------------------------------------------------------------------------------------------------------------
session.register('s4t.board.provisioning', board_utils.Provisioning);
logger.debug('[SYSTEM] --> s4t.board.provisioning');
// ---------------------------------------------------------------------------------------------------------------------------------------------
// BOARD SERVICES RESTORE ON CONNECTION---------------------------------------------------------------------------------------------------------
session.register('s4t.iotronic.service.restore', services_utils.restoreServices);
logger.debug('[SYSTEM] --> s4t.iotronic.service.restore');
// ---------------------------------------------------------------------------------------------------------------------------------------------
// VNET CONFIGURATION INJECTION AFTER BOARD RECONNECTION----------------------------------------------------------------------------------------
session.register('s4t.iotronic.vnet.result_network_board', net_utils.result_network_board);
logger.debug('[SYSTEM] --> s4t.iotronic.vnet.result_network_board');
// ---------------------------------------------------------------------------------------------------------------------------------------------
};
*/

module.exports.initIoTronicModules = initIoTronicModules;
module.exports.loadIoTronicModules = loadIoTronicModules;
Expand Down
21 changes: 15 additions & 6 deletions lib/iotronic_standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//##
//############################################################################################


nconf = require('nconf');
log4js = require('log4js');

Expand Down Expand Up @@ -58,9 +59,16 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {

logger.info("[SYSTEM] - Connected to WAMP router!");

if (https_enable == "true"){
logger.info("[SYSTEM] - Admin dashboard available at https://" + IoTronic_IP + "/iotronic/login");

}else{
logger.info("[SYSTEM] - Admin dashboard available at http://" + IoTronic_IP + "/iotronic/login");
}

iotronic_session = session;

if (IoTronic_IP != undefined) {
if (API_IP != undefined) {

var rest = express();

Expand All @@ -83,9 +91,9 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {

if ( (docs_embedded == "true" || docs_embedded == true) && (docs_exp == "false" || docs_exp == false) ){
if (https_enable == "true"){
link_docs = "https://" + IoTronic_IP + ":" + https_port + "/v1/iotronic-api-docs/";
link_docs = "https://" + API_IP + ":" + https_port + "/v1/iotronic-api-docs/";
}else{
link_docs = "http://" + IoTronic_IP + ":" + http_port + "/v1/iotronic-api-docs/";
link_docs = "http://" + API_IP + ":" + http_port + "/v1/iotronic-api-docs/";
}
res.status(200).send("<center> Welcome in Iotronic-standalone! <br><br><br> <a href="+link_docs+">Please visit API documentation</a> </center>");

Expand Down Expand Up @@ -116,7 +124,7 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {

rest.use(function(req, res, next) {

console.log("URL: " + req.url); console.log("Header:\n" + JSON.stringify(req.headers, null, "\t")); console.log("Body:\n" + JSON.stringify(req.body, null, "\t"));
//console.log("URL: " + req.url); console.log("Header:\n" + JSON.stringify(req.headers, null, "\t")); console.log("Body:\n" + JSON.stringify(req.body, null, "\t"));

var ip_requester = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

Expand Down Expand Up @@ -198,6 +206,7 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {
if (load_result.result == "SUCCESS"){

logger.info("[SYSTEM] - " + load_result.message);
logger.info("[SYSTEM] -------------------------------------------------------");

// REST server starting if there are not errors caught
if (iotronic_status === "OK") {
Expand Down Expand Up @@ -233,7 +242,7 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {

//logger.debug("CREDENTIALS: " + JSON.stringify(credentials));
https.createServer(credentials, rest).listen(https_port, function(){
logger.info("[SYSTEM] - Server REST started on: https://" + IoTronic_IP + ":" + https_port + " - IoTronic CERT: \n" + s4t_cert);
logger.info("[SYSTEM] - Server REST started on: https://" + API_IP + ":" + https_port + " - IoTronic CERT: \n" + s4t_cert);
});

}else{
Expand All @@ -242,7 +251,7 @@ iotronic_standalone.prototype.start = function (wamp_router_url, wamp_realm) {
server_rest_port = http_port;
var http = require('http');
http.createServer(rest).listen(http_port, function(){
logger.info("[SYSTEM] - Server REST started on: http://" + IoTronic_IP + ":" + http_port);
logger.info("[SYSTEM] - Server REST started on: http://" + API_IP + ":" + http_port);
});

}
Expand Down
Loading

0 comments on commit f3cc008

Please sign in to comment.