Skip to content

VM template fixes#2020

Merged
limetech merged 34 commits into
unraid:masterfrom
bergware:master
Feb 15, 2025
Merged

VM template fixes#2020
limetech merged 34 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Feb 13, 2025

Copy link
Copy Markdown
Contributor
  • fix show/hide elements
  • fix translations

Summary by CodeRabbit

  • Style

    • Added a new CSS class .hidden to control element visibility more effectively.
    • Refined on-screen warnings and messages to enhance clarity when configuring storage names and options.
  • Refactor

    • Improved the responsiveness and interactive behavior of virtual machine configuration controls, ensuring smoother handling of disk, BIOS, port, and video settings.
    • Streamlined the mechanism for toggling visibility of configuration fields for a more consistent user experience.
    • Enhanced the identification of HTML elements for better DOM management.
  • Bug Fixes

    • Enhanced error handling for network variable assignments to prevent undefined variable notices.
    • Improved file reading behavior to avoid warnings when accessing non-existent files.
    • Adjusted logic for WiFi connection status checks to ensure more reliable detection.
    • Enhanced the handling of WiFi SSID retrieval to improve accuracy when connected.
  • New Features

    • Introduced an updated method for managing WiFi updates, allowing for more frequent checks and improved data handling based on network conditions.
    • Enhanced logic for managing virtual machine snapshots and ZFS configurations for better user experience.
    • Added several new functions to improve user interactions with array operations and maintenance features.
    • Enhanced the user interface for managing array operations, particularly in terms of maintenance and encryption handling.

- fix show/hide elements
- fix translations
@coderabbitai

coderabbitai Bot commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@bergware has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 28d620e and de3b154.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/scripts/notify (1 hunks)

Walkthrough

The changes update the Custom.form.php file to enhance virtual machine management, including refining conditional logic, updating HTML for snapshot warnings, and revising JavaScript functions for improved control over disk bus and SSD checks. Additional modifications in NetworkInfo.php, Wrappers.php, and wireless-related files improve robustness and error handling. New functions in ArrayOperation.page expand maintenance and disk operations capabilities, while a new CSS class in ArrayOperation.css standardizes element visibility control.

Changes

File Path Change Summary
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php - Enhanced conditional logic for snapshots
- Updated HTML for snapshot warnings using $snaphidden
- Revised JavaScript functions (BusChange, updateSSDCheck, BIOSChange, AutoportChange, VMConsoleDriverChange) to include new parameters and improve visibility handling
emhttp/plugins/dynamix/include/NetworkInfo.php - Introduced null coalescing operator for $eth and $vlan to prevent undefined variable notices; updated logic for displaying wireless info.
emhttp/plugins/dynamix/include/Wrappers.php - Modified lan_port function to add error suppression for file_get_contents and return 0 instead of false if the file is inaccessible.
emhttp/plugins/dynamix/Wireless.page - Updated update_wifi function to accept a parameter load and modified AJAX request accordingly; reduced timeout from 10000 ms to 6000 ms.
emhttp/plugins/dynamix/include/Wireless.php - Added $load variable in the list case to alter logic for populating the $wlan array based on existing configuration data.
emhttp/plugins/dynamix/nchan/wlan0 - Changed checks for WiFi connection status from file_exists to is_readable and updated SSID retrieval logic for better reliability.
emhttp/plugins/dynamix/ArrayOperation.page - Added multiple new functions for enhanced maintenance and disk operations management, including maintenance_mode(), status_indicator(), and others.
emhttp/plugins/dynamix/sheets/ArrayOperation.css - Introduced a new CSS class .hidden for controlling element visibility.
emhttp/plugins/dynamix/scripts/netconfig - Updated formatting in the port function for consistent style; no changes to functional logic.

Possibly related PRs

  • 7.x Various VM Updates #1988: The changes in the main PR are related to the modifications in the Custom.form.php file, specifically the updates to the VMConsoleDriverChange function and the GPU configuration, which align with the enhancements made in the retrieved PR regarding virtual machine configurations and display options.
  • VM: make reference to interface instead of vhost #2013: The changes in the main PR, specifically the modifications to the Custom.form.php file regarding network interface handling, are directly related to the updates in the retrieved PR that also involve network interface configurations in the libvirt.php and libvirt_helpers.php files. Both PRs enhance the management of network interfaces for virtual machines.

Poem

I'm a bunny in a code field, hopping so free,
Tweaking bits and bytes with joyful glee.
New parameters and clearer tags in play,
Making VM configurations a brighter day.
Hoppily I code, through changes I bound,
Spreading smiles and updates all around!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (3)

1285-1287: Improved port input field handling

The port and WebSocket port input fields now use semantic class names for visibility control. Consider adding input validation to ensure valid port numbers are entered.

-<input id="port" type="number" size="5" maxlength="5" class="trim second <?=$hiddenport?>" name="gpu[<?=$i?>][port]" value="<?=$arrGPU['port']?>">
+<input id="port" type="number" size="5" maxlength="5" min="1" max="65535" class="trim second <?=$hiddenport?>" name="gpu[<?=$i?>][port]" value="<?=$arrGPU['port']?>">

-<input id="wsport" type="number" size="5" maxlength="5" class="trim second <?=$hiddenwsport?>" name="gpu[<?=$i?>][wsport]" value="<?=$arrGPU['wsport']?>">
+<input id="wsport" type="number" size="5" maxlength="5" min="1" max="65535" class="trim second <?=$hiddenwsport?>" name="gpu[<?=$i?>][wsport]" value="<?=$arrGPU['wsport']?>">

2146-2163: Enhanced port configuration visibility

The AutoportChange function has been improved to handle port visibility more consistently. However, consider adding error handling for invalid port configurations.

Add validation to ensure port numbers don't conflict when manually configured:

function AutoportChange(autoport) {
  $("#port").removeClass('hidden');
  $("#Porttext").removeClass('hidden');
  $("#wsport").removeClass('hidden');
  $("#WSPorttext").removeClass('hidden');
  if (autoport.value == "yes") {
    $("#port").addClass('hidden');
    $("#Porttext").addClass('hidden');
    $("#wsport").addClass('hidden');
    $("#WSPorttext").addClass('hidden');
  } else {
    var protocol = document.getElementById("protocol").value;
+   // Validate port numbers when manually configured
+   $("#port").on('change', function() {
+     var port = parseInt($(this).val());
+     var wsport = parseInt($("#wsport").val());
+     if (port === wsport) {
+       alert("Port and WebSocket port must be different");
+       $(this).val('');
+     }
+   });
    if (protocol != "vnc") {
      $("#wsport").addClass('hidden');
      $("#WSPorttext").addClass('hidden');
    }
  }
}

2694-2696: Improved template creation dialog

The template creation dialog text has been updated to be more descriptive. Consider adding validation for the template name to prevent invalid characters.

swal({
  title: "_(Template Name)_",
  text: "_(Enter name)_:\n_(If name already exists it will be replaced)_.",
  type: "input",
  showCancelButton: true,
  closeOnConfirm: false,
+ inputValidator: (value) => {
+   if (!/^[a-zA-Z0-9-_]+$/.test(value)) {
+     return 'Template name can only contain letters, numbers, hyphens and underscores';
+   }
+ },
  inputPlaceholder: "_(Leaving blank will use OS name)_."
},

Also applies to: 2700-2700

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fb440a and 8c2590d.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (18 hunks)
🔇 Additional comments (5)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (5)

350-354: Improved element identification with semantic ID

The addition of id="zfs-name" to the <tr> element improves element identification and accessibility. The warning message has also been updated to be more descriptive.


2036-2047: Improved SSD flag handling

The BusChange and updateSSDCheck functions have been updated to handle SSD flags more consistently. The code now properly toggles visibility of SSD-related elements based on the bus type.


2049-2056: Improved BIOS change handling

The BIOSChange function now properly handles USB boot options visibility based on the BIOS type. The code uses consistent class manipulation for showing/hiding elements.


2165-2178: Improved video driver configuration

The VMConsoleDriverChange function now handles rendering options visibility more consistently. The code uses proper class manipulation for showing/hiding elements based on the selected driver.


916-917:

Details

✅ Verification successful

Verify disk bus change handling

The BusChange function now accepts an index parameter to handle multiple disks correctly. However, ensure that all existing calls to this function have been updated to pass the required index parameter.

Also applies to: 927-927


🏁 Script executed:

#!/bin/bash
# Search for any calls to BusChange that don't pass an index parameter
rg -A 2 "BusChange\([^,]+" 

Length of output: 2152


Disk Bus Change Handling Verified

The updated file (emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php) correctly calls BusChange with two parameters (e.g., using <?=$i?> and {{INDEX}}), and the function itself is defined as function BusChange(value, index) { … }. This confirms that the changes on lines 916–917 and 927 are in line with the intention of handling multiple disks.

• Verified that the select elements now invoke BusChange(this.value,<?=$i?>) and BusChange(this.value,{{INDEX}}).
• Confirmed that the corresponding BusChange definition accepts both value and index parameters.
• Note: The legacy file (Custom.formold.php) still contains outdated calls (e.g., BusChange(this)), which you may want to review if that file remains in active use.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (6)

350-357: Improve error message visibility handling.

The error message container for ZFS name validation has been updated to use class-based visibility control. While this works, consider adding ARIA attributes for better accessibility.

-<tr id="zfs-name" class="hidden">
+<tr id="zfs-name" class="hidden" role="alert" aria-live="polite">

2036-2043: Improve class manipulation for disk rotation UI.

The code uses jQuery's addClass/removeClass for toggling visibility. Consider using classList for better performance.

-$('input[id="disk['+index+'][rotation]"]').removeClass('hidden');
-$('span[id="disk['+index+'][rotatetext]"]').removeClass('hidden');
+document.querySelector('input[id="disk['+index+'][rotation]"]').classList.remove('hidden');
+document.querySelector('span[id="disk['+index+'][rotatetext]"]').classList.remove('hidden');

2046-2047: Simplify SSD checkbox value update.

The current implementation uses jQuery to get the checked state. This can be simplified.

-ssd.value = $(ssd).prop('checked') ? "1" : "0";
+ssd.value = ssd.checked ? "1" : "0";

2627-2634: Improve translation string handling.

Translation strings are properly marked with _() function. However, consider using template literals for better readability.

-title: "_(Template Name)_",
-text: "_(Enter name)_:\n_(If name already exists it will be replaced)_.",
-inputPlaceholder: "_(Leaving blank will use OS name)_."
+title: _("Template Name"),
+text: `${_("Enter name")}:\n${_("If name already exists it will be replaced")}.`,
+inputPlaceholder: _("Leaving blank will use OS name")

1471-1474: Improve conditional rendering logic.

The code uses class manipulation for visibility. Consider using data attributes for better maintainability.

-if (mylabel == "_(None)_") $("#gpubootvga"+myindex).removeClass().addClass('hidden');
+if (mylabel == "_(None)_") {
+  const element = document.querySelector("#gpubootvga"+myindex);
+  element.dataset.visible = 'false';
+  element.classList.add('hidden');
+}

926-927: Improve checkbox initialization.

The code mixes HTML attributes and JavaScript for checkbox state. Consider using a single source of truth.

-<input type="checkbox" id="disk[<?=$i?>][rotation]" class="rotation <?=$ssddisabled?>" onchange="updateSSDCheck(this)" name="disk[<?=$i?>][rotation]" <?=$arrDisk['rotation'] ? "checked ":"";?> value="<?=$arrDisk['rotation']?>">
+<input type="checkbox" id="disk[<?=$i?>][rotation]" class="rotation <?=$ssddisabled?>" onchange="updateSSDCheck(this)" name="disk[<?=$i?>][rotation]" data-initial-state="<?=$arrDisk['rotation']?>" value="<?=$arrDisk['rotation']?>">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7c881a and d84e9be.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (18 hunks)
🔇 Additional comments (3)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (3)

1036-1042: LGTM! Improved dropdown options handling.

The code properly handles manual option selection in disk configuration.


2049-2056: LGTM! Clean implementation of BIOS change handler.

The function properly handles USB boot options visibility based on BIOS selection.


749-751: LGTM! Clear documentation for USB Controller options.

The code includes well-written documentation explaining USB controller options and OS compatibility.

Comment on lines +1285 to 1288
<input id="port" type="number" size="5" maxlength="5" class="trim second <?=$hiddenport?>" name="gpu[<?=$i?>][port]" value="<?=$arrGPU['port']?>">
<span id="WSPorttext" class="label <?=$hiddenwsport?>">_(VM Console WS Port)_:</span>
<input type="number" size="5" maxlength="5" id="wsport" class="trim second <?=$hiddenwsport?>" name="gpu[<?=$i?>][wsport]" value="<?=$arrGPU['wsport']?>">
<input id="wsport" type="number" size="5" maxlength="5" class="trim second <?=$hiddenwsport?>" name="gpu[<?=$i?>][wsport]" value="<?=$arrGPU['wsport']?>">
</td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify port number validation.

The code accepts port numbers without validation. Consider adding range checks for valid port numbers.


🏁 Script executed:

#!/bin/bash
# Check for any port number validation in the codebase
rg -A 2 'port.*=.*value' | grep -E 'if.*port.*[<>]'

Length of output: 102483


Action Required: Missing Range Validation for Port Numbers

The input fields for the GPU port numbers in this file currently lack any range validation checks. Unlike similar port inputs elsewhere (e.g., in WGX.page and WG0.page where explicit min/max attributes are used), these fields do not enforce valid port values through additional attributes or conditional checks. Please consider adding proper validation—either via HTML attributes (such as setting min="1" and max="65535") or through server‐side/client‐side logic—to ensure only valid port numbers are accepted.

  • File: emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (Lines 1285–1288)
  • Suggestion: Add range checks by:
    • Including HTML attributes (min and max) in the <input> elements.
    • Implementing appropriate validation logic in any supporting JavaScript or PHP that processes these values.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (1)

1286-1289: ⚠️ Potential issue

Add port number validation.

The code accepts port numbers without validation, which could lead to invalid configurations.

Add proper validation for port numbers to ensure they are within valid ranges (1-65535).

🧹 Nitpick comments (6)
emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (6)

350-358: Improve warning message visibility handling.

The code uses direct class manipulation for showing/hiding warning messages. Consider using a dedicated function to handle visibility state changes consistently.

-	<tr id="zfs-name" class="hidden">
+	<tr id="zfs-name" class="warning-message hidden">

And add a utility function:

function toggleWarningVisibility(elementId, show) {
  const element = document.getElementById(elementId);
  if (element) {
    element.classList.toggle('hidden', !show);
  }
}

1038-1045: Improve disk bus change handler.

The function uses direct DOM manipulation for showing/hiding SSD-related elements. Consider using a more maintainable approach with data attributes.

-function BusChange(value, index) {
-  $('input[id="disk['+index+'][rotation]"]').removeClass('hidden');
-  $('span[id="disk['+index+'][rotatetext]"]').removeClass('hidden');
-  if (value == "virtio" || value == "usb" ) {
-    $('input[id="disk['+index+'][rotation]"]').addClass('hidden');
-    $('span[id="disk['+index+'][rotatetext]"]').addClass('hidden');
-  }
-}
+function BusChange(value, index) {
+  const hideSSD = value === "virtio" || value === "usb";
+  const elements = document.querySelectorAll(`[data-disk-index="${index}"][data-ssd-element]`);
+  elements.forEach(el => el.classList.toggle('hidden', hideSSD));
+}

2047-2049: Simplify SSD check update handler.

The function can be simplified to a one-liner using the checked property directly.

-function updateSSDCheck(ssd) {
-  ssd.value = $(ssd).prop('checked') ? "1" : "0";
-}
+const updateSSDCheck = ssd => ssd.value = ssd.checked ? "1" : "0";

2051-2058: Improve BIOS change handler.

The function uses direct DOM manipulation for showing/hiding USB boot elements. Consider using a more maintainable approach.

-function BIOSChange(value) {
-  $("#USBBoottext").removeClass('hidden');
-  $("#domain_usbboot").removeClass('hidden');
-  if (value == "0") {
-    $("#USBBoottext").addClass('hidden');
-    $("#domain_usbboot").addClass('hidden');
-  }
-}
+function BIOSChange(value) {
+  const showUSBBoot = value !== "0";
+  ["USBBoottext", "domain_usbboot"].forEach(id => {
+    document.getElementById(id)?.classList.toggle('hidden', !showUSBBoot);
+  });
+}

2148-2165: Improve autoport change handler.

The function has redundant class manipulations and can be simplified.

-function AutoportChange(autoport) {
-  $("#port").removeClass('hidden');
-  $("#Porttext").removeClass('hidden');
-  $("#wsport").removeClass('hidden');
-  $("#WSPorttext").removeClass('hidden');
-  if (autoport.value == "yes") {
-    $("#port").addClass('hidden');
-    $("#Porttext").addClass('hidden');
-    $("#wsport").addClass('hidden');
-    $("#WSPorttext").addClass('hidden');
-  } else {
-    var protocol = document.getElementById("protocol").value;
-    if (protocol != "vnc") {
-      $("#wsport").addClass('hidden');
-      $("#WSPorttext").addClass('hidden');
-    }
-  }
-}
+function AutoportChange(autoport) {
+  const elements = ["port", "Porttext", "wsport", "WSPorttext"];
+  const hideAll = autoport.value === "yes";
+  const protocol = document.getElementById("protocol").value;
+  
+  elements.forEach(id => {
+    const el = document.getElementById(id);
+    if (el) {
+      const isWSElement = id.toLowerCase().includes('ws');
+      el.classList.toggle('hidden', hideAll || (protocol !== "vnc" && isWSElement));
+    }
+  });
+}

2167-2180: Improve VM console driver change handler.

The function has redundant class manipulations and can be simplified.

-function VMConsoleDriverChange(driver) {
-  $("#vncrender").removeClass('hidden');
-  $("#vncrendertext").removeClass('hidden');
-  if (driver.value != "virtio3d") {
-    $("#vncrender").addClass('hidden');
-    $("#vncrendertext").addClass('hidden');
-  }
-  $("#vncdspopt").removeClass('hidden');
-  $("#vncdspopttext").removeClass('hidden');
-  if (driver.value != "qxl") {
-    $("#vncdspopt").addClass('hidden');
-    $("#vncdspopttext").addClass('hidden');
-  }
-}
+function VMConsoleDriverChange(driver) {
+  const elements = {
+    render: ["vncrender", "vncrendertext"],
+    display: ["vncdspopt", "vncdspopttext"]
+  };
+  
+  elements.render.forEach(id => {
+    document.getElementById(id)?.classList.toggle('hidden', driver.value !== "virtio3d");
+  });
+  
+  elements.display.forEach(id => {
+    document.getElementById(id)?.classList.toggle('hidden', driver.value !== "qxl");
+  });
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4902592 and f9d1443.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php (19 hunks)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
emhttp/plugins/dynamix/include/Wireless.php (1)

77-95: Consider simplifying the array initialization logic.

While the logic is correct, it could be more concise by using early returns.

Consider this alternative:

-  if ($load && count(array_keys($wifi)) > 1) {
-    foreach ($wifi as $network => $block) {
-      if ($network == $port) continue;
-      $wlan[$index]['bss'] = $block['ATTR1'];
-      $wlan[$index]['signal'] = $block['ATTR2'];
-      $wlan[$index]['security'] = $block['ATTR3'] ?? $block['SECURITY'];
-      $wlan[$index]['ssid'] = $network;
-      $index++;
-    }
-    $index = 0;
-  } else {
-    $wlan  = scanWifi($port);
-  }
+  if (!$load || count(array_keys($wifi)) <= 1) {
+    return scanWifi($port);
+  }
+  
+  $wlan = [];
+  foreach ($wifi as $network => $block) {
+    if ($network == $port) continue;
+    $wlan[] = [
+      'bss' => $block['ATTR1'],
+      'signal' => $block['ATTR2'],
+      'security' => $block['ATTR3'] ?? $block['SECURITY'],
+      'ssid' => $network
+    ];
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad120e and 3c6301d.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix/Wireless.page (2 hunks)
  • emhttp/plugins/dynamix/include/Wireless.php (2 hunks)
🔇 Additional comments (4)
emhttp/plugins/dynamix/Wireless.page (2)

67-77: LGTM! Performance and UX improvements.

The changes improve the function by:

  • Adding load parameter for optimized scanning
  • Reducing update interval for better responsiveness
  • Adding conditional rendering to prevent empty sections

149-149: LGTM! Proper initialization.

The change correctly passes the load parameter for initial WiFi scanning.

emhttp/plugins/dynamix/include/Wireless.php (2)

97-97: LGTM! Improved error handling.

The change from file_exists to is_readable improves security by ensuring both file existence and proper permissions.


122-122: LGTM! Better empty state handling.

The change improves UX by preventing the "None" message from flickering during initial load.

Comment thread emhttp/plugins/dynamix/include/NetworkInfo.php
Comment thread emhttp/plugins/dynamix/include/NetworkInfo.php Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
emhttp/plugins/dynamix/scripts/wireless (1)

34-34: Consider improving readability of the complex condition.

While the null coalescing operator improves robustness, the condition combines multiple checks that could be more readable if split:

-    if (($block['GROUP']??'') == $state && (!$arg || $arg == $network)) {
+    $groupState = $block['GROUP'] ?? '';
+    $isTargetNetwork = !$arg || $arg == $network;
+    if ($groupState == $state && $isTargetNetwork) {

This refactoring:

  1. Makes the logic more self-documenting
  2. Maintains the same robust behavior
  3. Separates concerns for easier maintenance
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e16fb7b and 561e9b4.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix/scripts/wireless (1 hunks)
  • etc/rc.d/rc.docker (1 hunks)
🔇 Additional comments (2)
etc/rc.d/rc.docker (1)

471-477: LGTM! Improved network interface cleanup.

The changes correctly move the VHOST assignment into the else block and add proper cleanup of IP addresses for existing vhost interfaces when host access is disabled. This ensures that network interfaces are properly managed and prevents potential IP address conflicts.

emhttp/plugins/dynamix/scripts/wireless (1)

31-31: LGTM! Improved control flow with defensive programming.

The addition of the null coalescing operator and explicit wireless check enhances robustness by ensuring the configuration block only executes when wireless is actually enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants