diff --git a/app.js b/app.js index 0cb73c9..b1d3b62 100755 --- a/app.js +++ b/app.js @@ -70,6 +70,8 @@ app.use(function(req, res, next) { }); } + res.locals.env = env; + res.locals.host = req.session.host; res.locals.port = req.session.port; diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index 8e6b916..adb6c88 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -8,7 +8,7 @@ var bitcoin = require("bitcoin"); var rpcApi = require("./../app/rpcApi"); router.get("/", function(req, res) { - if (!req.session.host) { + if (req.session.host == null || req.session.host.trim() == "") { if (req.cookies['rpc-host']) { res.locals.host = req.cookies['rpc-host']; } @@ -140,6 +140,25 @@ router.post("/connect", function(req, res) { res.redirect("/"); }); +router.get("/disconnect", function(req, res) { + res.cookie('rpc-host', ""); + res.cookie('rpc-port', ""); + res.cookie('rpc-username', ""); + + req.session.host = ""; + req.session.port = ""; + req.session.username = ""; + + console.log("destroyed client."); + + global.client = null; + + req.session.userMessage = "Disconnected from node."; + req.session.userMessageType = "success"; + + res.redirect("/"); +}); + router.get("/blocks", function(req, res) { var limit = 20; var offset = 0; diff --git a/views/terminal.pug b/views/terminal.pug index db043cd..eb9a736 100644 --- a/views/terminal.pug +++ b/views/terminal.pug @@ -1,7 +1,15 @@ extends layout block content - h1 RPC Terminal + div(class="row mt-5") + div(class="col") + h1 RPC Terminal + + div(class="col") + if (!env.bitcoind || !env.bitcoind.rpc) + span(style="float: right;") + a(href="/disconnect") Disconnect from node + hr :markdown-it