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