@hivedev/hivesdk 1.0.3
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/Client/Utility/DisableAllButtons.js +4 -0
- package/Client/Utility/GenerateUUID.js +23 -0
- package/Client/Utility/GetDeviceId.js +21 -0
- package/Client/Utility/IsInApp.js +4 -0
- package/Client/Utility/SetupAppUsage.js +65 -0
- package/Common/Constants.js +6 -0
- package/Common/Enumerations/AppWebViewInteractions.js +5 -0
- package/Common/Enumerations/ApprovalTypes.js +5 -0
- package/Common/Enumerations/FileTreeNodeTypes.js +5 -0
- package/Common/Enumerations/FilterOperators.js +5 -0
- package/Common/Enumerations/FilterTypes.js +6 -0
- package/Common/Enumerations/UserDataFetchFilterComparision.js +11 -0
- package/Common/Enumerations/UserFieldFormats.js +12 -0
- package/Common/Enumerations/UserFieldTypes.js +6 -0
- package/Common/Enumerations/UserPrivileges.js +12 -0
- package/Common/Utility/ConvertEnumerationKeyToTitleCase.js +8 -0
- package/Common/Utility/Delay.js +4 -0
- package/Common/Utility/ExtractIpFromUrl.js +18 -0
- package/Common/Utility/GenerateRandomId.js +12 -0
- package/Common/Utility/GetDirectoryName.js +8 -0
- package/Common/Utility/GetSha512Hash.js +6 -0
- package/Common/Utility/NormalizeIp.js +12 -0
- package/Common/Utility/Sha256.js +98 -0
- package/README.md +1 -0
- package/Server/Utility/DecryptDataWithPassword.js +13 -0
- package/Server/Utility/DecryptFileWithPassword.js +18 -0
- package/Server/Utility/EncryptDataWithPassword.js +12 -0
- package/Server/Utility/EncryptFileWithPassword.js +13 -0
- package/Server/Utility/ExtractConfigurationForService.js +11 -0
- package/Server/Utility/GetAppdataDirectory.js +16 -0
- package/Server/Utility/GetHostIp.js +19 -0
- package/Server/Utility/IsLocalRequest.js +21 -0
- package/Server/Utility/IsRequestOriginatingFromService.js +55 -0
- package/Server/Utility/LoadConfiguration.js +62 -0
- package/Server/Utility/PromptPassword.js +24 -0
- package/Server/Utility/SendMail.js +33 -0
- package/Server/Utility/SetupPassword.js +56 -0
- package/client.js +0 -0
- package/dist/server/index.js +11479 -0
- package/package.json +41 -0
- package/server.js +3 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function generateUUID()
|
|
2
|
+
{
|
|
3
|
+
let d = new Date().getTime();
|
|
4
|
+
let d2 = (performance && performance.now && (performance.now() * 1000)) || 0;
|
|
5
|
+
|
|
6
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c)
|
|
7
|
+
{
|
|
8
|
+
let r = Math.random() * 16;
|
|
9
|
+
|
|
10
|
+
if (d > 0)
|
|
11
|
+
{
|
|
12
|
+
r = (d + r) % 16 | 0;
|
|
13
|
+
d = Math.floor(d / 16);
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
{
|
|
17
|
+
r = (d2 + r) % 16 | 0;
|
|
18
|
+
d2 = Math.floor(d2 / 16);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sha256 } from "../../Common/Utility/Sha256.js";
|
|
2
|
+
import { generateUUID } from "./GenerateUUID.js";
|
|
3
|
+
|
|
4
|
+
export async function getDeviceId()
|
|
5
|
+
{
|
|
6
|
+
let uuid = localStorage.getItem("deviceId");
|
|
7
|
+
|
|
8
|
+
if (!uuid)
|
|
9
|
+
{
|
|
10
|
+
uuid = generateUUID();
|
|
11
|
+
localStorage.setItem("deviceId", uuid);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
15
|
+
const language = navigator.language;
|
|
16
|
+
const userAgent = navigator.userAgent;
|
|
17
|
+
|
|
18
|
+
const rawId = `${uuid}|${timezone}|${language}|${userAgent}`;
|
|
19
|
+
|
|
20
|
+
return sha256(rawId);
|
|
21
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { appWebViewInteractions } from "../../Common/Enumerations/AppWebViewInteractions.js";
|
|
2
|
+
import { isInApp } from "./IsInApp.js";
|
|
3
|
+
|
|
4
|
+
export function setupAppUsage()
|
|
5
|
+
{
|
|
6
|
+
document.cookie = "usesCookies=true; path=/";
|
|
7
|
+
|
|
8
|
+
if(isInApp())
|
|
9
|
+
{
|
|
10
|
+
window.fallbackOpen = window.open;
|
|
11
|
+
|
|
12
|
+
window.open = (url, name, features)=>
|
|
13
|
+
{
|
|
14
|
+
const iframe = document.createElement("iframe");
|
|
15
|
+
iframe.src = url;
|
|
16
|
+
iframe.style.position = "fixed";
|
|
17
|
+
iframe.style.display = "block";
|
|
18
|
+
iframe.style.height = "100vh";
|
|
19
|
+
iframe.style.width = "100vw";
|
|
20
|
+
iframe.style.top = "0px";
|
|
21
|
+
iframe.style.left = "0px";
|
|
22
|
+
iframe.style.border = "none";
|
|
23
|
+
iframe.style.zIndex = "10000"
|
|
24
|
+
document.body.appendChild(iframe);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
close: ()=>
|
|
28
|
+
{
|
|
29
|
+
iframe.remove();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
document.querySelectorAll("img").forEach(img =>
|
|
36
|
+
{
|
|
37
|
+
if(img.getAttribute("src") && !img.src.startsWith("http"))
|
|
38
|
+
{
|
|
39
|
+
img.src = new URL(img.getAttribute("src"), window.location.origin).href;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
window.addEventListener("message", (event)=>
|
|
44
|
+
{
|
|
45
|
+
try
|
|
46
|
+
{
|
|
47
|
+
|
|
48
|
+
const messageObject = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
49
|
+
|
|
50
|
+
switch(messageObject.interaction)
|
|
51
|
+
{
|
|
52
|
+
case appWebViewInteractions.BACK_PRESSED:
|
|
53
|
+
{
|
|
54
|
+
window.history.back();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
catch(error)
|
|
60
|
+
{
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { URL } from "url";
|
|
2
|
+
import dns from "dns/promises";
|
|
3
|
+
|
|
4
|
+
export async function extractIpFromUrl(httpUrl)
|
|
5
|
+
{
|
|
6
|
+
console.log("URL IS" + httpUrl);
|
|
7
|
+
console.log(httpUrl);
|
|
8
|
+
const parsed = new URL(httpUrl);
|
|
9
|
+
const hostname = parsed.hostname;
|
|
10
|
+
|
|
11
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname))
|
|
12
|
+
{
|
|
13
|
+
return hostname;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const addresses = await dns.lookup(hostname);
|
|
17
|
+
return addresses.address;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function generateRandomId(length)
|
|
2
|
+
{
|
|
3
|
+
const characters = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`;
|
|
4
|
+
let result = '';
|
|
5
|
+
|
|
6
|
+
for(let i = 0; i < length; i++)
|
|
7
|
+
{
|
|
8
|
+
result += characters[Math.floor(Math.random() * characters.length)]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Pure JS SHA-256 (no dependencies)
|
|
2
|
+
export function sha256(ascii)
|
|
3
|
+
{
|
|
4
|
+
function rightRotate(value, amount)
|
|
5
|
+
{
|
|
6
|
+
return (value >>> amount) | (value << (32 - amount));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var mathPow = Math.pow;
|
|
10
|
+
var maxWord = mathPow(2, 32);
|
|
11
|
+
var lengthProperty = "length";
|
|
12
|
+
var i, j;
|
|
13
|
+
var result = "";
|
|
14
|
+
|
|
15
|
+
var words = [];
|
|
16
|
+
var asciiBitLength = ascii[lengthProperty] * 8;
|
|
17
|
+
|
|
18
|
+
var hash = sha256.h = sha256.h || [];
|
|
19
|
+
var k = sha256.k = sha256.k || [];
|
|
20
|
+
var primeCounter = k[lengthProperty];
|
|
21
|
+
|
|
22
|
+
var isComposite = {};
|
|
23
|
+
for (var candidate = 2; primeCounter < 64; candidate++)
|
|
24
|
+
{
|
|
25
|
+
if (!isComposite[candidate])
|
|
26
|
+
{
|
|
27
|
+
for (i = 0; i < 313; i += candidate)
|
|
28
|
+
{
|
|
29
|
+
isComposite[i] = candidate;
|
|
30
|
+
}
|
|
31
|
+
hash[primeCounter] = (mathPow(candidate, 0.5) * maxWord) | 0;
|
|
32
|
+
k[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ascii += "\x80"; // Append '1' bit (plus zero padding)
|
|
37
|
+
while (ascii[lengthProperty] % 64 - 56)
|
|
38
|
+
{
|
|
39
|
+
ascii += "\x00";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (i = 0; i < ascii[lengthProperty]; i++)
|
|
43
|
+
{
|
|
44
|
+
j = ascii.charCodeAt(i);
|
|
45
|
+
if (j >> 8) return; // ASCII check
|
|
46
|
+
words[i >> 2] |= j << ((3 - i) % 4) * 8;
|
|
47
|
+
}
|
|
48
|
+
words[words[lengthProperty]] = ((asciiBitLength / maxWord) | 0);
|
|
49
|
+
words[words[lengthProperty]] = (asciiBitLength);
|
|
50
|
+
|
|
51
|
+
for (j = 0; j < words[lengthProperty];)
|
|
52
|
+
{
|
|
53
|
+
var w = words.slice(j, j += 16);
|
|
54
|
+
var oldHash = hash;
|
|
55
|
+
|
|
56
|
+
// This is now the "working hash", often labelled as variables a...g
|
|
57
|
+
hash = hash.slice(0, 8);
|
|
58
|
+
|
|
59
|
+
for (i = 0; i < 64; i++)
|
|
60
|
+
{
|
|
61
|
+
var w15 = w[i - 15], w2 = w[i - 2];
|
|
62
|
+
|
|
63
|
+
var a = hash[0], e = hash[4];
|
|
64
|
+
var temp1 = hash[7]
|
|
65
|
+
+ (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25))
|
|
66
|
+
+ ((e & hash[5]) ^ ((~e) & hash[6]))
|
|
67
|
+
+ k[i]
|
|
68
|
+
+ (w[i] = (i < 16) ? w[i] : (
|
|
69
|
+
w[i - 16]
|
|
70
|
+
+ (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15 >>> 3))
|
|
71
|
+
+ w[i - 7]
|
|
72
|
+
+ (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2 >>> 10))
|
|
73
|
+
) | 0
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22))
|
|
77
|
+
+ ((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2]));
|
|
78
|
+
|
|
79
|
+
hash = [(temp1 + temp2) | 0].concat(hash);
|
|
80
|
+
hash[4] = (hash[4] + temp1) | 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (i = 0; i < 8; i++)
|
|
84
|
+
{
|
|
85
|
+
hash[i] = (hash[i] + oldHash[i]) | 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (i = 0; i < 8; i++)
|
|
90
|
+
{
|
|
91
|
+
for (j = 3; j + 1; j--)
|
|
92
|
+
{
|
|
93
|
+
var b = (hash[i] >> (j * 8)) & 255;
|
|
94
|
+
result += ((b < 16) ? 0 : "") + b.toString(16);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
export async function decryptDataWithPassword(data, password)
|
|
4
|
+
{
|
|
5
|
+
const iv = data.subarray(0, 16);
|
|
6
|
+
const encrypted = data.subarray(16);
|
|
7
|
+
|
|
8
|
+
const key = crypto.scryptSync(password, "salt", 32);
|
|
9
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
10
|
+
|
|
11
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
12
|
+
return decrypted.toString("utf8");
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import { decryptDataWithPassword } from "./DecryptDataWithPassword.js";
|
|
4
|
+
|
|
5
|
+
export async function decryptFileWithPassword(fullPath, password)
|
|
6
|
+
{
|
|
7
|
+
const payload = await fs.readFile(fullPath);
|
|
8
|
+
|
|
9
|
+
try
|
|
10
|
+
{
|
|
11
|
+
return (await decryptDataWithPassword(payload, password));
|
|
12
|
+
}
|
|
13
|
+
catch(e)
|
|
14
|
+
{
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
export async function encryptDataWithPassword(data, password)
|
|
4
|
+
{
|
|
5
|
+
const key = crypto.scryptSync(password, "salt", 32);
|
|
6
|
+
const iv = crypto.randomBytes(16);
|
|
7
|
+
|
|
8
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
9
|
+
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
10
|
+
|
|
11
|
+
return Buffer.concat([iv, encrypted]);
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { encryptDataWithPassword } from "./EncryptDataWithPassword.js";
|
|
4
|
+
|
|
5
|
+
export async function encryptAndStoreFile(data, fullPath, password)
|
|
6
|
+
{
|
|
7
|
+
const payload = await encryptDataWithPassword(data, password);
|
|
8
|
+
|
|
9
|
+
const dir = path.dirname(fullPath);
|
|
10
|
+
await fs.mkdir(dir, { recursive: true });
|
|
11
|
+
await fs.writeFile(fullPath, payload);
|
|
12
|
+
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function extractConfigurationForService(serviceName)
|
|
2
|
+
{
|
|
3
|
+
const firebaseAdminCredentials = process.env.firebaseAdminCredentials? JSON.parse(process.env.firebaseAdminCredentials): null;
|
|
4
|
+
const databaseCredentials = process.env.databaseCredentials? JSON.parse(process.env.databaseCredentials): null;
|
|
5
|
+
const permissions = process.env.permissions? JSON.parse(process.env.permissions): null;
|
|
6
|
+
const smtpCredentials = process.env.smtpCredentials? JSON.parse(process.env.smtpCredentials): null;
|
|
7
|
+
|
|
8
|
+
const databaseCredentialsForService = databaseCredentials[serviceName]? databaseCredentials[serviceName]: null;
|
|
9
|
+
return { firebaseAdminCredentials: firebaseAdminCredentials, databaseCredentials: databaseCredentialsForService, permissions: permissions, smtpCredentials: smtpCredentials };
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
export function getAppDataDirectory()
|
|
5
|
+
{
|
|
6
|
+
const baseDir = process.env.APPDATA ||
|
|
7
|
+
(process.platform === "darwin"
|
|
8
|
+
? path.join(process.env.HOME, "Library", "Application Support")
|
|
9
|
+
: path.join(process.env.HOME, ".config"));
|
|
10
|
+
|
|
11
|
+
const hiveDir = path.join(baseDir, "Hive");
|
|
12
|
+
|
|
13
|
+
fs.mkdirSync(hiveDir, { recursive: true });
|
|
14
|
+
|
|
15
|
+
return hiveDir.replace(/\\/g, "/");
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
|
|
3
|
+
export function getHostIp()
|
|
4
|
+
{
|
|
5
|
+
const interfaces = os.networkInterfaces();
|
|
6
|
+
|
|
7
|
+
for (const devName in interfaces)
|
|
8
|
+
{
|
|
9
|
+
const iface = interfaces[devName];
|
|
10
|
+
for (let i = 0; i < iface.length; i++)
|
|
11
|
+
{
|
|
12
|
+
const alias = iface[i];
|
|
13
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal)
|
|
14
|
+
{
|
|
15
|
+
return alias.address;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
|
|
3
|
+
export function isLocalRequest(request)
|
|
4
|
+
{
|
|
5
|
+
const ip = request.ip || request.connection.remoteAddress || request.socket.remoteAddress;
|
|
6
|
+
|
|
7
|
+
const localAddresses = new Set(["127.0.0.1", "::1"]);
|
|
8
|
+
|
|
9
|
+
for (const iface of Object.values(os.networkInterfaces()))
|
|
10
|
+
{
|
|
11
|
+
for (const net of iface || [])
|
|
12
|
+
{
|
|
13
|
+
if (!net.internal)
|
|
14
|
+
{
|
|
15
|
+
localAddresses.add(net.address);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return localAddresses.has(ip);
|
|
21
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import url from "url";
|
|
2
|
+
import { normalizeIp } from "../../Common/Utility/NormalizeIp.js";
|
|
3
|
+
import DatabaseQueryEngine from "../../Database/DatabaseQueryEngine.js";
|
|
4
|
+
import { extractIpFromUrl } from "../../Common/Utility/ExtractIpFromUrl.js";
|
|
5
|
+
|
|
6
|
+
export async function isRequestOriginatingFromService(request)
|
|
7
|
+
{
|
|
8
|
+
const serviceUrls = await DatabaseQueryEngine.getServiceUrls(null);
|
|
9
|
+
|
|
10
|
+
if (!serviceUrls || serviceUrls.length === 0)
|
|
11
|
+
{
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const ip = request.ip || request.connection.remoteAddress || request.socket.remoteAddress;
|
|
16
|
+
|
|
17
|
+
const normalizedIp = normalizeIp(ip);
|
|
18
|
+
|
|
19
|
+
for (const service of serviceUrls)
|
|
20
|
+
{
|
|
21
|
+
for (const key of ["local", "remote"])
|
|
22
|
+
{
|
|
23
|
+
console.log(service);
|
|
24
|
+
console.log(key);
|
|
25
|
+
console.log(service.urls[key]);
|
|
26
|
+
|
|
27
|
+
try
|
|
28
|
+
{
|
|
29
|
+
const serviceUrl = await extractIpFromUrl(service.urls[key]);
|
|
30
|
+
}
|
|
31
|
+
catch(err)
|
|
32
|
+
{
|
|
33
|
+
console.log("ERROR");
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const serviceUrl = await extractIpFromUrl(service.urls[key]);
|
|
38
|
+
if (!serviceUrl) continue;
|
|
39
|
+
|
|
40
|
+
const normalizedServiceUrl = normalizeIp(serviceUrl);
|
|
41
|
+
|
|
42
|
+
console.log(normalizedIp);
|
|
43
|
+
console.log(normalizedServiceUrl);
|
|
44
|
+
|
|
45
|
+
console.log("____")
|
|
46
|
+
|
|
47
|
+
if (normalizedIp === normalizedServiceUrl)
|
|
48
|
+
{
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { decryptFileWithPassword } from "./DecryptFileWithPassword.js";
|
|
2
|
+
import { getHiveAppDataDirectory } from "./GetHiveAppdataDirectory.js";
|
|
3
|
+
import DatabaseConnector from "../../Database/DatabaseConnector.js";
|
|
4
|
+
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
|
|
8
|
+
export async function loadConfiguration()
|
|
9
|
+
{
|
|
10
|
+
let firebaseAdminCredentials = "";
|
|
11
|
+
let databaseCredentials = "";
|
|
12
|
+
let permissions = "";
|
|
13
|
+
let smtpCredentials = "";
|
|
14
|
+
|
|
15
|
+
const firebaseAdminCredentialsPath = path.join(getHiveAppDataDirectory(), "firebase_admin_credentials.dat");
|
|
16
|
+
const databaseCredentialsPath = path.join(getHiveAppDataDirectory(), "database_credentials.dat");
|
|
17
|
+
const permissionsPath = path.join(getHiveAppDataDirectory(), "permissions.dat");
|
|
18
|
+
const smtpCredentialsPath = path.join(getHiveAppDataDirectory(), "smtp_credentials.dat");
|
|
19
|
+
|
|
20
|
+
if(fs.existsSync(firebaseAdminCredentialsPath))
|
|
21
|
+
{
|
|
22
|
+
firebaseAdminCredentials = await decryptFileWithPassword(path.join(getHiveAppDataDirectory(), "firebase_admin_credentials.dat"), process.env.serverPassword);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if(fs.existsSync(databaseCredentialsPath))
|
|
26
|
+
{
|
|
27
|
+
databaseCredentials = await decryptFileWithPassword(path.join(getHiveAppDataDirectory(), "database_credentials.dat"), process.env.serverPassword);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if(fs.existsSync(permissionsPath))
|
|
31
|
+
{
|
|
32
|
+
permissions = await decryptFileWithPassword(path.join(getHiveAppDataDirectory(), "permissions.dat"), process.env.serverPassword);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if(fs.existsSync(smtpCredentialsPath))
|
|
36
|
+
{
|
|
37
|
+
smtpCredentials = await decryptFileWithPassword(path.join(getHiveAppDataDirectory(), "smtp_credentials.dat"), process.env.serverPassword);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
process.env.firebaseAdminCredentials = firebaseAdminCredentials;
|
|
41
|
+
process.env.databaseCredentials = databaseCredentials;
|
|
42
|
+
process.env.permissions = permissions;
|
|
43
|
+
process.env.smtpCredentials = smtpCredentials;
|
|
44
|
+
|
|
45
|
+
if(databaseCredentials)
|
|
46
|
+
{
|
|
47
|
+
databaseCredentials = JSON.parse(databaseCredentials);
|
|
48
|
+
|
|
49
|
+
const hivePortalDatabaseCredentials = databaseCredentials["HivePortal"];
|
|
50
|
+
DatabaseConnector.setCredentials
|
|
51
|
+
(
|
|
52
|
+
{
|
|
53
|
+
host: hivePortalDatabaseCredentials.host || "127.0.0.1",
|
|
54
|
+
username: hivePortalDatabaseCredentials.username || "",
|
|
55
|
+
password: hivePortalDatabaseCredentials.password || "",
|
|
56
|
+
name: hivePortalDatabaseCredentials.name || "hive"
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//This is not my code, it is chatgpt code please do not complain readbility
|
|
2
|
+
import readline from "readline";
|
|
3
|
+
|
|
4
|
+
export async function promptPassword(promptText = "Enter password: ")
|
|
5
|
+
{
|
|
6
|
+
return new Promise((resolve) =>
|
|
7
|
+
{
|
|
8
|
+
const rl = readline.createInterface(
|
|
9
|
+
{
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
rl.question(promptText, (answer) =>
|
|
15
|
+
{
|
|
16
|
+
rl.close();
|
|
17
|
+
process.stdout.write("\n");
|
|
18
|
+
resolve(answer);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
rl._writeToOutput = () => {};
|
|
23
|
+
});
|
|
24
|
+
}
|