WIP License server

staging
zomars 2022-04-04 17:21:49 -06:00
parent b3f9921dd8
commit 13a05b9d79
8 changed files with 42 additions and 1 deletions

View File

@ -22,6 +22,8 @@
# - You can not repackage or sell the codebase
# - Acquire a commercial license to remove these terms by visiting: cal.com/sales
NEXT_PUBLIC_LICENSE_CONSENT=''
# To enable enterprise-only features, fill your license key in here
CALCOM_LICENSE_KEY=
# ***********************************************************************************************************
# - DATABASE ************************************************************************************************

View File

@ -73,6 +73,7 @@
"ics": "^2.31.0",
"jimp": "^0.16.1",
"lodash": "^4.17.21",
"memory-cache": "^0.2.0",
"micro": "^9.3.4",
"mime-types": "^2.1.35",
"next": "^12.1.0",
@ -122,6 +123,7 @@
"@types/glidejs__glide": "^3.4.1",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.177",
"@types/memory-cache": "^0.2.2",
"@types/micro": "^7.3.6",
"@types/mime-types": "^2.1.1",
"@types/module-alias": "^2.0.1",

View File

@ -5,6 +5,7 @@ import CredentialsProvider from "next-auth/providers/credentials";
import GoogleProvider from "next-auth/providers/google";
import { authenticator } from "otplib";
import checkLicense from "@calcom/ee/server/checkLicense";
import { symmetricDecrypt } from "@calcom/lib/crypto";
import { ErrorCode, verifyPassword } from "@lib/auth";
@ -224,6 +225,7 @@ export default NextAuth({
return token;
},
async session({ session, token }) {
const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || "");
const calendsoSession: Session = {
...session,
user: {
@ -231,6 +233,7 @@ export default NextAuth({
id: token.id as number,
name: token.name,
username: token.username as string,
hasValidLicense,
},
};
return calendsoSession;

@ -1 +1 @@
Subproject commit 25e75c810c0d6c2af558e1ced295f009d1ccd1da
Subproject commit fb5ce134e57d708cb46036c53d91bbb1f33072af

View File

@ -0,0 +1,21 @@
import cache from "memory-cache";
async function checkLicense(license: string): Promise<boolean> {
const url = `https://cal.com/api/license?key=${license}`;
const cachedResponse = cache.get(url);
if (cachedResponse) {
return cachedResponse;
} else {
try {
const hours = 24;
const response = await fetch(url);
const data = await response.json();
cache.put(url, data.valid, hours * 1000 * 60 * 60);
return data.valid;
} catch (error) {
return false;
}
}
}
export default checkLicense;

View File

@ -10,6 +10,8 @@ declare namespace NodeJS {
* - Acquire a commercial license to remove these terms by visiting: cal.com/sales
**/
readonly NEXT_PUBLIC_LICENSE_CONSENT: "agree" | undefined;
/** Needed to enable enterprise-only features */
readonly CALCOM_LICENSE_KEY: string | undefined;
readonly CALENDSO_ENCRYPTION_KEY: string | undefined;
readonly DATABASE_URL: string | undefined;
readonly GOOGLE_API_CREDENTIALS: string | undefined;

View File

@ -5,6 +5,7 @@ declare module "next-auth" {
type CalendsoSessionUser = DefaultSessionUser & {
id: number;
username: string;
hasValidLicense: boolean;
};
/**
* Returned by `useSession`, `getSession` and received as a prop on the `Provider` React Context

View File

@ -3828,6 +3828,11 @@
resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.1.tgz#e4c05d355d092d7b58db1abfe460e53f41102ac8"
integrity sha512-JPEv4iAl0I+o7g8yVWDwk30es8mfVrjkvh5UeVR2sYPpZCK44vrAPsbJpIS+rJAUxLgaSAMKTEH5Vn5qd9XsrQ==
"@types/memory-cache@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@types/memory-cache/-/memory-cache-0.2.2.tgz#f8fb6d8aa0eb006ed44fc659bf8bfdc1a5cc57fa"
integrity sha512-xNnm6EkmYYhTnLiOHC2bdKgcYY5qjjrq5vl9KXD2nh0em0koZoFS500EL4Q4V/eW+A3P7NC7P7GIYzNOSQp7jQ==
"@types/micro@7.3.6":
version "7.3.6"
resolved "https://registry.yarnpkg.com/@types/micro/-/micro-7.3.6.tgz#7d68eb5a780ac4761e3b80687b4ee7328ebc3f2e"
@ -10981,6 +10986,11 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
integrity sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==
memory-cache@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/memory-cache/-/memory-cache-0.2.0.tgz#7890b01d52c00c8ebc9d533e1f8eb17e3034871a"
integrity sha1-eJCwHVLADI68nVM+H46xfjA0hxo=
memory-pager@^1.0.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/memory-pager/-/memory-pager-1.5.0.tgz#d8751655d22d384682741c972f2c3d6dfa3e66b5"