aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2019-03-16 20:01:48 -0400
committerMark Powers <markppowers0@gmail.com>2019-03-16 20:01:48 -0400
commit13407c1acdf6a8c8893c78f2c1959e7ac8752b20 (patch)
tree69ae2f2e2ad5eed529a4d50c3a8a00a7aa83ae1e
parent23c5e6810888c30f10167405f0516f62b32d8f5b (diff)
Update
-rw-r--r--package.json1
-rw-r--r--src/css/styles.css35
-rw-r--r--src/html/admin.html14
-rw-r--r--src/html/index.html17
-rw-r--r--src/index.js2
-rw-r--r--src/server.js16
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 @@
<div id="stats">
<h1>Stats</h1>
<div>
- <input type="checkbox" id="showIp" v-model="showIpTable">
- <label for="showIp">Show IP Stats</label>
+ <input type="checkbox" id="showSession" v-model="showSessionTable">
+ <label for="showSession">Show Session Stats</label>
</div>
- <table class="table ip-table" v-if="showIpTable">
+ <table class="table session-table" v-if="showSessionTable">
<tr><th>Host</th><th>Total Requests</th></tr>
- <tr v-for="item in stats.ip">
- <td>{{item.ip}}</td><td>{{item.c}}</td>
+ <tr v-for="item in stats.cookie">
+ <td>{{item.cookie.substring(0,10)}}...</td><td>{{item.c}}</td>
</tr>
</table>
<div>
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 @@
<body>
<h1>Welcome to Mark's Kitchen</h1>
- <div class="main-page">
- <nav class="float-left sidebar">
- <ul>
- <li><a href="bread" class="btn btn-primary">Bread</a></li>
- <li><a href="blog" class="btn btn-primary">Blog</a></li>
- <li><a href="essay" class="btn btn-primary">Essays</a></li>
- </ul>
- </nav>
+ <nav class="titlebar">
+ <a href="bread" class="btn btn-primary">Bread</a>
+ <a href="blog" class="btn btn-primary">Blog</a>
+ <a href="essay" class="btn btn-primary">Essays</a>
+ </nav>
+
+ <div id="feed"></div>
- <div id="feed"></div>
- </div>
<footer>
<div>Mark Powers</div>
</footer>
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 {