mybase 1.0.40 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/mybase.js +20 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ var { isLocal } = require('mybase')
|
|
|
33
33
|
### isMochaRunning
|
|
34
34
|
### ip2int(), int2ip()
|
|
35
35
|
### ensureProperty(obj,'tier.tier',defaultValue)
|
|
36
|
-
|
|
36
|
+
### Geoip2Paths() : boolean | object
|
|
37
37
|
### arrayRandomItem(array,defaultValue=false)
|
|
38
38
|
### maxmindOpen(geoipFile) : <Promise>
|
|
39
39
|
|
package/mybase.js
CHANGED
|
@@ -2,6 +2,8 @@ const aesjs = require("aes-js")
|
|
|
2
2
|
const debug = require('debug')('mybase')
|
|
3
3
|
const os = require('os')
|
|
4
4
|
const fs = require('fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
|
|
5
7
|
const net = require('net')
|
|
6
8
|
const chalk = require('chalk')
|
|
7
9
|
const punycode = require('punycode');
|
|
@@ -56,6 +58,22 @@ function validIp(str) {
|
|
|
56
58
|
return false
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
function Geoip2Paths() {
|
|
62
|
+
function firstExisting(paths) {
|
|
63
|
+
if (Array.isArray(paths))
|
|
64
|
+
for(let fpath of paths)
|
|
65
|
+
if (fs.existsSync(fpath)) return fpath
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
country:firstExisting(['/opt/geoip2/GeoIP2-Country.mmdb','/usr/local/var/GeoIP/GeoIP2-Country.mmdb','/var/lib/GeoIP/GeoIP2-Country.mmdb','/usr/share/GeoIP/GeoIP2-Country.mmdb',path.join(__dirname, 'assets/GeoIP2-Country.mmdb')]),
|
|
71
|
+
city:firstExisting(['/opt/geoip2/GeoIP2-City.mmdb','/usr/local/var/GeoIP/GeoIP2-City.mmdb','/var/lib/GeoIP/GeoIP2-City.mmdb','/usr/share/GeoIP/GeoIP2-City.mmdb',path.join(__dirname, 'assets/GeoIP2-City.mmdb')]),
|
|
72
|
+
isp:firstExisting(['/opt/geoip2/GeoIP2-ISP.mmdb','/usr/local/var/GeoIP/GeoIP2-ISP.mmdb','/var/lib/GeoIP/GeoIP2-ISP.mmdb','/usr/share/GeoIP/GeoIP2-ISP.mmdb',path.join(__dirname, 'assets/GeoIP2-ISP.mmdb')]),
|
|
73
|
+
ct:firstExisting(['/opt/geoip2/GeoIP2-Connection-Type.mmdb','/usr/local/var/GeoIP/GeoIP2-Connection-Type.mmdb','/var/lib/GeoIP/GeoIP2-Connection-Type.mmdb','/usr/share/GeoIP/GeoIP2-Connection-Type.mmdb',path.join(__dirname, 'assets/GeoIP2-Connection-Type.mmdb')]),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
function validIpNative(str) {
|
|
60
78
|
return (net.isIP(str)!==0)
|
|
61
79
|
// const octet = '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)';
|
|
@@ -580,6 +598,6 @@ module.exports = {
|
|
|
580
598
|
asJSON,
|
|
581
599
|
ensureProperty,
|
|
582
600
|
arrayRandomItem,
|
|
583
|
-
promiseTimeout
|
|
584
|
-
|
|
601
|
+
promiseTimeout,
|
|
602
|
+
Geoip2Paths
|
|
585
603
|
}
|