@nextjs-cms-plugins/cpanel-dashboard 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ type TrpcLike = {
2
+ cpanelDashboard?: {
3
+ getData: {
4
+ useQuery: () => {
5
+ data?: any;
6
+ isLoading: boolean;
7
+ isError?: boolean;
8
+ error?: unknown;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ export declare const CpanelDashboardPage: ({ trpc }: {
14
+ trpc: TrpcLike;
15
+ }) => import("react/jsx-runtime").JSX.Element;
16
+ export default CpanelDashboardPage;
17
+ //# sourceMappingURL=DashboardPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DashboardPage.d.ts","sourceRoot":"","sources":["../../src/client/DashboardPage.tsx"],"names":[],"mappings":"AAMA,KAAK,QAAQ,GAAG;IACZ,eAAe,CAAC,EAAE;QACd,OAAO,EAAE;YACL,QAAQ,EAAE,MAAM;gBACZ,IAAI,CAAC,EAAE,GAAG,CAAA;gBACV,SAAS,EAAE,OAAO,CAAA;gBAClB,OAAO,CAAC,EAAE,OAAO,CAAA;gBACjB,KAAK,CAAC,EAAE,OAAO,CAAA;aAClB,CAAA;SACJ,CAAA;KACJ,CAAA;CACJ,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,UAAU;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,4CAmF/D,CAAA;AAUD,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import getString from 'nextjs-cms/translations';
4
+ import { humanReadableFileSize } from 'nextjs-cms/utils';
5
+ export const CpanelDashboardPage = ({ trpc }) => {
6
+ const query = trpc?.cpanelDashboard?.getData.useQuery;
7
+ const { data, isLoading, isError, error } = query ? query() : { isLoading: true, isError: true, error: null };
8
+ if (!query) {
9
+ return _jsx("div", { className: 'p-6 text-sm text-red-500', children: "cPanel dashboard plugin misconfigured: missing trpc client." });
10
+ }
11
+ return (_jsxs("div", { className: 'w-full', children: [_jsx("div", { className: 'bg-linear-to-r from-sky-200 via-emerald-300 to-blue-600 p-8 font-extrabold text-foreground dark:from-blue-800 dark:via-amber-700 dark:to-rose-900', children: _jsx("h1", { className: 'text-3xl', children: getString('dashboard') }) }), _jsxs("div", { className: 'flex flex-col gap-4 p-4', children: [isLoading && _jsx("div", { className: 'text-sm text-muted-foreground', children: "Loading cPanel usage\u2026" }), isError && !isLoading && (_jsx("div", { className: 'rounded border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive', children: error instanceof Error ? error.message : 'Unable to load cPanel data' })), data ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: 'grid grid-cols-1 gap-4 sm-sidebar:grid-cols-1 md-sidebar:grid-cols-2 lg-sidebar:grid-cols-2 2xl-sidebar:grid-cols-4', children: [_jsx(StatCard, { title: getString('disk_space'), used: humanReadableFileSize(data.diskSpaceUsage), total: humanReadableFileSize(data.diskSpaceLimit) }), _jsx(StatCard, { title: getString('this_moth_bandwidth'), used: humanReadableFileSize(data.bandwidthUsage), total: humanReadableFileSize(data.bandwidthLimit) }), _jsx(StatCard, { title: getString('email_accounts'), used: data.emailsUsage.toString(), total: data.emailsLimit.toString() }), _jsx(StatCard, { title: 'MySQL\u00AE/MariaDB Databases', used: data.dbsCount.toString(), total: data.dbsLimit.toString() })] }), _jsxs("div", { className: 'grid grid-cols-1 gap-4 md:grid-cols-2', children: [_jsxs("div", { className: 'rounded-lg border bg-card p-4 text-card-foreground shadow-sm', children: [_jsx("div", { className: 'text-lg font-semibold', children: getString('accountInformation') }), _jsxs("div", { className: 'text-sm text-muted-foreground', children: [_jsxs("div", { children: ["PHP Version: ", data?.phpVersion ?? 'N/A'] }), _jsxs("div", { children: ["Root: ", data?.documentRoot ?? 'N/A'] })] })] }), _jsxs("div", { className: 'rounded-lg border bg-card p-4 text-card-foreground shadow-sm', children: [_jsx("div", { className: 'text-lg font-semibold', children: "MySQL/MariaDB" }), _jsx("div", { className: 'text-sm text-muted-foreground', children: data?.dbInfo ? (_jsxs(_Fragment, { children: [_jsxs("div", { children: ["Version: ", data.dbInfo.version] }), _jsxs("div", { children: ["Remote: ", data.dbInfo.is_remote ? 'Yes' : 'No'] })] })) : (_jsx("div", { children: "MySQL/MariaDB is not installed" })) }), _jsx("div", { className: 'mt-3 space-y-2 text-sm', children: data?.dbsList?.map((db, index) => (_jsxs("div", { className: 'rounded border p-2', children: [_jsx("div", { className: 'font-semibold', children: db.database }), _jsxs("div", { className: 'text-muted-foreground', children: ["Disk Usage: ", humanReadableFileSize(db.disk_usage)] }), _jsxs("div", { className: 'text-muted-foreground', children: ["Users: ", db.users?.length ?? 0] })] }, `${db.name}_${db.database}_${index}`))) })] })] })] })) : null] })] }));
12
+ };
13
+ const StatCard = ({ title, used, total }) => (_jsxs("div", { className: 'rounded-lg border bg-card p-4 text-card-foreground shadow-sm', children: [_jsx("div", { className: 'text-base font-semibold', children: title }), _jsxs("div", { className: 'mt-2 text-sm text-muted-foreground', children: ["Used: ", used] }), _jsxs("div", { className: 'text-sm text-muted-foreground', children: ["Total: ", total] })] }));
14
+ export default CpanelDashboardPage;
@@ -0,0 +1,19 @@
1
+ import { CpanelDashboardPage } from './client/DashboardPage.js';
2
+ export declare const components: {
3
+ cpanelDashboard: ({ trpc }: {
4
+ trpc: {
5
+ cpanelDashboard?: {
6
+ getData: {
7
+ useQuery: () => {
8
+ data?: any;
9
+ isLoading: boolean;
10
+ isError?: boolean;
11
+ error?: unknown;
12
+ };
13
+ };
14
+ };
15
+ };
16
+ }) => import("react/jsx-runtime").JSX.Element;
17
+ };
18
+ export { CpanelDashboardPage };
19
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAE/D,eAAO,MAAM,UAAU;;;;;;4BAKuE,CAAC;;+BAAgE,CAAC;6BAA+B,CAAC;;;;;;CAH/L,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,5 @@
1
+ import { CpanelDashboardPage } from './client/DashboardPage.js';
2
+ export const components = {
3
+ cpanelDashboard: CpanelDashboardPage,
4
+ };
5
+ export { CpanelDashboardPage };
@@ -0,0 +1,5 @@
1
+ import type { CMSPlugin } from 'nextjs-cms/plugins';
2
+ import { cpanelDashboardRouter } from './router.js';
3
+ export declare function createPlugin(): CMSPlugin;
4
+ export { cpanelDashboardRouter };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD,wBAAgB,YAAY,IAAI,SAAS,CAaxC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { cpanelDashboardRouter } from './router.js';
2
+ export function createPlugin() {
3
+ return {
4
+ name: 'cPanel Dashboard',
5
+ router: cpanelDashboardRouter,
6
+ routes: [
7
+ {
8
+ path: '/dashboard',
9
+ title: 'Dashboard',
10
+ icon: 'home',
11
+ component: 'cpanelDashboard',
12
+ },
13
+ ],
14
+ };
15
+ }
16
+ export { cpanelDashboardRouter };
@@ -0,0 +1,43 @@
1
+ export declare const cpanelDashboardRouter: import("@trpc/server").TRPCBuiltRouter<{
2
+ ctx: {
3
+ headers: Headers;
4
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("nextjs-cms/db/schema")> & {
5
+ $client: import("mysql2/promise").Pool;
6
+ };
7
+ session: import("nextjs-cms").Session | null;
8
+ };
9
+ meta: object;
10
+ errorShape: {
11
+ data: {
12
+ zodError: import("zod").ZodFlattenedError<unknown, string> | null;
13
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
14
+ httpStatus: number;
15
+ path?: string;
16
+ stack?: string;
17
+ };
18
+ message: string;
19
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
20
+ };
21
+ transformer: true;
22
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
23
+ getData: import("@trpc/server").TRPCQueryProcedure<{
24
+ input: void;
25
+ output: {
26
+ dbsLimit: number;
27
+ dbsCount: number;
28
+ bandwidthUsage: number;
29
+ bandwidthLimit: number;
30
+ diskSpaceUsage: number;
31
+ diskSpaceLimit: number;
32
+ emailsUsage: number;
33
+ emailsLimit: number;
34
+ dbInfo: any;
35
+ dbsList: any;
36
+ phpVersion: any;
37
+ passengerAppList: never[];
38
+ documentRoot: any;
39
+ };
40
+ meta: object;
41
+ }>;
42
+ }>>;
43
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;gBAoDd,CAApB;iBAA2B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1B,CAAA"}
package/dist/router.js ADDED
@@ -0,0 +1,72 @@
1
+ import { TRPCError } from '@trpc/server';
2
+ import getString from 'nextjs-cms/translations';
3
+ import { CpanelAPI } from 'nextjs-cms/utils';
4
+ import { privateProcedure, router } from 'nextjs-cms/api/trpc';
5
+ export const cpanelDashboardRouter = router({
6
+ getData: privateProcedure.query(async () => {
7
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
8
+ throw new TRPCError({
9
+ code: 'BAD_REQUEST',
10
+ message: getString('cpanelCredentialsNotSet'),
11
+ });
12
+ }
13
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
14
+ const data = await Promise.all([
15
+ cPanel.callApi('DomainInfo', 'single_domain_data', {
16
+ domain: process.env.CPANEL_DOMAIN,
17
+ }),
18
+ cPanel.callApi('ResourceUsage', 'get_usages'),
19
+ cPanel.callApi('Mysql', 'get_server_information'),
20
+ cPanel.callApi('Mysql', 'list_databases'),
21
+ ]);
22
+ if (cPanel.isError) {
23
+ throw new TRPCError({
24
+ code: 'BAD_REQUEST',
25
+ message: cPanel.getError(),
26
+ });
27
+ }
28
+ const dbInfo = data[2];
29
+ const dbsList = data[3];
30
+ let bandwidthLimit = 0, bandwidthUsage = 0;
31
+ let diskSpaceLimit = 0, usedDiskSpace = 0;
32
+ let emailsLimit = 0, emailsCount = 0;
33
+ let dbsLimit = 0, dbsCount = 0;
34
+ const domainInfoData = data[0].data;
35
+ const cpanelUsagesArray = data[1].data;
36
+ cpanelUsagesArray.forEach((singleItemUsage) => {
37
+ switch (singleItemUsage.id) {
38
+ case 'bandwidth':
39
+ bandwidthLimit = singleItemUsage.maximum || 1000000000000;
40
+ bandwidthUsage = singleItemUsage.usage;
41
+ break;
42
+ case 'disk_usage':
43
+ diskSpaceLimit = singleItemUsage.maximum || 1000000000000;
44
+ usedDiskSpace = singleItemUsage.usage;
45
+ break;
46
+ case 'email_accounts':
47
+ emailsLimit = singleItemUsage.maximum || 1000000000000;
48
+ emailsCount = singleItemUsage.usage;
49
+ break;
50
+ case 'mysql_databases':
51
+ dbsLimit = singleItemUsage.maximum || 1000000000000;
52
+ dbsCount = singleItemUsage.usage;
53
+ break;
54
+ }
55
+ });
56
+ return {
57
+ dbsLimit,
58
+ dbsCount,
59
+ bandwidthUsage,
60
+ bandwidthLimit,
61
+ diskSpaceUsage: usedDiskSpace,
62
+ diskSpaceLimit,
63
+ emailsUsage: emailsCount,
64
+ emailsLimit,
65
+ dbInfo: dbInfo.data,
66
+ dbsList: dbsList.data,
67
+ phpVersion: domainInfoData?.phpversion,
68
+ passengerAppList: [],
69
+ documentRoot: domainInfoData?.documentroot,
70
+ };
71
+ }),
72
+ });
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@nextjs-cms-plugins/cpanel-dashboard",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./client": {
13
+ "types": "./dist/client.d.ts",
14
+ "default": "./dist/client.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist/**/*",
19
+ "README.md"
20
+ ],
21
+ "private": false,
22
+ "dependencies": {
23
+ "@trpc/server": "^11.4.2",
24
+ "zod": "4.1.12"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "19.0.0",
28
+ "react-dom": "19.0.0",
29
+ "nextjs-cms": "0.5.68"
30
+ },
31
+ "devDependencies": {
32
+ "@types/react": "~19.0.0",
33
+ "@types/react-dom": "^19.0.0",
34
+ "typescript": "^5.9.2"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "dev": "tsc --watch",
39
+ "clean": "git clean -xdf .cache .turbo dist node_modules"
40
+ }
41
+ }