Raspberry Pi as your note keeper

Say goodbye to the green elephant and hello to Pi!

Here is a guide on setting up a Raspberry Pi as your private online note keeper. Say goodbye to the green elephant and hello to Pi! Since storing notes only needs a bit storage and you need the note keeper service to be available 24/7 the Raspberry Pi is perfectly suited for this job.

This basic idea is having an Evernote alternative by using Tomboy (the client side) and Snowy (the server) with the Raspberry Pi. In this guide we’ll be using the Raspian wheezy image from http://www.raspberrypi.org/downloads. Apart rom the Snowy download only standard Raspian packages are used to complete the installation.

For starters be sure to have a fresh Raspian installation (guide here) have it connected to the internet and have access to the console.

It is always wise to start with updating apt:

[email protected] ~ $ sudo apt-get update

Prepare/install apache

Snowy will run within the apache webserver through WSGI:

[email protected] ~ $ sudo apt-get install libapache2-mod-wsgi

This will install everything that is required to use wsgi on an apache server

Install snowy

Snowy is a web application for synchronizing, viewing, sharing, and editing your Tomboy notes online. It must be downloaded rom gnome’s git repository. So first install git, navigate to /var/www and download Snowy:

[email protected] ~ $ sudo apt-get install git-core
[email protected] ~ $ cd /var/www
[email protected] /var/www $ sudo git clone git://git.gnome.org/snowy

Note: putting everything in /var/www is not required but it is the most common place to store apache stuff.

Snowy is implemented in python an needs some additional python packages:

[email protected] /var/www $ sudo apt-get install python-django
[email protected] /var/www $ sudo apt-get install python-tz python-lxml python-sqlite python-dateutil python-pkg-resources python-openid python-django-south

Note that, compared to https://live.gnome.org/Snowy/Install I left out ‘python-json’ and added ‘python-django-south’

Create a settings file:

[email protected] /var/www $ cd snowy
[email protected] /var/www/snowy $ sudo cp local_settings.py.in local_settings.py

We keep the original content en move on to creation of the database

[email protected] /var/www/snowy $ sudo python manage.py syncdb
Syncing...
Creating tables ...
Creating table accounts_userprofile
Creating table django_openid_auth_nonce
Creating table django_openid_auth_association
Creating table django_openid_auth_useropenid
Creating table notes_note_tags
Creating table notes_note
Creating table notes_notetag
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table registration_registrationprofile
Creating table south_migrationhistory
Creating table piston_nonce
Creating table piston_consumer
Creating table piston_token

[email protected] /var/www/snowy $ sudo cp local_settings.py.in local_settings.py
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'root'): pi
E-mail address: [email protected]
Password:
Password (again):
Superuser created successfully.
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 1 object(s) from 1 fixture(s)

Synced:
 > api
 > accounts
 > django_openid_auth
 > notes
 > export
 > django.contrib.admin
 > django.contrib.admindocs
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.humanize
 > django.contrib.messages
 > registration
 > south
 > gravatar
 > pagination
 > piston

Not synced (use migrations):
 -
(use ./manage.py migrate to migrate these)

Make apache run snowy

To run Snowy under apache 2 files are needed, the wsgi script and a virtual host configuration.

Create the wsgi file with nano:

[email protected] /var/www/snowy $ sudo nano snowy.wsgi

And fill the file with:

import os
import sys
sys.stdout = sys.stderr
sys.path.insert(0, '/var/www/snowy')
sys.path.insert(1, '/var/www')

os.environ['DJANGO_SETTINGS_MODULE'] = 'snowy.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Exit with Ctrl-X and enter y to save.

Now create the second file, a new virtual host for apache:

[email protected] /var/www/snowy $ sudo nano /etc/apache2/sites-available/snowy

Fill the file with:

WSGIPassAuthorization On
WSGIApplicationGroup %{GLOBAL}
Alias /media/ /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/
WSGIDaemonProcess snowy user=www-data home=/var/www/snowy
WSGIProcessGroup snowy
WSGIScriptAlias / /var/www/snowy/snowy.wsgi

Since snowy will be running under the user www-data (the standard apache user) we´ll make www-data the owner of the files under the snowy directory:

[email protected] /var/www/snowy $ sudo chown www-data -R /var/www/snowy

Finally Snowy can be started:

[email protected] /var/www/snowy $ sudo a2ensite snowy
[email protected] /var/www/snowy $ sudo service apache2 reload

Final configuration

With abrowser go to: http://<raspberry-ip>/admin/. And log in with the user name password created earlier.
The styling of the admin page may be missing but we won’t be here long anyway.

After successfull login go to http://<raspberry-pi>/admin/sites/site/1/

Choose a display name. And set the ip of the Raspberry Pi.
Note: If you only intend to access your notes from the internet you need to fill in the external dns name or ip here.

When done go to http://<raspberry-pi>/<user>/notes/ to see all note of a user. Offcourse there are no notes on the available yet, but at least you know that Snowy has been set up properly.

Testing

Download and install Tomboy from http://projects.gnome.org/tomboy/. Go to the Preferences and select the Sychronization tab. Set the service to ‘Tomboy Web’, fill in http://<raspberry-pi> and press Connect. Follow the intructions and you’re done and ready to sync notes you make!

All notes that you make are also available through the web interface at http://<raspberry-pi>/<user>/notes/:

Tomdroid

As you might guess Tomdroid is a tomboy app for Android.

Authentification from Tomdroid to Snowy does not work out of the box. Tomdroid registers with a callback to url : “tomdroid://sync”. But due to cross-site scripting security in django code, django refuses to redirect the browser to to the Tomdroid url. As a result Tomdroid never gets the acknowledgement of verification.

The cross-site scripting security basically comes down to the fact that only ‘http’, ‘https’ and ‘ftp’ are allowed. See allowed_schemes in https://www.djangoproject.com/weblog/2012/jul/30/security-releases-issued/

To workaround it edit /usr/lib/python2.7/dist-packages/django/http/__init__.py.

[email protected] /var/www/snowy $ sudo nano /usr/lib/python2.7/dist-packages/django/http/__init__.py

Add 'tomdroid' to the allowed_schemes list in HttpResponseRedirectBase. Like below:

class HttpResponseRedirectBase(HttpResponse):
	allowed_schemes = ['http', 'https', 'ftp', 'tomdroid']

	def __init__(self, redirect_to):
	super(HttpResponseRedirectBase, self).__init__()
	parsed = urlparse(redirect_to)
	if parsed[0] and parsed[0] not in self.allowed_schemes:
		 raise SuspiciousOperation("Unsafe redirect to URL with scheme '%s'" % parsed[0])
	self['Location'] = iri_to_uri(redirect_to)

Then restart apache (sudo service apache2 restart) and authenticate Tomdroid.

Links and references

 

3 thoughts on “Raspberry Pi as your note keeper

Leave a Reply

Your email address will not be published. Required fields are marked *