mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Merge branch 'master' of https://gitlab.com/YourFriendlyNeighborhoodDealer/question-node-server
This commit is contained in:
		@@ -4,3 +4,5 @@ Install:
 | 
			
		||||
    npm install express connect-busboy ejs express-layout querystring express
 | 
			
		||||
 | 
			
		||||
some stuff maybe missing 
 | 
			
		||||
 | 
			
		||||
"Client:" https://gitlab.com/YourFriendlyNeighborhoodDealer/moodle-test-userscript
 | 
			
		||||
							
								
								
									
										311
									
								
								actions.js
									
									
									
									
									
								
							
							
						
						
									
										311
									
								
								actions.js
									
									
									
									
									
								
							@@ -21,16 +21,202 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
	ProcessIncomingRequest: ProcessIncomingRequest,
 | 
			
		||||
	CheckData: CheckData,
 | 
			
		||||
	NLoad: NLoad
 | 
			
		||||
	NLoad: NLoad,
 | 
			
		||||
	LoadJSON: LoadJSON
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var recievedFile = "stats/recieved";
 | 
			
		||||
var staticFile = "public/data/static";
 | 
			
		||||
var manFile = "public/man.html";
 | 
			
		||||
var dataFile = "public/data.json";
 | 
			
		||||
var motdFile = "public/motd";
 | 
			
		||||
 | 
			
		||||
var logger = require('./logger.js');
 | 
			
		||||
var utils = require('./utils.js');
 | 
			
		||||
 | 
			
		||||
class Question {
 | 
			
		||||
	constructor(q, a, i) {
 | 
			
		||||
		this.Q = q;
 | 
			
		||||
		this.A = a;
 | 
			
		||||
		this.I = i;
 | 
			
		||||
	}
 | 
			
		||||
	toString() {
 | 
			
		||||
		var r = "?" + this.Q + "\n!" + this.A;
 | 
			
		||||
		if (this.I)
 | 
			
		||||
			r += "\n>" + this.I;
 | 
			
		||||
		return r;
 | 
			
		||||
	}
 | 
			
		||||
	HasQuestion() {
 | 
			
		||||
		return this.Q != undefined;
 | 
			
		||||
	}
 | 
			
		||||
	HasAnswer() {
 | 
			
		||||
		return this.A != undefined;
 | 
			
		||||
	}
 | 
			
		||||
	HasImage() {
 | 
			
		||||
		return this.I != undefined;
 | 
			
		||||
	}
 | 
			
		||||
	IsComplete() {
 | 
			
		||||
		return this.HasQuestion() && this.HasAnswer();
 | 
			
		||||
	}
 | 
			
		||||
	Compare(q2, i) {
 | 
			
		||||
		if (typeof q2 == 'string') {
 | 
			
		||||
			var qmatchpercent = Question.CompareString(this.Q, q2);
 | 
			
		||||
 | 
			
		||||
			if (i == undefined || i.length == 0)
 | 
			
		||||
				return qmatchpercent;
 | 
			
		||||
			else {
 | 
			
		||||
				if (this.HasImage()) {
 | 
			
		||||
					const imatchpercent = this.HasImage() ? Question.CompareString(this.I.join(" "), i.join(" ")) :
 | 
			
		||||
						0;
 | 
			
		||||
					return (qmatchpercent + imatchpercent) / 2;
 | 
			
		||||
				} else {
 | 
			
		||||
					qmatchpercent -= 30;
 | 
			
		||||
					if (qmatchpercent < 0)
 | 
			
		||||
						return 0;
 | 
			
		||||
					else
 | 
			
		||||
						return qmatchpercent;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			const qmatchpercent = Question.CompareString(this.Q, q2.Q);
 | 
			
		||||
			const amatchpercent = Question.CompareString(this.A, q2.A);
 | 
			
		||||
			if (this.I != undefined) {
 | 
			
		||||
				const imatchpercent = this.I == undefined ? Question.CompareString(this.I.join(" "), q2.I.join(
 | 
			
		||||
					" ")) : 0;
 | 
			
		||||
				return (qmatchpercent + amatchpercent + imatchpercent) / 3;
 | 
			
		||||
			} else {
 | 
			
		||||
				return (qmatchpercent + amatchpercent) / 2;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	static CompareString(s1, s2) {
 | 
			
		||||
		//if (s1 == undefined || s2 == undefined)
 | 
			
		||||
		//	return 0;
 | 
			
		||||
		s1 = SimplifyStringForComparison(s1).split(" ");
 | 
			
		||||
		s2 = SimplifyStringForComparison(s2).split(" ");
 | 
			
		||||
		var match = 0;
 | 
			
		||||
		for (var i = 0; i < s1.length; i++)
 | 
			
		||||
			if (s2.includes(s1[i]))
 | 
			
		||||
				match++;
 | 
			
		||||
		var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
 | 
			
		||||
		var lengthDifference = Math.abs(s2.length - s1.length);
 | 
			
		||||
		percent -= lengthDifference * 3;
 | 
			
		||||
		if (percent < 0)
 | 
			
		||||
			percent = 0;
 | 
			
		||||
		return percent;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Subject {
 | 
			
		||||
	constructor(n) {
 | 
			
		||||
		this.Name = n;
 | 
			
		||||
		this.Questions = [];
 | 
			
		||||
	}
 | 
			
		||||
	get length() {
 | 
			
		||||
		return this.Questions.length;
 | 
			
		||||
	}
 | 
			
		||||
	AddQuestion(q) {
 | 
			
		||||
		this.Questions.push(q);
 | 
			
		||||
	}
 | 
			
		||||
	Search(q, img) {
 | 
			
		||||
		var r = [];
 | 
			
		||||
		for (var i = 0; i < this.length; i++) {
 | 
			
		||||
			let percent = this.Questions[i].Compare(q, img);
 | 
			
		||||
			if (percent > minMatchAmmount)
 | 
			
		||||
				r.push({
 | 
			
		||||
					q: this.Questions[i],
 | 
			
		||||
					match: percent
 | 
			
		||||
				});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for (var i = 0; i < r.length; i++)
 | 
			
		||||
			for (var j = i; j < r.length; j++)
 | 
			
		||||
				if (r[i].match < r[j].match) {
 | 
			
		||||
					var tmp = r[i];
 | 
			
		||||
					r[i] = r[j];
 | 
			
		||||
					r[j] = tmp;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
		return r;
 | 
			
		||||
	}
 | 
			
		||||
	toString() {
 | 
			
		||||
		var r = [];
 | 
			
		||||
		for (var i = 0; i < this.Questions.length; i++)
 | 
			
		||||
			r.push(this.Questions[i].toString());
 | 
			
		||||
		return "+" + this.Name + "\n" + r.join("\n");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class QuestionDB {
 | 
			
		||||
	constructor() {
 | 
			
		||||
		this.Subjects = [];
 | 
			
		||||
	}
 | 
			
		||||
	get length() {
 | 
			
		||||
		return this.Subjects.length;
 | 
			
		||||
	}
 | 
			
		||||
	get activeIndexes() {
 | 
			
		||||
		var r = [];
 | 
			
		||||
		for (var i = 0; i < this.length; i++) {
 | 
			
		||||
			if (GM_getValue("Is" + i + "Active")) {
 | 
			
		||||
				r.push(i);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return r;
 | 
			
		||||
	}
 | 
			
		||||
	GetIfActive(ind) {
 | 
			
		||||
		return GM_getValue("Is" + ind + "Active");
 | 
			
		||||
	}
 | 
			
		||||
	ChangeActive(i, value) {
 | 
			
		||||
		GM_setValue("Is" + i + "Active", !!value);
 | 
			
		||||
	}
 | 
			
		||||
	AddQuestion(subj, q) {
 | 
			
		||||
		var i = 0;
 | 
			
		||||
		while (i < this.Subjects.length && this.Subjects[i].Name != subj)
 | 
			
		||||
			i++;
 | 
			
		||||
		if (i < this.Subjects.length)
 | 
			
		||||
			this.Subjects[i].AddQuestion(q);
 | 
			
		||||
		else {
 | 
			
		||||
			const n = new Subject(subj);
 | 
			
		||||
			n.AddQuestion(q);
 | 
			
		||||
			this.Subjects.push(n);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	Search(q, img) {
 | 
			
		||||
		var r = [];
 | 
			
		||||
		for (var i = 0; i < this.length; i++)
 | 
			
		||||
			if (this.GetIfActive(i))
 | 
			
		||||
				r = r.concat(this.Subjects[i].Search(q, img));
 | 
			
		||||
 | 
			
		||||
		for (var i = 0; i < r.length; i++)
 | 
			
		||||
			for (var j = i; j < r.length; j++)
 | 
			
		||||
				if (r[i].match < r[j].match) {
 | 
			
		||||
					var tmp = r[i];
 | 
			
		||||
					r[i] = r[j];
 | 
			
		||||
					r[j] = tmp;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
		return r;
 | 
			
		||||
	}
 | 
			
		||||
	AddSubject(subj) {
 | 
			
		||||
		var i = 0;
 | 
			
		||||
		while (i < this.length && subj.Name != this.Subjects[i].Name)
 | 
			
		||||
			i++;
 | 
			
		||||
 | 
			
		||||
		if (i < this.length) {
 | 
			
		||||
			this.Subjects.concat(subj.Questions);
 | 
			
		||||
		} else {
 | 
			
		||||
			this.Subjects.push(subj);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	toString() {
 | 
			
		||||
		var r = [];
 | 
			
		||||
		for (var i = 0; i < this.Subjects.length; i++)
 | 
			
		||||
			r.push(this.Subjects[i].toString());
 | 
			
		||||
		return r.join("\n\n");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function Process(d, file) {
 | 
			
		||||
	try {
 | 
			
		||||
		logger.Log("[PCES]:\tFile: " + file);
 | 
			
		||||
@@ -77,39 +263,64 @@ function ProcessIncomingRequest(data) {
 | 
			
		||||
		logger.Log("[PCES]:\tRecieved data is undefined!", logger.GetColor("redbg"));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var d = SetupData(data);
 | 
			
		||||
	var qcount = -1;
 | 
			
		||||
	try {
 | 
			
		||||
		var splitted = d.alldata.split("\n");
 | 
			
		||||
		var count = 0;
 | 
			
		||||
		for (var i = 0; i < splitted.length; i++)
 | 
			
		||||
			if (splitted[i][0] == '?')
 | 
			
		||||
				count ++;
 | 
			
		||||
		qcount = count;
 | 
			
		||||
	} catch (e) {console.log("Error :c"); console.log(e);}
 | 
			
		||||
		var d = JSON.parse(data);
 | 
			
		||||
		var dfile = utils.ReadFile(dataFile);
 | 
			
		||||
		var data = LoadJSON(dfile);
 | 
			
		||||
		var allQuestions = [];
 | 
			
		||||
		for ( var i = 0; i < d.allData.length; i++){
 | 
			
		||||
			allQuestions.push(new Question(d.allData[i].Q, d.allData[i].A, d.allData[i].I));
 | 
			
		||||
		}
 | 
			
		||||
		var questions = [];
 | 
			
		||||
		for ( var i = 0; i < d.data.length; i++){
 | 
			
		||||
			let q = new Question(d.data[i].Q, d.data[i].A, d.data[i].I);
 | 
			
		||||
			questions.push(q);
 | 
			
		||||
			data.AddQuestion(d.subj, q);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		var motd = utils.ReadFile(motdFile);
 | 
			
		||||
		data.motd = motd;
 | 
			
		||||
		logger.Log("[PCES]:\t" + d.subj);
 | 
			
		||||
		var msg = "All / new count: " + allQuestions.length + " / " + questions.length;
 | 
			
		||||
		if (d.version != undefined)
 | 
			
		||||
			msg += ". Version: " + d.version;
 | 
			
		||||
		var color = logger.GetColor("green");
 | 
			
		||||
 | 
			
		||||
	logger.Log("[PCES]:\tProcessing data: " + d.subj + " (" + d.type + "), count: " + qcount, logger.GetColor("green"));
 | 
			
		||||
	if (d.subj == undefined){
 | 
			
		||||
		logger.Log(JSON.stringify(d), logger.GetColor("red"));
 | 
			
		||||
		return;
 | 
			
		||||
		if (data != undefined && d.data.length > 0){
 | 
			
		||||
			utils.WriteBackup();
 | 
			
		||||
			utils.WriteFile(JSON.stringify(data), dataFile);
 | 
			
		||||
			msg += " - Data file written!";
 | 
			
		||||
			var color = logger.GetColor("blue");
 | 
			
		||||
		}
 | 
			
		||||
		logger.Log("[PCES]:\t" + msg, color);
 | 
			
		||||
 | 
			
		||||
	} catch (e) {
 | 
			
		||||
		console.log(e);
 | 
			
		||||
		logger.Log("[PCES]: Couldnt parse JSON data, trying old format...");
 | 
			
		||||
		var d = SetupData(data);
 | 
			
		||||
		var qcount = -1;
 | 
			
		||||
		try {
 | 
			
		||||
			var splitted = d.alldata.split("\n");
 | 
			
		||||
			var count = 0;
 | 
			
		||||
			for (var i = 0; i < splitted.length; i++)
 | 
			
		||||
				if (splitted[i][0] == '?')
 | 
			
		||||
					count ++;
 | 
			
		||||
			qcount = count;
 | 
			
		||||
		} catch (e) {console.log("Error :c"); console.log(e);}
 | 
			
		||||
 | 
			
		||||
		logger.Log("[PCES]:\tProcessing data: " + d.subj + " (" + d.type + "), count: " + qcount, logger.GetColor("green"));
 | 
			
		||||
		if (d.subj == undefined){
 | 
			
		||||
			logger.Log(JSON.stringify(d), logger.GetColor("red"));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var newItems = 0;
 | 
			
		||||
 | 
			
		||||
		var newStatItems = Process(d, staticFile);
 | 
			
		||||
 | 
			
		||||
		utils.AppendToFile(logger.GetDateString() + "\n" + d.data, recievedFile);
 | 
			
		||||
		PrintNewCount(d, newStatItems, staticFile);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var newItems = 0;
 | 
			
		||||
 | 
			
		||||
	/*if (d.type == 0) // -> safe, static
 | 
			
		||||
		newItems = Process(d, staticFile);
 | 
			
		||||
	else if (d.type == 1) // -> unsafe, public
 | 
			
		||||
		newItems = Process(d, publicFile);
 | 
			
		||||
	else { // -> error, or old client
 | 
			
		||||
		logger.Log("[PCES]: Old client...");
 | 
			
		||||
		Process(d, publicFile);
 | 
			
		||||
		Process(d, staticFile);
 | 
			
		||||
	}*/
 | 
			
		||||
	var newStatItems = Process(d, staticFile);
 | 
			
		||||
 | 
			
		||||
	utils.AppendToFile(logger.GetDateString() + "\n" + d.data, recievedFile);
 | 
			
		||||
	PrintNewCount(d, newStatItems, staticFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function PrintNewCount(d, newItems, file) {
 | 
			
		||||
@@ -125,15 +336,20 @@ function PrintNewCount(d, newItems, file) {
 | 
			
		||||
 | 
			
		||||
function SetupData(data) {
 | 
			
		||||
	var pdata = data.split("<#>");
 | 
			
		||||
	if (pdata.length <= 0)
 | 
			
		||||
	if (pdata.length <= 0){
 | 
			
		||||
		logger.Log("[SUPD]: Data length is zero !", logger.GetColor("redbg"));
 | 
			
		||||
		throw "No data recieved!";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var d = {}; // parsed data
 | 
			
		||||
	for (var i = 0; i < pdata.length; i++) {
 | 
			
		||||
		var td = pdata[i].split("<=>");
 | 
			
		||||
		if (td.length == 2)
 | 
			
		||||
			d[td[0]] = td[1];
 | 
			
		||||
		else
 | 
			
		||||
		else {
 | 
			
		||||
			logger.Log("[SUPD]: Invalid parameter!", logger.GetColor("redbg"));
 | 
			
		||||
			throw "Invalid parameter recieved!";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return d;
 | 
			
		||||
}
 | 
			
		||||
@@ -242,3 +458,32 @@ function NLoad(resource) {
 | 
			
		||||
		log: resultLog
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// loading stuff
 | 
			
		||||
function LoadJSON(resource) {
 | 
			
		||||
	var count = -1;
 | 
			
		||||
	try {
 | 
			
		||||
		var	d = JSON.parse(resource);
 | 
			
		||||
		var r = new QuestionDB();
 | 
			
		||||
		var rt = [];
 | 
			
		||||
		var allCount = -1;
 | 
			
		||||
 | 
			
		||||
		for (var i = 0; i < d.Subjects.length; i++) {
 | 
			
		||||
			let s = new Subject(d.Subjects[i].Name);
 | 
			
		||||
			var j = 0;
 | 
			
		||||
			for (j = 0; j < d.Subjects[i].Questions.length; j++) {
 | 
			
		||||
				var currQ = d.Subjects[i].Questions[j];
 | 
			
		||||
				s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I));
 | 
			
		||||
			}
 | 
			
		||||
			rt.push({
 | 
			
		||||
				name: d.Subjects[i].Name,
 | 
			
		||||
				count: j
 | 
			
		||||
			});
 | 
			
		||||
			allCount += j;
 | 
			
		||||
			r.AddSubject(s);
 | 
			
		||||
		}
 | 
			
		||||
		return r;
 | 
			
		||||
	} catch (e) {
 | 
			
		||||
			logger.Log("[LOAD]:Error loading sutff", logger.GetColor("redbg"), true);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,8 +24,6 @@
 | 
			
		||||
			}
 | 
			
		||||
		</style>
 | 
			
		||||
	</head>
 | 
			
		||||
	<img src="https://greasyfork.org/system/screenshots/screenshots/000/012/446/original/rtfm.jpg"
 | 
			
		||||
	alt="img" height=1 style="visibility:hidden" />
 | 
			
		||||
	<center>
 | 
			
		||||
		<h1>Moodle/Elearnig/KMOOC manual</h1>
 | 
			
		||||
	</center>
 | 
			
		||||
@@ -33,16 +31,6 @@
 | 
			
		||||
		Ez a userscript Moodle/Elearnig/KMOOC tesztek megoldása során segítséget jelenít meg.
 | 
			
		||||
	</center>
 | 
			
		||||
	</p>
 | 
			
		||||
	<center>
 | 
			
		||||
		<img src="https://greasyfork.org/system/screenshots/screenshots/000/010/158/original/1.jpeg"
 | 
			
		||||
		width="30%" alt="img"/>
 | 
			
		||||
		<img src="https://greasyfork.org/system/screenshots/screenshots/000/010/159/original/2.jpeg"
 | 
			
		||||
		width="30%" alt="img" />
 | 
			
		||||
		<img
 | 
			
		||||
		src="https://greasyfork.org/system/screenshots/screenshots/000/010/643/original/script.png"
 | 
			
		||||
		width="30%" alt="img" />
 | 
			
		||||
	</center>
 | 
			
		||||
	</p>
 | 
			
		||||
	<b>A válasz ablakban jobb felül lévő százalék jelzi, hogy mekkora eséllyel jó a megoldás. Ez
 | 
			
		||||
	sokszor jó viszonyítás, de semmi sem biztos! Bármikor előfordulhat, hogy nem jó a
 | 
			
		||||
	megjelenített válasz! Ezért csak saját felelőségedre használd!</b> Sok kikerülhetetlen
 | 
			
		||||
@@ -132,6 +120,8 @@ változtatni akarsz, akkor illik tudni
 | 
			
		||||
			</p> A script radiobuttonos, tickboxos, képes és szöveges kérdéseknél is jól működik. Egyéb
 | 
			
		||||
			típusú kérdésekre nincsen (nagyon) felkészítve.
 | 
			
		||||
 | 
			
		||||
			</p> Érdemes az éppen nem használt tárgyakat nem-bepipálni, mert akkor baromi sok kérdés
 | 
			
		||||
			közül kell keresni, és az előfordulhat, hogy lassú.
 | 
			
		||||
			</p> Egyéb funkciók: 
 | 
			
		||||
			<ul>
 | 
			
		||||
				<li>
 | 
			
		||||
@@ -162,8 +152,7 @@ változtatni akarsz, akkor illik tudni
 | 
			
		||||
 | 
			
		||||
		</td>
 | 
			
		||||
		<td width=20%>
 | 
			
		||||
			<img src="https://greasyfork.org/system/screenshots/screenshots/000/012/446/original/rtfm.jpg"
 | 
			
		||||
			alt="img" />
 | 
			
		||||
			<img src="img/rtfm.jpg" alt="img"/>
 | 
			
		||||
		</td>
 | 
			
		||||
	</table>
 | 
			
		||||
	<center>
 | 
			
		||||
@@ -314,18 +303,21 @@ változtatni akarsz, akkor illik tudni
 | 
			
		||||
	<ul>
 | 
			
		||||
		<li>
 | 
			
		||||
			<b>1. Mindent megcsináltam, mégsem hajlandó beolvasni a fájlt</b>
 | 
			
		||||
			</br> Ha netről szeded a kérdéseket, akkor nem online a webszerver.
 | 
			
		||||
			</br> Ha (tényleg) rendesen bemásoltad a @resource-hoz az elérési utat, és még mindég
 | 
			
		||||
			nem működik: A böngésződ nem éri el a file-t. Chrome/Opera: bővítményeknél engedélyezni
 | 
			
		||||
			kell a fájlelérést. (Allow acces to file URLs bővítményeknél) Firefoxnál csak a
 | 
			
		||||
			tampermonkey-nél kell álligatni más böngészőt meg nem ismerek. Ezután Tampermonkey
 | 
			
		||||
			beállítása, hogy használja a @resource-ot: Klikk az ikonra böngésződnél, majd dashboard
 | 
			
		||||
			-> Settings tab -> "Config mode: " Advanced. Ezután meg kell jelennie egy olyan
 | 
			
		||||
			részlegnek, hogy "Security" (ha nem frissítsd az oldalt). Ott : "Allow scripts to access
 | 
			
		||||
			local files" -> "Externals (@require and @resource) Ha üres a txt-d, akkor még hibát fog
 | 
			
		||||
			jelezni, de amint első kérdésekkel feltöltöd jónak kellene lennie. Ha mégsem, akkor
 | 
			
		||||
			F12-> console -> és ott van egy pár log, ami hátha segít.
 | 
			
		||||
 | 
			
		||||
			</br> Ha netről szeded a kérdéseket, akkor nem online a webszerver, vagy éppen nem aktív
 | 
			
		||||
			a tárgyad a menüben. Jobb alsó sarokban lévő 'M' gombra kattintva fel kell ugorjon egy
 | 
			
		||||
			menü, és ott az éppen megoldani kívánt tárgy melett ki kell hogy legyen pipálva a
 | 
			
		||||
			tickbox.
 | 
			
		||||
			</br> Helyi fájl használata: Ha (tényleg) rendesen bemásoltad a @resource-hoz az elérési
 | 
			
		||||
			utat, és még mindég nem működik: A böngésződ nem éri el a file-t. Chrome/Opera:
 | 
			
		||||
			bővítményeknél engedélyezni kell a fájlelérést. (Allow acces to file URLs
 | 
			
		||||
					bővítményeknél) Firefoxnál csak a tampermonkey-nél kell álligatni más böngészőt
 | 
			
		||||
			meg nem ismerek. Ezután Tampermonkey beállítása, hogy használja a @resource-ot: Klikk az
 | 
			
		||||
			ikonra böngésződnél, majd dashboard -> Settings tab -> "Config mode: " Advanced. Ezután
 | 
			
		||||
			meg kell jelennie egy olyan részlegnek, hogy "Security" (ha nem frissítsd az oldalt).
 | 
			
		||||
			Ott : "Allow scripts to access local files" -> "Externals (@require and @resource) Ha
 | 
			
		||||
			üres a txt-d, akkor még hibát fog jelezni, de amint első kérdésekkel feltöltöd jónak
 | 
			
		||||
			kellene lennie. Ha mégsem, akkor F12-> console -> és ott van egy pár log, ami hátha
 | 
			
		||||
			segít.
 | 
			
		||||
		</li>
 | 
			
		||||
		</p>
 | 
			
		||||
		<li>
 | 
			
		||||
@@ -363,7 +355,7 @@ változtatni akarsz, akkor illik tudni
 | 
			
		||||
				programodnál. Ez nélkül nem működik.</li>
 | 
			
		||||
				<li>Nem elérhető a szerver. Ezt ellenőrizheted: <a
 | 
			
		||||
				href="http://questionmining.tk/">link</a></li>
 | 
			
		||||
				<li>Lehet hibás a nem karbantartott kérdés adatok.</li>
 | 
			
		||||
				<li>Nincs kiválasztva a megoldani kívánt tárgy a menüben.</li>
 | 
			
		||||
			</ul>
 | 
			
		||||
		</li>
 | 
			
		||||
		</p>
 | 
			
		||||
@@ -406,8 +398,6 @@ consolra ki vannak írva, amit f12 megnyitásával tudsz előhozni (chrome/firef
 | 
			
		||||
	|
 | 
			
		||||
	<a target="_blank" href="http://questionmining.tk/">Weboldal</a>
 | 
			
		||||
	</h1>
 | 
			
		||||
	</p>
 | 
			
		||||
	<img src="img/thanks.png" alt="img"/>
 | 
			
		||||
	</center>
 | 
			
		||||
	<script>
 | 
			
		||||
		function conv() {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										71
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								server.js
									
									
									
									
									
								
							@@ -23,6 +23,8 @@ var bodyParser = require('body-parser');
 | 
			
		||||
var busboy = require('connect-busboy');
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
var app = express();
 | 
			
		||||
var http = require('http');
 | 
			
		||||
var https = require('https');
 | 
			
		||||
 | 
			
		||||
var logger = require('./logger.js');
 | 
			
		||||
var utils = require('./utils.js');
 | 
			
		||||
@@ -34,42 +36,42 @@ var bodyParser = require('body-parser');
 | 
			
		||||
const recivedFiles = "public/recivedfiles";
 | 
			
		||||
const motdFile = "public/motd";
 | 
			
		||||
const staticFile = "public/data/static";
 | 
			
		||||
const dataFile = "public/data.json";
 | 
			
		||||
const countFile = "public/data/count";
 | 
			
		||||
const manFile = "public/man.html";
 | 
			
		||||
const simpOutFile = "public/simplified";
 | 
			
		||||
const inputFile = "stats/inputs";
 | 
			
		||||
const msgFile = "stats/msgs";
 | 
			
		||||
const logFile = "stats/logs";
 | 
			
		||||
 | 
			
		||||
// https://certbot.eff.org/
 | 
			
		||||
const key = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/privkey.pem", "utf8");
 | 
			
		||||
const cert = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/fullchain.pem", "utf8");
 | 
			
		||||
const ca = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/chain.pem", "utf8");
 | 
			
		||||
var certs = {key:key, cert:cert, ca:ca};
 | 
			
		||||
const port = 8080;
 | 
			
		||||
const httpsPort = 8443;
 | 
			
		||||
 | 
			
		||||
var highlights = ["public", "static", "manual", "isgetting", "postfeedback",
 | 
			
		||||
	"postquestions"
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
	var stdin = process.openStdin();
 | 
			
		||||
	stdin.addListener("data", function(d) {
 | 
			
		||||
		var input = d.toString().trim();
 | 
			
		||||
 | 
			
		||||
		if (input == "hello")
 | 
			
		||||
			console.log("hello, messages: \n" + newMessages);
 | 
			
		||||
		if (input == "clear" || input == "c")
 | 
			
		||||
			console.clear();
 | 
			
		||||
 | 
			
		||||
	});
 | 
			
		||||
} catch (e) {
 | 
			
		||||
	console.log("Failed to open STDIN");
 | 
			
		||||
	console.log(e);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var newMessages = "";
 | 
			
		||||
 | 
			
		||||
app.set('view engine', 'ejs');
 | 
			
		||||
//app.all('*', function(req, res, next) {
 | 
			
		||||
//	if(req.secure) {
 | 
			
		||||
//		next();
 | 
			
		||||
//	} else {
 | 
			
		||||
//		res.redirect('https://' + req.hostname + req.url); 
 | 
			
		||||
//	}
 | 
			
		||||
//});
 | 
			
		||||
app.use(function(req, res, next) {
 | 
			
		||||
	res.on('finish', function() {
 | 
			
		||||
		Log(req, true);
 | 
			
		||||
		Log(req, true, res.statusCode);
 | 
			
		||||
		if (res.statusCode != 404)
 | 
			
		||||
			stat.LogStat(req.url);
 | 
			
		||||
	});
 | 
			
		||||
	stat.LogStat(req.url);
 | 
			
		||||
	next();
 | 
			
		||||
});
 | 
			
		||||
app.use(express.static('public'));
 | 
			
		||||
@@ -113,6 +115,20 @@ app.get('/static', function(req, res) {
 | 
			
		||||
	res.end();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
app.get('/legacy', function(req, res) {
 | 
			
		||||
	// TODO: make this ejs
 | 
			
		||||
	var f = utils.ReadFile(dataFile);
 | 
			
		||||
	var r = '<html><body bgcolor="#212127"><head><meta charset="UTF-8">';
 | 
			
		||||
	r += '<style>body { font: normal 14px Verdana; color: #999999;}</style>';
 | 
			
		||||
	var d = actions.LoadJSON(f).toString().split("\n");
 | 
			
		||||
	for (var i = 0; i < d.length; i++)
 | 
			
		||||
		r += d[i] + "</br>";
 | 
			
		||||
	r += '</head></body></html>';
 | 
			
		||||
 | 
			
		||||
	res.write(r);
 | 
			
		||||
	res.end();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
app.post('/postfeedback', function(req, res) {
 | 
			
		||||
	res.redirect('back');
 | 
			
		||||
	newMessages += "\n" + req.body.message_field;
 | 
			
		||||
@@ -178,24 +194,29 @@ app.get('/servergit', function(req, res) {
 | 
			
		||||
app.get('*', function(req, res) {
 | 
			
		||||
	res.render('404');
 | 
			
		||||
	res.status(404);
 | 
			
		||||
	utils.AppendToFile(logger.GetDateString() + ": " + "404 GET", logFile);
 | 
			
		||||
	// utils.AppendToFile(logger.GetDateString() + ": " + "404 GET", logFile);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
app.post('*', function(req, res) {
 | 
			
		||||
	res.status(404);
 | 
			
		||||
	utils.AppendToFile(logger.GetDateString() + ": " + "404 POST", logFile);
 | 
			
		||||
	Log(req, true);
 | 
			
		||||
	// utils.AppendToFile(logger.GetDateString() + ": " + "404 POST", logFile);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
stat.Load();
 | 
			
		||||
app.listen(port);
 | 
			
		||||
logger.Log("[STRT]: Server listening on port " + port + "...", logger.GetColor("yellow"));
 | 
			
		||||
const httpServer = http.createServer(app);
 | 
			
		||||
const httpsServer = https.createServer(certs, app);
 | 
			
		||||
httpServer.listen(port);
 | 
			
		||||
httpsServer.listen(httpsPort);
 | 
			
		||||
logger.Log("[STRT]: Server listening on port " + port + " (http), and " + httpsPort + " (https)...", logger.GetColor("yellow"));
 | 
			
		||||
 | 
			
		||||
function Log(req, toFile) {
 | 
			
		||||
function Log(req, toFile, sc) {
 | 
			
		||||
	try {
 | 
			
		||||
		var ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress;
 | 
			
		||||
		var logEntry = "[RSND]: " + ip + ", " + req.headers['user-agent'] +
 | 
			
		||||
			" " + req.method + " " + req.url;
 | 
			
		||||
			" " + req.method + " ";
 | 
			
		||||
		if (sc == 404)
 | 
			
		||||
			logEntry += sc + " ";
 | 
			
		||||
		logEntry += req.url;
 | 
			
		||||
		var color = logger.GetColor("green");
 | 
			
		||||
		for (var i = 0; i < highlights.length; i++)
 | 
			
		||||
			if (req.url.toLowerCase().includes(highlights[i])) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								stat.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								stat.js
									
									
									
									
									
								
							@@ -84,7 +84,7 @@ function AddVisitStat(name) {
 | 
			
		||||
		("0" + (m.getMonth() + 1)).slice(-2) + "/" +
 | 
			
		||||
		("0" + m.getDate()).slice(-2);
 | 
			
		||||
	if (vData[now] == undefined)
 | 
			
		||||
		vData[now] = [];
 | 
			
		||||
		vData[now] = {};
 | 
			
		||||
	if (vData[now][name] == undefined)
 | 
			
		||||
		vData[now][name] = 0;
 | 
			
		||||
	vData[now][name]++;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								utils.js
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								utils.js
									
									
									
									
									
								
							@@ -12,10 +12,10 @@ var fs = require('fs');
 | 
			
		||||
var logger = require('./logger.js');
 | 
			
		||||
 | 
			
		||||
const recievedFile = "stats/recieved";
 | 
			
		||||
const publicFile = "public/data/public";
 | 
			
		||||
const staticFile = "public/data/static";
 | 
			
		||||
const manFile = "public/man.html";
 | 
			
		||||
const logFile = "stats/logs";
 | 
			
		||||
const dataFile = "public/data.json";
 | 
			
		||||
 | 
			
		||||
function ReadFile(name) {
 | 
			
		||||
	return fs.readFileSync(name, "utf8");
 | 
			
		||||
@@ -57,11 +57,12 @@ function WriteBackup() {
 | 
			
		||||
		logger.Log("[ERR ]: Error backing up recieved file!", logger.GetColor("redbg"));
 | 
			
		||||
		console.log(e);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	try {
 | 
			
		||||
		WriteFileAsync(ReadFile(publicFile), 'public/backs/public_' + new Date().toString());
 | 
			
		||||
		//logger.Log('[SAVE]: Public questions backup wrote');
 | 
			
		||||
		WriteFileAsync(ReadFile(dataFile), 'public/backs/data_' + new Date().toString());
 | 
			
		||||
 | 
			
		||||
	} catch (e) {
 | 
			
		||||
		logger.Log("[ERR ]: Error backing up public file!", logger.GetColor("redbg"), true);
 | 
			
		||||
		logger.Log("[ERR ]: Error backing up data json file!", logger.GetColor("redbg"));
 | 
			
		||||
		console.log(e);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
<body bgcolor="#212127">
 | 
			
		||||
<head>
 | 
			
		||||
 | 
			
		||||
<meta charset="UTF-8">
 | 
			
		||||
<style>
 | 
			
		||||
body { font: normal 14px Verdana; color: #999999;}
 | 
			
		||||
td {vertical-align: top }
 | 
			
		||||
@@ -24,18 +25,12 @@ greasyforkon</a>
 | 
			
		||||
<a href="http://questionmining.tk/servergit">Szerver repó</a>
 | 
			
		||||
|
 | 
			
		||||
<a href="http://questionmining.tk/scriptgit">Userscript repó</a>
 | 
			
		||||
|
 | 
			
		||||
<a href="http://questionmining.tk/data.json">Összes kérdés (JSON)</a>
 | 
			
		||||
|
 | 
			
		||||
<a href="http://questionmining.tk/legacy">Összes kérdés (Régi formátum)</a>
 | 
			
		||||
</h2>
 | 
			
		||||
 | 
			
		||||
<meta charset="UTF-8">
 | 
			
		||||
<table style="table-layout:fixed;width:100%">
 | 
			
		||||
<td >
 | 
			
		||||
<a href="http://questionmining.tk/static">Összes kérdés</a>
 | 
			
		||||
</br>
 | 
			
		||||
<textarea readonly ><%= sdata %></textarea>
 | 
			
		||||
</td>
 | 
			
		||||
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<table style="table-layout:fixed;width:100%">
 | 
			
		||||
<td>
 | 
			
		||||
<form action="/postfeedback", method="post">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user