const moment = require('moment')
const maxmind = require('maxmind')
const conf = require('nconf')
const path = require('path')

conf.file({file: path.join(__dirname, 'cfg.json')})
conf.defaults({
  port: process.env.STATUS_PORT || 3013,
  bind: process.env.STATUS_BIND || '127.0.0.1',
  servers: [{
    name: 'Server', host: '127.0.0.1', man_port: 7656
  }],
  username: process.env.STATUS_USERNAME || 'admin',
  password: process.env.STATUS_PASSWORD || 'admin',
  web: {
    dateFormat: process.env.STATUS_WEB_FORMAT || 'HH:mm:ss - DD.MM.YY'
  }
})

const log = (...args) => console.log(...[moment().format(conf.get('web').dateFormat), ...args])

const loadIPdatabase = () => {
  return new Promise((resolve, reject) => {
    maxmind.open(path.join(__dirname, 'GeoLite2-City.mmdb'))
      .then((lookup) => resolve(ip => (ip ? lookup.get(ip) : false)))
      .catch((err) => {reject();log(err)})
  })
}

module.exports = {log, loadIPdatabase, conf}

@@ -26,16 +26,41 @@
 oment')%0A
+const fs = require('fs')%0A
 const ma
@@ -86,16 +86,16 @@
 xmind')%0A
-
 const co
@@ -164,28 +164,31 @@
 %7Bfile: path.
-join
+resolve
 (__dirname, 
@@ -188,16 +188,18 @@
 rname, '
+./
 cfg.json
@@ -324,67 +324,8 @@
 s: %5B
-%7B%0A    name: 'Server', host: '127.0.0.1', man_port: 7656%0A  %7D
 %5D,%0A 
@@ -515,16 +515,292 @@
   %7D%0A%7D)%0A%0A
+const servers = fs.readdirSync(path.resolve(__dirname, './servers'))%0A  .filter((fname) =%3E fname.endsWith('.json'))%0A  .map((fname) =%3E JSON.parse(fs.readFileSync(path.resolve(__dirname, %60./servers/$%7Bfname%7D%60), 'utf8')))%0Aconf.set('servers', %5B...conf.get('servers'), ...servers%5D)%0A%0A
 const lo
@@ -989,12 +989,15 @@
 ath.
-join
+resolve
 (__d

merge from cfg and servers folder