dbgate-api 5.4.0 → 5.4.1
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "5.4.
|
|
4
|
+
"version": "5.4.1",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"compare-versions": "^3.6.0",
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"cross-env": "^6.0.3",
|
|
29
|
-
"dbgate-datalib": "^5.4.
|
|
29
|
+
"dbgate-datalib": "^5.4.1",
|
|
30
30
|
"dbgate-query-splitter": "^4.10.3",
|
|
31
|
-
"dbgate-sqltree": "^5.4.
|
|
32
|
-
"dbgate-tools": "^5.4.
|
|
31
|
+
"dbgate-sqltree": "^5.4.1",
|
|
32
|
+
"dbgate-tools": "^5.4.1",
|
|
33
33
|
"debug": "^4.3.4",
|
|
34
34
|
"diff": "^5.0.0",
|
|
35
35
|
"diff2html": "^3.4.13",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/fs-extra": "^9.0.11",
|
|
76
76
|
"@types/lodash": "^4.14.149",
|
|
77
|
-
"dbgate-types": "^5.4.
|
|
77
|
+
"dbgate-types": "^5.4.1",
|
|
78
78
|
"env-cmd": "^10.1.0",
|
|
79
79
|
"node-loader": "^1.0.2",
|
|
80
80
|
"nodemon": "^2.0.2",
|
|
@@ -7,6 +7,7 @@ const { hasPermission } = require('../utility/hasPermission');
|
|
|
7
7
|
const socket = require('../utility/socket');
|
|
8
8
|
const _ = require('lodash');
|
|
9
9
|
const AsyncLock = require('async-lock');
|
|
10
|
+
const jwt = require('jsonwebtoken');
|
|
10
11
|
|
|
11
12
|
const currentVersion = require('../currentVersion');
|
|
12
13
|
const platformInfo = require('../utility/platformInfo');
|
|
@@ -14,6 +15,8 @@ const connections = require('../controllers/connections');
|
|
|
14
15
|
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
|
15
16
|
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
|
|
16
17
|
const storage = require('./storage');
|
|
18
|
+
const { getAuthProxyUrl } = require('../utility/authProxy');
|
|
19
|
+
const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
|
|
17
20
|
|
|
18
21
|
const lock = new AsyncLock();
|
|
19
22
|
|
|
@@ -150,6 +153,22 @@ module.exports = {
|
|
|
150
153
|
|
|
151
154
|
saveLicenseKey_meta: true,
|
|
152
155
|
async saveLicenseKey({ licenseKey }) {
|
|
156
|
+
const decoded = jwt.decode(licenseKey);
|
|
157
|
+
if (!decoded) {
|
|
158
|
+
return {
|
|
159
|
+
status: 'error',
|
|
160
|
+
errorMessage: 'Invalid license key',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const { exp } = decoded;
|
|
165
|
+
if (exp * 1000 < Date.now()) {
|
|
166
|
+
return {
|
|
167
|
+
status: 'error',
|
|
168
|
+
errorMessage: 'License key is expired',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
153
172
|
try {
|
|
154
173
|
if (process.env.STORAGE_DATABASE) {
|
|
155
174
|
await storage.writeConfig({ group: 'license', config: { licenseKey } });
|
|
@@ -158,8 +177,33 @@ module.exports = {
|
|
|
158
177
|
await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey);
|
|
159
178
|
}
|
|
160
179
|
socket.emitChanged(`config-changed`);
|
|
180
|
+
return { status: 'ok' };
|
|
161
181
|
} catch (err) {
|
|
162
|
-
return
|
|
182
|
+
return {
|
|
183
|
+
status: 'error',
|
|
184
|
+
errorMessage: err.message,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
startTrial_meta: true,
|
|
190
|
+
async startTrial() {
|
|
191
|
+
try {
|
|
192
|
+
const fingerprint = await getPublicHardwareFingerprint();
|
|
193
|
+
|
|
194
|
+
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, {
|
|
195
|
+
type: 'premium-trial',
|
|
196
|
+
days: 30,
|
|
197
|
+
fingerprint,
|
|
198
|
+
});
|
|
199
|
+
const { token } = resp.data;
|
|
200
|
+
|
|
201
|
+
return await this.saveLicenseKey({ licenseKey: token });
|
|
202
|
+
} catch (err) {
|
|
203
|
+
return {
|
|
204
|
+
status: 'error',
|
|
205
|
+
errorMessage: err.message,
|
|
206
|
+
};
|
|
163
207
|
}
|
|
164
208
|
},
|
|
165
209
|
|
package/src/currentVersion.js
CHANGED
package/src/utility/authProxy.js
CHANGED
|
@@ -12,9 +12,14 @@ async function authProxyGetTokenFromCode(options) {
|
|
|
12
12
|
|
|
13
13
|
function startTokenChecking(sid, callback) {}
|
|
14
14
|
|
|
15
|
+
function getAuthProxyUrl() {
|
|
16
|
+
return 'https://auth.dbgate.eu';
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
module.exports = {
|
|
16
20
|
isAuthProxySupported,
|
|
17
21
|
authProxyGetRedirectUrl,
|
|
18
22
|
authProxyGetTokenFromCode,
|
|
19
23
|
startTokenChecking,
|
|
24
|
+
getAuthProxyUrl,
|
|
20
25
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
async function getPublicIp() {
|
|
6
|
+
try {
|
|
7
|
+
const resp = await axios.default.get('https://api.ipify.org?format=json');
|
|
8
|
+
return resp.data.ip || 'unknown-ip';
|
|
9
|
+
} catch (err) {
|
|
10
|
+
return 'unknown-ip';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getMacAddress() {
|
|
15
|
+
try {
|
|
16
|
+
const interfaces = os.networkInterfaces();
|
|
17
|
+
for (let iface of Object.values(interfaces)) {
|
|
18
|
+
for (let config of iface) {
|
|
19
|
+
if (config.mac && config.mac !== '00:00:00:00:00:00') {
|
|
20
|
+
return config.mac;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return '00:00:00:00:00:00';
|
|
25
|
+
} catch (err) {
|
|
26
|
+
return '00:00:00:00:00:00';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function getHardwareFingerprint() {
|
|
31
|
+
const publicIp = await getPublicIp();
|
|
32
|
+
const macAddress = getMacAddress();
|
|
33
|
+
const platform = os.platform();
|
|
34
|
+
const release = os.release();
|
|
35
|
+
const hostname = os.hostname();
|
|
36
|
+
const totalMemory = os.totalmem();
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
publicIp,
|
|
40
|
+
macAddress,
|
|
41
|
+
platform,
|
|
42
|
+
release,
|
|
43
|
+
hostname,
|
|
44
|
+
totalMemory,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function getHardwareFingerprintHash(data = undefined) {
|
|
49
|
+
if (!data) {
|
|
50
|
+
data = await getHardwareFingerprint();
|
|
51
|
+
}
|
|
52
|
+
const fingerprintData = JSON.stringify(data);
|
|
53
|
+
const hash = crypto.createHash('sha256').update(fingerprintData).digest('hex');
|
|
54
|
+
return hash;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function getPublicHardwareFingerprint() {
|
|
58
|
+
const fingerprint = await getHardwareFingerprint();
|
|
59
|
+
const hash = await getHardwareFingerprintHash(fingerprint);
|
|
60
|
+
return {
|
|
61
|
+
hash,
|
|
62
|
+
payload: {
|
|
63
|
+
platform: fingerprint.platform,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// getHardwareFingerprint().then(console.log);
|
|
69
|
+
// getHardwareFingerprintHash().then(console.log);
|
|
70
|
+
// getPublicHardwareFingerprint().then(console.log);
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
getHardwareFingerprint,
|
|
74
|
+
getHardwareFingerprintHash,
|
|
75
|
+
getPublicHardwareFingerprint,
|
|
76
|
+
};
|