Skip to content

Wireless support - fine tuning#2001

Merged
limetech merged 4 commits into
unraid:masterfrom
bergware:master
Feb 7, 2025
Merged

Wireless support - fine tuning#2001
limetech merged 4 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores
    • Enhanced the wireless setup process to generate a more consistent unique identifier.
    • Enabled complete diagnostic logging for improved troubleshooting of wireless connectivity.
    • Updated the scope of the network driver variable for better accessibility within the Docker management functionality.
    • Improved language translation management by dynamically responding to locale changes.

@coderabbitai

coderabbitai Bot commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The rc.wireless script has been updated in the ssl_init function to modify how the initialization vector (IV) is generated and logged. Instead of using the product name from dmidecode, the IV is now formed by concatenating a fixed prefix ("12"), the MAC address retrieved from /sys/class/net/$PORT/address, and a fixed suffix ("34"). Additionally, the logging now captures the complete IV without truncation. In DockerClient.php, the scope of the $driver variable has been changed to global, allowing broader access within the file. A new variable $locale_init has been added in the nchan/wlan0 script to track language settings and update translations dynamically.

Changes

File Path Change Summary
etc/rc.d/rc.wireless Modified ssl_init: IV now constructed as "12" + MAC address (from /sys/…/net/$PORT/address) + "34"; full IV logging implemented
emhttp/plugins/dynamix.docker.manager/include/DockerClient.php Added global $driver variable and updated its scope in getAllInfo method; $driver now retrieved globally before $docker_cfgfile declaration
emhttp/plugins/dynamix/nchan/wlan0 Introduced $locale_init to track current language; updated translations dynamically using update_translation function

Sequence Diagram(s)

sequenceDiagram
    participant Script as rc.wireless
    participant Net as Wireless Interface
    participant Log as Logger

    Script->>Net: Retrieve MAC address from /sys/class/net/$PORT/address
    Net-->>Script: Return MAC address
    Script->>Script: Concatenate "12" + MAC address + "34" to form IV
    Script->>Log: Log the full IV without truncation
Loading

Poem

Oh, what fun in lines of code,
A rabbit hops on a new abode!
"12" at start, MAC in the middle,
"34" at the end - a neat fiddle.
Full IV logged with a cheerful smile,
Happy hops in code for a while!


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: 1

🧹 Nitpick comments (1)
etc/rc.d/rc.wireless (1)

50-50: Consider security implications of logging the full IV.

While logging the full IV can help with debugging, it may expose sensitive information used in encryption. Consider:

  1. Logging only when debugging is enabled
  2. Masking part of the IV in logs

Example implementation with debug-only logging:

-  echo "iv=$IV" >>$SSLINPUT
+  if [[ "${DEBUG:-0}" == "1" ]]; then
+    echo "iv=$IV" >>$SSLINPUT
+  else
+    echo "iv=$IV" | sed 's/\(.\{4\}\).*\(.\{4\}\)/\1****\2/' >>$SSLINPUT
+  fi
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11084b4 and b99db0e.

📒 Files selected for processing (1)
  • etc/rc.d/rc.wireless (1 hunks)

Comment thread etc/rc.d/rc.wireless
ssl_init(){
KEY="$(dmidecode -qt1 | grep -Pom1 'Manufacturer: \K.+' | sed 's/ /_/g')ABCDEFGH"
IV="$(dmidecode -qt1 | grep -Pom1 'Product Name: \K.+' | sed 's/ /_/g')1234567890123456"
IV="12$(cat $SYSTEM/$PORT/address | sed 's/://g')34"

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.

⚠️ Potential issue

Security concern: IV generation method may weaken encryption.

The current IV generation method using MAC address with fixed prefix/suffix ("12" and "34") has several security implications:

  1. MAC addresses are publicly visible and can be spoofed
  2. Fixed prefix/suffix reduces entropy
  3. Predictable IVs can weaken the encryption of sensitive data (USERNAME and PASSWORD)

Consider using a cryptographically secure random number generator instead:

-  IV="12$(cat $SYSTEM/$PORT/address | sed 's/://g')34"
+  IV="$(openssl rand -hex 16)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
IV="12$(cat $SYSTEM/$PORT/address | sed 's/://g')34"
IV="$(openssl rand -hex 16)"

@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 (2)
emhttp/plugins/dynamix.docker.manager/include/DockerClient.php (2)

38-39: Consider caching network driver information.

The network driver information is fetched every time the script runs. Consider caching this information to improve performance, especially since network configurations don't change frequently during runtime.

Example implementation:

-// get network drivers
-$driver = DockerUtil::driver();
+// get network drivers with caching
+$driver = DockerUtil::getCachedDriver();

// In DockerUtil class:
+private static $driverCache = null;
+
+public static function getCachedDriver() {
+    if (self::$driverCache === null) {
+        self::$driverCache = self::driver();
+    }
+    return self::$driverCache;
+}

Also applies to: 298-298


1148-1152: Add error handling for network driver retrieval.

The driver() method should include error handling for cases where Docker daemon is not responsive or network commands fail.

Example implementation:

 public static function driver() {
+    try {
         $list = [];
         foreach (static::docker("network ls --format='{{.Name}}={{.Driver}}'",true) as $network) {
             [$net,$driver] = array_pad(explode('=',$network),2,'');
             $list[$net] = $driver;
         }
         return $list;
+    } catch (Exception $e) {
+        error_log("Failed to retrieve network drivers: " . $e->getMessage());
+        return [];
+    }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b99db0e and 913d18b.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix.docker.manager/include/DockerClient.php (3 hunks)
🔇 Additional comments (2)
emhttp/plugins/dynamix.docker.manager/include/DockerClient.php (2)

38-39: LGTM! Network driver initialization looks good.

The addition of the global $driver variable with proper initialization using DockerUtil::driver() is well-placed and appropriately commented.


298-298: LGTM! Consistent global variable declaration.

The addition of $driver to the global declaration in getAllInfo method is consistent with its usage within the method for network mode checks.

@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/nchan/wlan0 (1)

52-55: Consider rate limiting locale checks for better performance.

While the locale change detection works correctly, checking for locale changes in every iteration of a 3-second loop might be unnecessary. Consider implementing a less frequent check or using an event-driven approach.

Here's a suggested implementation using a time-based check:

+$last_locale_check = 0;
+$locale_check_interval = 60; // Check every minute
 while (true) {
   extract(parse_plugin_cfg('dynamix',true));
-  if (_var($display,'locale') != $locale_init) {
+  $current_time = time();
+  if ($current_time - $last_locale_check >= $locale_check_interval) {
+    $last_locale_check = $current_time;
+    if (_var($display,'locale') != $locale_init) {
       $locale_init = _var($display,'locale');
       update_translation($locale_init);
+    }
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 913d18b and e2b793b.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/nchan/wlan0 (1 hunks)
🔇 Additional comments (1)
emhttp/plugins/dynamix/nchan/wlan0 (1)

25-26: LGTM! Clean implementation of locale tracking.

The initialization of $locale_init is well-placed and follows good practices.

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.

2 participants