Compare commits

...

7 Commits

Author SHA1 Message Date
Eduard Gert
47db655e9f Update eslint and tailwind (#515)
Some checks failed
build and push / build_n_push (push) Has been cancelled
2025-11-27 17:38:18 +01:00
dependabot[bot]
0661cbf9f4 Bump js-yaml from 4.1.0 to 4.1.1 (#509)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.1.0 to 4.1.1.
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/4.1.0...4.1.1)

---
updated-dependencies:
- dependency-name: js-yaml
  dependency-version: 4.1.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-27 15:25:50 +01:00
Eduard Gert
240a96fa8b Add onboarding for new accounts (#514) 2025-11-27 14:49:58 +01:00
Eduard Gert
43bc069a49 Increase ssh detection timeout (#512)
Some checks failed
build and push / build_n_push (push) Has been cancelled
2025-11-21 10:32:50 +01:00
Eduard Gert
936de0f4f3 Add ssh policy info for peers (#511)
Some checks failed
build and push / build_n_push (push) Has been cancelled
2025-11-20 14:29:14 +01:00
Eduard Gert
d81b75a946 Bump browser ssh versions for ssh rewrite (#510)
Some checks failed
build and push / build_n_push (push) Has been cancelled
* Bump browser ssh versions for ssh rewrite

* Remove cypress temporary
2025-11-18 17:07:58 +01:00
Eduard Gert
a632eeeef0 Remove dns0eu (#508) 2025-11-10 14:21:58 +01:00
46 changed files with 5779 additions and 2947 deletions

View File

@@ -2,7 +2,6 @@ name: build and push
on:
push:
branches:
- "feature/**"
- main
tags:
- "**"

5202
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,6 @@
"date-fns": "^2.30.0",
"dayjs": "^1.11.10",
"elkjs": "^0.10.0",
"eslint": "^8",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"flowbite": "^1.8.1",
@@ -90,10 +89,10 @@
"@faker-js/faker": "^9.5.1",
"@types/chroma-js": "^3.1.1",
"@types/js-cookie": "^3.0.6",
"eslint-config-next": "^14.2.28",
"cypress": "^13.13.0",
"eslint": "^9.39.1",
"eslint-config-next": "^16.0.5",
"postcss": "^8",
"prettier": "3.0.3",
"tailwindcss": "^3"
"tailwindcss": "^3.4.17"
}
}

View File

@@ -108,6 +108,7 @@ function SSHTerminal({ username, port, peer }: Props) {
if (!peer.id) return;
if (connected.current) return;
connected.current = true;
try {
const aclPort = isNativeSSHSupported(peer.version) ? "22022" : port;
const rules = [`tcp/${aclPort}`];
@@ -121,7 +122,7 @@ function SSHTerminal({ username, port, peer }: Props) {
sshConnectedOnce.current = true;
}
} catch (error) {
console.error("Connection failed:", error);
console.error("Connection error:", error);
}
};

View File

@@ -1,12 +0,0 @@
<svg width="573" height="148" viewBox="0 0 573 148" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_4_4)">
<path d="M0.739014 125.602V33.09H28.239C34.491 33.09 39.919 34.274 44.524 36.638C49.128 39.004 52.698 42.341 55.233 46.65C57.767 50.958 59.034 56.071 59.034 61.984V96.58C59.034 102.41 57.767 107.5 55.233 111.85C52.698 116.203 49.128 119.581 44.523 121.99C39.918 124.397 34.491 125.601 28.239 125.601L0.739014 125.602ZM16.58 111.028H28.24C32.801 111.028 36.433 109.741 39.138 107.163C41.841 104.587 43.193 101.06 43.193 96.581V61.984C43.193 57.592 41.841 54.107 39.138 51.529C36.433 48.952 32.801 47.663 28.239 47.663H16.58V111.028ZM76.396 125.602V33.09H95.786L121.512 107.86C121.216 104.673 120.942 101.483 120.688 98.292C120.386 94.5366 120.154 90.776 119.991 87.012C119.821 83.169 119.738 79.812 119.738 76.938V33.09H134.185V125.602H114.795L89.323 50.832C89.491 53.283 89.703 56.239 89.956 59.702C90.2137 63.2478 90.4251 66.7967 90.59 70.348C90.758 73.982 90.844 77.318 90.844 80.36V125.602H76.396ZM181.582 126.869C175.245 126.869 169.752 125.812 165.107 123.701C160.46 121.591 156.889 118.569 154.398 114.64C151.905 110.711 150.616 106.086 150.533 100.763H166.374C166.374 104.565 167.747 107.543 170.494 109.698C173.238 111.852 176.976 112.929 181.709 112.929C186.271 112.929 189.839 111.874 192.417 109.761C194.993 107.65 196.282 104.735 196.282 101.017C196.282 97.892 195.374 95.167 193.558 92.842C191.74 90.52 189.142 88.936 185.764 88.09L175.119 85.175C167.852 83.318 162.256 79.979 158.327 75.164C154.398 70.348 152.434 64.518 152.434 57.675C152.434 52.438 153.616 47.875 155.982 43.988C158.347 40.103 161.705 37.103 166.058 34.99C170.408 32.88 175.54 31.822 181.455 31.822C190.409 31.822 197.506 34.125 202.745 38.729C207.983 43.335 210.645 49.523 210.73 57.295H194.888C194.888 53.663 193.704 50.812 191.34 48.741C188.974 46.671 185.637 45.636 181.328 45.636C177.188 45.636 173.978 46.608 171.697 48.551C169.416 50.495 168.275 53.24 168.275 56.788C168.275 60 169.141 62.724 170.873 64.962C172.603 67.202 175.119 68.786 178.413 69.714L189.439 72.756C196.789 74.616 202.407 77.932 206.294 82.704C210.179 87.478 212.124 93.371 212.124 100.383C212.124 105.623 210.856 110.248 208.322 114.26C205.787 118.273 202.239 121.378 197.677 123.574C193.114 125.77 187.748 126.869 181.582 126.869ZM257.366 126.869C251.366 126.869 246.17 125.729 241.778 123.448C237.384 121.167 233.985 117.957 231.577 113.816C229.169 109.678 227.965 104.818 227.965 99.242V59.45C227.965 53.874 229.169 49.017 231.577 44.876C233.984 40.738 237.384 37.526 241.778 35.245C246.17 32.964 251.366 31.823 257.366 31.823C263.449 31.823 268.665 32.963 273.017 35.245C277.367 37.526 280.747 40.738 283.156 44.876C285.563 49.016 286.767 53.874 286.767 59.45V99.243C286.767 104.819 285.563 109.679 283.156 113.817C280.748 117.957 277.346 121.167 272.954 123.449C268.56 125.729 263.364 126.869 257.366 126.869ZM257.366 113.183C261.758 113.183 265.265 111.915 267.885 109.381C270.502 106.846 271.813 103.468 271.813 99.242V59.45C271.813 55.227 270.503 51.846 267.885 49.312C265.265 46.777 261.758 45.51 257.366 45.51C252.972 45.51 249.466 46.777 246.848 49.312C244.228 51.846 242.918 55.227 242.918 59.45V99.243C242.918 103.469 244.228 106.847 246.848 109.382C249.465 111.916 252.972 113.183 257.366 113.183ZM257.366 87.583C254.915 87.583 252.909 86.781 251.346 85.175C249.782 83.571 249.002 81.5 249.002 78.965C249.002 76.431 249.762 74.403 251.283 72.883C252.803 71.362 254.831 70.601 257.366 70.601C259.901 70.601 261.928 71.361 263.449 72.883C264.969 74.403 265.73 76.431 265.73 78.966C265.73 81.5 264.97 83.571 263.45 85.176C261.928 86.781 259.9 87.583 257.366 87.583Z" fill="black"/>
<path d="M332.69 126.999C329.057 126.999 326.164 125.941 324.01 123.831C321.855 121.72 320.778 118.847 320.778 115.213C320.778 111.581 321.855 108.686 324.01 106.532C326.164 104.378 329.057 103.3 332.69 103.3C336.322 103.3 339.217 104.378 341.372 106.532C343.526 108.686 344.603 111.582 344.603 115.213C344.603 118.847 343.526 121.72 341.372 123.831C339.217 125.941 336.322 126.999 332.691 126.999H332.69ZM381.862 125.732V33.219H437.369V47.032H397.449V71.112H432.934V84.798H397.45V111.918H437.37V125.732H381.862ZM484.766 126.999C475.725 126.999 468.65 124.528 463.539 119.585C458.426 114.643 455.872 107.906 455.872 99.372V33.219H471.84V99.245C471.84 103.639 472.937 107.061 475.135 109.51C477.331 111.962 480.54 113.185 484.766 113.185C488.905 113.185 492.095 111.962 494.334 109.51C496.572 107.06 497.693 103.639 497.693 99.245V33.219H513.66V99.372C513.66 107.906 511.126 114.642 506.057 119.585C500.987 124.528 493.891 126.999 484.767 126.999H484.766Z" fill="#686868"/>
<path d="M549 0H573V148H549V0Z" fill="#FFCC03"/>
</g>
<defs>
<clipPath id="clip0_4_4">
<rect width="573" height="148" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -1,12 +0,0 @@
<svg width="573" height="148" viewBox="0 0 573 148" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_4_4)">
<path d="M0.739014 125.602V33.09H28.239C34.491 33.09 39.919 34.274 44.524 36.638C49.128 39.004 52.698 42.341 55.233 46.65C57.767 50.958 59.034 56.071 59.034 61.984V96.58C59.034 102.41 57.767 107.5 55.233 111.85C52.698 116.203 49.128 119.581 44.523 121.99C39.918 124.397 34.491 125.601 28.239 125.601L0.739014 125.602ZM16.58 111.028H28.24C32.801 111.028 36.433 109.741 39.138 107.163C41.841 104.587 43.193 101.06 43.193 96.581V61.984C43.193 57.592 41.841 54.107 39.138 51.529C36.433 48.952 32.801 47.663 28.239 47.663H16.58V111.028ZM76.396 125.602V33.09H95.786L121.512 107.86C121.216 104.673 120.942 101.483 120.688 98.292C120.386 94.5366 120.154 90.776 119.991 87.012C119.821 83.169 119.738 79.812 119.738 76.938V33.09H134.185V125.602H114.795L89.323 50.832C89.491 53.283 89.703 56.239 89.956 59.702C90.2137 63.2478 90.4251 66.7967 90.59 70.348C90.758 73.982 90.844 77.318 90.844 80.36V125.602H76.396ZM181.582 126.869C175.245 126.869 169.752 125.812 165.107 123.701C160.46 121.591 156.889 118.569 154.398 114.64C151.905 110.711 150.616 106.086 150.533 100.763H166.374C166.374 104.565 167.747 107.543 170.494 109.698C173.238 111.852 176.976 112.929 181.709 112.929C186.271 112.929 189.839 111.874 192.417 109.761C194.993 107.65 196.282 104.735 196.282 101.017C196.282 97.892 195.374 95.167 193.558 92.842C191.74 90.52 189.142 88.936 185.764 88.09L175.119 85.175C167.852 83.318 162.256 79.979 158.327 75.164C154.398 70.348 152.434 64.518 152.434 57.675C152.434 52.438 153.616 47.875 155.982 43.988C158.347 40.103 161.705 37.103 166.058 34.99C170.408 32.88 175.54 31.822 181.455 31.822C190.409 31.822 197.506 34.125 202.745 38.729C207.983 43.335 210.645 49.523 210.73 57.295H194.888C194.888 53.663 193.704 50.812 191.34 48.741C188.974 46.671 185.637 45.636 181.328 45.636C177.188 45.636 173.978 46.608 171.697 48.551C169.416 50.495 168.275 53.24 168.275 56.788C168.275 60 169.141 62.724 170.873 64.962C172.603 67.202 175.119 68.786 178.413 69.714L189.439 72.756C196.789 74.616 202.407 77.932 206.294 82.704C210.179 87.478 212.124 93.371 212.124 100.383C212.124 105.623 210.856 110.248 208.322 114.26C205.787 118.273 202.239 121.378 197.677 123.574C193.114 125.77 187.748 126.869 181.582 126.869ZM257.366 126.869C251.366 126.869 246.17 125.729 241.778 123.448C237.384 121.167 233.985 117.957 231.577 113.816C229.169 109.678 227.965 104.818 227.965 99.242V59.45C227.965 53.874 229.169 49.017 231.577 44.876C233.984 40.738 237.384 37.526 241.778 35.245C246.17 32.964 251.366 31.823 257.366 31.823C263.449 31.823 268.665 32.963 273.017 35.245C277.367 37.526 280.747 40.738 283.156 44.876C285.563 49.016 286.767 53.874 286.767 59.45V99.243C286.767 104.819 285.563 109.679 283.156 113.817C280.748 117.957 277.346 121.167 272.954 123.449C268.56 125.729 263.364 126.869 257.366 126.869ZM257.366 113.183C261.758 113.183 265.265 111.915 267.885 109.381C270.502 106.846 271.813 103.468 271.813 99.242V59.45C271.813 55.227 270.503 51.846 267.885 49.312C265.265 46.777 261.758 45.51 257.366 45.51C252.972 45.51 249.466 46.777 246.848 49.312C244.228 51.846 242.918 55.227 242.918 59.45V99.243C242.918 103.469 244.228 106.847 246.848 109.382C249.465 111.916 252.972 113.183 257.366 113.183ZM257.366 87.583C254.915 87.583 252.909 86.781 251.346 85.175C249.782 83.571 249.002 81.5 249.002 78.965C249.002 76.431 249.762 74.403 251.283 72.883C252.803 71.362 254.831 70.601 257.366 70.601C259.901 70.601 261.928 71.361 263.449 72.883C264.969 74.403 265.73 76.431 265.73 78.966C265.73 81.5 264.97 83.571 263.45 85.176C261.928 86.781 259.9 87.583 257.366 87.583Z" fill="black"/>
<path d="M332.69 126.999C329.057 126.999 326.164 125.941 324.01 123.831C321.855 121.72 320.778 118.847 320.778 115.213C320.778 111.581 321.855 108.686 324.01 106.532C326.164 104.378 329.057 103.3 332.69 103.3C336.322 103.3 339.217 104.378 341.372 106.532C343.526 108.686 344.603 111.582 344.603 115.213C344.603 118.847 343.526 121.72 341.372 123.831C339.217 125.941 336.322 126.999 332.691 126.999H332.69ZM381.862 125.732V33.219H437.369V47.032H397.449V71.112H432.934V84.798H397.45V111.918H437.37V125.732H381.862ZM484.766 126.999C475.725 126.999 468.65 124.528 463.539 119.585C458.426 114.643 455.872 107.906 455.872 99.372V33.219H471.84V99.245C471.84 103.639 472.937 107.061 475.135 109.51C477.331 111.962 480.54 113.185 484.766 113.185C488.905 113.185 492.095 111.962 494.334 109.51C496.572 107.06 497.693 103.639 497.693 99.245V33.219H513.66V99.372C513.66 107.906 511.126 114.642 506.057 119.585C500.987 124.528 493.891 126.999 484.767 126.999H484.766Z" fill="#359CEF"/>
<path d="M549 0H573V148H549V0Z" fill="#FFCC03"/>
</g>
<defs>
<clipPath id="clip0_4_4">
<rect width="573" height="148" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

View File

@@ -17,6 +17,12 @@ declare global {
}
}
export type HubspotFormField = {
objectTypeId?: string;
name: string;
value: string;
};
const AnalyticsContext = React.createContext(
{} as {
initialized: boolean;

View File

@@ -4,7 +4,18 @@ import md5 from "crypto-js/md5";
import React, { useEffect, useState } from "react";
import { usePermissions } from "@/contexts/PermissionsProvider";
const initialAnnouncements: Announcement[] = [];
const initialAnnouncements: Announcement[] = [
{
tag: "New",
text: "NetBird v0.60.0 - Identity-aware, private SSH over your NetBird network.",
link: "https://docs.netbird.io/how-to/ssh",
linkText: "Documentation",
variant: "default", // "default" or "important"
isExternal: true,
closeable: true,
isCloudOnly: false,
},
];
export interface Announcement extends AnnouncementVariant {
tag: string;

View File

@@ -138,6 +138,7 @@ export default function PeerProvider({
<PeerSSHInstructions
open={sshInstructionsModal}
onOpenChange={setSSHInstructionsModal}
peer={peer}
onSuccess={() => toggleSSH(true)}
/>
)}

View File

@@ -23,4 +23,10 @@ export interface Account {
network_range?: string;
lazy_connection_enabled: boolean;
};
onboarding?: AccountOnboarding;
}
export interface AccountOnboarding {
onboarding_flow_pending: boolean;
signup_form_pending: boolean;
}

View File

@@ -104,50 +104,4 @@ export const NameserverPresets: Record<string, NameserverGroup> = {
enabled: true,
search_domains_enabled: false,
},
DNS0: {
name: "DNS0.EU",
description: "DNS0.EU DNS Servers",
primary: true,
domains: [],
nameservers: [
{
ip: "193.110.81.0",
ns_type: "udp",
port: 53,
id: "1",
},
{
ip: "185.253.5.0",
ns_type: "udp",
port: 53,
id: "2",
},
],
groups: [],
enabled: true,
search_domains_enabled: false,
},
DNS0Zero: {
name: "DNS0.EU Zero",
description: "DNS0.EU Zero DNS Servers",
primary: true,
domains: [],
nameservers: [
{
ip: "193.110.81.9",
ns_type: "udp",
port: 53,
id: "1",
},
{
ip: "185.253.5.9",
ns_type: "udp",
port: 53,
id: "2",
},
],
groups: [],
enabled: true,
search_domains_enabled: false,
},
};

View File

@@ -24,6 +24,7 @@ export interface Peer {
login_expiration_enabled: boolean;
inactivity_expiration_enabled: boolean;
approval_required: boolean;
disapproval_reason?: string;
city_name: string;
country_code: string;
connection_ip: string;

View File

@@ -5,6 +5,7 @@ import { useOidcUser } from "@axa-fr/react-oidc";
import Button from "@components/Button";
import { UserAvatar } from "@components/ui/UserAvatar";
import { cn } from "@utils/helpers";
import { isNetBirdHosted } from "@utils/netbird";
import { useIsSm, useIsXs } from "@utils/responsive";
import { AnimatePresence, motion } from "framer-motion";
import { XIcon } from "lucide-react";
@@ -20,6 +21,7 @@ import GroupsProvider from "@/contexts/GroupsProvider";
import { usePermissions } from "@/contexts/PermissionsProvider";
import UsersProvider from "@/contexts/UsersProvider";
import Navigation from "@/layouts/Navigation";
import { OnboardingProvider } from "@/modules/onboarding/OnboardingProvider";
import Header, { headerHeight } from "./Header";
export default function DashboardLayout({
@@ -33,6 +35,7 @@ export default function DashboardLayout({
<AnnouncementProvider>
<GroupsProvider>
<CountryProvider>
{!isNetBirdHosted() && <OnboardingProvider />}
<DashboardPageContent>{children}</DashboardPageContent>
</CountryProvider>
</GroupsProvider>

View File

@@ -45,7 +45,7 @@ import React, { useMemo, useState } from "react";
import AccessControlIcon from "@/assets/icons/AccessControlIcon";
import { usePermissions } from "@/contexts/PermissionsProvider";
import { Group } from "@/interfaces/Group";
import { Policy, Protocol } from "@/interfaces/Policy";
import { Policy, PolicyRuleResource, Protocol } from "@/interfaces/Policy";
import { PostureCheck } from "@/interfaces/PostureCheck";
import { useAccessControl } from "@/modules/access-control/useAccessControl";
import { PostureCheckTab } from "@/modules/posture-checks/ui/PostureCheckTab";
@@ -116,6 +116,9 @@ type ModalProps = {
postureCheckTemplates?: PostureCheck[];
useSave?: boolean;
allowEditPeers?: boolean;
initialProtocol?: Protocol;
initialPorts?: number[];
initialDestinationResource?: PolicyRuleResource;
};
export function AccessControlModalContent({
@@ -128,6 +131,9 @@ export function AccessControlModalContent({
initialDestinationGroups,
initialName,
initialDescription,
initialProtocol,
initialPorts,
initialDestinationResource,
}: Readonly<ModalProps>) {
const { permission } = usePermissions();
@@ -170,6 +176,9 @@ export function AccessControlModalContent({
initialDestinationGroups,
initialName,
initialDescription,
initialPorts,
initialProtocol,
initialDestinationResource,
});
const [tab, setTab] = useState(() => {

View File

@@ -6,7 +6,12 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { useSWRConfig } from "swr";
import { usePolicies } from "@/contexts/PoliciesProvider";
import { Group } from "@/interfaces/Group";
import { Policy, PortRange, Protocol } from "@/interfaces/Policy";
import {
Policy,
PolicyRuleResource,
PortRange,
Protocol,
} from "@/interfaces/Policy";
import { PostureCheck } from "@/interfaces/PostureCheck";
import useGroupHelper from "@/modules/groups/useGroupHelper";
import { usePostureCheck } from "@/modules/posture-checks/usePostureCheck";
@@ -18,6 +23,9 @@ type Props = {
initialDestinationGroups?: Group[] | string[];
initialName?: string;
initialDescription?: string;
initialProtocol?: Protocol;
initialPorts?: number[];
initialDestinationResource?: PolicyRuleResource;
};
// TODO add reducer
@@ -29,6 +37,9 @@ export const useAccessControl = ({
initialName,
initialDescription,
onSuccess,
initialProtocol,
initialPorts,
initialDestinationResource,
}: Props = {}) => {
const { data: allPostureChecks, isLoading: isPostureChecksLoading } =
useFetchApi<PostureCheck[]>("/posture-checks");
@@ -75,6 +86,7 @@ export const useAccessControl = ({
const [enabled, setEnabled] = useState<boolean>(policy?.enabled ?? true);
const [ports, setPorts] = useState<number[]>(() => {
if (initialPorts) return initialPorts;
if (!firstRule) return [];
if (firstRule.ports == undefined) return [];
if (firstRule.ports.length > 0) {
@@ -93,7 +105,7 @@ export const useAccessControl = ({
});
const [protocol, setProtocol] = useState<Protocol>(
firstRule ? firstRule.protocol : "all",
firstRule ? firstRule.protocol : initialProtocol ?? "all",
);
const [direction, setDirection] = useState<Direction>(() => {
if (!firstRule) return "bi";
@@ -131,7 +143,7 @@ export const useAccessControl = ({
);
const [destinationResource, setDestinationResource] = useState(
firstRule?.destinationResource,
firstRule?.destinationResource ?? initialDestinationResource,
);
const { updateOrCreateAndNotify: checkToCreate } = usePostureCheck({});

View File

@@ -5,8 +5,6 @@ import { ExternalLinkIcon, GlobeIcon } from "lucide-react";
import Image, { StaticImageData } from "next/image";
import React, { useState } from "react";
import CloudflareLogo from "@/assets/nameservers/cloudflare.svg";
import DNS0Logo from "@/assets/nameservers/dns0.svg";
import DNS0ZeroLogo from "@/assets/nameservers/dns0-zero.svg";
import GoogleLogo from "@/assets/nameservers/google.svg";
import Quad9Logo from "@/assets/nameservers/quad9.svg";
import { Group } from "@/interfaces/Group";
@@ -66,9 +64,9 @@ export function NameserverTemplateModalContent({
onePresetSelection,
}: Readonly<ModalProps>) {
return (
<ModalContent maxWidthClass={"max-w-5xl"} showClose={true}>
<ModalContent maxWidthClass={"max-w-xl"} showClose={true}>
<div className={"px-8 py-3 flex flex-col gap-6 mt-4"}>
<div className={"grid grid-cols-1 md:grid-cols-2 gap-4"}>
<div className={"grid grid-cols-1 md:grid-cols-1 gap-4"}>
<NameserverTemplate
onClick={() => onePresetSelection(NameserverPresets.Google)}
src={GoogleLogo}
@@ -87,25 +85,6 @@ export function NameserverTemplateModalContent({
}
href={"https://www.cloudflare.com/learning/dns/what-is-1.1.1.1/"}
/>
<NameserverTemplate
onClick={() => onePresetSelection(NameserverPresets.DNS0)}
src={DNS0Logo}
title={"DNS0.EU DNS"}
description={
"A free, sovereign and GDPR-compliant DNS resolver with a strong focus on security to protect the citizens and organizations of the European Union."
}
href={"https://www.dns0.eu/"}
/>
<NameserverTemplate
onClick={() => onePresetSelection(NameserverPresets.DNS0Zero)}
src={DNS0ZeroLogo}
title={"DNS0.EU Zero DNS"}
description={
"Increase the catch rate for malicious domains by combining human-vetted threat intelligence with advanced heuristics that automatically identify high-risk patterns."
}
href={"https://www.dns0.eu/zero"}
/>
<NameserverTemplate
onClick={() => onePresetSelection(NameserverPresets.Quad9)}
src={Quad9Logo}

View File

@@ -0,0 +1,643 @@
import InlineLink from "@components/InlineLink";
import { Modal, ModalPortal } from "@components/modal/Modal";
import { NetBirdLogo } from "@components/NetBirdLogo";
import { notify } from "@components/Notification";
import { GradientFadedBackground } from "@components/ui/GradientFadedBackground";
import { DialogContent } from "@radix-ui/react-dialog";
import useFetchApi, { useApiCall } from "@utils/api";
import { cn } from "@utils/helpers";
import { isNetBirdHosted } from "@utils/netbird";
import { useRouter } from "next/navigation";
import * as React from "react";
import { useEffect, useMemo, useReducer, useState } from "react";
import { useSWRConfig } from "swr";
import { HubspotFormField } from "@/contexts/AnalyticsProvider";
import { Group } from "@/interfaces/Group";
import { Network, NetworkResource, NetworkRouter } from "@/interfaces/Network";
import type { Peer } from "@/interfaces/Peer";
import { Policy } from "@/interfaces/Policy";
import { OnboardingAddResource } from "@/modules/onboarding/networks/OnboardingAddResource";
import { OnboardingAddRoutingPeer } from "@/modules/onboarding/networks/OnboardingAddRoutingPeer";
import { OnboardingAddUserDevice } from "@/modules/onboarding/networks/OnboardingAddUserDevice";
import { OnboardingExplainPolicy } from "@/modules/onboarding/networks/OnboardingExplainPolicy";
import { OnboardingTestResource } from "@/modules/onboarding/networks/OnboardingTestResource";
import { OnboardingDevices } from "@/modules/onboarding/OnboardingDevices";
import { OnboardingEnd } from "@/modules/onboarding/OnboardingEnd";
import { OnboardingIntent } from "@/modules/onboarding/OnboardingIntent";
import { OnboardingSurvey } from "@/modules/onboarding/OnboardingSurvey";
import { OnboardingExplainDefaultPolicy } from "@/modules/onboarding/p2p/OnboardingExplainDefaultPolicy";
import { OnboardingFirstDevice } from "@/modules/onboarding/p2p/OnboardingFirstDevice";
import { OnboardingSecondDevice } from "@/modules/onboarding/p2p/OnboardingSecondDevice";
import { OnboardingTestP2P } from "@/modules/onboarding/p2p/OnboardingTestP2P";
export interface OnboardingState {
intent: Intent;
step: number;
finished_at?: string;
survey_submitted_at?: string;
skipped?: boolean;
}
export enum Intent {
P2P = "p2p",
NETWORKS = "networks",
}
type OnboardingAction =
| { type: "SET_INTENT"; payload: OnboardingState["intent"] }
| { type: "SET_FINISHED_AT"; payload: string }
| { type: "SET_STEP"; payload: number }
| { type: "SET_SURVEY_SUBMITTED_AT"; payload: string }
| { type: "RESET" }
| { type: "SKIP" };
const onboardingReducer = (
state: OnboardingState,
action: OnboardingAction,
): OnboardingState => {
switch (action.type) {
case "SET_INTENT":
return { ...state, intent: action.payload };
case "SET_STEP":
return { ...state, step: action.payload };
case "SET_FINISHED_AT":
return { ...state, finished_at: action.payload };
case "SET_SURVEY_SUBMITTED_AT":
return { ...state, survey_submitted_at: action.payload };
case "RESET":
return { intent: Intent.P2P, step: 1 };
case "SKIP":
return { ...state, skipped: true };
default:
return state;
}
};
type Props = {
initial: OnboardingState;
setLocalOnboarding: (onboarding: OnboardingState) => void;
peers: Peer[];
onSurveySubmit?: (fields: HubspotFormField[]) => void;
onSkip: (intent: Intent, step: number) => void;
onFinish: (n?: Network) => void;
formSubmitted: boolean;
onTroubleshootingClick?: (intent: Intent) => void;
isOnboardingPending: boolean;
domainCategory?: string;
};
export const Onboarding = ({
initial,
setLocalOnboarding,
peers,
onSurveySubmit,
onSkip,
onFinish,
formSubmitted,
onTroubleshootingClick,
isOnboardingPending,
domainCategory,
}: Props) => {
const { data: networks } = useFetchApi<Network[]>("/networks", true, false);
const { data: policies } = useFetchApi<Policy[]>("/policies", true);
const router = useRouter();
const resourceRequest = useApiCall<NetworkResource>("/networks", true);
const routerRequest = useApiCall<NetworkRouter>("/networks", true);
const policyRequest = useApiCall<Policy>("/policies", true);
const { mutate } = useSWRConfig();
const [onboarding, dispatch] = useReducer(onboardingReducer, initial);
const { step, intent } = onboarding;
const [resource, setResource] = useState<NetworkResource>();
const [firstRoutingPeer, setFirstRoutingPeer] = useState<Peer>();
const [useCases, setUseCases] = useState("");
const [isBusiness, setIsBusiness] = useState(false);
const firstNetwork = useMemo(() => {
return networks?.find((n) => n.name === "My First Network") ?? undefined;
}, [networks]);
const firstDevice = useMemo(() => {
return (
peers?.find((p) => p.id !== firstRoutingPeer?.id && p.user_id !== "") ??
undefined
);
}, [firstRoutingPeer?.id, peers]);
const secondDevice = useMemo(() => {
return (
peers?.find(
(p) => p.id !== firstDevice?.id && p.id !== firstRoutingPeer?.id,
) ?? undefined
);
}, [peers, firstDevice, firstRoutingPeer]);
const maxSteps = useMemo(() => {
if (intent === Intent.P2P) return 7;
return 8;
}, [intent]);
const showWaitingForDevices = useMemo(() => {
if (intent === Intent.NETWORKS) {
return step === 4 || step === 5 || step === 6 || step === 7;
} else {
return step === 3 || step === 4 || step === 5 || step === 6;
}
}, [intent, step]);
const policy = useMemo(() => {
if (intent === Intent.P2P) {
return policies?.find((p) => p.name === "Default");
} else if (resource) {
return policies?.find((p) => p.name.includes(resource?.name));
}
}, [intent, policies, resource]);
const defaultPolicy = useMemo(() => {
return policies?.find((p) => p.name === "Default");
}, [policies]);
const disableDefaultPolicy = async () => {
if (!defaultPolicy) return;
if (defaultPolicy.enabled) return await togglePolicy(defaultPolicy, true);
};
const togglePolicy = async (p: Policy, ignoreNotification = false) => {
if (!p) return;
const rule = p?.rules?.[0];
if (!rule) return;
const enabled = p?.enabled || false;
const sources = rule.sources
?.map((group) => {
const g = group as Group;
return g?.id;
})
.filter((x) => x !== undefined);
const destinations = rule.destinations
?.map((group) => {
const g = group as Group;
return g?.id;
})
.filter((x) => x !== undefined);
const request = policyRequest.put(
{
...p,
rules: [
{
...rule,
sources: sources || [],
destinations: rule.destinationResource
? undefined
: destinations || [],
},
],
enabled: !enabled,
},
`/${p.id}`,
);
if (ignoreNotification) {
return request.then(() => mutate("/policies"));
} else {
notify({
title: p.name + " Policy",
description: `Policy was successfully ${
!enabled ? "enabled" : "disabled"
}`,
loadingMessage: "Updating policy...",
promise: request.then(() => mutate("/policies")),
duration: 800,
});
}
};
useEffect(() => {
if (firstNetwork && intent === Intent.NETWORKS && !firstRoutingPeer) {
const firstRouterId = firstNetwork?.routers?.[0];
if (firstRouterId) {
routerRequest
.get(`/${firstNetwork?.id}/routers/${firstRouterId}`)
.then((r) => {
const routingPeer =
peers?.find((p) => p.id === r.peer) ?? undefined;
if (!routingPeer) return;
setFirstRoutingPeer(routingPeer);
});
}
}
}, [intent, firstNetwork, peers]);
useEffect(() => {
if (firstNetwork && intent === Intent.NETWORKS) {
const firstResourceId = firstNetwork?.resources?.[0];
if (firstResourceId) {
resourceRequest
.get(`/${firstNetwork?.id}/resources/${firstResourceId}`)
.then((r) => {
setResource(r);
});
}
}
}, [intent, firstNetwork]);
/**
* Polling every 5s if we are still waiting for devices to connect, in case browser focus does not trigger a refresh
*/
useEffect(() => {
if (
(firstDevice && secondDevice) ||
(firstDevice && firstRoutingPeer) ||
!(step === 3 || step === 4 || step === 5)
) {
return; // Stop polling if condition is met
}
const interval = setInterval(() => {
mutate("/peers");
}, 5000);
return () => clearInterval(interval); // Clean up when dependencies change
}, [firstDevice, secondDevice, firstRoutingPeer, step, mutate]);
/**
* Skip form if already submitted
*/
useEffect(() => {
if (formSubmitted && step === 1) {
dispatch({
type: "SET_STEP",
payload: 2,
});
}
}, [formSubmitted, step]);
/**
* Sync state with local storage
*/
useEffect(() => {
setLocalOnboarding(onboarding);
}, [onboarding, setLocalOnboarding]);
/**
* Prefetch the first network page if it exists for faster navigation
*/
useEffect(() => {
if (!firstNetwork) return;
router.prefetch(`/network?id=${firstNetwork.id}`);
}, [firstNetwork, router]);
return (
<Modal open={true}>
<ModalPortal>
<DialogContent
onEscapeKeyDown={(e) => e.preventDefault()}
onInteractOutside={(e) => e.preventDefault()}
onPointerDownOutside={(e) => e.preventDefault()}
asChild={true}
className={
"h-full w-screen fixed z-[50] left-0 top-0 bg-nb-gray-950 flex overflow-y-auto"
}
>
<div>
<div
className={cn(
"sm:px-4 py-10 max-w-6xl mx-auto flex flex-col items-center",
intent === Intent.P2P && step === 3 && "max-w-4xl",
intent === Intent.NETWORKS && step === 7 && "max-w-5xl",
)}
>
<NetBirdLogo size={"large"} mobile={false} />
<div
className={
"grid grid-cols-1 md:grid-cols-12 gap-4 pb-10 mt-8 sm:mt-10"
}
>
<Card
className={cn(
"max-w-2xl md:col-span-12",
step === 1 && "max-w-lg",
step === 3 &&
intent == "p2p" &&
"md:col-span-7 lg:col-span-6",
step === 4 &&
intent == "p2p" &&
"md:col-span-7 lg:col-span-6",
step === 5 &&
intent == "p2p" &&
"md:col-span-7 lg:col-span-6",
step === 6 &&
intent == "p2p" &&
"md:col-span-7 lg:col-span-6",
step === 3 && intent == "networks" && "max-w-xl ",
step === 4 &&
intent == "networks" &&
"md:col-span-7 lg:col-span-6",
step === 5 &&
intent == "networks" &&
"md:col-span-7 lg:col-span-6",
step === 6 &&
intent == "networks" &&
"md:col-span-7 lg:col-span-6",
step === 7 &&
intent == "networks" &&
"md:col-span-7 lg:col-span-6",
step === maxSteps && "max-w-2xl",
)}
>
{isOnboardingPending && (
<Stepper
step={isNetBirdHosted() ? step : step - 1}
maxSteps={isNetBirdHosted() ? maxSteps : maxSteps - 1}
/>
)}
{step === 1 && domainCategory && (
<OnboardingSurvey
domainCategory={domainCategory}
onSubmit={(fields) => {
dispatch({
type: "SET_SURVEY_SUBMITTED_AT",
payload: new Date().toISOString(),
});
onSurveySubmit?.(fields);
let u = fields?.find((f) => f.name === "use_case");
if (u) setUseCases(u.value);
let businessOrPersonal = fields?.find(
(f) => f.name === "is_company",
);
if (businessOrPersonal)
setIsBusiness(
businessOrPersonal.value === "Business",
);
if (isOnboardingPending) {
dispatch({
type: "SET_STEP",
payload: 2,
});
} else {
dispatch({
type: "SET_FINISHED_AT",
payload: new Date().toISOString(),
});
}
}}
/>
)}
{step === 2 && (
<OnboardingIntent
useCases={useCases}
isBusiness={isBusiness}
onSelect={(val) => {
dispatch({
type: "SET_INTENT",
payload: val,
});
dispatch({
type: "SET_STEP",
payload: 3,
});
}}
/>
)}
{intent === Intent.P2P && (
<>
{step === 3 && (
<OnboardingFirstDevice
firstDevice={firstDevice}
onFinish={() => {
dispatch({
type: "SET_STEP",
payload: 4,
});
}}
onBack={() => {
dispatch({
type: "SET_STEP",
payload: 2,
});
}}
/>
)}
{step === 4 && (
<OnboardingSecondDevice
secondDevice={secondDevice}
onFinish={() => {
dispatch({
type: "SET_STEP",
payload: 5,
});
}}
/>
)}
{step === 5 && (
<OnboardingTestP2P
firstDevice={firstDevice}
secondDevice={secondDevice}
onTroubleshootingClick={() =>
onTroubleshootingClick?.(intent)
}
onNext={() => {
dispatch({
type: "SET_STEP",
payload: 6,
});
}}
/>
)}
{step === 6 && (
<OnboardingExplainDefaultPolicy
policy={policy}
onToggle={togglePolicy}
onNext={() => {
dispatch({
type: "SET_STEP",
payload: 7,
});
}}
/>
)}
</>
)}
{intent === Intent.NETWORKS && (
<>
{step === 3 && (
<OnboardingAddResource
onResourceCreation={(res) => {
setResource(res);
dispatch({
type: "SET_STEP",
payload: 4,
});
mutate("/networks");
}}
onBack={() => {
dispatch({
type: "SET_STEP",
payload: 2,
});
}}
/>
)}
{step === 4 && (
<OnboardingAddRoutingPeer
network={firstNetwork}
peers={peers}
onRoutingPeerAdded={(p) => {
setFirstRoutingPeer(p);
dispatch({
type: "SET_STEP",
payload: 5,
});
}}
/>
)}
{step === 5 && (
<OnboardingAddUserDevice
device={firstDevice}
policy={policy}
onNext={() => {
dispatch({
type: "SET_STEP",
payload: 6,
});
}}
/>
)}
{step === 6 && (
<OnboardingTestResource
resource={resource}
device={firstDevice}
onTroubleshootingClick={() =>
onTroubleshootingClick?.(intent)
}
onNext={() => {
dispatch({
type: "SET_STEP",
payload: 7,
});
}}
/>
)}
{step === 7 && (
<OnboardingExplainPolicy
policy={policy}
onToggle={togglePolicy}
onNext={() => {
dispatch({
type: "SET_STEP",
payload: 8,
});
disableDefaultPolicy().then();
}}
/>
)}
</>
)}
{step === maxSteps && (
<OnboardingEnd
onFinish={() => {
dispatch({
type: "SET_FINISHED_AT",
payload: new Date().toISOString(),
});
if (intent === Intent.NETWORKS) {
onFinish(firstNetwork);
} else {
onFinish();
}
}}
/>
)}
</Card>
{showWaitingForDevices && (
<Card className={"md:col-span-5 lg:col-span-6"}>
<OnboardingDevices
intent={intent}
resource={resource}
firstDevice={firstDevice}
secondDevice={secondDevice}
firstRoutingPeer={firstRoutingPeer}
enabled={policy?.enabled}
/>
</Card>
)}
</div>
{step !== 1 && step !== maxSteps && (
<span
className={
"text-sm text-nb-gray-400 font-light pb-10 text-center px-4"
}
>
Already know how NetBird works?
<InlineLink
href={"#"}
className={"!text-nb-gray-200 ml-1"}
onClick={() => {
dispatch({
type: "SKIP",
});
onSkip(intent, step);
}}
>
Skip to Dashboard
</InlineLink>
</span>
)}
</div>
</div>
</DialogContent>
</ModalPortal>
</Modal>
);
};
const Stepper = ({ step, maxSteps }: { step: number; maxSteps: number }) => {
if (step <= 0) return;
return (
<div className={"flex gap-2 w-full items-center justify-center mb-6 mt-2"}>
{Array.from({ length: maxSteps }).map((_, index) => (
<div
key={index}
className={cn(
"w-8 h-1 rounded-full bg-nb-gray-800",
step >= index + 1 && "bg-netbird",
)}
/>
))}
</div>
);
};
const Card = ({
children,
className,
}: {
children: React.ReactNode;
className?: string;
}) => {
return (
<div
className={cn(
"px-6 sm:px-8 py-8 pt-6",
"bg-nb-gray-940 border border-nb-gray-910 rounded-lg relative",
className,
)}
>
<GradientFadedBackground className={"opacity-0"} />
{children}
</div>
);
};

View File

@@ -0,0 +1,297 @@
import TruncatedText from "@components/ui/TruncatedText";
import { getOperatingSystem } from "@hooks/useOperatingSystem";
import { cn } from "@utils/helpers";
import {
GlobeIcon,
NetworkIcon,
ShieldCheckIcon,
ShieldXIcon,
WorkflowIcon,
} from "lucide-react";
import * as React from "react";
import RoundedFlag from "@/assets/countries/RoundedFlag";
import { NetworkResource } from "@/interfaces/Network";
import { OperatingSystem } from "@/interfaces/OperatingSystem";
import type { Peer } from "@/interfaces/Peer";
import { Intent } from "@/modules/onboarding/Onboarding";
import { OSLogo } from "@/modules/peers/PeerOSCell";
type Props = {
intent?: Intent;
resource?: NetworkResource;
firstDevice?: Peer;
secondDevice?: Peer;
firstRoutingPeer?: Peer;
enabled?: boolean;
};
export const OnboardingDevices = ({
intent,
resource,
firstDevice,
secondDevice,
firstRoutingPeer,
enabled = false,
}: Props) => {
return intent === Intent.P2P ? (
<div
className={cn(
"flex h-full flex-col items-center justify-center text-center text-nb-gray-300 py-8 w-full relative",
!firstDevice && !secondDevice ? "gap-y-8" : "gap-y-2",
)}
>
<DeviceCard device={firstDevice} />
{firstDevice && secondDevice && (
<div
className={cn(
"h-[70px] w-[2px] rounded-full border-l border-dashed border-green-400 relative",
!enabled && "border-nb-gray-600",
)}
></div>
)}
{firstDevice && secondDevice && (
<div
className={
"absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 bg-nb-gray-940 p-2 "
}
>
{enabled ? (
<ShieldCheckIcon size={16} className={"text-green-500"} />
) : (
<ShieldXIcon size={16} className={"text-red-500"} />
)}
</div>
)}
<DeviceCard device={secondDevice} />
{(!firstDevice || !secondDevice) && (
<WaitingForDevice
text={
!firstDevice
? "Waiting for your first device to connect"
: "Waiting for your second device to connect"
}
/>
)}
</div>
) : (
<div
className={cn(
"flex h-full flex-col items-center justify-center text-center text-nb-gray-300 w-full",
"gap-y-2",
firstRoutingPeer && "h-full",
)}
>
{firstRoutingPeer && resource && (
<span className={"text-xs text-nb-gray-500"}>Network</span>
)}
<div
className={cn(
"flex flex-col items-center justify-center gap-y-1",
resource &&
firstRoutingPeer &&
"border px-4 py-5 bg-nb-gray-940 border-nb-gray-900 rounded-lg border-dashed",
)}
>
<DeviceCard resource={resource} />
{resource && (
<Line
className={cn(
firstRoutingPeer && firstDevice && enabled
? "bg-green-400 animate-bg-scroll-faster"
: "bg-nb-gray-600",
)}
height={"30px"}
bg={"#1c1d21"}
config={["4px", "4px", "8px", "7.5px"]}
/>
)}
<DeviceCard device={firstRoutingPeer} />
</div>
<div className={"flex flex-col items-center justify-center relative"}>
{firstRoutingPeer && (
<Line
className={cn(
firstRoutingPeer && firstDevice && enabled
? "bg-green-400 animate-bg-scroll"
: "bg-nb-gray-600",
)}
height={firstDevice && firstRoutingPeer ? "65px" : "25px"}
bg={"#1c1d21"}
/>
)}
<DeviceCard device={firstDevice} />
{(!firstDevice || !firstRoutingPeer) && (
<WaitingForDevice
text={
!firstRoutingPeer
? "Waiting for your routing peer to connect"
: "Waiting for your own device to connect"
}
/>
)}
{firstDevice && firstRoutingPeer && (
<div
className={
"absolute top-0 left-1/2 -translate-x-1/2 bg-nb-gray-940 p-1 mt-[20px]"
}
>
{enabled ? (
<ShieldCheckIcon size={16} className={"text-green-500"} />
) : (
<ShieldXIcon size={16} className={"text-red-500"} />
)}
</div>
)}
</div>
</div>
);
};
export const WaitingForDevice = ({
text = "Waiting for your first device to connect",
}: {
text: string;
}) => {
return (
<div className={"flex flex-col items-center justify-center mt-3"}>
<div className="relative h-10 w-10 mt-4">
<div className="absolute inset-0 flex items-center justify-center">
<div className="h-10 w-10 rounded-full bg-netbird/10 border border-netbird/60 animate-slow-ping "></div>
</div>
<div className="absolute top-1/2 left-1/2 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full bg-netbird z-10" />
</div>
<div className="text-sm font-light animate-slow-pulse mt-6">{text}</div>
</div>
);
};
type DeviceCardProps = {
device?: Peer;
resource?: NetworkResource;
};
export const DeviceCard = ({ device, resource }: DeviceCardProps) => {
if (!device && !resource) return;
return (
<div
className={cn(
"flex shrink-0 items-center gap-2.5 text-nb-gray-300 text-left py-1 pl-3 pr-4 rounded-md group/machine my-0 w-[200px]",
)}
>
<div
className={cn(
"flex items-center justify-center rounded-md h-9 w-9 shrink-0 bg-nb-gray-900 transition-all",
"group-hover:bg-nb-gray-800 relative",
)}
>
{device && <PeerOSIcon os={device.os} />}
{resource?.type && <ResourceIcon type={resource.type} />}
{device?.country_code && (
<div className={"absolute -bottom-[4px] -right-[4px]"}>
<div
className={cn(
"flex items-center justify-center rounded-full border-[3px] shrink-0",
"border-nb-gray-940",
)}
>
<RoundedFlag country={device?.country_code} size={10} />
</div>
</div>
)}
</div>
<div className={"flex flex-col gap-0 justify-center mt-2 leading-tight"}>
<span
className={
"mb-1.5 font-normal text-[0.85rem] text-nb-gray-100 flex items-center gap-2"
}
>
<TruncatedText
text={device?.name || resource?.name || "Unknown"}
maxWidth={"150px"}
hideTooltip={true}
/>
</span>
<span
className={
"text-sm font-normal text-nb-gray-400 -top-[0.3rem] relative"
}
>
{device?.ip || resource?.address}
</span>
</div>
</div>
);
};
const PeerOSIcon = ({ os }: { os: string }) => {
const osType = getOperatingSystem(os);
return (
<div
className={cn(
"flex items-center justify-center grayscale brightness-[100%] contrast-[40%]",
"w-4 h-4 shrink-0",
osType === OperatingSystem.WINDOWS && "p-[2.5px]",
osType === OperatingSystem.APPLE && "p-[2.7px]",
osType === OperatingSystem.FREEBSD && "p-[1.5px]",
)}
>
<OSLogo os={os} />
</div>
);
};
const ResourceIcon = ({
type,
size = 15,
}: {
type: "domain" | "host" | "subnet";
size?: number;
}) => {
switch (type) {
case "domain":
return <GlobeIcon size={size} />;
case "subnet":
return <NetworkIcon size={size} />;
case "host":
return <WorkflowIcon size={size} />;
default:
return <WorkflowIcon size={size} />;
}
};
const Line = ({
className,
height = "100%",
bg = "#1c1d21",
config = ["2px", "3px", "6px", "8.2px"],
}: {
className?: string;
height?: string;
bg?: string;
config?: string[];
}) => {
return (
<div
className={cn(
className,
"w-[1px] overflow-hidden relative -left-[0.5px]",
)}
style={{
height: height,
}}
>
<div
className={cn("absolute inset-0 w-full", className)}
style={{
backgroundImage: `repeating-linear-gradient(to bottom, transparent 0%, transparent ${config?.[0]}, ${bg} ${config?.[1]}, ${bg} ${config?.[2]})`,
backgroundSize: `100% ${config?.[3]}`,
}}
/>
</div>
);
};

View File

@@ -0,0 +1,131 @@
import { useOidcUser } from "@axa-fr/react-oidc";
import Button from "@components/Button";
import { ArrowRightIcon, PlayIcon } from "lucide-react";
import Image, { StaticImageData } from "next/image";
import Link from "next/link";
import * as React from "react";
import ACLImage from "@/assets/onboarding/acl.png";
import ActivityImage from "@/assets/onboarding/activity.png";
import PostureCheckImage from "@/assets/onboarding/posture.png";
type Props = {
onFinish?: () => void;
};
export const OnboardingEnd = ({ onFinish }: Props) => {
const { oidcUser: user } = useOidcUser();
const name = user?.given_name || user?.name || user?.preferred_username;
const title = name ? `Congratulations, ${name}!` : "Congratulations!";
return (
<div className={"relative flex flex-col h-full justify-between"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{title} <br />
Youve completed the onboarding.
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Whats next? Check out these guides to get the most out of NetBird. To
learn more, explore the dashboard, visit our documentation, or browse
our YouTube channel.
</div>
<div className={"mt-8 flex flex-col gap-8"}>
<VideoGuide
title={"Access Control in Under 5 Minutes"}
src={ACLImage}
description={
"Learn how to manage access for your network resources effectively. Whether you want to restrict access to specific machines or allow certain users to connect."
}
href={"https://www.youtube.com/watch?v=WtZD_q-g_Jc"}
/>
<VideoGuide
title={"Provision Users & Groups From Your IdP"}
src={PostureCheckImage}
description={
"Learn how to provision users and groups from your identity provider, such as Okta, Azure AD, or Google Workspace, to manage access control in NetBird and automate onboarding and offboarding processes."
}
href={"https://www.youtube.com/watch?v=RxYWTpf7cgY"}
/>
<VideoGuide
title={"How NetBird Works"}
description={
"Learn more about how NetBird works, its architecture, and how it can help you build secure networks."
}
src={ActivityImage}
href={"https://www.youtube.com/watch?v=CFa7SY4Up9k&t=261s"}
/>
</div>
<div className={"mt-10 flex items-center justify-center"}>
<Button variant={"secondaryLighter"} onClick={onFinish}>
Go to Dashboard
<ArrowRightIcon size={16} />
</Button>
</div>
</div>
</div>
);
};
type VideoGuideProps = {
src?: string | StaticImageData;
title?: string;
description?: string;
href?: string;
};
const VideoGuide = ({
src = ACLImage,
title = "Access Control in Under 5 Minutes",
description = "Learn how to manage access for your network resources effectively. Whether you want to restrict access to specific machines or allow certain users to connect.",
href = "#",
}: VideoGuideProps) => {
return (
<div
className={
"flex flex-col sm:flex-row gap-3 items-center text-center sm:text-left sm:gap-6"
}
>
<Link
className={
"border border-nb-gray-900 rounded-lg p-[2px] bg-nb-gray-920 min-w-[160px] max-w-[160px] relative group hover:bg-nb-gray-900 transition-all"
}
target={"_blank"}
href={href}
>
<span
className={
"flex items-center justify-center absolute left-0 top-0 h-full w-full"
}
>
<div
className={
"bg-nb-gray-900/50 group-hover:bg-nb-gray-600/50 backdrop-blur h-8 w-8 flex items-center justify-center rounded-full"
}
>
<PlayIcon size={14} />
</div>
</span>
<Image
src={src}
alt={title}
className={"border border-nb-gray-900 rounded-md"}
/>
</Link>
<div>
<div className={"text-md"}>{title}</div>
<div
className={"text-[0.8rem] text-nb-gray-300 font-light mt-1.5 block"}
>
{description}
</div>
</div>
</div>
);
};

View File

@@ -0,0 +1,176 @@
import FullTooltip from "@components/FullTooltip";
import {IconArrowRight} from "@tabler/icons-react";
import {cn} from "@utils/helpers";
import {HelpCircle} from "lucide-react";
import * as React from "react";
import {useMemo} from "react";
import NetworkRoutesIcon from "@/assets/icons/NetworkRoutesIcon";
import PeerIcon from "@/assets/icons/PeerIcon";
import {Intent} from "@/modules/onboarding/Onboarding";
type Props = {
onSelect: (intent: Intent) => void,
useCases?: string,
isBusiness?: boolean
};
export const OnboardingIntent = ({onSelect, useCases, isBusiness}: Props) => {
/**
* Recommend Networks if users ticks any of these use cases
*/
const isNetworksRecommended = useMemo(() => {
if (!useCases) return false;
const intents = [
"Zero Trust Security",
"Employee Remote Access",
"Business VPN",
"Site-to-Site Connectivity",
"IoT (Internet of Things)",
"MSP (Managed Service Provider)",
];
for (const intent of intents) {
if (useCases.toLowerCase().includes(intent.toLowerCase())) {
return true;
}
}
return false;
}, [useCases]);
/**
* Recommend P2P if users ticks any of these use cases
*/
const isP2PRecommended = useMemo(() => {
if (!useCases) return false;
const intents = [
"Homelab Automation",
"Home Remote Access",
"File Access",
"Gaming",
];
for (const intent of intents) {
if (useCases.toLowerCase().includes(intent.toLowerCase())) {
return true;
}
}
return false;
}, [useCases]);
return (
<div className={"relative flex flex-col h-full justify-between"}>
<div>
<h1 className={"text-xl text-center"}>Get started with NetBird</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
NetBird provides the flexibility of both a peer-to-peer overlay network and a remote network access
solution.
Choose what fits your needs, you can always combine both.
</div>
<div
className={cn(
"grid grid-cols-1 mt-8",
"border border-nb-gray-900 rounded-lg flex items-start flex-col relative bg-nb-gray-930/60 transition-all ",
)}
>
<IntentCard
title={"Peer-to-Peer Network"}
description={
isBusiness ? "Install NetBird on two or more devices to create secure, direct WireGuard connections, like laptop to server or server to database. Add at least two machines to get started." :"Install NetBird on two or more devices in your homelab, such as your laptop, NAS, or Raspberry Pi, to create secure, direct WireGuard connections."
}
recommended={isP2PRecommended}
icon={<PeerIcon size={18} className={"fill-netbird"}/>}
onClick={() => onSelect(Intent.P2P)}
/>
<IntentCard
title={"Remote Network Access"}
description={
isBusiness ? "Enable employee remote access to VMs, Kubernetes clusters, and cloud or on-prem resources without installing NetBird on every machine." : "Securely access your homelab remotely from anywhere without installing NetBird on every device."
}
recommended={isNetworksRecommended}
icon={<NetworkRoutesIcon size={18} className={"fill-netbird"}/>}
onClick={() => onSelect(Intent.NETWORKS)}
/>
</div>
</div>
</div>
);
};
type IntentCardProps = {
title: string;
description: string;
icon: React.ReactNode;
onClick: () => void;
recommended?: boolean;
};
const IntentCard = ({
title,
description,
icon,
onClick,
recommended,
}: IntentCardProps) => {
return (
<button
className={
"px-6 py-6 flex items-start flex-col relative hover:bg-nb-gray-920 transition-all group first:border-b border-nb-gray-900"
}
onClick={onClick}
>
<div className={"flex gap-6"}>
<div
className={cn(
"h-10 w-10 flex items-center justify-center rounded-md shrink-0 mt-2",
"bg-nb-gray-900 border border-nb-gray-800 ",
)}
>
{icon}
</div>
<div className={"flex gap-4 items-center"}>
<div className={"text-left"}>
<h2
className={
"text-base font-medium mb-.5 group-hover:text-netbird transition-all inline-flex gap-x-2 gap-y-1 flex-wrap"
}
>
{title}
{recommended && (
<FullTooltip
content={
<div className={"text-xs max-w-xs"}>
Based on your previous choices, we recommend starting with{" "}
{title}. You can always combine both options later.
</div>
}
>
<span
className={cn(
"relative",
"inline-flex text-[0.7rem] font-light bg-netbird/10 border border-netbird-400/30 text-netbird-400 rounded-full px-2 py-1 pb-0.5 leading-none",
"hover:bg-netbird/20 cursor-help transition-all self-center",
)}
>
Recommended
<HelpCircle size={10} className={"ml-1"}/>
</span>
</FullTooltip>
)}
</h2>
<p className={"!text-nb-gray-300 text-[.85rem]"}>{description}</p>
</div>
<div
className={"h-full items-center text-nb-gray-400 hidden sm:flex"}
>
<IconArrowRight
size={24}
className={"shrink-0 group-hover:text-netbird"}
/>
</div>
</div>
</div>
</button>
);
};

View File

@@ -0,0 +1,39 @@
import { ToggleSwitch } from "@components/ToggleSwitch";
import { cn } from "@utils/helpers";
import { ShieldIcon } from "lucide-react";
import * as React from "react";
import { Policy } from "@/interfaces/Policy";
type Props = {
policy?: Policy;
onToggle?: (policy: Policy) => void;
};
export const OnboardingPolicy = ({ policy, onToggle }: Props) => {
if (!policy) return;
return (
<label
className={cn(
"relative block rounded-lg border border-nb-gray-900 px-5 py-3 transition-all",
"flex justify-between items-center mt-3 cursor-pointer",
)}
>
<div>
<div className="text-nb-gray-100 font-normal text-sm text-left gap-2 flex items-center">
<ShieldIcon size={12} className={"shrink-0"} />
{policy?.name} Policy
</div>
<div className={"text-nb-gray-300 text-[0.8rem] text-left mt-0.5"}>
{policy?.name.includes("Default")
? "Allows connections between all your devices"
: policy?.description}
</div>
</div>
<ToggleSwitch
onCheckedChange={() => onToggle?.(policy)}
checked={policy?.enabled || false}
/>
</label>
);
};

View File

@@ -0,0 +1,170 @@
import { useLocalStorage } from "@hooks/useLocalStorage";
import useFetchApi, { useApiCall } from "@utils/api";
import { isLocalDev, isNetBirdHosted } from "@utils/netbird";
import { useRouter, useSearchParams } from "next/navigation";
import { useMemo } from "react";
import { useSWRConfig } from "swr";
import { HubspotFormField, useAnalytics } from "@/contexts/AnalyticsProvider";
import { useLoggedInUser } from "@/contexts/UsersProvider";
import { Account } from "@/interfaces/Account";
import { Network } from "@/interfaces/Network";
import type { Peer } from "@/interfaces/Peer";
import { useAccount } from "@/modules/account/useAccount";
import {
Intent,
Onboarding,
OnboardingState,
} from "@/modules/onboarding/Onboarding";
type Props = {
onSurveySubmit?: (data: {
fields: HubspotFormField[];
hsId: string;
gaId: string;
accountId?: string;
userId?: string;
}) => void;
domainCategory?: string;
};
export const OnboardingProvider = ({
onSurveySubmit,
domainCategory,
}: Props) => {
const { data: peers } = useFetchApi<Peer[]>("/peers");
const accountRequest = useApiCall<Account>("/accounts", true);
const account = useAccount();
const router = useRouter();
const { isOwner, loggedInUser } = useLoggedInUser();
const { mutate } = useSWRConfig();
const { trackEventV2 } = useAnalytics();
const params = useSearchParams();
const hsId = params?.get("hs_id") ?? "";
const gaId = params?.get("ga_id") ?? "";
const accountId = account?.id ?? "unknown";
const onboardingKey = `netbird-onboarding-flow:${accountId}`;
// Migrate old onboarding state to new key if needed
if (typeof window !== "undefined" && account?.id) {
const oldKey = "netbird-onboarding-flow";
const oldValue = window.localStorage.getItem(oldKey);
const newValue = window.localStorage.getItem(onboardingKey);
if (oldValue && !newValue) {
window.localStorage.setItem(onboardingKey, oldValue);
window.localStorage.removeItem(oldKey);
}
}
const [onboarding, setOnboarding] = useLocalStorage<OnboardingState>(
onboardingKey,
{
intent: Intent.P2P,
step: 1,
},
);
const showOnboarding = useMemo(() => {
if (process.env.APP_ENV === "test") return false;
if (!account) return false;
const isSignupFormPending = isNetBirdHosted()
? !!account?.onboarding?.signup_form_pending
: false;
const show =
!!account?.onboarding?.onboarding_flow_pending || isSignupFormPending;
return isOwner && show;
}, [account, isOwner]);
const updateAccountMeta = async (meta: Partial<Account["onboarding"]>) => {
if (!account) return;
await accountRequest
.put(
{
...account,
id: account.id,
onboarding: {
...account.onboarding,
...meta,
},
},
`/${account.id}`,
)
.then(() => mutate("/accounts"));
};
const onSkip = async (intent: Intent, step: number) => {
await updateAccountMeta({
onboarding_flow_pending: false,
});
trackEventV2(
"Onboarding",
`Skipped Onboarding - ${intent} (Step ${step})`,
account?.id,
loggedInUser?.id,
);
};
const onFinish = async (n?: Network) => {
await updateAccountMeta({
onboarding_flow_pending: false,
});
trackEventV2(
"Onboarding",
"Finished Onboarding",
account?.id,
loggedInUser?.id,
);
if (n) {
// router.push(`/network?id=${n.id}`);
router.push("/control-center?tab=networks");
} else {
router.push("/control-center");
}
};
const onTroubleshootingClick = (intent: Intent) => {
trackEventV2(
"Onboarding",
`Troubleshooting - ${intent}`,
account?.id,
loggedInUser?.id,
);
};
const submitSurvey = async (fields: HubspotFormField[]) => {
await updateAccountMeta({
signup_form_pending: false,
});
if (isLocalDev()) return;
onSurveySubmit?.({
fields,
hsId,
gaId,
accountId: account?.id,
userId: loggedInUser?.id,
});
};
const formSubmitted = isNetBirdHosted()
? !account?.onboarding?.signup_form_pending
: true;
return (
<>
{showOnboarding && peers && (
<Onboarding
formSubmitted={formSubmitted}
isOnboardingPending={!!account?.onboarding?.onboarding_flow_pending}
initial={onboarding}
setLocalOnboarding={setOnboarding}
peers={peers}
onSurveySubmit={submitSurvey}
onTroubleshootingClick={onTroubleshootingClick}
onSkip={onSkip}
onFinish={onFinish}
domainCategory={domainCategory}
/>
)}
</>
);
};

View File

@@ -0,0 +1,516 @@
import { useOidcUser } from "@axa-fr/react-oidc";
import Button from "@components/Button";
import ButtonGroup from "@components/ButtonGroup";
import { Checkbox } from "@components/Checkbox";
import HelpText from "@components/HelpText";
import { Input } from "@components/Input";
import { Label } from "@components/Label";
import { SegmentedTabs } from "@components/SegmentedTabs";
import { SelectDropdown } from "@components/select/SelectDropdown";
import { cn } from "@utils/helpers";
import {
BriefcaseIcon,
FolderIcon,
Gamepad2,
HomeIcon,
Laptop,
Layers,
Server,
ShieldCheck,
UserIcon,
Waypoints,
} from "lucide-react";
import React, { useMemo, useState } from "react";
import { useLoggedInUser } from "@/contexts/UsersProvider";
import { HubspotFormField } from "@/contexts/AnalyticsProvider";
type Props = {
domainCategory: string;
onSubmit?: (fields: HubspotFormField[]) => void;
};
export const companySizes = [
{
label: "1-5",
value: "1",
},
{
label: "5-50",
value: "5",
},
{
label: "50-300",
value: "50",
},
{
label: "300-1000",
value: "300",
},
{
label: "1000+",
value: "1000",
},
];
export const referralSourceOptions = [
{
label: "Search Engines (Google, Bing etc.)",
value: "Search Engines (Google, Bing etc.)",
},
{
label: "Coworker or Friend",
value: "Coworker or Friend",
},
{
label: "Trade Show or Event",
value: "Trade Show or Event",
},
{
label: "Blogs",
value: "Blogs",
},
{
label: "Comparison Sites",
value: "Comparison Sites",
},
{
label: "Slack",
value: "Slack",
},
{
label: "Other",
value: "Other",
},
{
label: "NetBird YouTube Channel",
value: "NetBird YouTube Channel",
},
{
label: "Other YouTube Channel",
value: "Other YouTube Channel",
},
{
label: "NetBird SubReddit",
value: "NetBird SubReddit",
},
{
label: "Other Reddit Thread",
value: "Other Reddit Thread",
},
{
label: "GitHub",
value: "GitHub",
},
];
export const OnboardingSurvey = ({ domainCategory, onSubmit }: Props) => {
const { oidcUser: user } = useOidcUser();
const name = user?.given_name || user?.name || user?.preferred_username;
const welcomeMessage = name
? `Welcome to NetBird, ${name}!`
: "Welcome to NetBird!";
const isPrivate = domainCategory === "private";
const [personalOrBusiness, setPersonalOrBusiness] = useState(
isPrivate ? "business" : "personal",
);
const [companySize, setCompanySize] = useState<string>("");
const isCompanySizeSelected = (size: string) => companySize === size;
const isBusiness = personalOrBusiness === "business";
const [homelab, setHomelab] = useState(false);
const [remoteAccess, setRemoteAccess] = useState(false);
const [homeRemoteAccess, setHomeRemoteAccess] = useState(false);
const [fileAccess, setFileAccess] = useState(false);
const [gaming, setGaming] = useState(false);
const [zeroTrust, setZeroTrust] = useState(false);
const [ioT, setIoT] = useState(false);
const [siteToSite, setSiteToSite] = useState(false);
const [businessVPN, setBusinessVPN] = useState(false);
const [referralSource, setReferralSource] = useState("");
const [msp, setMsp] = useState(false);
const [other, setOther] = useState(false);
const [otherUseCase, setOtherUseCase] = useState("");
const inputRef = React.useRef<HTMLInputElement>(null);
const { loggedInUser } = useLoggedInUser();
const getUseCases = () => {
const hl = homelab && !isBusiness ? "Homelab Automation" : "";
const hra = homeRemoteAccess && !isBusiness ? "Home Remote Access" : "";
const fa = fileAccess && !isBusiness ? "File Access" : "";
const g = gaming && !isBusiness ? "Gaming" : "";
const zt = zeroTrust && isBusiness ? "Zero Trust Security" : "";
const ra = remoteAccess && isBusiness ? "Employee Remote Access" : "";
const bv = businessVPN && isBusiness ? "Business VPN" : "";
const st = siteToSite && isBusiness ? "Site-to-Site Connectivity" : "";
const iot = ioT && isBusiness ? "IoT (Internet of Things)" : "";
const mp = msp && isBusiness ? "MSP (Managed Service Provider)" : "";
const ou = other ? otherUseCase : "";
return [hl, hra, fa, g, zt, ra, bv, st, iot, mp, ou]
.filter((s) => s != "")
.join(", ");
};
const hasSelectedUseCase = useMemo(() => {
if (isBusiness) {
return (
zeroTrust ||
remoteAccess ||
businessVPN ||
siteToSite ||
ioT ||
msp ||
(other && otherUseCase !== "")
);
} else {
return (
homelab ||
homeRemoteAccess ||
fileAccess ||
gaming ||
(other && otherUseCase !== "")
);
}
}, [
businessVPN,
fileAccess,
gaming,
homeRemoteAccess,
homelab,
ioT,
isBusiness,
other,
otherUseCase,
remoteAccess,
siteToSite,
zeroTrust,
msp,
]);
const hasCompanySizeSelected = useMemo(() => {
return companySize !== "";
}, [companySize]);
const hasHowDidYouHearAboutUsSelected = useMemo(() => {
return referralSource !== "";
}, [referralSource]);
const canSubmit = useMemo(() => {
if (isBusiness) {
return (
hasCompanySizeSelected &&
hasSelectedUseCase &&
hasHowDidYouHearAboutUsSelected
);
} else {
return hasSelectedUseCase && hasHowDidYouHearAboutUsSelected;
}
}, [
hasSelectedUseCase,
isBusiness,
hasCompanySizeSelected,
hasHowDidYouHearAboutUsSelected,
]);
const randomizedOptions = useMemo(() => {
return referralSourceOptions.sort(() => Math.random() - 0.5);
}, []);
const submitForm = () => {
let fields: HubspotFormField[] = [];
try {
// Fallback: use OIDC user email if loggedInUser?.email is missing
const email = loggedInUser?.email || user?.email || "";
if (loggedInUser || user) {
fields = [
{
name: "email",
value: email,
},
{
name: "is_company",
value: personalOrBusiness === "business" ? "Business" : "Personal",
},
{
name: "use_case",
value: getUseCases(),
},
{
name: "how_did_you_hear_about_us",
value: referralSource || "Other",
},
];
let accountCategory;
switch (personalOrBusiness) {
case "business":
accountCategory = "business";
break;
case "personal":
accountCategory = "personal";
break;
default:
accountCategory = "unknown";
}
fields.push({
name: "account_category",
value: accountCategory,
});
if (domainCategory) {
if (domainCategory === "business") {
fields.push({
name: "0-2/domain",
value: email.split("@")[1] || "",
});
}
}
if (personalOrBusiness === "business" && companySize !== "") {
fields.push({
name: "planned_users",
value: companySize,
});
}
}
} catch (e) {}
onSubmit?.(fields);
};
return (
<>
<div className={"relative"}>
<h1 className={"text-xl text-center"}>{welcomeMessage}</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center max-w-md px-10"
}
>
Share a few details about your use case to help us get you started
smoothly.
</div>
<div className={"flex flex-col mt-8 z-0 gap-8"}>
<SegmentedTabs
value={personalOrBusiness}
onChange={setPersonalOrBusiness}
>
<SegmentedTabs.List className={"rounded-lg border"}>
<SegmentedTabs.Trigger value={"business"}>
<BriefcaseIcon size={16} />
Business
</SegmentedTabs.Trigger>
<SegmentedTabs.Trigger value={"personal"}>
<UserIcon size={16} />
Personal
</SegmentedTabs.Trigger>
</SegmentedTabs.List>
</SegmentedTabs>
{personalOrBusiness === "business" && (
<div className={"flex w-full flex-col gap-2"}>
<div>
<Label>
How many people in your company will use NetBird?
<RequiredAsterisk />
</Label>
</div>
<ButtonGroup>
{companySizes.map((size) => (
<ButtonGroup.Button
key={size.value}
className={"w-full"}
onClick={() => setCompanySize(size.value)}
variant={
isCompanySizeSelected(size.value)
? "tertiary"
: "secondary"
}
>
{size.label}
</ButtonGroup.Button>
))}
</ButtonGroup>
</div>
)}
<div className={"flex w-full flex-col gap-2"}>
<Label>
How did you hear about NetBird?
<RequiredAsterisk />
</Label>
<SelectDropdown
value={referralSource}
onChange={setReferralSource}
options={randomizedOptions}
showValues={false}
placeholder={"Please select an option..."}
variant={"dropdown"}
/>
</div>
<div className={"flex w-full flex-col gap-2"}>
<div>
<Label>
How do you plan to use NetBird?
<RequiredAsterisk />
</Label>
<HelpText className={"mt-1.5"}>
You can also select multiple use cases.
</HelpText>
</div>
<div className={"flex flex-col gap-3"}>
{isBusiness ? (
<>
<OnboardingCheckbox value={zeroTrust} setValue={setZeroTrust}>
<ShieldCheck size={16} />
Zero Trust Security
</OnboardingCheckbox>
<OnboardingCheckbox
value={remoteAccess}
setValue={setRemoteAccess}
>
<Laptop size={16} />
Employee Remote Access
</OnboardingCheckbox>
<OnboardingCheckbox
value={businessVPN}
setValue={setBusinessVPN}
>
<BriefcaseIcon size={16} />
Business VPN
</OnboardingCheckbox>
<OnboardingCheckbox
value={siteToSite}
setValue={setSiteToSite}
>
<Layers size={16} />
Site-to-Site Connectivity
</OnboardingCheckbox>
<OnboardingCheckbox value={ioT} setValue={setIoT}>
<Waypoints size={16} />
IoT (Internet of Things)
</OnboardingCheckbox>
<OnboardingCheckbox value={msp} setValue={setMsp}>
<Server size={15} />
MSP (Managed Service Provider)
</OnboardingCheckbox>
</>
) : (
<>
<OnboardingCheckbox value={homelab} setValue={setHomelab}>
<HomeIcon size={16} />
Homelab Automation
</OnboardingCheckbox>
<OnboardingCheckbox
value={homeRemoteAccess}
setValue={setHomeRemoteAccess}
>
<Laptop size={16} />
Home Remote Access
</OnboardingCheckbox>
<OnboardingCheckbox
value={fileAccess}
setValue={setFileAccess}
>
<FolderIcon size={16} />
File Access
</OnboardingCheckbox>
<OnboardingCheckbox value={gaming} setValue={setGaming}>
<Gamepad2 size={16} />
Gaming
</OnboardingCheckbox>
</>
)}
<label
className={
"text-neutral-500 dark:text-nb-gray-300 font-normal flex items-center gap-4 cursor-pointer"
}
>
<Checkbox
checked={other}
onCheckedChange={(v) => {
setOther(!other);
inputRef.current?.focus();
}}
/>
<div
className={
"flex items-center gap-1.5 whitespace-nowrap text-sm select-none"
}
>
Other (Please specify)
</div>
</label>
</div>
<div
className={cn(
!other && "!h-0 opacity-0",
"mt-2",
other && "mb-3",
)}
>
<Input
ref={inputRef}
placeholder={
isBusiness
? "e.g. DNS Management, File Access"
: "e.g. DNS Management, IoT"
}
value={otherUseCase}
onChange={(e) => setOtherUseCase(e.target.value)}
/>
</div>
</div>
</div>
</div>
<Button
variant={"primary"}
className={"w-full mt-4"}
onClick={submitForm}
disabled={!canSubmit}
>
Continue
</Button>
</>
);
};
const OnboardingCheckbox = ({
value,
setValue,
children,
}: {
value: boolean;
setValue: (value: boolean) => void;
children: React.ReactNode;
}) => {
return (
<label
className={
"text-neutral-500 dark:text-nb-gray-300 font-normal flex items-center gap-4 cursor-pointer"
}
>
<Checkbox checked={value} onCheckedChange={setValue} />
<div
className={
"flex items-center gap-1.5 whitespace-nowrap text-sm select-none"
}
>
{children}
</div>
</label>
);
};
const RequiredAsterisk = () => (
<span className={"text-red-500 relative -top-[2.5px]"}>*</span>
);

View File

@@ -0,0 +1,259 @@
import Button from "@components/Button";
import { notify } from "@components/Notification";
import { RadioCard, RadioCardGroup } from "@components/RadioCard";
import { useApiCall } from "@utils/api";
import { GlobeIcon, NetworkIcon, WorkflowIcon } from "lucide-react";
import * as React from "react";
import { useMemo, useState } from "react";
import { useSWRConfig } from "swr";
import { useGroups } from "@/contexts/GroupsProvider";
import { Group } from "@/interfaces/Group";
import { Network, NetworkResource } from "@/interfaces/Network";
import { Policy } from "@/interfaces/Policy";
import { ResourceSingleAddressInput } from "@/modules/networks/resources/ResourceSingleAddressInput";
type Props = {
onNetworkCreation?: (network: Network) => void;
onResourceCreation?: (resource: NetworkResource) => void;
onBack: () => void;
};
export const OnboardingAddResource = ({
onNetworkCreation,
onResourceCreation,
onBack,
}: Props) => {
const [resourceType, setResourceType] = useState("");
const [resourceAddress, setResourceAddress] = useState("");
const [error, setError] = useState("");
const [network, setNetwork] = useState<Network>();
const { mutate } = useSWRConfig();
const { groups } = useGroups();
const networkRequest = useApiCall<Network>("/networks", true);
const resourceRequest = useApiCall<NetworkResource>("/networks", true);
const policyRequest = useApiCall<Policy>("/policies", true);
const groupRequest = useApiCall<Group>("/groups", true);
const allGroupId = groups?.find((g) => g.name === "All")?.id;
/**
* Create a new network and add a resource to it
*/
const createResource = async () => {
let myNetwork = network;
if (!network) {
await networkRequest
.post({
name: "My First Network",
description: "Created during onboarding",
})
.then((n) => {
myNetwork = n;
onNetworkCreation?.(n);
setNetwork(n);
});
}
if (!myNetwork) return;
notify({
title: "My First Network",
description: "Network & Resource created successfully",
loadingMessage: "Creating your resource...",
promise: resourceRequest
.post(
{
name: resourceType === "subnet" ? "My Subnet" : "My Resource",
description: "Created during onboarding",
address: resourceAddress,
enabled: true,
groups: [],
},
`/${myNetwork.id}/resources`,
)
.then((r) => {
onResourceCreation?.(r);
createOnboardingGroups().then(({ usersGroup, routingPeersGroup }) => {
createUsersToResourcePolicy(r, usersGroup);
createUsersToRoutingPeersPolicy(r, usersGroup, routingPeersGroup);
});
}),
});
};
/**
* Create Users and Routing Peers groups if they do not exist
*/
const createOnboardingGroups = async () => {
let usersGroup = groups?.find((group) => group.name === "Users");
let routingPeersGroup = groups?.find(
(group) => group.name === "Routing Peers",
);
if (!usersGroup) {
usersGroup = await groupRequest.post({
name: "Users",
});
}
if (!routingPeersGroup) {
routingPeersGroup = await groupRequest.post({
name: "Routing Peers",
});
}
return {
usersGroup,
routingPeersGroup,
};
};
/**
* Create a policy that allows users to access the resource
*/
const createUsersToResourcePolicy = async (
r: NetworkResource,
usersGroup: Group,
) => {
const isSubnet = r.type === "subnet";
await policyRequest.post({
name: `Users to ${r.name}`,
description: `Allows access to this ${
isSubnet ? `subnet ${r.address}` : `resource ${r.address}`
}`,
enabled: true,
rules: [
{
name: `Users to ${r.name}`,
description: `Allows access to this ${
isSubnet ? `subnet ${r.address}` : `resource ${r.address}`
}`,
enabled: true,
action: "accept",
bidirectional: true,
protocol: "all",
sources: usersGroup ? [usersGroup.id] : [allGroupId],
destinationResource: {
type: r.type,
id: r.id,
},
},
],
});
};
/**
* Create a policy that allows users to access routing peers
*/
const createUsersToRoutingPeersPolicy = async (
r: NetworkResource,
usersGroup: Group,
routingPeersGroup: Group,
) => {
await policyRequest
.post({
name: `Users to Routing Peers`,
description: `Allows users to access routing peers`,
enabled: true,
rules: [
{
name: `Users to Routing Peers`,
description: `Allows users to access routing peers`,
enabled: true,
action: "accept",
bidirectional: true,
protocol: "all",
sources: usersGroup ? [usersGroup.id] : [allGroupId],
destinations: routingPeersGroup
? [routingPeersGroup.id]
: [allGroupId],
},
],
})
.then(() => {
mutate("/policies");
mutate("/groups");
});
};
const description = useMemo(() => {
if (resourceType === "ip")
return "Enter a single IPv4 address of your resource";
if (resourceType === "subnet") return "Enter a CIDR range of your network";
if (resourceType === "domain")
return "Enter a domain name of your resource";
}, [resourceType]);
const placeholder = useMemo(() => {
if (resourceType === "ip") return "e.g., 192.168.31.45";
if (resourceType === "subnet") return "e.g., 192.168.1.0/24";
if (resourceType === "domain")
return "e.g., service.internal or *.services.internal";
}, [resourceType]);
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div className={"flex flex-col gap-8"}>
<div>
<h1 className={"text-xl text-center"}>Add your first resource</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Resources are your subnets, services, or machines inside your network.
Pick the type you want to connect to.
</div>
</div>
<RadioCardGroup value={resourceType} onValueChange={setResourceType}>
<RadioCard
value={"ip"}
title={"Single IP Address"}
icon={<WorkflowIcon size={12} />}
description={"IPv4 address like 192.168.31.45"}
/>
<RadioCard
value={"subnet"}
title={"Entire Subnet"}
icon={<NetworkIcon size={12} />}
description={"CIDR range like 192.168.0.0/24"}
/>
<RadioCard
value={"domain"}
title={"Domain"}
icon={<GlobeIcon size={12} />}
description={
"A domain like service.internal or a wildcard like *.services.internal"
}
/>
</RadioCardGroup>
{resourceType && (
<ResourceSingleAddressInput
label={"What is the address of your resource?"}
value={resourceAddress}
onChange={setResourceAddress}
onError={setError}
description={description}
placeholder={placeholder}
/>
)}
<div className={"flex gap-4"}>
<Button variant={"secondary"} className={"w-full"} onClick={onBack}>
Go Back
</Button>
<Button
variant={"primary"}
className={"w-full"}
onClick={createResource}
disabled={resourceAddress === "" || error !== ""}
>
Create Resource
</Button>
</div>
</div>
</div>
);
};

View File

@@ -0,0 +1,185 @@
import Button from "@components/Button";
import { Modal, ModalContent } from "@components/modal/Modal";
import { notify } from "@components/Notification";
import { useApiCall } from "@utils/api";
import { cn } from "@utils/helpers";
import { CopyIcon, DownloadIcon, KeyRoundIcon } from "lucide-react";
import * as React from "react";
import { useEffect, useState } from "react";
import { useGroups } from "@/contexts/GroupsProvider";
import { Group } from "@/interfaces/Group";
import { Network, NetworkRouter } from "@/interfaces/Network";
import { Peer } from "@/interfaces/Peer";
import { SetupKey } from "@/interfaces/SetupKey";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";
type Props = {
network?: Network;
peers?: Peer[];
onRoutingPeerAdded: (peer: Peer) => void;
};
export const OnboardingAddRoutingPeer = ({
network,
peers,
onRoutingPeerAdded,
}: Props) => {
const [open, setOpen] = useState(false);
const [setupKey, setSetupKey] = useState<SetupKey>();
const { groups } = useGroups();
const setupKeyRequest = useApiCall<SetupKey>("/setup-keys", true);
const groupRequest = useApiCall<Group>("/groups", true);
const routerRequest = useApiCall<NetworkRouter>("/networks", true);
/**
* Generate a new setup key for the routing peer
*/
const generateSetupKey = async () => {
let routingPeerGroup = groups?.find(
(group) => group.name === "Routing Peers",
);
if (!routingPeerGroup) {
routingPeerGroup = await groupRequest.post({
name: "Routing Peers",
});
}
notify({
title: "Setup Key Created",
description: "Successfully copied to clipboard.",
loadingMessage: "Generating setup key...",
promise: setupKeyRequest
.post({
name: "Routing Peer (My First Network)",
type: "one-off",
expires_in: 24 * 60 * 60, // 1 day expiration
revoked: false,
auto_groups: routingPeerGroup ? [routingPeerGroup.id] : [],
usage_limit: 1,
ephemeral: false,
allow_extra_dns_labels: false,
})
.then((setupKey) => {
setSetupKey(setupKey);
copySetupKey(setupKey.key);
}),
});
};
/**
* Detect routing peer based on group and add it to the network
*/
useEffect(() => {
const routingPeer = peers?.find(
(p) => p.groups?.some((g) => g.name === "Routing Peers"),
);
const hasNetworkRoutingPeer =
network?.routers?.find((r) => r === routingPeer?.id) !== undefined;
if (routingPeer && network && !hasNetworkRoutingPeer) {
routerRequest
.post(
{
peer: routingPeer.id,
metric: 9999,
masquerade: true,
enabled: true,
},
`/${network.id}/routers`,
)
.then(() => {
onRoutingPeerAdded(routingPeer);
});
}
}, [network, peers]);
/**
* Copy the setup key to clipboard
*/
const copySetupKey = async (key: string, showMessage = false) => {
try {
await navigator.clipboard.writeText(key || "");
if (showMessage) {
notify({
title: "Setup Key Copied",
description: "Successfully copied to clipboard.",
});
}
} catch (e) {}
};
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center"}>
Add a routing peer and get the traffic flowing
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Think of a routing peer as a connector to your internal network.
It runs NetBird and lets your remote devices access internal resources, while enforcing access control policies.
</div>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Generate a setup key and install NetBird on that machine.
</div>
</div>
<div
className={cn(
"relative block rounded-lg border border-nb-gray-900 px-5 py-3 transition-all",
"flex justify-between items-center mt-3",
)}
>
<div>
<div className="text-nb-gray-100 font-normal text-sm text-left gap-2 flex items-center">
<KeyRoundIcon size={12} />
Setup-Key
</div>
<div className={"text-nb-gray-300 text-[0.8rem] text-left mt-0.5"}>
{setupKey?.key || "Not yet generated"}
</div>
</div>
{setupKey ? (
<Button
variant={"secondary"}
onClick={() => copySetupKey(setupKey.key, true)}
>
<CopyIcon size={14} />
</Button>
) : (
<Button variant={"primary"} onClick={generateSetupKey} size={"xs"}>
Generate Setup Key
</Button>
)}
</div>
<Button
variant={"primary"}
className={""}
disabled={!setupKey}
onClick={() => setOpen(true)}
>
<DownloadIcon size={16} />
Install Routing Peer
</Button>
{setupKey && (
<Modal open={open} onOpenChange={setOpen}>
<ModalContent>
<SetupModalContent
hostname={"routing-peer"}
title={"Install NetBird"}
setupKey={setupKey.key}
/>
</ModalContent>
</Modal>
)}
</div>
);
};

View File

@@ -0,0 +1,95 @@
import Button from "@components/Button";
import { Modal, ModalContent } from "@components/modal/Modal";
import { useApiCall } from "@utils/api";
import { DownloadIcon } from "lucide-react";
import * as React from "react";
import { useEffect, useMemo, useState } from "react";
import { useSWRConfig } from "swr";
import { Group, GroupPeer } from "@/interfaces/Group";
import { Peer } from "@/interfaces/Peer";
import { Policy } from "@/interfaces/Policy";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";
type Props = {
device?: Peer;
policy?: Policy;
onNext?: () => void;
};
export const OnboardingAddUserDevice = ({ device, policy, onNext }: Props) => {
const groupRequest = useApiCall<Group>("/groups", true);
const { mutate } = useSWRConfig();
const [open, setOpen] = useState(false);
const usersGroup = useMemo(() => {
let rule = policy?.rules?.[0];
const sourceGroups = rule?.sources as Group[];
return sourceGroups?.find((g) => g.name === "Users");
}, [policy]);
const hasDeviceUsersGroup = device?.groups?.find((g) => g.name === "Users");
/**
* Detect the device and add it to the "Users" group
*/
useEffect(() => {
if (!hasDeviceUsersGroup && usersGroup && device) {
let peersOfGroup = (usersGroup.peers as GroupPeer[]) || [];
let newPeers = peersOfGroup
.map((p) => p.id)
.filter((x) => x !== undefined);
if (device?.id) newPeers.push(device.id);
groupRequest
.put(
{
...usersGroup,
peers: newPeers,
},
`/${usersGroup.id}`,
)
.then(() => {
mutate("/peers");
mutate("/groups");
});
}
}, [usersGroup, device, hasDeviceUsersGroup]);
/**
* Continue to next step once device is recognized
*/
useEffect(() => {
if (device && hasDeviceUsersGroup) {
onNext?.();
}
}, [device, hasDeviceUsersGroup]);
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{"Time to add your client device"}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{`Your first resource and routing peer are all set. Now, take your device, install NetBird, and let's get you connected.`}
</div>
</div>
<div className={"flex items-center justify-center mt-3"}>
<Button variant={"primary"} onClick={() => setOpen(true)}>
<DownloadIcon size={16} />
Install NetBird
</Button>
</div>
<Modal open={open} onOpenChange={setOpen}>
<ModalContent>
<SetupModalContent title={"Install NetBird"} hideDocker={true} />
</ModalContent>
</Modal>
</div>
);
};

View File

@@ -0,0 +1,52 @@
import Button from "@components/Button";
import * as React from "react";
import { Policy } from "@/interfaces/Policy";
import { OnboardingPolicy } from "@/modules/onboarding/OnboardingPolicy";
type Props = {
policy?: Policy;
onNext?: () => void;
onToggle?: (policy: Policy) => void;
};
export const OnboardingExplainPolicy = ({
policy,
onNext,
onToggle,
}: Props) => {
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{`Set the rules. You're in control`}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{`NetBird makes it easy for admins to enforce least-privilege access with access control policies.
We've already created one for your resource during onboarding.`}
</div>
{policy && (
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Flip the switch, then try pinging your resource again to see how it affects the connection.
</div>
)}
</div>
<div>
<OnboardingPolicy policy={policy} onToggle={onToggle} />
</div>
<Button variant={"primary"} onClick={onNext}>
Continue
</Button>
</div>
);
};

View File

@@ -0,0 +1,102 @@
import Button from "@components/Button";
import Code from "@components/Code";
import InlineLink from "@components/InlineLink";
import { Modal, ModalContent } from "@components/modal/Modal";
import Steps from "@components/Steps";
import { cn } from "@utils/helpers";
import { ExternalLinkIcon } from "lucide-react";
import * as React from "react";
import { useMemo, useState } from "react";
import { NetworkResource } from "@/interfaces/Network";
import { Peer } from "@/interfaces/Peer";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";
type Props = {
resource?: NetworkResource;
device?: Peer;
onNext?: () => void;
onTroubleshootingClick?: () => void;
};
export const OnboardingTestResource = ({
resource,
device,
onNext,
onTroubleshootingClick,
}: Props) => {
const [open, setOpen] = useState(false);
const isSubnet = resource?.type === "subnet";
const isWildCard = resource?.address.includes("*");
const isHost = resource?.type === "host";
const pingAddress = useMemo(() => {
let a = resource?.address || "";
if (isHost && a.endsWith("/32")) {
a = a.slice(0, -3);
}
if (isWildCard) return `(any subdomain of ${a})`;
return isSubnet ? `(resource ip in your subnet)` : a;
}, [isWildCard, isHost, isSubnet, resource?.address]);
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{`Let's put that connection to the test`}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{`Nice work connecting your client device! Now, lets have a little fun and test if it can reach your resource.`}
</div>
</div>
<Steps className={"stepper-bg-variant"}>
<Steps.Step step={1}>
<p className={"!text-nb-gray-300"}>
Open your command line and run this command from{" "}
<span className={cn(device && "text-white")}>
{device?.name || "your device"}
</span>{" "}
to ping your resource.
</p>
<Code showCopyIcon={!isSubnet && !isWildCard}>
ping {pingAddress}
</Code>
</Steps.Step>
<Steps.Step step={2} line={false} className={"pb-0"} disabled={!device}>
<p className={"!text-nb-gray-300"}>
Everything working? Great! You can now continue with the onboarding.
If something isnt right, please check our{" "}
<InlineLink
href={"https://docs.netbird.io/how-to/troubleshooting-client"}
target={"_blank"}
onClick={onTroubleshootingClick}
>
troubleshooting guide
<ExternalLinkIcon size={12} />
</InlineLink>
</p>
<div className={"mt-2"}>
<Button
variant={"secondaryLighter"}
onClick={onNext}
className={"w-full"}
>
It works! - Continue
</Button>
</div>
</Steps.Step>
</Steps>
<Modal open={open} onOpenChange={setOpen}>
<ModalContent>
<SetupModalContent title={"Install NetBird"} />
</ModalContent>
</Modal>
</div>
);
};

View File

@@ -0,0 +1,52 @@
import Button from "@components/Button";
import * as React from "react";
import { Policy } from "@/interfaces/Policy";
import { OnboardingPolicy } from "@/modules/onboarding/OnboardingPolicy";
type Props = {
policy?: Policy;
onNext?: () => void;
onToggle?: (policy: Policy) => void;
};
export const OnboardingExplainDefaultPolicy = ({
policy,
onNext,
onToggle,
}: Props) => {
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{`Set the rules. You're in control`}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{`With NetBird, you decide who gets access to what.
We've already set up an access policy for your devices.`}
</div>
{policy && (
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
Flip the switch, then try pinging your other device again to see how it affects the connection.
</div>
)}
</div>
<div>
<OnboardingPolicy policy={policy} onToggle={onToggle} />
</div>
<Button variant={"primary"} onClick={onNext}>
Continue
</Button>
</div>
);
};

View File

@@ -0,0 +1,62 @@
import Button from "@components/Button";
import { Modal, ModalContent } from "@components/modal/Modal";
import { DownloadIcon } from "lucide-react";
import * as React from "react";
import { useEffect, useState } from "react";
import { Peer } from "@/interfaces/Peer";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";
type Props = {
onBack: () => void;
firstDevice?: Peer;
onFinish?: () => void;
};
export const OnboardingFirstDevice = ({
onBack,
firstDevice,
onFinish,
}: Props) => {
const [open, setOpen] = useState(false);
/**
* Continue to next step once first device is recognized
*/
useEffect(() => {
firstDevice && onFinish?.();
}, [firstDevice]);
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center"}>
{`Let's get your first device online`}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{`To access other machines, install NetBird, sign in, and your device joins the network.
Every device you add becomes a NetBird peer in your network. It's that simple.`}
</div>
</div>
<div className={"flex items-center justify-center mt-4 gap-3"}>
<Button variant={"secondary"} onClick={onBack}>
Go Back
</Button>
<Button variant={"primary"} onClick={() => setOpen(true)}>
<DownloadIcon size={16} />
Install NetBird
</Button>
</div>
<Modal open={open} onOpenChange={setOpen}>
<ModalContent className={"!z-[70]"}>
<SetupModalContent title={"Install NetBird"} hideDocker={true} />
</ModalContent>
</Modal>
</div>
);
};

View File

@@ -0,0 +1,133 @@
import Button from "@components/Button";
import Code from "@components/Code";
import InlineLink from "@components/InlineLink";
import { Modal, ModalContent } from "@components/modal/Modal";
import { useApiCall } from "@utils/api";
import { cn } from "@utils/helpers";
import { getInstallUrl } from "@utils/netbird";
import { ArrowUpRightIcon, ShareIcon } from "lucide-react";
import * as React from "react";
import { useEffect, useState } from "react";
import { useDialog } from "@/contexts/DialogProvider";
import { Peer } from "@/interfaces/Peer";
import { SetupKey } from "@/interfaces/SetupKey";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";
type Props = {
secondDevice?: Peer;
onFinish?: () => void;
};
export const OnboardingSecondDevice = ({ secondDevice, onFinish }: Props) => {
const setupKeyRequest = useApiCall<SetupKey>("/setup-keys", true);
const [setupKey, setSetupKey] = useState<SetupKey>();
const { confirm } = useDialog();
const [open, setOpen] = useState(false);
const isShareSupported = navigator.share !== undefined;
/**
* Continue to next step once second device is recognized
*/
useEffect(() => {
secondDevice && onFinish?.();
}, [secondDevice]);
const openNavigatorShare = () => {
if (navigator.share) {
navigator.share({
title: "Install NetBird",
text: "Install NetBird on another device using this link.",
url: getInstallUrl(),
});
}
};
const installUsingSetupKey = async () => {
const choice = await confirm({
title: `Create a Setup Key?`,
description:
"If you continue, a one-off setup key will be automatically created and you will be able to install NetBird.",
confirmText: "Continue",
cancelText: "Cancel",
type: "default",
});
if (!choice) return;
await setupKeyRequest
.post({
name: "Onboarding (Second Device)",
type: "one-off",
expires_in: 24 * 60 * 60, // 1 day expiration
revoked: false,
auto_groups: [],
usage_limit: 1,
ephemeral: false,
allow_extra_dns_labels: false,
})
.then((setupKey) => {
setOpen(true);
setSetupKey(setupKey);
});
};
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{`Time to bring in your second device`}
</h1>
<div className="text-sm text-nb-gray-300 font-light mt-2 block text-center">
Each device (a.k.a. peer) in your NetBird network gets its own private IP and name to communicate securely in the network.
</div>
<div className="text-sm text-nb-gray-300 font-light mt-2 block text-center">
To complete the setup, just share this link or email it to yourself to set up your next device
with ease.
</div>
</div>
<div
className={cn(
"flex flex-wrap sm:flex-nowrap md:!flex-wrap gap-3 items-center justify-center",
)}
>
<div>
<Code
message={"Installation link successfully copied"}
className={"text-[0.8rem]"}
>
{getInstallUrl()}
</Code>
</div>
{isShareSupported && (
<Button
variant={"input"}
onClick={openNavigatorShare}
className={"h-[42px]"}
>
<ShareIcon size={16} />
<span className={"lg:hidden"}>Share Link</span>
</Button>
)}
</div>
<div className="text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4">
Use the headless setup to register a peer without a browser or user interaction.{" "}
<InlineLink onClick={installUsingSetupKey} href={"#"}>
Install with a setup key
<ArrowUpRightIcon size={12} />
</InlineLink>{" "}
</div>
{setupKey && (
<Modal open={open} onOpenChange={setOpen}>
<ModalContent>
<SetupModalContent
title={"Install NetBird"}
setupKey={setupKey.key}
/>
</ModalContent>
</Modal>
)}
</div>
);
};

View File

@@ -0,0 +1,79 @@
import Button from "@components/Button";
import Code from "@components/Code";
import InlineLink from "@components/InlineLink";
import Steps from "@components/Steps";
import { ExternalLinkIcon } from "lucide-react";
import * as React from "react";
import { Peer } from "@/interfaces/Peer";
import { Policy } from "@/interfaces/Policy";
type Props = {
firstDevice?: Peer;
secondDevice?: Peer;
policy?: Policy;
onNext?: () => void;
onTroubleshootingClick?: () => void;
};
export const OnboardingTestP2P = ({
firstDevice,
secondDevice,
onNext,
onTroubleshootingClick,
}: Props) => {
return (
<div className={"relative flex flex-col h-full gap-4"}>
<div>
<h1 className={"text-xl text-center max-w-sm mx-auto"}>
{`Let's put that connection to the test`}
</h1>
<div
className={
"text-sm text-nb-gray-300 font-light mt-2 block text-center sm:px-4"
}
>
{
"Nice work connecting your devices! Now, lets have a little fun and test if they can talk to each other."
}
</div>
</div>
<Steps className={"stepper-bg-variant"}>
<Steps.Step step={1}>
<p className={"!text-nb-gray-300"}>
Run this command from{" "}
<span className={"text-white"}>{firstDevice?.name}</span> to ping{" "}
<span className={"text-white"}>{secondDevice?.name}</span>.
You should receive a response if the connection is working.
</p>
<Code message={"Command has been copied successfully"}>
ping {secondDevice?.ip}
</Code>
</Steps.Step>
<Steps.Step step={2} line={false} className={"pb-0"}>
<p className={"!text-nb-gray-300"}>
Everything working? Great! You can now continue with the onboarding.
If something isnt right, please check our{" "}
<InlineLink
onClick={onTroubleshootingClick}
href={"https://docs.netbird.io/how-to/troubleshooting-client"}
target={"_blank"}
>
troubleshooting guide
<ExternalLinkIcon size={12} />
</InlineLink>
</p>
<div className={"mt-2"}>
<Button
variant={"secondaryLighter"}
className={"w-full"}
onClick={onNext}
>
It works! - Continue
</Button>
</div>
</Steps.Step>
</Steps>
</div>
);
};

View File

@@ -9,26 +9,37 @@ import {
} from "@components/modal/Modal";
import ModalHeader from "@components/modal/ModalHeader";
import Paragraph from "@components/Paragraph";
import { SegmentedTabs } from "@components/SegmentedTabs";
import Separator from "@components/Separator";
import Steps from "@components/Steps";
import { Lightbox } from "@components/ui/Lightbox";
import { Mark } from "@components/ui/Mark";
import { cn } from "@utils/helpers";
import { ExternalLinkIcon, TerminalSquare } from "lucide-react";
import { ExternalLinkIcon, PlusCircle, TerminalSquare } from "lucide-react";
import * as React from "react";
import { useState } from "react";
import NetBirdIcon from "@/assets/icons/NetBirdIcon";
import sshImage from "@/assets/ssh/ssh-client.png";
import { Peer } from "@/interfaces/Peer";
import { PeerSSHPolicyModal } from "@/modules/peer/PeerSSHPolicyModal";
import { Terminal } from "@/modules/remote-access/ssh/Terminal";
type Props = {
open?: boolean;
onOpenChange?: (open: boolean) => void;
onSuccess?: () => void;
peer?: Peer;
};
export const PeerSSHInstructions = ({
open,
onOpenChange,
onSuccess,
peer,
}: Props) => {
const [client, setClient] = useState("cli");
const [policyModal, setPolicyModal] = useState(false);
return (
<Modal open={open} onOpenChange={onOpenChange}>
<ModalContent
@@ -39,36 +50,70 @@ export const PeerSSHInstructions = ({
icon={<TerminalSquare size={16} className={"text-netbird"} />}
title={"Enable SSH Access"}
description={
"Allow remote SSH access to this machine from other connected network participants. NetBird's embedded SSH server is running on port 44338."
"Allow remote SSH access from other connected network participants."
}
color={"netbird"}
/>
<Separator />
<div className={"px-8 py-3 flex flex-col gap-0 z-0"}>
<div className={"px-8 py-3 flex flex-col gap-0 z-0 mt-1"}>
<SegmentedTabs value={client} onChange={setClient}>
<SegmentedTabs.List className={"rounded-lg border"}>
<SegmentedTabs.Trigger value={"cli"}>
<TerminalSquare size={16} />
CLI
</SegmentedTabs.Trigger>
<SegmentedTabs.Trigger value={"gui"}>
<NetBirdIcon size={16} />
Desktop Client
</SegmentedTabs.Trigger>
</SegmentedTabs.List>
</SegmentedTabs>
<Steps>
<Steps.Step step={1}>
<p className={"font-normal"}>
If you are using NetBird via CLI, you can enable SSH by running
</p>
<Code codeToCopy={"netbird down"}>
<Code.Line>{`netbird down # if NetBird is already running`}</Code.Line>
</Code>
<Code>
<Code.Line>{`netbird up --allow-server-ssh`}</Code.Line>
</Code>
</Steps.Step>
{client === "cli" ? (
<Steps.Step step={1}>
<p className={"font-normal"}>
If you are using NetBird via CLI, you can enable SSH by
running
</p>
<Code codeToCopy={"netbird down"}>
<Code.Line>{`netbird down # if NetBird is already running`}</Code.Line>
</Code>
<Code>
<Code.Line>{`netbird up --allow-server-ssh --enable-ssh-root`}</Code.Line>
</Code>
</Steps.Step>
) : (
<Steps.Step step={1}>
<p className={"font-normal"}>
If you are using NetBird via the Desktop Client, click on the
NetBird tray icon, go to <Mark>Settings</Mark> and click{" "}
<Mark>Allow SSH</Mark>. If you want to enable Root Login go to{" "}
<Mark>Settings &gt; Advanced Settings</Mark> and enable SSH
Root Login under the SSH tab.
</p>
<Lightbox image={sshImage} />
</Steps.Step>
)}
<Steps.Step step={2}>
<p className={"font-normal"}>
If you are using NetBird via the Desktop Client, click on the
NetBird tray icon, go to <Mark>Settings</Mark> and click{" "}
<Mark>Allow SSH</Mark> <br />
Starting from NetBird v0.60.0, SSH requires an explicit access
control policy that allows <Mark>TCP</Mark> traffic on port{" "}
<Mark>22</Mark>
</p>
<Lightbox image={sshImage} />
<div className={"mt-2"}>
<Button
variant={"secondary"}
onClick={() => setPolicyModal(true)}
>
<PlusCircle size={16} />
Create SSH Policy
</Button>
</div>
</Steps.Step>
<Steps.Step step={3} line={false}>
<p className={"font-normal"}>
Once the NetBird SSH server is allowed on the client, <br />
@@ -96,15 +141,17 @@ export const PeerSSHInstructions = ({
<Button variant={"secondary"}>Cancel</Button>
</ModalClose>
<Button
variant={"primary"}
onClick={onSuccess}
data-cy={"create-setup-key"}
>
<Button variant={"primary"} onClick={onSuccess}>
Confirm & Enable
</Button>
</div>
</ModalFooter>
<PeerSSHPolicyModal
open={policyModal}
onOpenChange={setPolicyModal}
peer={peer}
/>
</ModalContent>
</Modal>
);

View File

@@ -0,0 +1,38 @@
import { Callout } from "@components/Callout";
import { InlineButtonLink } from "@components/InlineLink";
import { cn } from "@utils/helpers";
import * as React from "react";
import { useState } from "react";
import { Peer } from "@/interfaces/Peer";
import { PeerSSHPolicyModal } from "@/modules/peer/PeerSSHPolicyModal";
import { usePeerSSHPolicyCheck } from "@/modules/peer/usePeerSSHPolicyCheck";
type Props = {
peer?: Peer;
className?: string;
};
export const PeerSSHPolicyInfo = ({ peer, className }: Props) => {
const { showSSHPolicyInfo } = usePeerSSHPolicyCheck(peer);
const [policyModal, setPolicyModal] = useState(false);
return (
showSSHPolicyInfo && (
<>
<Callout className={cn("max-w-xl", className)} variant={"warning"}>
<span>
Starting from NetBird v0.60.0, SSH requires an explicit access
control policy that allows TCP traffic on port 22.{" "}
<InlineButtonLink onClick={() => setPolicyModal(true)}>
Create SSH Policy
</InlineButtonLink>
</span>
</Callout>
<PeerSSHPolicyModal
open={policyModal}
onOpenChange={setPolicyModal}
peer={peer}
/>
</>
)
);
};

View File

@@ -0,0 +1,35 @@
import { Modal } from "@components/modal/Modal";
import * as React from "react";
import { Peer } from "@/interfaces/Peer";
import { PolicyRuleResource } from "@/interfaces/Policy";
import { AccessControlModalContent } from "@/modules/access-control/AccessControlModal";
type Props = {
open: boolean;
onOpenChange: (open: boolean) => void;
peer?: Peer;
};
export const PeerSSHPolicyModal = ({ open, onOpenChange, peer }: Props) => {
return (
<Modal open={open} onOpenChange={onOpenChange}>
<AccessControlModalContent
key={open ? "1" : "0"}
initialPorts={[22]}
initialProtocol={"tcp"}
initialName={"SSH Access"}
initialDestinationResource={
peer
? ({
id: peer.id,
type: "peer",
} as PolicyRuleResource)
: undefined
}
onSuccess={async (p) => {
onOpenChange(false);
}}
/>
</Modal>
);
};

View File

@@ -4,6 +4,7 @@ import { LockIcon, TerminalSquare } from "lucide-react";
import * as React from "react";
import { usePeer } from "@/contexts/PeerProvider";
import { usePermissions } from "@/contexts/PermissionsProvider";
import { PeerSSHPolicyInfo } from "@/modules/peer/PeerSSHPolicyInfo";
export const PeerSSHToggle = () => {
const { permission } = usePermissions();
@@ -42,6 +43,7 @@ export const PeerSSHToggle = () => {
}
/>
</FullTooltip>
<PeerSSHPolicyInfo peer={peer} />
</>
);
};

View File

@@ -0,0 +1,77 @@
import useFetchApi from "@utils/api";
import { Peer } from "@/interfaces/Peer";
import { Policy } from "@/interfaces/Policy";
import { isNativeSSHSupported } from "@utils/version";
export const usePeerSSHPolicyCheck = (peer?: Peer) => {
const { data: policies, isLoading } = useFetchApi<Policy[]>(
"/policies",
true,
false,
);
const peerGroupIds = peer?.groups?.map((p) => p.id);
const peerPolicies = policies?.filter((policy) => {
// Skip disabled policies
if (!policy?.enabled) return false;
const rule = policy?.rules?.[0];
if (!rule) return false;
// Skip icmp and udp
if (rule.protocol === "icmp" || rule.protocol === "udp") return false;
// Check resource and groups
const isPeerInDestinationResource =
rule.destinationResource?.id === peer?.id;
const isPeerInDestinationGroup =
rule.destinations?.some((group) => {
const groupId = typeof group === "string" ? group : group?.id;
return peerGroupIds?.includes(groupId);
}) ?? false;
const isPeerInDestination =
isPeerInDestinationResource || isPeerInDestinationGroup;
// If bidirectional, also check if peer is in source
let isPeerInSource = false;
if (rule.bidirectional) {
const isPeerInSourceResource = rule.sourceResource?.id === peer?.id;
const isPeerInSourceGroup =
rule.sources?.some((group) => {
const groupId = typeof group === "string" ? group : group?.id;
return peerGroupIds?.includes(groupId);
}) ?? false;
isPeerInSource = isPeerInSourceResource || isPeerInSourceGroup;
}
const isInSourceOrDestination = isPeerInDestination || isPeerInSource;
if (!isInSourceOrDestination) return false;
if (rule.protocol === "all") return true;
// Check ports
const hasNoPortRestrictions = rule.ports === undefined;
const hasExplicitPort22 = rule.ports?.includes("22");
const hasPort22InRange = rule.port_ranges?.some(
(range) => 22 >= range.start && 22 <= range.end,
);
return hasNoPortRestrictions || hasExplicitPort22 || hasPort22InRange;
});
const hasSSHPolicy = (peerPolicies?.length ?? 0) > 0;
const showSSHPolicyInfo =
!hasSSHPolicy &&
!isLoading &&
!!peer?.ssh_enabled &&
isNativeSSHSupported(peer.version);
return {
peerPolicies,
isCheckLoading: isLoading,
hasSSHPolicy,
showSSHPolicyInfo,
};
};

View File

@@ -1,4 +1,3 @@
import FullTooltip from "@components/FullTooltip";
import InlineLink from "@components/InlineLink";
import {
Tooltip,
@@ -8,13 +7,14 @@ import {
} from "@components/Tooltip";
import MemoizedNetBirdIcon from "@components/ui/MemoizedNetBirdIcon";
import { getOperatingSystem } from "@hooks/useOperatingSystem";
import { parseVersionString } from "@utils/version";
import { compareVersions } from "@utils/version";
import { ArrowRightIcon, ArrowUpCircleIcon } from "lucide-react";
import * as React from "react";
import { useMemo } from "react";
import { useApplicationContext } from "@/contexts/ApplicationProvider";
import { OperatingSystem } from "@/interfaces/OperatingSystem";
import { PeerOperatingSystemIcon } from "@/modules/peers/PeerOperatingSystemIcon";
import FullTooltip from "@components/FullTooltip";
type Props = {
version: string;
@@ -31,7 +31,8 @@ export default function PeerVersionCell({ version, os, serial }: Props) {
operatingSystem === OperatingSystem.ANDROID
)
return false;
return parseVersionString(version) < parseVersionString(latestVersion);
if (!latestVersion) return false;
return !compareVersions(version, latestVersion);
}, [os, version, latestVersion]);
const updateIcon = useMemo(() => {

View File

@@ -24,6 +24,8 @@ export enum SSHStatus {
export const SSH_DOCS_LINK =
"https://docs.netbird.io/how-to/browser-client#ssh-connection";
const SSH_DETECTION_TIMEOUT_MS = 20000;
export const useSSH = (client: any) => {
const [status, setStatus] = useState(SSHStatus.DISCONNECTED);
const [config, setConfig] = useState<SSHConfig | null>(null);
@@ -38,12 +40,37 @@ export const useSSH = (client: any) => {
setStatus(SSHStatus.CONNECTING);
setConfig(config);
setError("");
try {
let requiresJwt = false;
try {
requiresJwt = await client.detectSSHServerType(
config.hostname,
config.port,
SSH_DETECTION_TIMEOUT_MS,
);
console.log("Detection:", { requiresJwt, hasToken: !!accessToken });
} catch (detectionErr) {
console.error(
"Detection failed, falling back to pubkey:",
detectionErr,
);
}
if (requiresJwt && !accessToken) {
console.error("No access token available");
setError("No access token available");
setStatus(SSHStatus.DISCONNECTED);
setConfig(null);
return SSHStatus.DISCONNECTED;
}
const ssh = await client.createSSHConnection(
config.hostname,
config.port,
config.username,
requiresJwt ? accessToken : undefined,
);
ssh.onclose = () => {
@@ -57,7 +84,7 @@ export const useSSH = (client: any) => {
setStatus(SSHStatus.CONNECTED);
return SSHStatus.CONNECTED;
} catch (err) {
console.error("SSH connection failed:", err);
console.error("Connection failed:", err);
session.current = null;
setStatus(SSHStatus.DISCONNECTED);
setError("SSH connection failed. Check the console for details.");
@@ -65,7 +92,7 @@ export const useSSH = (client: any) => {
return SSHStatus.DISCONNECTED;
}
},
[client, status],
[client, status, accessToken],
);
const disconnect = useCallback(() => {

View File

@@ -209,11 +209,11 @@ export const useNetBirdClient = () => {
}, []);
const detectSSHServerType = useCallback(
async (host: string, port: number): Promise<boolean> => {
async (host: string, port: number, timeoutMs: number): Promise<boolean> => {
if (!netBirdClient.current?.detectSSHServerType) {
throw new Error("NetBird client not ready");
}
return netBirdClient.current.detectSSHServerType(host, port);
return netBirdClient.current.detectSSHServerType(host, port, timeoutMs);
},
[],
);
@@ -228,7 +228,12 @@ export const useNetBirdClient = () => {
if (!netBirdClient.current?.createSSHConnection) {
throw new Error("Go client not ready");
}
return netBirdClient.current.createSSHConnection(host, port, username);
return netBirdClient.current.createSSHConnection(
host,
port,
username,
jwtToken,
);
},
[],
);

View File

@@ -68,7 +68,7 @@ const loadConfig = (): Config => {
googleAnalyticsID: configJson?.googleAnalyticsID || undefined,
googleTagManagerID: configJson?.googleTagManagerID || undefined,
wasmPath:
configJson.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.59.11",
configJson?.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.60.2",
} as Config;
};

34
src/utils/version.test.ts Normal file
View File

@@ -0,0 +1,34 @@
import { isNativeSSHSupported } from "./version.js";
console.log("=== Testing isNativeSSHSupported ===");
const sshTestCases = [
{ version: "v0.59.9", shouldSupport: false },
{ version: "v0.59.10", shouldSupport: false },
{ version: "v0.59.11", shouldSupport: false },
{ version: "v0.60.0", shouldSupport: true },
{ version: "v0.60.1", shouldSupport: true },
{ version: "v0.61.0", shouldSupport: true },
{ version: "v1.0.0", shouldSupport: true },
// Edge cases
{ version: "development", shouldSupport: true, desc: "development build" },
{ version: "0.60.0", shouldSupport: true, desc: "no v prefix" },
{ version: "0.59.11", shouldSupport: false, desc: "no v prefix" },
{ version: "v0.60.0-beta", shouldSupport: true, desc: "with suffix" },
{ version: "v0.60.0-rc1", shouldSupport: true, desc: "with rc suffix" },
{ version: "v0.59.9-beta", shouldSupport: false, desc: "old version with suffix" },
];
let failures = 0;
sshTestCases.forEach(({ version, shouldSupport, desc }) => {
const result = isNativeSSHSupported(version);
const status = result === shouldSupport ? "✓" : "✗";
if (result !== shouldSupport) failures++;
const label = desc ? `${version.padEnd(15)} (${desc})` : version.padEnd(15);
console.log(
`${status} ${label}${result.toString().padStart(5)} (expected: ${shouldSupport})`,
);
});
console.log(`\n${failures} test(s) failed`);
process.exit(failures > 0 ? 1 : 0);

View File

@@ -36,9 +36,30 @@ export const getLatestNetbirdRelease = async (
}
};
export const parseVersionString = (version: string | undefined) => {
if (!version) return -1;
return parseInt(version.replace(/\D/g, ""));
/**
* Compare semantic versions.
* Returns true if version >= minVersion.
*/
export const compareVersions = (
version: string,
minVersion: string,
): boolean => {
const parseVersion = (v: string): number[] => {
return v.replace(/^v/, "").split(".").map(Number);
};
const vParts = parseVersion(version);
const minParts = parseVersion(minVersion);
for (let i = 0; i < Math.max(vParts.length, minParts.length); i++) {
const vPart = vParts[i] || 0;
const minPart = minParts[i] || 0;
if (vPart > minPart) return true;
if (vPart < minPart) return false;
}
return true;
};
/**
@@ -51,16 +72,15 @@ export const isRoutingPeerSupported = (version: string, os: string) => {
const operatingSystem = getOperatingSystem(os);
if (operatingSystem == OperatingSystem.LINUX) return true;
if (version == "development") return true;
const versionNumber = parseVersionString(version);
return versionNumber >= 366;
return compareVersions(version, "0.36.6");
};
/**
* Check if native SSH is supported
* Check if native SSH is supported.
* Supported starting from NetBird v0.60.0+.
* @param version
*/
export const isNativeSSHSupported = (version: string) => {
if (version == "development") return true;
const versionNumber = parseVersionString(version);
return versionNumber >= 999999;
return compareVersions(version, "0.60.0");
};