app; logging: Change timestamp format

Previously the timestamp in the logs was seconds.microseconds, while
this is useful for the timestamps in the database, it would perhaps be
nicer to have a more human readable timestamp in the logs.

Thus we now use the following format:

    [YYYY-MM-DD HH:MM:SS tz-offset]

e.g

    [2013-07-04 00:06:38 +0100]

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
db: logging: Update the SQL log datestamp format

Commit 3c5f64b ("app: logging: Change timestamp format") changed the
timestamp in the logs from seconds.microseconds to a more human readable
format.

However the SQL log is not written via d_fprintf() and was still using
the old format. Update it.

It now looks like

    [2014-04-15 15:58:01 +0100]

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
app: last login: Don't display anything for initial login

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
app: Fix potentially slow logins

When a user logs in we do a reverse DNS lookup of the users IP address
to get the hostname. We store both the IP address and hostname (if any)
of the requesting client in the utmp table. This is used in the 'Last
login' line we display. Also having both the IP address _and_ hostname
provides a better audit trail.

Normally this should only take a fraction of a second. However there are
cases where we get a 2(SERVFAIL) after a timeout. If there was just no
PTR record then we'd get a 3(NXDOMAIN) pretty quickly.

Seeing as there is no need to delay the login just to get the hostname,
we can do the IP->hostname lookup in a thread which will do the lookup
and update the utmp table accordingly based on the clients session id.

We move the hostname lookup out of log_login() and into a thread routine
log_utmp_host() which is created from log_login. This allows the login
to complete right away and the utmp table is updated asynchronously.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
templates/login: Display the clients IP address

This is simple to do and may be useful. The address is displayed just
under the 'Restrict this session to your IP address:' text.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>
utmp: Log the remote port for the login

This logs the port on the remote end that the connection originated
from. In the case of NAT this will be a port on the NAT device.

The main point of this is to allow some chance of linking a login back
to a specific host behind NAT where the logged port will be a port on
the NAT device which you can use to link back to a host behind the NAT
e.g by looking in /proc/net/ip_conntrack on Linux.

Signed-off-by: Andrew Clayton <andrew@digital-domain.net>