#!/bin/bash
#file should be created as /usr/local/directadmin/scripts/custom/user_modify_pre.sh
#chown diradmin:diradmin /usr/local/directadmin/scripts/custom/user_modify_pre.sh
#chmod 700 /usr/local/directadmin/scripts/custom/user_modify_pre.sh
#Create a login key on destination (mail) server with CMD_MODIFY_USER permissions
da_host='mx1.hitme.net.pl'
da_user='admin'
da_pass='R1g4W43e458H28ObOX1x747S61J57511lyDpfc7fRGXZfo1IX0UrhPP1tZ3apx29'


if [ "${action}" = "package" ]; then

	json_data=$(cat <<- EOF
	{
		"user":"${user}",
		"package":"${package}",
		"json":"yes",
		"action":"package"
	}
	EOF
	)

	response=$(curl -s --request "POST" --data "${json_data}" "https://${da_user}:${da_pass}@${da_host}:2222/CMD_MODIFY_USER?json=yes")
	if ! echo "${response}" | grep -q \"success\"; then
		echo "Problem with a package on ${da_host}:</br>"
		echo "${response}"
		exit 1
	fi

fi
