beech-api 3.9.0-beta.9-rc → 3.9.80
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/LICENSE +21 -21
- package/README.md +1717 -1649
- package/index.js +2 -2
- package/package.json +92 -84
- package/packages/cli/beech +9 -10
- package/packages/cli/bin/beech-app.js +390 -390
- package/packages/cli/bin/beech-service.js +263 -170
- package/packages/cli/core/auth/Credentials.js +174 -174
- package/packages/cli/core/auth/Passport.js +664 -664
- package/packages/cli/core/auth/_Request.js +12 -12
- package/packages/cli/core/configure/_gitignore +16 -15
- package/packages/cli/core/configure/_sequelizerc +9 -9
- package/packages/cli/core/configure/app.config-basic.js +55 -55
- package/packages/cli/core/configure/app.config-sequelize.js +88 -88
- package/packages/cli/core/configure/beech.config.js +9 -9
- package/packages/cli/core/configure/global.config-basic.js +8 -8
- package/packages/cli/core/configure/global.config-sequelize.js +8 -8
- package/packages/cli/core/configure/jest.config.js +6 -6
- package/packages/cli/core/configure/jsconfig.json +8 -7
- package/packages/cli/core/configure/passport.config.js +97 -97
- package/packages/cli/core/databases/mysql.js +94 -95
- package/packages/cli/core/databases/sequelize.js +187 -188
- package/packages/cli/core/databases/test.js +250 -255
- package/packages/cli/core/file-walk/file-walk.js +35 -35
- package/packages/cli/core/generator/_endpoints +15 -15
- package/packages/cli/core/generator/_endpoints_basic +42 -42
- package/packages/cli/core/generator/_help +29 -19
- package/packages/cli/core/generator/_help_create +10 -10
- package/packages/cli/core/generator/_help_service +10 -10
- package/packages/cli/core/generator/_helpers +9 -9
- package/packages/cli/core/generator/_helpers_basic +166 -22
- package/packages/cli/core/generator/_models +6 -6
- package/packages/cli/core/generator/_models_basic +13 -13
- package/packages/cli/core/generator/_package +23 -19
- package/packages/cli/core/generator/_scheduler +32 -32
- package/packages/cli/core/generator/_spec +29 -29
- package/packages/cli/core/generator/index.js +1229 -992
- package/packages/cli/core/helpers/2fa.js +106 -106
- package/packages/cli/core/helpers/math.js +115 -115
- package/packages/cli/core/helpers/poolEntity.js +103 -103
- package/packages/cli/core/index.js +264 -266
- package/packages/cli/core/middleware/express/duplicateRequest.js +16 -16
- package/packages/cli/core/middleware/express/jwtCheckAllow.js +85 -85
- package/packages/cli/core/middleware/express/rateLimit.js +29 -29
- package/packages/cli/core/middleware/express/slowDown.js +2 -2
- package/packages/cli/core/middleware/index.js +6 -6
- package/packages/cli/core/middleware/origin/guard/advance.js +75 -75
- package/packages/cli/core/middleware/origin/whitelist/cors.js +94 -94
- package/packages/cli/core/services/http.express.js +481 -481
- package/packages/cli/core/test/check-node.js +21 -21
- package/packages/cli/core/test/utils.js +7 -7
- package/packages/cli/entry +10 -0
- package/packages/lib/index.js +6 -6
- package/packages/lib/src/endpoint.js +947 -885
- package/packages/lib/src/guard.js +60 -60
- package/packages/lib/src/salt.js +3 -3
- package/packages/lib/src/schema.js +96 -96
- package/packages/lib/src/specificExpress.js +7 -7
- package/packages/lib/src/user.js +271 -271
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const { FindOne } = require("../../../lib/src/user");
|
|
3
|
-
const { findPassportPk } = require("./poolEntity");
|
|
4
|
-
const passport_config_file = appRoot + "/passport.config.js";
|
|
5
|
-
const md5 = require("md5");
|
|
6
|
-
const secret = require("../../../lib/src/salt").salt;
|
|
7
|
-
|
|
8
|
-
function TwoFactor(user, reqBody, guard_field, cb) {
|
|
9
|
-
try {
|
|
10
|
-
findFkInFields((err, userId) => {
|
|
11
|
-
if(err) {
|
|
12
|
-
cb(true, err);
|
|
13
|
-
} else {
|
|
14
|
-
if(userId.length) {
|
|
15
|
-
if (fs.existsSync(passport_config_file)) {
|
|
16
|
-
passport_config = require(passport_config_file);
|
|
17
|
-
} else {
|
|
18
|
-
cb(true, {
|
|
19
|
-
code: 500,
|
|
20
|
-
status: "INTERNAL_SERVER_ERR",
|
|
21
|
-
error: {
|
|
22
|
-
code: 404,
|
|
23
|
-
status: "ERROR_FILE_NOT_EXISTS",
|
|
24
|
-
message: "The file passport.config.js not exists!",
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
let usrField = passport_config.model.username_field || "username";
|
|
30
|
-
let pwdField = passport_config.model.password_field || "password"
|
|
31
|
-
// filter without base user, pass
|
|
32
|
-
let without_base = Object.keys(reqBody).map((k) => {
|
|
33
|
-
return guard_field.filter((e) => e == k)[0];
|
|
34
|
-
});
|
|
35
|
-
// filter without undefined
|
|
36
|
-
let x = without_base.filter((x) => {
|
|
37
|
-
return x !== undefined;
|
|
38
|
-
});
|
|
39
|
-
// check length match ?
|
|
40
|
-
if(x.length == guard_field.length) {
|
|
41
|
-
let z = {};
|
|
42
|
-
z[usrField] = reqBody[usrField];
|
|
43
|
-
z[pwdField] = md5(reqBody[pwdField] + secret);
|
|
44
|
-
x.map((guard) => {
|
|
45
|
-
z[guard] = reqBody[guard];
|
|
46
|
-
});
|
|
47
|
-
// FindUser
|
|
48
|
-
FindOne([], z, (err, result) => {
|
|
49
|
-
if(err) {
|
|
50
|
-
cb(true, { code: 500, status: "INTERNAL_SERVER_ERR", error: err });
|
|
51
|
-
} else {
|
|
52
|
-
if(result.length) {
|
|
53
|
-
cb(null, result);
|
|
54
|
-
} else {
|
|
55
|
-
cb(null, []);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
cb(true, {
|
|
61
|
-
code: 400,
|
|
62
|
-
status: 'BAD_REQUEST',
|
|
63
|
-
message: "Bad request.",
|
|
64
|
-
info: {
|
|
65
|
-
status: "BAD_ENTITY",
|
|
66
|
-
message: "Bad guard Entity."
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
// Can't find Auth Open ID
|
|
72
|
-
cb(true, {
|
|
73
|
-
code: 400,
|
|
74
|
-
status: 'BAD_REQUEST',
|
|
75
|
-
message: "Bad request.",
|
|
76
|
-
info: {
|
|
77
|
-
status: "BAD_ENTITY",
|
|
78
|
-
message: "Unprocessable with Auth Open ID Entity.",
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
} catch (error) {
|
|
85
|
-
cb(error, null);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function findFkInFields(cb) {
|
|
90
|
-
try {
|
|
91
|
-
const passport_config = require(appRoot + "/passport.config.js");
|
|
92
|
-
const pool = await eval("sql." + passport_config.model.name);
|
|
93
|
-
let passportTable = await [passport_config.model.table || "users"];
|
|
94
|
-
await findPassportPk(pool_base, pool, passportTable, [], async (err, pk) => {
|
|
95
|
-
if(err) {
|
|
96
|
-
cb(err, null);
|
|
97
|
-
} else {
|
|
98
|
-
cb(null, pk);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
} catch (error) {
|
|
102
|
-
cb(error, null);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = { TwoFactor }
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { FindOne } = require("../../../lib/src/user");
|
|
3
|
+
const { findPassportPk } = require("./poolEntity");
|
|
4
|
+
const passport_config_file = appRoot + "/passport.config.js";
|
|
5
|
+
const md5 = require("md5");
|
|
6
|
+
const secret = require("../../../lib/src/salt").salt;
|
|
7
|
+
|
|
8
|
+
function TwoFactor(user, reqBody, guard_field, cb) {
|
|
9
|
+
try {
|
|
10
|
+
findFkInFields((err, userId) => {
|
|
11
|
+
if(err) {
|
|
12
|
+
cb(true, err);
|
|
13
|
+
} else {
|
|
14
|
+
if(userId.length) {
|
|
15
|
+
if (fs.existsSync(passport_config_file)) {
|
|
16
|
+
passport_config = require(passport_config_file);
|
|
17
|
+
} else {
|
|
18
|
+
cb(true, {
|
|
19
|
+
code: 500,
|
|
20
|
+
status: "INTERNAL_SERVER_ERR",
|
|
21
|
+
error: {
|
|
22
|
+
code: 404,
|
|
23
|
+
status: "ERROR_FILE_NOT_EXISTS",
|
|
24
|
+
message: "The file passport.config.js not exists!",
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let usrField = passport_config.model.username_field || "username";
|
|
30
|
+
let pwdField = passport_config.model.password_field || "password"
|
|
31
|
+
// filter without base user, pass
|
|
32
|
+
let without_base = Object.keys(reqBody).map((k) => {
|
|
33
|
+
return guard_field.filter((e) => e == k)[0];
|
|
34
|
+
});
|
|
35
|
+
// filter without undefined
|
|
36
|
+
let x = without_base.filter((x) => {
|
|
37
|
+
return x !== undefined;
|
|
38
|
+
});
|
|
39
|
+
// check length match ?
|
|
40
|
+
if(x.length == guard_field.length) {
|
|
41
|
+
let z = {};
|
|
42
|
+
z[usrField] = reqBody[usrField];
|
|
43
|
+
z[pwdField] = md5(reqBody[pwdField] + secret);
|
|
44
|
+
x.map((guard) => {
|
|
45
|
+
z[guard] = reqBody[guard];
|
|
46
|
+
});
|
|
47
|
+
// FindUser
|
|
48
|
+
FindOne([], z, (err, result) => {
|
|
49
|
+
if(err) {
|
|
50
|
+
cb(true, { code: 500, status: "INTERNAL_SERVER_ERR", error: err });
|
|
51
|
+
} else {
|
|
52
|
+
if(result.length) {
|
|
53
|
+
cb(null, result);
|
|
54
|
+
} else {
|
|
55
|
+
cb(null, []);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
cb(true, {
|
|
61
|
+
code: 400,
|
|
62
|
+
status: 'BAD_REQUEST',
|
|
63
|
+
message: "Bad request.",
|
|
64
|
+
info: {
|
|
65
|
+
status: "BAD_ENTITY",
|
|
66
|
+
message: "Bad guard Entity."
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
// Can't find Auth Open ID
|
|
72
|
+
cb(true, {
|
|
73
|
+
code: 400,
|
|
74
|
+
status: 'BAD_REQUEST',
|
|
75
|
+
message: "Bad request.",
|
|
76
|
+
info: {
|
|
77
|
+
status: "BAD_ENTITY",
|
|
78
|
+
message: "Unprocessable with Auth Open ID Entity.",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
cb(error, null);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function findFkInFields(cb) {
|
|
90
|
+
try {
|
|
91
|
+
const passport_config = require(appRoot + "/passport.config.js");
|
|
92
|
+
const pool = await eval("sql." + passport_config.model.name);
|
|
93
|
+
let passportTable = await [passport_config.model.table || "users"];
|
|
94
|
+
await findPassportPk(pool_base, pool, passportTable, [], async (err, pk) => {
|
|
95
|
+
if(err) {
|
|
96
|
+
cb(err, null);
|
|
97
|
+
} else {
|
|
98
|
+
cb(null, pk);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
cb(error, null);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = { TwoFactor }
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
const secret = require("../../../lib/src/salt").salt;
|
|
2
|
-
const Cryptr = require("cryptr");
|
|
3
|
-
const CryptoJS = require("crypto-js");
|
|
4
|
-
const md5 = require("md5");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const appRoot = require("app-root-path");
|
|
7
|
-
|
|
8
|
-
function Rand(length) {
|
|
9
|
-
let result = "";
|
|
10
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".concat(Math.floor(Math.random() * 1000000000));
|
|
11
|
-
const charactersLength = characters.length;
|
|
12
|
-
let counter = 0;
|
|
13
|
-
while (counter < length) {
|
|
14
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
15
|
-
counter += 1;
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getAppKey(cb) {
|
|
21
|
-
// chcek app.config file for Prd. || Dev.
|
|
22
|
-
if(fs.existsSync(appRoot + "/app.config.js")) {
|
|
23
|
-
cb(null, require(appRoot + "/app.config.js").main_config.app_key);
|
|
24
|
-
} else {
|
|
25
|
-
fs.readFile("./app.config.js", 'utf8', (err, e) => {
|
|
26
|
-
if(err) {
|
|
27
|
-
cb(err, null);
|
|
28
|
-
} else {
|
|
29
|
-
cb(null, eval(e).main_config.app_key);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function HashIt(txt, app_key, iteration = 10000, len = 10, cb) {
|
|
36
|
-
const crypIt = new Cryptr(secret.toString().concat(app_key.toString()), { encoding: "base64url", pbkdf2Iterations: iteration, saltLength: len, });
|
|
37
|
-
let result = "";
|
|
38
|
-
let loop = 0;
|
|
39
|
-
const maxLoop = 10;
|
|
40
|
-
do {
|
|
41
|
-
const payload = txt.concat(md5(secret).toString().slice(0, len + 1));
|
|
42
|
-
result = crypIt.encrypt(payload);
|
|
43
|
-
loop++;
|
|
44
|
-
if (loop >= maxLoop) {
|
|
45
|
-
console.log("\n[101m FAIL [0m Hash loop limit exceeded, Try again.");
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
} while (/[+-]/.test(result)); // reject -, +
|
|
49
|
-
cb(result);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function DeHashIt(txtHashed, iteration = 10000, len = 10, cb) {
|
|
53
|
-
try {
|
|
54
|
-
getAppKey((err, app_key) => {
|
|
55
|
-
if(err) {
|
|
56
|
-
cb(err, null);
|
|
57
|
-
} else {
|
|
58
|
-
const crypIt = new Cryptr(secret.toString().concat(app_key.toString()), { encoding: "base64", pbkdf2Iterations: iteration, saltLength: len, });
|
|
59
|
-
let decryped = crypIt.decrypt(txtHashed);
|
|
60
|
-
cb(false, decryped.concat(md5(secret).toString()));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
} catch (error) {
|
|
64
|
-
cb(error, null);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Advanced guard
|
|
69
|
-
function getAVGKey(cb) {
|
|
70
|
-
// chcek app.config file for Prd. || Dev.
|
|
71
|
-
if(fs.existsSync(appRoot + "/passport.config.js")) {
|
|
72
|
-
const avg = require(appRoot + "/passport.config.js").model.guard;
|
|
73
|
-
if(avg.advanced_guard) {
|
|
74
|
-
let avgKey = (avg.advanced_guard.secret || "~A26o$I6s8!");
|
|
75
|
-
cb(null, avgKey, md5(avgKey));
|
|
76
|
-
} else {
|
|
77
|
-
let avgKey = "!zI2c#Xo5z@";
|
|
78
|
-
cb(null, avgKey, md5(avgKey));
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
fs.readFile("./passport.config.js", 'utf8', (err, e) => {
|
|
82
|
-
if(err) {
|
|
83
|
-
cb(err, null);
|
|
84
|
-
} else {
|
|
85
|
-
const avg = eval(e);
|
|
86
|
-
if(avg.advanced_guard) {
|
|
87
|
-
let avgKey = (avg.advanced_guard.secret || "#sY7f~pQ2g1")
|
|
88
|
-
cb(null, avgKey, md5(avgKey));
|
|
89
|
-
} else {
|
|
90
|
-
let avgKey = "?e1Av$lnSw#";
|
|
91
|
-
cb(null, avgKey, md5(avgKey));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function avgDeHashIt(txtHashed, cb) {
|
|
99
|
-
try {
|
|
100
|
-
getAVGKey((err, advanced_key) => {
|
|
101
|
-
if(err) {
|
|
102
|
-
cb(err, null);
|
|
103
|
-
} else {
|
|
104
|
-
const reb64 = CryptoJS.enc.Hex.parse(txtHashed);
|
|
105
|
-
const bytes = reb64.toString(CryptoJS.enc.Base64);
|
|
106
|
-
const decrypt = CryptoJS.AES.decrypt(bytes, md5(advanced_key));
|
|
107
|
-
cb(null, decrypt.toString(CryptoJS.enc.Utf8));
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
} catch (error) {
|
|
111
|
-
cb(error, null);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
module.exports = { Rand, HashIt, DeHashIt, X:secret, M:md5, Z:getAppKey, avgDeHashIt, avgZ:getAVGKey };
|
|
1
|
+
const secret = require("../../../lib/src/salt").salt;
|
|
2
|
+
const Cryptr = require("cryptr");
|
|
3
|
+
const CryptoJS = require("crypto-js");
|
|
4
|
+
const md5 = require("md5");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const appRoot = require("app-root-path");
|
|
7
|
+
|
|
8
|
+
function Rand(length) {
|
|
9
|
+
let result = "";
|
|
10
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".concat(Math.floor(Math.random() * 1000000000));
|
|
11
|
+
const charactersLength = characters.length;
|
|
12
|
+
let counter = 0;
|
|
13
|
+
while (counter < length) {
|
|
14
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
15
|
+
counter += 1;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getAppKey(cb) {
|
|
21
|
+
// chcek app.config file for Prd. || Dev.
|
|
22
|
+
if(fs.existsSync(appRoot + "/app.config.js")) {
|
|
23
|
+
cb(null, require(appRoot + "/app.config.js").main_config.app_key);
|
|
24
|
+
} else {
|
|
25
|
+
fs.readFile("./app.config.js", 'utf8', (err, e) => {
|
|
26
|
+
if(err) {
|
|
27
|
+
cb(err, null);
|
|
28
|
+
} else {
|
|
29
|
+
cb(null, eval(e).main_config.app_key);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function HashIt(txt, app_key, iteration = 10000, len = 10, cb) {
|
|
36
|
+
const crypIt = new Cryptr(secret.toString().concat(app_key.toString()), { encoding: "base64url", pbkdf2Iterations: iteration, saltLength: len, });
|
|
37
|
+
let result = "";
|
|
38
|
+
let loop = 0;
|
|
39
|
+
const maxLoop = 10;
|
|
40
|
+
do {
|
|
41
|
+
const payload = txt.concat(md5(secret).toString().slice(0, len + 1));
|
|
42
|
+
result = crypIt.encrypt(payload);
|
|
43
|
+
loop++;
|
|
44
|
+
if (loop >= maxLoop) {
|
|
45
|
+
console.log("\n[101m FAIL [0m Hash loop limit exceeded, Try again.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
} while (/[+-]/.test(result)); // reject -, +
|
|
49
|
+
cb(result);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function DeHashIt(txtHashed, iteration = 10000, len = 10, cb) {
|
|
53
|
+
try {
|
|
54
|
+
getAppKey((err, app_key) => {
|
|
55
|
+
if(err) {
|
|
56
|
+
cb(err, null);
|
|
57
|
+
} else {
|
|
58
|
+
const crypIt = new Cryptr(secret.toString().concat(app_key.toString()), { encoding: "base64", pbkdf2Iterations: iteration, saltLength: len, });
|
|
59
|
+
let decryped = crypIt.decrypt(txtHashed);
|
|
60
|
+
cb(false, decryped.concat(md5(secret).toString()));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
cb(error, null);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Advanced guard
|
|
69
|
+
function getAVGKey(cb) {
|
|
70
|
+
// chcek app.config file for Prd. || Dev.
|
|
71
|
+
if(fs.existsSync(appRoot + "/passport.config.js")) {
|
|
72
|
+
const avg = require(appRoot + "/passport.config.js").model.guard;
|
|
73
|
+
if(avg.advanced_guard) {
|
|
74
|
+
let avgKey = (avg.advanced_guard.secret || "~A26o$I6s8!");
|
|
75
|
+
cb(null, avgKey, md5(avgKey));
|
|
76
|
+
} else {
|
|
77
|
+
let avgKey = "!zI2c#Xo5z@";
|
|
78
|
+
cb(null, avgKey, md5(avgKey));
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
fs.readFile("./passport.config.js", 'utf8', (err, e) => {
|
|
82
|
+
if(err) {
|
|
83
|
+
cb(err, null);
|
|
84
|
+
} else {
|
|
85
|
+
const avg = eval(e);
|
|
86
|
+
if(avg.advanced_guard) {
|
|
87
|
+
let avgKey = (avg.advanced_guard.secret || "#sY7f~pQ2g1")
|
|
88
|
+
cb(null, avgKey, md5(avgKey));
|
|
89
|
+
} else {
|
|
90
|
+
let avgKey = "?e1Av$lnSw#";
|
|
91
|
+
cb(null, avgKey, md5(avgKey));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function avgDeHashIt(txtHashed, cb) {
|
|
99
|
+
try {
|
|
100
|
+
getAVGKey((err, advanced_key) => {
|
|
101
|
+
if(err) {
|
|
102
|
+
cb(err, null);
|
|
103
|
+
} else {
|
|
104
|
+
const reb64 = CryptoJS.enc.Hex.parse(txtHashed);
|
|
105
|
+
const bytes = reb64.toString(CryptoJS.enc.Base64);
|
|
106
|
+
const decrypt = CryptoJS.AES.decrypt(bytes, md5(advanced_key));
|
|
107
|
+
cb(null, decrypt.toString(CryptoJS.enc.Utf8));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
cb(error, null);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = { Rand, HashIt, DeHashIt, X:secret, M:md5, Z:getAppKey, avgDeHashIt, avgZ:getAVGKey };
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
async function findPassportPk(pool_base, pool, passportTable, passportConfigField, cb) {
|
|
2
|
-
try {
|
|
3
|
-
let finalPassportField = [];
|
|
4
|
-
// Push and Replace it
|
|
5
|
-
const pushOrReplace = (arr, value) => {
|
|
6
|
-
arr = arr.filter(v => !value.includes(v));
|
|
7
|
-
arr = [...value, ...arr];
|
|
8
|
-
return arr;
|
|
9
|
-
}
|
|
10
|
-
// Check pool engine
|
|
11
|
-
if(pool_base == "basic") {
|
|
12
|
-
// pool base is Basic
|
|
13
|
-
pool.query("SHOW KEYS FROM " + passportTable + " WHERE Key_name = 'PRIMARY'", (err, pk) => {
|
|
14
|
-
if(err) {
|
|
15
|
-
throw "Authentication table: " + err;
|
|
16
|
-
} else {
|
|
17
|
-
if(passportConfigField.length) {
|
|
18
|
-
finalPassportField = pushOrReplace(passportConfigField, [pk[0].Column_name]);
|
|
19
|
-
cb(null, finalPassportField);
|
|
20
|
-
} else {
|
|
21
|
-
cb(null, [pk[0].Column_name]);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
} else if (pool_base == "sequelize") {
|
|
26
|
-
// pool base is Sequelize
|
|
27
|
-
// Find table primaryKey
|
|
28
|
-
try {
|
|
29
|
-
const tableInfo = await pool.getQueryInterface().describeTable(String(passportTable));
|
|
30
|
-
const primaryKeys = Object.entries(tableInfo).filter(([columnName, columnInfo]) => columnInfo.primaryKey).map(([columnName]) => columnName);
|
|
31
|
-
if(primaryKeys.length) {
|
|
32
|
-
if(passportConfigField.length) {
|
|
33
|
-
finalPassportField = pushOrReplace(passportConfigField, primaryKeys);
|
|
34
|
-
cb(null, finalPassportField);
|
|
35
|
-
} else {
|
|
36
|
-
cb(null, primaryKeys);
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if(passportConfigField.length) {
|
|
40
|
-
finalPassportField = pushOrReplace(passportConfigField, [Object.keys(tableInfo)[0]]);
|
|
41
|
-
cb(null, finalPassportField);
|
|
42
|
-
} else {
|
|
43
|
-
cb(null, [Object.keys(tableInfo)[0]]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw `Query Interface ${error}`;
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
throw "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'";
|
|
51
|
-
}
|
|
52
|
-
} catch (error) {
|
|
53
|
-
cb(error, null);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function checkAuthFields(pool_base, pool, passportTable, passportConfigField, cb) {
|
|
58
|
-
try {
|
|
59
|
-
if(passportConfigField.length) {
|
|
60
|
-
if(pool_base == "basic") {
|
|
61
|
-
// pool base is Basic
|
|
62
|
-
pool.query("SELECT "+ passportConfigField.join(",") +" FROM " + passportTable + " LIMIT 1", (err, result) => {
|
|
63
|
-
if(err) {
|
|
64
|
-
cb(`Authentication table: '${passportTable}' ${err}`, null);
|
|
65
|
-
} else {
|
|
66
|
-
cb(null, [result]);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
} else if (pool_base == "sequelize") {
|
|
70
|
-
// pool base is Sequelize
|
|
71
|
-
// Check assing fields exists
|
|
72
|
-
const checkColumnsExist = async (tableName, fields = []) => {
|
|
73
|
-
const queryInterface = pool.getQueryInterface();
|
|
74
|
-
try {
|
|
75
|
-
const tableDescription = await queryInterface.describeTable(tableName);
|
|
76
|
-
const result = {};
|
|
77
|
-
for (const column of fields) {
|
|
78
|
-
result[column] = tableDescription.hasOwnProperty(column);
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
throw `Query Interface ${error}`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const openFields = await checkColumnsExist(passportTable, passportConfigField);
|
|
86
|
-
const assignFieldsIsWhitelist = Object.values(openFields).includes(false) ? false : true;
|
|
87
|
-
if(assignFieldsIsWhitelist) {
|
|
88
|
-
cb(null, openFields);
|
|
89
|
-
} else {
|
|
90
|
-
cb(`Authentication table fields error: '${passportTable}' => [${passportConfigField}]`, null);
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
cb("The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'", null);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
cb(null, []);
|
|
97
|
-
}
|
|
98
|
-
} catch (error) {
|
|
99
|
-
cb(error, null);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
module.exports = { findPassportPk, checkAuthFields };
|
|
1
|
+
async function findPassportPk(pool_base, pool, passportTable, passportConfigField, cb) {
|
|
2
|
+
try {
|
|
3
|
+
let finalPassportField = [];
|
|
4
|
+
// Push and Replace it
|
|
5
|
+
const pushOrReplace = (arr, value) => {
|
|
6
|
+
arr = arr.filter(v => !value.includes(v));
|
|
7
|
+
arr = [...value, ...arr];
|
|
8
|
+
return arr;
|
|
9
|
+
}
|
|
10
|
+
// Check pool engine
|
|
11
|
+
if(pool_base == "basic") {
|
|
12
|
+
// pool base is Basic
|
|
13
|
+
pool.query("SHOW KEYS FROM " + passportTable + " WHERE Key_name = 'PRIMARY'", (err, pk) => {
|
|
14
|
+
if(err) {
|
|
15
|
+
throw "Authentication table: " + err;
|
|
16
|
+
} else {
|
|
17
|
+
if(passportConfigField.length) {
|
|
18
|
+
finalPassportField = pushOrReplace(passportConfigField, [pk[0].Column_name]);
|
|
19
|
+
cb(null, finalPassportField);
|
|
20
|
+
} else {
|
|
21
|
+
cb(null, [pk[0].Column_name]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
} else if (pool_base == "sequelize") {
|
|
26
|
+
// pool base is Sequelize
|
|
27
|
+
// Find table primaryKey
|
|
28
|
+
try {
|
|
29
|
+
const tableInfo = await pool.getQueryInterface().describeTable(String(passportTable));
|
|
30
|
+
const primaryKeys = Object.entries(tableInfo).filter(([columnName, columnInfo]) => columnInfo.primaryKey).map(([columnName]) => columnName);
|
|
31
|
+
if(primaryKeys.length) {
|
|
32
|
+
if(passportConfigField.length) {
|
|
33
|
+
finalPassportField = pushOrReplace(passportConfigField, primaryKeys);
|
|
34
|
+
cb(null, finalPassportField);
|
|
35
|
+
} else {
|
|
36
|
+
cb(null, primaryKeys);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if(passportConfigField.length) {
|
|
40
|
+
finalPassportField = pushOrReplace(passportConfigField, [Object.keys(tableInfo)[0]]);
|
|
41
|
+
cb(null, finalPassportField);
|
|
42
|
+
} else {
|
|
43
|
+
cb(null, [Object.keys(tableInfo)[0]]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw `Query Interface ${error}`;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
throw "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'";
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
cb(error, null);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function checkAuthFields(pool_base, pool, passportTable, passportConfigField, cb) {
|
|
58
|
+
try {
|
|
59
|
+
if(passportConfigField.length) {
|
|
60
|
+
if(pool_base == "basic") {
|
|
61
|
+
// pool base is Basic
|
|
62
|
+
pool.query("SELECT "+ passportConfigField.join(",") +" FROM " + passportTable + " LIMIT 1", (err, result) => {
|
|
63
|
+
if(err) {
|
|
64
|
+
cb(`Authentication table: '${passportTable}' ${err}`, null);
|
|
65
|
+
} else {
|
|
66
|
+
cb(null, [result]);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} else if (pool_base == "sequelize") {
|
|
70
|
+
// pool base is Sequelize
|
|
71
|
+
// Check assing fields exists
|
|
72
|
+
const checkColumnsExist = async (tableName, fields = []) => {
|
|
73
|
+
const queryInterface = pool.getQueryInterface();
|
|
74
|
+
try {
|
|
75
|
+
const tableDescription = await queryInterface.describeTable(tableName);
|
|
76
|
+
const result = {};
|
|
77
|
+
for (const column of fields) {
|
|
78
|
+
result[column] = tableDescription.hasOwnProperty(column);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw `Query Interface ${error}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const openFields = await checkColumnsExist(passportTable, passportConfigField);
|
|
86
|
+
const assignFieldsIsWhitelist = Object.values(openFields).includes(false) ? false : true;
|
|
87
|
+
if(assignFieldsIsWhitelist) {
|
|
88
|
+
cb(null, openFields);
|
|
89
|
+
} else {
|
|
90
|
+
cb(`Authentication table fields error: '${passportTable}' => [${passportConfigField}]`, null);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
cb("The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'", null);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
cb(null, []);
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
cb(error, null);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = { findPassportPk, checkAuthFields };
|