Exim redeliver / reinject mails

 perl redeliver.pl MAILBOX
Where MAILBOX is the mailbox file
my $file = shift || die "need file\n";
my $gto  = shift; # global to.  if present, override other per-email decision
my $msg  = '';
my $to   = '';
my $from = '';

open(I, "<$file") || die "Can't open $file\n";
while (<I>) {
  if (/^From /) {
    if ($msg) {
      if ($to && $from) {
        do_mail($from, $to, $msg);
      } else {
        print STDERR "have a message but no recips\n";
    } else {
      print STDERR "saw From w/ no message\n";
    $msg  = '';
    $from = '';
    $to   = '';
  } elsif (/^Return-path:\s*<(.*)>$/) {
    $from = $1;
  } elsif (/^Envelope-to:\s*(\S+)\s*$/) {
    $to = $1;
  } elsif (/^Delivery-date:\s*/) {
    ; # just ignore
  } else {
    $msg .= $_;

if ($msg && $to && $from) {
  do_mail($from, $to, $msg);

sub do_mail {
  my $f = shift;
  my $t = shift;
  my $m = shift;
  $t = $gto if ($gto);

  print "$f -> $t\n";
  #print "MAIL FROM:<$f>\nRCPT TO:<$t>\nDATA\n$m\n.\n";
  open(P, "|/usr/lib/sendmail -f $f $t") || warn "can't open sendmail: $!\n";
  print P $m, "\n.\n";


BIND DNS Web Interface

Working on a web interface for BIND DNS with major inspiration from probinder, here are some preliminary screenshots:

Zone record view

Record edit

Generate and push zone files

This is still in development and very alpha quality, will post some more as I add things.

Exim stop all outgoing emails

A client wanted to ensure their scripts were sending out mails without the clients actually receiving the mails and having them redirected somewhere else.

You can do this with an exim filter:

1. Create /etc/cpanel_exim_system_filter_custom with the following content:

# Stop outgoing emails and redirect

if first_delivery
and (“$h_from:” contains “outgoing@domain.com”)
seen deliver “test@otherdomain.com”

Then in whm->Exim Configuration Editor->Filters

Change the filter to point to this new file.

Best Doughnut Recipe Ever!

This is my variation on a recipe I found online, bill style, these doughnuts are the best ones I ever made, they are light fluffy, sweet and taste just like shop bought doughnuts, easy and quick to make.


  • 6-7 Teaspoons of yeast
  • 1/4 cup lukewarm water
  • 1 & 1/2 cups of lukewarm milk (full fat)
  • 3/4 cup sugar
  • 2 eggs
  • 1/3 cup shortening (lard) – I couldn’t get hold of lard which is basically pig fat, but you can get it from a polish shop, its called smalec and has pictures of pigs on the wrapper.
  • 4 cups plain white flour
  • 1 cup cornflour
  • 1 teaspoon salt


Put water in bowl, add in yeast and 1 tablespoon sugar – leave for 10 minutes until frothy.

In another bowl mix:

Milk, sugar, salt, eggs, shortening and 2 cups of the plain flour

After 5 minutes add in the remaining ingredients and mix thoroughly:

2 cups of plain flour, 1 cup of cornflour and the yeast mixture

Leave for 1 hour – it should grow substantially, I use a glass bowl so I can see the side of the dough as its growing, you want lots of bubbles.

Dust surface with flour and roll out dough, cut into doughnut shapes

Leave cut out doughnuts for another 30 minutes

Fry at 175 Degrees C (use a fat fryer as its much easier than a pan and you get the best results), about a minute each side until golden brown on both sides.

Dip in the glaze and allow to cool.


  • 1/3 Cup butter
  • 2 cups icing sugar
  • 1 & 1/2 teaspoons of vanilla essence
  • 4-6 tablesppons of hot water.

Easy – add everything together except the water and mix thouroughly.

Add water 1 teaspoon at a time to get the right consistency (not too runny)

Plesk useful password related tips

Useful things to add to your aliases file to retrieve plesk passwords:

if [ $# -eq 1 ]; then
MYSQLPWD=`cat /etc/psa/.psa.shadow`
#query mysql db for domain name
QUERY="SELECT CONCAT_WS('@',mail.mail_name,domains.name),accounts.password FROM domains,mail,accounts WHERE domains.id=mail.dom_id AND accounts.id=mail.account_id AND domains.name = '$DOMAIN';";
mysql -B -uadmin -p`echo $MYSQLPWD` -D psa -e"$QUERY";
echo "Function mailpwd requires 1 argument - a domain name"

if [ $# -eq 1 ]; then
MYSQLPWD=`cat /etc/psa/.psa.shadow`
#query mysql db for domain name
QUERY="SELECT REPLACE(sys_users.home,'/home/httpd/vhosts/','') AS domain, sys_users.login,accounts.password FROM sys_users LEFT JOIN accounts on sys_users.account_id=accounts.id WHERE sys_users.home = '$DOMAIN';";
mysql -B -uadmin -p`echo $MYSQLPWD` -D psa -e"$QUERY";
echo "Function ftppwd requires 1 argument - a domain name"

if [ $# -eq 1 ]; then
MYSQLPWD=`cat /etc/psa/.psa.shadow`
#query mysql db for domain name
QUERY="SELECT domains.name AS domain_name,data_bases.name AS database_name, db_users.login, accounts.password FROM data_bases, db_users, domains, accounts WHERE data_bases.dom_id = domains.id AND db_users.db_id = data_bases.id AND db_users.account_id = accounts.id AND domains.name = '$DOMAIN';";
mysql -B -uadmin -p`echo $MYSQLPWD` -D psa -e"$QUERY";
echo "Function dbpwd requires 1 argument - a domain name"

alias qstat='/var/qmail/bin/qmail-qstat'
alias qread='/var/qmail/bin/qmail-qread | less'

From a shell script usage is as follows:

mailpwd domainname.com – This will get you all the usernames & passwords for all the mail accounts under a domain.

ftppwd domainname.com – This will get you all the ftp usernames & passwords for all the ftp accounts under a domain.

dbpwd domainname.com – This will get you all the database usernames & passwords for all the db accounts under a domain.

Hope its useful.

WHMCS and opensrs API

We use WHMCS at work, its a fantastic piece of software and comes with lots of built in modules for integrating with various registrars, normally you only need your reseller username and password to enable integration with a registrar from WHMCS but in the case of opensrs things are a little different, every domain name has its own username and password rendering the opensrs module in whmcs useless for entering in legacy domains – its great for new domains but for entering old ones no integration is possible with the whmcs opensrs module.

If you are an opensrs reseller you can request from them the ability to view each domains username and password in the opensrs admin control panel (you have to sign an additional agreement).

I have written a module which integrates with opensrs for existing domains – you have to put the domain username and password in the subscription field in whmcs (I do not use this field).

The following actions are supported:

  • Get / save Nameservers
  • Get / save Registrar lock
  • Get / save Contact details
  • Get EPP Code
  • Renew

Features not supported:

  • Register – you should use the normal opensrs module for new domains
  • All the DNS / Email Forwarding functionality
  • Transfer

Download the existing opensrs module

I accept no responsibility for any damanage caused by this module, as with everything – BACKUP FIRST!