2014-09-04 06:25:48 +03:00
# Realms Wiki Beta
Git based wiki written in Python
2014-09-10 22:37:48 +03:00
Inspired by [Gollum][gollum], [Ghost][ghost], and [Dillinger][dillinger].
2014-09-04 06:25:48 +03:00
Basic authentication and registration included.
2014-09-04 16:06:22 +03:00
Demo: http://realms.io
This domain is being used temporarily as a demo so expect it to change.
2014-10-17 22:30:00 +03:00
Source: https://github.com/scragg0x/realms-wiki
2014-09-04 06:25:48 +03:00
## Features
2015-07-01 23:44:38 +03:00
- Built with Bootstrap 3.
- Markdown (w/ HTML Support).
- Syntax highlighting (Ace Editor).
- Live preview.
- Collaboration (TogetherJS / Firepad).
- Drafts saved to local storage.
- Handlebars for templates and logic.
2014-09-04 06:25:48 +03:00
## Screenshots
2014-09-10 19:35:11 +03:00
[<img src="https://db.tt/Q2XHGRnT" width=340 /> ](https://db.tt/Q2XHGRnT ) [< img width = 340 src = "https://db.tt/pIZ4w2oN" /> ](https://db.tt/pIZ4w2oN) [< img width = 340 src = "https://db.tt/ERLmDHrk" /> ](https://db.tt/ERLmDHrk) [< img width = 340 src = "https://db.tt/Ls08ocLh" /> ](https://db.tt/Ls08ocLh) [< img width = 340 src = "https://db.tt/7QVfXFQ4" /> ](https://db.tt/7QVfXFQ4) [< img width = 340 src = "https://db.tt/Lna3BOm1" /> ](https://db.tt/Lna3BOm1)
2014-09-04 06:25:48 +03:00
## Requirements
2014-10-17 22:30:00 +03:00
2014-09-04 06:25:48 +03:00
- Python 2.7
2014-10-17 22:30:00 +03:00
### Optional
2015-07-01 23:44:38 +03:00
- Nginx (if you want proxy requests, this is recommended).
- Memcached or Redis, default is memonization.
- MariaDB, MySQL, Postgresql, or another database supported by SQLAlchemy, default is sqlite.
Anon or single user does not require a database.
2014-09-02 17:29:04 +03:00
## Installation
2014-09-04 06:25:48 +03:00
2015-06-30 15:34:02 +03:00
### Requirements installation
You will need the following packages to get started:
#### Ubuntu
2014-10-17 22:30:00 +03:00
2015-11-07 06:05:02 +02:00
sudo apt-get install -y python-pip python-dev libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libyaml-dev libssl-dev libsasl2-dev libldap2-dev
2014-10-17 22:30:00 +03:00
2015-06-30 15:34:02 +03:00
#### CentOS / RHEL
2015-11-07 06:05:02 +02:00
yum install -y python-pip python-devel.x86_64 libxslt-devel.x86_64 libxml2-devel.x86_64 libffi-devel.x86_64 libyaml-devel.x86_64 libxslt-devel.x86_64 zlib-devel.x86_64 openssl-devel.x86_64 openldap2-devel cyrus-sasl-devel python-pbr gcc
2015-06-30 15:34:02 +03:00
#### OSX / Windows
This app is designed for Linux and I recommend using Vagrant to install on OSX or Windows.
2014-10-17 22:30:00 +03:00
2015-06-30 15:34:02 +03:00
### Realms Wiki installation via PyPI
2015-07-01 23:44:38 +03:00
The easiest way. Install it using Python Package Index:
2014-10-17 22:30:00 +03:00
pip install realms-wiki
2014-09-18 18:13:33 +03:00
2015-06-30 15:34:02 +03:00
### Realms Wiki installation via Git
#### Ubuntu
2014-10-17 22:30:00 +03:00
git clone https://github.com/scragg0x/realms-wiki
cd realms-wiki
sudo apt-get install -y software-properties-common python-software-properties
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
2015-11-07 06:05:02 +02:00
sudo apt-get install -y nodejs python-pip python-dev libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libyaml-dev libssl-dev libsasl2-dev libldap2-dev
2014-10-17 22:30:00 +03:00
sudo npm install -g bower
bower install
2014-10-24 06:22:30 +03:00
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
realms-wiki start
2014-09-18 18:13:33 +03:00
2015-07-01 23:44:38 +03:00
NodeJS is required for installing [bower ](http://bower.io ) and it's used for pulling front end dependencies.
2014-09-18 18:13:33 +03:00
2015-06-30 15:34:02 +03:00
### Realms Wiki via Vagrant
2014-09-18 18:13:33 +03:00
Vagrantfile is included for development or running locally.
2015-07-01 23:44:38 +03:00
To get started with Vagrant, download and install Vagrant and VirtualBox for your platform with the links provided:
2014-09-18 18:13:33 +03:00
2015-07-01 23:44:38 +03:00
- https://www.vagrantup.com/downloads.html
- https://www.virtualbox.org/wiki/Downloads
2014-09-18 18:13:33 +03:00
Then execute the following in the terminal:
git clone https://github.com/scragg0x/realms-wiki
cd realms-wiki
vagrant up
2015-06-30 15:34:02 +03:00
Check [http://127.0.0.1:5000/ ](http://127.0.0.1:5000/ ) to make sure it's running.
2014-09-18 18:13:33 +03:00
2015-06-30 15:34:02 +03:00
### Realms Wiki via Docker
2014-09-21 01:30:34 +03:00
Make sure you have docker installed. http://docs.docker.com/installation/
Here is an example run command, it will pull the image from docker hub initially.
docker run --name realms-wiki -p 5000:5000 -d realms/realms-wiki
2015-07-01 23:44:38 +03:00
You can build your own image if you want. Mine is based off https://github.com/phusion/baseimage-docker
The Dockerfile is located in [docker/Dockerfile ](docker/Dockerfile ) `realms/base` just creates the deploy user.
2014-09-21 01:30:34 +03:00
2014-09-18 18:13:33 +03:00
## Config and Setup
2015-07-01 23:44:38 +03:00
You should be able to run the wiki without configuration using the default config values.
You may want to customize your app and the easiest way is the setup command:
2014-09-18 18:13:33 +03:00
realms-wiki setup
2015-11-22 19:19:11 +02:00
This will ask you questions and create a `realms-wiki.json` file.
2014-10-17 22:30:00 +03:00
You can manually edit this file as well.
2015-07-01 23:44:38 +03:00
Any config value set in `realms-wiki.json` will override values set in `realms/config/__init__.py` .
2014-09-18 18:13:33 +03:00
2014-10-03 21:49:18 +03:00
### Nginx Setup
2014-09-04 06:25:48 +03:00
2014-09-18 18:13:33 +03:00
sudo apt-get install -y nginx
2014-09-02 17:29:04 +03:00
2015-07-01 23:44:38 +03:00
Create a file called `realms.conf` in `/etc/nginx/conf.d`
2014-09-09 23:36:23 +03:00
2014-09-18 18:13:33 +03:00
sudo nano /etc/nginx/conf.d/realms.conf
2014-09-09 23:36:23 +03:00
2015-07-01 23:44:38 +03:00
Put the following sample configuration in that file:
2014-09-09 23:36:23 +03:00
2014-09-09 23:46:41 +03:00
server {
listen 80;
# Your domain here
server_name wiki.example.org;
2014-09-18 18:13:33 +03:00
# Settings to by-pass for static files
location ^~ /static/ {
# Example:
2015-03-10 08:06:07 +02:00
root /full/path/to/realms/;
2014-09-18 18:13:33 +03:00
}
2014-09-09 23:46:41 +03:00
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:5000/;
proxy_redirect off;
}
}
2014-09-09 23:36:23 +03:00
2015-07-01 23:44:38 +03:00
Test Nginx config:
2014-09-18 18:13:33 +03:00
sudo nginx -t
2014-09-09 23:36:23 +03:00
2015-07-01 23:44:38 +03:00
Reload Nginx:
2014-09-18 18:13:33 +03:00
sudo service nginx reload
2014-09-02 17:29:04 +03:00
2014-11-18 15:39:54 +02:00
### Apache + mod_wsgi Setup
sudo apt-get install -y apache2 libapache2-mod-wsgi
2015-06-30 15:34:02 +03:00
Create a virtual host configuration in `/etc/apache2/sites-available/realms_vhost`
2014-11-18 15:39:54 +02:00
< VirtualHost * :80 >
ServerName wiki.example.org
WSGIDaemonProcess realms_wsgi display-name=%{GROUP}
WSGIProcessGroup realms_wsgi
WSGIScriptAlias / /var/www/my-realms-dir/wsgi.py
Alias /static /full/path/to/realms/static
< / VirtualHost >
2015-06-30 15:34:02 +03:00
Create `/var/www/my-realms-dir/wsgi.py`
2014-11-18 15:39:54 +02:00
import os
import site
# Uncomment the following lines if you are using a virtual environment
# ----------------------------------
# Enter path to your virtualenv's site-packages directory
# VENV_SITE_DIR = ".venv/lib/python2.7/site-packages"
# PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# site.addsitedir(os.path.abspath(os.path.join(PROJECT_ROOT, VENV_SITE_DIR)))
# ----------------------------------
from realms import create_app
application = create_app()
2015-07-01 23:44:38 +03:00
Enable the virtual host:
2014-11-18 15:39:54 +02:00
sudo a2ensite realms_vhost
2015-07-01 23:44:38 +03:00
Test your configuration:
2014-11-18 15:39:54 +02:00
apache2ctl configtest
2015-07-01 23:44:38 +03:00
Reload apache:
2014-11-18 15:39:54 +02:00
sudo service apache2 reload
2015-07-01 23:46:31 +03:00
### MySQL Setup
2014-10-03 21:49:18 +03:00
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
realms-wiki pip install python-memcached
### MariaDB Setup
sudo apt-get install -y mariadb-server mariadb-client libmariadbclient-dev
realms-wiki pip install MySQL-Python
2014-11-19 17:43:34 +02:00
### Postgres Setup
2014-10-03 21:49:18 +03:00
sudo apt-get install -y libpq-dev postgresql postgresql-contrib postgresql-client
realms-wiki pip install psycopg2
_Don't forget to create your database._
2014-11-19 17:43:34 +02:00
## Search
2015-07-01 23:44:38 +03:00
Realms wiki comes with basic search capabilities, however this is not recommended
for large wikis or if you require more advanced search capabilities.
We currently support Elasticsearch and Whoosh as alternative backend.
2014-11-19 17:43:34 +02:00
### Elasticsearch Setup
2015-07-01 23:44:38 +03:00
There are multiple ways to install/run Elasticsearch. An easy way is to use your their
2014-11-19 17:43:34 +02:00
repositories.
**apt**
wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main" | sudo tee /etc/apt/sources.list.d/elasticsearch.list
apt-get update & & apt-get install elasticsearch
2015-07-01 23:44:38 +03:00
For `yum` instructions or more details, follow the link below:
2014-11-19 17:43:34 +02:00
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-repositories.html
**Configuring Elasticsearch**
In your Realms Config, have the following options set:
"SEARCH_TYPE": "elasticsearch"
"ELASTICSEARCH_URL": "http://127.0.0.1:9200"
2015-07-24 15:43:22 +03:00
Optionally, also set the following option to configure which fields are searchable:
"ELASTICSEARCH_FIELDS": ["name"]
Allowable values are `"name"` , `"content"` , `"username"` , `"message"` . The default is `["name"]` .
2014-11-21 18:24:49 +02:00
### Whoosh Setup
Simply install Whoosh to your Python environment, e.g.
pip install Whoosh
**Configuring Whoosh**
To use Whoosh, set the following in your Realms config:
"SEARCH_TYPE": "whoosh"
"WHOOSH_INDEX": "/path/to/your/whoosh/index"
"WHOOSH_LANGUAGE": "en"
2015-07-01 23:44:38 +03:00
WHOOSH_INDEX has to be a path readable and writeable by Realm's user. It will be created automatically if it doesn't exist.
2014-11-21 18:24:49 +02:00
2015-07-01 23:44:38 +03:00
Whoosh is set up to use language optimization, so set WHOOSH_LANGUAGE to the language used in your wiki. For available languages, check `whoosh.lang.languages` .
2014-11-21 18:24:49 +02:00
If your language is not supported, Realms will fall back to a simple text analyzer.
2015-11-22 19:19:11 +02:00
## Authentication
### Local
Local default will be done using a backend database as defined in the config.
2015-11-23 01:12:26 +02:00
To disable local authentication, put the following your config.
"AUTH_LOCAL_ENABLE": false
2015-11-22 19:19:11 +02:00
### LDAP (beta)
Realms uses the following library to authenticate using LDAP. https://github.com/ContinuumIO/flask-ldap-login
It supports direct bind and bind by search.
Use these examples as a guide and place it in your realms-wiki.json config.
#### Bind By Search Example
In this example, BIND_DN and BIND_AUTH are used to search and authenticate. Leaving them blank implies anonymous authentication.
2015-11-23 01:12:26 +02:00
"LDAP": {
"URI": "ldap://localhost:8389",
"BIND_DN": "",
"BIND_AUTH": "",
"USER_SEARCH": {"base": "dc=realms,dc=io", "filter": "uid=%(username)s"},
"KEY_MAP": {
"username":"cn",
"email": "mail"
}
2015-11-22 19:19:11 +02:00
}
#### Direct Bind Example
2015-11-23 01:12:26 +02:00
"LDAP": {
"URI": "ldap://localhost:8389",
"BIND_DN": "uid=%(username)s,ou=People,dc=realms,dc=io",
"KEY_MAP": {
"username":"cn",
"email": "mail",
},
"OPTIONS": {
"OPT_PROTOCOL_VERSION": 3,
}
2015-11-22 19:19:11 +02:00
}
2015-11-23 01:12:26 +02:00
2015-11-22 19:19:11 +02:00
### OAuth (beta)
Realms currently supports Github, Twitter, Facebook and Google. Each provider requires a key and secret.
Put them in your `realms-wiki.json` config file. Use the example below.
2015-11-23 01:12:26 +02:00
"OAUTH": {
"twitter": {
"key": "",
"secret": ""
},
"github": {
"key": "",
"secret": ""
}
2015-11-22 19:19:11 +02:00
}
2016-09-05 23:54:53 +03:00
### Authentication by reverse proxy
If you configured realms behind a reverse-proxy or a single-sign-on, it is possible to delegate authentication to
the proxy.
"AUTH_PROXY": true
Note: of course with that setup you must ensure that **Realms is only accessible through the proxy** .
Example Nginx configuration:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header REMOTE_USER $remote_user;
proxy_pass http://127.0.0.1:5000/;
proxy_redirect off;
}
By default, Realms will look for the user ID in `REMOTE_USER` HTTP header. You can specify another header name with:
"AUTH_PROXY_HEADER_NAME": "LOGGED_IN_USER"
2014-09-04 06:25:48 +03:00
## Running
2014-10-17 22:30:00 +03:00
realms-wiki start
### Upstart
2015-07-01 23:44:38 +03:00
Setup upstart with this command:
2014-09-04 06:25:48 +03:00
2014-10-17 22:30:00 +03:00
sudo realms-wiki setup_upstart
2014-09-04 06:25:48 +03:00
2015-07-01 23:44:38 +03:00
This command requires root priveleges because it creates an upstart script.
Also note that ports below `1024` require user root.
2014-10-17 22:30:00 +03:00
After your config is in place use the following commands:
2014-09-04 06:25:48 +03:00
2014-10-17 22:30:00 +03:00
sudo start realms-wiki
sudo stop realms-wiki
sudo restart realms-wiki
2014-09-04 06:25:48 +03:00
2015-11-07 06:05:02 +02:00
### Development mode
2014-09-04 06:25:48 +03:00
2015-07-01 23:44:38 +03:00
This will start the server in the foreground with auto reloaded enabled:
2014-09-04 06:25:48 +03:00
2014-10-17 22:30:00 +03:00
realms-wiki dev
### Other commands
Usage: realms-wiki [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
auth
configure Set config.json, expects JSON encoded string
create_db Creates DB tables
dev Run development server
drop_db Drops DB tables
pip Execute pip commands, useful for virtualenvs
restart Restart server
run Run production server (alias for start)
setup Start setup wizard
setup_upstart Start upstart conf creation wizard
start Run server daemon
status Get server status
stop Stop server
test Run tests
version Output version
2014-09-04 06:25:48 +03:00
2015-07-01 23:44:38 +03:00
Access from your browser:
2014-09-04 06:25:48 +03:00
2014-09-04 16:59:19 +03:00
http://localhost:5000
2014-09-04 06:25:48 +03:00
2014-10-02 01:14:54 +03:00
## Templating
2014-09-04 16:06:22 +03:00
2015-07-01 23:44:38 +03:00
Realms uses Handlebars partials to create templates.
2014-10-03 21:49:18 +03:00
Each page that you create can be imported as a partial.
2014-10-02 01:14:54 +03:00
2014-10-03 21:49:18 +03:00
This page imports and uses a partial:
2014-10-02 01:14:54 +03:00
2014-10-17 22:30:00 +03:00
http://realms.io/_edit/hbs
2014-10-02 01:14:54 +03:00
2014-10-03 21:49:18 +03:00
This page contains the content of the partial:
2014-10-02 01:14:54 +03:00
2014-10-17 22:30:00 +03:00
http://realms.io/_edit/example-tmpl
2014-10-03 21:49:18 +03:00
I locked these pages to preserve them.
2015-07-01 23:44:38 +03:00
You can copy and paste into a new page for testing purposes.
2014-10-17 22:30:00 +03:00
## Contributing
Issues and pull requests are welcome.
2015-07-01 23:44:38 +03:00
Please follow the code style guide.
2014-10-17 22:30:00 +03:00
2016-05-28 04:10:43 +03:00
[Python style guide ](https://www.python.org/dev/peps/pep-0008/ )
2014-10-17 22:30:00 +03:00
2014-09-04 16:06:22 +03:00
## Author
Matthew Scragg < scragg @ gmail . com >
2014-09-10 22:37:48 +03:00
[gollum]: https://github.com/gollum/gollum
[ghost]: https://github.com/tryghost/Ghost
[dillinger]: https://github.com/joemccann/dillinger/