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 :  /var/packages/SynologyApplicationService/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/packages/SynologyApplicationService/scripts/utils
#!/bin/sh

SynoSettingsGet()
{
	synogetkeyvalue /var/packages/SynologyApplicationService/etc/settings.conf $1
}

SynoSettingsSet()
{
	synosetkeyvalue /var/packages/SynologyApplicationService/etc/settings.conf $1 $2
}

SynoService()
{
	if [ -z "$SYNOPKG_DSM_VERSION_MAJOR" ]; then
		echo "Require SYNOPKG_DSM_VERSION_MAJOR";
	fi;

	if [[ "$SYNOPKG_DSM_VERSION_MAJOR" -le "6" ]]; then
		SynoUpstartService "$@"
	else
		SynoSystemdService "$@"
	fi;

	return $?;
}

SynoUpstartService()
{
	if (( $# < 2 )); then
		echo "Fatal, Wrong params." > $SYNOPKG_TEMP_LOGFILE
		return 2
	fi

	NEED_GREP=$( [ $1 == 'stop' ] && echo 'stop' || echo 'running' )
	if [ "$1" != "status" ]; then
		initctl $1 $2
		sleep 1
	fi

	if (( $# > 2 )); then
		initctl status $2 | grep $NEED_GREP;
		while (( $? == 0 )); do
			result=true
			for (( idx = 3 ; $idx <= $# ; ++idx )); do
				if ! ${!idx}; then
					result=false
					break;
				fi
			done
			if $result; then
				return 0
			fi
			sleep 0.5
			initctl status $2 | grep $NEED_GREP >/dev/null 2>&1;
		done
		echo "Service \"$2\" $1 failed." > $SYNOPKG_TEMP_LOGFILE
		return 1
	fi
	initctl status $2 | grep $NEED_GREP >/dev/null 2>&1;
	return $?
}

SynoSystemdService()
{
	if (( $# < 2 )); then
		echo "Fatal, Wrong params." > $SYNOPKG_TEMP_LOGFILE
		return 2
	fi

	NEED_GREP=$( [ $1 == 'stop' ] && echo 'inactive' || echo 'active' )
	if [ "$1" != "status" ]; then
		/usr/syno/bin/synosystemctl "$1" "$2"
		sleep 3
	fi

	if (( $# > 2 )); then
		/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}"
		while (( $? == 0 )); do
			result=true
			for (( idx = 3 ; $idx <= $# ; ++idx )); do
				if ! ${!idx}; then
					result=false
					break;
				fi
			done
			if $result; then
				return 0
			fi
			sleep 0.5
			/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}" >/dev/null 2>&1;
		done
		echo "Service \"$2\" $1 failed." > $SYNOPKG_TEMP_LOGFILE
		return 1
	fi
	/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}" >/dev/null 2>&1;
	return $?
}

SynoSetVolume()
{
	volume="$(SynoSettingsGet volume)"

	volume_name=$(realpath /var/packages/SynologyApplicationService/target | /usr/bin/cut -d'/' -f2)
	install_volume="/$volume_name/@SynologyApplicationService"

	if [ ! -d ${install_volume} ]; then
		/bin/mkdir -p ${install_volume}
	fi

	if [[ "" != ${volume} && -d ${volume} && ${volume} != ${install_volume} ]]; then
		/bin/rm -rf ${install_volume}
		/bin/mv -f ${volume} ${install_volume}
	fi

	if [ ! -L /usr/local/SynologyApplicationService ]; then
		/bin/rm -rf /usr/local/SynologyApplicationService
	fi

	/bin/unlink /usr/local/SynologyApplicationService
	/bin/ln -s ${install_volume} /usr/local/SynologyApplicationService

	SynoSettingsSet volume ${install_volume}
}

GSMIsSupported()
{
	if [[ "$(/usr/syno/bin/synogetkeyvalue /etc.defaults/synoinfo.conf support_hyper_converged)" == "yes" ]]; then
		return 0
	fi
	return 1
}

GSMIsController()
{
	local SOFS_ROLE
	SOFS_ROLE=$1
	if [[ "$SOFS_ROLE" == "controller" ]]; then
		return 0
	elif [[ "$SOFS_ROLE" == "agent" ]]; then
		return 1
	fi
	if [[ "$(/usr/syno/bin/hcm-sentinel-tool get-role)" == "controller" ]]; then
		return 0
	fi
	return 1
}

FSDNIsSupported()
{
	if [[ ! -f "/usr/syno/sbin/syno_feature_check.sh" ]]; then
		return 1
	fi
	if [[ -z "$G_FSDN_IS_SUPPORT" ]];then
		if /usr/syno/sbin/syno_feature_check.sh SYNO_PRODUCT_FSDN ; then
			G_FSDN_IS_SUPPORT=0
		else
			G_FSDN_IS_SUPPORT=1
		fi
	fi
	return $G_FSDN_IS_SUPPORT
}

FSDNIsAdminNode()
{
	if [[ "$(/usr/syno/bin/aacore is-admin-node)" == "yes" ]]; then
		return 0
	fi
	return 1
}

IsSASServiceRunningNode()
{
	local role=$1
	# GSM agent node
	if GSMIsSupported && ! GSMIsController "${role}"; then
		return 1
	fi
	# PAM non-admin node
	if FSDNIsSupported && ! FSDNIsAdminNode; then
		return 1
	fi
	return 0
}

Youez - 2016 - github.com/yon3zu
LinuXploit