Skip to content

feat: replace key improvements#2077

Merged
limetech merged 6 commits into
unraid:masterfrom
zackspear:feat/replace-key-improvements
Mar 21, 2025
Merged

feat: replace key improvements#2077
limetech merged 6 commits into
unraid:masterfrom
zackspear:feat/replace-key-improvements

Conversation

@zackspear

@zackspear zackspear commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

Reflects recent changes to the same files in the api repo

  • feat: ReplaceKey 7 day window around regExp & new forceCheck param
  • feat: ReplaceKey notification for installing auto-extended license key
  • feat: adds ReplaceKey check to /Tools/Downgrade, /Tools/Update, & /Tools/Registration as they're directly related to a license key's OS Update eligibility date.
  • fix: KeyInstaller class success responses

Summary by CodeRabbit

  • New Features
    • Enhanced key management functionality has been integrated into registration, update, and downgrade workflows, ensuring proactive checks and smoother transitions.
    • Key installation responses now deliver clear status messages and improved error notifications, offering users more reliable feedback.
    • A new class for executing update checks has been introduced, further refining the update process.
    • Optimized overall flow ensures smoother system operations and a more robust user experience.

zackspear and others added 5 commits March 18, 2025 15:51
* feat: ReplaceKey 7 day window around regExp & new forceCheck param

* feat: Enhance writeJsonFile to support appending data
…n ReplaceKey

* Removed appending functionality from writeJsonFile for cleaner implementation.
* Inverted condition for forceCheck to improve logic clarity.
…tions

* Added logic to process the response from KeyInstaller's installKey method.
* Implemented error handling and notification system based on installation success or failure.
* Notifications include event, subject, and description for better user feedback.
* Added `ReplaceKey` initialization and check to `Registration.page`, `Downgrade.page`, `Update.page`, and `unraidcheck` script.
* Ensures consistent handling of key replacement across relevant components.
@zackspear zackspear requested a review from elibosley March 20, 2025 22:02
@coderabbitai

coderabbitai Bot commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new dependency on the ReplaceKey functionality across multiple Unraid plugin pages and scripts. In each instance, a ReplaceKey object is instantiated, and its check() method is called (with an optional forced parameter). Additionally, some existing methods in key installation and response handling have been updated with explicit return types and improved formatting. The control flow now integrates key replacement validation into registration, downgrade, update, and unraid check processes. A new class, UnraidCheckExec, is also introduced to manage update checks separately.

Changes

File(s) Change Summary
emhttp/plugins/dynamix.my.servers/Registration.page Instantiates ReplaceKey and calls check(true); adjusts tag formatting.
emhttp/plugins/dynamix.plugin.manager/{Downgrade.page, Update.page} Adds inclusion and instantiation of ReplaceKey with a check() call prior to existing reboot details logic; removes some comments in Downgrade.
emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck Introduces ReplaceKey dependency and performs a check before executing the existing update check via UnraidOsCheck.
emhttp/plugins/dynamix/include/{InstallKey.php, ReplaceKey.php} In InstallKey.php: Updates method signatures of responseComplete and installKey to include return types and adjusts response formatting. In ReplaceKey.php: Modifies installNewKey to capture and process the installation response, and updates check to accept a boolean parameter and improve error handling.
emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php Introduces a new class UnraidCheckExec with methods for executing the unraid check script and setting up the environment.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Page as "Plugin Page (Registration/Update/Downgrade/UnraidCheck)"
    participant ReplaceKey
    participant KeyInstaller

    User->>Page: Request page load
    Page->>ReplaceKey: Instantiate & invoke check(force?)
    ReplaceKey->>KeyInstaller: Optionally trigger key installation
    KeyInstaller-->>ReplaceKey: Return installation response
    ReplaceKey-->>Page: Return key check result
    Page->>User: Continue with subsequent logic
Loading

Poem

I'm a rabbit hopped on new keys today,
With checks and updates, I leap all the way.
Code now sings of logic crisp and clear,
In every file, improvements appear.
My digital burrow's now finely tuned,
🥕 Hopping happily, my path is hewn!
Cheers to new lines—a rabbit’s joyful tune!


🪧 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 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.

@zackspear zackspear requested a review from ljm42 March 20, 2025 22:02
* Added `UnraidCheckExec` class to handle execution of the unraidcheck script and return JSON responses.
* Updated the unraidcheck script to parse query parameters for better integration with web components.
* This change maintains separation of concerns between UnraidCheck and ReplaceKey functionalities.

@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.plugin.manager/include/UnraidCheckExec.php (1)

31-37: Consider adding error handling for script execution.

The execute method correctly calls setupEnvironment() and runs the script, but it lacks error handling for potential script execution failures. Consider checking the return value of exec() and handling cases where the script might not execute successfully.

public function execute(): string
{
    $this->setupEnvironment();
    $output = [];
-   exec(self::SCRIPT_PATH, $output);
+   $return_var = 0;
+   exec(self::SCRIPT_PATH, $output, $return_var);
+   if ($return_var !== 0) {
+       // Log error or handle failure
+       $output[] = json_encode(['error' => 'Failed to execute unraidcheck script']);
+   }
    return implode("\n", $output);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between f6aa74c and 116732f.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (1 hunks)
  • emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck
🔇 Additional comments (4)
emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (4)

1-11: Well-documented class purpose and integration context.

The docblock clearly explains the purpose of this file for maintaining separation of concerns between UnraidCheck and ReplaceKey, which aligns with the PR objectives. It provides valuable context about how this file integrates with other components through the WebguiCheckForUpdate function.


12-14: Good encapsulation of the script path constant.

The SCRIPT_PATH constant is properly defined as private since it's an implementation detail of the class.


40-42: Simple and effective implementation of the class.

The instantiation and execution of the UnraidCheckExec class is straightforward and follows good practices.


16-29:

Details

❓ Verification inconclusive

Verify the security implications of the altUrl parameter.

The method correctly sets the Content-Type header and handles the altUrl parameter by validating it as a URL. However, consider implementing additional validation beyond FILTER_VALIDATE_URL to mitigate potential security risks if the unraidcheck script uses this URL in sensitive operations.


🏁 Script executed:

#!/bin/bash
# Check how the unraidcheck script uses the altUrl parameter
cat "/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck" | grep -A 10 "altUrl"

Length of output: 195


Action Required: Verify altUrl Usage Manually

The altUrl parameter is validated with FILTER_VALIDATE_URL and then passed via the environment variable QUERY_STRING. However, our verification attempt to locate the associated unraidcheck script at /usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck did not find any such file. This makes it unclear how—and if—the URL is used in sensitive operations.

  • The unraidcheck script is missing at the expected location.
  • Without seeing its usage of altUrl, we cannot confirm whether additional validation or sanitization is needed.

Please manually verify how the altUrl parameter is handled in the broader unraidcheck workflow. If the script exists in a different location or if its usage is confirmed to be secure, update this section accordingly.

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