Browse Source

Removed traffic logging logic and removed unused email config

sql-refactor
jrtechs 2 years ago
parent
commit
700ee190f8
6 changed files with 5 additions and 136 deletions
  1. +2
    -0
      .gitignore
  2. +0
    -71
      admin/analytics.js
  3. +3
    -10
      config.json
  4. +0
    -3
      includes/html/adminHeader.html
  5. +0
    -20
      templates/admin/analytics.html
  6. +0
    -32
      utils/sql.js

+ 2
- 0
.gitignore View File

@ -3,3 +3,5 @@
.vscode .vscode
node_modules node_modules
package-lock.json package-lock.json
sitemap.txt
db/

+ 0
- 71
admin/analytics.js View File

@ -1,71 +0,0 @@
/** Whiskers template file */
const TEMPLATE_FILE = "admin/analytics.html";
const includes = require('../includes/includes.js');
//updates db
const sql = require('../utils/sql');
const generateData = function(templateContext)
{
return new Promise(function(resolve, reject)
{
var data = [];
sql.getTraffic().then(function(traffic)
{
var start = traffic[0].date;
var currentMonth = new Date(start.getUTCFullYear(), start.getMonth(), 1, 0,0,0);
templateContext.start = JSON.stringify(currentMonth);
var monthCount = 0;
for(var i = 0; i < traffic.length; i++)
{
var currentDate = traffic[i].date;
if(currentMonth.getMonth() != currentDate.getMonth())
{
var foo = new Object();
foo.x = currentMonth;
foo.y = monthCount;
data.push(foo);
monthCount = 0;
currentMonth = new Date(currentDate.getUTCFullYear(), currentDate.getMonth(), 1, 0,0,0);
}
monthCount = monthCount + 1;
}
templateContext.finish = JSON.stringify(currentMonth);
templateContext.dataset = JSON.stringify(data);
resolve();
});
});
};
module.exports=
{
/**
* Fetches context information for the admin blog page and handles post
* data sent regarding editing blog.
*
* @param templateContext json object used as the template context
* @returns {Promise} renders the template used for this page
*/
main: function(templateContext)
{
return new Promise(function(resolve, reject)
{
Promise.all([includes.fetchTemplate(TEMPLATE_FILE), generateData(templateContext)]).then(function(template)
{
templateContext.adminPage = template[0];
resolve();
}).catch(function(error)
{
console.log("error in add admin blog.js");
reject(error);
});
});
}
};

+ 3
- 10
config.json View File

@ -1,16 +1,9 @@
{ {
"PORT": 8000, "PORT": 8000,
"SESSION_SECRET": "random-data-to-seed-session-data", "SESSION_SECRET": "random-data-to-seed-session-data",
"SQL_HOST": "localhost",
"SQL_HOST": "db",
"SQL_DATABASE": "jrtechs_blog", "SQL_DATABASE": "jrtechs_blog",
"SQL_USER": "root", "SQL_USER": "root",
"SQL_PASSWORD": "password",
"CAPTCHA_SECRET": "captcha-secret",
"GMAIL_ACCOUNT": "email@gmail.com",
"EMAIL_PASSWORD": "email-password",
"DESTINATION_EMAIL": "destination email address"
"SQL_PASSWORD": "password"
} }

+ 0
- 3
includes/html/adminHeader.html View File

@ -82,9 +82,6 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/admin/users">Users</a> <a class="nav-link" href="/admin/users">Users</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="/admin/analytics">Analytics</a>
</li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li class="nav-item"> <li class="nav-item">

+ 0
- 20
templates/admin/analytics.html View File

@ -1,20 +0,0 @@
<h4 class="text-center">Traffic Graph</h4>
<div class="row">
<div class="col-12">
<div id="visualization"></div>
</div>
<br><br>
<script type="text/javascript">
var container = document.getElementById('visualization');
var items = {dataset};
var dataset = new vis.DataSet(items);
var options = {
start: {start},
end: {finish},
};
var graph2d = new vis.Graph2d(container, dataset, options);
</script>
</div>

+ 0
- 32
utils/sql.js View File

@ -551,37 +551,5 @@ module.exports=
}); });
}); });
},
/**
* Logs visited page for backend server analytics.
*
* @param ip
* @param page
*/
logTraffic: function(ip, page)
{
if(page.length > 40)
{
console.log("Error, request too long to log ip:"
+ ip + " page: " + page);
return;
}
if(ip.length > 20)
{
ip = "";
}
const q = "insert into traffic_log (url, ip, date) values " +
"('" + page + "', '" + ip + "', now())";
insert(q);
},
getTraffic: function()
{
return fetch("select * from traffic_log");
} }
}; };

Loading…
Cancel
Save