Skip to content

Conversation

@zackspear
Copy link
Contributor

@zackspear zackspear commented Mar 20, 2025

This change enhances the plugin's capability to manage license keys effectively.

  • Introduced ReplaceKey.php from the webgui repo for handling auto-extended key check & installation
  • Updated dynamix.unraid.net.plg to include the new ReplaceKey.php in restore and preserve files.
  • Changed the check() method call in Registration.page to use the force parameter per https://app.asana.com/0/1204220153625175/1209573221367693/f
  • Moved the require_once for reboot-details.php in Downgrade.page and Update.page to ensure it's included after the ReplaceKey check.

Summary by CodeRabbit

  • New Features

    • Enhanced license key management now validates and updates credentials more reliably.
    • Essential configuration files are preserved throughout updates and uninstalls to maintain system integrity.
  • Chores

    • Optimized the update and registration workflows for a smoother, more stable user experience.
    • Adjusted internal processing steps to prepare for upcoming improvements in update checks.

- Introduced a new ReplaceKey.php file for handling key validation and installation.
- Updated dynamix.unraid.net.plg to include the new ReplaceKey.php in restore and preserve files.

This change enhances the plugin's capability to manage license keys effectively.
…pdate, Registration

- Changed the `check()` method call in Registration.page to use the `force` parameter.
- Moved the `require_once` for reboot-details.php in Downgrade.page and Update.page to ensure it's included after the ReplaceKey check.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request introduces a new PHP class, ReplaceKey, that manages license key validation and updates. The changes update several plugin files to include and invoke this new class. Updates include adding file paths for restoration and preservation, modifying method invocations to pass a boolean argument, and reordering require statements related to reboot details. Additionally, the flow in the unraid check script now instantiates and calls the new ReplaceKey functionality before proceeding with update checks.

Changes

File(s) Change Summary
plugin/plugins/dynamix.unraid.net.plg Added /usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php to the FILES_TO_RESTORE array and a corresponding preserve entry in preserveFilesDirs.
plugin/source/dynamix.unraid.net/.../Registration.page Changed $replaceKey->check() to $replaceKey->check(true) to pass a boolean flag during the check.
plugin/source/dynamix.unraid.net/.../Downgrade.page
plugin/source/dynamix.unraid.net/.../Update.page
Reordered the require_once statement for reboot-details.php to occur after instantiating the ReplaceKey (and before creating or calling RebootDetails).
plugin/source/dynamix.unraid.net/.../scripts/unraidcheck Inserted code to include ReplaceKey.php, instantiated a new ReplaceKey, and invoked its check() method prior to the inclusion of UnraidCheck.php.
plugin/source/dynamix.unraid.net/.../include/ReplaceKey.php Introduced a new ReplaceKey class that handles key file loading, validation, HTTP requests, key retrieval, and installation processes.
web/composables/services/webgui.ts Updated the URL comment in the WebguiCheckForUpdate function with a note to replace the URL with /scripts/unraidcheck in the future.

Sequence Diagram(s)

sequenceDiagram
    participant S as Unraid Check Script
    participant RK as ReplaceKey
    participant UO as UnraidOsCheck
    S->>RK: Instantiate ReplaceKey
    S->>RK: call check() (or check(true) in Registration)
    RK-->>S: Return key validation/installation result
    S->>UO: Include UnraidCheck.php and instantiate UnraidOsCheck
    UO-->>S: Proceed with update check
Loading

Possibly related PRs

Suggested reviewers

  • pujitm

Poem

In the code where keys align,
A new class sings in rhythmic time,
ReplaceKey leads a clever dance,
Updating flows with nimble glance,
With files restored and steps renewed,
Our plugin's future is finely construed!


🪧 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 removed the request for review from mdatelle March 20, 2025 21:13
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

🧹 Nitpick comments (6)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck (1)

17-21: Consider error handling after calling $replaceKey->check().

Currently, any internal error from $replaceKey->check() is silently ignored. To improve resilience, you could log or handle possible failures (e.g., JSON error files) so that the update check can display or act upon license-related issues.

 require_once "$docroot/plugins/dynamix/include/ReplaceKey.php";
 $replaceKey = new ReplaceKey();
-$replaceKey->check();
+$checkResult = $replaceKey->check();
+if ($checkResult === false) {
+  // For instance, log or notify about ReplaceKey check failure
+  // This helps surface errors from ReplaceKey
+}

 require_once "$docroot/plugins/dynamix.plugin.manager/include/UnraidCheck.php";
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php (5)

1-3: Check for invalid docroot paths.

The $docroot fallback is correct, but consider verifying that $docroot points to a valid location to avoid file-inclusion issues in future expansions.


4-28: Validate constructor inputs.

The constructor sets crucial properties (guid, keyfile, etc.) silently using @. Consider validating the file read/parse_ini_file results for better error reporting and reliability.


72-109: Handle empty or malformed JSON gracefully.

When json_decode($response, true) fails, an empty array is returned. You might log a warning or store a diagnostic message if validation fails unexpectedly.


141-185: Mind potential concurrency in installNewKey().

Installation modifies system state and writes to /tmp/ReplaceKey/error.json. If multiple key replacements are triggered, concurrency might cause partial writes or race conditions. Consider adding locking or checks for concurrent calls.


187-195: Check file_put_contents return value.

file_put_contents can fail and return false. If the filesystem is read-only or space is full, the error JSON won’t be written. Handling that return gracefully can help in diagnosing deeper issues.

📜 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 8d56d12 and 2c62d07.

📒 Files selected for processing (7)
  • plugin/plugins/dynamix.unraid.net.plg (2 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page (1 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/Downgrade.page (1 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/Update.page (1 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck (1 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php (1 hunks)
  • web/composables/services/webgui.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (10)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/Downgrade.page (2)

19-22: Integration of ReplaceKey functionality

The code correctly adds the ReplaceKey class instantiation and check method call. This implements the license key validation functionality before proceeding with downgrade operations.


23-23: Moved reboot-details.php inclusion

The require_once statement for reboot-details.php has been appropriately repositioned to execute after the ReplaceKey check. This ensures proper sequencing where license key validation occurs before reboot details are processed.

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page (1)

19-19: Added force parameter to check method

The change adds a boolean parameter (true) to the ReplaceKey->check() method call, which implements the force check functionality mentioned in the PR objectives. This ensures the key validation is performed regardless of any cached state.

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/Update.page (2)

16-18: Integration of ReplaceKey functionality

The code correctly adds the ReplaceKey class instantiation and check method call, implementing license key validation before proceeding with update operations.


20-21: Moved reboot-details.php inclusion and RebootDetails instantiation

The require_once statement for reboot-details.php and the RebootDetails instantiation have been properly repositioned to execute after the ReplaceKey check. This ensures the correct sequence of operations where license key validation occurs before reboot details are processed.

web/composables/services/webgui.ts (1)

111-111: TODO comment for future URL update

A TODO comment has been added indicating that the URL should be replaced with '/scripts/unraidcheck' in the future. This is a good documentation practice that flags the need for a future code change without affecting current functionality.

plugin/plugins/dynamix.unraid.net.plg (2)

387-387: File restoration addition looks good.

Adding ReplaceKey.php to FILES_TO_RESTORE ensures the file is correctly restored after updates or uninstalls. No immediate concerns.


509-509: Correct approach to prevent file downgrade.

Including ReplaceKey.php in preserveFilesDirs with preventDowngrade prevents older plugin packages from overwriting the new file, maintaining version integrity.

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php (2)

30-70: Store or handle cURL errors.

A @todo exists to store cURL errors, but it's not implemented. Logging these errors could be essential for debugging misconfigurations or network failures.

Would you like a shell script to confirm that no other references handle the cURL errors, ensuring we don’t miss potential error-handling implementations?


111-139: Confirm license format in getLatestKey().

Currently, any non-empty 'license' field is assumed valid. Consider minimal checks to ensure that the returned string is indeed a valid key or a well-formed license file content.

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1264/dynamix.unraid.net.plg

@zackspear zackspear merged commit 4aadcef into main Mar 20, 2025
8 checks passed
@zackspear zackspear deleted the feat/integrate-replace-key-php branch March 20, 2025 21:29
elibosley pushed a commit that referenced this pull request Mar 25, 2025
🤖 I have created a release *beep* *boop*
---


## [4.4.0](v4.3.1...v4.4.0)
(2025-03-25)


### Features

* add ReplaceKey functionality to plugin
([#1264](#1264))
([4aadcef](4aadcef))
* downgrade page replace key check
([#1263](#1263))
([8d56d12](8d56d12))
* make log viewer component dynamic
([#1242](#1242))
([e6ec110](e6ec110))
* ReplaceKey functionality in Registration and Update pages
([#1246](#1246))
([04307c9](04307c9))
* UnraidCheckExec for Check OS Updates via UPC dropdown
([#1265](#1265))
([5935a3b](5935a3b))


### Bug Fixes

* **deps:** update all non-major dependencies
([#1236](#1236))
([7194f85](7194f85))
* **deps:** update all non-major dependencies
([#1247](#1247))
([20b0aeb](20b0aeb))
* **deps:** update all non-major dependencies
([#1251](#1251))
([33a1a1d](33a1a1d))
* **deps:** update all non-major dependencies
([#1253](#1253))
([53fec0e](53fec0e))
* **deps:** update dependency @nestjs/passport to v11
([#1244](#1244))
([edc93a9](edc93a9))
* **deps:** update dependency graphql-subscriptions to v3
([#1209](#1209))
([c14c85f](c14c85f))
* **deps:** update dependency ini to v5
([#1217](#1217))
([f27660f](f27660f))
* **deps:** update dependency jose to v6
([#1248](#1248))
([42e3d59](42e3d59))
* **deps:** update dependency marked to v15
([#1249](#1249))
([2b6693f](2b6693f))
* **deps:** update dependency pino-pretty to v13
([#1250](#1250))
([85fb910](85fb910))
* **deps:** update dependency pm2 to v6
([#1258](#1258))
([04ad2bc](04ad2bc))
* **deps:** update dependency shadcn-vue to v1
([#1259](#1259))
([1a4fe8f](1a4fe8f))
* **deps:** update dependency vue-i18n to v11
([#1261](#1261))
([0063286](0063286))
* **deps:** update vueuse monorepo to v13 (major)
([#1262](#1262))
([94caae3](94caae3))
* make scripts executable when building the plugin
([#1255](#1255))
([e237f38](e237f38))
* node installation not persisting across reboots
([#1256](#1256))
([0415cf1](0415cf1))
* update configValid state to ineligible in var.ini and adjust rel…
([#1268](#1268))
([ef8c954](ef8c954))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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