Script to control SMTP access for users

ak17_hk

Verified User
Joined
Nov 7, 2006
Messages
68
Hi All,

I found that many people asking for scripts of plugins to control (enable/disable) remote SMTP access for users while allowing them to use webmail properly, and I'm one of those people. However, there doesn't seem to have such scripts or plugins around, or even there is, they don't work well from my experience (and also from other people's comments).

Luckily, I found a way to add some codes to exim.pl to achieve this, which I learnt from this forum (if I remember correctly) long long time ago but still works when I applied it on the latest version of exim.pl for my new server! :)

Just clarify, I'm not the one who wrote these codes, but I'm just sharing it to all of you in case you find it useful. Here we go..

(1) First, create the file “/etc/virtual/smtp_domains” to store your SMTP access list, just put those users you would like to allow SMTP access in it line by line, just like below:

domain1.com: username1
domain2.com: username2

(2) Then, backup and modify “/etc/exim.pl” file as follows:

i) INSERT:
Code:
	my $smtpallowed=0;
	open(SMTPDOMAINOWNERS,"/etc/virtual/smtp_domains");
	while (<SMTPDOMAINOWNERS>)
	{
		$_ =~ s/\n//;
		my ($dmn,$usr) = split(/: /, $_);
		if ($usr eq $username)
		{
			$smtpallowed=1;
		}
	}
	close(SMTPDOMAINOWNERS);
	if ((!$smtpallowed) && ($username ne "root") && ($username ne "diradmin")) { return "no"; }

AFTER:
Code:
	if ($unixuser == 1)
	{
		#the username passed doesn't have a domain, so its a system account
		$homepath = (getpwnam($username))[7];
		if ($homepath eq "") { return 0; }
		open(PASSFILE, "< $homepath/.shadow") || return "no";
		$crypted_pass = <PASSFILE>;
		close PASSFILE;

ii) INSERT:
Code:
	my $smtpallowed=0;
	open(SMTPDOMAINOWNERS,"/etc/virtual/smtp_domains");
	while (<SMTPDOMAINOWNERS>)
	{
		$_ =~ s/\n//;
		my ($dmn,$usr) = split(/: /, $_);
		if ($dmn eq $domain)
		{
			$smtpallowed=1;
		}
	}
	close(SMTPDOMAINOWNERS);
	if (!$smtpallowed) { return "no"; }

AFTER:
Code:
		if ($crypted_pass eq crypt($password, $crypted_pass)) { return "yes"; }
		else { return "no"; }
	}
	else
	{
		#the username contain a domain, which is now in $domain.
		#this is a pure virtual pop account.

(3) Restart exim, and it's done! :)

It's pretty easy and quick. If there's someone who is familiar with making DA plugins (not me though :P), he may just try to make one base on the above changes, and create an easy interface for DA admin to easily enable/disable SMTP access from within DA. I think it may not be too difficult.

I hope this post can help those in need for such needs!

Anthony.
 
Last edited:
asking for scripts of plugins to control (enable/disable) remote SMTP access for users while allowing them to use webmail properly

I do not understand the problem and why you would need to modify exim.pl.

Are you saying you would want to disable allowing clients to use their own computer to send email but allow them to use webmail?
 
I do not understand the problem and why you would need to modify exim.pl.

Are you saying you would want to disable allowing clients to use their own computer to send email but allow them to use webmail?

Yep, exactly! :)
 
I think that is an odd request and do not understand the logic of forcing a user to use webmail versus their own computer.
 
I think that is an odd request and do not understand the logic of forcing a user to use webmail versus their own computer.

It maybe odd for you but not odd for us in my country at all. All internet broadband service companies in my country do provide their own SMTP server for their customers to use, some even blocked port 25 except for their own SMTP server. This is to secure their network from spammers. Thus, we do not provide SMTP service by default to minimize spamming activities from our servers. However, we do provided paid port 587 SMTP service to clients upon request. :)

We do not force them to use webmail, they can either use Outlook with SMTP server provided by their Broadband companies, or use our webmail interface (but we lock their email address to the actual one).
 
Just so you know, spammers can also take advantage of webmail clients. I have seen it done and its not hard.
 
Just so you know, spammers can also take advantage of webmail clients. I have seen it done and its not hard.

Of course you can never completely get rid of them unless you stop running mail service, but just to do something to make it difficult for them is good enough.
 
You can make custom acl stanzas or additions to exim.pl.

Jeff

Hi Jeff,

I don't quite understand your suggestions, as I'm not familiar with it, can you please kindly elaborate more? Thanks! :)

Anthony.
 
Exim is controlled by the exim.conf file, which uses ACLs (access control lists) to determine how it manages email. Exim.pl is filter file, written in Perl, that can also be used to filter and/or manage email.

I've written several exim.conf files for DirectAdmin, including one maintained by DirectAdmin staff, and newer one, which call SpamBlocker-Powered exim.conf, Version 4, for DirectAdmin, which I maintain.

The exim.pl file is maintained by DirectAdmin staff.

You can either learn how to write and maintain these files yourself, or hire someone to write and maintain them for you, if you lack the expertise or desire to do so yourself, and if the standard ones don't fit your needs.

Jeff
 
Exim is controlled by the exim.conf file, which uses ACLs (access control lists) to determine how it manages email. Exim.pl is filter file, written in Perl, that can also be used to filter and/or manage email.

I've written several exim.conf files for DirectAdmin, including one maintained by DirectAdmin staff, and newer one, which call SpamBlocker-Powered exim.conf, Version 4, for DirectAdmin, which I maintain.

The exim.pl file is maintained by DirectAdmin staff.

You can either learn how to write and maintain these files yourself, or hire someone to write and maintain them for you, if you lack the expertise or desire to do so yourself, and if the standard ones don't fit your needs.

Jeff

Thanks Jeff for the explainations! :)
 
Back
Top