@opengis/fastify-table 1.1.7 → 1.1.9
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/.eslintrc.cjs +42 -42
- package/Changelog.md +305 -301
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +131 -131
- package/cron/index.js +10 -10
- package/crud/controllers/deleteCrud.js +22 -22
- package/crud/controllers/insert.js +61 -61
- package/crud/controllers/update.js +62 -62
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +36 -30
- package/crud/funcs/getAccess.js +53 -53
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/logChanges.js +76 -74
- package/crud/index.js +36 -36
- package/helper.js +28 -28
- package/index.js +97 -97
- package/migration/exec.migrations.js +79 -79
- package/notification/controllers/testEmail.js +49 -49
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/notification/funcs/sendNotification.js +111 -111
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/notification/index.js +38 -38
- package/package.json +26 -26
- package/pg/funcs/getMeta.js +27 -27
- package/pg/funcs/getPG.js +30 -30
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +83 -83
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +23 -23
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/crm.sql +150 -150
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +30 -30
- package/server/migrations/roles.sql +164 -164
- package/server/migrations/users.sql +89 -89
- package/server.js +14 -14
- package/table/controllers/card.js +44 -44
- package/table/controllers/data.js +103 -103
- package/table/controllers/filter.js +37 -37
- package/table/controllers/form.js +28 -28
- package/table/controllers/search.js +80 -80
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +52 -52
- package/table/controllers/utils/addTemplateDir.js +8 -5
- package/table/controllers/utils/getSelect.js +19 -19
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate_old.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/gisIRColumn.js +68 -68
- package/table/controllers/utils/loadTemplate.js +1 -1
- package/table/controllers/utils/loadTemplatePath.js +1 -1
- package/table/controllers/utils/userTemplateDir.js +1 -1
- package/table/funcs/getFilterSQL/index.js +79 -79
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +28 -28
- package/table/index.js +84 -84
- package/test/api/crud.test.js +89 -88
- package/test/api/crud.xss.test.js +72 -72
- package/test/api/notification.test.js +37 -37
- package/test/api/suggest.test.js +66 -66
- package/test/api/table.test.js +89 -89
- package/test/api/widget.test.js +117 -117
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/{server → test}/templates/select/test.storage.data.json +3 -3
- package/test/templates/select/test.suggest.ato_new.json +4 -0
- package/{server → test}/templates/select/test.suggest.ato_new.sql +25 -25
- package/{server → test}/templates/select/test.suggest.data.json +4 -4
- package/{server → test}/templates/select/test.suggest.parent.sql +2 -3
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/util/controllers/logger.file.js +90 -90
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +57 -57
- package/util/controllers/properties.get.js +19 -19
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +19 -19
- package/util/controllers/utils/getRootDir.js +20 -20
- package/util/index.js +23 -23
- package/utils.js +48 -44
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +44 -44
- package/widget/controllers/widget.get.js +98 -98
- package/widget/controllers/widget.set.js +76 -76
- package/widget/index.js +40 -40
- package/server/templates/form/test.dataset.form.json +0 -412
- package/server/templates/select/test.suggest.ato_new.json +0 -3
- package/server/templates/table/test.dataset.table.json +0 -29
- package/server/templates/table/test.gis.map.table.json +0 -45
- package/test/funcs/crud.test.js +0 -122
- package/test/funcs/notification.test.js +0 -31
- /package/{server → test}/templates/select/test.storage.data.sql +0 -0
- /package/{server → test}/templates/select/test.suggest.data.sql +0 -0
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import dataUpdate from '../funcs/dataUpdate.js';
|
|
2
|
-
import dataInsert from '../funcs/dataInsert.js';
|
|
3
|
-
import pgClients from '../../pg/pgClients.js';
|
|
4
|
-
import getToken from '../funcs/getToken.js';
|
|
5
|
-
import checkXSS from './utils/checkXSS.js';
|
|
6
|
-
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
7
|
-
import getAccess from '../funcs/getAccess.js';
|
|
8
|
-
|
|
9
|
-
export default async function update(req) {
|
|
10
|
-
const { actions = [], scope, my } = await getAccess(req, req.params.table, req.params.id) || {};
|
|
11
|
-
if (!actions.includes('edit') || (scope === 'my' && !my)) {
|
|
12
|
-
return { message: 'access restricted', status: 403 };
|
|
13
|
-
}
|
|
14
|
-
if (!req.params?.table) {
|
|
15
|
-
return { message: 'table is required', status: 400 };
|
|
16
|
-
}
|
|
17
|
-
if (!req.params?.id) {
|
|
18
|
-
return { message: 'id is required', status: 404 };
|
|
19
|
-
}
|
|
20
|
-
const loadTemplate = await getTemplate('table', req.params.table);
|
|
21
|
-
const { table, public: ispublic } = loadTemplate || req.params || {};
|
|
22
|
-
const { id } = req.params || {};
|
|
23
|
-
|
|
24
|
-
const { funcs = {}, user = {}, params = {} } = req;
|
|
25
|
-
const uid = funcs.config?.auth?.disable || ispublic ? '1' : user.uid;
|
|
26
|
-
const tokenDataString = await getToken({
|
|
27
|
-
funcs, uid, token: params.table, mode: 'w', json: 0,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const tokenData = JSON.parse(tokenDataString || '{}');
|
|
31
|
-
|
|
32
|
-
const formData = tokenData?.form || loadTemplate?.form ? await getTemplate('form', tokenData.form || loadTemplate?.form) : {};
|
|
33
|
-
|
|
34
|
-
const xssCheck = checkXSS({ body: req.body, schema: formData?.schema });
|
|
35
|
-
|
|
36
|
-
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
37
|
-
req.log.warn({ name: 'injection/xss', msg: xssCheck.error, table }, req);
|
|
38
|
-
return { message: 'Дані містять заборонені символи. Приберіть їх та спробуйте ще раз', status: 409 };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const res = await dataUpdate({
|
|
42
|
-
table: tokenData?.table || table, id: tokenData?.id || id, data: req.body, uid,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const extraKeys = Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && req.body[key].length);
|
|
46
|
-
if (extraKeys?.length) {
|
|
47
|
-
res.extra = {};
|
|
48
|
-
await Promise.all(extraKeys?.map(async (key) => {
|
|
49
|
-
const objId = req.body[formData[key].parent_id] || req.body?.id;
|
|
50
|
-
// delete old extra data
|
|
51
|
-
await pgClients.client.query(`delete from ${formData[key].table} where ${formData[key].parent_id}=$1`, [objId]); // rewrite?
|
|
52
|
-
// insert new extra data
|
|
53
|
-
const extraRows = await Promise.all(req.body[key].map(async (row) => {
|
|
54
|
-
const extraRes = await dataInsert({ table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid });
|
|
55
|
-
return extraRes?.rows?.[0];
|
|
56
|
-
}));
|
|
57
|
-
Object.assign(res.extra, { [key]: extraRows.filter((el) => el) });
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return res;
|
|
62
|
-
}
|
|
1
|
+
import dataUpdate from '../funcs/dataUpdate.js';
|
|
2
|
+
import dataInsert from '../funcs/dataInsert.js';
|
|
3
|
+
import pgClients from '../../pg/pgClients.js';
|
|
4
|
+
import getToken from '../funcs/getToken.js';
|
|
5
|
+
import checkXSS from './utils/checkXSS.js';
|
|
6
|
+
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
7
|
+
import getAccess from '../funcs/getAccess.js';
|
|
8
|
+
|
|
9
|
+
export default async function update(req) {
|
|
10
|
+
const { actions = [], scope, my } = await getAccess(req, req.params.table, req.params.id) || {};
|
|
11
|
+
if (!actions.includes('edit') || (scope === 'my' && !my)) {
|
|
12
|
+
return { message: 'access restricted', status: 403 };
|
|
13
|
+
}
|
|
14
|
+
if (!req.params?.table) {
|
|
15
|
+
return { message: 'table is required', status: 400 };
|
|
16
|
+
}
|
|
17
|
+
if (!req.params?.id) {
|
|
18
|
+
return { message: 'id is required', status: 404 };
|
|
19
|
+
}
|
|
20
|
+
const loadTemplate = await getTemplate('table', req.params.table);
|
|
21
|
+
const { table, public: ispublic } = loadTemplate || req.params || {};
|
|
22
|
+
const { id } = req.params || {};
|
|
23
|
+
|
|
24
|
+
const { funcs = {}, user = {}, params = {} } = req;
|
|
25
|
+
const uid = funcs.config?.auth?.disable || ispublic ? '1' : user.uid;
|
|
26
|
+
const tokenDataString = await getToken({
|
|
27
|
+
funcs, uid, token: params.table, mode: 'w', json: 0,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const tokenData = JSON.parse(tokenDataString || '{}');
|
|
31
|
+
|
|
32
|
+
const formData = tokenData?.form || loadTemplate?.form ? await getTemplate('form', tokenData.form || loadTemplate?.form) : {};
|
|
33
|
+
|
|
34
|
+
const xssCheck = checkXSS({ body: req.body, schema: formData?.schema });
|
|
35
|
+
|
|
36
|
+
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
37
|
+
req.log.warn({ name: 'injection/xss', msg: xssCheck.error, table }, req);
|
|
38
|
+
return { message: 'Дані містять заборонені символи. Приберіть їх та спробуйте ще раз', status: 409 };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const res = await dataUpdate({
|
|
42
|
+
table: tokenData?.table || table, id: tokenData?.id || id, data: req.body, uid,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const extraKeys = Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && req.body[key].length);
|
|
46
|
+
if (extraKeys?.length) {
|
|
47
|
+
res.extra = {};
|
|
48
|
+
await Promise.all(extraKeys?.map(async (key) => {
|
|
49
|
+
const objId = req.body[formData[key].parent_id] || req.body?.id;
|
|
50
|
+
// delete old extra data
|
|
51
|
+
await pgClients.client.query(`delete from ${formData[key].table} where ${formData[key].parent_id}=$1`, [objId]); // rewrite?
|
|
52
|
+
// insert new extra data
|
|
53
|
+
const extraRows = await Promise.all(req.body[key].map(async (row) => {
|
|
54
|
+
const extraRes = await dataInsert({ table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid });
|
|
55
|
+
return extraRes?.rows?.[0];
|
|
56
|
+
}));
|
|
57
|
+
Object.assign(res.extra, { [key]: extraRows.filter((el) => el) });
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/* import sqlInjection from '../../../policy/funcs/sqlInjection.js'; */
|
|
2
|
-
import xssInjection from './xssInjection.js';
|
|
3
|
-
|
|
4
|
-
/* const checkList = xssInjection.concat(sqlInjection); */
|
|
5
|
-
|
|
6
|
-
// RTE - rich text editor
|
|
7
|
-
|
|
8
|
-
function checkXSS({ body, schema = {} }) {
|
|
9
|
-
const data = typeof body === 'string' ? body : JSON.stringify(body);
|
|
10
|
-
const stopWords = xssInjection.filter((el) => data.toLowerCase().includes(el));
|
|
11
|
-
|
|
12
|
-
// check sql injection
|
|
13
|
-
const stopSpecialSymbols = data.match(/\p{S}OR\p{S}|\p{P}OR\p{P}| OR |\+OR\+/gi);
|
|
14
|
-
if (stopSpecialSymbols?.length) stopSpecialSymbols?.forEach((el) => stopWords.push(el));
|
|
15
|
-
|
|
16
|
-
// escape arrows on non-RTE
|
|
17
|
-
Object.keys(body)
|
|
18
|
-
.filter((key) => ['<', '>'].find((el) => body[key]?.includes?.(el))
|
|
19
|
-
&& !['Summernote', 'Tiny', 'Ace'].includes(schema[key]?.type))
|
|
20
|
-
?.forEach((key) => {
|
|
21
|
-
Object.assign(body, { [key]: body[key].replace(/</g, '<').replace(/>/g, '>') });
|
|
22
|
-
});
|
|
23
|
-
// try { } catch (err) { return { error: err.toString() }; }
|
|
24
|
-
|
|
25
|
-
if (!stopWords.length) return { body };
|
|
26
|
-
|
|
27
|
-
const disabledCheckFields = Object.keys(schema)?.filter((el) => schema[el]?.xssCheck === false); // exclude specific columns
|
|
28
|
-
|
|
29
|
-
// check RTE
|
|
30
|
-
/* const richTextFields = Object.keys(schema).filter((el) => ['Summernote', 'Tiny', 'Ace'].includes(schema[el]?.type));
|
|
31
|
-
richTextFields.filter((key) => !checkList.find((el) => body[key].includes(el)))?.forEach((key) => {
|
|
32
|
-
disabledCheckFields.push(key);
|
|
33
|
-
}); */
|
|
34
|
-
|
|
35
|
-
const field = Object.keys(body)
|
|
36
|
-
?.find((key) => body[key]
|
|
37
|
-
&& !disabledCheckFields.includes(key)
|
|
38
|
-
&& body[key].toLowerCase().includes(stopWords[0]));
|
|
39
|
-
if (field) {
|
|
40
|
-
return { error: `rule: ${stopWords[0]} | attr: ${field} | val: ${body[field]}`, body };
|
|
41
|
-
}
|
|
42
|
-
return { body };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default checkXSS;
|
|
1
|
+
/* import sqlInjection from '../../../policy/funcs/sqlInjection.js'; */
|
|
2
|
+
import xssInjection from './xssInjection.js';
|
|
3
|
+
|
|
4
|
+
/* const checkList = xssInjection.concat(sqlInjection); */
|
|
5
|
+
|
|
6
|
+
// RTE - rich text editor
|
|
7
|
+
|
|
8
|
+
function checkXSS({ body, schema = {} }) {
|
|
9
|
+
const data = typeof body === 'string' ? body : JSON.stringify(body);
|
|
10
|
+
const stopWords = xssInjection.filter((el) => data.toLowerCase().includes(el));
|
|
11
|
+
|
|
12
|
+
// check sql injection
|
|
13
|
+
const stopSpecialSymbols = data.match(/\p{S}OR\p{S}|\p{P}OR\p{P}| OR |\+OR\+/gi);
|
|
14
|
+
if (stopSpecialSymbols?.length) stopSpecialSymbols?.forEach((el) => stopWords.push(el));
|
|
15
|
+
|
|
16
|
+
// escape arrows on non-RTE
|
|
17
|
+
Object.keys(body)
|
|
18
|
+
.filter((key) => ['<', '>'].find((el) => body[key]?.includes?.(el))
|
|
19
|
+
&& !['Summernote', 'Tiny', 'Ace'].includes(schema[key]?.type))
|
|
20
|
+
?.forEach((key) => {
|
|
21
|
+
Object.assign(body, { [key]: body[key].replace(/</g, '<').replace(/>/g, '>') });
|
|
22
|
+
});
|
|
23
|
+
// try { } catch (err) { return { error: err.toString() }; }
|
|
24
|
+
|
|
25
|
+
if (!stopWords.length) return { body };
|
|
26
|
+
|
|
27
|
+
const disabledCheckFields = Object.keys(schema)?.filter((el) => schema[el]?.xssCheck === false); // exclude specific columns
|
|
28
|
+
|
|
29
|
+
// check RTE
|
|
30
|
+
/* const richTextFields = Object.keys(schema).filter((el) => ['Summernote', 'Tiny', 'Ace'].includes(schema[el]?.type));
|
|
31
|
+
richTextFields.filter((key) => !checkList.find((el) => body[key].includes(el)))?.forEach((key) => {
|
|
32
|
+
disabledCheckFields.push(key);
|
|
33
|
+
}); */
|
|
34
|
+
|
|
35
|
+
const field = Object.keys(body)
|
|
36
|
+
?.find((key) => body[key]
|
|
37
|
+
&& !disabledCheckFields.includes(key)
|
|
38
|
+
&& body[key].toLowerCase().includes(stopWords[0]));
|
|
39
|
+
if (field) {
|
|
40
|
+
return { error: `rule: ${stopWords[0]} | attr: ${field} | val: ${body[field]}`, body };
|
|
41
|
+
}
|
|
42
|
+
return { body };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default checkXSS;
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
const xssInjection = [
|
|
2
|
-
'onkeypress=',
|
|
3
|
-
'onkeyup=',
|
|
4
|
-
'ondblclick=',
|
|
5
|
-
'onerror=',
|
|
6
|
-
'onmouseover=',
|
|
7
|
-
'<meta',
|
|
8
|
-
'<script',
|
|
9
|
-
'vascript:',
|
|
10
|
-
'onkeydown=',
|
|
11
|
-
'onmousedown=',
|
|
12
|
-
'onmouseenter=',
|
|
13
|
-
'onmouseleave=',
|
|
14
|
-
'onmousemove=',
|
|
15
|
-
'onmouseout=',
|
|
16
|
-
'onmouseup=',
|
|
17
|
-
'onmousewheel=',
|
|
18
|
-
'onpaste=',
|
|
19
|
-
'onscroll=',
|
|
20
|
-
'onwheel=',
|
|
21
|
-
'javascript:',
|
|
22
|
-
'\\x',
|
|
23
|
-
'eval(',
|
|
24
|
-
'onmouseover=',
|
|
25
|
-
'action=',
|
|
26
|
-
'xlink:',
|
|
27
|
-
'allowscriptaccess',
|
|
28
|
-
'href=',
|
|
29
|
-
'behavior:',
|
|
30
|
-
'onreadystatechange=',
|
|
31
|
-
'onstart=',
|
|
32
|
-
'offline=',
|
|
33
|
-
'onabort=',
|
|
34
|
-
'onafterprint=',
|
|
35
|
-
'onbeforeonload=',
|
|
36
|
-
'onbeforeprint=',
|
|
37
|
-
'onblur=',
|
|
38
|
-
'oncanplay=',
|
|
39
|
-
'oncanplaythrough=',
|
|
40
|
-
'onchange=',
|
|
41
|
-
'onclick=',
|
|
42
|
-
'oncontextmenu=',
|
|
43
|
-
'ondblclick=',
|
|
44
|
-
'ondrag=',
|
|
45
|
-
'ondragend=',
|
|
46
|
-
'ondragenter=',
|
|
47
|
-
'ondragleave=',
|
|
48
|
-
'ondragover=',
|
|
49
|
-
'ondragstart=',
|
|
50
|
-
'ondrop=',
|
|
51
|
-
'ondurationchange=',
|
|
52
|
-
'onemptied=',
|
|
53
|
-
'onended=',
|
|
54
|
-
'onerror=',
|
|
55
|
-
'onfocus=',
|
|
56
|
-
'onformchange=',
|
|
57
|
-
'onforminput=',
|
|
58
|
-
'onhaschange=',
|
|
59
|
-
'oninput=',
|
|
60
|
-
'oninvalid=',
|
|
61
|
-
'onkeydown=',
|
|
62
|
-
'onkeypress=',
|
|
63
|
-
'onkeyup=',
|
|
64
|
-
'onload=',
|
|
65
|
-
'onloadeddata=',
|
|
66
|
-
'onloadedmetadata=',
|
|
67
|
-
'onloadstart=',
|
|
68
|
-
'alert(',
|
|
69
|
-
'script:',
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
export default xssInjection;
|
|
1
|
+
const xssInjection = [
|
|
2
|
+
'onkeypress=',
|
|
3
|
+
'onkeyup=',
|
|
4
|
+
'ondblclick=',
|
|
5
|
+
'onerror=',
|
|
6
|
+
'onmouseover=',
|
|
7
|
+
'<meta',
|
|
8
|
+
'<script',
|
|
9
|
+
'vascript:',
|
|
10
|
+
'onkeydown=',
|
|
11
|
+
'onmousedown=',
|
|
12
|
+
'onmouseenter=',
|
|
13
|
+
'onmouseleave=',
|
|
14
|
+
'onmousemove=',
|
|
15
|
+
'onmouseout=',
|
|
16
|
+
'onmouseup=',
|
|
17
|
+
'onmousewheel=',
|
|
18
|
+
'onpaste=',
|
|
19
|
+
'onscroll=',
|
|
20
|
+
'onwheel=',
|
|
21
|
+
'javascript:',
|
|
22
|
+
'\\x',
|
|
23
|
+
'eval(',
|
|
24
|
+
'onmouseover=',
|
|
25
|
+
'action=',
|
|
26
|
+
'xlink:',
|
|
27
|
+
'allowscriptaccess',
|
|
28
|
+
'href=',
|
|
29
|
+
'behavior:',
|
|
30
|
+
'onreadystatechange=',
|
|
31
|
+
'onstart=',
|
|
32
|
+
'offline=',
|
|
33
|
+
'onabort=',
|
|
34
|
+
'onafterprint=',
|
|
35
|
+
'onbeforeonload=',
|
|
36
|
+
'onbeforeprint=',
|
|
37
|
+
'onblur=',
|
|
38
|
+
'oncanplay=',
|
|
39
|
+
'oncanplaythrough=',
|
|
40
|
+
'onchange=',
|
|
41
|
+
'onclick=',
|
|
42
|
+
'oncontextmenu=',
|
|
43
|
+
'ondblclick=',
|
|
44
|
+
'ondrag=',
|
|
45
|
+
'ondragend=',
|
|
46
|
+
'ondragenter=',
|
|
47
|
+
'ondragleave=',
|
|
48
|
+
'ondragover=',
|
|
49
|
+
'ondragstart=',
|
|
50
|
+
'ondrop=',
|
|
51
|
+
'ondurationchange=',
|
|
52
|
+
'onemptied=',
|
|
53
|
+
'onended=',
|
|
54
|
+
'onerror=',
|
|
55
|
+
'onfocus=',
|
|
56
|
+
'onformchange=',
|
|
57
|
+
'onforminput=',
|
|
58
|
+
'onhaschange=',
|
|
59
|
+
'oninput=',
|
|
60
|
+
'oninvalid=',
|
|
61
|
+
'onkeydown=',
|
|
62
|
+
'onkeypress=',
|
|
63
|
+
'onkeyup=',
|
|
64
|
+
'onload=',
|
|
65
|
+
'onloadeddata=',
|
|
66
|
+
'onloadedmetadata=',
|
|
67
|
+
'onloadstart=',
|
|
68
|
+
'alert(',
|
|
69
|
+
'script:',
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
export default xssInjection;
|
package/crud/funcs/dataDelete.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import logChanges from './utils/logChanges.js';
|
|
5
|
-
|
|
6
|
-
export default async function dataDelete({
|
|
7
|
-
table, id, pg: pg1, uid,
|
|
8
|
-
}) {
|
|
9
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
10
|
-
const { pk } = await getMeta(table);
|
|
11
|
-
if (!pg.tlist?.includes(table)) return 'table not exist';
|
|
12
|
-
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
13
|
-
// console.log(updateDataset);
|
|
14
|
-
const res = await pg.one(delQuery, [id]) || {};
|
|
15
|
-
await logChanges({
|
|
16
|
-
pg, table, id, uid, type: 'DELETE',
|
|
17
|
-
});
|
|
18
|
-
return res;
|
|
19
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import logChanges from './utils/logChanges.js';
|
|
5
|
+
|
|
6
|
+
export default async function dataDelete({
|
|
7
|
+
table, id, pg: pg1, uid,
|
|
8
|
+
}) {
|
|
9
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
10
|
+
const { pk } = await getMeta(table);
|
|
11
|
+
if (!pg.tlist?.includes(table)) return 'table not exist';
|
|
12
|
+
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
13
|
+
// console.log(updateDataset);
|
|
14
|
+
const res = await pg.one(delQuery, [id]) || {};
|
|
15
|
+
await logChanges({
|
|
16
|
+
pg, table, id, uid, type: 'DELETE',
|
|
17
|
+
});
|
|
18
|
+
return res;
|
|
19
|
+
}
|
package/crud/funcs/dataInsert.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import logChanges from './utils/logChanges.js';
|
|
4
|
-
|
|
5
|
-
export default async function dataInsert({
|
|
6
|
-
table, data, pg: pg1, uid,
|
|
7
|
-
}) {
|
|
8
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
9
|
-
if (!data) return null;
|
|
10
|
-
const { columns } = await getMeta(table);
|
|
11
|
-
if (!columns) return null;
|
|
12
|
-
|
|
13
|
-
const names = columns.map((el) => el.name);
|
|
14
|
-
const filterData = Object.keys(data)
|
|
15
|
-
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
16
|
-
|
|
17
|
-
const insertQuery = `insert into ${table}
|
|
18
|
-
|
|
19
|
-
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
20
|
-
|
|
21
|
-
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).join(',')})
|
|
22
|
-
|
|
23
|
-
returning *`;
|
|
24
|
-
|
|
25
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
26
|
-
await logChanges({
|
|
27
|
-
pg, table, data, id: res.rows?.[0]?.[pg.pk[table]], uid, type: 'INSERT',
|
|
28
|
-
});
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import logChanges from './utils/logChanges.js';
|
|
4
|
+
|
|
5
|
+
export default async function dataInsert({
|
|
6
|
+
table, data, pg: pg1, uid,
|
|
7
|
+
}) {
|
|
8
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
9
|
+
if (!data) return null;
|
|
10
|
+
const { columns } = await getMeta(table);
|
|
11
|
+
if (!columns) return null;
|
|
12
|
+
|
|
13
|
+
const names = columns.map((el) => el.name);
|
|
14
|
+
const filterData = Object.keys(data)
|
|
15
|
+
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
16
|
+
|
|
17
|
+
const insertQuery = `insert into ${table}
|
|
18
|
+
|
|
19
|
+
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
20
|
+
|
|
21
|
+
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).join(',')})
|
|
22
|
+
|
|
23
|
+
returning *`;
|
|
24
|
+
|
|
25
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
26
|
+
await logChanges({
|
|
27
|
+
pg, table, data, id: res.rows?.[0]?.[pg.pk[table]], uid, type: 'INSERT',
|
|
28
|
+
});
|
|
29
|
+
return res;
|
|
30
|
+
}
|
package/crud/funcs/dataUpdate.js
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import logChanges from './utils/logChanges.js';
|
|
5
|
-
|
|
6
|
-
export default async function dataUpdate({
|
|
7
|
-
table, id, data, pg: pg1, uid,
|
|
8
|
-
}) {
|
|
9
|
-
if (!data || !table || !id) return null;
|
|
10
|
-
|
|
11
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
12
|
-
const { columns, pk } = await getMeta(table);
|
|
13
|
-
|
|
14
|
-
const names = columns?.map((el) => el.name);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import logChanges from './utils/logChanges.js';
|
|
5
|
+
|
|
6
|
+
export default async function dataUpdate({
|
|
7
|
+
table, id, data, pg: pg1, uid,
|
|
8
|
+
}) {
|
|
9
|
+
if (!data || !table || !id) return null;
|
|
10
|
+
|
|
11
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
12
|
+
const { columns, pk } = await getMeta(table);
|
|
13
|
+
|
|
14
|
+
const names = columns?.map((el) => el.name);
|
|
15
|
+
Object.assign(data, { editor_id: uid });
|
|
16
|
+
const filterData = Object.keys(data)
|
|
17
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && el !== 'editor_date'));
|
|
18
|
+
|
|
19
|
+
const editorDate = names?.includes('editor_date') ? 'editor_date=now(),' : undefined;
|
|
20
|
+
|
|
21
|
+
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
22
|
+
|
|
23
|
+
const updateQuery = `UPDATE ${table} SET ${editorDate} ${filterData
|
|
24
|
+
?.map((key, i) => (key?.includes('geom') && key !== 'geom' ? `"${key}"=st_geomfromgeojson($${i + 2}::json)` : undefined)
|
|
25
|
+
|| (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`))
|
|
26
|
+
.join(',')}
|
|
27
|
+
WHERE ${pk} = $1 returning *`;
|
|
28
|
+
// console.log(updateQuery, filterValue);
|
|
29
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
30
|
+
|
|
31
|
+
await logChanges({
|
|
32
|
+
pg, table, data, id, uid, type: 'UPDATE',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return res;
|
|
36
|
+
}
|
package/crud/funcs/getAccess.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
2
|
-
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
3
|
-
import config from '../../config.js';
|
|
4
|
-
|
|
5
|
-
const q = `select a.route_id as id, b.actions, b.scope
|
|
6
|
-
from admin.routes a
|
|
7
|
-
left join admin.access b on
|
|
8
|
-
a.route_id=b.route_id
|
|
9
|
-
left join admin.roles c on
|
|
10
|
-
b.role_id=c.role_id
|
|
11
|
-
and c.enabled
|
|
12
|
-
left join admin.user_roles d on
|
|
13
|
-
c.role_id=d.role_id
|
|
14
|
-
and ( case when
|
|
15
|
-
d.expiration is not null
|
|
16
|
-
then d.expiration > CURRENT_DATE
|
|
17
|
-
else 1=1
|
|
18
|
-
end )
|
|
19
|
-
where a.route_id=$1 and $2 in (b.user_uid, d.user_uid)`;
|
|
20
|
-
|
|
21
|
-
export default async function getAccess(req, template, id = null) {
|
|
22
|
-
if (config.disableAccessRestriction || true) {
|
|
23
|
-
return { actions: ['get', 'edit', 'del'], my: true, query: '1=1' };
|
|
24
|
-
}
|
|
25
|
-
const { pg, session = {} } = req;
|
|
26
|
-
const { uid, user_type: userType } = session.passport?.user || {};
|
|
27
|
-
if (!uid || !template) return null;
|
|
28
|
-
|
|
29
|
-
if (!pg.pk?.['admin.access']) return null;
|
|
30
|
-
|
|
31
|
-
const { table } = await getTemplate('table', template) || {};
|
|
32
|
-
if (!table) return null;
|
|
33
|
-
|
|
34
|
-
const { scope = 'my', actions = [] } = await pg.one(q, [template, uid]);
|
|
35
|
-
// console.log(scope, actions);
|
|
36
|
-
|
|
37
|
-
const { columns = [] } = await getMeta(table);
|
|
38
|
-
const columnList = columns.map((el) => el.name || el).join(',');
|
|
39
|
-
|
|
40
|
-
const query = userType?.includes('admin') ? '1=1' : {
|
|
41
|
-
my: `uid='${uid}'`,
|
|
42
|
-
responsible: columnList.includes('responsible_id')
|
|
43
|
-
? `responsible_id='${uid}'`
|
|
44
|
-
: `uid='${uid}'`,
|
|
45
|
-
all: '1=1',
|
|
46
|
-
}[scope];
|
|
47
|
-
|
|
48
|
-
const { my } = pg.pk?.[table] && id ? await pg.one(`select uid=$1 as my from ${table} where ${pg.pk?.[table]}=$2`, [uid, id]) : {};
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
scope, actions, query, my,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
1
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
2
|
+
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
3
|
+
import config from '../../config.js';
|
|
4
|
+
|
|
5
|
+
const q = `select a.route_id as id, b.actions, b.scope
|
|
6
|
+
from admin.routes a
|
|
7
|
+
left join admin.access b on
|
|
8
|
+
a.route_id=b.route_id
|
|
9
|
+
left join admin.roles c on
|
|
10
|
+
b.role_id=c.role_id
|
|
11
|
+
and c.enabled
|
|
12
|
+
left join admin.user_roles d on
|
|
13
|
+
c.role_id=d.role_id
|
|
14
|
+
and ( case when
|
|
15
|
+
d.expiration is not null
|
|
16
|
+
then d.expiration > CURRENT_DATE
|
|
17
|
+
else 1=1
|
|
18
|
+
end )
|
|
19
|
+
where a.route_id=$1 and $2 in (b.user_uid, d.user_uid)`;
|
|
20
|
+
|
|
21
|
+
export default async function getAccess(req, template, id = null) {
|
|
22
|
+
if (config.disableAccessRestriction || true) {
|
|
23
|
+
return { actions: ['get', 'edit', 'del'], my: true, query: '1=1' };
|
|
24
|
+
}
|
|
25
|
+
const { pg, session = {} } = req;
|
|
26
|
+
const { uid, user_type: userType } = session.passport?.user || {};
|
|
27
|
+
if (!uid || !template) return null;
|
|
28
|
+
|
|
29
|
+
if (!pg.pk?.['admin.access']) return null;
|
|
30
|
+
|
|
31
|
+
const { table } = await getTemplate('table', template) || {};
|
|
32
|
+
if (!table) return null;
|
|
33
|
+
|
|
34
|
+
const { scope = 'my', actions = [] } = await pg.one(q, [template, uid]);
|
|
35
|
+
// console.log(scope, actions);
|
|
36
|
+
|
|
37
|
+
const { columns = [] } = await getMeta(table);
|
|
38
|
+
const columnList = columns.map((el) => el.name || el).join(',');
|
|
39
|
+
|
|
40
|
+
const query = userType?.includes('admin') ? '1=1' : {
|
|
41
|
+
my: `uid='${uid}'`,
|
|
42
|
+
responsible: columnList.includes('responsible_id')
|
|
43
|
+
? `responsible_id='${uid}'`
|
|
44
|
+
: `uid='${uid}'`,
|
|
45
|
+
all: '1=1',
|
|
46
|
+
}[scope];
|
|
47
|
+
|
|
48
|
+
const { my } = pg.pk?.[table] && id ? await pg.one(`select uid=$1 as my from ${table} where ${pg.pk?.[table]}=$2`, [uid, id]) : {};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
scope, actions, query, my,
|
|
52
|
+
};
|
|
53
|
+
}
|
package/crud/funcs/getOpt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
-
|
|
3
|
-
export default async function getOpt(token, funcs) {
|
|
4
|
-
const rclient = getRedis({ db: 0, funcs });
|
|
5
|
-
|
|
6
|
-
const key = `opt:${token}`;
|
|
7
|
-
const data = await rclient.get(key);
|
|
8
|
-
if (!data) return null;
|
|
9
|
-
return JSON.parse(data);
|
|
10
|
-
}
|
|
1
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
+
|
|
3
|
+
export default async function getOpt(token, funcs) {
|
|
4
|
+
const rclient = getRedis({ db: 0, funcs });
|
|
5
|
+
|
|
6
|
+
const key = `opt:${token}`;
|
|
7
|
+
const data = await rclient.get(key);
|
|
8
|
+
if (!data) return null;
|
|
9
|
+
return JSON.parse(data);
|
|
10
|
+
}
|