issue20: check that elem is defined

This commit is contained in:
Key Networks 2019-08-17 20:35:13 +08:00
parent b197655aa1
commit 537a567e29
7 changed files with 127 additions and 128 deletions

View File

@ -8,76 +8,74 @@ const fs = require('fs');
const ipaddr = require('ip-address'); const ipaddr = require('ip-address');
const storage = require('node-persist'); const storage = require('node-persist');
const zt = require('./zt'); const zt = require('./zt');
const util = require('util');
storage.initSync({dir: 'etc/storage'}); storage.initSync({dir: 'etc/storage'});
var nav =
{
active: '',
whence: ''
}
// ZT network controller home page // ZT network controller home page
exports.index = async function(req, res) { exports.index = async function(req, res) {
nav = const navigate =
{ {
active: 'controller_home', active: 'controller_home',
} }
try { try {
zt_address = await zt.get_zt_address(); zt_address = await zt.get_zt_address();
res.render('index', {title: 'ztncui', nav: nav, zt_address: zt_address}); res.render('index', {title: 'ztncui', navigate: navigate, zt_address: zt_address});
} catch (err) { } catch (err) {
res.render('index', {title: 'ztncui', res.render('index', {title: 'ztncui',
nav: nav, error: 'ERROR resolving ZT address: ' + err}); navigate: navigate, error: 'ERROR resolving ZT address: ' + err});
} }
}; };
// Display list of all networks on this ZT network controller // Display list of all networks on this ZT network controller
exports.network_list = async function(req, res) { exports.network_list = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
} }
try { try {
networks = await zt.network_list(); networks = await zt.network_list();
res.render('networks', {title: 'Networks on this controller', nav: nav, networks: networks}); res.render('networks', {title: 'Networks on this controller', navigate: navigate, networks: networks});
} catch (err) { } catch (err) {
res.render('networks', {title: 'Networks on this controller', nav: nav, error: 'Error retrieving list of networks on this controller: ' + err}); res.render('networks', {title: 'Networks on this controller', navigate: navigate, error: 'Error retrieving list of networks on this controller: ' + err});
} }
}; };
// Display detail page for specific network // Display detail page for specific network
exports.network_detail = async function(req, res) { exports.network_detail = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
} }
console.log('NAVIGATE = ' + navigate.toString());
console.log(util.inspect(navigate, false, null, true /* enable colors */))
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
const members = await zt.members(req.params.nwid); const members = await zt.members(req.params.nwid);
res.render('network_detail', {title: 'Detail for network', nav: nav, network: network, members: members}); res.render('network_detail', {title: 'Detail for network', navigate: navigate, network: network, members: members});
} catch (err) { } catch (err) {
res.render('network_detail', {title: 'Detail for network', nav: nav, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err}); res.render('network_detail', {title: 'Detail for network', navigate: navigate, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err});
} }
}; };
// Display Network create form on GET // Display Network create form on GET
exports.network_create_get = function(req, res) { exports.network_create_get = function(req, res) {
nav = const navigate =
{ {
active: 'add_network', active: 'add_network',
} }
res.render('network_create', {title: 'Create network', nav: nav}); res.render('network_create', {title: 'Create network', navigate: navigate});
}; };
// Handle Network create on POST // Handle Network create on POST
exports.network_create_post = async function(req, res) { exports.network_create_post = async function(req, res) {
nav = const navigate =
{ {
active: 'add_network', active: 'add_network',
} }
@ -92,21 +90,21 @@ exports.network_create_post = async function(req, res) {
let name = { name: req.body.name }; let name = { name: req.body.name };
if (errors) { if (errors) {
res.render('network_create', {title: 'Create Network', nav: nav, name: name, errors: errors}); res.render('network_create', {title: 'Create Network', navigate: navigate, name: name, errors: errors});
return; return;
} else { } else {
try { try {
const network = await zt.network_create(name); const network = await zt.network_create(name);
res.redirect('/controller/networks'); res.redirect('/controller/networks');
} catch (err) { } catch (err) {
res.render('network_detail', {title: 'Create Network - error', nav: nav, error: 'Error creating network ' + name.name}); res.render('network_detail', {title: 'Create Network - error', navigate: navigate, error: 'Error creating network ' + name.name});
} }
} }
}; };
// Display Network delete form on GET // Display Network delete form on GET
exports.network_delete_get = async function(req, res) { exports.network_delete_get = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -114,16 +112,16 @@ exports.network_delete_get = async function(req, res) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
res.render('network_delete', {title: 'Delete network', nav: nav, res.render('network_delete', {title: 'Delete network', navigate: navigate,
nwid: req.params.nwid, network: network}); nwid: req.params.nwid, network: network});
} catch (err) { } catch (err) {
res.render('network_delete', {title: 'Delete network', nav: nav, error: 'Error resolving network ' + req.params.nwid + ': ' + err}); res.render('network_delete', {title: 'Delete network', navigate: navigate, error: 'Error resolving network ' + req.params.nwid + ': ' + err});
} }
}; };
// Handle Network delete on POST // Handle Network delete on POST
exports.network_delete_post = async function(req, res) { exports.network_delete_post = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -131,15 +129,15 @@ exports.network_delete_post = async function(req, res) {
try { try {
const network = await zt.network_delete(req.params.nwid); const network = await zt.network_delete(req.params.nwid);
res.render('network_delete', {title: 'Delete network', nav: nav, network: network}); res.render('network_delete', {title: 'Delete network', navigate: navigate, network: network});
} catch (err) { } catch (err) {
res.render('network_delete', {title: 'Delete network', nav: nav, error: 'Error deleting network ' + req.params.nwid + ': ' + err}); res.render('network_delete', {title: 'Delete network', navigate: navigate, error: 'Error deleting network ' + req.params.nwid + ': ' + err});
} }
}; };
// Network object GET // Network object GET
exports.network_object = async function(req, res) { exports.network_object = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -147,24 +145,24 @@ exports.network_object = async function(req, res) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render(req.params.object, {title: req.params.object, nav: nav, network: network}, function(err, html) { res.render(req.params.object, {title: req.params.object, navigate: navigate, network: network}, function(err, html) {
if (err) { if (err) {
if (err.message.indexOf('Failed to lookup view') !== -1 ) { if (err.message.indexOf('Failed to lookup view') !== -1 ) {
return res.render('not_implemented', {title: req.params.object, nav: nav, network: network}); return res.render('not_implemented', {title: req.params.object, navigate: navigate, network: network});
} }
throw err; throw err;
} }
res.send(html); res.send(html);
}); });
} catch (err) { } catch (err) {
res.render(req.params.object, {title: req.params.object, nav: nav, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err}); res.render(req.params.object, {title: req.params.object, navigate: navigate, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err});
} }
} }
// Handle Network rename form on POST // Handle Network rename form on POST
exports.name = async function(req, res) { exports.name = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -181,16 +179,16 @@ exports.name = async function(req, res) {
if (errors) { if (errors) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
res.render('name', {title: 'Rename network', nav: nav, network: network, name: name, errors: errors}); res.render('name', {title: 'Rename network', navigate: navigate, network: network, name: name, errors: errors});
} catch (err) { } catch (err) {
res.render('name', {title: 'Rename network', nav: nav, error: 'Error resolving network detail for network ' + req.params.nwid + ': ' + err}); res.render('name', {title: 'Rename network', navigate: navigate, error: 'Error resolving network detail for network ' + req.params.nwid + ': ' + err});
} }
} else { } else {
try { try {
const network = await zt.network_object(req.params.nwid, name); const network = await zt.network_object(req.params.nwid, name);
res.redirect('/controller/networks'); res.redirect('/controller/networks');
} catch ( err) { } catch ( err) {
res.render('name', {title: 'Rename network', nav: nav, error: 'Error renaming network ' + req.params.nwid + ': ' + err}); res.render('name', {title: 'Rename network', navigate: navigate, error: 'Error renaming network ' + req.params.nwid + ': ' + err});
} }
} }
@ -198,7 +196,7 @@ exports.name = async function(req, res) {
// ipAssignmentPools POST // ipAssignmentPools POST
exports.ipAssignmentPools = async function(req, res) { exports.ipAssignmentPools = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -224,18 +222,18 @@ exports.ipAssignmentPools = async function(req, res) {
if (errors) { if (errors) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, ipAssignmentPool: ipAssignmentPool, network: network, errors: errors}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network, errors: errors});
} catch (err) { } catch (err) {
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, error: 'Error resolving network detail for network ' + req.params.nwid + ': ' + err}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, error: 'Error resolving network detail for network ' + req.params.nwid + ': ' + err});
} }
} else { } else {
try { try {
const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'add'); const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'add');
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, ipAssignmentPool: ipAssignmentPool, network: network}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network});
} catch (err) { } catch (err) {
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, error: 'Error applying IP Assignment Pools for network ' + req.params.nwid + ': ' + err}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, error: 'Error applying IP Assignment Pools for network ' + req.params.nwid + ': ' + err});
} }
} }
} }
@ -247,7 +245,7 @@ isValidPrefix = function(str, max) {
// routes POST // routes POST
exports.routes = async function (req, res) { exports.routes = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -291,18 +289,18 @@ exports.routes = async function (req, res) {
if (errors) { if (errors) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('routes', {title: 'routes', nav: nav, route: route, network: network, errors: errors}); res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network, errors: errors});
} catch (err) { } catch (err) {
res.render('routes', {title: 'routes', nav: nav, error: 'Error resolving network detail'}); res.render('routes', {title: 'routes', navigate: navigate, error: 'Error resolving network detail'});
} }
} else { } else {
try { try {
const network = await zt.routes(req.params.nwid, route, 'add'); const network = await zt.routes(req.params.nwid, route, 'add');
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('routes', {title: 'routes', nav: nav, route: route, network: network}); res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network});
} catch (err) { } catch (err) {
res.render('routes', {title: 'routes', nav: nav, error: 'Error adding route for network ' + req.params.nwid + ': ' + err}); res.render('routes', {title: 'routes', navigate: navigate, error: 'Error adding route for network ' + req.params.nwid + ': ' + err});
} }
} }
@ -310,7 +308,7 @@ exports.routes = async function (req, res) {
// route_delete GET // route_delete GET
exports.route_delete = async function (req, res) { exports.route_delete = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -325,16 +323,16 @@ exports.route_delete = async function (req, res) {
try { try {
const network = await zt.routes(req.params.nwid, route, 'delete'); const network = await zt.routes(req.params.nwid, route, 'delete');
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('routes', {title: 'routes', nav: nav, route: route, network: network}); res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network});
} catch (err) { } catch (err) {
res.render('routes', {title: 'routes', nav: nav, error: 'Error deleting route for network ' + req.params.nwid + ': ' + err}); res.render('routes', {title: 'routes', navigate: navigate, error: 'Error deleting route for network ' + req.params.nwid + ': ' + err});
} }
} }
// ipAssignmentPool_delete GET // ipAssignmentPool_delete GET
exports.ipAssignmentPool_delete = async function (req, res) { exports.ipAssignmentPool_delete = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -349,16 +347,16 @@ exports.ipAssignmentPool_delete = async function (req, res) {
try { try {
const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'delete'); const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'delete');
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, ipAssignmentPool: ipAssignmentPool, network: network}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network});
} catch (err) { } catch (err) {
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', nav: nav, error: 'Error deleting IP Assignment Pool for network ' + req.params.nwid + ': ' + err}); res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, error: 'Error deleting IP Assignment Pool for network ' + req.params.nwid + ': ' + err});
} }
} }
// private POST // private POST
exports.private = async function (req, res) { exports.private = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -371,16 +369,16 @@ exports.private = async function (req, res) {
try { try {
const network = await zt.network_object(req.params.nwid, private); const network = await zt.network_object(req.params.nwid, private);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('private', {title: 'private', nav: nav, network: network}); res.render('private', {title: 'private', navigate: navigate, network: network});
} catch (err) { } catch (err) {
res.render('private', {title: 'private', nav: nav, error: 'Error applying private for network ' + req.params.nwid + ': ' + err}); res.render('private', {title: 'private', navigate: navigate, error: 'Error applying private for network ' + req.params.nwid + ': ' + err});
} }
} }
// v4AssignMode POST // v4AssignMode POST
exports.v4AssignMode = async function (req, res) { exports.v4AssignMode = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -393,16 +391,16 @@ exports.v4AssignMode = async function (req, res) {
try { try {
const network = await zt.network_object(req.params.nwid, v4AssignMode); const network = await zt.network_object(req.params.nwid, v4AssignMode);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('v4AssignMode', {title: 'v4AssignMode', nav: nav, network: network}); res.render('v4AssignMode', {title: 'v4AssignMode', navigate: navigate, network: network});
} catch (err) { } catch (err) {
res.render('v4AssignMode', {title: 'v4AssignMode', nav: nav, error: 'Error applying v4AssignMode for network ' + req.params.nwid + ': ' + err}); res.render('v4AssignMode', {title: 'v4AssignMode', navigate: navigate, error: 'Error applying v4AssignMode for network ' + req.params.nwid + ': ' + err});
} }
} }
// v6AssignMode POST // v6AssignMode POST
exports.v6AssignMode = async function (req, res) { exports.v6AssignMode = async function (req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -420,16 +418,16 @@ exports.v6AssignMode = async function (req, res) {
try { try {
const network = await zt.network_object(req.params.nwid, v6AssignMode); const network = await zt.network_object(req.params.nwid, v6AssignMode);
nav.whence = '/controller/network/' + network.nwid; navigate.whence = '/controller/network/' + network.nwid;
res.render('v6AssignMode', {title: 'v6AssignMode', nav: nav, network: network}); res.render('v6AssignMode', {title: 'v6AssignMode', navigate: navigate, network: network});
} catch (err) { } catch (err) {
res.render('v6AssignMode', {title: 'v6AssignMode', nav: nav, error: 'Error applying v6AssignMode for network ' + req.params.nwid + ': ' + err}); res.render('v6AssignMode', {title: 'v6AssignMode', navigate: navigate, error: 'Error applying v6AssignMode for network ' + req.params.nwid + ': ' + err});
} }
} }
// Display detail page for specific member // Display detail page for specific member
exports.member_detail = async function(req, res) { exports.member_detail = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -441,16 +439,16 @@ exports.member_detail = async function(req, res) {
let name = await storage.getItem(member.id); let name = await storage.getItem(member.id);
if (!name) name = ''; if (!name) name = '';
member.name = name; member.name = name;
nav.whence = '/controller/network/' + network.nwid + '/members'; navigate.whence = '/controller/network/' + network.nwid + '/members';
res.render('member_detail', {title: 'Network member detail', nav: nav, network: network, member: member}); res.render('member_detail', {title: 'Network member detail', navigate: navigate, network: network, member: member});
} catch (err) { } catch (err) {
res.render(req.params.object, {title: req.params.object, nav: nav, error: 'Error resolving detail for member ' + req.params.id + ' of network ' + req.params.nwid + ': ' + err}); res.render(req.params.object, {title: req.params.object, navigate: navigate, error: 'Error resolving detail for member ' + req.params.id + ' of network ' + req.params.nwid + ': ' + err});
} }
}; };
// Member object GET // Member object GET
exports.member_object = async function(req, res) { exports.member_object = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -462,24 +460,24 @@ exports.member_object = async function(req, res) {
let name = await storage.getItem(member.id); let name = await storage.getItem(member.id);
if (!name) name = ''; if (!name) name = '';
member.name = name; member.name = name;
nav.whence = '/controller/network/' + network.nwid + '/members'; navigate.whence = '/controller/network/' + network.nwid + '/members';
res.render(req.params.object, {title: req.params.object, nav: nav, network: network, member: member}, function(err, html) { res.render(req.params.object, {title: req.params.object, navigate: navigate, network: network, member: member}, function(err, html) {
if (err) { if (err) {
if (err.message.indexOf('Failed to lookup view') !== -1 ) { if (err.message.indexOf('Failed to lookup view') !== -1 ) {
return res.render('not_implemented', {title: req.params.object, nav: nav, network: network, member: member}); return res.render('not_implemented', {title: req.params.object, navigate: navigate, network: network, member: member});
} }
throw err; throw err;
} }
res.send(html); res.send(html);
}); });
} catch (err) { } catch (err) {
res.render(req.params.object, {title: req.params.object, nav: nav, error: 'Error resolving detail for member ' + req.params.id + ' of network ' + req.params.nwid + ': ' + err}); res.render(req.params.object, {title: req.params.object, navigate: navigate, error: 'Error resolving detail for member ' + req.params.id + ' of network ' + req.params.nwid + ': ' + err});
} }
} }
// Easy network setup GET // Easy network setup GET
exports.easy_get = async function(req, res) { exports.easy_get = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -487,15 +485,15 @@ exports.easy_get = async function(req, res) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
res.render('network_easy', {title: 'Easy setup of network', nav: nav, network: network}); res.render('network_easy', {title: 'Easy setup of network', navigate: navigate, network: network});
} catch (err) { } catch (err) {
res.render('network_easy', {title: 'Easy setup of network', nav: nav, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err}); res.render('network_easy', {title: 'Easy setup of network', navigate: navigate, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err});
} }
} }
// Easy network setup POST // Easy network setup POST
exports.easy_post = async function(req, res) { exports.easy_post = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -549,23 +547,23 @@ exports.easy_post = async function(req, res) {
v4AssignMode: v4AssignMode v4AssignMode: v4AssignMode
}; };
res.render('network_easy', {title: 'Easy setup of network', nav: nav, network: network, errors: errors}); res.render('network_easy', {title: 'Easy setup of network', navigate: navigate, network: network, errors: errors});
} else { } else {
try { try {
const network = await zt.network_easy_setup(req.params.nwid, const network = await zt.network_easy_setup(req.params.nwid,
routes, routes,
ipAssignmentPools, ipAssignmentPools,
v4AssignMode); v4AssignMode);
res.render('network_easy', {title: 'Easy setup of network', nav: nav, network: network, message: 'Network setup succeeded'}); res.render('network_easy', {title: 'Easy setup of network', navigate: navigate, network: network, message: 'Network setup succeeded'});
} catch (err) { } catch (err) {
res.render('network_easy', {title: 'Easy setup of network', nav: nav, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err}); res.render('network_easy', {title: 'Easy setup of network', navigate: navigate, error: 'Error resolving detail for network ' + req.params.nwid + ': ' + err});
} }
} }
} }
// Easy members auth GET or POST // Easy members auth GET or POST
exports.members = async function(req, res) { exports.members = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '/controller/networks' whence: '/controller/networks'
@ -645,10 +643,10 @@ exports.members = async function(req, res) {
members.push(member); members.push(member);
} }
res.render('members', {title: 'Members of this network', nav: nav, res.render('members', {title: 'Members of this network', navigate: navigate,
network: network, members: members, errors: errors}); network: network, members: members, errors: errors});
} catch (err) { } catch (err) {
res.render('members', {title: 'Members of this network', nav: nav, res.render('members', {title: 'Members of this network', navigate: navigate,
error: 'Error resolving detail for network ' + req.params.nwid error: 'Error resolving detail for network ' + req.params.nwid
+ ': ' + err}); + ': ' + err});
} }
@ -656,7 +654,7 @@ exports.members = async function(req, res) {
// Member delete GET or POST // Member delete GET or POST
exports.member_delete = async function(req, res) { exports.member_delete = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -678,11 +676,11 @@ exports.member_delete = async function(req, res) {
if (!name) name = ''; if (!name) name = '';
member.name = name; member.name = name;
nav.whence = '/controller/network/' + network.nwid + '/members'; navigate.whence = '/controller/network/' + network.nwid + '/members';
res.render('member_delete', {title: 'Delete member from ' + network.name, res.render('member_delete', {title: 'Delete member from ' + network.name,
nav: nav, network: network, member: member}); navigate: navigate, network: network, member: member});
} catch (err) { } catch (err) {
res.render('member_delete', {title: 'Delete member from network', nav: nav, res.render('member_delete', {title: 'Delete member from network', navigate: navigate,
error: 'Error resolving detail for member ' + req.params.id error: 'Error resolving detail for member ' + req.params.id
+ ' of network ' + req.params.nwid + ': ' + err}); + ' of network ' + req.params.nwid + ': ' + err});
} }
@ -690,7 +688,7 @@ exports.member_delete = async function(req, res) {
// ipAssignment delete GET // ipAssignment delete GET
exports.delete_ip = async function(req, res) { exports.delete_ip = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -699,7 +697,7 @@ exports.delete_ip = async function(req, res) {
try { try {
const network = await zt.network_detail(req.params.nwid); const network = await zt.network_detail(req.params.nwid);
let member = await zt.member_detail(req.params.nwid, req.params.id); let member = await zt.member_detail(req.params.nwid, req.params.id);
nav.whence = '/controller/network/' + network.nwid + '/members'; navigate.whence = '/controller/network/' + network.nwid + '/members';
let name = await storage.getItem(member.id); let name = await storage.getItem(member.id);
if (!name) name = ''; if (!name) name = '';
member.name = name; member.name = name;
@ -710,9 +708,9 @@ exports.delete_ip = async function(req, res) {
member.id + '/ipAssignments'); member.id + '/ipAssignments');
} }
res.render('ipAssignments', {title: 'ipAssignments ' + network.name, res.render('ipAssignments', {title: 'ipAssignments ' + network.name,
nav: nav, index: req.params.index, network: network, member: member}); navigate: navigate, index: req.params.index, network: network, member: member});
} catch (err) { } catch (err) {
res.render('ipAssignments', {title: 'ipAssignments', nav: nav, res.render('ipAssignments', {title: 'ipAssignments', navigate: navigate,
error: 'Error resolving detail for member ' + req.params.id error: 'Error resolving detail for member ' + req.params.id
+ ' of network ' + req.params.nwid + ': ' + err}); + ' of network ' + req.params.nwid + ': ' + err});
} }
@ -720,7 +718,7 @@ exports.delete_ip = async function(req, res) {
// ipAssignments POST // ipAssignments POST
exports.assign_ip = async function(req, res) { exports.assign_ip = async function(req, res) {
nav = const navigate =
{ {
active: 'networks', active: 'networks',
whence: '' whence: ''
@ -760,7 +758,7 @@ exports.assign_ip = async function(req, res) {
try { try {
let member = await zt.member_detail(req.params.nwid, req.params.id); let member = await zt.member_detail(req.params.nwid, req.params.id);
nav.whence = '/controller/network/' + network.nwid + '/members'; navigate.whence = '/controller/network/' + network.nwid + '/members';
if (!errors) { if (!errors) {
member = await zt.ipAssignmentAdd(network.nwid, member.id, ipAssignment); member = await zt.ipAssignmentAdd(network.nwid, member.id, ipAssignment);
@ -770,11 +768,11 @@ exports.assign_ip = async function(req, res) {
if (!name) name = ''; if (!name) name = '';
member.name = name; member.name = name;
res.render('ipAssignments', {title: 'ipAssignments', nav: nav, res.render('ipAssignments', {title: 'ipAssignments', navigate: navigate,
ipAssignment: ipAssignment, network: network, member: member, ipAssignment: ipAssignment, network: network, member: member,
errors: errors}); errors: errors});
} catch (err) { } catch (err) {
res.render('ipAssignments', {title: 'ipAssignments', nav: nav, res.render('ipAssignments', {title: 'ipAssignments', navigate: navigate,
error: 'Error resolving detail for member ' + req.params.id error: 'Error resolving detail for member ' + req.params.id
+ ' of network ' + req.params.nwid + ': ' + err}); + ' of network ' + req.params.nwid + ': ' + err});
} }

View File

@ -44,21 +44,21 @@ update_users = async function(users) {
} }
exports.users_list = async function(req, res) { exports.users_list = async function(req, res) {
const nav = const navigate =
{ {
active: 'users', active: 'users',
} }
try { try {
const users = await get_users(); const users = await get_users();
res.render('users', { title: 'Admin users', nav: nav, message: 'List of users with admin priviledges', users: users }); res.render('users', { title: 'Admin users', navigate: navigate, message: 'List of users with admin priviledges', users: users });
} catch (err) { } catch (err) {
res.render('users', { title: 'Admin users', nav: nav, message: 'Error', users: null, error: 'Error returning list of users: ' + err }); res.render('users', { title: 'Admin users', navigate: navigate, message: 'Error', users: null, error: 'Error returning list of users: ' + err });
} }
} }
exports.password_get = async function(req, res) { exports.password_get = async function(req, res) {
const nav = const navigate =
{ {
active: 'users', active: 'users',
} }
@ -69,11 +69,11 @@ exports.password_get = async function(req, res) {
password1: null, password1: null,
password2: null password2: null
}; };
res.render('password', { title: 'Set password', nav: nav, user: user, readonly: true, message: '' }); res.render('password', { title: 'Set password', navigate: navigate, user: user, readonly: true, message: '' });
} }
exports.password_post = async function(req, res) { exports.password_post = async function(req, res) {
const nav = const navigate =
{ {
active: 'users', active: 'users',
} }
@ -99,7 +99,7 @@ exports.password_post = async function(req, res) {
password2: req.body.password2 password2: req.body.password2
}; };
const message = 'Please check errors below'; const message = 'Please check errors below';
res.render('password', { title: 'Set password', nav: nav, user: user, readonly: true, message: message, errors: errors }); res.render('password', { title: 'Set password', navigate: navigate, user: user, readonly: true, message: message, errors: errors });
} else { } else {
let pass_set = true; let pass_set = true;
if (req.body.pass_set === 'check') pass_set = false; if (req.body.pass_set === 'check') pass_set = false;
@ -124,12 +124,12 @@ exports.password_post = async function(req, res) {
users = await update_users(users); users = await update_users(users);
const message = 'Successfully set password for ' + req.body.username; const message = 'Successfully set password for ' + req.body.username;
res.render('password', { title: 'Set password', nav: nav, user: user, readonly: true, message: message }); res.render('password', { title: 'Set password', navigate: navigate, user: user, readonly: true, message: message });
} }
} }
exports.user_create_get = async function(req, res) { exports.user_create_get = async function(req, res) {
const nav = const navigate =
{ {
active: 'create_user', active: 'create_user',
} }
@ -141,11 +141,11 @@ exports.user_create_get = async function(req, res) {
password2: null password2: null
}; };
res.render('password', { title: 'Create new admin user', nav: nav, user: user, readonly: false}); res.render('password', { title: 'Create new admin user', navigate: navigate, user: user, readonly: false});
} }
exports.user_create_post = async function(req, res) { exports.user_create_post = async function(req, res) {
const nav = const navigate =
{ {
active: 'create_user', active: 'create_user',
} }
@ -154,7 +154,7 @@ exports.user_create_post = async function(req, res) {
} }
exports.user_delete = async function(req, res) { exports.user_delete = async function(req, res) {
const nav = const navigate =
{ {
active: 'users', active: 'users',
} }
@ -168,7 +168,7 @@ exports.user_delete = async function(req, res) {
const user = users[req.params.name]; const user = users[req.params.name];
if (user && (req.session.user.name === user.name)) { if (user && (req.session.user.name === user.name)) {
res.render('user_delete', { title: 'Delete user', nav: nav, user: user, self_delete: true }); res.render('user_delete', { title: 'Delete user', navigate: navigate, user: user, self_delete: true });
} }
if (req.body.delete === 'delete') { if (req.body.delete === 'delete') {
@ -176,15 +176,15 @@ exports.user_delete = async function(req, res) {
const deleted_user = { name: user.name }; const deleted_user = { name: user.name };
delete users[user.name]; delete users[user.name];
users = await update_users(users); users = await update_users(users);
res.render('user_delete', { title: 'Deleted user', nav: nav, user: deleted_user, deleted: true }); res.render('user_delete', { title: 'Deleted user', navigate: navigate, user: deleted_user, deleted: true });
} else { } else {
res.render('user_delete', { title: 'Delete user', nav: nav, user: null }); res.render('user_delete', { title: 'Delete user', navigate: navigate, user: null });
} }
} else { } else {
if (user) { if (user) {
res.render('user_delete', { title: 'Delete user', nav: nav, user: user }); res.render('user_delete', { title: 'Delete user', navigate: navigate, user: user });
} else { } else {
res.render('user_delete', { title: 'Delete user', nav: nav, user: null }); res.render('user_delete', { title: 'Delete user', navigate: navigate, user: null });
} }
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "ztncui", "name": "ztncui",
"version": "0.5.6", "version": "0.5.8",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node ./bin/www", "start": "node ./bin/www",

View File

@ -18,13 +18,13 @@ block body_content
| Key Networks | Key Networks
.collapse.navbar-collapse(id='BarNav') .collapse.navbar-collapse(id='BarNav')
ul.nav.navbar-nav ul.nav.navbar-nav
li(class=(nav.active === 'controller_home'? 'active' : '')) li(class=(navigate.active === 'controller_home'? 'active' : ''))
a(href='/controller') Home a(href='/controller') Home
li(class=(nav.active === 'users'? 'active' : '')) li(class=(navigate.active === 'users'? 'active' : ''))
a(href='/users') Users a(href='/users') Users
li(class=(nav.active === 'networks'? 'active' : '')) li(class=(navigate.active === 'networks'? 'active' : ''))
a(href='/controller/networks') Networks a(href='/controller/networks') Networks
li(class=(nav.active === 'add_network'? 'active' : '')) li(class=(navigate.active === 'add_network'? 'active' : ''))
a(href='/controller/network/create') Add network a(href='/controller/network/create') Add network
ul.nav.navbar-nav.navbar-right ul.nav.navbar-nav.navbar-right
li li

View File

@ -33,8 +33,9 @@ block net_content
p [ p [
each elem in value each elem in value
p { p {
each v2, k2 in elem - if (!!elem)
p #{k2}: #{v2}, each v2, k2 in elem
p #{k2}: #{v2},
p }, p },
p ] p ]
- else - else

View File

@ -18,5 +18,5 @@ block content
.col-sm-2 .col-sm-2
h2.right h2.right
a.btn.btn-default(href=nav.whence role='button') Back a.btn.btn-default(href=navigate.whence role='button') Back
block net_content block net_content

View File

@ -18,11 +18,11 @@ block body_content
| Key Networks | Key Networks
.collapse.navbar-collapse(id='BarNav') .collapse.navbar-collapse(id='BarNav')
ul.nav.navbar-nav ul.nav.navbar-nav
li(class=(nav.active === 'home'? 'active' : '')) li(class=(navigate.active === 'home'? 'active' : ''))
a(href='/controller') Home a(href='/controller') Home
li(class=(nav.active === 'users'? 'active' : '')) li(class=(navigate.active === 'users'? 'active' : ''))
a(href='/users') Users a(href='/users') Users
li(class=(nav.active === 'create_user'? 'active' : '')) li(class=(navigate.active === 'create_user'? 'active' : ''))
a(href='/users/create') Create user a(href='/users/create') Create user
ul.nav.navbar-nav.navbar-right ul.nav.navbar-nav.navbar-right
li li