Usermin Command Line, Remote API

10 posts / 0 new
Last post
#1 Fri, 05/16/2008 - 06:07
joeles

Usermin Command Line, Remote API

I couldn't find any info anywhere on this so please excuse me if it's discussed elsewhere. Is there a command line or remote API for Usermin functions? I particularly interested in reporting and deleting spam.

Sun, 06/07/2009 - 07:22
Joe
Joe's picture

Howdy joeles,

I'm afraid not. Usermin has the least API support of any of the tools in the chain. It'd be possible to write a script to use the various functions in the mailbox module--but you'd have to know a bit of perl and set things up the old-fashioned way (takes about ten lines of boiler plate to setup a Webmin/Usermin execution environment, and then you can use web-lib.pl functions to load up and access the rest of the API normally). I'll try to get Webmin:API (which removes the boiler plate and replaces it with "use Webmin::API") ported to Usermin sometime in the next couple of weeks--if I forget, please remind me on this thread. ;-)

But, the two functions you're after <i>are</i> accessible via the command line...though I'll need to do a bit of digging to figure out exactly how to do the first without too much headache. Usermin, when reporting spam, uses two tools (both are optional and configurable): sa-learn (or spamassassin -r) and razor, but the process of picking out the right message and training on the one message without removing all prior training is not immediately obvious to me.

If you're using Maildir format files, deleting spam could be done very easily using standard command line tools. Assuming you're dumping spam into a specific spam folder, you could do something like:

find /home/domain/homes/joe/Maildir/.spam/cur -mtime +5 -exec rm {} \;

Which will remove files older than 5 days old in the spam folder of user joe in the &quot;domain&quot; virtual server. Deleting a single specific spam is a bit more problematic, since picking it out of the list (probably very long) will be difficult unless you have the unique message ID.

If you're using mbox (why!?), I'm not sure off-hand how to do this. Probably putting the Usermin mailbox library to work would be the best bet.

--

Check out the forum guidelines!

Sun, 06/07/2009 - 07:28
Joe
Joe's picture

Howdy joeles,

I'm afraid not. Usermin has the least API support of any of the tools in the chain. It'd be possible to write a script to use the various functions in the mailbox module--but you'd have to know a bit of perl and set things up the old-fashioned way (takes about ten lines of boiler plate to setup a Webmin/Usermin execution environment, and then you can use web-lib.pl functions to load up and access the rest of the API normally). I'll try to get Webmin:API (which removes the boiler plate and replaces it with &quot;use Webmin::API&quot;) ported to Usermin sometime in the next couple of weeks--if I forget, please remind me on this thread. ;-)

But, the two functions you're after <i>are</i> accessible via the command line...though I'll need to do a bit of digging to figure out exactly how to do the first without too much headache. Usermin, when reporting spam, uses two tools (both are optional and configurable): sa-learn (or spamassassin -r) and razor, but the process of picking out the right message and training on the one message without removing all prior training is not immediately obvious to me.

If you're using Maildir format files, deleting spam could be done very easily using standard command line tools. Assuming you're dumping spam into a specific spam folder, you could do something like:

find /home/domain/homes/joe/Maildir/.spam/cur -mtime +5 -exec rm {} \;

Which will remove files older than 5 days old in the spam folder of user joe in the &quot;domain&quot; virtual server. Deleting a single specific spam is a bit more problematic, since picking it out of the list (probably very long) will be difficult unless you have the unique message ID.

If you're using mbox (why!?), I'm not sure off-hand how to do this. Probably putting the Usermin mailbox library to work would be the best bet.

--

Check out the forum guidelines!

Sun, 06/07/2009 - 07:28
joeles

Joe,
I wanted to give this thread a bump to see if you've had time to implement the Webmin::API for Usermin. I still want to nail tackle the spam/ham reporting/deleting, but I thought I would cut my teeth on some other functions first.

I provide a control panel for my clients to manage their web content and would like to either fold common email account settings into it or create a plugin for RoundCube to manage them. There are already API calls for changing passwords and managing aliases, but I'd also like to have the following:

1. Deliver locally, foward to address
2. Auto-reply
3. Maximum spam score, whitelisting, blacklisting

I did some poking around and I think I found all the files I would need to modify to perform the above functions, but I'd like to get your confirmation that I'm modifying the correct stuff.

1. Deliver locally, foward to address
~/.forward
\user-domain.com ## deliver locally
email@domain.com ## forward to
&quot;|/etc/usermin/forward/autoreply.pl /home/domain.com/homes/user/autoreply.txt user@domain.com&quot;

2. Auto Reply
~/autoreply.txt
Reply-Tracking: /home/domain.com/homes/user/.usermin/forward/replies
Reply-Period: 660 ## seconds between replies
From: email@domain.com ## reply from
Message ## message

3. Maximum spam score, whitelisting, blacklisting
~/.spamassassin/user_prefs
required_score 5 ## maximum allowed spam score
whitelist_from email@domain.com ## one line for each whitelisted address
blacklist_from email@domain.com ## one line for each blacklisted address

I have Virtualmin Pro running CentOS 5.2, Dovecot, Postfix, Spamassassin as spamc. Usernames are configured as the full email address.

Thanks for the help.

Wed, 09/17/2008 - 12:00
joeles

Joe, could I get your feedback on this?

Sun, 06/07/2009 - 07:29
Joe
Joe's picture

Howdy joeles,

I'm afraid not. Usermin has the least API support of any of the tools in the chain. It'd be possible to write a script to use the various functions in the mailbox module--but you'd have to know a bit of perl and set things up the old-fashioned way (takes about ten lines of boiler plate to setup a Webmin/Usermin execution environment, and then you can use web-lib.pl functions to load up and access the rest of the API normally). I'll try to get Webmin:API (which removes the boiler plate and replaces it with &quot;use Webmin::API&quot;) ported to Usermin sometime in the next couple of weeks--if I forget, please remind me on this thread. ;-)

But, the two functions you're after <i>are</i> accessible via the command line...though I'll need to do a bit of digging to figure out exactly how to do the first without too much headache. Usermin, when reporting spam, uses two tools (both are optional and configurable): sa-learn (or spamassassin -r) and razor, but the process of picking out the right message and training on the one message without removing all prior training is not immediately obvious to me.

If you're using Maildir format files, deleting spam could be done very easily using standard command line tools. Assuming you're dumping spam into a specific spam folder, you could do something like:

find /home/domain/homes/joe/Maildir/.spam/cur -mtime +5 -exec rm {} \;

Which will remove files older than 5 days old in the spam folder of user joe in the &quot;domain&quot; virtual server. Deleting a single specific spam is a bit more problematic, since picking it out of the list (probably very long) will be difficult unless you have the unique message ID.

If you're using mbox (why!?), I'm not sure off-hand how to do this. Probably putting the Usermin mailbox library to work would be the best bet.

--

Check out the forum guidelines!

Sun, 06/07/2009 - 07:29
joeles

Joe,
I wanted to give this thread a bump to see if you've had time to implement the Webmin::API for Usermin. I still want to nail tackle the spam/ham reporting/deleting, but I thought I would cut my teeth on some other functions first.

I provide a control panel for my clients to manage their web content and would like to either fold common email account settings into it or create a plugin for RoundCube to manage them. There are already API calls for changing passwords and managing aliases, but I'd also like to have the following:

1. Deliver locally, foward to address
2. Auto-reply
3. Maximum spam score, whitelisting, blacklisting

I did some poking around and I think I found all the files I would need to modify to perform the above functions, but I'd like to get your confirmation that I'm modifying the correct stuff.

1. Deliver locally, foward to address
~/.forward
\user-domain.com ## deliver locally
email@domain.com ## forward to
&quot;|/etc/usermin/forward/autoreply.pl /home/domain.com/homes/user/autoreply.txt user@domain.com&quot;

2. Auto Reply
~/autoreply.txt
Reply-Tracking: /home/domain.com/homes/user/.usermin/forward/replies
Reply-Period: 660 ## seconds between replies
From: email@domain.com ## reply from
Message ## message

3. Maximum spam score, whitelisting, blacklisting
~/.spamassassin/user_prefs
required_score 5 ## maximum allowed spam score
whitelist_from email@domain.com ## one line for each whitelisted address
blacklist_from email@domain.com ## one line for each blacklisted address

I have Virtualmin Pro running CentOS 5.2, Dovecot, Postfix, Spamassassin as spamc. Usernames are configured as the full email address.

Thanks for the help.

Wed, 09/17/2008 - 14:25
Joe
Joe's picture

<div class='quote'>but I'd also like to have the following:

1. Deliver locally, foward to address
2. Auto-reply
3. Maximum spam score, whitelisting, blacklisting</div>

All of these are already available in the Virtualmin API--you don't need Usermin for them (as long as you make sure you're careful how you call it, as it runs as root, and so would be ripe for abuse if not used with care), and you don't have to dig into the individual config files.

For example:

virtualmin modify-spam --domain virtualmin.com --spamclear-days 15 --spam-whitelist

Enables removal of spam after 15 days and uses the auto-white/black list feature of SpamAssassin.

Manual training with specific messages is only available via Usermin, and would need some code written (even with API calls--it's a pretty wide-reaching bit of functionality with no single API call to handle reporting).

Spam score...for some reason doesn't seem to be available in that command. I'll have to look into it a little.

--

Check out the forum guidelines!

Fri, 01/06/2012 - 10:23
nick108

Joeles,

I'd also be very much interested in integrating auto-reply into Roundcube.

Have you been able to figure this out in the end?

Nick

Fri, 01/06/2012 - 11:42
nick108

Just found an existing solution for Roundcube auto-reply

http://sourceforge.net/projects/rcubevacation/

Not integrated with VM, but better than nothing ;-)

Topic locked