@yobytechautomation/config-lib 0.3.0 → 0.3.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.
|
@@ -41,15 +41,16 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const os = __importStar(require("os"));
|
|
44
|
+
const crypto = __importStar(require("crypto"));
|
|
44
45
|
class BaseConfigServiceImpl {
|
|
45
46
|
constructor() {
|
|
46
47
|
this.env = process.env;
|
|
47
48
|
this.checkIntegrity();
|
|
48
49
|
}
|
|
49
50
|
checkIntegrity() {
|
|
50
|
-
const fileContent = fs.readFileSync(__filename,
|
|
51
|
-
if (!fileContent.includes(
|
|
52
|
-
console.error(
|
|
51
|
+
const fileContent = fs.readFileSync(__filename, "utf-8");
|
|
52
|
+
if (!fileContent.includes("validateLicenseOrThrow")) {
|
|
53
|
+
console.error("❌ License system tampered");
|
|
53
54
|
process.exit(1);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -57,65 +58,71 @@ class BaseConfigServiceImpl {
|
|
|
57
58
|
setInterval(async () => {
|
|
58
59
|
try {
|
|
59
60
|
await this.validateLicenseOrThrow();
|
|
60
|
-
console.log(
|
|
61
|
+
console.log("💓 License heartbeat OK");
|
|
61
62
|
}
|
|
62
63
|
catch (err) {
|
|
63
|
-
console.error(
|
|
64
|
+
console.error("💀 License revoked during runtime");
|
|
64
65
|
process.exit(1);
|
|
65
66
|
}
|
|
66
67
|
}, 5 * 60 * 1000);
|
|
67
68
|
}
|
|
68
69
|
getDatabaseConfig() {
|
|
69
|
-
throw new Error(
|
|
70
|
+
throw new Error("Method not implemented.");
|
|
70
71
|
}
|
|
71
72
|
getPort() {
|
|
72
|
-
throw new Error(
|
|
73
|
+
throw new Error("Method not implemented.");
|
|
73
74
|
}
|
|
74
75
|
getMode() {
|
|
75
|
-
throw new Error(
|
|
76
|
+
throw new Error("Method not implemented.");
|
|
76
77
|
}
|
|
77
78
|
getConsulConfig() {
|
|
78
|
-
throw new Error(
|
|
79
|
+
throw new Error("Method not implemented.");
|
|
79
80
|
}
|
|
80
81
|
getRedisConfig() {
|
|
81
|
-
throw new Error(
|
|
82
|
+
throw new Error("Method not implemented.");
|
|
82
83
|
}
|
|
83
84
|
getJWTConfig() {
|
|
84
|
-
throw new Error(
|
|
85
|
+
throw new Error("Method not implemented.");
|
|
85
86
|
}
|
|
86
87
|
getJUtilConfig() {
|
|
87
|
-
throw new Error(
|
|
88
|
+
throw new Error("Method not implemented.");
|
|
88
89
|
}
|
|
89
90
|
getMailConfig() {
|
|
90
|
-
throw new Error(
|
|
91
|
+
throw new Error("Method not implemented.");
|
|
91
92
|
}
|
|
92
93
|
getKAFKAConfig() {
|
|
93
|
-
throw new Error(
|
|
94
|
+
throw new Error("Method not implemented.");
|
|
94
95
|
}
|
|
95
96
|
async validateLicenseOrThrow() {
|
|
96
97
|
var _a, _b, _c;
|
|
97
|
-
const cachePath = path.join(process.cwd(),
|
|
98
|
+
const cachePath = path.join(process.cwd(), ".license-cache.json");
|
|
98
99
|
const apiKey = this.env.LICENSE_KEY;
|
|
99
100
|
if (!apiKey) {
|
|
100
|
-
throw new Error(
|
|
101
|
+
throw new Error("LICENSE_KEY missing");
|
|
101
102
|
}
|
|
102
103
|
try {
|
|
103
|
-
const part1 =
|
|
104
|
-
const part2 =
|
|
105
|
-
const part3 =
|
|
106
|
-
const url = Buffer.from(part1 + part2 + part3,
|
|
104
|
+
const part1 = "aHR0cHM6Ly9kZXYu";
|
|
105
|
+
const part2 = "d2F0ZXJhdXRvLnlvYnl0ZWNo";
|
|
106
|
+
const part3 = "LmluL2xpY2Vuc2UvY2hlY2s=";
|
|
107
|
+
const url = Buffer.from(part1 + part2 + part3, "base64").toString("utf-8");
|
|
107
108
|
const secret = process.env.LICENSE_SECRET;
|
|
108
109
|
const machineId = os.hostname();
|
|
110
|
+
const signature = crypto
|
|
111
|
+
.createHmac("sha256", secret)
|
|
112
|
+
.update(apiKey + machineId)
|
|
113
|
+
.digest("hex");
|
|
114
|
+
console.log('DEBUG SIGNATURE:', signature);
|
|
109
115
|
const res = await axios_1.default.get(url, {
|
|
110
116
|
headers: {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
"x-api-key": apiKey,
|
|
118
|
+
"x-license-secret": secret,
|
|
119
|
+
"x-machine-id": machineId,
|
|
120
|
+
'x-signature': signature,
|
|
114
121
|
},
|
|
115
122
|
timeout: 5000,
|
|
116
123
|
});
|
|
117
124
|
const status = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
118
|
-
if (status !==
|
|
125
|
+
if (status !== "active") {
|
|
119
126
|
throw new Error(`License ${status}. Please contact vendor.`);
|
|
120
127
|
}
|
|
121
128
|
const machineId2 = os.hostname();
|
|
@@ -123,7 +130,7 @@ class BaseConfigServiceImpl {
|
|
|
123
130
|
lastValidated: new Date().toISOString(),
|
|
124
131
|
machineId: machineId2,
|
|
125
132
|
}));
|
|
126
|
-
console.log(
|
|
133
|
+
console.log("✅ License validated (online)");
|
|
127
134
|
}
|
|
128
135
|
catch (err) {
|
|
129
136
|
const errorMsg = (_c = (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.status;
|
|
@@ -132,25 +139,26 @@ class BaseConfigServiceImpl {
|
|
|
132
139
|
throw new Error(`License ${errorMsg}. Please contact vendor.`);
|
|
133
140
|
}
|
|
134
141
|
// 🔥 CASE 2 — SERVER NOT REACHABLE
|
|
135
|
-
console.error(
|
|
142
|
+
console.error("❌ License server unreachable");
|
|
136
143
|
// ⚠️ OPTIONAL STRICT CACHE (VERY LIMITED USE)
|
|
137
144
|
const ALLOW_OFFLINE = false; // 🔥 set FALSE for production
|
|
138
145
|
if (ALLOW_OFFLINE && fs.existsSync(cachePath)) {
|
|
139
|
-
const data = JSON.parse(fs.readFileSync(cachePath,
|
|
146
|
+
const data = JSON.parse(fs.readFileSync(cachePath, "utf-8"));
|
|
140
147
|
if (data.machineId !== os.hostname()) {
|
|
141
|
-
throw new Error(
|
|
148
|
+
throw new Error("License cache copied from another machine");
|
|
142
149
|
}
|
|
143
150
|
const last = new Date(data.lastValidated);
|
|
144
151
|
const now = new Date();
|
|
145
152
|
const diffMinutes = (now.getTime() - last.getTime()) / (1000 * 60);
|
|
146
|
-
if (diffMinutes <= 5) {
|
|
147
|
-
|
|
153
|
+
if (diffMinutes <= 5) {
|
|
154
|
+
// max 5 minutes only
|
|
155
|
+
console.log("⚠️ Temporary offline mode (5 min)");
|
|
148
156
|
return;
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
|
-
throw new Error(
|
|
159
|
+
throw new Error("License server unreachable. App blocked.");
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
}
|
|
155
163
|
exports.BaseConfigServiceImpl = BaseConfigServiceImpl;
|
|
156
|
-
exports.BASE_CONFIG_SERVICE = Symbol(
|
|
164
|
+
exports.BASE_CONFIG_SERVICE = Symbol("BASE_CONFIG_SERVICE");
|