ee2f7e8095a37e9c2430c11b0d0305282bb4fbfb
[phorkie.git] / README.rst
1 ************************************
2 phorkie - PHP and Git based pastebin
3 ************************************
4 Self-hosted pastebin software written in PHP.
5 Pastes are editable, may have multiple files and are stored in git repositories.
6
7 Project page: http://sourceforge.net/p/phorkie/
8
9 .. contents:: Table of Contents
10
11 ========
12 Features
13 ========
14 - every paste is a git repository
15
16   - repositories can be cloned
17   - clone url can be displayed
18   - remote pastes can be forked (rel="vcs-git" and gist.github.com)
19 - paste editing
20
21   - add new files
22   - delete existing files
23   - replace file with upload
24 - multiple files in one paste
25 - syntax highlighting with GeSHi
26 - rST and Markdown rendering
27 - image upload + display
28 - OpenID authentication
29 - external tool support
30
31   - xmllint
32   - php syntax check
33 - history in the sidebar
34
35   - old files can be downloaded easily
36 - search across pastes: description, file names and file content
37
38   - options: quoting, logical and, or, not, partial words
39
40
41 ============
42 Installation
43 ============
44 1. Unzip the phorkie release file::
45
46    $ tar xjvf phorkie-0.3.0.tar.bz2
47
48 2. Create the git directories::
49
50    $ mkdir -p repos/git repos/work
51    $ chmod og+w repos/git repos/work
52
53 3. Install dependencies_
54
55 4. Copy ``data/config.php.dist`` to ``data/config.php`` and adjust it
56    to your needs::
57
58    $ cp data/config.php.dist data/config.php
59    $ $EDITOR data/config.php
60
61    Look at ``config.default.php`` for values that you may adjust.
62
63 5. Set your web server's document root to ``/path/to/phorkie/www/``
64
65 6. Open phorkie in your web browser
66
67
68 Dependencies
69 ============
70 phorkie stands on the shoulders of giants.
71
72 It requires the following programs to be installed
73 on your machine:
74
75 - Git v1.7.5 or later
76 - PHP v5.3.0 or later
77 - PEAR v1.9.2 or later
78
79 ::
80
81   $ pear install versioncontrol_git-alpha
82   $ pear install services_libravatar-alpha
83   $ pear install http_request2
84   $ pear install pager
85   $ pear install date_humandiff-alpha
86
87   $ pear channel-discover pear.twig-project.org
88   $ pear install twig/Twig
89
90   $ pear channel-discover mediawiki.googlecode.com/svn
91   $ pear install mediawiki/geshi
92
93   $ pear channel-discover zustellzentrum.cweiske.de
94   $ pear install zz/mime_type_plaindetect-alpha
95
96   $ pear channel-discover pear.michelf.ca
97   $ pear install michelf/Markdown
98
99 Note that this version of GeSHi is a bit outdated, but it's the fastest
100 way to install it.
101 If you install it manually be sure to update the
102 path from ``data/config.default.php``.
103
104
105 ======
106 Search
107 ======
108
109 phorkie makes use of an Elasticsearch__ installation, if you have one.
110
111 It is used to provide search capabilities and the list of recent pastes.
112
113 __ http://www.elasticsearch.org/
114
115 Setup
116 =====
117 Edit ``config.php``, setting the ``elasticsearch`` property to the HTTP URL
118 of the index, e.g. ::
119
120   http://localhost:9200/phorkie/
121
122 Run the index script to import all existing pastes into the index::
123
124   php scripts/index.php
125
126 That's all. Open phorkie in your browser, and you'll notice the search box
127 in the top menu.
128
129
130 Reset
131 =====
132 In case something really went wrong and you need to reset the search
133 index, run the following command::
134
135   $ curl -XDELETE http://localhost:9200/phorkie/
136   {"ok":true,"acknowledged"}
137
138 Phorkie will automatically re-index everything when ``setupcheck`` is enabled
139 in the configuration file.
140
141 You may also manually run the reindexing script with::
142
143   $ php scripts/index.php
144
145
146 =====
147 HowTo
148 =====
149
150 Make git repositories clonable
151 ==============================
152 To make git repositories clonable, you need to install ``git-daemon``
153 (``git-daemon-run`` package on Debian/Ubuntu).
154
155 Make the repositories available by symlinking the paste repository
156 directory (``$GLOBALS['phorkie']['cfg']['repos']`` setting) into
157 ``/var/cache/git``, e.g.::
158
159   $ ln -s /home/user/www/paste/repos/git /var/cache/git/paste
160
161 Edit your ``config.php`` and set the ``$GLOBALS['phorkie']['cfg']['git']['public']``
162 setting to ``git://$yourhostname/git/paste/``.
163 The rest will be appended automatically.
164
165
166 You're on your own to setup writable repositories.
167
168
169 Protect your site with OpenID
170 =============================
171 You have the option of enabling OpenID authentication to help secure your
172 pastes on phorkie.
173 Set the ``$GLOBALS['phorkie']['auth']`` values in the
174 ``data/config.php`` file as desired.
175
176 There are two different types of security you can apply.
177 First, you can restrict to one of three ``securityLevels``:
178
179 - completely open (``0``)
180 - protection of write-enabled functions such as add, edit, etc. (``1``)
181 - full site protection (``2``)
182
183 Additionally, you can restrict your site to ``listedUsersOnly``.
184 You will need to add the individual OpenID urls to the
185 ``$GLOBALS['phorkie']['auth']['users']`` variable.
186
187
188 Get information about paste editors
189 ===================================
190 Phorkie stores the user's OpenID or IP address (when not logged in) when
191 a paste is edited.
192 It is possible to get this information for each single commit::
193
194     // IP / OpenID for the latest commit
195     $ git notes --ref=identity show
196     127.0.0.1
197
198     // show IP / OpenID for a given commit
199     $ git notes --ref=identity show 29f82a
200     http://cweiske.de/
201
202
203 =================
204 Technical details
205 =================
206
207 TODO
208 ====
209 - filters (``xmllint --format``, ``rapper``)
210 - document how to keep disk usage low (block size)
211 - comments
212 - when 2 people edit, merge changes
213 - diff changes
214 - configurable highlights
215 - Atom feed for new pastes
216 - Atom feed for paste changes
217
218
219 URLs
220 ====
221
222 ``/``
223   Index page.
224 ``/[0-9]+``
225   Display page for paste
226 ``/[0-9]/edit``
227   Edit the paste
228 ``/[0-9]+/raw/(.+)``
229   Display raw file contents
230 ``/[0-9]/tool/[a-zA-Z]+/(.+)``
231   Run a tool on the given file
232 ``/[0-9]/rev/[a-z0-9]+``
233   Show specific revision of the paste
234 ``/[0-9]/delete``
235   Delete the paste
236 ``/[0-9]/doap``
237   Show DOAP document for paste
238 ``/[0-9]/fork``
239   Create a fork of the paste
240 ``/search?q=..(&page=[0-9]+)?``
241   Search for term, with optional page
242 ``/list(/[0-9])?``
243   List all pastes, with optional page
244 ``/new``
245   Shows form for new paste
246 ``/login``
247   Login page for protecting site
248 ``/user``
249   Edit logged-in user information
250
251
252 Internal directory layout
253 =========================
254 ::
255
256   repos/
257     work/
258       1/ - work directory for paste #1
259       2/ - work directory for paste #2
260     git/
261       1.git/ - git repository for paste #1
262         description - Description for the repository
263       2.git/ - git repository for paste #2
264
265 nginx rewrites
266 ==============
267 If you use nginx, place the following lines into your ``server`` block:
268
269 ::
270
271   if (!-e $request_uri) {
272     rewrite ^/([0-9]+)$ /display.php?id=$1;
273     rewrite ^/([0-9]+)/delete$ /delete.php?id=$1;
274     rewrite ^/([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1;
275     rewrite ^/([0-9]+)/doap$ /doap.php?id=$1;
276     rewrite ^/([0-9]+)/edit$ /edit.php?id=$1;
277     rewrite ^/([0-9]+)/fork$ /fork.php?id=$1;
278     rewrite ^/([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2;
279     rewrite ^/([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2;
280     rewrite ^/([0-9]+)/rev-raw/(.+)$ /raw.php?id=$1&rev=$2&file=$3;
281     rewrite ^/([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3;
282
283     rewrite ^/new$ /new.php;
284     rewrite ^/list$ /list.php;
285     rewrite ^/list/([0-9]+)$ /list.php?page=$1;
286
287     rewrite ^/search$ /search.php;
288     rewrite ^/search/([0-9]+)$ /search.php?page=$1;
289
290     rewrite ^/login$ /login.php;
291     rewrite ^/user$ /user.php;
292   }