mirror of
https://github.com/unraid/api.git
synced 2026-01-06 08:39:54 -06:00
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:
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user