postfix admin article #1

This commit is contained in:
CaptainArk 2016-03-13 17:39:32 +01:00
parent fb9fae817c
commit 5b722e1027
9 changed files with 644 additions and 2 deletions

150
content/postfixadmin.md Normal file
View File

@ -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 !

View File

@ -88,6 +88,8 @@
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<dl> <dl>
<dt>Sun 06 March 2016</dt>
<dd><a href="https://captainark.net/postfix-admin.html">Postfix Admin</a></dd>
<dt>Tue 02 February 2016</dt> <dt>Tue 02 February 2016</dt>
<dd><a href="https://captainark.net/my-tmux-configuration.html">My tmux configuration</a></dd> <dd><a href="https://captainark.net/my-tmux-configuration.html">My tmux configuration</a></dd>
<dt>Sun 31 January 2016</dt> <dt>Sun 31 January 2016</dt>

View File

@ -87,6 +87,18 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
<h2 class="post-title">
Postfix Admin
</h2>
</a>
<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 ...
<p class="post-meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
on Sun 06 March 2016
</p>
<p>There are <a href="https://captainark.net/postfix-admin.html#disqus_thread">comments</a>.</p> </div>
<div class="post-preview"> <div class="post-preview">
<a href="https://captainark.net/my-tmux-configuration.html" rel="bookmark" title="Permalink to My tmux configuration"> <a href="https://captainark.net/my-tmux-configuration.html" rel="bookmark" title="Permalink to My tmux configuration">
<h2 class="post-title"> <h2 class="post-title">

View File

@ -90,7 +90,7 @@
<div class="post-preview"> <div class="post-preview">
<a href="https://captainark.net/author/antoine-joubert.html" rel="bookmark"> <a href="https://captainark.net/author/antoine-joubert.html" rel="bookmark">
<h2 class="post-title"> <h2 class="post-title">
Antoine Joubert (5) Antoine Joubert (6)
</h2> </h2>
</a> </a>
</div> </div>

View File

@ -87,6 +87,18 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
<h2 class="post-title">
Postfix Admin
</h2>
</a>
<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 ...
<p class="post-meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
on Sun 06 March 2016
</p>
<p>There are <a href="https://captainark.net/postfix-admin.html#disqus_thread">comments</a>.</p> </div>
<div class="post-preview"> <div class="post-preview">
<a href="https://captainark.net/private-git-repo.html" rel="bookmark" title="Permalink to Private Git Repo"> <a href="https://captainark.net/private-git-repo.html" rel="bookmark" title="Permalink to Private Git Repo">
<h2 class="post-title"> <h2 class="post-title">

View File

@ -90,6 +90,18 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<a href="https://captainark.net/postfix-admin.html" rel="bookmark" title="Permalink to Postfix Admin">
<h2 class="post-title">
Postfix Admin
</h2>
</a>
<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 ...
<p class="post-meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
on Sun 06 March 2016
</p>
<p>There are <a href="https://captainark.net/postfix-admin.html#disqus_thread">comments</a>.</p> </div>
<div class="post-preview"> <div class="post-preview">
<a href="https://captainark.net/my-tmux-configuration.html" rel="bookmark" title="Permalink to My tmux configuration"> <a href="https://captainark.net/my-tmux-configuration.html" rel="bookmark" title="Permalink to My tmux configuration">
<h2 class="post-title"> <h2 class="post-title">

345
output/postfix-admin.html Normal file
View File

@ -0,0 +1,345 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Antoine Joubert">
<title>Postfix Admin</title>
<link href="https://captainark.net/rss.xml" type="application/atom+xml" rel="alternate" title="Sysadmining. All day. Every day. Full Atom Feed" />
<!-- Bootstrap Core CSS -->
<link href="https://captainark.net/theme/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="https://captainark.net/theme/css/clean-blog.min.css" rel="stylesheet">
<!-- Code highlight color scheme -->
<link href="https://captainark.net/theme/css/code_blocks/github.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta name="description" content="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 ...">
<meta name="author" content="Antoine Joubert">
<meta property="og:locale" content="">
<meta property="og:site_name" content="Sysadmining. All day. Every day.">
<meta property="og:type" content="article">
<meta property="article:author" content="Antoine Joubert" >
<meta property="og:url" content="https://captainark.net/postfix-admin.html">
<meta property="og:title" content="Postfix Admin">
<meta property="article:published_time" content="2016-03-06 00:00:00+01:00">
<meta property="og:description" content="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 ...">
<meta property="og:image" content="https://captainark.net//bg.png">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://captainark.net/">Sysadmining. All day. Every day.</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Homepage</a></li>
<li><a href="/rss.xml">RSS</a></li>
<li><a href="/categories.html">Categories</a></li>
<li><a href="https://captainark.net/pages/about.html">About</a></li>
<li><a href="https://captainark.net/pages/resume.html">Resume</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<header class="intro-header" style="background-image: url('/bg.png')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>Postfix Admin</h1>
<span class="meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
on Sun 06 March 2016
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<!-- Post Content -->
<article>
<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>
</article>
<hr>
<div class="sharing">
</div>
<hr>
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'captainark';
var disqus_identifier = 'postfix-admin.html';
var disqus_url = 'https://captainark.net/postfix-admin.html';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//captainark.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript>
</div>
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a href="mailto:contact@captainark.net">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://twitter.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://github.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.last.fm/user/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-lastfm fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://steamcommunity.com/id/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-steam fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.twitch.tv/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitch fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="copyright text-muted">
Blog powered by <a href="http://getpelican.com">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>.
</p> </div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="https://captainark.net/theme/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="https://captainark.net/theme/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="https://captainark.net/theme/js/clean-blog.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-53658366-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
var disqus_shortname = 'captainark';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
</body>
</html>

View File

@ -1,5 +1,114 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Sysadmining. All day. Every day.</title><link href="https://captainark.net/" rel="alternate"></link><link href="https://captainark.net/rss.xml" rel="self"></link><id>https://captainark.net/</id><updated>2016-02-02T00:00:00+01:00</updated><entry><title>My tmux configuration</title><link href="https://captainark.net/my-tmux-configuration.html" rel="alternate"></link><updated>2016-02-02T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-02-02:my-tmux-configuration.html</id><summary type="html">&lt;p&gt;&lt;a href="https://tmux.github.io/"&gt;tmux&lt;/a&gt; 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.&lt;/p&gt; <feed xmlns="http://www.w3.org/2005/Atom"><title>Sysadmining. All day. Every day.</title><link href="https://captainark.net/" rel="alternate"></link><link href="https://captainark.net/rss.xml" rel="self"></link><id>https://captainark.net/</id><updated>2016-03-06T00:00:00+01:00</updated><entry><title>Postfix Admin</title><link href="https://captainark.net/postfix-admin.html" rel="alternate"></link><updated>2016-03-06T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-03-06:postfix-admin.html</id><summary type="html">&lt;p&gt;As I explained in &lt;a href="https://www.captainark.net/setting-up-a-mail-server.html"&gt;this previous tutorial&lt;/a&gt;, I've been running my own mail server without any issue for some time now.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;After a bit a googling, I've settled on &lt;a href="http://postfixadmin.sourceforge.net/"&gt;Postfix Admin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;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 &lt;a href="https://github.com/postfixadmin/postfixadmin"&gt;Github repo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I've also tried &lt;a href="http://www.vimbadmin.net/"&gt;ViMbAdmin&lt;/a&gt;, but it felt a little heavy considering what I was going to use it for.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;h1&gt;Creating a new database&lt;/h1&gt;
&lt;p&gt;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, &lt;code&gt;'mail'@'localhost'&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;mailnew&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GRANT&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;mailnew&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;mail&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;localhost&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;FLUSH&lt;/span&gt; &lt;span class="k"&gt;PRIVILEGES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;At this point, you can clone the Postfix Admin project from Github and go through the installation process.&lt;/p&gt;
&lt;p&gt;While editing the config.inc.php file (or config.local.php file if you've decided to copy it), make sure that the &lt;code&gt;database_name&lt;/code&gt; option is set to use the &lt;code&gt;mailnew&lt;/code&gt; database we've just created.&lt;/p&gt;
&lt;p&gt;Also, make sure that the &lt;code&gt;encrypt&lt;/code&gt; option is set to &lt;code&gt;dovecot:SHA512-CRYPT&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The installation process will create all the necessary tables in the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;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.&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;Postfix configuration&lt;/h1&gt;
&lt;p&gt;Once you're done with Postfix Admin, it's time to configure Postfix to use its schema.&lt;/p&gt;
&lt;p&gt;First thing first, let's backup our current configuration :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;mkdir /etc/postfix/mysql-backup
cp -a /etc/postfix/mysql-virtual* /etc/postfix/mysql-backup/
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, we have to edit the 3 files we've just backuped. The only line that actually changes is the one beginning with &lt;code&gt;query&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first file is /etc/postfix/mysql-virtual-mailbox-domains.cf :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT 1 FROM domain WHERE domain=&amp;#39;%s&amp;#39; AND active=&amp;#39;1&amp;#39;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The second one is /etc/postfix/mysql-virtual-mailbox-maps.cf :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT 1 FROM mailbox WHERE username=&amp;#39;%s&amp;#39; AND active=&amp;#39;1&amp;#39;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And the last one is /etc/postfix/mysql-virtual-alias-maps.cf :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT goto FROM alias WHERE address=&amp;#39;%s&amp;#39; AND active=&amp;#39;1&amp;#39;
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Dovecot configuration&lt;/h1&gt;
&lt;p&gt;Same as with Postfix, we now need to configure Dovecot to use the Postfix Admin schema.&lt;/p&gt;
&lt;p&gt;First, let's backup our current configuration :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;cp -a /etc/dovecot/sql.conf /etc/dovecot/sql.conf.bak
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, we have to edit the /etc/dovecot/sql.conf file. The only line that changes is the one beginning with &lt;code&gt;password_query&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;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=&amp;#39;%u&amp;#39; AND active=&amp;#39;1&amp;#39;;
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Migrating to the new schema&lt;/h1&gt;
&lt;p&gt;We're done with the configuration part. Time to migrate to the new schema.&lt;/p&gt;
&lt;p&gt;First, let's create a backup of our current mail database :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;mysqldump mail &lt;span class="p"&gt;|&lt;/span&gt; bzip2 &amp;gt; /home/user/mail.sql.bz2
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, in a SQL shell, we're going to drop and recreate the mail database :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;mail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;mail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We now have to dump the contents of the mailnew database into the newly created mail database :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;mysqldump mailnew &lt;span class="p"&gt;|&lt;/span&gt; mysql mail
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The last thing we have to do is to restart Postfix and Dovecot so that it starts using the new database schema :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;systemctl restart postfix
systemctl restart dovecot
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;At this point, Postfix and Dovecot are using the Postfix Admin schema in the mail database.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;h1&gt;Cleanup&lt;/h1&gt;
&lt;p&gt;Once you've confirmed that everything is working properly, you can delete the backup files we've created :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;rm -rf /etc/postfix/mysql-backup
rm /etc/dovecot/sql.conf.bak
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can drop the mailnew database as well :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;mailnew&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;That's all ! As always, please do leave a comment if this article has been of any use to you !&lt;/p&gt;</summary></entry><entry><title>My tmux configuration</title><link href="https://captainark.net/my-tmux-configuration.html" rel="alternate"></link><updated>2016-02-02T00:00:00+01:00</updated><author><name>Antoine Joubert</name></author><id>tag:captainark.net,2016-02-02:my-tmux-configuration.html</id><summary type="html">&lt;p&gt;&lt;a href="https://tmux.github.io/"&gt;tmux&lt;/a&gt; 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.&lt;/p&gt;
&lt;p&gt;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 :&lt;/p&gt; &lt;p&gt;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 :&lt;/p&gt;
&lt;p&gt;&lt;a href="images/tmux_fullsize.png"&gt;&lt;img alt="tmux" src="images/tmux.png" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="images/tmux_fullsize.png"&gt;&lt;img alt="tmux" src="images/tmux.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This screenshot was done on Mac OS X, using the Terminal app and this &lt;a href="https://github.com/tomislav/osx-terminal.app-colors-solarized"&gt;Solarized theme&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;This screenshot was done on Mac OS X, using the Terminal app and this &lt;a href="https://github.com/tomislav/osx-terminal.app-colors-solarized"&gt;Solarized theme&lt;/a&gt;.&lt;/p&gt;

BIN
output/theme/.DS_Store vendored

Binary file not shown.