403Webshell
Server IP : 193.86.120.172  /  Your IP : 216.73.216.67
Web Server : Apache/2.4.63 (Unix)
System : Linux JServices 3.10.108 #86003 SMP Wed Oct 22 13:20:46 CST 2025 x86_64
User : kubec ( 1026)
PHP Version : 8.2.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/29145/root/lib64/systemd/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/29145/root/lib64/systemd/scripts/accountdb-cache.sh
#!/bin/bash

CACHE_IMG_LINK="/usr/syno/etc/private/.account.cache.img"
CACHE_MNT_LINK="/usr/syno/etc/private/@accountcache"
FLAG_MNT="/usr/syno/etc/private/@accountcache/.cache_mount"

IsDomain() {
	local SECURITY;
	if [ -f "/run/samba/synoadserver" ]; then
		return 0
	fi

	SECURITY=$(/usr/syno/bin/synogetkeyvalue /etc/samba/smb.conf "security")
	if [ "ads" == "$SECURITY" ] || [ "domain" == "$SECURITY" ]; then
		return 0
	fi
	return 1
}

IsLDAP() {
	# currently ldap not support this feature
	#if [ -f "/usr/syno/etc/ldapclient/ldap_joined" ]; then
	#	return 0
	#fi
	return 1
}

IsForceEnable() {
	if [ -f "/run/.force_enable_account_cache" ]; then
		return 0
	fi
	return 1
}

IsMntCache() {
	local MNT_REALPATH;
	local MNT_REALPATH_PARENT;
	local DEVNO_MNT;
	local DEVNO_PARENT;
	if [ -h "$CACHE_MNT_LINK" ]; then
		MNT_REALPATH=$(/bin/realpath "$CACHE_MNT_LINK" 2> /dev/null)
	else
		MNT_REALPATH=$(/bin/grep "@accountdb" "/proc/mounts" | cut -d' ' -f2)
	fi
	if [ -z "$MNT_REALPATH" ]; then
		# not found mount point
		return 1
	fi
	MNT_REALPATH_PARENT=$(/bin/dirname "$MNT_REALPATH")
	if ! DEVNO_MNT=$(/bin/stat -c "%D" "$MNT_REALPATH"); then
		return 1
	fi
	DEVNO_PARENT=$(/bin/stat -c "%D" "$MNT_REALPATH_PARENT")
	if [ "$DEVNO_MNT" = "$DEVNO_PARENT" ]; then
		# not mount cache
		return 1
	fi
	return 0
}

CreateCacheImg() {
	local AVAIL_VOLUME;
	local CACHE_DIR;
	local MNT_DIR;

	# check reserve 20G ?
	if AVAIL_VOLUME=$(/usr/syno/bin/servicetool --get-available-volume --space-requirement 20480); then
		# not found
		echo "no available volume"
		return;
	fi
	CACHE_DIR="${AVAIL_VOLUME}/@accountdb"
	if [ ! -d "$CACHE_DIR" ]; then
		mkdir "${CACHE_DIR}"
	fi
	MNT_DIR="${CACHE_DIR}/@accountcache"
	if [ ! -d "${MNT_DIR}" ]; then
		if ! mkdir "${MNT_DIR}"; then
			# mkdir mnt point fail
			echo "mkdir (${MNT_DIR}) fail"
			return
		fi
	fi
	rm -f "${CACHE_MNT_LINK}"
	ln -s "${MNT_DIR}" "${CACHE_MNT_LINK}"

	# create sparse 30GB file
	if ! [ -f "${CACHE_DIR}/.account.cache.img" ]; then
		/bin/truncate -s "30G" "${CACHE_DIR}/.account.cache.img"
		/sbin/mkfs.ext4 -i 1024 "${CACHE_DIR}/.account.cache.img"
		/bin/sync "${CACHE_DIR}/.account.cache.img"
	fi
	rm -f "${CACHE_IMG_LINK}"
	ln -s "${CACHE_DIR}/.account.cache.img" "${CACHE_IMG_LINK}"
}

EnlargeImg() {
	local IMG_FILE="$1"
	local EXPAND_SIZE="+10G"

	COUNT=5
	while true
	do
		if ! REMAIN_LOOP="$(losetup -a | grep account.cache.img 2> /dev/null)"; then
			break
		fi
		REMAIN_LOOP="$(echo "$REMAIN_LOOP" | head -n1 | cut -d':' -f 1)"
		losetup -d "${REMAIN_LOOP}"
		sleep 2
		COUNT=$((COUNT-1))
		if [ $COUNT -le 0 ]; then
			break
		fi
	done
	if [ "$COUNT" -eq 0 ]; then
		echo "wait account-cache lo timeout"
		return 1
	fi

	if ! truncate -s $EXPAND_SIZE "$IMG_FILE"; then
		# expand fail
		echo "expand img file fail"
		return 1
	fi

	if ! LOOP_DEV="$(losetup -fP --show "$IMG_FILE")"; then
		# losetup fail maybe it can't be used
		echo "losetup img file:'${IMG_FILE}' fail"
		return 1
	fi

	if ! e2fsck -f -y "${LOOP_DEV}"; then
		# e2fsck fail
		echo "e2fsck img file fail"
		losetup -d "${LOOP_DEV}"
		return 1
	fi

	if ! resize2fs "${LOOP_DEV}"; then
		echo "resize2fs fail"
		losetup -d "${LOOP_DEV}"
		return 1
	fi
	losetup -d "${LOOP_DEV}"
	return 0
}

Start() {
	local CACHE_REALPATH;
	local CACHE_MNT_PATH;
	if ! IsForceEnable && ! IsDomain && ! IsLDAP; then
		return
	fi

	if IsMntCache; then
		return
	fi

	if ! [ -h "${CACHE_IMG_LINK}" ]; then
		CreateCacheImg
	fi
	CACHE_REALPATH=$(/bin/realpath "${CACHE_IMG_LINK}" 2> /dev/null)
	if [ -f "$CACHE_REALPATH" ] && IMG_SIZE="$(/bin/stat -c "%s" "${CACHE_REALPATH}")"; then
		if [ "${IMG_SIZE}" -lt 30000000000 ] && ! EnlargeImg "${CACHE_REALPATH}"; then
			rm -f "$CACHE_REALPATH"
		fi
	fi
	if ! [ -f "$CACHE_REALPATH" ]; then
		CreateCacheImg
		CACHE_REALPATH=$(/bin/realpath "${CACHE_IMG_LINK}" 2> /dev/null)
		if ! [ -f "$CACHE_REALPATH" ]; then
			echo "create cache image($CACHE_REALPATH) fail"
			return
		fi
	fi

	if ! [ -h "$CACHE_MNT_LINK" ]; then
		CreateCacheImg
	fi
	CACHE_MNT_PATH=$(/bin/realpath "$CACHE_MNT_LINK" 2> /dev/null)
	if ! [ -d "$CACHE_MNT_PATH" ]; then
		CreateCacheImg
		CACHE_MNT_PATH=$(/bin/realpath "$CACHE_MNT_LINK" 2> /dev/null)
		if ! [ -d "$CACHE_MNT_PATH" ]; then
			echo "create cache image mount path($CACHE_MNT_PATH) fail"
			return
		fi
	fi

	if /bin/mount -o noatime "${CACHE_REALPATH}" "$CACHE_MNT_PATH"; then
		/bin/touch "${FLAG_MNT}"
	else
		echo "mount accountdb cache fail: $CACHE_MNT_PATH"
	fi
}

Stop() {
	local CACHE_MNT_PATH;
	CACHE_MNT_PATH=$(/bin/realpath "$CACHE_MNT_LINK" 2> /dev/null)
	if IsMntCache; then
		/bin/umount -fl "$CACHE_MNT_PATH"
	fi
	rm -f "${FLAG_MNT}"
}

case $1 in
	start)
		Start
		;;
	stop)
		Stop
		;;
	*)
		echo "Wrong Parameter"
		;;
esac

Youez - 2016 - github.com/yon3zu
LinuXploit