mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
hardware fingerprint
This commit is contained in:
parent
a256acb203
commit
787d6596bf
@ -16,6 +16,7 @@ const { getAuthProviderFromReq } = require('../auth/authProvider');
|
||||
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
|
||||
const storage = require('./storage');
|
||||
const { getAuthProxyUrl } = require('../utility/authProxy');
|
||||
const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
|
||||
|
||||
const lock = new AsyncLock();
|
||||
|
||||
@ -188,12 +189,12 @@ module.exports = {
|
||||
startTrial_meta: true,
|
||||
async startTrial() {
|
||||
try {
|
||||
const ipResp = await axios.default.get('https://api.ipify.org?format=json');
|
||||
const fingerprint = await getPublicHardwareFingerprint();
|
||||
|
||||
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, {
|
||||
type: 'premium-trial',
|
||||
days: 30,
|
||||
publicIp: ipResp.data.ip,
|
||||
fingerprint,
|
||||
});
|
||||
const { token } = resp.data;
|
||||
|
||||
|
72
packages/api/src/utility/hardwareFingerprint.js
Normal file
72
packages/api/src/utility/hardwareFingerprint.js
Normal file
@ -0,0 +1,72 @@
|
||||
const axios = require('axios');
|
||||
const os = require('os');
|
||||
const crypto = require('crypto');
|
||||
|
||||
async function getPublicIp() {
|
||||
try {
|
||||
const resp = await axios.default.get('https://api.ipify.org?format=json');
|
||||
return resp.data.ip || 'unknown-ip';
|
||||
} catch (err) {
|
||||
return 'unknown-ip';
|
||||
}
|
||||
}
|
||||
|
||||
function getMacAddress() {
|
||||
const interfaces = os.networkInterfaces();
|
||||
for (let iface of Object.values(interfaces)) {
|
||||
for (let config of iface) {
|
||||
if (config.mac && config.mac !== '00:00:00:00:00:00') {
|
||||
return config.mac;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '00:00:00:00:00:00';
|
||||
}
|
||||
|
||||
async function getHardwareFingerprint() {
|
||||
const publicIp = await getPublicIp();
|
||||
const macAddress = getMacAddress();
|
||||
const platform = os.platform();
|
||||
const release = os.release();
|
||||
const hostname = os.hostname();
|
||||
const totalMemory = os.totalmem();
|
||||
|
||||
return {
|
||||
publicIp,
|
||||
macAddress,
|
||||
platform,
|
||||
release,
|
||||
hostname,
|
||||
totalMemory,
|
||||
};
|
||||
}
|
||||
|
||||
async function getHardwareFingerprintHash(data = undefined) {
|
||||
if (!data) {
|
||||
data = await getHardwareFingerprint();
|
||||
}
|
||||
const fingerprintData = JSON.stringify(data);
|
||||
const hash = crypto.createHash('sha256').update(fingerprintData).digest('hex');
|
||||
return hash;
|
||||
}
|
||||
|
||||
async function getPublicHardwareFingerprint() {
|
||||
const fingerprint = await getHardwareFingerprint();
|
||||
const hash = await getHardwareFingerprintHash(fingerprint);
|
||||
return {
|
||||
hash,
|
||||
payload: {
|
||||
platform: fingerprint.platform,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// getHardwareFingerprint().then(console.log);
|
||||
// getHardwareFingerprintHash().then(console.log);
|
||||
// getPublicHardwareFingerprint().then(console.log);
|
||||
|
||||
module.exports = {
|
||||
getHardwareFingerprint,
|
||||
getHardwareFingerprintHash,
|
||||
getPublicHardwareFingerprint,
|
||||
};
|
Loading…
Reference in New Issue
Block a user