From 13407c1acdf6a8c8893c78f2c1959e7ac8752b20 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 16 Mar 2019 20:01:48 -0400 Subject: Update --- package.json | 1 + src/css/styles.css | 35 +++++++++++++---------------------- src/html/admin.html | 14 +++++++------- src/html/index.html | 17 +++++++---------- src/index.js | 2 +- src/server.js | 16 ++++++++++++---- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index ae9a975..7538b7e 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "mysql2": "^1.6.4", "request": "^2.88.0", "sequelize": "^4.42.0", + "uuid": "^3.3.2", "vue": "^2.5.22" } } diff --git a/src/css/styles.css b/src/css/styles.css index fdb2551..e3694a8 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -20,6 +20,7 @@ h1 { font-size: 30pt; font-weight: 150; margin-bottom: 0; + font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; } @keyframes zoom-left { @@ -66,9 +67,8 @@ img { border: 2px solid #888; } -.main-page{ - display: flex; - flex-direction: row; +h1 { + margin: auto; } #feed { @@ -76,6 +76,8 @@ img { } .feed { width: 90%; + min-width: 200px; + margin: auto; display: flex; flex-direction: column; margin-top: 8px; @@ -100,28 +102,17 @@ p { } } -.sidebar { - /* height: 50vh; */ - height: 100%; - width: 100px; - margin: 20px; - padding: 20px; - border: 1px solid var(--text); - border-radius: 3px; +.titlebar { + padding: 5px; + border-top: 1px solid var(--light-text); + border-bottom: 1px solid var(--light-text); background-color: var(--background-accent); } -.sidebar ul { - list-style: none; - padding: 0; - margin-top: 0; -} - -.sidebar ul li { - display: block; - margin: 5px; - margin-left: auto; - margin-right: auto; +.titlebar a{ + margin: auto; + max-width: 10%; + min-width: 100px; } .btn { diff --git a/src/html/admin.html b/src/html/admin.html index 0f98eea..a1fcec8 100644 --- a/src/html/admin.html +++ b/src/html/admin.html @@ -13,8 +13,8 @@ var feed = new Vue({ el: '#stats', data: { - stats: {ip: [], url: []}, - showIpTable: true, + stats: {cookie: [], url: []}, + showSessionTable: true, showUrlTable: true, }, created() { @@ -55,13 +55,13 @@

Stats

- - + +
- +
- - + +
HostTotal Requests
{{item.ip}}{{item.c}}
{{item.cookie.substring(0,10)}}...{{item.c}}
diff --git a/src/html/index.html b/src/html/index.html index 73ed147..f004784 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -28,17 +28,14 @@

Welcome to Mark's Kitchen

-
- + + +
-
-
diff --git a/src/index.js b/src/index.js index 5315c8d..1a78436 100644 --- a/src/index.js +++ b/src/index.js @@ -70,7 +70,7 @@ function setUpModels(){ allowNull: false, },}), "requests": database.define('requests', { - ip: Sequelize.STRING, + cookie: Sequelize.STRING, method: Sequelize.STRING, url: Sequelize.STRING, }) diff --git a/src/server.js b/src/server.js index adcc846..f154f8d 100644 --- a/src/server.js +++ b/src/server.js @@ -3,6 +3,7 @@ const bodyParser = require('body-parser'); const cookieParser = require('cookie-parser'); const request = require('request'); const crypto = require('crypto'); +const uuidv4 = require('uuid/v4'); const Op = require('sequelize').Op; @@ -68,7 +69,14 @@ function setUpRoutes(models, jwtFunctions, database) { // Route logging server.use(function (req, res, next) { - var request = models.requests.create({ createdAt: new Date(), ip: req.ip, method: req.method, url: req.originalUrl }); + let cookie = req.cookies.authorization + if (!cookie) { + res.cookie('session-id', uuidv4(), { expires: new Date(Date.now() + (1000*60*60))}); + } + + models.requests.create({ + createdAt: new Date(), cookie: cookie, method: req.method, url: req.originalUrl + }); next() }) @@ -88,9 +96,9 @@ function setUpRoutes(models, jwtFunctions, database) { }) server.get('/admin/stats', async (req, res, next) => { try { - var ipResult = await database.query("SELECT ip, count(id) as c FROM requests GROUP BY ip", { type: database.QueryTypes.SELECT }) + var sessionResult = await database.query("SELECT cookie, count(id) as c FROM requests GROUP BY cookie", { type: database.QueryTypes.SELECT }) var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url", { type: database.QueryTypes.SELECT }) - res.status(200).send({ ip: ipResult, url: urlResult }); + res.status(200).send({ cookie: sessionResult, url: urlResult }); next(); } catch (e) { res.status(400).send(e.message); @@ -157,7 +165,7 @@ function setUpRoutes(models, jwtFunctions, database) { const user = await models.users.findOne({ where: { username: req.body.username, password: hash } }) if (user) { const token = jwtFunctions.sign(user.username); - res.cookie('authorization', token); + res.cookie('authorization', token, { expires: new Date(Date.now() + (1000*60*60))}); console.debug("Redirecting to admin - logged in") res.redirect('/admin'); } else { -- cgit v1.2.3