Postfixadmin

Pre Installation

If for no other reason that to make sure that your DBMS is working as it should, prior to installing postfixadmin you are advised to manually create the database and user that it will use in postgresql. First you need to su to the postgres user and create a postgresql user that postfixadmin can use to access the database. To do this on a local database server run

#createuser postfixadmin -U postgres -DRSP

and enter a password when prompted. (if you want to generate random reasonably simple passwords then you can install apg and run it from the command line)

Now you can go ahead and create a database called postfix with the owner being the postfixadmin user that we created in the previous step

#createdb postfixadmin -O postfixadmin -U postgres

The way that the system works is that postfixadmin provides a way to insert and update data into the postgresql database, postfix reads and uses that data but never actually alters it itself. For this reason and for added security we can create a second user with read only privileges that can be used by postfix. We will call that user postfixro.

#createuser postfixro -U postgres -DRSP

If you now set the privileges using psql then when the tables are created later they should automatically have default roles assigned to them.

#psql -U postgres -d postfixadmin

postfix# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO postfixro;
postfix# \q

If you forget this step or for any reason the databse is already populated then you will have to run

GRANT SELECT ON ALL TABLES IN SCHEMA public TO postfixro;

 

Installation

You should now be able to go ahead and install postfixadmin

#apt-get install postfixadmin

You will be presented with a wizard that will ask you what DBMS you are using as well as the name of the database, the user and the password. As you have already created the database and user, when asked if you would like to configure the database select “no

Once postfixadmin is installed you should have 2 files in /etc/postfixadmin/. These are:

config.inc.php

and;

dbconfig.inc.php

 

Configuration

config.inc.php handles the connection to the database and should look something like

$dbuser='postfixadmin';
$dbpass='changeme';
$basepath='';
$dbname='postfix';
$dbserver='';
$dbport='';
$dbtype='pgsql';

If you are connecting to a remote server then dbserver will need to be set, and if you are using a port other than 5432 then dbport will also have to be set.

Before continuing you need to make a few changes to config.inc.php. These are

$CONF['configured'] = true;
$CONF['admin_email'] = 'postmaster@domain.net'; $CONF['smtp_server'] = 'fqdn.suffix';
$CONF['smtp_port'] = '25';

these will result in a maildir path like /home/mailstore/fqdn.suffix/user

$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';

Now save the file and from a browser navigate to

https://fqdn.suffix/postfixadmin/setup.php

where you should be presented with a configuration screen that should inform you that the database structure has been created. If there are any issues then this page should tell you what then are.

Connectivity issues can be caused by a number of things but you may want to start by checking the following:

php5-pgsql is installed (see the Apache2 section)

the credentials in config.inc.php are correct

pg_hba.conf is configured correctly to allow your postfixadmin user to log on from the server – try to logon using psql to test this

        • psql –U postfixadmin –d postfix

and see what happens

If all is well then scroll to the bottom of the screen where you should see a prompt to change setup password. Now type in your desired password, click the button and you should be presented with a long string which is a hash of your password along with some instructions. DO NOT CLOSE THE WINDOW.

if you reopen /etc/postfixadmin/config.inc.php and navigate to $CONF[‘setup_password’] = ‘changeme’ you can now replace “changeme” with the password hash

Once you have saved the file, you can create a superadmin by typing in the password that you have just created and the desired details of the superadmin and then you can create mailboxes and domains as per your needs.

It is probably a good idea to add a domain and at least one mailbox at this stage, just don’t forget your MX records.

NOTE THAT WHILE IT IS PERFECTLY SAFE TO ADD MAILBOXES, YOU WILL NOT BE ABLE TO CONNECT YOUR CLIENTS YET.

 

Optional

You might want to change the default message that you send to new users. This is done in /etc/postfixadmin/config.inc.php under the $CONF[‘welcome_text’] directive. The text of the message must be placed inbetween “<<<EOM” and “EOM” and respects ordinary character returns <enter key> as line breaks.

I find it helpful to tell new users where they can go to manage their account; something like:

Hi,

Welcome to your new account. To change your password or manage your account please visit https://fqdn.suffix/postfixadmin/users and log in using your email address and current mailbox password.

But you can use any text you like.

 

BUG ALERT

There is a bug in v2.3.7 of postfix admin where you cannot update a password without getting an error message. To resolve this edit /usr/share/postfixadmin/edit-mailbox.php. go to line 165 and put single quotation marks around ‘$sqlActive’ so that the line reads:

$result = db_query ("UPDATE $table_alias SET active='$sqlActive' WHERE address='$fUsername' AND domain='$fDomain'");

instead of

$result = db_query ("UPDATE $table_alias SET active=$sqlActive WHERE address='$fUsername' AND domain='$fDomain'");

THIS HAS BEEN RESOLVED IN LATER VERSIONS IN FACT THE WHOLE FILE HAS NOW GONE

 

BUG ALERT 2 (DEBIAN BUSTER)

When you navigate to setup.php you may see a message that states that either the templates_c directory does not exist or is not writeable by the webserver.  The message is fairly self explanatory, you need to create a directory /usr/share/postfixadmin/templates_c and allow the webserver to write to it

chown www-data:www-data /usr/share/postfixadmin/templates_c