dbgate-api 5.4.0 → 5.4.2

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.0",
4
+ "version": "5.4.2",
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.0",
29
+ "dbgate-datalib": "^5.4.2",
30
30
  "dbgate-query-splitter": "^4.10.3",
31
- "dbgate-sqltree": "^5.4.0",
32
- "dbgate-tools": "^5.4.0",
31
+ "dbgate-sqltree": "^5.4.2",
32
+ "dbgate-tools": "^5.4.2",
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.0",
77
+ "dbgate-types": "^5.4.2",
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 null;
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
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.4.0',
4
- buildTime: '2024-09-03T13:07:02.765Z'
3
+ version: '5.4.2',
4
+ buildTime: '2024-09-06T11:51:54.891Z'
5
5
  };
@@ -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,88 @@
1
+ const axios = require('axios');
2
+ const os = require('os');
3
+ const crypto = require('crypto');
4
+ const platformInfo = require('./platformInfo');
5
+
6
+ async function getPublicIpInfo() {
7
+ try {
8
+ const resp = await axios.default.get('https://ipinfo.io/json');
9
+ if (!resp.data?.ip) {
10
+ return { ip: 'unknown-ip' };
11
+ }
12
+ return resp.data;
13
+ } catch (err) {
14
+ return { ip: 'unknown-ip' };
15
+ }
16
+ }
17
+
18
+ function getMacAddress() {
19
+ try {
20
+ const interfaces = os.networkInterfaces();
21
+ for (let iface of Object.values(interfaces)) {
22
+ for (let config of iface) {
23
+ if (config.mac && config.mac !== '00:00:00:00:00:00') {
24
+ return config.mac;
25
+ }
26
+ }
27
+ }
28
+ return '00:00:00:00:00:00';
29
+ } catch (err) {
30
+ return '00:00:00:00:00:00';
31
+ }
32
+ }
33
+
34
+ async function getHardwareFingerprint() {
35
+ const publicIpInfo = await getPublicIpInfo();
36
+ const macAddress = getMacAddress();
37
+ const platform = os.platform();
38
+ const release = os.release();
39
+ const hostname = os.hostname();
40
+ const totalMemory = os.totalmem();
41
+
42
+ return {
43
+ publicIp: publicIpInfo.ip,
44
+ country: publicIpInfo.country,
45
+ region: publicIpInfo.region,
46
+ city: publicIpInfo.city,
47
+ macAddress,
48
+ platform,
49
+ release,
50
+ hostname,
51
+ totalMemory,
52
+ };
53
+ }
54
+
55
+ async function getHardwareFingerprintHash(data = undefined) {
56
+ if (!data) {
57
+ data = await getHardwareFingerprint();
58
+ }
59
+ const fingerprintData = JSON.stringify(data);
60
+ const hash = crypto.createHash('sha256').update(fingerprintData).digest('hex');
61
+ return hash;
62
+ }
63
+
64
+ async function getPublicHardwareFingerprint() {
65
+ const fingerprint = await getHardwareFingerprint();
66
+ const hash = await getHardwareFingerprintHash(fingerprint);
67
+ return {
68
+ hash,
69
+ payload: {
70
+ platform: fingerprint.platform,
71
+ city: fingerprint.city,
72
+ country: fingerprint.country,
73
+ region: fingerprint.region,
74
+ isDocker: platformInfo.isDocker,
75
+ isElectron: platformInfo.isElectron,
76
+ },
77
+ };
78
+ }
79
+
80
+ // getHardwareFingerprint().then(console.log);
81
+ // getHardwareFingerprintHash().then(console.log);
82
+ // getPublicHardwareFingerprint().then(console.log);
83
+
84
+ module.exports = {
85
+ getHardwareFingerprint,
86
+ getHardwareFingerprintHash,
87
+ getPublicHardwareFingerprint,
88
+ };