~libravatar/libravatar/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
External dependencies
----------------------

- Python 2.6
- Django 1.2
- Apache 2 with:
  - mod_alias
  - mod_expires
  - mod_headers
  - mod_rewrite
- Python DNS 2.3.4
  (http://pydns.sourceforge.net/)
- jQuery 1.4
- Python Imaging Library
  (http://www.pythonware.com/library/)
- YUI Compressor, for minifying CSS/JS files
  (http://developer.yahoo.com/yui/compressor/)
- Gearman (http://www.gearman.org)
- Python bindings for libgearman
  (http://www.launchpad.net/gearman-interface)
- Python OpenID
  (https://github.com/openid/python-openid)

(optional, if using LDAP authenticaion):

- Python LDAP library

On Debian unstable or squeeze:

  apt-get install python-django apache2-mpm-prefork python-dns libjs-jquery python2.6 python-imaging libapache2-mod-wsgi python-psycopg2 yui-compressor gearman-job-server gearman-tools python-gearman.libgearman jpegoptim optipng python-openid
  
  apt-get install python-ldap


Create your database
---------------------

Create a database user:

  sudo -u postgres createuser djangouser

Create a database:

  sudo -u postgres createdb -O djangouser libravatar

Create the required tables:

  cd /usr/share/libravatar/libravatar
  python manage.py syncdb

Create an index for the sessions table (not needed for Django 1.3 or later):

  sudo -u postrgres psql libravatar
  CREATE INDEX "django_session_expire_date" ON "django_session" ("expire_date");


Apache Configuration
---------------------

Start by adding this to your /etc/hosts:

  127.0.0.1 www.libravatar.org secure.libravatar.org cdn.libravatar.org seccdn.libravatar.org

Enable mod_alias, mod_expires, mod_headers, mod_rewrite and mod_wsgi:

  a2enmod alias
  a2enmod expires
  a2enmod headers
  a2enmod rewrite
  a2enmod wsgi

Create a uploaded/ and user/ directories that are writable by the www-data user:

  mkdir /var/lib/libravatar/uploaded
  mkdir /var/lib/libravatar/user
  sudo chgrp www-data /var/lib/libravatar/uploaded
  sudo chgrp www-data /var/lib/libravatar/user
  sudo chmod g+w /var/lib/libravatar/uploaded
  sudo chmod g+w /var/lib/libravatar/user

Similarly, an avatar/ directory that's writable by the www-data user:

  mkdir /var/lib/libravatar/avatar
  sudo chgrp www-data /var/lib/libravatar/avatar
  sudo chmod g+w /var/lib/libravatar/avatar

Then copy config/*.conf to /etc/apache2/sites-enabled/, adjust the
path to the cdn-common include file and restart Apache using:

  apache2ctl configtest
  apache2ctl restart


Gearman jobs
-------------

A few Gearman jobs must be running to fully take care of photo management:

  cropresize: must run under a user that has read access to /uploaded and
              write access to /ready
  ready2user: must run under a user with read access to /ready and write
              access to /uploaded and /user

  changephoto: must run as root
  deletephoto: must run as root
  resizeavatar: must run as root
  exportaccount: must run as root

There are python scripts under libravatar/ for all of these functions and
workers can be setup like this:

  gearman -w -f FUNCTION_NAME libravatar/FUNCTION_NAME.py


Cron job
---------

You should have a daily cron job which does the following:

- delete old sessions
- delete old uploaded (i.e. non-cropped) files

Have a look in debian/libravatar-www.cron.daily for an example.


Authenticating with an external LDAP server:
---------------------------------------------

Download and install the Django LDAP authentication backend. This is a BSD-
licensed module written by Peter Sagerson:

http://packages.python.org/django-auth-ldap/

The module can be checked out and installed as follows:

   hg clone http://bitbucket.org/psagers/django-auth-ldap
   sudo easy_install django-auth-ldap

Then uncomment the LDAP backend line in AUTHENTICATION_BACKENDS in your
settings.py and set your AUTH_LDAP_SERVER_URI and AUTH_LDAP_USER_DN_TEMPLATE
settings to something appropriate. More complex setups are also well documented
in the package documentation.