mybase 1.0.44 → 1.0.46
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 -0
- package/mybase.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ var { isLocal } = require('mybase')
|
|
|
19
19
|
### softexit(message=false,seconds=60,exitcode=-1)
|
|
20
20
|
### validHPassword(hpassword)
|
|
21
21
|
### randomHPassword(length=10)
|
|
22
|
+
### isURL(string)
|
|
22
23
|
### validIp(ip)
|
|
23
24
|
### validTime(t)
|
|
24
25
|
### randomIP()
|
|
@@ -41,6 +42,7 @@ var { isLocal } = require('mybase')
|
|
|
41
42
|
## Encryption
|
|
42
43
|
### decryptAES_CBC_NOIV(encryptedHex, encryptionKey)
|
|
43
44
|
### encryptAES_CBC_NOIV(plainString, encryptionKey)
|
|
45
|
+
### hash_sha512(plain)
|
|
44
46
|
```
|
|
45
47
|
var handle = await maxmindOpen(config.geoip.country)
|
|
46
48
|
```
|
package/mybase.js
CHANGED
|
@@ -11,6 +11,10 @@ const { match } = require('assert');
|
|
|
11
11
|
const validator = require('validator')
|
|
12
12
|
const sha512 = require('js-sha512')
|
|
13
13
|
|
|
14
|
+
// create cache folder if not exists
|
|
15
|
+
let vault_cache_folder = '/var/tmp/vault-cache'
|
|
16
|
+
if (!fs.existsSync(vault_cache_folder)) fs.mkdirSync(vault_cache_folder)
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
Date.prototype.yyyymmdd = function() {
|
|
16
20
|
var mm = this.getMonth() + 1; // getMonth() is zero-based
|
|
@@ -22,6 +26,11 @@ Date.prototype.yyyymmdd = function() {
|
|
|
22
26
|
].join('');
|
|
23
27
|
};
|
|
24
28
|
|
|
29
|
+
function hash_sha512(plain) {
|
|
30
|
+
if (typeof plain==='string') return sha512(plain)
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
function validHPassword(hpassword) { return (hpassword && hpassword.length === 128 && hpassword.search(/^[a-f0-9]+$/) == 0) }
|
|
26
35
|
function randomHPassword(length=10) {
|
|
27
36
|
let plain = randomString(length)
|
|
@@ -97,6 +106,12 @@ function randomIP() {
|
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
|
|
109
|
+
function isURL(url) {
|
|
110
|
+
if (typeof url === 'string') try { return new URL(url) } catch (e) { }
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
100
115
|
function validTime(t) {
|
|
101
116
|
var valid = (t && parseInt(t)>0 && t.toString().length===10)
|
|
102
117
|
if (!valid) return false
|
|
@@ -609,5 +624,7 @@ module.exports = {
|
|
|
609
624
|
promiseTimeout,
|
|
610
625
|
utcnow,
|
|
611
626
|
Geoip2Paths,
|
|
612
|
-
randomHPassword
|
|
627
|
+
randomHPassword,
|
|
628
|
+
isURL,
|
|
629
|
+
hash_sha512
|
|
613
630
|
}
|