fix: OEM plugin issues (#1288)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- The file synchronization tool now requires an explicitly defined
destination and offers a new option to remove remote password files
before syncing. Additionally, synchronization now omits ownership,
group, and permission metadata for smoother transfers.
- The activation flow has been refined, with legacy authentication
modifications removed to deliver a cleaner welcome modal experience.
- A new variable has been introduced to enhance server state management.

- **Refactor**
- Internal configuration adjustments have been made to enhance component
delivery and streamline system actions.

- **Bug Fixes**
- Updated handling of remote user and host parameters in the
synchronization script for improved functionality.
- Simplified the activation code removal process by focusing solely on
the `.set-password.php` file restoration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Zack Spear <hi@zackspear.com>
This commit is contained in:
Eli Bosley
2025-03-28 16:39:15 -04:00
committed by GitHub
parent 2266139742
commit d5a3d0dfac
5 changed files with 43 additions and 74 deletions

View File

@@ -2,8 +2,6 @@ import { existsSync } from 'fs';
import { readFile } from 'fs/promises';
import { join } from 'node:path';
import { createPatch } from 'diff';
import {
FileModification,
ShouldApplyWithReason,
@@ -12,7 +10,7 @@ import {
export default class AuthRequestModification extends FileModification {
public filePath: string = '/usr/local/emhttp/auth-request.php' as const;
public webComponentsDirectory: string =
'/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/_nuxt/' as const;
'/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/' as const;
id: string = 'auth-request';
/**

View File

@@ -2,24 +2,14 @@
# Bash script to sync local activation code directory to the correct location on the Unraid server's boot device
# Usage: ./sync_files.sh --local-directory <local_directory> [--remote-user <remote_user>] [--remote-host <remote_host>] [--remote-path <remote_path>]
# Usage: ./sync_files.sh --local-directory <local_directory> --remote-host <remote_host> [--remote-path <remote_path>] [--remove-password]
# Example usage 0
# ./plugin/scripts/rsync-activation-dir.sh --local-directory /Users/zack/Downloads/activation_code_pdfs_12_19_2024_1436
# Path to store the last used remote host
state_file="$HOME/.deploy_state"
# Read the last used remote host from the state file
if [[ -f "$state_file" ]]; then
LAST_REMOTE_HOST=$(cat "$state_file")
else
LAST_REMOTE_HOST=""
fi
# Example usage:
# ./plugin/scripts/rsync-activation-dir.sh --local-directory /Users/zack/Downloads/activation_code_pdfs_12_19_2024_1436 --remote-host unraid.local --remove-password
# Default values
REMOTE_USER="root"
REMOTE_PATH="/boot/config/activation"
REMOVE_PASSWORD=false
# Parse named flag parameters
while [[ $# -gt 0 ]]; do
@@ -28,10 +18,6 @@ while [[ $# -gt 0 ]]; do
LOCAL_DIRECTORY="$2"
shift 2
;;
--remote-user)
REMOTE_USER="$2"
shift 2
;;
--remote-host)
REMOTE_HOST="$2"
shift 2
@@ -40,32 +26,29 @@ while [[ $# -gt 0 ]]; do
REMOTE_PATH="$2"
shift 2
;;
--remove-password)
REMOVE_PASSWORD=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 --local-directory <local_directory> [--remote-user <remote_user>] [--remote-host <remote_host>] [--remote-path <remote_path>]"
echo "Usage: $0 --local-directory <local_directory> --remote-host <remote_host> [--remote-path <remote_path>] [--remove-password]"
exit 1
;;
esac
done
# Validate required parameter
# Validate required parameters
if [[ -z "$LOCAL_DIRECTORY" ]]; then
echo "Error: --local-directory is required."
exit 1
fi
# Use last remote host if none is provided
REMOTE_HOST=${REMOTE_HOST:-$LAST_REMOTE_HOST}
# Check if remote host is provided
if [[ -z "$REMOTE_HOST" ]]; then
echo "Please provide the remote host using --remote-host."
echo "Error: --remote-host is required."
exit 1
fi
# Save the current remote host to the state file
echo "$REMOTE_HOST" > "$state_file"
# Check if local directory ends with a slash
if [[ "$LOCAL_DIRECTORY" != */ ]]; then
echo "The local directory does not end with a slash."
@@ -75,8 +58,31 @@ if [[ "$LOCAL_DIRECTORY" != */ ]]; then
fi
fi
# First, remove any existing password files on the remote server
ssh "root@$REMOTE_HOST" "rm -rf $REMOTE_PATH/*" || {
echo "Error: Failed to clean remote directory"
exit 1
}
# Remove Unraid password file if requested
if [[ "$REMOVE_PASSWORD" == true ]]; then
read -p "Do you want to remove any existing Unraid license keys on the server? (y/n): " REMOVE_KEYS
if [[ "$REMOVE_KEYS" =~ ^[Yy]$ ]]; then
ssh "root@$REMOTE_HOST" "rm -f /boot/config/*.key" || {
echo "Error: Failed to remove Unraid license keys"
exit 1
}
echo "Removed Unraid license keys"
fi
ssh "root@$REMOTE_HOST" "rm -f /boot/config/passwd /boot/config/shadow /boot/config/super.dat" || {
echo "Error: Failed to remove Unraid password file"
exit 1
}
echo "Removed Unraid password file"
fi
# Execute the rsync command and capture its output
RSYNC_OUTPUT=$(rsync -av -e ssh "$LOCAL_DIRECTORY" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH" 2>&1)
RSYNC_OUTPUT=$(rsync -av --no-owner --no-group --no-perms -e ssh "$LOCAL_DIRECTORY" "root@$REMOTE_HOST:$REMOTE_PATH" 2>&1)
RSYNC_EXIT_CODE=$?
# Output the rsync command's output

View File

@@ -1,5 +1,6 @@
<?php
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
$var = (array)parse_ini_file('state/var.ini'); // required for state.php - don't remove unless you've refactored the code to work without it
require_once "$docroot/plugins/dynamix.my.servers/include/state.php";
$serverState = new ServerState();

View File

@@ -70,18 +70,13 @@ debug_echo "Checking for setup flag at $ACTIVATION_SETUP_FLAG"
if [[ -f "$ACTIVATION_SETUP_FLAG" ]]; then
debug_echo "Setup flag found, proceeding with removal"
# Restore the original auth-request and .set-password files modified for the welcome modal
AUTH_REQUEST_FILE="/usr/local/emhttp/auth-request.php"
AUTH_REQUEST_BK_FILE="$AUTH_REQUEST_FILE.bak"
rm -f "$AUTH_REQUEST_FILE"
mv -f "$AUTH_REQUEST_BK_FILE" "$AUTH_REQUEST_FILE"
# Restore the original .set-password files modified for the welcome modal
WELCOME_MODAL_INJECT_FILE="/usr/local/emhttp/plugins/dynamix/include/.set-password.php"
WELCOME_MODAL_INJECT_BK_FILE="$WELCOME_MODAL_INJECT_FILE.bak"
rm -f "$WELCOME_MODAL_INJECT_FILE"
mv -f "$WELCOME_MODAL_INJECT_BK_FILE" "$WELCOME_MODAL_INJECT_FILE"
debug_echo "Restored auth-request and .set-password files"
debug_echo "Restored .set-password file"
# Remove the partner logo symbolic link if it exists
WEBGUI_IMAGES_DIR="/usr/local/emhttp/webGui/images"

View File

@@ -98,41 +98,8 @@ if [[ -d "$ACTIVATION_DIR" ]]; then
# create the setup flag file to prevent re-running this setup
touch "$ACTIVATION_SETUP_FLAG"
#
# Inject welcome modal into .set-password.php
#
# We first need to add files to allow them to be requested without authentication
AUTH_REQUEST_FILE="/usr/local/emhttp/auth-request.php"
WEB_COMPS_DIR="/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/_nuxt/"
mapfile -t JS_FILES < <(find "$WEB_COMPS_DIR" -type f -name "*.js" | sed 's|/usr/local/emhttp||') # modifying the path to be relative to the webgui's webroot
debug_echo "Found ${#JS_FILES[@]} .js files in $WEB_COMPS_DIR"
FILES_TO_ADD=(
"/webGui/images/partner-logo.svg"
)
FILES_TO_ADD+=("${JS_FILES[@]}")
if grep -q "\$arrWhitelist" "$AUTH_REQUEST_FILE"; then
cp "$AUTH_REQUEST_FILE" "${AUTH_REQUEST_FILE}.bak"
debug_echo "Backup of $AUTH_REQUEST_FILE created at ${AUTH_REQUEST_FILE}.bak"
# prepending items to the array as appending them to the end of the array was causing issues with trying to detect the last item with or without a comma
awk -v files_to_add="$(printf "%s\n" "${FILES_TO_ADD[@]}" | awk '{printf " \x27%s\x27,\n", $0}')" '
BEGIN { added = 0 }
/\$arrWhitelist\s*=\s*\[/ {
print $0
print files_to_add
added = 1
next
}
{ print }
' "$AUTH_REQUEST_FILE" > "${AUTH_REQUEST_FILE}.tmp"
mv "${AUTH_REQUEST_FILE}.tmp" "$AUTH_REQUEST_FILE"
debug_echo "Default values and .js files from $WEB_COMPS_DIR added to \$arrWhitelist."
else
debug_echo "\$arrWhitelist array not found in the file."
fi
# Auth Request Modification move into the Unraid API
# @todo - Move the remaining modifications into the Unraid API
# Inject the welcome modal into the .set-password.php file
WELCOME_MODAL_INJECT_FILE="/usr/local/emhttp/plugins/dynamix/include/.set-password.php"
# shellcheck disable=SC2016
@@ -298,6 +265,8 @@ if [[ -d "$ACTIVATION_DIR" ]]; then
PARTNER_CASE_ICON=$(jq -r '.caseIcon // empty' "$ACTIVATION_JSON" 2>/dev/null || true); # for included with system icon
debug_echo "Partner case model icon: $PARTNER_CASE_MODEL"
if [[ -f "$PARTNER_CASE_MODEL" ]]; then
# First remove any existing symlink or file
rm -f "$WEBGUI_IMAGES_DIR/$CUSTOM_CASE_FILE_NAME"
cp -f "$PARTNER_CASE_MODEL" "$WEBGUI_IMAGES_DIR/$CUSTOM_CASE_FILE_NAME"
if [[ $? -ne 0 ]]; then
echo "⚠️ Warning: Failed to replace the original case model icon with the custom icon."