Files
api/plugin/plugins/dynamix.unraid.net.plg
T
Eli Bosley 83107a743c feat: implement CSS class prefixing and exclusion logic for improved style management
- Introduced a new Vite plugin to prefix CSS classes, ensuring that styles from the webgui do not interfere with our components.
- Enhanced the CSS patching script to apply exclusion selectors, preventing style leakage from `.unapi` containers.
- Updated the Nuxt configuration to integrate the new postcssPrefixPlugin, allowing for better control over CSS class names.
- Modified the Vue app mounting logic to add the `.unapi` class for improved style isolation and backward compatibility with `.unraid-reset`.
2025-08-31 12:37:53 -04:00

613 lines
23 KiB
XML
Executable File

<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "dynamix.unraid.net">
<!ENTITY launch "Connect">
<!ENTITY author "limetech">
<!ENTITY version "">
<!ENTITY plugin_url "">
<!ENTITY source "/boot/config/plugins/dynamix.my.servers/&txz_name;">
<!ENTITY txz_sha256 "">
<!ENTITY txz_url "">
<!ENTITY txz_name "">
<!ENTITY arch "x86_64">
<!ENTITY build "1">
<!ENTITY tag "">
<!ENTITY api_version "">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="&plugin_url;"
launch="&launch;" min="6.9.0-rc1" icon="globe">
<CHANGES>
##a long time ago in a galaxy far far away
- initial release
</CHANGES>
<!-- Check disk space before installation -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
<![CDATA[
# Check available disk space on /usr
echo -n "Checking disk space on /usr... "
FREE_SPACE=$(df -m /usr | awk 'NR==2 {print $4}')
if [ -z "$FREE_SPACE" ]; then
echo "⚠️ Error: Unable to determine free space on /usr"
exit 1
fi
if [ "$FREE_SPACE" -lt 300 ]; then
echo "⚠️ Error: Insufficient disk space on /usr. Need at least 300MB free, only ${FREE_SPACE}MB available"
exit 1
fi
echo "ok. (${FREE_SPACE}MB free)"
exit 0
]]>
</INLINE>
</FILE>
<!-- download main txz -->
<FILE Name="&source;">
<URL>&txz_url;</URL>
<SHA256>&txz_sha256;</SHA256>
</FILE>
<!-- Check for compatible Unraid version -->
<FILE Run="/usr/bin/php" Method="install">
<INLINE>
<![CDATA[
<?php
// Check Unraid version
$version = @parse_ini_file('/etc/unraid-version', true)['version'];
// Check if this is a supported version
// - Must be 6.12.0 or higher
// - Must not be a 6.12.0 beta/rc version
$is_stable_6_12_or_higher = version_compare($version, '6.12.0', '>=') && !preg_match('/^6\\.12\\.0-/', $version);
if ($is_stable_6_12_or_higher) {
echo "Running on supported version {$version}\n";
exit(0);
}
echo "Warning: Unsupported Unraid version {$version}. This plugin requires Unraid 6.12.0 or higher.\n";
echo "The plugin may not function correctly on this system.\n";
exit(0);
]]>
</INLINE>
</FILE>
<!-- Backup files before installation -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
<![CDATA[
echo "Backing up original files..."
# Define files to backup in a shell variable
FILES_TO_BACKUP=(
"/usr/local/emhttp/plugins/dynamix/DisplaySettings.page"
"/usr/local/emhttp/plugins/dynamix/Registration.page"
"/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php"
"/usr/local/emhttp/plugins/dynamix/include/ProvisionCert.php"
"/usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php"
"/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php"
"/usr/local/emhttp/plugins/dynamix/include/Wrappers.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/Downgrade.page"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/Update.page"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/ShowChanges.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/showchanges"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/MyServers.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers2.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/data/server-state.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/reboot-details.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/translations.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php"
"/usr/local/emhttp/update.htm"
"/usr/local/emhttp/logging.htm"
"/etc/nginx/nginx.conf"
"/etc/rc.d/rc.nginx"
"/usr/share/mozilla/firefox/9n35r0i1.default/user.js"
)
# Backup each file if it exists and doesn't already have a backup
for FILE in "${FILES_TO_BACKUP[@]}"; do
if [ -f "$FILE" ] && [ ! -f "$FILE-" ]; then
cp -p "$FILE" "$FILE-"
echo "Backed up: $FILE"
fi
done
# Handle the unraid-components directory
DIR=/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components
if [ -d "$DIR" ] && [ ! -d "$DIR-" ]; then
mv "$DIR" "$DIR-"
echo "Moved directory: $DIR to $DIR-"
fi
echo "Backup complete."
exit 0
]]>
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="install">
<INLINE>
<![CDATA[
echo "Patching header logo if necessary..."
# We do this here instead of via API FileModification to avoid undesirable
# rollback when the API is stopped.
#
# This is necessary on < 7.2 because the unraid-header-os-version web component
# that ships with the base OS only displayes the version, not the logo as well.
#
# Rolling back in this case (i.e when stopping the API) yields a duplicate logo
# that blocks interaction with the navigation menu.
# Remove the old header logo from DefaultPageLayout.php if present
if [ -f "/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php" ]; then
sed -i 's|<a href="https://unraid.net" target="_blank"><?readfile("$docroot/webGui/images/UN-logotype-gradient.svg")?></a>||g' "/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php"
# Add unraid-modals element if not already present
if ! grep -q '<unraid-modals>' "/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php"; then
sed -i 's|<body>|<body>\n<unraid-modals></unraid-modals>|' "/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php"
fi
fi
]]>
</INLINE>
</FILE>
<FILE Run="/usr/bin/php" Method="install">
<INLINE>
<![CDATA[
<?php
echo "Patching webgui CSS files for compatibility...\n";
$cssDir = "/usr/local/emhttp/plugins/dynamix/styles";
$backupDir = "$cssDir/.unraid-api-backup";
if (!is_dir($cssDir)) {
echo "Warning: CSS directory not found at $cssDir\n";
exit(0);
}
// First restore any existing backups to ensure clean state
if (is_dir($backupDir)) {
echo "Restoring original CSS files from backup...\n";
foreach (glob("$backupDir/*.css") as $backupFile) {
$filename = basename($backupFile);
$originalFile = "$cssDir/$filename";
echo " Restoring $filename...\n";
copy($backupFile, $originalFile);
}
}
// Create backup directory if it doesn't exist
if (!is_dir($backupDir)) {
mkdir($backupDir, 0755, true);
}
// Define selectors to exclude from webgui styles
// Simply exclude anything inside .unapi containers
$exclusionSelectors = [
'.unapi',
'.unraid-reset' // Keep for backwards compatibility
];
// Function to patch CSS rules to exclude our components
function patchCssContent($content, $exclusionSelectors) {
// Split CSS into rules while preserving structure
$lines = explode("\n", $content);
$inRule = false;
$currentRule = [];
$output = [];
$braceDepth = 0;
foreach ($lines as $line) {
// Count braces to track rule boundaries
$openBraces = substr_count($line, '{');
$closeBraces = substr_count($line, '}');
// Check if this line starts a new rule
if (!$inRule && strpos($line, '{') !== false && !preg_match('/^\s*@/', $line)) {
$inRule = true;
$currentRule = [$line];
$braceDepth = $openBraces - $closeBraces;
} elseif ($inRule) {
$currentRule[] = $line;
$braceDepth += $openBraces - $closeBraces;
// Check if rule is complete
if ($braceDepth <= 0) {
// Process the complete rule
$ruleText = implode("\n", $currentRule);
// Extract selector (everything before first {)
if (preg_match('/^([^{]+)\{/', $ruleText, $matches)) {
$selector = trim($matches[1]);
// Skip if this is an @-rule or already has :not()
if (strpos($selector, '@') === 0 || strpos($selector, ':not(') !== false) {
$output[] = $ruleText;
} else {
// Add exclusions to problematic selectors
$needsPatch = false;
// Check if this selector could affect our components
// Target generic selectors, element selectors, and broad class selectors
if (preg_match('/^(\*|body|html|div|button|input|a|span|p|h[1-6]|ul|li|form|label|select|textarea)(\s|,|$|\.|#|\[)/', $selector) ||
strpos($selector, '*') !== false ||
preg_match('/^\.[a-z]/', $selector)) {
$needsPatch = true;
}
if ($needsPatch) {
// Parse individual selectors
$selectors = array_map('trim', explode(',', $selector));
$patchedSelectors = [];
foreach ($selectors as $sel) {
// Add :not(.unapi) for element selectors
// Or prepend :not(.unapi) * for other selectors
if (preg_match('/^[a-z]+/i', $sel) && strpos($sel, '.') === false && strpos($sel, '#') === false) {
// Pure element selector (button, input, etc)
// Exclude elements that have .unapi class or are inside .unapi
$patchedSel = $sel . ':not(.unapi):not(.unapi ' . $sel . ')';
} else {
// Class or ID selector - ensure it doesn't apply within .unapi
$patchedSel = ':not(.unapi) ' . $sel . ':not(.unapi)';
}
$patchedSelectors[] = $patchedSel;
}
// Rebuild the rule with patched selectors
$newSelector = implode(', ', $patchedSelectors);
$ruleText = preg_replace('/^[^{]+\{/', $newSelector . ' {', $ruleText);
}
}
}
$output[] = $ruleText;
$inRule = false;
$currentRule = [];
$braceDepth = 0;
}
} else {
// Not in a rule, just pass through
$output[] = $line;
}
}
// Add any remaining lines
if (!empty($currentRule)) {
$output = array_merge($output, $currentRule);
}
return implode("\n", $output);
}
// Process only default-* and dynamix-* CSS files
foreach (glob("$cssDir/*.css") as $cssFile) {
$filename = basename($cssFile);
// Only process default-* and dynamix-* files
if (!preg_match('/^(default-|dynamix-).*\.css$/', $filename)) {
continue;
}
$backupFile = "$backupDir/$filename";
// Read file content
$content = file_get_contents($cssFile);
// Skip if already patched
if (strpos($content, "/* Unraid API compatibility patch - exclusion based */") !== false) {
echo " $filename already patched, skipping...\n";
continue;
}
// Create backup if it doesn't exist
if (!file_exists($backupFile)) {
copy($cssFile, $backupFile);
}
echo " Patching $filename...\n";
// Add compatibility patch comment and apply exclusion patches
$patchedContent = "/* Unraid API compatibility patch - exclusion based */\n";
$patchedContent .= patchCssContent($content, $exclusionSelectors);
// Write modified content back
file_put_contents($cssFile, $patchedContent);
}
echo "CSS patching complete.\n";
?>
]]>
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
MAINNAME="&name;"
<![CDATA[
echo "Removing Plugin"
# Check Unraid version
UNRAID_VERSION=""
is_7_2_or_higher=false
# Check if version file exists and is readable
if [ -f "/etc/unraid-version" ] && [ -r "/etc/unraid-version" ]; then
UNRAID_VERSION=$(cat /etc/unraid-version | grep "^version=" | cut -d'"' -f2 2>/dev/null)
if [ -z "$UNRAID_VERSION" ]; then
echo "Warning: Unable to parse version from /etc/unraid-version"
echo "Using safe removal method (plugin file removal + reboot)"
is_7_2_or_higher=true # Default to safe method
else
# Check if this is Unraid 7.2 or higher (including RCs and prereleases)
if [[ "$UNRAID_VERSION" =~ ^7\.([2-9]|[1-9][0-9]+)\. ]] || [[ "$UNRAID_VERSION" =~ ^([8-9]|[1-9][0-9]+)\. ]]; then
is_7_2_or_higher=true
fi
fi
else
echo "Warning: /etc/unraid-version file not found or not readable"
echo "Using safe removal method (plugin file removal + reboot)"
is_7_2_or_higher=true # Default to safe method
fi
if [ "$is_7_2_or_higher" = true ]; then
echo "Unraid 7.2+ detected. Using safe removal method."
if ! /etc/rc.d/rc.unraid-api plugins remove unraid-api-plugin-connect -b; then
echo "Warning: Failed to remove connect API plugin"
fi
# Send notification to user
/usr/local/emhttp/webGui/scripts/notify \
-e "Unraid Connect" \
-s "Reboot Required for Unraid Connect Removal" \
-d "Unraid Connect plugin has been marked for removal. Please reboot your server to complete the uninstallation." \
-i "warning"
# Remove the plugin file so it won't be installed on reboot
PLUGIN_FILE="/boot/config/plugins/${MAINNAME}.plg"
if [ -f "$PLUGIN_FILE" ]; then
echo "Removing plugin file: $PLUGIN_FILE"
rm -f "$PLUGIN_FILE"
fi
echo "Plugin marked for removal. Reboot required to complete uninstallation."
else
# Original removal method for older versions
# Find any installed dynamix.unraid.net package
pkg_installed=$(ls -1 /var/log/packages/dynamix.unraid.net* 2>/dev/null | head -1)
if [ -n "$pkg_installed" ]; then
pkg_basename=$(basename "$pkg_installed")
echo "Removing package: $pkg_basename"
removepkg --terse "$pkg_basename"
else
echo "No dynamix.unraid.net package found. Trying with basic package name."
removepkg --terse "${MAINNAME}"
fi
fi
# File restoration function
echo "Restoring files..."
# Define files to restore in a shell variable - must match backup list
FILES_TO_RESTORE=(
"/usr/local/emhttp/plugins/dynamix/DisplaySettings.page"
"/usr/local/emhttp/plugins/dynamix/Registration.page"
"/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php"
"/usr/local/emhttp/plugins/dynamix/include/ProvisionCert.php"
"/usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php"
"/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php"
"/usr/local/emhttp/plugins/dynamix/include/Wrappers.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/Downgrade.page"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/Update.page"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/ShowChanges.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/showchanges"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php"
"/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/MyServers.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers2.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/data/server-state.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/reboot-details.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/translations.php"
"/usr/local/emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php"
"/usr/local/emhttp/update.htm"
"/usr/local/emhttp/logging.htm"
"/etc/nginx/nginx.conf"
"/etc/rc.d/rc.nginx"
"/usr/share/mozilla/firefox/9n35r0i1.default/user.js"
)
# Restore each file if backup exists
for FILE in "${FILES_TO_RESTORE[@]}"; do
[ -f "$FILE-" ] && mv -f "$FILE-" "$FILE"
done
# Restore CSS files from backup
echo "Restoring original CSS files..."
CSS_DIR="/usr/local/emhttp/plugins/dynamix/styles"
BACKUP_DIR="$CSS_DIR/.unraid-api-backup"
if [ -d "$BACKUP_DIR" ]; then
for backup_file in "$BACKUP_DIR"/*.css; do
if [ -f "$backup_file" ]; then
filename=$(basename "$backup_file")
original_file="$CSS_DIR/$filename"
echo " Restoring $filename..."
cp "$backup_file" "$original_file"
fi
done
# Remove backup directory after restoration
rm -rf "$BACKUP_DIR"
echo "CSS restoration complete."
else
echo "No CSS backup found, skipping restoration."
fi
# Handle the unraid-components directory
DIR=/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components
# Remove the archive's contents before restoring
if [ -d "$DIR" ]; then
rm -rf "$DIR"
fi
if [ -d "$DIR-" ]; then
mv "$DIR-" "$DIR"
echo "Restored directory: $DIR- to $DIR"
fi
]]>
</INLINE>
</FILE>
<!-- install api package and all necessary files -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
TAG="&tag;"
PKG_FILE="&source;" # Full path to the package file including .txz extension
PKG_URL="&txz_url;" # URL where package was downloaded from
PKG_NAME="&txz_name;" # Name of the package file
<![CDATA[
# Install the Slackware package
echo "Installing package..."
# Clean up any old package txz files if they don't match our current version
for txz_file in /boot/config/plugins/dynamix.my.servers/dynamix.unraid.net-*.txz; do
if [ -f "$txz_file" ] && [ "$txz_file" != "${PKG_FILE}" ]; then
echo "Removing old package file: $txz_file"
rm -f "$txz_file"
fi
done
# Remove existing node_modules directory
echo "Cleaning up existing node_modules directory..."
if [ -d "/usr/local/unraid-api/node_modules" ]; then
echo "Removing: /usr/local/unraid-api/node_modules"
rm -rf "/usr/local/unraid-api/node_modules"
fi
# Install the package using the explicit file path
upgradepkg --install-new --reinstall "${PKG_FILE}"
if [ $? -ne 0 ]; then
echo "⚠️ Package installation failed"
exit 1
fi
if [[ -n "$TAG" && "$TAG" != "" ]]; then
printf -v sedcmd 's@^\*\*Unraid Connect\*\*@**Unraid Connect (%s)**@' "$TAG"
sed -i "${sedcmd}" "/usr/local/emhttp/plugins/dynamix.unraid.net/README.md"
fi
exit 0
]]>
</INLINE>
</FILE>
<!-- port of the old doinst.sh script -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
<![CDATA[
SCRIPTS_DIR="/usr/local/share/dynamix.unraid.net/install/scripts"
# Log file for debugging
mkdir -p "/var/log/unraid-api"
echo "Starting Unraid Connect installation..."
# Move settings on flash drive
CFG_OLD=/boot/config/plugins/Unraid.net
CFG_NEW=/boot/config/plugins/dynamix.my.servers
[ -d "$CFG_OLD" ] && [ ! -d "$CFG_NEW" ] && mv "$CFG_OLD" "$CFG_NEW"
# Setup the API (but don't start it yet)
if [ -x "$SCRIPTS_DIR/setup_api.sh" ]; then
echo "Setting up Unraid API..."
echo "Running setup_api.sh"
# Run and show output to user
"$SCRIPTS_DIR/setup_api.sh"
else
echo "ERROR: setup_api.sh not found or not executable"
echo "ERROR: setup_api.sh not found or not executable"
fi
# Run post-installation verification
if [ -x "$SCRIPTS_DIR/verify_install.sh" ]; then
echo "Running post-installation verification..."
echo "Running verify_install.sh"
# Run and show output to user
"$SCRIPTS_DIR/verify_install.sh"
else
echo "ERROR: verify_install.sh not found or not executable"
echo "ERROR: verify_install.sh not found or not executable"
fi
echo "Installation completed at $(date)"
]]>
</INLINE>
</FILE>
<!-- start the unraid api service -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
<![CDATA[
# Clean up any old node_modules archives (on the boot drive) that don't match our current version
#
# Must run after package installation because the package provides an update api config file,
# which determines the current API version and vendor archive to keep.
/etc/rc.d/rc.unraid-api cleanup-dependencies
echo "Starting Unraid API service"
echo "DEBUG: Checking PATH: $PATH"
echo "DEBUG: Checking if unraid-api files exist:"
ls -la /usr/local/unraid-api/dist/
echo "DEBUG: Checking symlink:"
ls -la /usr/local/bin/unraid-api
echo "DEBUG: Checking Node.js version:"
node --version
echo "DEBUG: Checking if cli.js is executable:"
ls -la /usr/local/unraid-api/dist/cli.js
echo "DEBUG: Attempting to run unraid-api directly:"
/usr/local/unraid-api/dist/cli.js version || echo "Direct execution failed"
echo "If no additional messages appear within 30 seconds, it is safe to refresh the page."
/etc/rc.d/rc.unraid-api plugins add unraid-api-plugin-connect -b --no-restart
/etc/rc.d/rc.unraid-api start
echo "Unraid API service started"
echo "✅ Installation is complete, it is safe to close this window"
echo
exit 0
]]>
</INLINE>
</FILE>
<!-- uninstall cleanup message -->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
<![CDATA[
echo
echo "✅ Uninstall is complete, it is safe to close this window"
echo
exit 0
]]>
</INLINE>
</FILE>
</PLUGIN>