mirror of
https://github.com/key-networks/ztncui.git
synced 2025-10-17 18:55:06 +02:00
手工修改遗漏的basePath
This commit is contained in:
parent
0a246bca3e
commit
4045ac8a3b
2 changed files with 38 additions and 28 deletions
|
@ -12,6 +12,11 @@ const util = require('util');
|
|||
|
||||
storage.initSync({dir: 'etc/storage'});
|
||||
|
||||
// Unified helper to get basePath consistently across the controller
|
||||
function getBasePath(req) {
|
||||
return (req.app && req.app.locals ? (req.app.locals.basePath || '') : '');
|
||||
}
|
||||
|
||||
async function get_network_with_members(nwid) {
|
||||
const [network, peers, members] = await Promise.all([
|
||||
zt.network_detail(nwid),
|
||||
|
@ -92,7 +97,7 @@ exports.network_list = async function(req, res) {
|
|||
|
||||
// Display detail page for specific network
|
||||
exports.network_detail = async function(req, res) {
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
|
@ -145,7 +150,7 @@ exports.network_create_post = async function(req, res) {
|
|||
} else {
|
||||
try {
|
||||
const network = await zt.network_create(name);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
res.redirect(basePath + '/controller/network/' + network.nwid);
|
||||
} catch (err) {
|
||||
res.render('network_detail', {title: 'Create Network - error', navigate: navigate, error: 'Error creating network ' + name.name});
|
||||
|
@ -155,7 +160,7 @@ exports.network_create_post = async function(req, res) {
|
|||
|
||||
// Display Network delete form on GET
|
||||
exports.network_delete_get = async function(req, res) {
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
|
@ -173,7 +178,7 @@ exports.network_delete_get = async function(req, res) {
|
|||
|
||||
// Handle Network delete on POST
|
||||
exports.network_delete_post = async function(req, res) {
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
|
@ -198,7 +203,7 @@ exports.network_object = async function(req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.network_detail(req.params.nwid);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render(req.params.object, {title: req.params.object, navigate: navigate, network: network}, function(err, html) {
|
||||
if (err) {
|
||||
|
@ -216,7 +221,7 @@ exports.network_object = async function(req, res) {
|
|||
|
||||
// Handle Network rename form on POST
|
||||
exports.name = async function(req, res) {
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
|
@ -271,7 +276,7 @@ exports.ipAssignmentPools = async function(req, res) {
|
|||
if (errors) {
|
||||
try {
|
||||
const network = await zt.network_detail(req.params.nwid);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network, errors: errors});
|
||||
} catch (err) {
|
||||
|
@ -280,7 +285,8 @@ exports.ipAssignmentPools = async function(req, res) {
|
|||
} else {
|
||||
try {
|
||||
const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'add');
|
||||
navigate.whence = '/controller/network/' + network.nwid;
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network});
|
||||
} catch (err) {
|
||||
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, error: 'Error applying IP Assignment Pools for network ' + req.params.nwid + ': ' + err});
|
||||
|
@ -339,7 +345,8 @@ exports.routes = async function (req, res) {
|
|||
if (errors) {
|
||||
try {
|
||||
const network = await zt.network_detail(req.params.nwid);
|
||||
navigate.whence = '/controller/network/' + network.nwid;
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network, errors: errors});
|
||||
} catch (err) {
|
||||
res.render('routes', {title: 'routes', navigate: navigate, error: 'Error resolving network detail'});
|
||||
|
@ -347,7 +354,7 @@ exports.routes = async function (req, res) {
|
|||
} else {
|
||||
try {
|
||||
const network = await zt.routes(req.params.nwid, route, 'add');
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network});
|
||||
} catch (err) {
|
||||
|
@ -374,7 +381,7 @@ exports.route_delete = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.routes(req.params.nwid, route, 'delete');
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('routes', {title: 'routes', navigate: navigate, route: route, network: network});
|
||||
} catch (err) {
|
||||
|
@ -399,7 +406,7 @@ exports.ipAssignmentPool_delete = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.ipAssignmentPools(req.params.nwid, ipAssignmentPool, 'delete');
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('ipAssignmentPools', {title: 'ipAssignmentPools', navigate: navigate, ipAssignmentPool: ipAssignmentPool, network: network});
|
||||
} catch (err) {
|
||||
|
@ -422,7 +429,7 @@ exports.private = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.network_object(req.params.nwid, private);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('private', {title: 'private', navigate: navigate, network: network});
|
||||
} catch (err) {
|
||||
|
@ -445,7 +452,7 @@ exports.v4AssignMode = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.network_object(req.params.nwid, v4AssignMode);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('v4AssignMode', {title: 'v4AssignMode', navigate: navigate, network: network});
|
||||
} catch (err) {
|
||||
|
@ -473,7 +480,7 @@ exports.v6AssignMode = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.network_object(req.params.nwid, v6AssignMode);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('v6AssignMode', {title: 'v6AssignMode', navigate: navigate, network: network});
|
||||
} catch (err) {
|
||||
|
@ -503,7 +510,7 @@ exports.dns = async function (req, res) {
|
|||
|
||||
try {
|
||||
const network = await zt.network_object(req.params.nwid, dns);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('dns', {title: 'dns', navigate: navigate, network: network});
|
||||
} catch (err) {
|
||||
|
@ -521,7 +528,7 @@ exports.member_detail = async function(req, res) {
|
|||
|
||||
try {
|
||||
const {network, member} = await get_network_member(req.params.nwid, req.params.id);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid + '#members';
|
||||
res.render('member_detail', {title: 'Network member detail', navigate: navigate, network: network, member: member});
|
||||
} catch (err) {
|
||||
|
@ -540,7 +547,7 @@ exports.member_object = async function(req, res) {
|
|||
|
||||
try {
|
||||
const {network, member} = await get_network_member(req.params.nwid, req.params.id);
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid + '#members';
|
||||
res.render(req.params.object, {title: req.params.object, navigate: navigate, network: network, member: member}, function(err, html) {
|
||||
if (err) {
|
||||
|
@ -558,7 +565,7 @@ exports.member_object = async function(req, res) {
|
|||
|
||||
// Easy network setup GET
|
||||
exports.easy_get = async function(req, res) {
|
||||
const basePath = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
|
@ -575,11 +582,11 @@ exports.easy_get = async function(req, res) {
|
|||
|
||||
// Easy network setup POST
|
||||
exports.easy_post = async function(req, res) {
|
||||
const basePath2 = req.app && req.app.locals ? (req.app.locals.basePath || '') : '';
|
||||
const basePath = getBasePath(req);
|
||||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
whence: basePath2 + '/controller/networks'
|
||||
whence: basePath + '/controller/networks'
|
||||
}
|
||||
|
||||
req.checkBody('networkCIDR', 'Network address is required').notEmpty();
|
||||
|
@ -649,7 +656,7 @@ exports.members = async function(req, res) {
|
|||
const navigate =
|
||||
{
|
||||
active: 'networks',
|
||||
whence: '/controller/networks'
|
||||
whence: getBasePath(req) + '/controller/networks'
|
||||
}
|
||||
|
||||
let errors = null;
|
||||
|
@ -713,7 +720,8 @@ exports.members = async function(req, res) {
|
|||
}
|
||||
}
|
||||
} else { // GET
|
||||
res.redirect("/controller/network/" + req.params.nwid + "#members");
|
||||
const basePath = getBasePath(req);
|
||||
res.redirect(basePath + "/controller/network/" + req.params.nwid + "#members");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -740,7 +748,8 @@ exports.member_delete = async function(req, res) {
|
|||
}
|
||||
member.name = name || '';
|
||||
|
||||
navigate.whence = '/controller/network/' + network.nwid;
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
res.render('member_delete', {title: 'Delete member from ' + network.name,
|
||||
navigate: navigate, network: network, member: member});
|
||||
} catch (err) {
|
||||
|
@ -761,12 +770,13 @@ exports.delete_ip = async function(req, res) {
|
|||
try {
|
||||
const network = await zt.network_detail(req.params.nwid);
|
||||
let member = await zt.member_detail(req.params.nwid, req.params.id);
|
||||
navigate.whence = '/controller/network/' + network.nwid;
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
member.name = await storage.getItem(member.id) | '';
|
||||
if (req.params.index) {
|
||||
member = await zt.ipAssignmentDelete(network.nwid, member.id,
|
||||
req.params.index);
|
||||
res.redirect('/controller/network/' + network.nwid + '/member/' +
|
||||
res.redirect(basePath + '/controller/network/' + network.nwid + '/member/' +
|
||||
member.id + '/ipAssignments');
|
||||
}
|
||||
res.render('ipAssignments', {title: 'ipAssignments ' + network.name,
|
||||
|
@ -820,7 +830,8 @@ exports.assign_ip = async function(req, res) {
|
|||
|
||||
try {
|
||||
let member = await zt.member_detail(req.params.nwid, req.params.id);
|
||||
navigate.whence = '/controller/network/' + network.nwid;
|
||||
const basePath = getBasePath(req);
|
||||
navigate.whence = basePath + '/controller/network/' + network.nwid;
|
||||
|
||||
if (!errors) {
|
||||
member = await zt.ipAssignmentAdd(network.nwid, member.id, ipAssignment);
|
||||
|
|
|
@ -21,7 +21,6 @@ html(lang='en')
|
|||
meta(name='viewport', content='width=device-width, initial-scale=1')
|
||||
link(rel='stylesheet', href=(basePath + '/bscss/bootstrap.min.css'))
|
||||
link(rel='stylesheet', href=(basePath + '/stylesheets/style.css'))
|
||||
//- Explicit favicon with basePath to avoid root-level request
|
||||
link(rel='icon', type='image/x-icon', href=(basePath + '/favicon.ico'))
|
||||
link(rel='shortcut icon', type='image/x-icon', href=(basePath + '/favicon.ico'))
|
||||
script(src=(basePath + '/jqjs/jquery.min.js'))
|
||||
|
|
Loading…
Add table
Reference in a new issue