strapi-plugin-magic-mail 2.2.0 → 2.2.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/README.md +2 -0
- package/dist/server/index.js +431 -353
- package/dist/server/index.mjs +431 -353
- package/package.json +1 -1
- package/server/src/bootstrap.js +36 -32
- package/server/src/config/index.js +4 -1
- package/server/src/destroy.js +8 -4
- package/server/src/services/license-guard.js +44 -39
- package/server/src/utils/logger.js +84 -0
package/dist/server/index.mjs
CHANGED
|
@@ -17,29 +17,98 @@ function requireRegister() {
|
|
|
17
17
|
};
|
|
18
18
|
return register;
|
|
19
19
|
}
|
|
20
|
+
var logger;
|
|
21
|
+
var hasRequiredLogger;
|
|
22
|
+
function requireLogger() {
|
|
23
|
+
if (hasRequiredLogger) return logger;
|
|
24
|
+
hasRequiredLogger = 1;
|
|
25
|
+
const PLUGIN_NAME = "magic-mail";
|
|
26
|
+
const PREFIX = "[magic-mail]";
|
|
27
|
+
function formatMessage(prefix, args) {
|
|
28
|
+
if (args.length === 0) return prefix;
|
|
29
|
+
const parts = args.map(
|
|
30
|
+
(arg) => typeof arg === "string" ? arg : JSON.stringify(arg)
|
|
31
|
+
);
|
|
32
|
+
return `${prefix} ${parts.join(" ")}`;
|
|
33
|
+
}
|
|
34
|
+
function createLogger(strapi2) {
|
|
35
|
+
const getDebugMode = () => {
|
|
36
|
+
try {
|
|
37
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_NAME}`) || {};
|
|
38
|
+
return config2.debug === true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
/**
|
|
45
|
+
* Log info - only when debug: true
|
|
46
|
+
*/
|
|
47
|
+
info: (...args) => {
|
|
48
|
+
if (getDebugMode()) {
|
|
49
|
+
strapi2.log.info(formatMessage(PREFIX, args));
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Log debug - only when debug: true
|
|
54
|
+
*/
|
|
55
|
+
debug: (...args) => {
|
|
56
|
+
if (getDebugMode()) {
|
|
57
|
+
strapi2.log.debug(formatMessage(PREFIX, args));
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Log warning - only when debug: true
|
|
62
|
+
*/
|
|
63
|
+
warn: (...args) => {
|
|
64
|
+
if (getDebugMode()) {
|
|
65
|
+
strapi2.log.warn(formatMessage(PREFIX, args));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Log error - only when debug: true
|
|
70
|
+
*/
|
|
71
|
+
error: (...args) => {
|
|
72
|
+
if (getDebugMode()) {
|
|
73
|
+
strapi2.log.error(formatMessage(PREFIX, args));
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Force log - always logged (for critical errors only)
|
|
78
|
+
*/
|
|
79
|
+
forceError: (...args) => {
|
|
80
|
+
strapi2.log.error(formatMessage(PREFIX, args));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
logger = { createLogger };
|
|
85
|
+
return logger;
|
|
86
|
+
}
|
|
20
87
|
var bootstrap;
|
|
21
88
|
var hasRequiredBootstrap;
|
|
22
89
|
function requireBootstrap() {
|
|
23
90
|
if (hasRequiredBootstrap) return bootstrap;
|
|
24
91
|
hasRequiredBootstrap = 1;
|
|
92
|
+
const { createLogger } = requireLogger();
|
|
25
93
|
bootstrap = async ({ strapi: strapi2 }) => {
|
|
26
|
-
|
|
94
|
+
const log = createLogger(strapi2);
|
|
95
|
+
log.info("[BOOTSTRAP] Starting...");
|
|
27
96
|
try {
|
|
28
97
|
const licenseGuardService = strapi2.plugin("magic-mail").service("license-guard");
|
|
29
98
|
setTimeout(async () => {
|
|
30
99
|
const licenseStatus = await licenseGuardService.initialize();
|
|
31
100
|
if (!licenseStatus.valid && licenseStatus.demo) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
101
|
+
log.error("╔════════════════════════════════════════════════════════════════╗");
|
|
102
|
+
log.error("║ [ERROR] MAGICMAIL - NO VALID LICENSE ║");
|
|
103
|
+
log.error("║ ║");
|
|
104
|
+
log.error("║ This plugin requires a valid license to operate. ║");
|
|
105
|
+
log.error("║ Please activate your license via Admin UI: ║");
|
|
106
|
+
log.error("║ Go to MagicMail → License tab ║");
|
|
107
|
+
log.error("║ ║");
|
|
108
|
+
log.error('║ Click "Generate Free License" to get started! ║');
|
|
109
|
+
log.error("╚════════════════════════════════════════════════════════════════╝");
|
|
41
110
|
} else if (licenseStatus.gracePeriod) {
|
|
42
|
-
|
|
111
|
+
log.warn("[WARNING] Running on grace period (license server unreachable)");
|
|
43
112
|
}
|
|
44
113
|
}, 2e3);
|
|
45
114
|
const accountManager2 = strapi2.plugin("magic-mail").service("account-manager");
|
|
@@ -48,8 +117,8 @@ function requireBootstrap() {
|
|
|
48
117
|
if (originalEmailService && originalEmailService.send) {
|
|
49
118
|
const originalSend = originalEmailService.send.bind(originalEmailService);
|
|
50
119
|
originalEmailService.send = async (emailData) => {
|
|
51
|
-
|
|
52
|
-
|
|
120
|
+
log.info("[EMAIL] Intercepted from native Strapi service");
|
|
121
|
+
log.debug("Email data:", {
|
|
53
122
|
to: emailData.to,
|
|
54
123
|
subject: emailData.subject,
|
|
55
124
|
templateId: emailData.templateId,
|
|
@@ -61,31 +130,31 @@ function requireBootstrap() {
|
|
|
61
130
|
emailData.templateData = emailData.data;
|
|
62
131
|
}
|
|
63
132
|
const result = await emailRouter2.send(emailData);
|
|
64
|
-
|
|
133
|
+
log.info("[SUCCESS] Email routed successfully through MagicMail");
|
|
65
134
|
return result;
|
|
66
135
|
} catch (magicMailError) {
|
|
67
|
-
|
|
68
|
-
|
|
136
|
+
log.warn("[WARNING] MagicMail routing failed, falling back to original service");
|
|
137
|
+
log.error("Error:", magicMailError.message);
|
|
69
138
|
return await originalSend(emailData);
|
|
70
139
|
}
|
|
71
140
|
};
|
|
72
|
-
|
|
73
|
-
|
|
141
|
+
log.info("[SUCCESS] Native email service overridden!");
|
|
142
|
+
log.info("[INFO] All strapi.plugins.email.services.email.send() calls will route through MagicMail");
|
|
74
143
|
} else {
|
|
75
|
-
|
|
76
|
-
|
|
144
|
+
log.warn("[WARNING] Native email service not found - MagicMail will work standalone");
|
|
145
|
+
log.warn("[INFO] Make sure @strapi/plugin-email is installed");
|
|
77
146
|
}
|
|
78
147
|
const hourlyResetInterval = setInterval(async () => {
|
|
79
148
|
try {
|
|
80
149
|
if (!strapi2 || !strapi2.plugin) {
|
|
81
|
-
console.warn("
|
|
150
|
+
console.warn("Strapi not available for hourly reset");
|
|
82
151
|
return;
|
|
83
152
|
}
|
|
84
153
|
const accountMgr = strapi2.plugin("magic-mail").service("account-manager");
|
|
85
154
|
await accountMgr.resetCounters("hourly");
|
|
86
|
-
|
|
155
|
+
log.info("[RESET] Hourly counters reset");
|
|
87
156
|
} catch (err) {
|
|
88
|
-
console.error("
|
|
157
|
+
console.error("Hourly reset error:", err.message);
|
|
89
158
|
}
|
|
90
159
|
}, 60 * 60 * 1e3);
|
|
91
160
|
if (!commonjsGlobal.magicMailIntervals) commonjsGlobal.magicMailIntervals = {};
|
|
@@ -96,34 +165,34 @@ function requireBootstrap() {
|
|
|
96
165
|
setTimeout(async () => {
|
|
97
166
|
try {
|
|
98
167
|
if (!strapi2 || !strapi2.plugin) {
|
|
99
|
-
console.warn("
|
|
168
|
+
console.warn("Strapi not available for daily reset");
|
|
100
169
|
return;
|
|
101
170
|
}
|
|
102
171
|
const accountMgr = strapi2.plugin("magic-mail").service("account-manager");
|
|
103
172
|
await accountMgr.resetCounters("daily");
|
|
104
|
-
|
|
173
|
+
log.info("[RESET] Daily counters reset");
|
|
105
174
|
const dailyResetInterval = setInterval(async () => {
|
|
106
175
|
try {
|
|
107
176
|
if (!strapi2 || !strapi2.plugin) {
|
|
108
|
-
console.warn("
|
|
177
|
+
console.warn("Strapi not available for daily reset");
|
|
109
178
|
return;
|
|
110
179
|
}
|
|
111
180
|
const accountMgr2 = strapi2.plugin("magic-mail").service("account-manager");
|
|
112
181
|
await accountMgr2.resetCounters("daily");
|
|
113
|
-
|
|
182
|
+
log.info("[RESET] Daily counters reset");
|
|
114
183
|
} catch (err) {
|
|
115
|
-
console.error("
|
|
184
|
+
console.error("Daily reset error:", err.message);
|
|
116
185
|
}
|
|
117
186
|
}, 24 * 60 * 60 * 1e3);
|
|
118
187
|
commonjsGlobal.magicMailIntervals.daily = dailyResetInterval;
|
|
119
188
|
} catch (err) {
|
|
120
|
-
console.error("
|
|
189
|
+
console.error("Initial daily reset error:", err.message);
|
|
121
190
|
}
|
|
122
191
|
}, msUntilMidnight);
|
|
123
|
-
|
|
124
|
-
|
|
192
|
+
log.info("[SUCCESS] Counter reset schedules initialized");
|
|
193
|
+
log.info("[SUCCESS] Bootstrap complete");
|
|
125
194
|
} catch (err) {
|
|
126
|
-
|
|
195
|
+
log.error("[ERROR] Bootstrap error:", err);
|
|
127
196
|
}
|
|
128
197
|
};
|
|
129
198
|
return bootstrap;
|
|
@@ -133,22 +202,24 @@ var hasRequiredDestroy;
|
|
|
133
202
|
function requireDestroy() {
|
|
134
203
|
if (hasRequiredDestroy) return destroy;
|
|
135
204
|
hasRequiredDestroy = 1;
|
|
205
|
+
const { createLogger } = requireLogger();
|
|
136
206
|
destroy = ({ strapi: strapi2 }) => {
|
|
207
|
+
const log = createLogger(strapi2);
|
|
137
208
|
if (commonjsGlobal.magicMailIntervals) {
|
|
138
209
|
if (commonjsGlobal.magicMailIntervals.hourly) {
|
|
139
210
|
clearInterval(commonjsGlobal.magicMailIntervals.hourly);
|
|
140
|
-
|
|
211
|
+
log.info("Cleared hourly reset interval");
|
|
141
212
|
}
|
|
142
213
|
if (commonjsGlobal.magicMailIntervals.daily) {
|
|
143
214
|
clearInterval(commonjsGlobal.magicMailIntervals.daily);
|
|
144
|
-
|
|
215
|
+
log.info("Cleared daily reset interval");
|
|
145
216
|
}
|
|
146
217
|
}
|
|
147
218
|
if (strapi2.licenseGuardMagicMail && strapi2.licenseGuardMagicMail.pingInterval) {
|
|
148
219
|
clearInterval(strapi2.licenseGuardMagicMail.pingInterval);
|
|
149
|
-
|
|
220
|
+
log.info("Cleared license ping interval");
|
|
150
221
|
}
|
|
151
|
-
|
|
222
|
+
log.info("👋 Plugin destroyed gracefully");
|
|
152
223
|
};
|
|
153
224
|
return destroy;
|
|
154
225
|
}
|
|
@@ -158,7 +229,10 @@ function requireConfig() {
|
|
|
158
229
|
if (hasRequiredConfig) return config;
|
|
159
230
|
hasRequiredConfig = 1;
|
|
160
231
|
config = {
|
|
161
|
-
default: {
|
|
232
|
+
default: {
|
|
233
|
+
// Enable debug logging (set to true to see all plugin logs)
|
|
234
|
+
debug: false
|
|
235
|
+
},
|
|
162
236
|
validator() {
|
|
163
237
|
}
|
|
164
238
|
};
|
|
@@ -4788,7 +4862,7 @@ function requireOauth() {
|
|
|
4788
4862
|
});
|
|
4789
4863
|
return oauth;
|
|
4790
4864
|
}
|
|
4791
|
-
const version = "2.1
|
|
4865
|
+
const version = "2.2.1";
|
|
4792
4866
|
const require$$2 = {
|
|
4793
4867
|
version
|
|
4794
4868
|
};
|
|
@@ -4800,352 +4874,356 @@ function requireLicenseGuard() {
|
|
|
4800
4874
|
const crypto = require$$0$1;
|
|
4801
4875
|
const os = require$$1$1;
|
|
4802
4876
|
const pluginPkg = require$$2;
|
|
4877
|
+
const { createLogger } = requireLogger();
|
|
4803
4878
|
const LICENSE_SERVER_URL = "https://magicapi.fitlex.me";
|
|
4804
|
-
licenseGuard = ({ strapi: strapi2 }) =>
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4879
|
+
licenseGuard = ({ strapi: strapi2 }) => {
|
|
4880
|
+
const log = createLogger(strapi2);
|
|
4881
|
+
return {
|
|
4882
|
+
/**
|
|
4883
|
+
* Get license server URL
|
|
4884
|
+
*/
|
|
4885
|
+
getLicenseServerUrl() {
|
|
4886
|
+
return LICENSE_SERVER_URL;
|
|
4887
|
+
},
|
|
4888
|
+
/**
|
|
4889
|
+
* Generate device ID
|
|
4890
|
+
*/
|
|
4891
|
+
generateDeviceId() {
|
|
4892
|
+
try {
|
|
4893
|
+
const networkInterfaces = os.networkInterfaces();
|
|
4894
|
+
const macAddresses = [];
|
|
4895
|
+
Object.values(networkInterfaces).forEach((interfaces) => {
|
|
4896
|
+
interfaces?.forEach((iface) => {
|
|
4897
|
+
if (iface.mac && iface.mac !== "00:00:00:00:00:00") {
|
|
4898
|
+
macAddresses.push(iface.mac);
|
|
4899
|
+
}
|
|
4900
|
+
});
|
|
4823
4901
|
});
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
}
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
}
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4902
|
+
const identifier = `${macAddresses.join("-")}-${os.hostname()}`;
|
|
4903
|
+
return crypto.createHash("sha256").update(identifier).digest("hex").substring(0, 32);
|
|
4904
|
+
} catch (error) {
|
|
4905
|
+
return crypto.randomBytes(16).toString("hex");
|
|
4906
|
+
}
|
|
4907
|
+
},
|
|
4908
|
+
getDeviceName() {
|
|
4909
|
+
try {
|
|
4910
|
+
return os.hostname() || "Unknown Device";
|
|
4911
|
+
} catch (error) {
|
|
4912
|
+
return "Unknown Device";
|
|
4913
|
+
}
|
|
4914
|
+
},
|
|
4915
|
+
getIpAddress() {
|
|
4916
|
+
try {
|
|
4917
|
+
const networkInterfaces = os.networkInterfaces();
|
|
4918
|
+
for (const name of Object.keys(networkInterfaces)) {
|
|
4919
|
+
const interfaces = networkInterfaces[name];
|
|
4920
|
+
if (interfaces) {
|
|
4921
|
+
for (const iface of interfaces) {
|
|
4922
|
+
if (iface.family === "IPv4" && !iface.internal) {
|
|
4923
|
+
return iface.address;
|
|
4924
|
+
}
|
|
4847
4925
|
}
|
|
4848
4926
|
}
|
|
4849
4927
|
}
|
|
4928
|
+
return "127.0.0.1";
|
|
4929
|
+
} catch (error) {
|
|
4930
|
+
return "127.0.0.1";
|
|
4850
4931
|
}
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
}
|
|
4888
|
-
|
|
4932
|
+
},
|
|
4933
|
+
getUserAgent() {
|
|
4934
|
+
const pluginVersion = pluginPkg.version;
|
|
4935
|
+
const strapiVersion = strapi2.config.get("info.strapi") || "5.0.0";
|
|
4936
|
+
return `MagicMail/${pluginVersion} Strapi/${strapiVersion} Node/${process.version} ${os.platform()}/${os.release()}`;
|
|
4937
|
+
},
|
|
4938
|
+
async createLicense({ email, firstName, lastName }) {
|
|
4939
|
+
try {
|
|
4940
|
+
const deviceId = this.generateDeviceId();
|
|
4941
|
+
const deviceName = this.getDeviceName();
|
|
4942
|
+
const ipAddress = this.getIpAddress();
|
|
4943
|
+
const userAgent = this.getUserAgent();
|
|
4944
|
+
const licenseServerUrl = this.getLicenseServerUrl();
|
|
4945
|
+
const response = await fetch(`${licenseServerUrl}/api/licenses/create`, {
|
|
4946
|
+
method: "POST",
|
|
4947
|
+
headers: { "Content-Type": "application/json" },
|
|
4948
|
+
body: JSON.stringify({
|
|
4949
|
+
email,
|
|
4950
|
+
firstName,
|
|
4951
|
+
lastName,
|
|
4952
|
+
deviceName,
|
|
4953
|
+
deviceId,
|
|
4954
|
+
ipAddress,
|
|
4955
|
+
userAgent,
|
|
4956
|
+
pluginName: "magic-mail",
|
|
4957
|
+
productName: "MagicMail - Email Business Suite"
|
|
4958
|
+
})
|
|
4959
|
+
});
|
|
4960
|
+
const data = await response.json();
|
|
4961
|
+
if (data.success) {
|
|
4962
|
+
log.info("[SUCCESS] License created:", data.data.licenseKey);
|
|
4963
|
+
return data.data;
|
|
4964
|
+
} else {
|
|
4965
|
+
log.error("[ERROR] License creation failed:", data);
|
|
4966
|
+
return null;
|
|
4967
|
+
}
|
|
4968
|
+
} catch (error) {
|
|
4969
|
+
log.error("[ERROR] Error creating license:", error);
|
|
4889
4970
|
return null;
|
|
4890
4971
|
}
|
|
4891
|
-
}
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4972
|
+
},
|
|
4973
|
+
async verifyLicense(licenseKey, allowGracePeriod = false) {
|
|
4974
|
+
try {
|
|
4975
|
+
const controller2 = new AbortController();
|
|
4976
|
+
const timeoutId = setTimeout(() => controller2.abort(), 5e3);
|
|
4977
|
+
const licenseServerUrl = this.getLicenseServerUrl();
|
|
4978
|
+
const response = await fetch(`${licenseServerUrl}/api/licenses/verify`, {
|
|
4979
|
+
method: "POST",
|
|
4980
|
+
headers: { "Content-Type": "application/json" },
|
|
4981
|
+
body: JSON.stringify({
|
|
4982
|
+
licenseKey,
|
|
4983
|
+
pluginName: "magic-mail",
|
|
4984
|
+
productName: "MagicMail - Email Business Suite"
|
|
4985
|
+
}),
|
|
4986
|
+
signal: controller2.signal
|
|
4987
|
+
});
|
|
4988
|
+
clearTimeout(timeoutId);
|
|
4989
|
+
const data = await response.json();
|
|
4990
|
+
if (data.success && data.data) {
|
|
4991
|
+
return { valid: true, data: data.data, gracePeriod: false };
|
|
4992
|
+
} else {
|
|
4993
|
+
return { valid: false, data: null };
|
|
4994
|
+
}
|
|
4995
|
+
} catch (error) {
|
|
4996
|
+
if (allowGracePeriod) {
|
|
4997
|
+
log.warn("[WARNING] License verification timeout - grace period active");
|
|
4998
|
+
return { valid: true, data: null, gracePeriod: true };
|
|
4999
|
+
}
|
|
5000
|
+
log.error("[ERROR] License verification error:", error.message);
|
|
4916
5001
|
return { valid: false, data: null };
|
|
4917
5002
|
}
|
|
4918
|
-
}
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
const data = await response.json();
|
|
4936
|
-
if (data.success && data.data) {
|
|
4937
|
-
return data.data;
|
|
5003
|
+
},
|
|
5004
|
+
async getLicenseByKey(licenseKey) {
|
|
5005
|
+
try {
|
|
5006
|
+
const licenseServerUrl = this.getLicenseServerUrl();
|
|
5007
|
+
const url = `${licenseServerUrl}/api/licenses/key/${licenseKey}`;
|
|
5008
|
+
const response = await fetch(url, {
|
|
5009
|
+
method: "GET",
|
|
5010
|
+
headers: { "Content-Type": "application/json" }
|
|
5011
|
+
});
|
|
5012
|
+
const data = await response.json();
|
|
5013
|
+
if (data.success && data.data) {
|
|
5014
|
+
return data.data;
|
|
5015
|
+
}
|
|
5016
|
+
return null;
|
|
5017
|
+
} catch (error) {
|
|
5018
|
+
log.error("Error fetching license by key:", error);
|
|
5019
|
+
return null;
|
|
4938
5020
|
}
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
strapi2.log.error("[magic-mail] Error fetching license by key:", error);
|
|
4942
|
-
return null;
|
|
4943
|
-
}
|
|
4944
|
-
},
|
|
4945
|
-
async pingLicense(licenseKey) {
|
|
4946
|
-
try {
|
|
4947
|
-
const deviceId = this.generateDeviceId();
|
|
4948
|
-
const deviceName = this.getDeviceName();
|
|
4949
|
-
const ipAddress = this.getIpAddress();
|
|
4950
|
-
const userAgent = this.getUserAgent();
|
|
4951
|
-
const licenseServerUrl = this.getLicenseServerUrl();
|
|
4952
|
-
const response = await fetch(`${licenseServerUrl}/api/licenses/ping`, {
|
|
4953
|
-
method: "POST",
|
|
4954
|
-
headers: { "Content-Type": "application/json" },
|
|
4955
|
-
body: JSON.stringify({
|
|
4956
|
-
licenseKey,
|
|
4957
|
-
deviceId,
|
|
4958
|
-
deviceName,
|
|
4959
|
-
ipAddress,
|
|
4960
|
-
userAgent,
|
|
4961
|
-
pluginName: "magic-mail"
|
|
4962
|
-
})
|
|
4963
|
-
});
|
|
4964
|
-
const data = await response.json();
|
|
4965
|
-
return data.success ? data.data : null;
|
|
4966
|
-
} catch (error) {
|
|
4967
|
-
return null;
|
|
4968
|
-
}
|
|
4969
|
-
},
|
|
4970
|
-
async storeLicenseKey(licenseKey) {
|
|
4971
|
-
const pluginStore = strapi2.store({
|
|
4972
|
-
type: "plugin",
|
|
4973
|
-
name: "magic-mail"
|
|
4974
|
-
});
|
|
4975
|
-
await pluginStore.set({ key: "licenseKey", value: licenseKey });
|
|
4976
|
-
strapi2.log.info(`[magic-mail] [SUCCESS] License key stored: ${licenseKey.substring(0, 8)}...`);
|
|
4977
|
-
},
|
|
4978
|
-
startPinging(licenseKey, intervalMinutes = 15) {
|
|
4979
|
-
this.pingLicense(licenseKey);
|
|
4980
|
-
const interval = setInterval(async () => {
|
|
5021
|
+
},
|
|
5022
|
+
async pingLicense(licenseKey) {
|
|
4981
5023
|
try {
|
|
4982
|
-
|
|
5024
|
+
const deviceId = this.generateDeviceId();
|
|
5025
|
+
const deviceName = this.getDeviceName();
|
|
5026
|
+
const ipAddress = this.getIpAddress();
|
|
5027
|
+
const userAgent = this.getUserAgent();
|
|
5028
|
+
const licenseServerUrl = this.getLicenseServerUrl();
|
|
5029
|
+
const response = await fetch(`${licenseServerUrl}/api/licenses/ping`, {
|
|
5030
|
+
method: "POST",
|
|
5031
|
+
headers: { "Content-Type": "application/json" },
|
|
5032
|
+
body: JSON.stringify({
|
|
5033
|
+
licenseKey,
|
|
5034
|
+
deviceId,
|
|
5035
|
+
deviceName,
|
|
5036
|
+
ipAddress,
|
|
5037
|
+
userAgent,
|
|
5038
|
+
pluginName: "magic-mail"
|
|
5039
|
+
})
|
|
5040
|
+
});
|
|
5041
|
+
const data = await response.json();
|
|
5042
|
+
return data.success ? data.data : null;
|
|
4983
5043
|
} catch (error) {
|
|
4984
|
-
|
|
5044
|
+
return null;
|
|
4985
5045
|
}
|
|
4986
|
-
},
|
|
4987
|
-
|
|
4988
|
-
},
|
|
4989
|
-
/**
|
|
4990
|
-
* Get current license data from store
|
|
4991
|
-
*/
|
|
4992
|
-
async getCurrentLicense() {
|
|
4993
|
-
try {
|
|
5046
|
+
},
|
|
5047
|
+
async storeLicenseKey(licenseKey) {
|
|
4994
5048
|
const pluginStore = strapi2.store({
|
|
4995
5049
|
type: "plugin",
|
|
4996
5050
|
name: "magic-mail"
|
|
4997
5051
|
});
|
|
4998
|
-
|
|
4999
|
-
|
|
5052
|
+
await pluginStore.set({ key: "licenseKey", value: licenseKey });
|
|
5053
|
+
log.info(`[SUCCESS] License key stored: ${licenseKey.substring(0, 8)}...`);
|
|
5054
|
+
},
|
|
5055
|
+
startPinging(licenseKey, intervalMinutes = 15) {
|
|
5056
|
+
this.pingLicense(licenseKey);
|
|
5057
|
+
const interval = setInterval(async () => {
|
|
5058
|
+
try {
|
|
5059
|
+
await this.pingLicense(licenseKey);
|
|
5060
|
+
} catch (error) {
|
|
5061
|
+
console.error("Ping error:", error);
|
|
5062
|
+
}
|
|
5063
|
+
}, intervalMinutes * 60 * 1e3);
|
|
5064
|
+
return interval;
|
|
5065
|
+
},
|
|
5066
|
+
/**
|
|
5067
|
+
* Get current license data from store
|
|
5068
|
+
*/
|
|
5069
|
+
async getCurrentLicense() {
|
|
5070
|
+
try {
|
|
5071
|
+
const pluginStore = strapi2.store({
|
|
5072
|
+
type: "plugin",
|
|
5073
|
+
name: "magic-mail"
|
|
5074
|
+
});
|
|
5075
|
+
const licenseKey = await pluginStore.get({ key: "licenseKey" });
|
|
5076
|
+
if (!licenseKey) {
|
|
5077
|
+
return null;
|
|
5078
|
+
}
|
|
5079
|
+
const license2 = await this.getLicenseByKey(licenseKey);
|
|
5080
|
+
return license2;
|
|
5081
|
+
} catch (error) {
|
|
5082
|
+
log.error(`[ERROR] Error loading license:`, error);
|
|
5000
5083
|
return null;
|
|
5001
5084
|
}
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
});
|
|
5060
|
-
const licenseKey = await pluginStore.get({ key: "licenseKey" });
|
|
5061
|
-
const lastValidated = await pluginStore.get({ key: "lastValidated" });
|
|
5062
|
-
const now = /* @__PURE__ */ new Date();
|
|
5063
|
-
const gracePeriodHours = 24;
|
|
5064
|
-
let withinGracePeriod = false;
|
|
5065
|
-
if (lastValidated) {
|
|
5066
|
-
const lastValidatedDate = new Date(lastValidated);
|
|
5067
|
-
const hoursSinceValidation = (now.getTime() - lastValidatedDate.getTime()) / (1e3 * 60 * 60);
|
|
5068
|
-
withinGracePeriod = hoursSinceValidation < gracePeriodHours;
|
|
5069
|
-
}
|
|
5070
|
-
strapi2.log.info("──────────────────────────────────────────────────────────");
|
|
5071
|
-
strapi2.log.info(`📦 Plugin Store Check:`);
|
|
5072
|
-
if (licenseKey) {
|
|
5073
|
-
strapi2.log.info(` [SUCCESS] License Key found: ${licenseKey}`);
|
|
5074
|
-
strapi2.log.info(` [LICENSE] Key (short): ${licenseKey.substring(0, 10)}...`);
|
|
5085
|
+
},
|
|
5086
|
+
/**
|
|
5087
|
+
* Check if license has specific feature
|
|
5088
|
+
*/
|
|
5089
|
+
async hasFeature(featureName) {
|
|
5090
|
+
const license2 = await this.getCurrentLicense();
|
|
5091
|
+
const features2 = requireFeatures();
|
|
5092
|
+
return features2.hasFeature(license2, featureName);
|
|
5093
|
+
},
|
|
5094
|
+
/**
|
|
5095
|
+
* Check if provider is allowed
|
|
5096
|
+
*/
|
|
5097
|
+
async isProviderAllowed(provider) {
|
|
5098
|
+
const license2 = await this.getCurrentLicense();
|
|
5099
|
+
const features2 = requireFeatures();
|
|
5100
|
+
return features2.isProviderAllowed(license2, provider);
|
|
5101
|
+
},
|
|
5102
|
+
/**
|
|
5103
|
+
* Get max allowed accounts
|
|
5104
|
+
*/
|
|
5105
|
+
async getMaxAccounts() {
|
|
5106
|
+
const license2 = await this.getCurrentLicense();
|
|
5107
|
+
const features2 = requireFeatures();
|
|
5108
|
+
return features2.getMaxAccounts(license2);
|
|
5109
|
+
},
|
|
5110
|
+
/**
|
|
5111
|
+
* Get max allowed routing rules
|
|
5112
|
+
*/
|
|
5113
|
+
async getMaxRoutingRules() {
|
|
5114
|
+
const license2 = await this.getCurrentLicense();
|
|
5115
|
+
const features2 = requireFeatures();
|
|
5116
|
+
return features2.getMaxRoutingRules(license2);
|
|
5117
|
+
},
|
|
5118
|
+
/**
|
|
5119
|
+
* Get max allowed email templates
|
|
5120
|
+
*/
|
|
5121
|
+
async getMaxEmailTemplates() {
|
|
5122
|
+
const license2 = await this.getCurrentLicense();
|
|
5123
|
+
const features2 = requireFeatures();
|
|
5124
|
+
return features2.getMaxEmailTemplates(license2);
|
|
5125
|
+
},
|
|
5126
|
+
/**
|
|
5127
|
+
* Initialize license guard
|
|
5128
|
+
* Checks for existing license and starts pinging
|
|
5129
|
+
*/
|
|
5130
|
+
async initialize() {
|
|
5131
|
+
try {
|
|
5132
|
+
log.info("[INIT] Initializing License Guard...");
|
|
5133
|
+
const pluginStore = strapi2.store({
|
|
5134
|
+
type: "plugin",
|
|
5135
|
+
name: "magic-mail"
|
|
5136
|
+
});
|
|
5137
|
+
const licenseKey = await pluginStore.get({ key: "licenseKey" });
|
|
5138
|
+
const lastValidated = await pluginStore.get({ key: "lastValidated" });
|
|
5139
|
+
const now = /* @__PURE__ */ new Date();
|
|
5140
|
+
const gracePeriodHours = 24;
|
|
5141
|
+
let withinGracePeriod = false;
|
|
5075
5142
|
if (lastValidated) {
|
|
5076
5143
|
const lastValidatedDate = new Date(lastValidated);
|
|
5077
|
-
const
|
|
5078
|
-
|
|
5144
|
+
const hoursSinceValidation = (now.getTime() - lastValidatedDate.getTime()) / (1e3 * 60 * 60);
|
|
5145
|
+
withinGracePeriod = hoursSinceValidation < gracePeriodHours;
|
|
5146
|
+
}
|
|
5147
|
+
log.info("──────────────────────────────────────────────────────────");
|
|
5148
|
+
log.info(`📦 Plugin Store Check:`);
|
|
5149
|
+
if (licenseKey) {
|
|
5150
|
+
log.info(` [SUCCESS] License Key found: ${licenseKey}`);
|
|
5151
|
+
log.info(` [LICENSE] Key (short): ${licenseKey.substring(0, 10)}...`);
|
|
5152
|
+
if (lastValidated) {
|
|
5153
|
+
const lastValidatedDate = new Date(lastValidated);
|
|
5154
|
+
const hoursAgo = Math.floor((now.getTime() - lastValidatedDate.getTime()) / (1e3 * 60 * 60));
|
|
5155
|
+
log.info(` [TIME] Last validated: ${hoursAgo}h ago (Grace: ${withinGracePeriod ? "ACTIVE" : "EXPIRED"})`);
|
|
5156
|
+
} else {
|
|
5157
|
+
log.info(` [TIME] Last validated: Never (Grace: ACTIVE for first ${gracePeriodHours}h)`);
|
|
5158
|
+
}
|
|
5079
5159
|
} else {
|
|
5080
|
-
|
|
5160
|
+
log.info(` [ERROR] No license key stored`);
|
|
5081
5161
|
}
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5162
|
+
log.info("──────────────────────────────────────────────────────────");
|
|
5163
|
+
if (!licenseKey) {
|
|
5164
|
+
log.info("[DEMO] No license found - Running in demo mode");
|
|
5165
|
+
log.info("[INFO] Create a license in the admin panel to activate full features");
|
|
5166
|
+
return {
|
|
5167
|
+
valid: false,
|
|
5168
|
+
demo: true,
|
|
5169
|
+
data: null
|
|
5170
|
+
};
|
|
5171
|
+
}
|
|
5172
|
+
log.info("[VERIFY] Verifying stored license key...");
|
|
5173
|
+
const verification = await this.verifyLicense(licenseKey, withinGracePeriod);
|
|
5174
|
+
if (verification.valid) {
|
|
5175
|
+
const license2 = await this.getLicenseByKey(licenseKey);
|
|
5176
|
+
log.info(`[SUCCESS] License verified online: ACTIVE (Key: ${licenseKey.substring(0, 10)}...)`);
|
|
5177
|
+
await pluginStore.set({
|
|
5178
|
+
key: "lastValidated",
|
|
5179
|
+
value: now.toISOString()
|
|
5180
|
+
});
|
|
5181
|
+
log.info("[SUCCESS] License is valid and active");
|
|
5182
|
+
const pingInterval = this.startPinging(licenseKey, 15);
|
|
5183
|
+
log.info("[PING] Started pinging license every 15 minutes");
|
|
5184
|
+
strapi2.licenseGuardMagicMail = {
|
|
5185
|
+
licenseKey,
|
|
5186
|
+
pingInterval,
|
|
5187
|
+
data: verification.data
|
|
5188
|
+
};
|
|
5189
|
+
log.info("╔════════════════════════════════════════════════════════════════╗");
|
|
5190
|
+
log.info("║ [SUCCESS] MAGIC MAIL PLUGIN LICENSE ACTIVE ║");
|
|
5191
|
+
log.info("║ ║");
|
|
5192
|
+
log.info(`║ License: ${licenseKey.padEnd(38, " ")}║`);
|
|
5193
|
+
log.info(`║ User: ${(license2?.firstName + " " + license2?.lastName).padEnd(41, " ")}║`);
|
|
5194
|
+
log.info(`║ Email: ${(license2?.email || "N/A").padEnd(40, " ")}║`);
|
|
5195
|
+
log.info("║ ║");
|
|
5196
|
+
log.info("║ [AUTO] Pinging every 15 minutes ║");
|
|
5197
|
+
log.info("╚════════════════════════════════════════════════════════════════╝");
|
|
5198
|
+
return {
|
|
5199
|
+
valid: true,
|
|
5200
|
+
demo: false,
|
|
5201
|
+
data: verification.data,
|
|
5202
|
+
gracePeriod: verification.gracePeriod || false
|
|
5203
|
+
};
|
|
5204
|
+
} else {
|
|
5205
|
+
log.error(`[ERROR] License validation failed (Key: ${licenseKey.substring(0, 10)}...)`);
|
|
5206
|
+
log.info("──────────────────────────────────────────────────────────");
|
|
5207
|
+
log.info("[WARNING] Running in demo mode with limited features");
|
|
5208
|
+
return {
|
|
5209
|
+
valid: false,
|
|
5210
|
+
demo: true,
|
|
5211
|
+
error: "Invalid or expired license",
|
|
5212
|
+
data: null
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5215
|
+
} catch (error) {
|
|
5216
|
+
log.error("[ERROR] Error initializing License Guard:", error);
|
|
5131
5217
|
return {
|
|
5132
5218
|
valid: false,
|
|
5133
5219
|
demo: true,
|
|
5134
|
-
error:
|
|
5220
|
+
error: error.message,
|
|
5135
5221
|
data: null
|
|
5136
5222
|
};
|
|
5137
5223
|
}
|
|
5138
|
-
} catch (error) {
|
|
5139
|
-
strapi2.log.error("[ERROR] Error initializing License Guard:", error);
|
|
5140
|
-
return {
|
|
5141
|
-
valid: false,
|
|
5142
|
-
demo: true,
|
|
5143
|
-
error: error.message,
|
|
5144
|
-
data: null
|
|
5145
|
-
};
|
|
5146
5224
|
}
|
|
5147
|
-
}
|
|
5148
|
-
}
|
|
5225
|
+
};
|
|
5226
|
+
};
|
|
5149
5227
|
return licenseGuard;
|
|
5150
5228
|
}
|
|
5151
5229
|
var emailDesigner;
|