diff --git a/content/postfixadmin.md b/content/postfixadmin.md new file mode 100644 index 0000000..a66c0cc --- /dev/null +++ b/content/postfixadmin.md @@ -0,0 +1,150 @@ +Title: Postfix Admin +Date: 2016-03-06 +Category: Tutorial + +As I explained in [this previous tutorial](https://www.captainark.net/setting-up-a-mail-server.html), I've been running my own mail server without any issue for some time now. + +However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database. + +After a bit a googling, I've settled on [Postfix Admin](http://postfixadmin.sourceforge.net/). + +The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their [Github repo](https://github.com/postfixadmin/postfixadmin). + +I've also tried [ViMbAdmin](http://www.vimbadmin.net/), but it felt a little heavy considering what I was going to use it for. + +You'll need a web server with PHP support to run Postfix Admin. I personnaly run nginx with php5-fpm, but I won't explain how to configure it here. I'll simply explain how to migrate your current database to one managed with Postfix Admin with as little downtime as possible. + +# Creating a new database + +Since the database managed by Postfix Admin does not use the same schema as the one we've created in my previous tutorial, we'll have to create a new one. We will give all privileges on that database to the same user as before, `'mail'@'localhost'`. + +```sql +CREATE DATABASE mailnew; +GRANT SELECT ON mailnew.* TO 'mail'@'localhost'; +FLUSH PRIVILEGES; +``` + +At this point, you can clone the Postfix Admin project from Github and go through the installation process. + +While editing the config.inc.php file (or config.local.php file if you've decided to copy it), make sure that the `database_name` option is set to use the `mailnew` database we've just created. + +Also, make sure that the `encrypt` option is set to `dovecot:SHA512-CRYPT`. + +The installation process will create all the necessary tables in the database. + +**At this point, you'll have to recreate all domains, mailboxes and aliases that you have configured in your current mail database using the Postfix Admin interface.** + +# Postfix configuration + +Once you're done with Postfix Admin, it's time to configure Postfix to use its schema. + +First thing first, let's backup our current configuration : + +``` +mkdir /etc/postfix/mysql-backup +cp -a /etc/postfix/mysql-virtual* /etc/postfix/mysql-backup/ +``` + +Next, we have to edit the 3 files we've just backuped. The only line that actually changes is the one beginning with `query`. + +The first file is /etc/postfix/mysql-virtual-mailbox-domains.cf : + +``` +user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT 1 FROM domain WHERE domain='%s' AND active='1' +``` + +The second one is /etc/postfix/mysql-virtual-mailbox-maps.cf : + +``` +user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT 1 FROM mailbox WHERE username='%s' AND active='1' +``` + +And the last one is /etc/postfix/mysql-virtual-alias-maps.cf : + +``` +user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT goto FROM alias WHERE address='%s' AND active='1' +``` + +# Dovecot configuration + +Same as with Postfix, we now need to configure Dovecot to use the Postfix Admin schema. + +First, let's backup our current configuration : + +```bash +cp -a /etc/dovecot/sql.conf /etc/dovecot/sql.conf.bak +``` + +Next, we have to edit the /etc/dovecot/sql.conf file. The only line that changes is the one beginning with `password_query`. + +``` +driver = mysql +connect = host=localhost dbname=mail user=mail password=mailpassword +default_pass_scheme = SHA512-CRYPT +password_query = SELECT username as user, password FROM mailbox WHERE username='%u' AND active='1'; +``` + +# Migrating to the new schema + +We're done with the configuration part. Time to migrate to the new schema. + +First, let's create a backup of our current mail database : + +```bash +mysqldump mail | bzip2 > /home/user/mail.sql.bz2 +``` + +Next, in a SQL shell, we're going to drop and recreate the mail database : + +```sql +DROP DATABASE mail; +CREATE DATABASE mail; +``` + +We now have to dump the contents of the mailnew database into the newly created mail database : + +```bash +mysqldump mailnew | mysql mail +``` + +The last thing we have to do is to restart Postfix and Dovecot so that it starts using the new database schema : + +```bash +systemctl restart postfix +systemctl restart dovecot +``` + +At this point, Postfix and Dovecot are using the Postfix Admin schema in the mail database. + +The last thing we have to do is to edit Postfix Admin's config.inc.php file to use the mail database as well instead of the mailnew database that it should be currently using. + +# Cleanup + +Once you've confirmed that everything is working properly, you can delete the backup files we've created : + +```bash +rm -rf /etc/postfix/mysql-backup +rm /etc/dovecot/sql.conf.bak +``` + +You can drop the mailnew database as well : + +```sql +DROP DATABASE mailnew; +``` + +# Conclusion + +That's all ! As always, please do leave a comment if this article has been of any use to you ! \ No newline at end of file diff --git a/output/archives.html b/output/archives.html index c1624dd..8b31f77 100644 --- a/output/archives.html +++ b/output/archives.html @@ -88,6 +88,8 @@
+
Sun 06 March 2016
+
Postfix Admin
Tue 02 February 2016
My tmux configuration
Sun 31 January 2016
diff --git a/output/author/antoine-joubert.html b/output/author/antoine-joubert.html index e1fbab6..219192a 100644 --- a/output/author/antoine-joubert.html +++ b/output/author/antoine-joubert.html @@ -87,6 +87,18 @@
+
+ +

+ Postfix Admin +

+
+

As I explained in this previous tutorial, I've been running my ... +

+

There are comments.

diff --git a/output/authors.html b/output/authors.html index f0d5935..8798ba7 100644 --- a/output/authors.html +++ b/output/authors.html @@ -90,7 +90,7 @@

- Antoine Joubert (5) + Antoine Joubert (6)

diff --git a/output/category/tutorial.html b/output/category/tutorial.html index 7287edc..79f15ba 100644 --- a/output/category/tutorial.html +++ b/output/category/tutorial.html @@ -87,6 +87,18 @@
+
+ +

+ Postfix Admin +

+
+

As I explained in this previous tutorial, I've been running my ... +

+

There are comments.

diff --git a/output/index.html b/output/index.html index 45e91b4..aa10d6d 100644 --- a/output/index.html +++ b/output/index.html @@ -90,6 +90,18 @@
+
+ +

+ Postfix Admin +

+
+

As I explained in this previous tutorial, I've been running my ... +

+

There are comments.

diff --git a/output/postfix-admin.html b/output/postfix-admin.html new file mode 100644 index 0000000..cb56d0c --- /dev/null +++ b/output/postfix-admin.html @@ -0,0 +1,345 @@ + + + + + + + + + + + + Postfix Admin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Postfix Admin

+ Posted by + Antoine Joubert + on Sun 06 March 2016 + + +
+
+
+
+
+ + +
+
+
+ +
+

As I explained in this previous tutorial, I've been running my own mail server without any issue for some time now.

+

However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database.

+

After a bit a googling, I've settled on Postfix Admin.

+

The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their Github repo.

+

I've also tried ViMbAdmin, but it felt a little heavy considering what I was going to use it for.

+

You'll need a web server with PHP support to run Postfix Admin. I personnaly run nginx with php5-fpm, but I won't explain how to configure it here. I'll simply explain how to migrate your current database to one managed with Postfix Admin with as little downtime as possible.

+

Creating a new database

+

Since the database managed by Postfix Admin does not use the same schema as the one we've created in my previous tutorial, we'll have to create a new one. We will give all privileges on that database to the same user as before, 'mail'@'localhost'.

+
CREATE DATABASE mailnew;
+GRANT SELECT ON mailnew.* TO 'mail'@'localhost';
+FLUSH PRIVILEGES;
+
+ + +

At this point, you can clone the Postfix Admin project from Github and go through the installation process.

+

While editing the config.inc.php file (or config.local.php file if you've decided to copy it), make sure that the database_name option is set to use the mailnew database we've just created.

+

Also, make sure that the encrypt option is set to dovecot:SHA512-CRYPT.

+

The installation process will create all the necessary tables in the database.

+

At this point, you'll have to recreate all domains, mailboxes and aliases that you have configured in your current mail database using the Postfix Admin interface.

+

Postfix configuration

+

Once you're done with Postfix Admin, it's time to configure Postfix to use its schema.

+

First thing first, let's backup our current configuration :

+
mkdir /etc/postfix/mysql-backup
+cp -a /etc/postfix/mysql-virtual* /etc/postfix/mysql-backup/
+
+ + +

Next, we have to edit the 3 files we've just backuped. The only line that actually changes is the one beginning with query.

+

The first file is /etc/postfix/mysql-virtual-mailbox-domains.cf :

+
user = mail
+password = mailpassword
+hosts = 127.0.0.1
+dbname = mail
+query = SELECT 1 FROM domain WHERE domain='%s' AND active='1'
+
+ + +

The second one is /etc/postfix/mysql-virtual-mailbox-maps.cf :

+
user = mail
+password = mailpassword
+hosts = 127.0.0.1
+dbname = mail
+query = SELECT 1 FROM mailbox WHERE username='%s' AND active='1'
+
+ + +

And the last one is /etc/postfix/mysql-virtual-alias-maps.cf :

+
user = mail
+password = mailpassword
+hosts = 127.0.0.1
+dbname = mail
+query = SELECT goto FROM alias WHERE address='%s' AND active='1'
+
+ + +

Dovecot configuration

+

Same as with Postfix, we now need to configure Dovecot to use the Postfix Admin schema.

+

First, let's backup our current configuration :

+
cp -a /etc/dovecot/sql.conf /etc/dovecot/sql.conf.bak
+
+ + +

Next, we have to edit the /etc/dovecot/sql.conf file. The only line that changes is the one beginning with password_query.

+
driver = mysql
+connect = host=localhost dbname=mail user=mail password=mailpassword
+default_pass_scheme = SHA512-CRYPT
+password_query = SELECT username as user, password FROM mailbox WHERE username='%u' AND active='1';
+
+ + +

Migrating to the new schema

+

We're done with the configuration part. Time to migrate to the new schema.

+

First, let's create a backup of our current mail database :

+
mysqldump mail | bzip2 > /home/user/mail.sql.bz2
+
+ + +

Next, in a SQL shell, we're going to drop and recreate the mail database :

+
DROP DATABASE mail;
+CREATE DATABASE mail;
+
+ + +

We now have to dump the contents of the mailnew database into the newly created mail database :

+
mysqldump mailnew | mysql mail
+
+ + +

The last thing we have to do is to restart Postfix and Dovecot so that it starts using the new database schema :

+
systemctl restart postfix
+systemctl restart dovecot
+
+ + +

At this point, Postfix and Dovecot are using the Postfix Admin schema in the mail database.

+

The last thing we have to do is to edit Postfix Admin's config.inc.php file to use the mail database as well instead of the mailnew database that it should be currently using.

+

Cleanup

+

Once you've confirmed that everything is working properly, you can delete the backup files we've created :

+
rm -rf /etc/postfix/mysql-backup
+rm /etc/dovecot/sql.conf.bak 
+
+ + +

You can drop the mailnew database as well :

+
DROP DATABASE mailnew;
+
+ + +

Conclusion

+

That's all ! As always, please do leave a comment if this article has been of any use to you !

+
+ + +
+ +
+ +
+

Comments !

+
+ + +
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/output/rss.xml b/output/rss.xml index c1c3506..8148932 100644 --- a/output/rss.xml +++ b/output/rss.xml @@ -1,5 +1,114 @@ -Sysadmining. All day. Every day.https://captainark.net/2016-02-02T00:00:00+01:00My tmux configuration2016-02-02T00:00:00+01:00Antoine Jouberttag:captainark.net,2016-02-02:my-tmux-configuration.html<p><a href="https://tmux.github.io/">tmux</a> is a terminal mutiplexer. It lets you have multiples shells running in a single terminal emulator window and it keeps those shells running in the background should you need to close your terminal emulator.</p> +Sysadmining. All day. Every day.https://captainark.net/2016-03-06T00:00:00+01:00Postfix Admin2016-03-06T00:00:00+01:00Antoine Jouberttag:captainark.net,2016-03-06:postfix-admin.html<p>As I explained in <a href="https://www.captainark.net/setting-up-a-mail-server.html">this previous tutorial</a>, I've been running my own mail server without any issue for some time now.</p> +<p>However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database.</p> +<p>After a bit a googling, I've settled on <a href="http://postfixadmin.sourceforge.net/">Postfix Admin</a>.</p> +<p>The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their <a href="https://github.com/postfixadmin/postfixadmin">Github repo</a>.</p> +<p>I've also tried <a href="http://www.vimbadmin.net/">ViMbAdmin</a>, but it felt a little heavy considering what I was going to use it for.</p> +<p>You'll need a web server with PHP support to run Postfix Admin. I personnaly run nginx with php5-fpm, but I won't explain how to configure it here. I'll simply explain how to migrate your current database to one managed with Postfix Admin with as little downtime as possible.</p> +<h1>Creating a new database</h1> +<p>Since the database managed by Postfix Admin does not use the same schema as the one we've created in my previous tutorial, we'll have to create a new one. We will give all privileges on that database to the same user as before, <code>'mail'@'localhost'</code>.</p> +<div class="highlight"><pre><span></span><span class="k">CREATE</span> <span class="k">DATABASE</span> <span class="n">mailnew</span><span class="p">;</span> +<span class="k">GRANT</span> <span class="k">SELECT</span> <span class="k">ON</span> <span class="n">mailnew</span><span class="p">.</span><span class="o">*</span> <span class="k">TO</span> <span class="s1">&#39;mail&#39;</span><span class="o">@</span><span class="s1">&#39;localhost&#39;</span><span class="p">;</span> +<span class="n">FLUSH</span> <span class="k">PRIVILEGES</span><span class="p">;</span> +</pre></div> + + +<p>At this point, you can clone the Postfix Admin project from Github and go through the installation process.</p> +<p>While editing the config.inc.php file (or config.local.php file if you've decided to copy it), make sure that the <code>database_name</code> option is set to use the <code>mailnew</code> database we've just created.</p> +<p>Also, make sure that the <code>encrypt</code> option is set to <code>dovecot:SHA512-CRYPT</code>.</p> +<p>The installation process will create all the necessary tables in the database.</p> +<p><strong>At this point, you'll have to recreate all domains, mailboxes and aliases that you have configured in your current mail database using the Postfix Admin interface.</strong></p> +<h1>Postfix configuration</h1> +<p>Once you're done with Postfix Admin, it's time to configure Postfix to use its schema.</p> +<p>First thing first, let's backup our current configuration :</p> +<div class="highlight"><pre><span></span>mkdir /etc/postfix/mysql-backup +cp -a /etc/postfix/mysql-virtual* /etc/postfix/mysql-backup/ +</pre></div> + + +<p>Next, we have to edit the 3 files we've just backuped. The only line that actually changes is the one beginning with <code>query</code>.</p> +<p>The first file is /etc/postfix/mysql-virtual-mailbox-domains.cf :</p> +<div class="highlight"><pre><span></span>user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT 1 FROM domain WHERE domain=&#39;%s&#39; AND active=&#39;1&#39; +</pre></div> + + +<p>The second one is /etc/postfix/mysql-virtual-mailbox-maps.cf :</p> +<div class="highlight"><pre><span></span>user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT 1 FROM mailbox WHERE username=&#39;%s&#39; AND active=&#39;1&#39; +</pre></div> + + +<p>And the last one is /etc/postfix/mysql-virtual-alias-maps.cf :</p> +<div class="highlight"><pre><span></span>user = mail +password = mailpassword +hosts = 127.0.0.1 +dbname = mail +query = SELECT goto FROM alias WHERE address=&#39;%s&#39; AND active=&#39;1&#39; +</pre></div> + + +<h1>Dovecot configuration</h1> +<p>Same as with Postfix, we now need to configure Dovecot to use the Postfix Admin schema.</p> +<p>First, let's backup our current configuration :</p> +<div class="highlight"><pre><span></span>cp -a /etc/dovecot/sql.conf /etc/dovecot/sql.conf.bak +</pre></div> + + +<p>Next, we have to edit the /etc/dovecot/sql.conf file. The only line that changes is the one beginning with <code>password_query</code>.</p> +<div class="highlight"><pre><span></span>driver = mysql +connect = host=localhost dbname=mail user=mail password=mailpassword +default_pass_scheme = SHA512-CRYPT +password_query = SELECT username as user, password FROM mailbox WHERE username=&#39;%u&#39; AND active=&#39;1&#39;; +</pre></div> + + +<h1>Migrating to the new schema</h1> +<p>We're done with the configuration part. Time to migrate to the new schema.</p> +<p>First, let's create a backup of our current mail database :</p> +<div class="highlight"><pre><span></span>mysqldump mail <span class="p">|</span> bzip2 &gt; /home/user/mail.sql.bz2 +</pre></div> + + +<p>Next, in a SQL shell, we're going to drop and recreate the mail database :</p> +<div class="highlight"><pre><span></span><span class="k">DROP</span> <span class="k">DATABASE</span> <span class="n">mail</span><span class="p">;</span> +<span class="k">CREATE</span> <span class="k">DATABASE</span> <span class="n">mail</span><span class="p">;</span> +</pre></div> + + +<p>We now have to dump the contents of the mailnew database into the newly created mail database :</p> +<div class="highlight"><pre><span></span>mysqldump mailnew <span class="p">|</span> mysql mail +</pre></div> + + +<p>The last thing we have to do is to restart Postfix and Dovecot so that it starts using the new database schema :</p> +<div class="highlight"><pre><span></span>systemctl restart postfix +systemctl restart dovecot +</pre></div> + + +<p>At this point, Postfix and Dovecot are using the Postfix Admin schema in the mail database.</p> +<p>The last thing we have to do is to edit Postfix Admin's config.inc.php file to use the mail database as well instead of the mailnew database that it should be currently using.</p> +<h1>Cleanup</h1> +<p>Once you've confirmed that everything is working properly, you can delete the backup files we've created :</p> +<div class="highlight"><pre><span></span>rm -rf /etc/postfix/mysql-backup +rm /etc/dovecot/sql.conf.bak +</pre></div> + + +<p>You can drop the mailnew database as well :</p> +<div class="highlight"><pre><span></span><span class="k">DROP</span> <span class="k">DATABASE</span> <span class="n">mailnew</span><span class="p">;</span> +</pre></div> + + +<h1>Conclusion</h1> +<p>That's all ! As always, please do leave a comment if this article has been of any use to you !</p>My tmux configuration2016-02-02T00:00:00+01:00Antoine Jouberttag:captainark.net,2016-02-02:my-tmux-configuration.html<p><a href="https://tmux.github.io/">tmux</a> is a terminal mutiplexer. It lets you have multiples shells running in a single terminal emulator window and it keeps those shells running in the background should you need to close your terminal emulator.</p> <p>I've played around with the configuration quite a bit to find settings that suit my needs. Here's what it ended up looking like :</p> <p><a href="images/tmux_fullsize.png"><img alt="tmux" src="images/tmux.png" /></a></p> <p>This screenshot was done on Mac OS X, using the Terminal app and this <a href="https://github.com/tomislav/osx-terminal.app-colors-solarized">Solarized theme</a>.</p> diff --git a/output/theme/.DS_Store b/output/theme/.DS_Store deleted file mode 100644 index 59a5ba8..0000000 Binary files a/output/theme/.DS_Store and /dev/null differ