Run script whenever a new domain is added?

dlogan

Verified User
Joined
Jan 4, 2007
Messages
18
Is there a way in DA to have a script executed whenever a domain is added? I'm running ASSP spam proxy which requires a file with a list of all the local domains. I have a script put together that can generate this file but would love a way to only execute this script whenever a domain is added (since thats the only time the file needs to be updated). Thanks.

Doug Logan
 
Is there a way in DA to have a script executed whenever a domain is added? I'm running ASSP spam proxy which requires a file with a list of all the local domains. I have a script put together that can generate this file but would love a way to only execute this script whenever a domain is added (since thats the only time the file needs to be updated). Thanks.

Doug Logan

Are you running ASSP on the same server as Direct Admin? I have been following ASSP very closely but have not implemented it.
 
Yes, I am. ASSP is great. The delaying feature alone cut down the spam I received by 80%. I still have the Bayesian filter in test mode and I receive very little spam. Once I get around to writing a script that will move spam messages to the appropriate spam folders I'll likely take the Bayesian test out of spam mode. In the meantime I have it flagging the subject of the messages with [SPAM] to make it easy to identify.

The perl script I wrote for updating the local domain files is really simple, but I'd be happy to provide it to you if you would find that helpful.
 
Yes, I would very much like the perl script.

Questions.

1. Do you have ASSP listening on port 25 and Exim listening on a different port?

2. Do you have any issues with SMTP authentication?

I tend to suffer from paralysis by analysis from time to time.
 
Per the above instructions I have the script named domain_create_post.sh, and one called domain_destroy_post.sh and located in /usr/local/directadmin/scripts/custom/ (the 2nd script is just a link of the first, they are both the same thing)

Below is the contents of my actual script
#!/usr/bin/perl
sub AutoLocalDomains{
opendir(DIR, "/var/spool/virtual") || print 'Could Not Open Directory';
$i = 0;
while ($name = readdir(DIR)) {
if($name ne '.' && $name ne '..'){
$domains[$i] = $name;
$i++;
}
}
return join("\n", @domains);
closedir(DIR);
}

open(OUTPUT,">/usr/local/assp/localdomains.txt") || print "Could Not Open";
print OUTPUT &AutoLocalDomains();
close(OUTPUT);

In assp.cfg I then have localDomains:=file:/usr/local/assp/localdomains.txt which has ASSP reference that file that is created.

Basically all the script does is get a directory listing of /var/spool/virtual/, which by default has a folder for every domain created on the server. Since the script is run after a domain is created, or after a domain is destroyed, the folders in /var/spool/virtual have already been created/removed. As a result the listing creates the appropriate file.

On my server I have modified exim to listen to port 125. I then have ASSP configured to listen on port 25, and relay it to the mail server on port 125. I did not have to do anything to have SMTP authentication work properly. I simply told my e-mail client to connect to port 25 and use SMTP authentication. It works great.

FYI, for some reason the GUI client for ASSP does not work right on my server. In posting on their forums a few others expressed difficulties with RHEL/CentOS with the same thing (basically the config file never updates). As a result I edited the config file manually with nano to change the settings. I kept a copy of the web client open so I knew what each line did, and I could search for the appropriate field to edit.

I hope this helps!

Thanks.

Doug Logan
 
In assp.cfg I then have localDomains:=file:/usr/local/assp/localdomains.txt which has ASSP reference that file that is created.

Basically all the script does is get a directory listing of /var/spool/virtual/, which by default has a folder for every domain created on the server. Since the script is run after a domain is created, or after a domain is destroyed, the folders in /var/spool/virtual have already been created/removed. As a result the listing creates the appropriate file.

Why don't you just configure localDomains to use /etc/virtual/domains file? :)
 
LOL, well if I knew that file existed I just might have! Thats too funny. Originally I googled it to see if such a file existed but I couldn't find one, so I made my own. I guess this is what happens when you're self trained in all things linux. Thanks for giving me that tip!
 
LOL, well if I knew that file existed I just might have! Thats too funny. Originally I googled it to see if such a file existed but I couldn't find one, so I made my own. I guess this is what happens when you're self trained in all things linux. Thanks for giving me that tip!

You are welcome :)
btw, there was no need to google, you could check exim config file /etc/exim.conf to find the answer.
 
The delaying feature alone cut down the spam I received by 80%.
By delaying feature do you mean greylisting? Greylisting will be included (as an option) in the final release of the SpamBlocker3 exim.conf file.

Jeff
 
Basically all the script does is get a directory listing of /var/spool/virtual/, which by default

/var/spool/virtual/ on a DA box? Where is that directory? I dont see such directory on any of my DA boxes.

Besides, there is more to getting the email addresses than just reading a directory. What about forwarders and users who have not setup any email addresses? Howabout catch-alls? Those also need to be retrieved.
 
/var/spool/virtual/ on a DA box? Where is that directory? I dont see such directory on any of my DA boxes.

Its on all of mine. FC and CentOS. Maybe you have another OS and DA stores it some place else.
 
tx1000# cd /var/spool/virtual
/var/spool/virtual: No such file or directory.
tx1000#

/etc/virtual would be more appropriate to read.
 
Last edited:
/var/spool/virtual contains all the domains, at least the ones with virtual email addresses. That is where the email is stored.
 
/var/spool/virtual contains all the domains, at least the ones with virtual email addresses. That is where the email is stored.
On your system, true, because you're using mbox, and not Maildir. There's no /var/spool/virtual directory once you've converted to Maildir and removed the old email.

Jeff
 
Because thats not enough to determine local users.

To help you understand the issue involved, I would like to clarify the following:
1. localDomains setting is used to advise ASSP on the complete list of local domains, as the name suggests, it has nothing to do with local users.
2. The configuration I suggested was actually tested and deployed on a number of servers. If you've made your statement without taking the time to actually test this, that's OK :) If you tried to use localDomains as suggested above and it didn't work for you, you might want to make sure your server is properly configured. If you need help figuring this out - do not forget to provide detailed diagnostic next time you ask for help.
 
Back
Top