From d70cb73fad7d7b03cd4c64e40af86719b9de572d Mon Sep 17 00:00:00 2001 From: Folke Ashberg Date: Sat, 15 Oct 2022 20:55:43 +0200 Subject: [PATCH 1/3] disable-customdomain --- .docker.env | 3 +++ .example.env | 3 +++ client/components/Features.tsx | 11 ++++++++--- client/consts/consts.ts | 4 ++++ client/pages/settings.tsx | 9 +++++++-- next.config.js | 1 + server/env.ts | 1 + 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.docker.env b/.docker.env index 740be822f..a443e6eee 100644 --- a/.docker.env +++ b/.docker.env @@ -35,6 +35,9 @@ DISALLOW_REGISTRATION=false # Disable anonymous link creation DISALLOW_ANONYMOUS_LINKS=false +# Disable customdomains +DISALLOW_CUSTOMDOMAINS=false + # The daily limit for each user USER_LIMIT_PER_DAY=50 diff --git a/.example.env b/.example.env index 634af8e6a..d3e60ad4b 100644 --- a/.example.env +++ b/.example.env @@ -35,6 +35,9 @@ DISALLOW_REGISTRATION=false # Disable anonymous link creation DISALLOW_ANONYMOUS_LINKS=false +# Disable customdomains +DISALLOW_CUSTOMDOMAINS=false + # The daily limit for each user USER_LIMIT_PER_DAY=50 diff --git a/client/components/Features.tsx b/client/components/Features.tsx index 2a6d450ec..eda9e9edb 100644 --- a/client/components/Features.tsx +++ b/client/components/Features.tsx @@ -1,6 +1,7 @@ import React from "react"; import styled from "styled-components"; import { Flex } from "reflexbox/styled-components"; +import { DISALLOW_CUSTOMDOMAINS } from "../consts"; import FeaturesItem from "./FeaturesItem"; import { ColCenterH } from "./Layout"; @@ -28,9 +29,13 @@ const Features = () => ( Create, protect and delete your links and monitor them with detailed statistics. - - Use custom domains for your links. Add or remove them for free. - + {DISALLOW_CUSTOMDOMAINS && ( + <> + + Use custom domains for your links. Add or remove them for free. + + + )} Use the provided API to create, delete, and get URLs from anywhere. diff --git a/client/consts/consts.ts b/client/consts/consts.ts index bd440eaca..db69a3fab 100644 --- a/client/consts/consts.ts +++ b/client/consts/consts.ts @@ -7,6 +7,10 @@ export const DISALLOW_ANONYMOUS_LINKS = export const DISALLOW_REGISTRATION = publicRuntimeConfig.DISALLOW_REGISTRATION === "true"; + +export const DISALLOW_CUSTOMDOMAINS = + publicRuntimeConfig.DISALLOW_CUSTOMDOMAINS === "true"; + export enum API { BAN_LINK = "/api/url/admin/ban", diff --git a/client/pages/settings.tsx b/client/pages/settings.tsx index 2d6bdb0d7..3119adb4c 100644 --- a/client/pages/settings.tsx +++ b/client/pages/settings.tsx @@ -12,6 +12,7 @@ import Divider from "../components/Divider"; import { Col } from "../components/Layout"; import Footer from "../components/Footer"; import { useStoreState } from "../store"; +import { DISALLOW_REGISTRATION } from "../consts"; const SettingsPage: NextPage = () => { const email = useStoreState(s => s.auth.email); @@ -26,8 +27,12 @@ const SettingsPage: NextPage = () => { . - - + {DISALLOW_REGISTRATION && ( + <> + + + + )} diff --git a/next.config.js b/next.config.js index 738db8eee..e7b197176 100644 --- a/next.config.js +++ b/next.config.js @@ -10,6 +10,7 @@ module.exports = { REPORT_EMAIL: localEnv && localEnv.REPORT_EMAIL, DISALLOW_ANONYMOUS_LINKS: localEnv && localEnv.DISALLOW_ANONYMOUS_LINKS, DISALLOW_REGISTRATION: localEnv && localEnv.DISALLOW_REGISTRATION, + DISALLOW_CUSTOMDOMAINS: localEnv && localEnv.DISALLOW_CUSTOMDOMAINS, SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN, } }; diff --git a/server/env.ts b/server/env.ts index 4f0d75ff1..ae98d91b1 100644 --- a/server/env.ts +++ b/server/env.ts @@ -24,6 +24,7 @@ const env = cleanEnv(process.env, { DEFAULT_MAX_STATS_PER_LINK: num({ default: 5000 }), DISALLOW_ANONYMOUS_LINKS: bool({ default: false }), DISALLOW_REGISTRATION: bool({ default: false }), + DISALLOW_CUSTOMDOMAINS: bool({ default: false }), CUSTOM_DOMAIN_USE_HTTPS: bool({ default: false }), JWT_SECRET: str(), ADMIN_EMAILS: str({ default: "" }), From 0601ed4e76faf77909358ba1cc0dc8fe43c7c88c Mon Sep 17 00:00:00 2001 From: John Clark Date: Sun, 23 Aug 2020 08:55:25 +0000 Subject: [PATCH 2/3] Merge change from @itsmechlark for custom domain --- .docker.env | 6 +++--- .example.env | 6 +++--- client/components/Features.tsx | 4 ++-- client/consts/consts.ts | 5 ++--- client/pages/settings.tsx | 10 +++------- next.config.js | 4 ++-- server/env.ts | 2 +- server/handlers/auth.ts | 4 ++++ server/routes/domains.ts | 3 +++ 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.docker.env b/.docker.env index a443e6eee..148cdc8b9 100644 --- a/.docker.env +++ b/.docker.env @@ -32,12 +32,12 @@ REDIS_PASSWORD= # Disable registration DISALLOW_REGISTRATION=false +# Disable Custom Domain +DISALLOW_DOMAIN=false + # Disable anonymous link creation DISALLOW_ANONYMOUS_LINKS=false -# Disable customdomains -DISALLOW_CUSTOMDOMAINS=false - # The daily limit for each user USER_LIMIT_PER_DAY=50 diff --git a/.example.env b/.example.env index d3e60ad4b..f748a21aa 100644 --- a/.example.env +++ b/.example.env @@ -32,12 +32,12 @@ REDIS_PASSWORD= # Disable registration DISALLOW_REGISTRATION=false +# Disable Custom Domain +DISALLOW_DOMAIN=false + # Disable anonymous link creation DISALLOW_ANONYMOUS_LINKS=false -# Disable customdomains -DISALLOW_CUSTOMDOMAINS=false - # The daily limit for each user USER_LIMIT_PER_DAY=50 diff --git a/client/components/Features.tsx b/client/components/Features.tsx index eda9e9edb..07dd081ec 100644 --- a/client/components/Features.tsx +++ b/client/components/Features.tsx @@ -1,7 +1,7 @@ import React from "react"; import styled from "styled-components"; import { Flex } from "reflexbox/styled-components"; -import { DISALLOW_CUSTOMDOMAINS } from "../consts"; +import { DISALLOW_DOMAIN } from "../consts"; import FeaturesItem from "./FeaturesItem"; import { ColCenterH } from "./Layout"; @@ -29,7 +29,7 @@ const Features = () => ( Create, protect and delete your links and monitor them with detailed statistics. - {DISALLOW_CUSTOMDOMAINS && ( + {DISALLOW_DOMAIN && ( <> Use custom domains for your links. Add or remove them for free. diff --git a/client/consts/consts.ts b/client/consts/consts.ts index db69a3fab..2acce0dd3 100644 --- a/client/consts/consts.ts +++ b/client/consts/consts.ts @@ -8,9 +8,8 @@ export const DISALLOW_ANONYMOUS_LINKS = export const DISALLOW_REGISTRATION = publicRuntimeConfig.DISALLOW_REGISTRATION === "true"; -export const DISALLOW_CUSTOMDOMAINS = - publicRuntimeConfig.DISALLOW_CUSTOMDOMAINS === "true"; - +export const DISALLOW_DOMAIN = + publicRuntimeConfig.DISALLOW_DOMAIN === "true"; export enum API { BAN_LINK = "/api/url/admin/ban", diff --git a/client/pages/settings.tsx b/client/pages/settings.tsx index 3119adb4c..12457b604 100644 --- a/client/pages/settings.tsx +++ b/client/pages/settings.tsx @@ -12,7 +12,7 @@ import Divider from "../components/Divider"; import { Col } from "../components/Layout"; import Footer from "../components/Footer"; import { useStoreState } from "../store"; -import { DISALLOW_REGISTRATION } from "../consts"; +import { DISALLOW_DOMAIN } from "../consts"; const SettingsPage: NextPage = () => { const email = useStoreState(s => s.auth.email); @@ -27,12 +27,8 @@ const SettingsPage: NextPage = () => { . - {DISALLOW_REGISTRATION && ( - <> - - - - )} + {!DISALLOW_DOMAIN && } + {!DISALLOW_DOMAIN && } diff --git a/next.config.js b/next.config.js index e7b197176..0dd94fb8f 100644 --- a/next.config.js +++ b/next.config.js @@ -10,7 +10,7 @@ module.exports = { REPORT_EMAIL: localEnv && localEnv.REPORT_EMAIL, DISALLOW_ANONYMOUS_LINKS: localEnv && localEnv.DISALLOW_ANONYMOUS_LINKS, DISALLOW_REGISTRATION: localEnv && localEnv.DISALLOW_REGISTRATION, - DISALLOW_CUSTOMDOMAINS: localEnv && localEnv.DISALLOW_CUSTOMDOMAINS, - SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN, + DISALLOW_DOMAIN: localEnv && localEnv.DISALLOW_DOMAIN, + SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN } }; diff --git a/server/env.ts b/server/env.ts index ae98d91b1..e1c009fa7 100644 --- a/server/env.ts +++ b/server/env.ts @@ -23,8 +23,8 @@ const env = cleanEnv(process.env, { NON_USER_COOLDOWN: num({ default: 10 }), DEFAULT_MAX_STATS_PER_LINK: num({ default: 5000 }), DISALLOW_ANONYMOUS_LINKS: bool({ default: false }), + DISALLOW_DOMAIN: bool({ default: false }), DISALLOW_REGISTRATION: bool({ default: false }), - DISALLOW_CUSTOMDOMAINS: bool({ default: false }), CUSTOM_DOMAIN_USE_HTTPS: bool({ default: false }), JWT_SECRET: str(), ADMIN_EMAILS: str({ default: "" }), diff --git a/server/handlers/auth.ts b/server/handlers/auth.ts index a1431bd82..8fd425264 100644 --- a/server/handlers/auth.ts +++ b/server/handlers/auth.ts @@ -294,3 +294,7 @@ export const changeEmail: Handler = async (req, res, next) => { } return next(); }; + +export const bypass: Handler = async (req, res, next) => { + return next(); +}; diff --git a/server/routes/domains.ts b/server/routes/domains.ts index 2a06e633e..b6dc8092f 100644 --- a/server/routes/domains.ts +++ b/server/routes/domains.ts @@ -5,6 +5,7 @@ import * as validators from "../handlers/validators"; import * as helpers from "../handlers/helpers"; import * as domains from "../handlers/domains"; import * as auth from "../handlers/auth"; +import env from "../env"; const router = Router(); @@ -12,6 +13,7 @@ router.post( "/", asyncHandler(auth.apikey), asyncHandler(auth.jwt), + asyncHandler(env.DISALLOW_DOMAIN ? auth.admin : auth.bypass), validators.addDomain, asyncHandler(helpers.verify), asyncHandler(domains.add) @@ -21,6 +23,7 @@ router.delete( "/:id", asyncHandler(auth.apikey), asyncHandler(auth.jwt), + asyncHandler(env.DISALLOW_DOMAIN ? auth.admin : auth.bypass), validators.removeDomain, asyncHandler(helpers.verify), asyncHandler(domains.remove) From 6a3e3d1239131efdd69bd0f692e57ef48332cfda Mon Sep 17 00:00:00 2001 From: Folke Ashberg Date: Sun, 16 Oct 2022 13:12:14 +0200 Subject: [PATCH 3/3] remove-custom-dom-text --- client/components/NeedToLogin.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/components/NeedToLogin.tsx b/client/components/NeedToLogin.tsx index c2e8c5675..8d9e84f51 100644 --- a/client/components/NeedToLogin.tsx +++ b/client/components/NeedToLogin.tsx @@ -6,6 +6,7 @@ import { Flex } from "reflexbox/styled-components"; import { Button } from "./Button"; import { fadeIn } from "../helpers/animations"; import { Col } from "./Layout"; +import { DISALLOW_DOMAIN } from "../consts"; const Wrapper = styled(Flex).attrs({ width: 1200, @@ -63,7 +64,7 @@ const NeedToLogin = () => ( mb={[32, 32, 0]} > - Manage links, set custom <b>domains</b> and view <b>stats</b>. + Manage links{DISALLOW_DOMAIN && (<>, set custom <b>domains</b></>)} and view <b>stats</b>.