diff --git a/.gitignore b/.gitignore index c72d5dc..3f5512d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ node_modules package-lock.json sitemap.txt -db/ +blog.db diff --git a/Dockerfile b/Dockerfile index 7a11907..2e1c918 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,17 +5,17 @@ FROM node:buster-slim WORKDIR /src/ -# installs node dependencies - -ADD package.json package.json -RUN npm install - # installs pandoc for markdown to html # need git so admin page can pull blog updates RUN apt-get update && \ + apt-get install sqlite3 -y && \ apt-get install pandoc -y && \ apt-get install git -y +# installs node dependencies +ADD package.json package.json +RUN npm install + # exposes port application runs on EXPOSE 8000 diff --git a/admin/admin.js b/admin/admin.js deleted file mode 100644 index 72534e5..0000000 --- a/admin/admin.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Determines what template and controls that will be - * displayed based on the url such as - * / - * /blog - * /downloads - * - * For each controls it calls that "pages" associated javascript file - * which fetches the template, deals with post data and gathers context - * for the template engine. - */ - -//file IO -const utils = require('../utils/utils.js'); - - -module.exports= -{ - /** - * - * @param request -- used to get post data - * @param clientAddress -- used to see if user is banned for login - * @param templateContext -- used by whiskers for information to plug - * in the template - * @param filename -- specific admin page requested - * @returns {Promise} resolves once everything has been added to the template context - */ - main: function(request, clientAddress, templateContext, filename) - { - return new Promise(function(resolve, reject) - { - //if logged in - if(request.session && request.session.user) - { - templateContext.loggedIn = true; - utils.getPostData(request).then(function (postData) - { - var page = "./adminHome.js"; - if(filename.includes('/downloads')) - { - page = "./adminDownloads.js"; - } - else if(filename.includes("/posts")) - { - page = "./posts.js"; - } - else if(filename.includes("/users")) - { - page = "./users.js"; - } - else if(filename.includes("/analytics")) - { - page = "./analytics.js" - } - - require(page).main(postData, templateContext).then(function(template) - { - templateContext.adminPage = template; - resolve(); - }).catch(function(error) - { - console.log(error); - }); - }); - } - else - { - require("./login.js").main(request, clientAddress, templateContext) - .then(function() - { - resolve(); - }).catch(function(err) - { - console.log(err); - reject(err); - }) - } - }); - } -}; \ No newline at end of file diff --git a/admin/posts.js b/admin/posts.js index 6871bef..5b3b8c8 100644 --- a/admin/posts.js +++ b/admin/posts.js @@ -32,7 +32,7 @@ const processPostData = function(postData, renderContext) renderContext.editPost = true; sql.getPostById(postParsed.edit_post).then(function(post) { - post.published = post.published.toISOString().split('T')[0]; + post.published = new Date(post.published).toDateString(); renderContext.post = post; resolve(); }); diff --git a/blog/renderBlogPost.js b/blog/renderBlogPost.js index 01a5ee9..052b9d8 100644 --- a/blog/renderBlogPost.js +++ b/blog/renderBlogPost.js @@ -47,8 +47,7 @@ module.exports= { if(post.picture_url !== "n/a") post.hasPicture = true; - - post.published = post.published.toDateString(); + post.published = new Date(post.published).toDateString(); return; }, diff --git a/config.json b/config.json index 776eb51..909d739 100644 --- a/config.json +++ b/config.json @@ -1,9 +1,6 @@ { "PORT": 8000, - - "SESSION_SECRET": "random-data-to-seed-session-data", - "SQL_HOST": "db", - "SQL_DATABASE": "jrtechs_blog", - "SQL_USER": "root", - "SQL_PASSWORD": "password" + "CACHE": false, + "ADMIN_CHECK": true, + "SESSION_SECRET": "random-data-to-seed-session-data" } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e8da41c..c0b9f1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,14 @@ version: '3' # mysql --port=3306 --host=127.0.0.1 -u root --password=password services: - db: - image: mysql - command: --default-authentication-plugin=mysql_native_password - restart: always - environment: - MYSQL_ROOT_PASSWORD: password - volumes: - - "./db:/var/lib/mysql" + # db: + # image: mysql + # command: --default-authentication-plugin=mysql_native_password + # restart: always + # environment: + # MYSQL_ROOT_PASSWORD: password + # volumes: + # - "./db:/var/lib/mysql" blog: build: . @@ -20,5 +20,5 @@ services: ports: - 8000:8000 restart: always - links: - - db:database \ No newline at end of file + # links: + # - db:database \ No newline at end of file diff --git a/package.json b/package.json index 65a7f3c..a97cad8 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "rss": "^1.2.2", "sanitizer": "^0.1.3", "sendmail": "^1.4.1", + "sqlite3": "^5.0.2", "whiskers": "^0.4.0" }, "scripts": { diff --git a/routes/admin/analytics.js b/routes/admin/analytics.js deleted file mode 100644 index b2882b7..0000000 --- a/routes/admin/analytics.js +++ /dev/null @@ -1,10 +0,0 @@ -const routes = require('express').Router(); - -const builder = require('../../utils/pageBuilder'); - -routes.get('/', (request, result) => -{ - builder.constructAdminPage(request, result, require("../../admin/analytics").main) -}); - -module.exports = routes; \ No newline at end of file diff --git a/routes/admin/index.js b/routes/admin/index.js index 04bdc89..56a5189 100644 --- a/routes/admin/index.js +++ b/routes/admin/index.js @@ -1,8 +1,5 @@ const routes = require('express').Router(); -const analytics = require('./analytics'); -routes.use('/analytics', analytics); - const login = require('./login'); routes.use('/login', login); diff --git a/routes/index.js b/routes/index.js index a900714..f3a3440 100644 --- a/routes/index.js +++ b/routes/index.js @@ -60,6 +60,7 @@ routes.use('/rss', feed); //blog home page routes.get('/', (request, result) => { + console.log("ummmm ping?"); pageBuilder.buildBlogPage(request, result, require("../blog/homePage").main) }); diff --git a/server.js b/server.js index c28ba88..e83839a 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ */ /** Stores the configuration for the server */ -const config = require('./utils/configLoader').getConfig(); +const config = require('./utils/utils').getConfig(); /** Port for the server to run on */ const port = config.PORT; @@ -24,7 +24,6 @@ const compression = require('compression'); const map = require('./utils/generateSiteMap.js'); map.main(); - /**session data for login */ const session = require('express-session'); diff --git a/sitemap.txt b/sitemap.txt index 86af81d..71fb22c 100644 --- a/sitemap.txt +++ b/sitemap.txt @@ -1,24 +1,46 @@ http://jrtechs.net/ +http://jrtechs.net/category/data-science http://jrtechs.net/category/hardware http://jrtechs.net/category/java +http://jrtechs.net/category/open-source http://jrtechs.net/category/other +http://jrtechs.net/category/photography http://jrtechs.net/category/programming http://jrtechs.net/category/projects http://jrtechs.net/category/web-development -http://jrtechs.net/hardware/2018-rochester-maker-faire -http://jrtechs.net/hardware/ddr4-ram-introduction -http://jrtechs.net/hardware/hard-drive-speeds +http://jrtechs.net/data-science/visualizing-fitbit-gps-data +http://jrtechs.net/data-science/quadtree-animations-with-matplotlib +http://jrtechs.net/data-science/implementing-a-quadtree-in-python +http://jrtechs.net/data-science/node2vec-with-steam-data +http://jrtechs.net/data-science/time-spent-in-steam-games +http://jrtechs.net/data-science/cuda-vs-cpu-performance +http://jrtechs.net/data-science/creating-pixel-art-with-open-cv +http://jrtechs.net/data-science/gans-in-pytorch +http://jrtechs.net/data-science/pytorch-headfirst +http://jrtechs.net/data-science/word-embeddings-part-2 +http://jrtechs.net/data-science/word-embeddings +http://jrtechs.net/data-science/image-clustering-with-k-means +http://jrtechs.net/data-science/graphing-my-life-with-matplotlib +http://jrtechs.net/data-science/developing-an-ai-to-play-asteroids-part-1 +http://jrtechs.net/data-science/csci-331-final-review +http://jrtechs.net/data-science/csci-331-review-2 +http://jrtechs.net/data-science/csci-331-review-1 +http://jrtechs.net/data-science/a-closer-look-at-fitbit-data +http://jrtechs.net/data-science/r-programming-language +http://jrtechs.net/data-science/is-using-ml-for-antivirus-safe +http://jrtechs.net/data-science/lets-build-a-genetic-algorithm +http://jrtechs.net/java/running-a-minecraft-server-with-docker +http://jrtechs.net/java/running-scala-code-in-docker +http://jrtechs.net/java/parallel-java-performance-overview +http://jrtechs.net/java/fun-with-functional-java http://jrtechs.net/java/gremlin-in-10-minutes http://jrtechs.net/java/top-three-recommended-java-ides http://jrtechs.net/java/bash-usr-bin-java-cannot-execute-binary-file -http://jrtechs.net/other/college-cookbook -http://jrtechs.net/other/2018-in-review -http://jrtechs.net/other/morality-of-self-driving-cars -http://jrtechs.net/other/my-college-essay -http://jrtechs.net/other/deepfakes -http://jrtechs.net/other/why-do-i-blog -http://jrtechs.net/other/ways-to-avoid-getting-hacked -http://jrtechs.net/other/should-you-run-a-server-on-desktop-hardware +http://jrtechs.net/photography/segmenting-images-with-quadtrees +http://jrtechs.net/photography/the-rise-of-profile-photos +http://jrtechs.net/photography/photography-in-the-age-of-social-media +http://jrtechs.net/programming/csci-344-final-review +http://jrtechs.net/programming/multi-threaded-file-io http://jrtechs.net/programming/sorting-algorithms http://jrtechs.net/programming/knapsack-problem http://jrtechs.net/programming/cs-theory-exam-2-review @@ -26,6 +48,8 @@ http://jrtechs.net/programming/everything-fibonacci http://jrtechs.net/programming/c-to-c++-tutorial http://jrtechs.net/programming/university-vs-teaching-yourself-programming http://jrtechs.net/programming/using-english-conventions-to-write-clean-code +http://jrtechs.net/projects/diy-video-hosting-server +http://jrtechs.net/projects/github-graphs-project http://jrtechs.net/projects/steam-friends-graph http://jrtechs.net/projects/musical-floppy-drive-build-log http://jrtechs.net/projects/musical-floppy-drives @@ -34,8 +58,43 @@ http://jrtechs.net/projects/ackermann-function-written-in-java http://jrtechs.net/projects/batch-minecraft-launcher-with-auto-restart http://jrtechs.net/projects/time-lapse-programming-zombie-game http://jrtechs.net/projects/time-lapse-programming-pong +http://jrtechs.net/web-development/pandoc-syntax-highlighting-with-prism +http://jrtechs.net/web-development/node-rss-feed http://jrtechs.net/web-development/lazy-loading-youtube-videos http://jrtechs.net/web-development/node-website-optimization http://jrtechs.net/web-development/node-vs-php http://jrtechs.net/web-development/why-i-stopped-using-wordpress http://jrtechs.net/web-development/history-of-jrtechs +http://jrtechs.net/hardware/creating-an-audio-switch +http://jrtechs.net/hardware/2018-rochester-maker-faire +http://jrtechs.net/hardware/ddr4-ram-introduction +http://jrtechs.net/hardware/hard-drive-speeds +http://jrtechs.net/other/2020-in-review +http://jrtechs.net/other/coming-out-as-bisexual +http://jrtechs.net/other/college-cookbook-part-3 +http://jrtechs.net/other/flirting-with-burnout-at-rit +http://jrtechs.net/other/how-films-portray-control +http://jrtechs.net/other/working-remote +http://jrtechs.net/other/college-cookbook-part-2 +http://jrtechs.net/other/2019-in-review +http://jrtechs.net/other/responsible-optimization +http://jrtechs.net/other/college-cookbook +http://jrtechs.net/other/2018-in-review +http://jrtechs.net/other/morality-of-self-driving-cars +http://jrtechs.net/other/my-college-essay +http://jrtechs.net/other/deepfakes +http://jrtechs.net/other/why-do-i-blog +http://jrtechs.net/other/ways-to-avoid-getting-hacked +http://jrtechs.net/other/should-you-run-a-server-on-desktop-hardware +http://jrtechs.net/open-source/creating-a-dynamic-github-profile +http://jrtechs.net/open-source/hosting-your-own-gitea-server +http://jrtechs.net/open-source/community-architecture +http://jrtechs.net/open-source/community-architecture-proposal +http://jrtechs.net/open-source/hfoss-quiz-1 +http://jrtechs.net/open-source/ritlug-bugfix +http://jrtechs.net/open-source/shallow-dive-into-open-cv +http://jrtechs.net/open-source/foss-vs-floss +http://jrtechs.net/open-source/jupyter-will-change-your-life +http://jrtechs.net/open-source/towards-a-new-hacker-ethic +http://jrtechs.net/open-source/teaching-ssh-through-a-ctf +http://jrtechs.net/open-source/the-essential-vim-configuration diff --git a/templates/admin/adminDownloads.html b/templates/admin/adminDownloads.html index 026fb29..ee3a8fa 100644 --- a/templates/admin/adminDownloads.html +++ b/templates/admin/adminDownloads.html @@ -1,7 +1,7 @@
-
+

Add Download

@@ -24,15 +24,16 @@
-
+

Downloads

- +
+ @@ -44,6 +45,9 @@ + diff --git a/utils/configLoader.js b/utils/configLoader.js deleted file mode 100644 index 8f5d960..0000000 --- a/utils/configLoader.js +++ /dev/null @@ -1,38 +0,0 @@ -const utils = require('../utils/utils'); - - -/** - * @author Jeffery Russell 11-24-18 - * - * @type {{main: module.exports.main}} - */ -module.exports= - { - - /** - * Verifies the contents of the config file - * and returns it. If the config is incomplete, - * it terminates the program. - * - * @returns {*|any} - */ - getConfig: function() - { - const configContents = ["PORT", "SESSION_SECRET", - "SQL_HOST", "SQL_DATABASE", "SQL_PASSWORD", - "CAPTCHA_SECRET", "GMAIL_ACCOUNT", "EMAIL_PASSWORD", - "DESTINATION_EMAIL"]; - - var config = utils.getFileAsJSON("./config.json"); - - for(var i = 0; i < configContents.length; i++) - { - if(!config.hasOwnProperty(configContents[i])) - { - console.log("Missing config property: " + configContents[i]); - process.exit(1); - } - } - return config; - } - } diff --git a/utils/pageBuilder.js b/utils/pageBuilder.js index 820b0d5..871980c 100644 --- a/utils/pageBuilder.js +++ b/utils/pageBuilder.js @@ -6,6 +6,11 @@ const includes = require("../includes/includes"); const cache = require('memory-cache'); + +const CACHE_ENABLED = utils.getConfig()['CACHE']; + +const ADMIN_CHECK = utils.getConfig()["ADMIN_CHECK"]; + /** used to parse the request URL */ const url = require('url'); @@ -128,7 +133,7 @@ module.exports = loggedIn(request) { - return(request.session && request.session.user); + return(ADMIN_CHECK == false || (request.session && request.session.user)); }, @@ -139,7 +144,7 @@ module.exports = page = 1; page = Number(page); - const html = cache.get(filename + "?page=" + page); + const html = CACHE_ENABLED == true ? cache.get(filename + "?page=" + page) : null; result.writeHead(200, {'Content-Type': 'text/html'}); if (html == null) @@ -156,7 +161,10 @@ module.exports = const html = whiskers.render(content[0], templateContext); result.write(html); result.end(); - cache.put(filename + "?page=" + page, html); + if(CACHE_ENABLED == true) + { + cache.put(filename + "?page=" + page, html); + } }).catch(function (err) { cache.del(filename + "?page=" + page); diff --git a/utils/sql.js b/utils/sql.js index f421789..8768373 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -17,21 +17,10 @@ const crypto = require('crypto'); const qs = require('querystring'); /** Used to load the config file from the disk */ -const config = require('../utils/configLoader').getConfig(); +const config = require('../utils/utils').getConfig(); -/** SQL connection */ -const con = mysql.createConnection({ - host: config.SQL_HOST, - port: config.SQL_PORT, - user: config.SQL_USER, - password: config.SQL_PASSWORD, - database: config.SQL_DATABASE -}); - -con.connect(function(err) { - if (err) - console.log(err); -}); +const sqlite3 = require('sqlite3').verbose(); +const con = new sqlite3.Database('./blog.db'); /** @@ -44,7 +33,8 @@ const fetch = function(sqlStatement) { return new Promise(function(resolve, reject) { - con.query(sanitizer.sanitize(sqlStatement), function (err, result) + + con.all(sanitizer.sanitize(sqlStatement), function (err, result) { if(err) { @@ -69,14 +59,14 @@ const insert = function(sqlStatement) { return new Promise(function(resolve, reject) { - con.query(sanitizer.sanitize(sqlStatement), function (err, result) + con.exec(sanitizer.sanitize(sqlStatement), function (err, result) { if (err) { console.log(err); reject(); } - resolve(result.insertId); + resolve(0); }); }) }; diff --git a/utils/utils.js b/utils/utils.js index fca1aec..2a439ef 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -5,6 +5,7 @@ //used for file io const fs = require('fs'); +const path = require('path') module.exports= @@ -101,4 +102,29 @@ module.exports= } }); }, + + /** + * Verifies the contents of the config file + * and returns it. If the config is incomplete, + * it terminates the program. + * + * @returns {*|any} + */ + getConfig: function() + { + const configContents = ["PORT", "SESSION_SECRET", + "CACHE", "ADMIN_CHECK"]; + + var config = JSON.parse(fs.readFileSync('/src/config.json', 'utf8')); + + for(var i = 0; i < configContents.length; i++) + { + if(!config.hasOwnProperty(configContents[i])) + { + console.log("Missing config property: " + configContents[i]); + process.exit(1); + } + } + return config; + } }; \ No newline at end of file
Download Name FileURL Download Count Delete
{download.name} + https://jrtechs.net/downloads/{download.name} + {download.file}