HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //var/packages/phpMyAdmin/scripts/script_customized
#!/bin/bash
# Copyright (c) 2000-2021 Synology Inc. All rights reserved.


GetPMAPrevWebsiteRoot()
{
	local dsm7_website_root="$(GetWebsiteRootOfPreviousVersion)"
	local legacy_website_root="$(dirname "${dsm7_website_root}")/phpMyAdmin"
	if [ -d "$legacy_website_root" ]; then
		echo "$legacy_website_root"
		return
	fi
	echo "$dsm7_website_root"
}

CustomPreupgrade()
{
	if [ -f ${BLOWFISHSECRET_PATH} ]; then
		return;
	fi

	# migrate blowfish secret for upgraders from DSM6
	local prev_website_root="$(GetPMAPrevWebsiteRoot)"
	local config_php="$prev_website_root/config.inc.php"
	local blowfish_secret=$(grep blowfish_secret $config_php)

	if [ -z "$blowfish_secret" ]; then
		echo "blowfish_secret does not exist in the old config"
		return
	fi

	echo $blowfish_secret | awk '{print $3}' | sed "s/[^A-Za-z0-9+\/=]//g" > ${BLOWFISHSECRET_PATH}
}

CustomRestoreUpgrade()
{
	if [ ! -f ${BLOWFISHSECRET_PATH} ]; then
		echo "blowfish secret does not exist in ${BLOWFISHSECRET_PATH}"
		return
	fi
	ApplyBlowfishSecret
}

ApplyBlowfishSecret()
{
	# setup blowfish secret config
	local blowfish_secret=$(cat "$BLOWFISHSECRET_PATH")
	cp -a "$WEBSITE_ROOT/config.sample.inc.php" "$WEBSITE_ROOT/config.inc.php"
	sed -i "s|__BLOWFISH_SECRET__|$blowfish_secret|" "$WEBSITE_ROOT/config.inc.php"

	# apply setting
	local service_choice_tool="/var/packages/$PKG_NAME/target/tool/serverchoicetool.php"
	$service_choice_tool INIT
	[ -f /var/packages/MariaDB10/enabled ] && $service_choice_tool ADDM10
}

InitializeBlowfishSecret()
{
	/usr/bin/openssl rand -base64 32 | head -c 32 > "$BLOWFISHSECRET_PATH"
	ApplyBlowfishSecret
}

CustomNewInst()
{
	InitializeBlowfishSecret
}

CustomSetCleanNew()
{
	InitializeBlowfishSecret
}