{"id":135,"date":"2019-06-02T18:23:01","date_gmt":"2019-06-02T17:23:01","guid":{"rendered":"https:\/\/blog.inplico.uk\/?p=135"},"modified":"2022-10-29T10:08:35","modified_gmt":"2022-10-29T09:08:35","slug":"postfixadmin","status":"publish","type":"post","link":"https:\/\/blog.inplico.uk\/?p=135","title":{"rendered":"Postfixadmin"},"content":{"rendered":"<p><strong>Pre Installation<\/strong><\/p>\n<p>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<\/p>\n<pre class=\"lang:sh decode:true\">#createuser postfixadmin -U postgres -DRSP<\/pre>\n<p>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)<\/p>\n<p>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<\/p>\n<pre class=\"lang:sh decode:true\">#createdb postfixadmin -O postfixadmin -U postgres<\/pre>\n<p>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.<\/p>\n<pre class=\"lang:sh decode:true\">#createuser postfixro -U postgres -DRSP<\/pre>\n<p>If you now set the privileges using psql then when the tables are created later they should automatically have default roles assigned to them.<\/p>\n<pre class=\"lang:sh decode:true\">#psql -U postgres -d postfixadmin\r\n\r\npostfix# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO postfixro;\r\npostfix# \\q<\/pre>\n<p>If you forget this step or for any reason the databse is already populated then you will have to run<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">GRANT SELECT ON ALL TABLES IN SCHEMA public TO postfixro;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Installation<\/strong><\/p>\n<p>You should now be able to go ahead and install postfixadmin<\/p>\n<pre class=\"lang:sh decode:true\">#apt-get install postfixadmin<\/pre>\n<p>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 \u201c<strong>no<\/strong>\u201d<\/p>\n<p>Once postfixadmin is installed you should have 2 files in \/etc\/postfixadmin\/. These are:<\/p>\n<p style=\"padding-left: 40px;\"><strong>config.inc.php<\/strong><\/p>\n<p style=\"padding-left: 40px;\">and;<\/p>\n<p style=\"padding-left: 40px;\"><strong>dbconfig.inc.php<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Configuration<\/strong><\/p>\n<p>config.inc.php handles the connection to the database and should look something like<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">$dbuser='postfixadmin';\r\n$dbpass='changeme';\r\n$basepath='';\r\n$dbname='postfix';\r\n$dbserver='';\r\n$dbport='';\r\n$dbtype='pgsql';<\/pre>\n<p>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.<\/p>\n<p>Before continuing you need to make a few changes to config.inc.php. These are<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">$CONF['configured'] = true;\r\n$CONF['admin_email'] = 'postmaster@domain.net'; $CONF['smtp_server'] = 'fqdn.suffix';\r\n$CONF['smtp_port'] = '25';<\/pre>\n<p>these will result in a maildir path like \/home\/mailstore\/fqdn.suffix\/user<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">$CONF['domain_path'] = 'YES';\r\n$CONF['domain_in_mailbox'] = 'NO';<\/pre>\n<p>Now save the file and from a browser navigate to<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">https:\/\/fqdn.suffix\/postfixadmin\/setup.php<\/pre>\n<p>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.<\/p>\n<p>Connectivity issues can be caused by a number of things but you may want to start by checking the following:<\/p>\n<p style=\"padding-left: 40px;\"><strong>php5-pgsql is installed<\/strong> (see the Apache2 section)<\/p>\n<p style=\"padding-left: 40px;\"><strong>the credentials in config.inc.php are correct<\/strong><\/p>\n<p style=\"padding-left: 40px;\"><strong>pg_hba.conf is configured correctly<\/strong> to allow your postfixadmin user to log on from the server \u2013 try to logon using psql to test this<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li class=\"lang:sh highlight:0 decode:true \">\n<pre class=\"lang:sh highlight:0 decode:true\">psql \u2013U postfixadmin \u2013d postfix<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">and see what happens<\/p>\n<p>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.<\/p>\n<p>if you reopen <strong>\/etc\/postfixadmin\/config.inc.php<\/strong> and navigate to $CONF[&#8216;setup_password&#8217;] = &#8216;changeme&#8217; you can now replace \u201cchangeme\u201d with the password hash<\/p>\n<p>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.<\/p>\n<p>It is probably a good idea to add a domain and at least one mailbox at this stage, just don\u2019t forget your MX records.<\/p>\n<p>NOTE THAT WHILE IT IS PERFECTLY SAFE TO ADD MAILBOXES, YOU WILL NOT BE ABLE TO CONNECT YOUR CLIENTS YET.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Optional<\/strong><\/p>\n<p>You might want to change the default message that you send to new users. This is done in <strong>\/etc\/postfixadmin\/config.inc.php<\/strong> under the $CONF[&#8216;welcome_text&#8217;] directive. The text of the message must be placed inbetween \u201c&lt;&lt;&lt;EOM\u201d and \u201cEOM\u201d and respects ordinary character returns &lt;enter key&gt; as line breaks.<\/p>\n<p>I find it helpful to tell new users where they can go to manage their account; something like:<\/p>\n<blockquote>\n<p style=\"padding-left: 40px;\">Hi,<\/p>\n<p style=\"padding-left: 40px;\">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.<\/p>\n<\/blockquote>\n<p>But you can use any text you like.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>BUG ALERT <\/strong><\/p>\n<p>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 &#8216;$sqlActive&#8217; so that the line reads:<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">$result = db_query (\"UPDATE $table_alias SET active='$sqlActive' WHERE address='$fUsername' AND domain='$fDomain'\");<\/pre>\n<p>instead of<\/p>\n<pre class=\"lang:sh highlight:0 decode:true\">$result = db_query (\"UPDATE $table_alias SET active=$sqlActive WHERE address='$fUsername' AND domain='$fDomain'\");<\/pre>\n<p>THIS HAS BEEN RESOLVED IN LATER VERSIONS IN FACT THE WHOLE FILE HAS NOW GONE<\/p>\n<p>&nbsp;<\/p>\n<p><strong>BUG ALERT 2 (DEBIAN BUSTER)<\/strong><\/p>\n<p>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.\u00a0 The message is fairly self explanatory, you need to create a directory <strong>\/usr\/share\/postfixadmin\/templates_c<\/strong> and allow the webserver to write to it<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">chown www-data:www-data \/usr\/share\/postfixadmin\/templates_c<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-debian-server"],"_links":{"self":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":5,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":203,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions\/203"}],"wp:attachment":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}