Skip to content

Commit 537d652

Browse files
feat: improve LXC settings modal and fix database issues (#174)
- Fix Prisma database errors in LXC config sync (advanced and rootfs field issues) - Remove double confirmation from LXC settings modal (keep confirmation modal, remove inline input) - Fix dependency loop in status check useEffect - Add LXC configuration management with proper validation - Improve error handling and user experience
1 parent ef460b5 commit 537d652

File tree

16 files changed

+1425
-51
lines changed

16 files changed

+1425
-51
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
-- CreateTable
2+
CREATE TABLE "installed_scripts" (
3+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4+
"script_name" TEXT NOT NULL,
5+
"script_path" TEXT NOT NULL,
6+
"container_id" TEXT,
7+
"server_id" INTEGER,
8+
"execution_mode" TEXT NOT NULL,
9+
"installation_date" DATETIME DEFAULT CURRENT_TIMESTAMP,
10+
"status" TEXT NOT NULL,
11+
"output_log" TEXT,
12+
"web_ui_ip" TEXT,
13+
"web_ui_port" INTEGER,
14+
CONSTRAINT "installed_scripts_server_id_fkey" FOREIGN KEY ("server_id") REFERENCES "servers" ("id") ON DELETE SET NULL ON UPDATE CASCADE
15+
);
16+
17+
-- CreateTable
18+
CREATE TABLE "servers" (
19+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
20+
"name" TEXT NOT NULL,
21+
"ip" TEXT NOT NULL,
22+
"user" TEXT NOT NULL,
23+
"password" TEXT,
24+
"auth_type" TEXT DEFAULT 'password',
25+
"ssh_key" TEXT,
26+
"ssh_key_passphrase" TEXT,
27+
"ssh_port" INTEGER DEFAULT 22,
28+
"color" TEXT,
29+
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
30+
"updated_at" DATETIME,
31+
"ssh_key_path" TEXT,
32+
"key_generated" BOOLEAN DEFAULT false
33+
);
34+
35+
-- CreateTable
36+
CREATE TABLE "lxc_configs" (
37+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
38+
"installed_script_id" INTEGER NOT NULL,
39+
"arch" TEXT,
40+
"cores" INTEGER,
41+
"memory" INTEGER,
42+
"hostname" TEXT,
43+
"swap" INTEGER,
44+
"onboot" INTEGER,
45+
"ostype" TEXT,
46+
"unprivileged" INTEGER,
47+
"net_name" TEXT,
48+
"net_bridge" TEXT,
49+
"net_hwaddr" TEXT,
50+
"net_ip_type" TEXT,
51+
"net_ip" TEXT,
52+
"net_gateway" TEXT,
53+
"net_type" TEXT,
54+
"net_vlan" INTEGER,
55+
"rootfs_storage" TEXT,
56+
"rootfs_size" TEXT,
57+
"feature_keyctl" INTEGER,
58+
"feature_nesting" INTEGER,
59+
"feature_fuse" INTEGER,
60+
"feature_mount" TEXT,
61+
"tags" TEXT,
62+
"advanced_config" TEXT,
63+
"synced_at" DATETIME,
64+
"config_hash" TEXT,
65+
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
66+
"updated_at" DATETIME NOT NULL,
67+
CONSTRAINT "lxc_configs_installed_script_id_fkey" FOREIGN KEY ("installed_script_id") REFERENCES "installed_scripts" ("id") ON DELETE CASCADE ON UPDATE CASCADE
68+
);
69+
70+
-- CreateIndex
71+
CREATE UNIQUE INDEX "servers_name_key" ON "servers"("name");
72+
73+
-- CreateIndex
74+
CREATE UNIQUE INDEX "lxc_configs_installed_script_id_key" ON "lxc_configs"("installed_script_id");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "sqlite"

prisma/schema.prisma

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ model InstalledScript {
2020
web_ui_ip String?
2121
web_ui_port Int?
2222
server Server? @relation(fields: [server_id], references: [id], onDelete: SetNull)
23+
lxc_config LXCConfig?
2324
2425
@@map("installed_scripts")
2526
}
@@ -43,3 +44,54 @@ model Server {
4344
4445
@@map("servers")
4546
}
47+
48+
model LXCConfig {
49+
id Int @id @default(autoincrement())
50+
installed_script_id Int @unique
51+
installed_script InstalledScript @relation(fields: [installed_script_id], references: [id], onDelete: Cascade)
52+
53+
// Basic settings
54+
arch String?
55+
cores Int?
56+
memory Int?
57+
hostname String?
58+
swap Int?
59+
onboot Int? // 0 or 1
60+
ostype String?
61+
unprivileged Int? // 0 or 1
62+
63+
// Network settings (net0)
64+
net_name String?
65+
net_bridge String?
66+
net_hwaddr String?
67+
net_ip_type String? // 'dhcp' or 'static'
68+
net_ip String? // IP with CIDR for static
69+
net_gateway String?
70+
net_type String? // usually 'veth'
71+
net_vlan Int?
72+
73+
// Storage
74+
rootfs_storage String?
75+
rootfs_size String?
76+
77+
// Features
78+
feature_keyctl Int? // 0 or 1
79+
feature_nesting Int? // 0 or 1
80+
feature_fuse Int? // 0 or 1
81+
feature_mount String? // other mount features
82+
83+
// Tags
84+
tags String?
85+
86+
// Advanced/raw settings (lxc.* entries and other uncommon settings)
87+
advanced_config String? // Text blob for advanced settings
88+
89+
// Metadata
90+
synced_at DateTime?
91+
config_hash String? // Hash of server config for diff detection
92+
93+
created_at DateTime @default(now())
94+
updated_at DateTime @updatedAt
95+
96+
@@map("lxc_configs")
97+
}

src/app/_components/HelpModal.tsx

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface HelpModalProps {
1010
initialSection?: string;
1111
}
1212

13-
type HelpSection = 'server-settings' | 'general-settings' | 'sync-button' | 'available-scripts' | 'downloaded-scripts' | 'installed-scripts' | 'update-system';
13+
type HelpSection = 'server-settings' | 'general-settings' | 'sync-button' | 'available-scripts' | 'downloaded-scripts' | 'installed-scripts' | 'lxc-settings' | 'update-system';
1414

1515
export function HelpModal({ isOpen, onClose, initialSection = 'server-settings' }: HelpModalProps) {
1616
const [activeSection, setActiveSection] = useState<HelpSection>(initialSection as HelpSection);
@@ -24,6 +24,7 @@ export function HelpModal({ isOpen, onClose, initialSection = 'server-settings'
2424
{ id: 'available-scripts' as HelpSection, label: 'Available Scripts', icon: Package },
2525
{ id: 'downloaded-scripts' as HelpSection, label: 'Downloaded Scripts', icon: HardDrive },
2626
{ id: 'installed-scripts' as HelpSection, label: 'Installed Scripts', icon: FolderOpen },
27+
{ id: 'lxc-settings' as HelpSection, label: 'LXC Settings', icon: Settings },
2728
{ id: 'update-system' as HelpSection, label: 'Update System', icon: Download },
2829
];
2930

@@ -501,6 +502,131 @@ export function HelpModal({ isOpen, onClose, initialSection = 'server-settings'
501502
</div>
502503
);
503504

505+
case 'lxc-settings':
506+
return (
507+
<div className="space-y-6">
508+
<div>
509+
<h3 className="text-xl font-semibold text-foreground mb-4">LXC Settings</h3>
510+
<p className="text-muted-foreground mb-6">
511+
Edit LXC container configuration files directly from the installed scripts interface. This feature allows you to modify container settings without manually accessing the Proxmox VE server.
512+
</p>
513+
</div>
514+
515+
<div className="space-y-4">
516+
<div className="p-4 border border-border rounded-lg">
517+
<h4 className="font-medium text-foreground mb-2">Overview</h4>
518+
<p className="text-sm text-muted-foreground mb-3">
519+
The LXC Settings modal provides a user-friendly interface to edit container configuration files. It parses common settings into editable fields while preserving advanced configurations.
520+
</p>
521+
<ul className="text-sm text-muted-foreground space-y-1">
522+
<li><strong>Common Settings:</strong> Edit basic container parameters like cores, memory, network, and storage</li>
523+
<li><strong>Advanced Settings:</strong> Raw text editing for lxc.* entries and other advanced configurations</li>
524+
<li><strong>Database Caching:</strong> Configurations are cached locally for faster access</li>
525+
<li><strong>Change Detection:</strong> Warns when cached config differs from server version</li>
526+
</ul>
527+
</div>
528+
529+
<div className="p-4 border border-border rounded-lg">
530+
<h4 className="font-medium text-foreground mb-2">Common Settings Tab</h4>
531+
<div className="space-y-3">
532+
<div>
533+
<h5 className="font-medium text-sm text-foreground mb-1">Basic Configuration</h5>
534+
<ul className="text-sm text-muted-foreground space-y-1">
535+
<li><strong>Architecture:</strong> Container architecture (usually amd64)</li>
536+
<li><strong>Cores:</strong> Number of CPU cores allocated to the container</li>
537+
<li><strong>Memory:</strong> RAM allocation in megabytes</li>
538+
<li><strong>Swap:</strong> Swap space allocation in megabytes</li>
539+
<li><strong>Hostname:</strong> Container hostname</li>
540+
<li><strong>OS Type:</strong> Operating system type (e.g., debian, ubuntu)</li>
541+
<li><strong>Start on Boot:</strong> Whether to start container automatically on host boot</li>
542+
<li><strong>Unprivileged:</strong> Whether the container runs in unprivileged mode</li>
543+
</ul>
544+
</div>
545+
546+
<div>
547+
<h5 className="font-medium text-sm text-foreground mb-1">Network Configuration</h5>
548+
<ul className="text-sm text-muted-foreground space-y-1">
549+
<li><strong>IP Configuration:</strong> Choose between DHCP or static IP assignment</li>
550+
<li><strong>IP Address:</strong> Static IP with CIDR notation (e.g., 10.10.10.164/24)</li>
551+
<li><strong>Gateway:</strong> Network gateway for static IP configuration</li>
552+
<li><strong>Bridge:</strong> Network bridge interface (usually vmbr0)</li>
553+
<li><strong>MAC Address:</strong> Hardware address for the network interface</li>
554+
<li><strong>VLAN Tag:</strong> Optional VLAN tag for network segmentation</li>
555+
</ul>
556+
</div>
557+
558+
<div>
559+
<h5 className="font-medium text-sm text-foreground mb-1">Storage & Features</h5>
560+
<ul className="text-sm text-muted-foreground space-y-1">
561+
<li><strong>Root Filesystem:</strong> Storage location and disk identifier</li>
562+
<li><strong>Size:</strong> Disk size allocation (e.g., 4G, 8G)</li>
563+
<li><strong>Features:</strong> Container capabilities (keyctl, nesting, fuse)</li>
564+
<li><strong>Tags:</strong> Comma-separated tags for organization</li>
565+
</ul>
566+
</div>
567+
</div>
568+
</div>
569+
570+
<div className="p-4 border border-border rounded-lg">
571+
<h4 className="font-medium text-foreground mb-2">Advanced Settings Tab</h4>
572+
<p className="text-sm text-muted-foreground mb-3">
573+
The Advanced Settings tab provides raw text editing for configurations not covered in the Common Settings tab.
574+
</p>
575+
<ul className="text-sm text-muted-foreground space-y-1">
576+
<li><strong>lxc.* entries:</strong> Low-level LXC configuration options</li>
577+
<li><strong>Comments:</strong> Configuration file comments and documentation</li>
578+
<li><strong>Custom settings:</strong> Any other configuration parameters</li>
579+
<li><strong>Preservation:</strong> All content is preserved when switching between tabs</li>
580+
</ul>
581+
</div>
582+
583+
<div className="p-4 border border-border rounded-lg">
584+
<h4 className="font-medium text-foreground mb-2">Saving Changes</h4>
585+
<div className="space-y-3">
586+
<p className="text-sm text-muted-foreground">
587+
To save configuration changes, you must type the container ID exactly as shown to confirm your changes.
588+
</p>
589+
<div className="bg-yellow-50 dark:bg-yellow-950/20 border border-yellow-200 dark:border-yellow-800 rounded-md p-3">
590+
<h5 className="font-medium text-yellow-800 dark:text-yellow-200 mb-2">⚠️ Important Warnings</h5>
591+
<ul className="text-sm text-yellow-700 dark:text-yellow-300 space-y-1">
592+
<li>• Modifying LXC configuration can break your container</li>
593+
<li>• Some changes may require container restart to take effect</li>
594+
<li>• Always backup your configuration before making changes</li>
595+
<li>• Test changes in a non-production environment first</li>
596+
</ul>
597+
</div>
598+
</div>
599+
</div>
600+
601+
<div className="p-4 border border-border rounded-lg">
602+
<h4 className="font-medium text-foreground mb-2">Sync from Server</h4>
603+
<p className="text-sm text-muted-foreground mb-3">
604+
The &quot;Sync from Server&quot; button allows you to refresh the configuration from the actual server file, useful when:
605+
</p>
606+
<ul className="text-sm text-muted-foreground space-y-1">
607+
<li>• Configuration was modified outside of this interface</li>
608+
<li>• You want to discard local changes and get the latest server version</li>
609+
<li>• The warning banner indicates the cached config differs from server</li>
610+
<li>• You want to ensure you&apos;re working with the most current configuration</li>
611+
</ul>
612+
</div>
613+
614+
<div className="p-4 border border-border rounded-lg">
615+
<h4 className="font-medium text-foreground mb-2">Database Caching</h4>
616+
<p className="text-sm text-muted-foreground mb-3">
617+
LXC configurations are cached in the database for improved performance and offline access.
618+
</p>
619+
<ul className="text-sm text-muted-foreground space-y-1">
620+
<li><strong>Automatic caching:</strong> Configs are cached during auto-detection and after saves</li>
621+
<li><strong>Cache expiration:</strong> Cached configs expire after 5 minutes for freshness</li>
622+
<li><strong>Change detection:</strong> Hash comparison detects external modifications</li>
623+
<li><strong>Manual sync:</strong> Always available via the &quot;Sync from Server&quot; button</li>
624+
</ul>
625+
</div>
626+
</div>
627+
</div>
628+
);
629+
504630
default:
505631
return null;
506632
}

0 commit comments

Comments
 (0)