Fix logging.htm (openBox) so it works in an iframe (#637)

This commit is contained in:
ljm42
2023-05-02 08:05:09 -07:00
committed by GitHub
parent ba7c6e8e2d
commit a168ab43a6

View File

@@ -0,0 +1,644 @@
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "">
<!ENTITY launch "Connect">
<!ENTITY author "limetech">
<!ENTITY env "">
<!ENTITY version "">
<!ENTITY pluginURL "">
<!ENTITY source "/boot/config/plugins/dynamix.my.servers/&name;">
<!ENTITY MD5 "">
<!ENTITY SHA256 "">
<!ENTITY API_version "">
<!ENTITY API_MD5 "">
<!ENTITY API_SHA256 "">
<!ENTITY downloadserver "">
<!ENTITY js_dl_server "">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="&pluginURL;" launch="&launch;" min="6.9.0-rc1" icon="globe">
<CHANGES>
##a long time ago in a galaxy far far away
- initial release
</CHANGES>
<!-- prevent prod plugin from installing when staging already installed, and vice versa -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
name="&name;"
version="&version;"
API_version="&API_version;"
PLGTYPE="&env;"
<![CDATA[
echo "Installing ${name}.plg ${version} with Unraid API ${API_version}"
if [ "${PLGTYPE}" = "production" ] && [ -f /boot/config/plugins/dynamix.unraid.net.staging.plg ]; then
echo "⚠️ Please uninstall the Unraid Connect staging plugin before installing the production version"
exit 1
fi
if [ "${PLGTYPE}" = "staging" ] && [ -f /boot/config/plugins/dynamix.unraid.net.plg ]; then
echo "⚠️ Please uninstall the Unraid Connect production plugin before installing the staging version"
exit 1
fi
exit 0
]]>
</INLINE>
</FILE>
<!-- gzip check, DNS check, then validate files before doing anything destructive -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
DLHOST=$(echo "&downloadserver;" | awk -F/ '{print $3}')
JSHOST=$(echo "&js_dl_server;" | awk -F/ '{print $3}')
<![CDATA[
version=
# shellcheck disable=SC1091
source /etc/unraid-version
# ensure gzip is available and executes, is needed by '/etc/rc.d/rc.unraid-api install'
if [ ! -x /bin/gzip ] || ! /bin/gzip -V &>/dev/null; then
echo "⚠️ Unable to install as gzip is not available on this system. For help, post your diagnostics.zip to a new support thread in the forum."
exit 1
fi
dnscheck() {
HOST=$1
if [ -x /usr/bin/host ] && ! /usr/bin/host -W 10 "${HOST}" &>/dev/null; then
echo "⚠️ Warning: Your DNS server (${DNS_SERVER1}) is unable to resolve '${HOST}'"
DNSERR=yes
fi
}
# shellcheck disable=SC1090
source <(grep "DNS_SERVER1" /usr/local/emhttp/state/network.ini 2>/dev/null)
DNSERR=no
echo "Checking DNS..."
#dnscheck "${DLHOST}"
#dnscheck "${JSHOST}"
dnscheck "mothership.unraid.net"
#dnscheck "wanip4.unraid.net"
#dnscheck "backup.unraid.net"
[[ "${DNSERR}" == "yes" && "${DNS_SERVER1}" != "8.8.8.8" ]] && echo " Recommend navigating to Settings -> Network Settings and changing your DNS server to 8.8.8.8"
# Note: DNS checks will fail if the network is not available at boot. Cannot exit the install when DNS checks fail.
echo
echo "⚠️ Do not close this window yet"
echo
# compare expected SHA256 to actual SHA256, if not equal delete file
# this is needed prior to Unraid 6.11.0
sha256check() {
FILE=$1
EXPECTED=$2
if [[ -f "${FILE}" ]]; then
echo -n "Validating ${FILE}... "
ACTUAL=$(sha256sum "${FILE}" 2>/dev/null | grep -Po '^\S+')
if [[ "$EXPECTED" != "$ACTUAL" ]]; then
rm "${FILE}"
echo " old. Deleted file."
else
echo " ok."
fi
fi
}
]]>
sha256check "&source;.txz" "&SHA256;"
sha256check "/boot/config/plugins/dynamix.my.servers/unraid-api.tgz" "&API_SHA256;"
exit 0
</INLINE>
</FILE>
<!-- download main txz -->
<FILE Name="&source;.txz">
<URL>&downloadserver;/unraid-api/&name;-&version;.txz</URL>
<MD5>&MD5;</MD5>
<SHA256>&SHA256;</SHA256>
</FILE>
<!-- download unraid-api -->
<FILE Name="/boot/config/plugins/dynamix.my.servers/unraid-api.tgz">
<URL>&downloadserver;/unraid-api/unraid-api-&API_version;.tgz</URL>
<MD5>&API_MD5;</MD5>
<SHA256>&API_SHA256;</SHA256>
</FILE>
<FILE Run="/bin/bash" Method="install">
<INLINE>
MAINTXZ="&source;.txz"
<![CDATA[
# before proceeding with install, doubly confirm downloaded files exist. just being pedantic.
FILE=${MAINTXZ} && [[ ! -f "$FILE" ]] && echo "⚠️ file missing - $FILE" && exit 1
FILE=/boot/config/plugins/dynamix.my.servers/unraid-api.tgz && [[ ! -f "$FILE" ]] && echo "⚠️ file missing - $FILE" && exit 1
exit 0
]]>
</INLINE>
</FILE>
<!-- download and install JavaScript web components -->
<!-- (installing this won't hurt anything if we exit the installer later) -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
js_dl_server=&js_dl_server;
<![CDATA[
version=
# shellcheck disable=SC1091
source /etc/unraid-version
# skip this install block on isUnsupportedVersion
if [[ "${version:0:3}" == "6.9" || "${version:0:7}" == "6.10.0-" ]]; then
exit 0
fi
echo
echo "⚠️ Do not close this window yet"
echo
# manually download the JavaScript web components
JS_FLASH_DEST=/boot/config/plugins/dynamix.my.servers/webComps/
JS_FINAL_DEST=/usr/local/emhttp/plugins/dynamix.my.servers/webComps/
JS_FILE=unraid.min.js
echo "🕹️ Installing JavaScript web components"
# on first install, no limits to wget retries/timeouts.
# on subsequent installs, don't let wget prevent Unraid from booting when network is down
WGET_LIMIT=
[[ -f "${JS_FLASH_DEST}${JS_FILE}" ]] && WGET_LIMIT=" -t 1 -T 20 "
# always re-download latest unraid.min.js
rm -f "/tmp/${JS_FILE}.tmp1"
rm -f "/tmp/${JS_FILE}.tmp2"
wget ${WGET_LIMIT} -q --compression=auto --no-cache "${js_dl_server}/webComps/${JS_FILE}" -O "/tmp/${JS_FILE}.tmp1" &>/dev/null
if [[ -f "/tmp/${JS_FILE}.tmp1" && -s "/tmp/${JS_FILE}.tmp1" ]]; then
# simple validatation that the file was downloaded correctly
if grep -q "sourceMappingURL=unraid.min.js.map" "/tmp/${JS_FILE}.tmp1"; then
# remove source mapping from js
head -n -1 "/tmp/${JS_FILE}.tmp1" >"/tmp/${JS_FILE}.tmp2"
rm "/tmp/${JS_FILE}.tmp1"
fi
fi
# if /tmp/${JS_FILE}.tmp2 was downloaded above, move it to JS_FLASH_DEST
[[ -f "/tmp/${JS_FILE}.tmp2" ]] && mkdir -p "${JS_FLASH_DEST}" && mv "/tmp/${JS_FILE}.tmp2" "${JS_FLASH_DEST}${JS_FILE}"
# NOTE: if download was not successful, there may still be a previous copy in JS_FLASH_DEST
# if unraid.min.js exists in JS_FLASH_DEST, copy it from JS_FLASH_DEST to JS_FINAL_DEST
# @TODO: validate that the unraid.min.js in JS_FLASH_DEST is not older than an existing one in JS_FINAL_DEST
[[ -f "${JS_FLASH_DEST}${JS_FILE}" ]] && mkdir -p "${JS_FINAL_DEST}" && cp "${JS_FLASH_DEST}${JS_FILE}" "${JS_FINAL_DEST}"
# NOTE: if file does not exist in JS_FLASH_DEST, there should still be a previous copy in JS_FINAL_DEST (unless Unraid 6.9)
# if not, we have to exit
[[ ! -f "${JS_FINAL_DEST}${JS_FILE}" ]] && echo "⚠️ Install failed - ${JS_FILE} missing" && exit 1
echo "✅ Finished installing web components"
echo
echo "⚠️ Do not close this window yet"
echo
exit 0
]]>
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
<![CDATA[
version=
# shellcheck disable=SC1091
source /etc/unraid-version
echo
echo "⚠️ Do not close this window yet"
echo
exit 0
]]>
</INLINE>
</FILE>
<!-- disable features on uninstall -->
<!-- NOTE: this script is PHP not bash -->
<FILE Run="/usr/bin/php" Method="remove">
<INLINE>
<![CDATA[
<?
$msini = @parse_ini_file('/boot/config/plugins/dynamix.my.servers/myservers.cfg', true);
# for convenience, scan myservers.cfg for deleteOnUninstall="no" and if that exists,
# then skip the rest of the cleanup.
$deleteOnUninstall = ($msini === false || empty($msini['plugin']['deleteOnUninstall']) || $msini['plugin']['deleteOnUninstall'] == 'yes');
if (!$deleteOnUninstall) {
exit(0);
}
echo "\n";
echo "**********************************\n";
echo "🧹 CLEANING UP - may take a minute\n";
echo "**********************************\n";
if (file_exists("/boot/.git")) {
if (file_exists("/etc/rc.d/rc.flash_backup")) {
# stop flash backup service
echo "\nStopping flash backup service. Please wait…";
exec("/etc/rc.d/rc.flash_backup stop &>/dev/null");
}
if (file_exists("/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php")) {
# deactivate and delete local flash backup
echo "\nDeactivating flash backup. Please wait…";
passthru("/usr/bin/php /usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php deactivate");
}
}
# set "Allow Remote Access" to "No" and sign out from Unraid Connect
if ($msini !== false) {
# stop unraid-api
echo "\nStopping unraid-api. Please wait…";
exec("/etc/rc.d/rc.unraid-api stop &>/dev/null");
if (!empty($msini['remote']['username'])) {
$var = parse_ini_file("/var/local/emhttp/var.ini");
$keyfile = @file_get_contents($var['regFILE']);
if ($keyfile !== false) {
echo "\nSigning out of Unraid Connect\n";
$ch = curl_init('https://keys.lime-technology.com/account/server/unregister');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['keyfile' => @base64_encode($keyfile)]);
curl_exec($ch);
curl_close($ch);
}
}
# remove myservers.cfg
unlink('/boot/config/plugins/dynamix.my.servers/myservers.cfg');
# reload nginx to disable Remote Access
echo "\n⚠ Reloading Web Server. If this window stops updating for two minutes please close it.\n";
exec("/etc/rc.d/rc.nginx reload &>/dev/null");
}
exit(0);
]]>
</INLINE>
</FILE>
<!-- disable features when upgrading on unsupported OS versions -->
<!-- duplicated from above because the script can't distinguish between install and remove -->
<!-- NOTE: this script is PHP not bash -->
<FILE Run="/usr/bin/php" Method="install">
<INLINE>
<![CDATA[
<?
$ver = @parse_ini_file('/etc/unraid-version', true)['version'];
$msini = @parse_ini_file('/boot/config/plugins/dynamix.my.servers/myservers.cfg', true);
// exit this install block if NOT isUnsupportedVersion
if (!( (substr($ver,0,3)=="6.9") || (substr($ver,0,7)=="6.10.0-") )) {
exit(0);
}
echo "\n";
echo "**********************************\n";
echo "🧹 CLEANING UP - may take a minute\n";
echo "**********************************\n";
if (file_exists("/boot/.git")) {
if (file_exists("/etc/rc.d/rc.flash_backup")) {
# stop flash backup service
echo "\nStopping flash backup service. Please wait…";
exec("/etc/rc.d/rc.flash_backup stop &>/dev/null");
}
if (file_exists("/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php")) {
# deactivate and delete local flash backup
echo "\nDeactivating flash backup. Please wait…";
passthru("/usr/bin/php /usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php deactivate");
}
}
# set "Allow Remote Access" to "No" and sign out from Unraid Connect
if ($msini !== false) {
# stop unraid-api
echo "\nStopping unraid-api. Please wait…";
exec("/etc/rc.d/rc.unraid-api stop &>/dev/null");
if (!empty($msini['remote']['username'])) {
$var = parse_ini_file("/var/local/emhttp/var.ini");
$keyfile = @file_get_contents($var['regFILE']);
if ($keyfile !== false) {
echo "\nSigning out of Unraid Connect\n";
$ch = curl_init('https://keys.lime-technology.com/account/server/unregister');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['keyfile' => @base64_encode($keyfile)]);
curl_exec($ch);
curl_close($ch);
}
}
# remove myservers.cfg
unlink('/boot/config/plugins/dynamix.my.servers/myservers.cfg');
# reload nginx to disable Remote Access
echo "\n⚠ Reloading Web Server. If this window stops updating for two minutes please close it.\n";
exec("/etc/rc.d/rc.nginx reload &>/dev/null");
}
exit(0);
]]>
</INLINE>
</FILE>
<!-- uninstall existing plugin during update or removal -->
<FILE Run="/bin/bash" Method="install remove">
<INLINE>
MAINNAME="&name;"
<![CDATA[
version=
# shellcheck disable=SC1091
source /etc/unraid-version
echo
echo "⚠️ Do not close this window yet"
echo
if [ -e /etc/rc.d/rc.unraid-api ]; then
# stop flash backup
/etc/rc.d/rc.flash_backup stop &>/dev/null
# stop the api gracefully
/etc/rc.d/rc.unraid-api stop
# forcibly stop older clients
kill -9 `pidof unraid-api` &>/dev/null
# uninstall the api
/etc/rc.d/rc.unraid-api uninstall &>/dev/null
# uninstall the main source package
[[ -f "/var/log/packages/${MAINNAME}" ]] && removepkg --terse "${MAINNAME}"
# restore stock files
FILE=/usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix/Registration.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix/DisplaySettings.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/MyServers.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers2.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
FILE=/sbin/upgradepkg && [[ -f "$FILE-" ]] && mv -f "$FILE-" "$FILE"
# delete plugin files from flash drive and OS
rm -f /boot/config/plugins/dynamix.my.servers/.gitignore
rm -f /etc/rc.d/rc.unraid-api
rm -f /etc/rc.d/rc.flash_backup
rm -f /usr/local/sbin/unraid-api
rm -rf /usr/local/emhttp/plugins/dynamix.unraid.net
rm -rf /usr/local/emhttp/plugins/dynamix.unraid.net.staging
rm -f /etc/rc.d/rc6.d/K10_flash_backup
rm -f /var/log/gitcount
rm -f /var/log/gitflash
rm -f /usr/local/emhttp/state/flashbackup.ini
rm -f /usr/local/emhttp/state/myservers.cfg
# delete any legacy files that may exist
rm -rf /boot/config/plugins/dynamix.my.servers/libvirt.node
rm -rf /boot/config/plugins/dynamix.my.servers/segfault-handler.node
rm -rf /boot/config/plugins/dynamix.my.servers/wc
rm -f /boot/config/plugins/Unraid.net/unraid-api.tgz
rm -f /boot/config/plugins/Unraid.net/.gitignore
rm -rf /boot/config/plugins/Unraid.net/webComps
rm -rf /boot/config/plugins/Unraid.net/wc
rm -f /usr/local/emhttp/webGui/javascript/vue.js
rm -f /usr/local/emhttp/webGui/javascript/vue.min.js
rm -rf /usr/local/emhttp/webGui/webComps
rm -rf /usr/local/emhttp/webGui/wc
# clean up our optional makestate modifications in rc.nginx (on 6.9 and 6.10.0-rc[12])
sed -i '/scripts\/makestate/d' /etc/rc.d/rc.nginx
# clean up extra origin for robots.txt
sed -i '#robots.txt any origin/d' /etc/rc.d/rc.nginx
fi
exit 0
]]>
</INLINE>
</FILE>
<!-- install all the things -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
PLGTYPE="&env;"
MAINTXZ="&source;.txz"
<![CDATA[
appendTextIfMissing() {
FILE="$1"
TEXT="$2"
if test -f "${FILE}" && ! grep -q "${TEXT}" "${FILE}" &>/dev/null; then
echo "${TEXT}" >>"${FILE}"
fi
}
version=
# shellcheck disable=SC1091
source /etc/unraid-version
# exit this install block on isUnsupportedVersion
if [[ "${version:0:3}" == "6.9" || "${version:0:7}" == "6.10.0-" ]]; then
echo
echo "⚠️ Please uninstall this plugin or upgrade to a newer version of Unraid to enjoy Unraid Connect"
echo
echo "✅ It is safe to close this window"
echo
PLGNAME=dynamix.unraid.net
[ "${PLGTYPE}" = "staging" ] && PLGNAME=dynamix.unraid.net.staging
DIR="/usr/local/emhttp/plugins/${PLGNAME}" && [[ ! -d "$DIR" ]] && mkdir "$DIR"
cat << EOF > "$DIR/README.md"
**Unraid Connect**
Please uninstall this plugin or upgrade to a newer version of Unraid to enjoy Unraid Connect
EOF
# exit 0 or else the original plugin will be reinstalled at boot
exit 0
fi
echo
echo "⚠️ Do not close this window yet"
echo
# NOTE: any 'exit 1' after this point will result in a broken install
# Preserve in case plugin is removed
FILE=/usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix/Registration.page && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/MyServers.page && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/Registration.page && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers2.php && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php && [[ -f "$FILE" ]] && mv -f "$FILE" "$FILE-"
FILE=/sbin/upgradepkg && [[ -f "$FILE" ]] && cp -f "$FILE" "$FILE-"
# 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"
# relax restrictions on built-in Firefox so it can sign in to Unraid Connect
# brings older versions of Unraid in sync with 6.12.0
# no need to restore original file on uninstall
# note: if file is modified while Firefox is open it will have no effect, reboot to change the file before Firefox is loaded
# note: prior to 6.12, file will only exist if system is booted in GUI Mode
FILE=/usr/share/mozilla/firefox/9n35r0i1.default/user.js
if [[ -f "$FILE" ]]; then
cp -f "$FILE" "$FILE-"
appendTextIfMissing "${FILE}" 'user_pref("privacy.firstparty.isolate", false);'
appendTextIfMissing "${FILE}" 'user_pref("javascript.options.asmjs", true);'
appendTextIfMissing "${FILE}" 'user_pref("javascript.options.wasm", true);'
fi
# fix update.htm to work in an iframe
# brings older versions of Unraid in sync with 6.12.0
# no need to restore original file on uninstall, will cause issues if uninstall from within an iframe
FILE=/usr/local/emhttp/update.htm
if test -f "${FILE}" && grep -q "top.document" "${FILE}" &>/dev/null; then
cp -f "$FILE" "$FILE-"
sed -i 's/top.document/parent.document/gm' "${FILE}"
fi
# fix logging.htm (openBox) to work in an iframe
# brings older versions of Unraid in sync with 6.12.0
# no need to restore original file on uninstall
FILE=/usr/local/emhttp/logging.htm
if test -f "${FILE}" && grep -q "top.Shadowbox" "${FILE}" &>/dev/null; then
cp -f "$FILE" "$FILE-"
sed -i 's/top.Shadowbox/parent.Shadowbox/gm' "${FILE}"
fi
# install the main txz
upgradepkg --install-new --reinstall "${MAINTXZ}"
# confirm an expected file now exists
# WARNING: failure here results in broken install
[[ ! -f /usr/local/emhttp/plugins/dynamix.my.servers/scripts/cfgMigration ]] && echo "⚠️ files missing from main txz" && exit 1
echo
echo "⚠️ Do not close this window yet"
echo
# setup env
if [ "${PLGTYPE}" = "production" ] || [ ! -f /boot/config/plugins/dynamix.my.servers/env ]; then
echo "env=\"${PLGTYPE}\"" >/boot/config/plugins/dynamix.my.servers/env
fi
echo
echo "⚠️ Do not close this window yet"
echo
# run dynamix.cfg to myservers.cfg migration
CFG_MIG=/usr/local/emhttp/plugins/dynamix.my.servers/scripts/cfgMigration
php $CFG_MIG
# Use myservers.cfg values to help prevent conflicts when installing
CFG=/boot/config/plugins/dynamix.my.servers/myservers.cfg
# shellcheck disable=SC1090
source <(grep 'email\|apikey="unraid_' "${CFG}" 2>/dev/null)
CFG_CLEANED=0
# If user is signed in but has no apikey, or if the apikey is not 64 chars, wipe the [remote] section from the cfg
if ([[ -n "${email}" && (-z "${apikey}" || "${#apikey}" -ne "64") ]]); then
# remove only the [remote] section
awk '{
if($0 ~ /\[remote\]/){output="off"; next}
if($0 ~ /\[/){output="on"; print; next}
if(output == "on"){print}
}' "${CFG}" >"${CFG}-new" && mv "${CFG}-new" "${CFG}"
CFG_CLEANED=1
echo "⚠️ Automatically signed out of Unraid.net"
fi
# if there wasn't an email or the CFG was cleaned
if [[ -z "${email}" ]] || [[ CFG_CLEANED -eq 1 ]]; then
echo "✨ Sign In to Unraid.net to use Unraid Connect ✨"
fi
# make the unraid-api work globally for easy cli access
ln -s /usr/local/bin/unraid-api/unraid-api /usr/local/sbin/unraid-api
# configure flash backup to stop when the system starts shutting down
[[ ! -d /etc/rc.d/rc6.d ]] && mkdir /etc/rc.d/rc6.d
[[ ! -h /etc/rc.d/rc0.d ]] && ln -s /etc/rc.d/rc6.d /etc/rc.d/rc0.d
[[ ! -h /etc/rc.d/rc6.d/K10_flash_backup ]] && ln -s /etc/rc.d/rc.flash_backup /etc/rc.d/rc6.d/K10_flash_backup
# allow webgui to be iframed only on Connect dashboard, only applies to 6.10+
# if needed, restart nginx before installing the unraid-api
CHANGED=no
FILE=/etc/nginx/nginx.conf
# brings older versions of Unraid in sync with 6.12.0
if grep -q "SAMEORIGIN" "${FILE}"; then
CHANGED=yes
cp "$FILE" "$FILE-"
OLD="add_header X-Frame-Options 'SAMEORIGIN';"
NEW="add_header Content-Security-Policy \"frame-ancestors 'self' https://connect.myunraid.net/\";"
sed -i "s#${OLD}#${NEW}#" "${FILE}"
fi
if [ "${PLGTYPE}" = "staging" ]; then
# staging plugin allows an additional origin
if ! grep -q "dev-my.myunraid.net:4000" "${FILE}"; then
CHANGED=yes
[[ ! -f "$FILE-" ]] && cp "$FILE" "$FILE-"
OLD="add_header Content-Security-Policy \"frame-ancestors 'self' https://connect.myunraid.net/\";"
NEW="add_header Content-Security-Policy \"frame-ancestors 'self' https://connect.myunraid.net/ https://dev-my.myunraid.net:4000/\";"
sed -i "s#${OLD}#${NEW}#" "${FILE}"
fi
fi
FILE=/etc/rc.d/rc.nginx
# brings older versions of Unraid in sync with 6.12.0
if ! grep -q "#robots.txt any origin" "${FILE}"; then
CHANGED=yes
cp "$FILE" "$FILE-"
FIND="location = \/robots.txt {"
# escape tabs and spaces
ADD="\ \ \ \ \ add_header Access-Control-Allow-Origin *; #robots.txt any origin"
sed -i "/${FIND}/a ${ADD}" "${FILE}"
fi
if [[ "${CHANGED}" == "yes" ]]; then
if /etc/rc.d/rc.nginx status &>/dev/null; then
# if nginx is running, reload it to enable the changes above
# note: if this is being installed at boot, nginx will not yet be running
echo ""
echo "⚠️ Reloading Web Server. If this window stops updating for two minutes please close it."
/etc/rc.d/rc.nginx reload &>/dev/null
fi
fi
# start background process to install/start the api and flash backup
echo
if [ -f /var/local/emhttp/var.ini ]; then
# the system has fully booted, emhttpd and nginx are running
echo "Installing and starting the Unraid API"
echo "Starting flash backup (if enabled)"
echo "/etc/rc.d/rc.unraid-api install; /etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
# else
# the system is booting, emhttpd will install the api and start rc.flash_backup. rc.nginx will start the api.
# nothing to do here
fi
echo
echo "✅ Installation is complete, it is safe to close this window"
echo
exit 0
]]>
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
<![CDATA[
version=
# shellcheck disable=SC1091
source /etc/unraid-version
echo
echo "✅ Uninstall is complete, it is safe to close this window"
echo
exit 0
]]>
</INLINE>
</FILE>
</PLUGIN>