This commit is contained in:
Sefinek committed 2025-02-01 20:29:35 +01:00
1 parent d5921f19e7
commit 5320952ccb
8 files changed
+47 -49

No files matched your search

+1 -2
View File
@@ -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
View File
@@ -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);
+29
View File
@@ -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 };