Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Add license verification module

Blue Mouseb7784df9c55c
diff --git a/backend/.env.example b/backend/.env.example
index d6c97dd32..ca77def2d 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -94,3 +94,6 @@ AI_URL=http://192.168.0.1:8000
# Uptime monitoring
MONITOR_QUEUE_URL=amqp://localhost:5672
+
+# Swetrix Enterprise (Cloud)
+SWETRIX_LICENSE_KEY=
diff --git a/backend/apps/cloud/src/common/license.ts b/backend/apps/cloud/src/common/license.ts
new file mode 100644
index 000000000..0c3b2d47a
--- /dev/null
+++ b/backend/apps/cloud/src/common/license.ts
@@ -0,0 +1,40 @@
+/*
+ This module ensures that you cannot run Swetrix Cloud without a valid license key.
+
+ The software contained within the cloud/ directory are Copyright © Swetrix Ltd.
+
+ We have made this code available solely for informational and transparency purposes. No rights are granted to use, distribute, or exploit this software in any form.
+
+ Any attempt to disable or modify the behavior of this module will be considered a violation of copyright.
+
+ If you wish to use the Swetrix Cloud for your own requirements, please contact us at [email protected] to discuss obtaining a license.
+*/
+
+import 'dotenv/config'
+import { createHash } from 'crypto'
+import { isDevelopment } from './constants'
+
+const SWETRIX_LICENSE_HASH =
+ 'af23eec423f59f00e26bceabbe1ca152de2b24619ebfafd5d5b8242b7702c705'
+
+export const validateLicense = () => {
+ if (isDevelopment) {
+ return
+ }
+
+ const licenseKey = process.env.SWETRIX_LICENSE_KEY
+
+ if (!licenseKey) {
+ throw new Error(
+ 'SWETRIX_LICENSE_KEY environment variable is not set. Please contact [email protected] to acquire a license.',
+ )
+ }
+
+ const hash = createHash('sha256').update(licenseKey).digest('hex')
+
+ if (hash !== SWETRIX_LICENSE_HASH) {
+ throw new Error(
+ 'Invalid license key provided for Swetrix Enterprise (Cloud) Edition. Please contact [email protected] to acquire a license.',
+ )
+ }
+}
diff --git a/backend/apps/cloud/src/main.ts b/backend/apps/cloud/src/main.ts
index cd392f9a2..a9b9ff71b 100644
--- a/backend/apps/cloud/src/main.ts
+++ b/backend/apps/cloud/src/main.ts
@@ -8,8 +8,11 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
import { isDevelopment } from './common/constants'
import { AppModule } from './app.module'
+import { validateLicense } from './common/license'
async function bootstrap() {
+ validateLicense()
+
const app = await NestFactory.create(AppModule)
app.use(cookieParser())