)[0];
+
+const setDemoFlag = (demoMode: boolean) =>
+ prisma.panelSettings.upsert({
+ create: { demoMode, id: SETTINGS_ID },
+ update: { demoMode },
+ where: { id: SETTINGS_ID },
+ });
+
+const removeDemoRecords = async () => {
+ // Servers the demo account owns elsewhere should not exist (demo accounts
+ // can't order servers), but clean up properly if an admin made one.
+ const elsewhere = await prisma.server.findMany({
+ select: { id: true },
+ where: {
+ deletedAt: null,
+ nodeId: { not: DEMO_NODE_ID },
+ userId: DEMO_USER_ID,
+ },
+ });
+ await Promise.all(
+ elsewhere.map((server) => destroyServer(server.id, { force: true }))
+ );
+
+ await prisma.$transaction([
+ prisma.server.deleteMany({
+ where: {
+ OR: [
+ { id: DEMO_SERVER_ID },
+ { nodeId: DEMO_NODE_ID },
+ { userId: DEMO_USER_ID },
+ ],
+ },
+ }),
+ prisma.node.deleteMany({ where: { id: DEMO_NODE_ID } }),
+ prisma.location.deleteMany({ where: { id: DEMO_LOCATION_ID } }),
+ prisma.user.deleteMany({ where: { id: DEMO_USER_ID } }),
+ ]);
+};
+
+export const enableDemoMode = async () => {
+ const clash = await prisma.user.findUnique({
+ select: { id: true },
+ where: { email: DEMO_EMAIL },
+ });
+ if (clash && clash.id !== DEMO_USER_ID) {
+ throw new DemoSetupError(
+ `A real account already uses ${DEMO_EMAIL}. Rename it before turning on demo mode.`
+ );
+ }
+ const locationClash = await prisma.location.findUnique({
+ select: { id: true },
+ where: { short: DEMO_LOCATION_SHORT },
+ });
+ if (locationClash && locationClash.id !== DEMO_LOCATION_ID) {
+ throw new DemoSetupError(
+ `A location named "${DEMO_LOCATION_SHORT}" already exists. Rename it before turning on demo mode.`
+ );
+ }
+
+ const [egg, password] = await Promise.all([
+ pickEgg(),
+ hashPassword(DEMO_PASSWORD),
+ ]);
+ const { daemonToken, daemonTokenId } = generateDaemonToken();
+ const now = new Date();
+
+ // Start from a clean slate so turning demo mode on also resets it.
+ await removeDemoRecords();
+ resetDemoServers();
+
+ await prisma.$transaction(async (tx) => {
+ await tx.user.create({
+ data: {
+ email: DEMO_EMAIL,
+ emailVerified: true,
+ id: DEMO_USER_ID,
+ name: DEMO_NAME,
+ role: "user",
+ },
+ });
+ await tx.account.create({
+ data: {
+ accountId: DEMO_USER_ID,
+ id: `${DEMO_USER_ID}-credential`,
+ password,
+ providerId: "credential",
+ userId: DEMO_USER_ID,
+ },
+ });
+ await tx.location.create({
+ data: {
+ id: DEMO_LOCATION_ID,
+ long: "Demo (simulated)",
+ short: DEMO_LOCATION_SHORT,
+ },
+ });
+ await tx.node.create({
+ data: {
+ daemonToken,
+ daemonTokenId,
+ description:
+ "Simulated node created by demo mode. Turn off demo mode to remove it.",
+ disk: 20_480,
+ fqdn: DEMO_NODE_FQDN,
+ id: DEMO_NODE_ID,
+ locationId: DEMO_LOCATION_ID,
+ memory: 8192,
+ name: "Demo Node",
+ public: false,
+ uuid: DEMO_NODE_UUID,
+ },
+ });
+ await tx.allocation.create({
+ data: {
+ id: DEMO_ALLOCATION_ID,
+ ip: "127.0.0.1",
+ ipAlias: "play.demo.invalid",
+ nodeId: DEMO_NODE_ID,
+ port: 25_565,
+ },
+ });
+ await tx.server.create({
+ data: {
+ ...DEMO_LIMITS,
+ allocationId: DEMO_ALLOCATION_ID,
+ description: "A sample server with simulated data. Try anything!",
+ eggId: egg?.id ?? null,
+ id: DEMO_SERVER_ID,
+ image:
+ firstImage(egg?.dockerImages) ?? "ghcr.io/pterodactyl/yolks:java_21",
+ installedAt: now,
+ name: "Demo Server",
+ nodeId: DEMO_NODE_ID,
+ startup: egg?.startup || "java -Xmx{{SERVER_MEMORY}}M -jar server.jar",
+ userId: DEMO_USER_ID,
+ uuid: DEMO_SERVER_UUID,
+ },
+ });
+ await tx.allocation.update({
+ data: { serverId: DEMO_SERVER_ID },
+ where: { id: DEMO_ALLOCATION_ID },
+ });
+ });
+
+ await emitActivity({
+ message: "Demo server created",
+ phase: "server:deploy",
+ serverId: DEMO_SERVER_ID,
+ });
+ await setDemoFlag(true);
+};
+
+export const disableDemoMode = async () => {
+ await removeDemoRecords();
+ resetDemoServers();
+ await setDemoFlag(false);
+};
diff --git a/apps/web/lib/servers/route.ts b/apps/web/lib/servers/route.ts
index 4f4577c..135aeb0 100644
--- a/apps/web/lib/servers/route.ts
+++ b/apps/web/lib/servers/route.ts
@@ -2,7 +2,7 @@ import "server-only";
import type { Node } from "@prisma/client";
import { NextResponse } from "next/server";
-import type { DaemonClient } from "@/lib/daemon/client";
+import type { Daemon } from "@/lib/daemon/client";
import { DaemonError, daemonFor } from "@/lib/daemon/client";
import type { ServerRole } from "@/lib/server-roles";
@@ -14,7 +14,7 @@ type Handler = (ctx: {
request: Request;
params: P;
access: ServerAccess & { server: ServerAccess["server"] & { node: Node } };
- daemon: DaemonClient;
+ daemon: Daemon;
}) => Promise;
export const daemonRoute =
diff --git a/apps/web/lib/servers/service.ts b/apps/web/lib/servers/service.ts
index 7a9936c..d64c064 100644
--- a/apps/web/lib/servers/service.ts
+++ b/apps/web/lib/servers/service.ts
@@ -6,6 +6,7 @@ import { ulid } from "ulid";
import { DaemonError, daemonFor } from "@/lib/daemon/client";
import { prisma } from "@/lib/db";
+import { DEMO_SERVER_ID, isDemoNode } from "@/lib/demo/constants";
import { validateVariable } from "@/lib/eggs/rules";
import { emitActivity } from "@/lib/events/emit";
@@ -222,6 +223,9 @@ export const deployServer = async (
if (!node) {
throw new ServiceError("No node has capacity for this server right now");
}
+ if (isDemoNode(node) && serverId !== DEMO_SERVER_ID) {
+ throw new ServiceError("The demo node only hosts the demo server");
+ }
const claimed = await prisma.$transaction(async (tx) => {
let ids: string[];
diff --git a/apps/web/lib/settings.ts b/apps/web/lib/settings.ts
index afbfb3d..0a63f61 100644
--- a/apps/web/lib/settings.ts
+++ b/apps/web/lib/settings.ts
@@ -19,6 +19,7 @@ export interface Branding {
supportUrl: string | null;
signUpEnabled: boolean;
bytepayLogin: boolean;
+ demoMode: boolean;
}
export interface PanelSettings extends Omit<
@@ -35,6 +36,7 @@ const DEFAULTS: PanelSettings = {
billingApiKeyHint: null,
billingProvider: "bytepay",
currency: "GBP",
+ demoMode: false,
logoUrl: null,
panelName: DEFAULT_PANEL_NAME,
storeUrl: null,
@@ -54,6 +56,7 @@ export const readPanelSettings = async (): Promise => {
billingApiKeyHint: row.billingApiKeyHint,
billingProvider: row.billingProvider,
currency: row.currency,
+ demoMode: row.demoMode,
logoUrl: row.logoUrl,
panelName: row.panelName,
storeUrl: row.storeUrl,
@@ -79,10 +82,17 @@ export const signUpOpen = async (provider: BillingProvider): Promise =>
provider === "builtin" || (await prisma.user.count()) === 0;
export const getBranding = async (): Promise => {
- const { billingProvider, panelName, logoUrl, websiteUrl, supportUrl } =
- await getPanelSettings();
+ const {
+ billingProvider,
+ demoMode,
+ panelName,
+ logoUrl,
+ websiteUrl,
+ supportUrl,
+ } = await getPanelSettings();
return {
bytepayLogin: customersUseBytepay(billingProvider),
+ demoMode,
logoUrl,
panelName,
signUpEnabled: await signUpOpen(billingProvider),
diff --git a/apps/web/prisma/migrations/20261129120000_demo_mode/migration.sql b/apps/web/prisma/migrations/20261129120000_demo_mode/migration.sql
new file mode 100644
index 0000000..64cabc6
--- /dev/null
+++ b/apps/web/prisma/migrations/20261129120000_demo_mode/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "panel_settings" ADD COLUMN "demoMode" BOOLEAN NOT NULL DEFAULT false;
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index c0b2d15..b5147ac 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -483,6 +483,7 @@ model PanelSettings {
billingApiKeyHash String?
billingApiKeyHint String?
updateBeta Boolean @default(false)
+ demoMode Boolean @default(false)
updatedAt DateTime @updatedAt
@@map("panel_settings")
diff --git a/apps/web/providers/branding.tsx b/apps/web/providers/branding.tsx
index 1bc9c64..9173b49 100644
--- a/apps/web/providers/branding.tsx
+++ b/apps/web/providers/branding.tsx
@@ -7,6 +7,7 @@ import type { Branding } from "@/lib/settings";
const BrandingContext = createContext({
bytepayLogin: false,
+ demoMode: false,
logoUrl: null,
panelName: "BytePanel",
signUpEnabled: true,
diff --git a/apps/web/test/demo-daemon.test.ts b/apps/web/test/demo-daemon.test.ts
new file mode 100644
index 0000000..38ae0f6
--- /dev/null
+++ b/apps/web/test/demo-daemon.test.ts
@@ -0,0 +1,100 @@
+import { beforeEach, describe, expect, mock, test } from "bun:test";
+
+import {
+ daemonServerDetailsSchema,
+ filesListResultSchema,
+} from "@bytepanel/protocol";
+
+mock.module("@/lib/db", () => ({
+ prisma: {
+ backup: { findUnique: () => null, update: () => null },
+ server: {
+ findUnique: () => ({ memory: 2048 }),
+ updateMany: () => null,
+ },
+ },
+}));
+mock.module("@/lib/events/emit", () => ({ emitActivity: () => null }));
+
+const { demoDaemon, demoSnapshot, resetDemoServers } =
+ await import("@/lib/demo/daemon");
+
+const UUID = "de000000-0000-4000-8000-000000000001";
+
+const names = async (dir: string) => {
+ const { entries } = await demoDaemon.listDirectory(UUID, dir);
+ return entries.map((e) => e.name);
+};
+
+describe("demo daemon", () => {
+ beforeEach(() => {
+ resetDemoServers();
+ });
+
+ test("seeds a browsable file tree that matches the protocol", async () => {
+ const result = await demoDaemon.listDirectory(UUID, "/");
+ expect(filesListResultSchema.parse(result).path).toBe("/");
+ expect(result.entries[0]?.type).toBe("dir");
+ expect(await names("/")).toContain("server.properties");
+ expect(await demoDaemon.getFileContents(UUID, "/eula.txt")).toContain(
+ "eula=true"
+ );
+ });
+
+ test("writes, renames and deletes files", async () => {
+ await demoDaemon.writeFile(UUID, "/notes/todo.txt", "hello");
+ expect(await names("/notes")).toEqual(["todo.txt"]);
+ await demoDaemon.renameFiles(UUID, "/", [{ from: "notes", to: "docs" }]);
+ expect(await demoDaemon.getFileContents(UUID, "/docs/todo.txt")).toBe(
+ "hello"
+ );
+ await demoDaemon.deleteFiles(UUID, "/", ["docs"]);
+ expect(await names("/")).not.toContain("docs");
+ expect(demoDaemon.listDirectory(UUID, "/docs")).rejects.toThrow(
+ "Directory not found"
+ );
+ });
+
+ test("keeps paths inside the server root", async () => {
+ await demoDaemon.writeFile(UUID, "../../etc/passwd", "x");
+ expect(await names("/etc")).toEqual(["passwd"]);
+ });
+
+ test("compresses and extracts archives it made", async () => {
+ await demoDaemon.createDirectory(UUID, "/", "box");
+ await demoDaemon.writeFile(UUID, "/box/a.txt", "a");
+ const archive = await demoDaemon.compressFiles(UUID, "/", ["box"]);
+ expect(archive).toMatch(/^archive-.*\.tar\.gz$/u);
+ await demoDaemon.deleteFiles(UUID, "/", ["box"]);
+ await demoDaemon.decompressFile(UUID, "/", archive);
+ expect(await demoDaemon.getFileContents(UUID, "/box/a.txt")).toBe("a");
+ });
+
+ test("refuses binary files and remote pulls", () => {
+ expect(demoDaemon.getFileContents(UUID, "/server.jar")).rejects.toThrow();
+ expect(
+ demoDaemon.pullFile(UUID, { directory: "/", url: "https://x.test/a" })
+ ).rejects.toThrow("demo mode");
+ });
+
+ test("reports power state, stats and console lines", async () => {
+ const details = await demoDaemon.getServer(UUID);
+ expect(daemonServerDetailsSchema.parse(details).utilization.state).toBe(
+ "offline"
+ );
+ expect(details.utilization.memoryLimitBytes).toBe(2048 * 1024 * 1024);
+
+ await demoDaemon.sendCommands(UUID, ["list"]);
+ let snapshot = await demoSnapshot(UUID, 0);
+ expect(snapshot.lines.at(-1)?.text).toContain("not running");
+
+ await demoDaemon.power(UUID, "start");
+ snapshot = await demoSnapshot(UUID, null);
+ expect(snapshot.state).toBe("starting");
+ expect(snapshot.lines).toEqual([]);
+
+ await demoDaemon.power(UUID, "kill");
+ snapshot = await demoSnapshot(UUID, null);
+ expect(snapshot.state).toBe("offline");
+ });
+});