diff --git a/public/moodle-test-userscript b/public/moodle-test-userscript index cbfaffa..fe74436 160000 --- a/public/moodle-test-userscript +++ b/public/moodle-test-userscript @@ -1 +1 @@ -Subproject commit cbfaffa70ceb29b4beac4b13f6cbb4b85baac8a8 +Subproject commit fe74436ab119a31fdb35f7a3bbae50a572b0fb21 diff --git a/utils/logger.js b/utils/logger.js index f312ff4..54d1d41 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -113,10 +113,13 @@ function LogReq (req, toFile, sc) { } function setNoLogReadInterval () { - noLogips = utils.ReadFile('./nolog').split('\n') - setInterval(() => { - noLogips = utils.ReadFile('./nolog').split('\n') - }, 1000 * 60 * 30) + utils.WatchFile('./nolog', (newData) => { + noLogips = newData.split('\n') + if (noLogips[noLogips.length - 1] === '') { + noLogips.pop() + } + Log('\tNo Log IP-s changed: ' + noLogips.join(', ')) + }) } function Load () { diff --git a/utils/utils.js b/utils/utils.js index 97c7e79..a429d08 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -6,7 +6,8 @@ module.exports = { Beep: Beep, WriteBackup: WriteBackup, FileExists: FileExists, - CreatePath: CreatePath + CreatePath: CreatePath, + WatchFile: WatchFile } var fs = require('fs') @@ -24,6 +25,25 @@ function FileExists (path) { return fs.existsSync(path) } +function WatchFile (file, callback) { + if (FileExists(file)) { + fs.watchFile(file, (curr, prev) => { + fs.readFile(file, 'utf8', (err, data) => { + if (err) { + // console.log(err) + } else { + callback(data) + } + }) + }) + } else { + console.log(file + ' does not eadjsalék') + setTimeout(() => { + WatchFile(file) + }, 1000) + } +} + function CreatePath (path, onlyPath) { if (FileExists(path)) { return }