HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: /volume1/@appstore/MailPlus-Server/hook/UserGroupPolicyUserUpdate.sh
#!/bin/bash

###############################################################
#	This script should be hooked when invoking SYNOUserSet()
#	Usable environment variable:
#		NITEMS, ORIGIN_USER_NAME_{n}, USER_NAME_{n}, UID_{n},
#		USER_OP_RESULT_{n}, RESULT
#
#	Note: The script should bear to be invoked multiple times
###############################################################

#Include common scripts
. /var/packages/MailPlus-Server/target/scripts/MailPlusServerCommon

#At begining, acquire package settings
PackageInfoGet;

MAIL_SERVER_PKG="/var/packages/MailPlus-Server"
PERSONAL_POLICY_BIN="${MAIL_SERVER_PKG}/target/bin/syno_personal_policy"
USAGE_MEMCACHED_BIN="${MAIL_SERVER_PKG}/target/bin/syno_usage_memcached"

UpdateUsageMemcached()
{
	if [ ! -z "$org_name" ] && [ "$org_name" != "$new_name" ]; then
		${USAGE_MEMCACHED_BIN} update_user "$org_name" "$new_name"
		if [ 0 != $? ]; then
			err_log "[Usage memcached Update]: failed to UPDATE [${org_name}]=>[${new_name}] from memcached"
		fi
	fi
}

case $1 in
	--sdk-mod-ver)
		#Print SDK support version
		echo "1.0";
		;;
	--name)
		#Print package name
		echo "${MAIL_SERVER_PKG_NAME}";
		;;
	--pkg-ver)
		#Print package version
		echo "${MAIL_SERVER_PKG_VERSION}";
		;;
	--vendor)
		#Print package vendor
		echo "${MAIL_SERVER_PKG_VENDOR}";
		;;
	--pre)
		#noop
		;;
	--post)

		#[TODO] Need refined
		${PERSONAL_POLICY_BIN} refresh
		# Update user policy config
		echo "all" | ${PERSONAL_POLICY_BIN} "genPoliciesConf" > /dev/null
		# Update memcached for usage limit
		usr_idx=1;
		usr_cnt=$(($NITEMS + 1));
		while [ "$usr_idx" != "$usr_cnt" ]
		do
			eval "org_name=\$ORIGIN_USER_NAME_$usr_idx"
			eval "new_name=\$USER_NAME_$usr_idx"
			UpdateUsageMemcached
			usr_idx=$(($usr_idx + 1));
		done
		;;
	*)
	echo "Usage: $0 --sdk-mod-ver|--name|--pkg-ver|--vendor|--pre|--post"
		;;
esac