Skip to content

Conversation

@Squidly271
Copy link
Contributor

@Squidly271 Squidly271 commented Nov 8, 2025

Check for VNC/Spice ports within range and set default ports to 5900/5901 instead of invalid -1

Summary by CodeRabbit

  • New Features

    • Added port validation ensuring console ports fall within the 5900-65535 range and are not equal to each other.
  • Bug Fixes

    • Updated default GPU console port values.
  • UI/UX Improvements

    • Enhanced console port input fields with range constraints and real-time validation alerts.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

Default GPU port values updated from -1 to 5900 and 5901. Form inputs enhanced with validation attributes. New client-side validation function added to enforce VNC port range constraints (5900-65535) and ensure port values differ.

Changes

Cohort / File(s) Change Summary
VM Console Port Validation
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php
Default GPU port values changed: gpu[0]['port'] from -1 to 5900; gpu[0]['wsport'] from -1 to 5901. Form inputs updated with onchange="checkVNCPorts()", min="5900", and max="65535" attributes. New JavaScript function checkVNCPorts() added to validate port ranges and prevent duplicate values between port and wsport fields.

Sequence Diagram

sequenceDiagram
    participant User
    participant Form as Form Input
    participant Validation as checkVNCPorts()
    participant Alert as Notification

    User->>Form: Change port/wsport value
    Form->>Validation: Trigger onchange event
    Validation->>Validation: Check if port in [5900, 65535]
    Validation->>Validation: Check if wsport in [5900, 65535]
    Validation->>Validation: Check port ≠ wsport
    
    alt Invalid Port Range or Duplicate
        Validation->>Alert: Show error message
        Alert->>User: Display alert
    else Valid Ports
        Validation->>User: ✓ Validation passed
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single file modification with straightforward default value updates
  • New validation function is concise and follows standard form validation patterns
  • No public API changes or exported entity modifications
  • Review focus: ensure port range logic is correct and validation messages are appropriate

Poem

🐰 Ports now dance in harmony,
Default values set so free,
5900 to 65535, validate with care,
No duplicates allowed, it's only fair!
VNC console shines, bugs beware. 🖥️✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding VNC port validation and updating default port values from -1 to sensible defaults.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2025.11.08.0813
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2452/webgui-pr-2452.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2452, or run:

plugin remove webgui-pr-2452

🤖 This comment is automatically generated and will be updated with each new push to this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5f1846 and c450dae.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: Squidly271
Repo: unraid/webgui PR: 0
File: :0-0
Timestamp: 2025-05-31T05:10:13.120Z
Learning: Squidly271 prefers not to receive CodeRabbit reviews or feedback while PRs are in draft status. Only provide reviews after PRs are moved out of draft.
Learnt from: Squidly271
Repo: unraid/webgui PR: 0
File: :0-0
Timestamp: 2025-09-03T07:28:01.902Z
Learning: Squidly271's preference for not reviewing drafts is specifically because they find reviews annoying during active development phases with multiple commits, but they do want reviews once the PR is ready and more stable.
🔇 Additional comments (2)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (2)

106-107: LGTM! Sensible default port values.

The change from -1 to 5900/5901 provides better defaults aligned with standard VNC port conventions.


1328-1330: Good addition of HTML5 validation attributes.

The min, max, and onchange attributes provide appropriate client-side validation constraints for port inputs.

Comment on lines +2091 to +2102
function checkVNCPorts() {
const port = $("#port").val();
const wsport = $("#wsport").val();
if (port < 5900 || port > 65535 || wsport < 5900 || wsport > 65535 || port == wsport) {
swal({
title: "_(Invalid Port)_",
text: "_(VNC/SPICE ports must be between 5900 and 65535, and cannot be equal to each other)_",
type: "error",
confirmButtonText: "_(Ok)_"
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix type coercion bug in numeric comparisons.

The function compares port values using < and > operators on strings returned by .val(), which can produce incorrect results. Additionally, the validation doesn't prevent form submission with invalid values.

Apply this diff to fix the type coercion and add form submission prevention:

 function checkVNCPorts() {
-	const port = $("#port").val();
-	const wsport = $("#wsport").val();
-	if (port < 5900 || port > 65535 || wsport < 5900 || wsport > 65535 || port == wsport) {
+	const port = parseInt($("#port").val(), 10);
+	const wsport = parseInt($("#wsport").val(), 10);
+	
+	// Only validate if fields are visible (autoport is "no")
+	if ($("#port").hasClass("hidden")) {
+		return true;
+	}
+	
+	if (isNaN(port) || isNaN(wsport) || port < 5900 || port > 65535 || wsport < 5900 || wsport > 65535 || port === wsport) {
 		swal({
 			title: "_(Invalid Port)_",
 			text: "_(VNC/SPICE ports must be between 5900 and 65535, and cannot be equal to each other)_",
 			type: "error",
 			confirmButtonText: "_(Ok)_"
 		});
+		return false;
 	}
+	return true;
 }

Additionally, consider validating before form submission by adding a check in the submit handlers (around lines 2662 and 2809):

// In the form submit handlers, before posting:
if (!checkVNCPorts()) {
	$panel.find('input').prop('disabled', false);
	$button.val($button.attr('readyvalue'));
	return;
}
🤖 Prompt for AI Agents
In emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php around lines 2091
to 2102, checkVNCPorts currently compares string values from .val(), causing
type coercion bugs and it doesn't prevent submission; update the function to
parse port and wsport to integers (use parseInt with base 10), validate for NaN
and the 5900–65535 range and inequality, return false when invalid (and show the
existing swal) and true when valid; then add the suggested pre-submit guard in
the form submit handlers near lines 2662 and 2809: call checkVNCPorts(), and if
it returns false re-enable inputs, reset the button value and return early to
stop the post.

@Squidly271 Squidly271 added the 7.3 label Nov 8, 2025
@limetech limetech merged commit 8fa0abe into unraid:master Nov 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants