Panormitis
Verified User
- Joined
- Sep 13, 2014
- Messages
- 37
Hello,
I have created a forwarder_create_pre.sh script in /usr/local/directadmin/scripts/custom because I want to disallow creation of forwarders to external e-mail addresses (such as [email protected]). The user is only allowed to forward e-mails to its own domain names.
The script works, but I'm not satisfied with the error message produced:
In case anyone wants to use the script, feel free, here is the code:
I have created a forwarder_create_pre.sh script in /usr/local/directadmin/scripts/custom because I want to disallow creation of forwarders to external e-mail addresses (such as [email protected]). The user is only allowed to forward e-mails to its own domain names.
The script works, but I'm not satisfied with the error message produced:
If there a way to remove "Script output: /usr/local/directadmin/scripts/custom/forwarder_create_pre.sh" from the error message?Error creating forwarder
Script output: /usr/local/directadmin/scripts/custom/forwarder_create_pre.sh
Forwarders to external e-mail addresses are not allowed!
In case anyone wants to use the script, feel free, here is the code:
Code:
#!/bin/bash
# Regex for e-mail validation:
email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
# Split $value by commas and check each part:
IFS=',' read -ra addresses <<< "$value"
for email_address in "${addresses[@]}"; do
# Trim whitespace (just in case):
email_address=$(echo "$email_address" | xargs)
# Check if it's a valid e-mail address:
if [[ $email_address =~ $email_regex ]]; then
# Extract domain name:
domain_name="${email_address##*@}"
# Check if domain_name exists in domains.list:
if ! grep -Fxq "$domain_name" /usr/local/directadmin/data/users/"$username"/domains.list; then
echo "Forwarders to external e-mail addresses are not allowed!"
exit 1
fi
fi
done
# If all checks passed, allow the forwarder.
exit 0