0.1.2
This commit is contained in:
1 parent
d5921f19e7
commit
5320952ccb
8 files changed
+47
-49
No files matched your search
+1
-2
@@ -1,9 +1,8 @@
|
||||
const axios = require('axios');
|
||||
const { version } = require('../package.json');
|
||||
const { GITHUB_REPO } = require('../config.js').MAIN;
|
||||
|
||||
axios.defaults.headers.common = {
|
||||
'User-Agent': `Mozilla/5.0 (compatible; UFW-AbuseIPDB-Reporter/${version}; +${GITHUB_REPO})`,
|
||||
'User-Agent': `Mozilla/5.0 (compatible; UFW-AbuseIPDB-Reporter/${version}; +https://github.com/sefinek/UFW-AbuseIPDB-Reporter)`,
|
||||
'Accept': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
const fs = require('node:fs');
|
||||
const { existsSync, readFileSync, writeFileSync } = require('node:fs');
|
||||
const { CACHE_FILE, IP_REPORT_COOLDOWN } = require('../config.js').MAIN;
|
||||
const log = require('../utils/log.js');
|
||||
|
||||
const reportedIPs = new Map();
|
||||
|
||||
const loadReportedIPs = () => {
|
||||
if (fs.existsSync(CACHE_FILE)) {
|
||||
fs.readFileSync(CACHE_FILE, 'utf8')
|
||||
if (existsSync(CACHE_FILE)) {
|
||||
readFileSync(CACHE_FILE, 'utf8')
|
||||
.split('\n')
|
||||
.forEach(line => {
|
||||
const [ip, time] = line.split(' ');
|
||||
@@ -18,7 +18,7 @@ const loadReportedIPs = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const saveReportedIPs = () => fs.writeFileSync(CACHE_FILE, Array.from(reportedIPs).map(([ip, time]) => `${ip} ${time}`).join('\n'), 'utf8');
|
||||
const saveReportedIPs = () => writeFileSync(CACHE_FILE, Array.from(reportedIPs).map(([ip, time]) => `${ip} ${time}`).join('\n'), 'utf8');
|
||||
|
||||
const isIPReportedRecently = ip => {
|
||||
const reportedTime = reportedIPs.get(ip);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
const { AUTO_UPDATE_SCHEDULE } = require('../config.js').MAIN;
|
||||
|
||||
const simpleGit = require('simple-git');
|
||||
const { CronJob } = require('cron');
|
||||
const restartApp = require('./reloadApp.js');
|
||||
const log = require('../utils/log.js');
|
||||
|
||||
const git = simpleGit();
|
||||
|
||||
const pull = async () => {
|
||||
log(0, '$ git pull');
|
||||
|
||||
const { summary } = await git.pull();
|
||||
log(0, `Changes: ${summary.changes}; Deletions: ${summary.insertions}; Insertions: ${summary.insertions};`);
|
||||
};
|
||||
|
||||
const pullAndRestart = async () => {
|
||||
try {
|
||||
await pull();
|
||||
await restartApp();
|
||||
} catch (err) {
|
||||
log(2, err.message);
|
||||
}
|
||||
};
|
||||
|
||||
// https://crontab.guru
|
||||
new CronJob(AUTO_UPDATE_SCHEDULE || '0 18 * * *', pullAndRestart, null, true, 'UTC'); // At 18:00
|
||||
|
||||
module.exports = { pull };
|
||||
Reference in new issue
Block a user