DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

A set of scripts for creating files for Exim sending messages with IP assigned to other users

| 00:15:26 12.03.2014

How to make Exim to send messages with IP assigned to other users is described here. And here in the article you can find some bash scripts for generating files with IP data automatically. Or you can use them with cron.

A script for creating /etc/virtual/domainips

#!/bin/bash#
# by Alex S Grebenschikov (support@poralix.com)
# v.0.1.2 2014-03-08
#


get_ip() {
    ip=`grep "^ip=" /usr/local/directadmin/data/users/$owner/domains/$domain.conf | cut -d\= -f2`
}


if [ -f "/etc/virtual/domainips" ]; then
    mv /etc/virtual/domainips /etc/virtual/domainips.bak`date +%Y%m%d`
fi;


touch /etc/virtual/domainips;


servername=`grep ^servername= /usr/local/directadmin/conf/directadmin.conf | cut -d\= -f2`


for domain in `cat /etc/virtual/domains | grep -v ^$servername$ | sort | uniq`;
do
    ip='';
    owner=`grep ^$domain: /etc/virtual/domainowners | cut -d\  -f2`


    if [ -f "/usr/local/directadmin/data/users/$owner/domains/$domain.conf" ]; then
        # REGULAR DOMAIN
        get_ip;
        echo "[D] Found domain $domain owned by $owner. IP=$ip";
        [ -z "$ip" ] || echo "$domain:$ip" >> /etc/virtual/domainips;
    else
        # POINTER
        pointer=$domain;
        if [ -d "/etc/virtual/$domain" ]; then
            domain=`ls -ld /etc/virtual/$domain | awk '{print $11}'`
        fi;
        get_ip;
        echo "[P] Found domain pointer $pointer to $domain owned by $owner. IP=$ip";
        [ -z "$ip" ] || echo "$pointer:$ip" >> /etc/virtual/domainips;
    fi;


done;


chmod 440 /etc/virtual/domainips;
chown mail:mail /etc/virtual/domainips;


exit;

A script for creating /etc/virtual/smtp_active_hostnames

The file /etc/virtual/helo_data is a link to /etc/virtual/smtp_active_hostnames

#!/bin/bash
#
# by Alex S Grebenschikov (support@poralix.com)
# v.0.1 2014-03-22
# Only IPv4 supported
#


save_to_file="/etc/virtual/smtp_active_hostnames";
servername=`grep ^servername= /usr/local/directadmin/conf/directadmin.conf | cut -d\= -f2`;

if [ -f "${save_to_file}" ]; then
    echo "Creating a backup copy of the file ${save_to_file}";
    mv ${save_to_file} ${save_to_file}.bak`date +%Y%m%d`;
fi;

touch ${save_to_file};

for IP in `cat /usr/local/directadmin/data/admin/ip.list | grep -v ^127.0.0.1$ | grep "\." | sort`;
do
{
    status='';
    owner='';
    hostname='';
    echo -n "[IP] Found ${IP}";
    if [ -f "/usr/local/directadmin/data/admin/ips/${IP}" ]; then
    {
        status=`grep ^status= /usr/local/directadmin/data/admin/ips/${IP} | cut -d\= -f2`;
        [ "${status}" != "owned" ] || owner=`grep ^value= /usr/local/directadmin/data/admin/ips/${IP} | cut -d\= -f2`;

        echo -n " with status=${status} ${owner}";
        hostname=${servername};

        if [ "${status}" == "owned" ]; then
        {
            homedir=`grep "^${owner}:" /etc/passwd | cut -d\: -f6`;
            if [ -d "${homedir}/public_html" ]; then
            {
                hostname="mail.`ls -dl ${homedir}/public_html | awk '{print $11}' | cut -d\/ -f3`";
            }
            fi;
        }
        fi;
        echo " hostname set to ${hostname}";

        echo "${IP}: ${hostname}" >> ${save_to_file};
    }
    fi;
}
done;

exit 0;

Posted here on Directadmin forums

Tags: Exim coding 
About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.




All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition