Added main site, code formatting

This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-08-15 11:15:24 +02:00
parent 814abae86b
commit 77427399db
4 changed files with 61 additions and 29 deletions

View file

@ -27,48 +27,44 @@ module.exports = {
const DELIM = '|'
var utils = require('../utils/utils.js')
const nlogFile = './stats/nlogs'
const utils = require('../utils/utils.js')
const locLogFile = './stats/logs'
const logFile = '/nlogs/nlogs'
const allLogFile = '/nlogs/log'
function GetDateString () {
var m = new Date()
const m = new Date()
return m.getFullYear() + '/' +
('0' + (m.getMonth() + 1)).slice(-2) + '/' +
('0' + m.getDate()).slice(-2) + ' ' +
('0' + m.getHours()).slice(-2) + ':' +
('0' + m.getMinutes()).slice(-2) + ':' +
('0' + m.getSeconds()).slice(-2)
('0' + (m.getMonth() + 1)).slice(-2) + '/' +
('0' + m.getDate()).slice(-2) + ' ' +
('0' + m.getHours()).slice(-2) + ':' +
('0' + m.getMinutes()).slice(-2) + ':' +
('0' + m.getSeconds()).slice(-2)
}
function Log (s, c, b) {
if (c != undefined) { console.log(c, GetDateString() + DELIM + s) } else { console.log(GetDateString() + DELIM + s) }
if (c !== undefined) { console.log(c, GetDateString() + DELIM + s) } else { console.log(GetDateString() + DELIM + s) }
if (b) { utils.Beep() }
utils.AppendToFile(GetDateString() + DELIM + s, nlogFile)
utils.AppendToFile(GetDateString() + DELIM + s, logFile)
}
function LogReq (req, toFile, sc) {
try {
var ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
var logEntry = ip + DELIM + req.hostname + DELIM + req.headers['user-agent'] +
DELIM + req.method + DELIM
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
let logEntry = ip + DELIM + req.hostname + DELIM + req.headers['user-agent'] + DELIM + req.method + DELIM
logEntry += req.url
if (sc != undefined && sc == 404) { logEntry += DELIM + sc }
var color = GetColor('green')
if (sc !== undefined && sc === 404) { logEntry += DELIM + sc }
let color = GetColor('green')
if (req.url.toLowerCase().includes('isadding')) { color = GetColor('yellow') }
if (!toFile) {
Log(logEntry, color)
} else {
var defLogs = GetDateString() + DELIM + logEntry
var extraLogs = '\n\t' + JSON.stringify(req.headers) + '\n\t' + JSON.stringify(req.body) + '\n'
let defLogs = GetDateString() + DELIM + logEntry
utils.AppendToFile(defLogs, locLogFile)
utils.AppendToFile(defLogs, allLogFile)
@ -80,11 +76,11 @@ function LogReq (req, toFile, sc) {
}
function GetColor (c) {
if (c == 'redbg') { return '\x1b[41m%s\x1b[0m' }
if (c == 'bluebg') { return '\x1b[44m%s\x1b[0m' }
if (c == 'red') { return '\x1b[31m%s\x1b[0m' }
if (c == 'green') { return '\x1b[32m%s\x1b[0m' }
if (c == 'yellow') { return '\x1b[33m%s\x1b[0m' }
if (c == 'blue') { return '\x1b[34m%s\x1b[0m' }
if (c == 'cyan') { return '\x1b[36m%s\x1b[0m' }
if (c === 'redbg') { return '\x1b[41m%s\x1b[0m' }
if (c === 'bluebg') { return '\x1b[44m%s\x1b[0m' }
if (c === 'red') { return '\x1b[31m%s\x1b[0m' }
if (c === 'green') { return '\x1b[32m%s\x1b[0m' }
if (c === 'yellow') { return '\x1b[33m%s\x1b[0m' }
if (c === 'blue') { return '\x1b[34m%s\x1b[0m' }
if (c === 'cyan') { return '\x1b[36m%s\x1b[0m' }
}