mybase 1.0.40 → 1.0.42
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 +2 -2
- package/mybase.js +25 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,10 +33,10 @@ 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
|
+
### utcnow():int
|
|
40
40
|
## Encryption
|
|
41
41
|
### decryptAES_CBC_NOIV(encryptedHex, encryptionKey)
|
|
42
42
|
### encryptAES_CBC_NOIV(plainString, encryptionKey)
|
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');
|
|
@@ -42,6 +44,10 @@ function arrayRandomItem(arry,defaultValue=false) {
|
|
|
42
44
|
return defaultValue
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
function utcnow() {
|
|
48
|
+
return Math.floor(Date.now() / 1000)
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
function validIp(str) {
|
|
46
52
|
if (str && typeof str==='string') {
|
|
47
53
|
let splitted
|
|
@@ -56,6 +62,22 @@ function validIp(str) {
|
|
|
56
62
|
return false
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
function Geoip2Paths() {
|
|
66
|
+
function firstExisting(paths) {
|
|
67
|
+
if (Array.isArray(paths))
|
|
68
|
+
for(let fpath of paths)
|
|
69
|
+
if (fs.existsSync(fpath)) return fpath
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
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')]),
|
|
75
|
+
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')]),
|
|
76
|
+
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')]),
|
|
77
|
+
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')]),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
59
81
|
function validIpNative(str) {
|
|
60
82
|
return (net.isIP(str)!==0)
|
|
61
83
|
// const octet = '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)';
|
|
@@ -580,6 +602,7 @@ module.exports = {
|
|
|
580
602
|
asJSON,
|
|
581
603
|
ensureProperty,
|
|
582
604
|
arrayRandomItem,
|
|
583
|
-
promiseTimeout
|
|
584
|
-
|
|
605
|
+
promiseTimeout,
|
|
606
|
+
utcnow,
|
|
607
|
+
Geoip2Paths
|
|
585
608
|
}
|