better file handling
This commit is contained in:
parent
076d03b7b9
commit
7034b14be8
1 changed files with 19 additions and 7 deletions
24
index.js
24
index.js
|
@ -8,10 +8,12 @@ let redirectURL = 'https://arrayinamatrix.xyz/res/site/images/trollface.gif'
|
||||||
if (process.argv[2] != undefined) {
|
if (process.argv[2] != undefined) {
|
||||||
redirectURL = process.argv[2]
|
redirectURL = process.argv[2]
|
||||||
}
|
}
|
||||||
|
let logFile = 'ip-addresses.log'
|
||||||
let httpPort = 3030
|
let httpPort = 3030
|
||||||
|
|
||||||
console.log(`Redirect: ${redirectURL}`);
|
console.log(`Redirect: ${redirectURL}`);
|
||||||
console.log(`Port: ${httpPort}`)
|
console.log(`Port: ${httpPort}`)
|
||||||
|
console.log(`Log file location: ${logFile}`)
|
||||||
console.log("########## IP LOGGER STARTED ##########");
|
console.log("########## IP LOGGER STARTED ##########");
|
||||||
|
|
||||||
const app = connect()
|
const app = connect()
|
||||||
|
@ -22,14 +24,24 @@ const app = connect()
|
||||||
|
|
||||||
let time = new Date();
|
let time = new Date();
|
||||||
let ip = req.clientIp;
|
let ip = req.clientIp;
|
||||||
let output = time.getFullYear() + "-" + ("0" + (time.getMonth() + 1)).slice(-2) + "-" + ("0" + time.getDate()).slice(-2) + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + ">> " + ip;
|
let output = time.getFullYear() + "-" + ("0" + (time.getMonth() + 1)).slice(-2) + "-" + ("0" + time.getDate()).slice(-2) + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + " >> " + ip.slice(7);
|
||||||
|
|
||||||
console.log(output);
|
console.log(output);
|
||||||
file.appendFile("../../res/downloads/ip-addresses.log", output + '\n', (e) => {
|
try {
|
||||||
if (e) {
|
file.accessSync(logFile, file.constants.R_OK | file.constants.W_OK)
|
||||||
console.log(e);
|
file.appendFile(logFile, output + '\n', (e) => {
|
||||||
};
|
if (e != null) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
file.writeFile(logFile, output + '\n', (e) => {
|
||||||
|
if (e != null) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
http.createServer(app).listen(httpPort);
|
http.createServer(app).listen(httpPort);
|
||||||
|
|
Loading…
Add table
Reference in a new issue