From 5ab2b57e790ed10cb06dbbc8e269a53a2b81ead1 Mon Sep 17 00:00:00 2001
From: gor_down
Date: Thu, 5 Dec 2024 00:56:01 -0300
Subject: [PATCH] visitor table
---
index.js | 7 +++-
package-lock.json | 48 +++++++++++++++++++++------
package.json | 5 +++
public/styles/home/index.css | 5 +++
src/router/common_path_logic/home.js | 17 ++++++++++
src/router/indexRouter.js | 49 ++++++++++++++++++++++++----
views/home.hbs | 43 +++++++++++++++++++++---
views/update_log.hbs | 1 +
8 files changed, 152 insertions(+), 23 deletions(-)
create mode 100644 src/router/common_path_logic/home.js
diff --git a/index.js b/index.js
index a2de631..a501a96 100644
--- a/index.js
+++ b/index.js
@@ -5,13 +5,14 @@ const serveIndex = require('./src/utils/serve_index')
const {engine} = require('express-handlebars')
const indexRouter = require('./src/router/indexRouter')
const { handlebars } = require('hbs')
+const bodyParser = require('body-parser')
const publicPath = "/public"
const inUrlPath = "public"
webserver.engine('.hbs', engine({extname: '.hbs', helpers: {
ifDivisibleBy: function (index, divisor, options) {
- if (index % divisor === 0) {
+ if ((index+1) % divisor === 0) {
return options.fn(this);
}
},
@@ -27,6 +28,10 @@ webserver.set('view engine', '.hbs');
webserver.use(publicPath, express.static(inUrlPath), serveIndex(inUrlPath, {
}))
+webserver.use(bodyParser.urlencoded({extend: false}));
+
+webserver.use(bodyParser.json());
+
webserver.listen(port, () => {
console.log(`Listening on port ${port}`)
diff --git a/package-lock.json b/package-lock.json
index d2bb9e2..c180f35 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,13 +9,18 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
+ "body-parser": "^1.20.3",
"byte-size": "^9.0.0",
"csv": "^6.3.10",
"express": "^4.21.0",
"express-handlebars": "^8.0.1",
+ "fs": "^0.0.1-security",
"hbs": "^4.2.0",
"japanese-date-converter": "^2.0.0",
"serve-index": "^1.9.1"
+ },
+ "devDependencies": {
+ "@types/node": "^22.10.1"
}
},
"node_modules/@isaacs/cliui": {
@@ -35,6 +40,16 @@
"node": ">=12"
}
},
+ "node_modules/@types/node": {
+ "version": "22.10.1",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz",
+ "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.20.0"
+ }
+ },
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@@ -200,9 +215,9 @@
}
},
"node_modules/cookie": {
- "version": "0.6.0",
- "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
- "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
+ "version": "0.7.1",
+ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
+ "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
@@ -215,9 +230,9 @@
"license": "MIT"
},
"node_modules/cross-spawn": {
- "version": "7.0.3",
- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
- "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
+ "version": "7.0.6",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
+ "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
"license": "MIT",
"dependencies": {
"path-key": "^3.1.0",
@@ -370,9 +385,9 @@
}
},
"node_modules/express": {
- "version": "4.21.0",
- "resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz",
- "integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==",
+ "version": "4.21.1",
+ "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz",
+ "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==",
"license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
@@ -380,7 +395,7 @@
"body-parser": "1.20.3",
"content-disposition": "0.5.4",
"content-type": "~1.0.4",
- "cookie": "0.6.0",
+ "cookie": "0.7.1",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
@@ -504,6 +519,12 @@
"node": ">= 0.6"
}
},
+ "node_modules/fs": {
+ "version": "0.0.1-security",
+ "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
+ "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==",
+ "license": "ISC"
+ },
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
@@ -1352,6 +1373,13 @@
"node": ">=0.8.0"
}
},
+ "node_modules/undici-types": {
+ "version": "6.20.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
+ "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
diff --git a/package.json b/package.json
index 9f6308c..9a464e3 100644
--- a/package.json
+++ b/package.json
@@ -10,12 +10,17 @@
"license": "ISC",
"description": "",
"dependencies": {
+ "body-parser": "^1.20.3",
"byte-size": "^9.0.0",
"csv": "^6.3.10",
"express": "^4.21.0",
"express-handlebars": "^8.0.1",
+ "fs": "^0.0.1-security",
"hbs": "^4.2.0",
"japanese-date-converter": "^2.0.0",
"serve-index": "^1.9.1"
+ },
+ "devDependencies": {
+ "@types/node": "^22.10.1"
}
}
diff --git a/public/styles/home/index.css b/public/styles/home/index.css
index 3de209b..0198c23 100644
--- a/public/styles/home/index.css
+++ b/public/styles/home/index.css
@@ -50,4 +50,9 @@
.maotatsu > small::selection{
background-color: var(--celeste);
+}
+
+.visitor_table > tbody > tr > td{
+ max-width: 160px;
+ overflow-x: scroll;
}
\ No newline at end of file
diff --git a/src/router/common_path_logic/home.js b/src/router/common_path_logic/home.js
new file mode 100644
index 0000000..2f5a73b
--- /dev/null
+++ b/src/router/common_path_logic/home.js
@@ -0,0 +1,17 @@
+const { readCsv } = require("../../utils/csv")
+const { dirname } = require('path');
+const rootDir = dirname(require.main.filename);
+
+module.exports = async (req, res) => {
+ try{
+ const commentsRead = (await readCsv(rootDir + '/public/dynamic/sync/comments.csv'))
+ const comments = commentsRead.slice(commentsRead.length-16, commentsRead.length).reverse()
+ return {
+ comments
+ }
+ }
+ catch(err){
+ console.error(err)
+ res.send("Mistakes were made")
+ }
+}
\ No newline at end of file
diff --git a/src/router/indexRouter.js b/src/router/indexRouter.js
index 2ab9edc..147186c 100644
--- a/src/router/indexRouter.js
+++ b/src/router/indexRouter.js
@@ -3,7 +3,7 @@ const express = require('express');
const router = express.Router();
const { readCsv } = require('../utils/csv');
const { dirname } = require('path');
-const appDir = dirname(require.main.filename);
+const thisDirectory = dirname(require.main.filename);
const fs = require('fs')
function addPaths(path, renderParams = {}){
@@ -15,17 +15,17 @@ function addPaths(path, renderParams = {}){
const possibleHeader = 'headers/' + viewsRelativeDir.slice(0, -1) + '.hbs'
const possibleSettingsPath = '/src/router/common_path_settings/' + viewsRelativeDir.slice(0, -1)
- if (fs.existsSync(appDir + possibleThemeStyle)){
+ if (fs.existsSync(thisDirectory + possibleThemeStyle)){
currentDefaultParams.theme = possibleThemeStyle
}
- if (fs.existsSync(appDir + possibleHeaderStyle)){
+ if (fs.existsSync(thisDirectory + possibleHeaderStyle)){
currentDefaultParams.header_style = possibleHeaderStyle
}
- if (fs.existsSync(appDir + '/views/partials/' + possibleHeader)){
+ if (fs.existsSync(thisDirectory + '/views/partials/' + possibleHeader)){
currentDefaultParams.headerPartial = possibleHeader.slice(0, -4)
}
- if (fs.existsSync(appDir + possibleSettingsPath + '/general.json')){
- const fileGeneralParams = JSON.parse(fs.readFileSync(appDir + possibleSettingsPath + '/general.json'))
+ if (fs.existsSync(thisDirectory + possibleSettingsPath + '/general.json')){
+ const fileGeneralParams = JSON.parse(fs.readFileSync(thisDirectory + possibleSettingsPath + '/general.json'))
currentDefaultParams = {
...currentDefaultParams,
...fileGeneralParams
@@ -53,7 +53,42 @@ router.get('/', (_req, res) => {
res.redirect('/public/pages/neocities-lyricaltokarev/index.html')
})
-addPaths(appDir + '/views/')
+
+const recent_posters = []
+
+router.post('/comment', (req, res) => {
+ const ip = req.header('x-forwarded-for') || req.connection.remoteAddress;
+ if(recent_posters.some( poster => poster.ip === ip)){
+ console.log("spammer, " + ip)
+ return res.redirect('/home#visitor_table')
+ }
+ recent_posters.push({
+ ip,
+ timeout: 3600
+ })
+ const comment = req.body.comment.replace(/"/g, '""');
+ fs.appendFileSync(thisDirectory + "/public/dynamic/sync/comments.csv", `\n${Date.now()},"${comment}",,1`)
+
+ res.redirect('/home#visitor_table')
+})
+
+
+setInterval(() => {
+ recent_posters.forEach(poster => {
+ poster.timeout -= 1
+ if (poster.timeout <= 0){
+ recent_posters.filter(p => {
+ return poster.ip !== p.ip
+ })
+ }
+ })
+}, 1000)
+
+
+
+
+
+addPaths(thisDirectory + '/views/')
module.exports = router;
\ No newline at end of file
diff --git a/views/home.hbs b/views/home.hbs
index fc76dee..40497c3 100644
--- a/views/home.hbs
+++ b/views/home.hbs
@@ -18,7 +18,6 @@
Content
Audience
Consume
- Identity
Policy
Term
Deserve
@@ -34,9 +33,9 @@
Browse
Develop
Saturated
- Bullying
Right
- Life
+ Life
+ Tweet
Obscure
Vibe
Aesthetic
@@ -51,6 +50,7 @@
Yikes
Project
Idea
+ Identity
Global
Emotional
Planning
@@ -72,6 +72,7 @@
Resource
Inequality
Fee
+ Bullying
Equality
System
Design
@@ -90,6 +91,7 @@
Medium
Amount
Reader
+ Dynamics
Collective
Rational
Mental
@@ -107,6 +109,8 @@
Activism
Activist
Privacy
+ Cancel
+ Controversial
Subscribers
Likes
Material
@@ -143,6 +147,7 @@
Comic Chat
YuugenMagan
Propaganda
+ Visitor Table
???
@@ -262,7 +267,6 @@
YuugenMagan
YuugenMagan
-
Propaganda
@@ -286,10 +290,39 @@
This site is an ip logger. Do not hotlink.
+
+
+ Visitor Table
+ Experimental.
+
+
+
+ {{#each comments}}
+
+ {{{this.comment}}}
+ |
+ {{#ifDivisibleBy @index 4}}
+
+
+ {{/ifDivisibleBy}}
+ {{/each}}
+
+
+
+
+
+
+
+
+
+
-
{{>lyrics lyrics="
熱くなれ夢みた明日を
必ずいつかつかまえる
diff --git a/views/update_log.hbs b/views/update_log.hbs
index 03ed272..2b427ae 100644
--- a/views/update_log.hbs
+++ b/views/update_log.hbs
@@ -2,6 +2,7 @@
2024