Redid all of the variable declarations
This commit is contained in:
parent
bc43092073
commit
182ec3ed9a
11 changed files with 104 additions and 105 deletions
10
api.js
10
api.js
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
|
||||
//Importing self-written modules.
|
||||
var lookup = require('./lookup');
|
||||
var schedule = require('./schedule');
|
||||
const lookup = require('./lookup');
|
||||
const schedule = require('./schedule');
|
||||
|
||||
/**
|
||||
* Takes the information from the request
|
||||
|
|
@ -58,8 +58,7 @@ function parse(req, res, next, api) {
|
|||
*/
|
||||
function error(str, res, data) {
|
||||
res.set('Content-Type', 'application/json');
|
||||
var error = JSON.stringify({'error' : str, 'data' : data}, null, 2);
|
||||
res.status(400).end(error);
|
||||
res.status(400).end(JSON.stringify({'error' : str, 'data' : data}, null, 2));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -72,8 +71,7 @@ function error(str, res, data) {
|
|||
*/
|
||||
function sendResponse(data, res, disablePretty) {
|
||||
res.set('Content-Type', 'application/json');
|
||||
var response = JSON.stringify({'data': data}, null, disablePretty ? 0 : 2);
|
||||
res.status(200).end(response);
|
||||
res.status(200).end(JSON.stringify({'data': data}, null, disablePretty ? 0 : 2));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
24
auth.js
24
auth.js
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
|
||||
//Importing first and third-party modules.
|
||||
var qs = require('querystring');
|
||||
var https = require('socks5-https-client');
|
||||
const qs = require('querystring');
|
||||
const https = require('socks5-https-client');
|
||||
|
||||
//Importing self-written modules.
|
||||
var crypt = require('./crypt');
|
||||
var config = require('./configuration');
|
||||
var lookup = require('./lookup');
|
||||
const crypt = require('./crypt');
|
||||
const config = require('./configuration');
|
||||
const lookup = require('./lookup');
|
||||
|
||||
/**
|
||||
* Function for starting a login request with the Magister servers.
|
||||
|
|
@ -21,7 +21,7 @@ var lookup = require('./lookup');
|
|||
* @param {Function} callback - Callback function to be called after request.
|
||||
*/
|
||||
function getLogin(username, password, callback) {
|
||||
var login = qs.stringify({
|
||||
let login = qs.stringify({
|
||||
GebruikersNaam : username,
|
||||
Wachtwoord : password
|
||||
});
|
||||
|
|
@ -52,18 +52,18 @@ function getLogin(username, password, callback) {
|
|||
* @param {Function} next - Next function supplied by Express.
|
||||
*/
|
||||
function login(req, res, next) {
|
||||
var _data = '';
|
||||
let _data = '';
|
||||
|
||||
req.on('data', function (data) {
|
||||
_data += data;
|
||||
});
|
||||
|
||||
req.on('end', function () {
|
||||
var loginInformation = qs.parse(_data)
|
||||
let loginInformation = qs.parse(_data)
|
||||
|
||||
getLogin(loginInformation.username, loginInformation.password, function (legit) {
|
||||
var username = crypt.encrypt(loginInformation.username);
|
||||
var password = crypt.encrypt(loginInformation.password);
|
||||
let username = crypt.encrypt(loginInformation.username);
|
||||
let password = crypt.encrypt(loginInformation.password);
|
||||
if (legit) {
|
||||
res.cookie('username', username);
|
||||
res.cookie('password', password);
|
||||
|
|
@ -93,10 +93,10 @@ function logout(req, res) {
|
|||
* @param {Function} next - Next function supplied by Express.
|
||||
*/
|
||||
function is(req, res, next) {
|
||||
var cookies = qs.parse((req.headers.cookie || '').replace(/\s/g, ''), ';', '=');
|
||||
let cookies = qs.parse((req.headers.cookie || '').replace(/\s/g, ''), ';', '=');
|
||||
if (!cookies.username || !cookies.password) {next(); return;}
|
||||
|
||||
var username = crypt.decrypt(cookies.username),
|
||||
let username = crypt.decrypt(cookies.username),
|
||||
password = crypt.decrypt(cookies.password);
|
||||
|
||||
getLogin(username, password, function (legit) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Function for the return/creating of a settings file/object.
|
||||
|
|
|
|||
22
crypt.js
22
crypt.js
|
|
@ -6,16 +6,16 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var crypto = require('crypto');
|
||||
const crypto = require('crypto');
|
||||
|
||||
//Import self-written modules.
|
||||
var config = require('./configuration');
|
||||
const config = require('./configuration');
|
||||
|
||||
//Set local variables.
|
||||
var encoding = 'utf8';
|
||||
var cryptEncoding = 'hex';
|
||||
var algo = 'aes192';
|
||||
var passwd = config().encryptionKey;
|
||||
//Set local constants.
|
||||
const encoding = 'utf8';
|
||||
const cryptEncoding = 'hex';
|
||||
const algo = 'aes192';
|
||||
const passwd = config().encryptionKey;
|
||||
|
||||
/**
|
||||
* Function for encrypting a string.
|
||||
|
|
@ -23,8 +23,8 @@ var passwd = config().encryptionKey;
|
|||
* @return {String} encryptArray - Encrypted string.
|
||||
*/
|
||||
function encrypt(str) {
|
||||
var cipher = crypto.createCipher(algo, passwd);
|
||||
var encryptArray = [];
|
||||
let cipher = crypto.createCipher(algo, passwd);
|
||||
let encryptArray = [];
|
||||
|
||||
encryptArray.push(cipher.update(str, encoding, cryptEncoding));
|
||||
encryptArray.push(cipher.final(cryptEncoding));
|
||||
|
|
@ -38,8 +38,8 @@ function encrypt(str) {
|
|||
* @return {String} The decrypted string.
|
||||
*/
|
||||
function decrypt(str) {
|
||||
var decipher = crypto.createDecipher(algo, passwd);
|
||||
var decryptArray = [];
|
||||
let decipher = crypto.createDecipher(algo, passwd);
|
||||
let decryptArray = [];
|
||||
|
||||
try {
|
||||
decryptArray.push(decipher.update(str, cryptEncoding, encoding));
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
//Import self-written modules.
|
||||
var config = require('./configuration');
|
||||
const config = require('./configuration');
|
||||
|
||||
/**
|
||||
* Function for using a database interface.
|
||||
|
|
@ -20,13 +20,13 @@ var config = require('./configuration');
|
|||
module.exports = function () {
|
||||
if (!config().localDatabase) return require('mongoskin').db('mongodb://' + config().database);
|
||||
else {
|
||||
var databases = {
|
||||
let databases = {
|
||||
index: new (require('nedb'))({ filename: __dirname + '/resources/databases/index.db', autoload: true})
|
||||
};
|
||||
|
||||
return {
|
||||
'collection': function (collection) {
|
||||
var database = databases[collection];
|
||||
let database = databases[collection];
|
||||
|
||||
database.drop = function () {
|
||||
fs.writeFileSync(database.filename, '');
|
||||
|
|
|
|||
18
lookup.js
18
lookup.js
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
//Importing first-party modules.
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
//Importing self-written modules.
|
||||
var config = require('./configuration');
|
||||
var database = require('./database')();
|
||||
const config = require('./configuration');
|
||||
const database = require('./database')();
|
||||
|
||||
//Getting local variables from the configuration file.
|
||||
var schoolID = config().schoolID;
|
||||
const schoolID = config().schoolID;
|
||||
|
||||
/**
|
||||
* Function for doing a lookup in the database containing all records
|
||||
|
|
@ -80,8 +80,8 @@ function handle(req, res, next, databaseEntry) {
|
|||
* @param {Function} callback - Callback function needed to return the API call.
|
||||
*/
|
||||
function api(req, callback) {
|
||||
var index = database.collection('index');
|
||||
var query = RegExp(req.query.name, 'i');
|
||||
let index = database.collection('index');
|
||||
let query = RegExp(req.query.name, 'i');
|
||||
|
||||
if (!config().localDatabase) {
|
||||
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}, {group: query}]}).toArray(function (err, databaseEntry) {
|
||||
|
|
@ -111,8 +111,8 @@ function api(req, callback) {
|
|||
* @param {String} list - The search (group) query given by the user.
|
||||
*/
|
||||
function list(req, res, next, list) {
|
||||
var index = database.collection('index');
|
||||
var query = RegExp(list, 'i');
|
||||
let index = database.collection('index');
|
||||
let query = RegExp(list, 'i');
|
||||
|
||||
if (!config().localDatabase) {
|
||||
index.find({group: list}).toArray(function (err, databaseEntry) {
|
||||
|
|
@ -177,7 +177,7 @@ function makeUrl(req, databaseEntry) {
|
|||
* @param {String} search - The user supplied search query.
|
||||
*/
|
||||
function easter(search) {
|
||||
var list = JSON.parse(fs.readFileSync(__dirname + '/eastereggs.json'));
|
||||
let list = JSON.parse(fs.readFileSync(__dirname + '/eastereggs.json'));
|
||||
|
||||
for (entry of list) {
|
||||
if (entry.easter == search.toLowerCase()) return entry;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
//Import first-party modules.
|
||||
var qs = require('querystring');
|
||||
const qs = require('querystring');
|
||||
|
||||
/**
|
||||
* Module for redirecting the user after they did a search query in any of the
|
||||
|
|
@ -16,15 +16,15 @@ var qs = require('querystring');
|
|||
* @param {Object} res - Response object supplied by Express.
|
||||
*/
|
||||
module.exports = function (req, res) {
|
||||
var referer = req.headers.referer.split('/')[3] || 'rooster';
|
||||
var _data = '';
|
||||
let referer = req.headers.referer.split('/')[3] || 'rooster';
|
||||
let _data = '';
|
||||
|
||||
req.on('data', function (data) {
|
||||
_data += data;
|
||||
});
|
||||
|
||||
req.on('end', function () {
|
||||
var query = qs.parse(_data);
|
||||
let query = qs.parse(_data);
|
||||
|
||||
if (query && query.search != '') {
|
||||
query.search = query.search.trim();
|
||||
|
|
|
|||
38
schedule.js
38
schedule.js
|
|
@ -7,14 +7,14 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var url = require('url');
|
||||
const url = require('url');
|
||||
|
||||
//Import third-party modules.
|
||||
var http = require('socks5-http-client');
|
||||
var cheerio = require('cheerio');
|
||||
const http = require('socks5-http-client');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
//Import self-written modules.
|
||||
var config = require('./configuration');
|
||||
const config = require('./configuration');
|
||||
|
||||
/**
|
||||
* Function being called by Express when the user requests a schedule.
|
||||
|
|
@ -35,12 +35,12 @@ function get(req, res, next) {
|
|||
* @param {Function} callback - Callback function to return the downloaded information.
|
||||
*/
|
||||
function getSchedule(getUrl, callback) {
|
||||
var options = url.parse(getUrl);
|
||||
let options = url.parse(getUrl);
|
||||
options.socksPort = config().torPort;
|
||||
options.socksHost = config().torHost;
|
||||
|
||||
http.get(options, function (res) {
|
||||
var _download = '';
|
||||
let _download = '';
|
||||
|
||||
res.on('data', function (data) {
|
||||
_download += data;
|
||||
|
|
@ -58,9 +58,9 @@ function getSchedule(getUrl, callback) {
|
|||
* @return {Array} names - An array populated with the schedule names (basic, week)
|
||||
*/
|
||||
function scheduleNames(page) {
|
||||
var extract = cheerio('table tr td[valign="bottom"] table tr td b, table tr td[valign="bottom"] table tr td a', page).text().split(/\s\s/);
|
||||
var tab = 0;
|
||||
var names = [];
|
||||
let extract = cheerio('table tr td[valign="bottom"] table tr td b, table tr td[valign="bottom"] table tr td a', page).text().split(/\s\s/);
|
||||
let tab = 0;
|
||||
let names = [];
|
||||
|
||||
for (element of extract) {
|
||||
element != '' ? names.push({
|
||||
|
|
@ -79,15 +79,15 @@ function scheduleNames(page) {
|
|||
* @return {Object} scheduleData - The converted JSON datastructure.
|
||||
*/
|
||||
function toJSON(page) {
|
||||
var result = cheerio('td:nth-child(3) table', page);
|
||||
var names = scheduleNames(page);
|
||||
var isTeacher = cheerio(cheerio(page).find('tr.CoreDark').find('td')[3]).find('a').html() == null;
|
||||
var amountOfDays = cheerio(result).find('tr.AccentDark').find('td').length - 1;
|
||||
var amountOfHours = config().amountOfHours;
|
||||
let result = cheerio('td:nth-child(3) table', page);
|
||||
let names = scheduleNames(page);
|
||||
let isTeacher = cheerio(cheerio(page).find('tr.CoreDark').find('td')[3]).find('a').html() == null;
|
||||
let amountOfDays = cheerio(result).find('tr.AccentDark').find('td').length - 1;
|
||||
let amountOfHours = config().amountOfHours;
|
||||
|
||||
var scheduleData = [];
|
||||
let scheduleData = [];
|
||||
|
||||
var offset = isTeacher ? 5 : 6;
|
||||
let offset = isTeacher ? 5 : 6;
|
||||
|
||||
//Looping for amount of days
|
||||
for (day = 0; day < amountOfDays; day++) {
|
||||
|
|
@ -95,13 +95,13 @@ function toJSON(page) {
|
|||
|
||||
//Looping for amount of hours
|
||||
for (hour = 0; hour < amountOfHours; hour++) {
|
||||
var schedule = cheerio('tr:nth-child('+ (offset + hour) +')', result);
|
||||
let schedule = cheerio('tr:nth-child('+ (offset + hour) +')', result);
|
||||
|
||||
//Looping for (optional) specialhours
|
||||
var specialHours = schedule.find('table').eq(day).children().length;
|
||||
let specialHours = schedule.find('table').eq(day).children().length;
|
||||
scheduleData[day][hour] = {teacher: [], chamber: [], course: [], changed: []};
|
||||
for (subhour = 0; subhour < specialHours; subhour++) {
|
||||
var selectedHour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td');
|
||||
let selectedHour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td');
|
||||
//Give the value of the schedule hour to the fitting array.
|
||||
scheduleData[day][hour].teacher[subhour] = selectedHour.eq(0).text().replace(/\r|\n/g, '');
|
||||
scheduleData[day][hour].chamber[subhour] = selectedHour.eq(2).text();
|
||||
|
|
|
|||
41
spider.js
41
spider.js
|
|
@ -7,25 +7,26 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var url = require('url');
|
||||
const url = require('url');
|
||||
|
||||
//Import third-party modules
|
||||
var http = require('socks5-http-client');
|
||||
var cheerio = require('cheerio');
|
||||
var iconv = require('iconv-lite');
|
||||
const http = require('socks5-http-client');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
//Import self-written modules.
|
||||
var config = require('./configuration');
|
||||
var database = require('./database')();
|
||||
const config = require('./configuration');
|
||||
const database = require('./database')();
|
||||
|
||||
//Define local variables.
|
||||
const schoolID = config().schoolID;
|
||||
|
||||
var scheduletypes = [
|
||||
'Klasrooster',
|
||||
'Docentrooster',
|
||||
'Leerlingrooster',
|
||||
'Lokaalrooster'
|
||||
];
|
||||
var schoolID = config().schoolID;
|
||||
|
||||
/**
|
||||
* Function for crawling the schedule site for data such as: students, teachers
|
||||
|
|
@ -38,13 +39,13 @@ function crawl() {
|
|||
|
||||
(function (scheduletype) {
|
||||
|
||||
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + scheduletype);
|
||||
let options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + scheduletype);
|
||||
options.socksPort = config().torPort;
|
||||
options.socksHost = config().torHost;
|
||||
|
||||
http.get(options, function (res) {
|
||||
|
||||
var _download = {};
|
||||
let _download = {};
|
||||
_download.type = scheduletype;
|
||||
|
||||
res.on('data', function (data) {
|
||||
|
|
@ -66,7 +67,7 @@ function crawl() {
|
|||
* @param {String} page - A string containing a downloaded schedule page.
|
||||
*/
|
||||
function extract(page) {
|
||||
var array = cheerio('select', page).text().split('\n');
|
||||
let array = cheerio('select', page).text().split('\n');
|
||||
return array.splice(1, array.length - 2);
|
||||
}
|
||||
|
||||
|
|
@ -75,36 +76,36 @@ function extract(page) {
|
|||
* @param {String} page - A string containing a downloaded schedule page.
|
||||
*/
|
||||
function rip(page) {
|
||||
var list = extract(page.data);
|
||||
var collection = database.collection('index');
|
||||
let list = extract(page.data);
|
||||
let collection = database.collection('index');
|
||||
|
||||
if (page.type == 'Leerlingrooster') {
|
||||
|
||||
for(studentcategory of list) {
|
||||
|
||||
(function (studentcategory) {
|
||||
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + page.type + '&afdeling=' + studentcategory);
|
||||
let options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + page.type + '&afdeling=' + studentcategory);
|
||||
options.socksPort = config().torPort;
|
||||
options.socksHost = config().torHost;
|
||||
|
||||
http.get(options, function (res) {
|
||||
var _download = '';
|
||||
let _download = '';
|
||||
|
||||
res.on('data', function (data) {
|
||||
_download += iconv.decode(data, 'binary');
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
var listOfStudents = cheerio('select', _download).children();
|
||||
let listOfStudents = cheerio('select', _download).children();
|
||||
|
||||
for (student in listOfStudents) {
|
||||
|
||||
if (!isNaN(student)) {
|
||||
var name = cheerio(listOfStudents[student]).text().split(' - ')[1];
|
||||
var group = cheerio(listOfStudents[student]).text().split(' - ')[0];
|
||||
var id = cheerio(listOfStudents[student]).val();
|
||||
let name = cheerio(listOfStudents[student]).text().split(' - ')[1];
|
||||
let group = cheerio(listOfStudents[student]).text().split(' - ')[0];
|
||||
let id = cheerio(listOfStudents[student]).val();
|
||||
|
||||
var databaseEntry = {
|
||||
let databaseEntry = {
|
||||
'id' : id,
|
||||
'group' : group,
|
||||
'username' : id + name.split(' ')[0].toLowerCase(),
|
||||
|
|
@ -132,7 +133,7 @@ function rip(page) {
|
|||
}
|
||||
else {
|
||||
for (entry of list) {
|
||||
var databaseEntry = {
|
||||
let databaseEntry = {
|
||||
'name' : entry,
|
||||
'type' : page.type.replace(/rooster/g, '').toLowerCase()
|
||||
}
|
||||
|
|
|
|||
12
time.js
12
time.js
|
|
@ -8,14 +8,14 @@
|
|||
*/
|
||||
|
||||
//Importing self-written modules.
|
||||
var config = require('./configuration');
|
||||
const config = require('./configuration');
|
||||
|
||||
/**
|
||||
* Function for getting the time, with minutes as a fracture.
|
||||
* @return {Float} time - The time, fractured (20.5 instead of 20:30)
|
||||
*/
|
||||
function get() {
|
||||
var time = new Date();
|
||||
let time = new Date();
|
||||
return time.getHours() + (time.getMinutes() / 60);
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +25,8 @@ function get() {
|
|||
* @return {Array} array - An array containing the time string split in two.
|
||||
*/
|
||||
function parse(timestr) {
|
||||
var parsed = timestr.match(/\d{1,2}:\d+/g);
|
||||
var array = [];
|
||||
let parsed = timestr.match(/\d{1,2}:\d+/g);
|
||||
let array = [];
|
||||
|
||||
for (time of parsed) {
|
||||
array.push(parseInt(time.split(':')[0]) + (parseInt(time.split(':')[1]) / 60));
|
||||
|
|
@ -51,8 +51,8 @@ function withinTimespan(timespan) {
|
|||
* @return {Boolean} - Returns true if the current time is within the timespan or false when it's not.
|
||||
*/
|
||||
function duringSchool() {
|
||||
var start = parse(config().times[0])[0];
|
||||
var end = parse(config().times[config().times.length - 1])[1];
|
||||
let start = parse(config().times[0])[0];
|
||||
let end = parse(config().times[config().times.length - 1])[1];
|
||||
|
||||
if (get() > start && get() < end) return true;
|
||||
else return false;
|
||||
|
|
|
|||
26
web.js
26
web.js
|
|
@ -7,21 +7,21 @@
|
|||
*/
|
||||
|
||||
//Import first-party modules.
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
//Import third-party modules.
|
||||
var express = require('express');
|
||||
var less = require('express-less');
|
||||
var body_parser = require('body-parser');
|
||||
const express = require('express');
|
||||
const less = require('express-less');
|
||||
const body_parser = require('body-parser');
|
||||
|
||||
//Import self-written modules.
|
||||
var api = require('./api');
|
||||
var config = require('./configuration');
|
||||
var lookup = require('./lookup');
|
||||
var schedule = require('./schedule');
|
||||
var auth = require('./auth');
|
||||
var redirecter = require('./redirecter');
|
||||
var time = require('./time');
|
||||
const api = require('./api');
|
||||
const config = require('./configuration');
|
||||
const lookup = require('./lookup');
|
||||
const schedule = require('./schedule');
|
||||
const auth = require('./auth');
|
||||
const redirecter = require('./redirecter');
|
||||
const time = require('./time');
|
||||
|
||||
//Setting local variables.
|
||||
var app = express();
|
||||
|
|
@ -83,9 +83,9 @@ function plugins() {
|
|||
var pluginsDirectory = fs.readdirSync(__dirname + '/plugins');
|
||||
|
||||
for (plugin of pluginsDirectory) {
|
||||
var app = __dirname + '/plugins/' + plugin + '/app.js';
|
||||
let app = __dirname + '/plugins/' + plugin + '/app.js';
|
||||
if (fs.existsSync(app)) {
|
||||
var app = require(app)(config().webPort + (1 + pluginsDirectory.indexOf(plugin)), config().webHost);
|
||||
let app = require(app)(config().webPort + (1 + pluginsDirectory.indexOf(plugin)), config().webHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue