dbgate-api 4.7.4-alpha.8 → 4.7.4
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/.env +12 -1
- package/package.json +5 -5
- package/src/controllers/config.js +16 -5
- package/src/controllers/files.js +19 -19
- package/src/controllers/plugins.js +7 -7
- package/src/controllers/runners.js +1 -1
- package/src/controllers/scheduler.js +3 -3
- package/src/currentVersion.js +2 -2
- package/src/index.js +1 -1
- package/src/main.js +23 -14
- package/src/utility/directories.js +16 -2
- package/src/utility/hasPermission.js +50 -6
- package/src/utility/platformInfo.js +1 -1
- package/src/utility/processArgs.js +12 -2
- package/src/utility/useController.js +1 -1
package/.env
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
DEVMODE=1
|
|
2
2
|
# PERMISSIONS=~widgets/app,~widgets/plugins
|
|
3
3
|
# DISABLE_SHELL=1
|
|
4
|
-
# HIDE_APP_EDITOR=1
|
|
4
|
+
# HIDE_APP_EDITOR=1
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# DEVWEB=1
|
|
8
|
+
# LOGINS=admin,test
|
|
9
|
+
|
|
10
|
+
# LOGIN_PASSWORD_admin=admin
|
|
11
|
+
# LOGIN_PERMISSIONS_admin=*
|
|
12
|
+
|
|
13
|
+
# LOGIN_PASSWORD_test=test
|
|
14
|
+
# LOGIN_PERMISSIONS_test=~*, widgets/database
|
|
15
|
+
# WORKSPACE_DIR=/home/jena/dbgate-data-2
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "4.7.4
|
|
4
|
+
"version": "4.7.4",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"compare-versions": "^3.6.0",
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
27
|
"cross-env": "^6.0.3",
|
|
28
|
-
"dbgate-query-splitter": "^4.7.4
|
|
29
|
-
"dbgate-sqltree": "^4.7.4
|
|
30
|
-
"dbgate-tools": "^4.7.4
|
|
28
|
+
"dbgate-query-splitter": "^4.7.4",
|
|
29
|
+
"dbgate-sqltree": "^4.7.4",
|
|
30
|
+
"dbgate-tools": "^4.7.4",
|
|
31
31
|
"diff": "^5.0.0",
|
|
32
32
|
"diff2html": "^3.4.13",
|
|
33
33
|
"eslint": "^6.8.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/fs-extra": "^9.0.11",
|
|
65
65
|
"@types/lodash": "^4.14.149",
|
|
66
|
-
"dbgate-types": "^4.7.4
|
|
66
|
+
"dbgate-types": "^4.7.4",
|
|
67
67
|
"env-cmd": "^10.1.0",
|
|
68
68
|
"node-loader": "^1.0.2",
|
|
69
69
|
"nodemon": "^2.0.2",
|
|
@@ -3,7 +3,7 @@ const os = require('os');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const axios = require('axios');
|
|
5
5
|
const { datadir } = require('../utility/directories');
|
|
6
|
-
const hasPermission = require('../utility/hasPermission');
|
|
6
|
+
const { hasPermission, getLogins } = require('../utility/hasPermission');
|
|
7
7
|
const socket = require('../utility/socket');
|
|
8
8
|
const _ = require('lodash');
|
|
9
9
|
const AsyncLock = require('async-lock');
|
|
@@ -26,8 +26,10 @@ module.exports = {
|
|
|
26
26
|
// },
|
|
27
27
|
|
|
28
28
|
get_meta: true,
|
|
29
|
-
async get() {
|
|
30
|
-
const
|
|
29
|
+
async get(_params, req) {
|
|
30
|
+
const logins = getLogins();
|
|
31
|
+
const login = logins ? logins.find(x => x.login == (req.auth && req.auth.user)) : null;
|
|
32
|
+
const permissions = login ? login.permissions : null;
|
|
31
33
|
|
|
32
34
|
return {
|
|
33
35
|
runAsPortal: !!connections.portalConnections,
|
|
@@ -36,10 +38,19 @@ module.exports = {
|
|
|
36
38
|
allowShellConnection: platformInfo.allowShellConnection,
|
|
37
39
|
allowShellScripting: platformInfo.allowShellConnection,
|
|
38
40
|
permissions,
|
|
41
|
+
login,
|
|
39
42
|
...currentVersion,
|
|
40
43
|
};
|
|
41
44
|
},
|
|
42
45
|
|
|
46
|
+
logout_meta: {
|
|
47
|
+
method: 'get',
|
|
48
|
+
raw: true,
|
|
49
|
+
},
|
|
50
|
+
logout(req, res) {
|
|
51
|
+
res.status(401).send('Logged out<br><a href="../..">Back to DbGate</a>');
|
|
52
|
+
},
|
|
53
|
+
|
|
43
54
|
platformInfo_meta: true,
|
|
44
55
|
async platformInfo() {
|
|
45
56
|
return platformInfo;
|
|
@@ -67,8 +78,8 @@ module.exports = {
|
|
|
67
78
|
},
|
|
68
79
|
|
|
69
80
|
updateSettings_meta: true,
|
|
70
|
-
async updateSettings(values) {
|
|
71
|
-
if (!hasPermission(`settings/change
|
|
81
|
+
async updateSettings(values, req) {
|
|
82
|
+
if (!hasPermission(`settings/change`, req)) return false;
|
|
72
83
|
|
|
73
84
|
const res = await lock.acquire('update', async () => {
|
|
74
85
|
const currentValue = await this.getSettings();
|
package/src/controllers/files.js
CHANGED
|
@@ -3,7 +3,7 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { filesdir, archivedir, resolveArchiveFolder, uploadsdir, appdir } = require('../utility/directories');
|
|
5
5
|
const getChartExport = require('../utility/getChartExport');
|
|
6
|
-
const hasPermission = require('../utility/hasPermission');
|
|
6
|
+
const { hasPermission } = require('../utility/hasPermission');
|
|
7
7
|
const socket = require('../utility/socket');
|
|
8
8
|
const scheduler = require('./scheduler');
|
|
9
9
|
const getDiagramExport = require('../utility/getDiagramExport');
|
|
@@ -23,8 +23,8 @@ function deserialize(format, text) {
|
|
|
23
23
|
|
|
24
24
|
module.exports = {
|
|
25
25
|
list_meta: true,
|
|
26
|
-
async list({ folder }) {
|
|
27
|
-
if (!hasPermission(`files/${folder}/read
|
|
26
|
+
async list({ folder }, req) {
|
|
27
|
+
if (!hasPermission(`files/${folder}/read`, req)) return [];
|
|
28
28
|
const dir = path.join(filesdir(), folder);
|
|
29
29
|
if (!(await fs.exists(dir))) return [];
|
|
30
30
|
const files = (await fs.readdir(dir)).map(file => ({ folder, file }));
|
|
@@ -32,11 +32,11 @@ module.exports = {
|
|
|
32
32
|
},
|
|
33
33
|
|
|
34
34
|
listAll_meta: true,
|
|
35
|
-
async listAll() {
|
|
35
|
+
async listAll(_params, req) {
|
|
36
36
|
const folders = await fs.readdir(filesdir());
|
|
37
37
|
const res = [];
|
|
38
38
|
for (const folder of folders) {
|
|
39
|
-
if (!hasPermission(`files/${folder}/read
|
|
39
|
+
if (!hasPermission(`files/${folder}/read`, req)) continue;
|
|
40
40
|
const dir = path.join(filesdir(), folder);
|
|
41
41
|
const files = (await fs.readdir(dir)).map(file => ({ folder, file }));
|
|
42
42
|
res.push(...files);
|
|
@@ -45,8 +45,8 @@ module.exports = {
|
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
delete_meta: true,
|
|
48
|
-
async delete({ folder, file }) {
|
|
49
|
-
if (!hasPermission(`files/${folder}/write
|
|
48
|
+
async delete({ folder, file }, req) {
|
|
49
|
+
if (!hasPermission(`files/${folder}/write`, req)) return false;
|
|
50
50
|
await fs.unlink(path.join(filesdir(), folder, file));
|
|
51
51
|
socket.emitChanged(`files-changed-${folder}`);
|
|
52
52
|
socket.emitChanged(`all-files-changed`);
|
|
@@ -54,8 +54,8 @@ module.exports = {
|
|
|
54
54
|
},
|
|
55
55
|
|
|
56
56
|
rename_meta: true,
|
|
57
|
-
async rename({ folder, file, newFile }) {
|
|
58
|
-
if (!hasPermission(`files/${folder}/write
|
|
57
|
+
async rename({ folder, file, newFile }, req) {
|
|
58
|
+
if (!hasPermission(`files/${folder}/write`, req)) return false;
|
|
59
59
|
await fs.rename(path.join(filesdir(), folder, file), path.join(filesdir(), folder, newFile));
|
|
60
60
|
socket.emitChanged(`files-changed-${folder}`);
|
|
61
61
|
socket.emitChanged(`all-files-changed`);
|
|
@@ -63,8 +63,8 @@ module.exports = {
|
|
|
63
63
|
},
|
|
64
64
|
|
|
65
65
|
copy_meta: true,
|
|
66
|
-
async copy({ folder, file, newFile }) {
|
|
67
|
-
if (!hasPermission(`files/${folder}/write
|
|
66
|
+
async copy({ folder, file, newFile }, req) {
|
|
67
|
+
if (!hasPermission(`files/${folder}/write`, req)) return false;
|
|
68
68
|
await fs.copyFile(path.join(filesdir(), folder, file), path.join(filesdir(), folder, newFile));
|
|
69
69
|
socket.emitChanged(`files-changed-${folder}`);
|
|
70
70
|
socket.emitChanged(`all-files-changed`);
|
|
@@ -72,7 +72,7 @@ module.exports = {
|
|
|
72
72
|
},
|
|
73
73
|
|
|
74
74
|
load_meta: true,
|
|
75
|
-
async load({ folder, file, format }) {
|
|
75
|
+
async load({ folder, file, format }, req) {
|
|
76
76
|
if (folder.startsWith('archive:')) {
|
|
77
77
|
const text = await fs.readFile(path.join(resolveArchiveFolder(folder.substring('archive:'.length)), file), {
|
|
78
78
|
encoding: 'utf-8',
|
|
@@ -84,22 +84,22 @@ module.exports = {
|
|
|
84
84
|
});
|
|
85
85
|
return deserialize(format, text);
|
|
86
86
|
} else {
|
|
87
|
-
if (!hasPermission(`files/${folder}/read
|
|
87
|
+
if (!hasPermission(`files/${folder}/read`, req)) return null;
|
|
88
88
|
const text = await fs.readFile(path.join(filesdir(), folder, file), { encoding: 'utf-8' });
|
|
89
89
|
return deserialize(format, text);
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
|
|
93
93
|
save_meta: true,
|
|
94
|
-
async save({ folder, file, data, format }) {
|
|
94
|
+
async save({ folder, file, data, format }, req) {
|
|
95
95
|
if (folder.startsWith('archive:')) {
|
|
96
|
-
if (!hasPermission(`archive/write
|
|
96
|
+
if (!hasPermission(`archive/write`, req)) return false;
|
|
97
97
|
const dir = resolveArchiveFolder(folder.substring('archive:'.length));
|
|
98
98
|
await fs.writeFile(path.join(dir, file), serialize(format, data));
|
|
99
99
|
socket.emitChanged(`archive-files-changed-${folder.substring('archive:'.length)}`);
|
|
100
100
|
return true;
|
|
101
101
|
} else if (folder.startsWith('app:')) {
|
|
102
|
-
if (!hasPermission(`apps/write
|
|
102
|
+
if (!hasPermission(`apps/write`, req)) return false;
|
|
103
103
|
const app = folder.substring('app:'.length);
|
|
104
104
|
await fs.writeFile(path.join(appdir(), app, file), serialize(format, data));
|
|
105
105
|
socket.emitChanged(`app-files-changed-${app}`);
|
|
@@ -107,7 +107,7 @@ module.exports = {
|
|
|
107
107
|
apps.emitChangedDbApp(folder);
|
|
108
108
|
return true;
|
|
109
109
|
} else {
|
|
110
|
-
if (!hasPermission(`files/${folder}/write
|
|
110
|
+
if (!hasPermission(`files/${folder}/write`, req)) return false;
|
|
111
111
|
const dir = path.join(filesdir(), folder);
|
|
112
112
|
if (!(await fs.exists(dir))) {
|
|
113
113
|
await fs.mkdir(dir);
|
|
@@ -128,8 +128,8 @@ module.exports = {
|
|
|
128
128
|
},
|
|
129
129
|
|
|
130
130
|
favorites_meta: true,
|
|
131
|
-
async favorites() {
|
|
132
|
-
if (!hasPermission(`files/favorites/read
|
|
131
|
+
async favorites(_params, req) {
|
|
132
|
+
if (!hasPermission(`files/favorites/read`, req)) return [];
|
|
133
133
|
const dir = path.join(filesdir(), 'favorites');
|
|
134
134
|
if (!(await fs.exists(dir))) return [];
|
|
135
135
|
const files = await fs.readdir(dir);
|
|
@@ -7,7 +7,7 @@ const socket = require('../utility/socket');
|
|
|
7
7
|
const compareVersions = require('compare-versions');
|
|
8
8
|
const requirePlugin = require('../shell/requirePlugin');
|
|
9
9
|
const downloadPackage = require('../utility/downloadPackage');
|
|
10
|
-
const hasPermission = require('../utility/hasPermission');
|
|
10
|
+
const { hasPermission } = require('../utility/hasPermission');
|
|
11
11
|
const _ = require('lodash');
|
|
12
12
|
const packagedPluginsContent = require('../packagedPluginsContent');
|
|
13
13
|
|
|
@@ -115,8 +115,8 @@ module.exports = {
|
|
|
115
115
|
// },
|
|
116
116
|
|
|
117
117
|
install_meta: true,
|
|
118
|
-
async install({ packageName }) {
|
|
119
|
-
if (!hasPermission(`plugins/install
|
|
118
|
+
async install({ packageName }, req) {
|
|
119
|
+
if (!hasPermission(`plugins/install`, req)) return;
|
|
120
120
|
const dir = path.join(pluginsdir(), packageName);
|
|
121
121
|
// @ts-ignore
|
|
122
122
|
if (!(await fs.exists(dir))) {
|
|
@@ -128,8 +128,8 @@ module.exports = {
|
|
|
128
128
|
},
|
|
129
129
|
|
|
130
130
|
uninstall_meta: true,
|
|
131
|
-
async uninstall({ packageName }) {
|
|
132
|
-
if (!hasPermission(`plugins/install
|
|
131
|
+
async uninstall({ packageName }, req) {
|
|
132
|
+
if (!hasPermission(`plugins/install`, req)) return;
|
|
133
133
|
const dir = path.join(pluginsdir(), packageName);
|
|
134
134
|
await fs.rmdir(dir, { recursive: true });
|
|
135
135
|
socket.emitChanged(`installed-plugins-changed`);
|
|
@@ -138,8 +138,8 @@ module.exports = {
|
|
|
138
138
|
},
|
|
139
139
|
|
|
140
140
|
upgrade_meta: true,
|
|
141
|
-
async upgrade({ packageName }) {
|
|
142
|
-
if (!hasPermission(`plugins/install
|
|
141
|
+
async upgrade({ packageName }, req) {
|
|
142
|
+
if (!hasPermission(`plugins/install`, req)) return;
|
|
143
143
|
const dir = path.join(pluginsdir(), packageName);
|
|
144
144
|
// @ts-ignore
|
|
145
145
|
if (await fs.exists(dir)) {
|
|
@@ -111,7 +111,7 @@ module.exports = {
|
|
|
111
111
|
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
112
112
|
env: {
|
|
113
113
|
...process.env,
|
|
114
|
-
DBGATE_API: global['API_PACKAGE'] ||
|
|
114
|
+
DBGATE_API: global['API_PACKAGE'] || process.argv[1],
|
|
115
115
|
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
|
|
116
116
|
},
|
|
117
117
|
}
|
|
@@ -3,7 +3,7 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const cron = require('node-cron');
|
|
5
5
|
const runners = require('./runners');
|
|
6
|
-
const hasPermission = require('../utility/hasPermission');
|
|
6
|
+
const { hasPermission } = require('../utility/hasPermission');
|
|
7
7
|
|
|
8
8
|
const scheduleRegex = /\s*\/\/\s*@schedule\s+([^\n]+)\n/;
|
|
9
9
|
|
|
@@ -26,8 +26,8 @@ module.exports = {
|
|
|
26
26
|
this.tasks.push(task);
|
|
27
27
|
},
|
|
28
28
|
|
|
29
|
-
async reload() {
|
|
30
|
-
if (!hasPermission('files/shell/read')) return;
|
|
29
|
+
async reload(_params, req) {
|
|
30
|
+
if (!hasPermission('files/shell/read', req)) return;
|
|
31
31
|
const shellDir = path.join(filesdir(), 'shell');
|
|
32
32
|
await this.unload();
|
|
33
33
|
if (!(await fs.exists(shellDir))) return;
|
package/src/currentVersion.js
CHANGED
package/src/index.js
CHANGED
|
@@ -8,7 +8,7 @@ if (processArgs.startProcess) {
|
|
|
8
8
|
const proc = require('./proc');
|
|
9
9
|
const module = proc[processArgs.startProcess];
|
|
10
10
|
module.start();
|
|
11
|
-
} else if (!processArgs.checkParent && !global['API_PACKAGE']
|
|
11
|
+
} else if (!processArgs.checkParent && !global['API_PACKAGE']) {
|
|
12
12
|
const main = require('./main');
|
|
13
13
|
|
|
14
14
|
main.start();
|
package/src/main.js
CHANGED
|
@@ -29,6 +29,8 @@ const queryHistory = require('./controllers/queryHistory');
|
|
|
29
29
|
const { rundir } = require('./utility/directories');
|
|
30
30
|
const platformInfo = require('./utility/platformInfo');
|
|
31
31
|
const getExpressPath = require('./utility/getExpressPath');
|
|
32
|
+
const { getLogins } = require('./utility/hasPermission');
|
|
33
|
+
const _ = require('lodash');
|
|
32
34
|
|
|
33
35
|
function start() {
|
|
34
36
|
// console.log('process.argv', process.argv);
|
|
@@ -37,12 +39,11 @@ function start() {
|
|
|
37
39
|
|
|
38
40
|
const server = http.createServer(app);
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
const logins = getLogins();
|
|
43
|
+
if (logins) {
|
|
41
44
|
app.use(
|
|
42
45
|
basicAuth({
|
|
43
|
-
users:
|
|
44
|
-
[process.env.LOGIN]: process.env.PASSWORD,
|
|
45
|
-
},
|
|
46
|
+
users: _.fromPairs(logins.map(x => [x.login, x.password])),
|
|
46
47
|
challenge: true,
|
|
47
48
|
realm: 'DbGate Web App',
|
|
48
49
|
})
|
|
@@ -85,15 +86,11 @@ function start() {
|
|
|
85
86
|
if (platformInfo.isDocker) {
|
|
86
87
|
// server static files inside docker container
|
|
87
88
|
app.use(getExpressPath('/'), express.static('/home/dbgate-docker/public'));
|
|
88
|
-
} else {
|
|
89
|
-
if (!platformInfo.isNpmDist) {
|
|
90
|
-
app.get(getExpressPath('/'), (req, res) => {
|
|
91
|
-
res.send('DbGate API');
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
89
|
|
|
96
|
-
|
|
90
|
+
const port = process.env.PORT || 3000;
|
|
91
|
+
console.log('DbGate API listening on port (docker build)', port);
|
|
92
|
+
server.listen(port);
|
|
93
|
+
} else if (platformInfo.isNpmDist) {
|
|
97
94
|
app.use(getExpressPath('/'), express.static(path.join(__dirname, '../../dbgate-web/public')));
|
|
98
95
|
getPort({
|
|
99
96
|
port: parseInt(
|
|
@@ -102,12 +99,24 @@ function start() {
|
|
|
102
99
|
),
|
|
103
100
|
}).then(port => {
|
|
104
101
|
server.listen(port, () => {
|
|
105
|
-
console.log(`DbGate API listening on port ${port}`);
|
|
102
|
+
console.log(`DbGate API listening on port ${port} (NPM build)`);
|
|
106
103
|
});
|
|
107
104
|
});
|
|
105
|
+
} else if (process.env.DEVWEB) {
|
|
106
|
+
console.log('__dirname', __dirname);
|
|
107
|
+
console.log(path.join(__dirname, '../../web/public/build'));
|
|
108
|
+
app.use(getExpressPath('/'), express.static(path.join(__dirname, '../../web/public')));
|
|
109
|
+
|
|
110
|
+
const port = process.env.PORT || 3000;
|
|
111
|
+
console.log('DbGate API & web listening on port (dev web build)', port);
|
|
112
|
+
server.listen(port);
|
|
108
113
|
} else {
|
|
114
|
+
app.get(getExpressPath('/'), (req, res) => {
|
|
115
|
+
res.send('DbGate API');
|
|
116
|
+
});
|
|
117
|
+
|
|
109
118
|
const port = process.env.PORT || 3000;
|
|
110
|
-
console.log('DbGate API listening on port', port);
|
|
119
|
+
console.log('DbGate API listening on port (dev API build)', port);
|
|
111
120
|
server.listen(port);
|
|
112
121
|
}
|
|
113
122
|
|
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cleanDirectory = require('./cleanDirectory');
|
|
5
5
|
const platformInfo = require('./platformInfo');
|
|
6
|
+
const processArgs = require('./processArgs');
|
|
6
7
|
|
|
7
8
|
const createDirectories = {};
|
|
8
9
|
const ensureDirectory = (dir, clean) => {
|
|
@@ -19,8 +20,18 @@ const ensureDirectory = (dir, clean) => {
|
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
function datadirCore() {
|
|
24
|
+
if (process.env.WORKSPACE_DIR) {
|
|
25
|
+
return process.env.WORKSPACE_DIR;
|
|
26
|
+
}
|
|
27
|
+
if (processArgs.workspaceDir) {
|
|
28
|
+
return processArgs.workspaceDir;
|
|
29
|
+
}
|
|
30
|
+
return path.join(os.homedir(), 'dbgate-data');
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
function datadir() {
|
|
23
|
-
const dir =
|
|
34
|
+
const dir = datadirCore();
|
|
24
35
|
ensureDirectory(dir);
|
|
25
36
|
|
|
26
37
|
return dir;
|
|
@@ -54,7 +65,10 @@ function packagedPluginsDir() {
|
|
|
54
65
|
}
|
|
55
66
|
if (platformInfo.isNpmDist) {
|
|
56
67
|
// node_modules
|
|
57
|
-
return global['
|
|
68
|
+
return global['PLUGINS_DIR'];
|
|
69
|
+
}
|
|
70
|
+
if (processArgs.pluginsDir) {
|
|
71
|
+
return processArgs.pluginsDir;
|
|
58
72
|
}
|
|
59
73
|
if (platformInfo.isElectronBundle) {
|
|
60
74
|
return path.resolve(__dirname, '../../plugins');
|
|
@@ -1,12 +1,56 @@
|
|
|
1
1
|
const { compilePermissions, testPermission } = require('dbgate-tools');
|
|
2
|
+
const _ = require('lodash');
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const userPermissions = {};
|
|
4
5
|
|
|
5
|
-
function hasPermission(tested) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function hasPermission(tested, req) {
|
|
7
|
+
const { user } = (req && req.auth) || {};
|
|
8
|
+
const key = user || '';
|
|
9
|
+
const logins = getLogins();
|
|
10
|
+
if (!userPermissions[key] && logins) {
|
|
11
|
+
const login = logins.find(x => x.login == user);
|
|
12
|
+
userPermissions[key] = compilePermissions(login ? login.permissions : null);
|
|
8
13
|
}
|
|
9
|
-
return testPermission(tested,
|
|
14
|
+
return testPermission(tested, userPermissions[key]);
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
let loginsCache = null;
|
|
18
|
+
let loginsLoaded = false;
|
|
19
|
+
|
|
20
|
+
function getLogins() {
|
|
21
|
+
if (loginsLoaded) {
|
|
22
|
+
return loginsCache;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const res = [];
|
|
26
|
+
if (process.env.LOGIN && process.env.PASSWORD) {
|
|
27
|
+
res.push({
|
|
28
|
+
login: process.env.LOGIN,
|
|
29
|
+
password: process.env.PASSWORD,
|
|
30
|
+
permissions: process.env.PERMISSIONS,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (process.env.LOGINS) {
|
|
34
|
+
const logins = _.compact(process.env.LOGINS.split(',').map(x => x.trim()));
|
|
35
|
+
for (const login of logins) {
|
|
36
|
+
const password = process.env[`LOGIN_PASSWORD_${login}`];
|
|
37
|
+
const permissions = process.env[`LOGIN_PERMISSIONS_${login}`];
|
|
38
|
+
if (password) {
|
|
39
|
+
res.push({
|
|
40
|
+
login,
|
|
41
|
+
password,
|
|
42
|
+
permissions,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
loginsCache = res.length > 0 ? res : null;
|
|
49
|
+
loginsLoaded = true;
|
|
50
|
+
return loginsCache;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
hasPermission,
|
|
55
|
+
getLogins,
|
|
56
|
+
};
|
|
@@ -10,7 +10,7 @@ const isMac = platform === 'darwin';
|
|
|
10
10
|
const isLinux = platform === 'linux';
|
|
11
11
|
const isDocker = fs.existsSync('/home/dbgate-docker/public');
|
|
12
12
|
const isDevMode = process.env.DEVMODE == '1';
|
|
13
|
-
const isNpmDist = !!global['
|
|
13
|
+
const isNpmDist = !!global['IS_NPM_DIST'];
|
|
14
14
|
const isForkedApi = processArgs.isForkedApi;
|
|
15
15
|
|
|
16
16
|
// function moduleAvailable(name) {
|
|
@@ -9,10 +9,18 @@ function getNamedArg(name) {
|
|
|
9
9
|
const checkParent = process.argv.includes('--checkParent');
|
|
10
10
|
const startProcess = getNamedArg('--start-process');
|
|
11
11
|
const isForkedApi = process.argv.includes('--is-forked-api');
|
|
12
|
+
const pluginsDir = getNamedArg('--plugins-dir');
|
|
13
|
+
const workspaceDir = getNamedArg('--workspace-dir');
|
|
12
14
|
|
|
13
15
|
function getPassArgs() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
const res = [];
|
|
17
|
+
if (global['NATIVE_MODULES']) {
|
|
18
|
+
res.push('--native-modules', global['NATIVE_MODULES']);
|
|
19
|
+
}
|
|
20
|
+
if (global['PLUGINS_DIR']) {
|
|
21
|
+
res.push('--plugins-dir', global['PLUGINS_DIR']);
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
module.exports = {
|
|
@@ -20,4 +28,6 @@ module.exports = {
|
|
|
20
28
|
startProcess,
|
|
21
29
|
isForkedApi,
|
|
22
30
|
getPassArgs,
|
|
31
|
+
pluginsDir,
|
|
32
|
+
workspaceDir,
|
|
23
33
|
};
|
|
@@ -62,7 +62,7 @@ module.exports = function useController(app, electron, route, controller) {
|
|
|
62
62
|
// controller._init_called = true;
|
|
63
63
|
// }
|
|
64
64
|
try {
|
|
65
|
-
let params = [{ ...req.body, ...req.query }];
|
|
65
|
+
let params = [{ ...req.body, ...req.query }, req];
|
|
66
66
|
if (rawParams) params = [req, res];
|
|
67
67
|
const data = await controller[key](...params);
|
|
68
68
|
res.json(data);
|