rev |
line source |
pankso@5
|
1 #!/bin/sh
|
pankso@5
|
2 #
|
paul@64
|
3 # TinyCM - Small, fast and elegant CGI/SHell Content Manager
|
pankso@5
|
4 #
|
pankso@76
|
5 # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
|
pankso@5
|
6 #
|
pankso@84
|
7 . /usr/lib/slitaz/httphelper.sh
|
pankso@5
|
8
|
paul@8
|
9 # Let's have a peer site config file with a .cgi extension so content
|
pankso@5
|
10 # is secure even if left in a web server directory.
|
pankso@57
|
11 . ./config.cgi
|
pankso@5
|
12
|
pankso@5
|
13 tiny="$PWD"
|
pankso@5
|
14 content="content"
|
pankso@5
|
15 wiki="$content/wiki"
|
pankso@5
|
16 index="index"
|
pankso@5
|
17 cache="cache"
|
pankso@5
|
18 plugins="plugins"
|
pankso@5
|
19 tmp="/tmp/tinycm"
|
pankso@5
|
20 sessions="$tmp/sessions"
|
pankso@15
|
21 script="$SCRIPT_NAME"
|
pankso@28
|
22 activity="$cache/log/activity.log"
|
pankso@5
|
23
|
pankso@5
|
24 # Content negotiation for Gettext
|
pankso@5
|
25 IFS=","
|
pankso@5
|
26 for lang in $HTTP_ACCEPT_LANGUAGE
|
pankso@5
|
27 do
|
pankso@5
|
28 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
|
pankso@5
|
29 case "$lang" in
|
pankso@57
|
30 en) lang="C" && break ;;
|
pankso@57
|
31 fr) lang="fr_FR" && break ;;
|
pankso@57
|
32 pt) lang="pt_BR" && break ;;
|
pankso@57
|
33 ru) lang="ru_RU" && break ;;
|
pankso@5
|
34 esac
|
pankso@5
|
35 done
|
pankso@5
|
36 unset IFS
|
pankso@5
|
37 export LANG=$lang LC_ALL=$lang
|
pankso@5
|
38
|
pankso@55
|
39 # Internationalization
|
pankso@55
|
40 . /usr/bin/gettext.sh
|
pankso@55
|
41 TEXTDOMAIN='tinycm'
|
pankso@55
|
42 export TEXTDOMAIN
|
pankso@55
|
43
|
pankso@5
|
44 #
|
pankso@5
|
45 # Functions
|
pankso@5
|
46 #
|
pankso@5
|
47
|
paul@8
|
48 # Used by edit to display language name and the language box. This is
|
pankso@5
|
49 # for CM content not gettext support.
|
pankso@5
|
50 get_lang() {
|
pankso@57
|
51 dlang=$(echo $d | cut -d "/" -f 1)
|
pankso@57
|
52 doc=${d#$dlang/}
|
pankso@5
|
53 echo '<div id="lang">'
|
pankso@5
|
54 for l in $LANGUAGES
|
pankso@5
|
55 do
|
pankso@57
|
56 case $dlang in
|
pankso@5
|
57 en) i18n="English" ;;
|
pankso@5
|
58 fr) i18n="Français" ;;
|
pankso@5
|
59 pt) i18n="Português" ;;
|
pankso@5
|
60 ru) i18n="Русский" ;;
|
pankso@5
|
61 *) i18n="*" ;;
|
pankso@5
|
62 esac
|
pankso@5
|
63 echo "<a href='?d=$l/$doc'>$l</a>"
|
pankso@5
|
64 done
|
pankso@5
|
65 echo '</div>'
|
pankso@5
|
66 }
|
pankso@5
|
67
|
pankso@5
|
68 # HTML 5 header.
|
pankso@5
|
69 html_header() {
|
pankso@5
|
70 if [ -f "$tiny/lib/header.html" ]; then
|
pankso@5
|
71 cat $tiny/lib/header.html | sed -e s!'%TITLE%'!"$TITLE - $d"!g
|
pankso@5
|
72 else
|
pankso@5
|
73 cat << EOT
|
pankso@5
|
74 <!DOCTYPE html>
|
pankso@5
|
75 <html xmlns="http://www.w3.org/1999/xhtml">
|
pankso@5
|
76 <head>
|
pankso@5
|
77 <title>$TITLE</title>
|
pankso@5
|
78 <meta charset="utf-8" />
|
pankso@5
|
79 <style type="text/css">body { margin: 40px 120px; }</style>
|
pankso@5
|
80 </head>
|
pankso@5
|
81 <body>
|
pankso@5
|
82 <!-- Content -->
|
pankso@5
|
83 <div id="content">
|
pankso@5
|
84 EOT
|
pankso@5
|
85 fi
|
pankso@5
|
86 }
|
pankso@5
|
87
|
pankso@5
|
88 # HTML 5 footer.
|
pankso@5
|
89 html_footer() {
|
pankso@5
|
90 if [ -f "$tiny/lib/footer.html" ]; then
|
pankso@5
|
91 cat $tiny/lib/footer.html
|
pankso@5
|
92 else
|
pankso@5
|
93 cat << EOT
|
pankso@5
|
94
|
pankso@5
|
95 <!-- End content -->
|
pankso@5
|
96 </div>
|
pankso@5
|
97
|
pankso@63
|
98 <div id="footer">
|
pankso@63
|
99 I ♥ <a href="http://tinycm.slitaz.org/">TinyCM</a>
|
pankso@63
|
100 </div>
|
pankso@5
|
101
|
pankso@5
|
102 </body>
|
pankso@5
|
103 </html>
|
pankso@5
|
104 EOT
|
pankso@5
|
105 fi
|
pankso@5
|
106 }
|
pankso@5
|
107
|
pankso@5
|
108 # Default index if missing
|
pankso@5
|
109 default_index() {
|
pankso@11
|
110 mkdir -p "$wiki"
|
pankso@5
|
111 cat > $wiki/$index.txt << EOT
|
pankso@5
|
112 ==== Welcome ====
|
pankso@5
|
113
|
pankso@36
|
114 <p>
|
pankso@32
|
115 This is the default index page of your TinyCM, you can login then start to
|
paul@80
|
116 edit and add some content. You can read the help about text formating
|
pankso@48
|
117 and functions: [Help page|en/help]
|
pankso@36
|
118 </p>
|
pankso@5
|
119
|
pankso@5
|
120 EOT
|
pankso@5
|
121 }
|
pankso@5
|
122
|
pankso@28
|
123 # Log main activity.
|
pankso@28
|
124 log_activity() {
|
pankso@28
|
125 [ -d "$cache/log" ] || mkdir -p ${cache}/log
|
pankso@28
|
126 #gravatar="$(get_gravatar $MAIL 24)"
|
pankso@28
|
127 grep ^[A-Z] | \
|
pankso@28
|
128 sed s"#^[A-Z]\([^']*\)#$user|$(date '+%Y-%m-%d')|\0#" \
|
pankso@28
|
129 >> $cache/log/activity.log
|
pankso@28
|
130 }
|
pankso@28
|
131
|
pankso@5
|
132 # Log documents activity.
|
pankso@5
|
133 log() {
|
pankso@5
|
134 grep ^[A-Z] | \
|
pankso@5
|
135 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" \
|
pankso@5
|
136 >> $cache/$d/activity.log
|
pankso@5
|
137 }
|
pankso@5
|
138
|
pankso@5
|
139 # Check if user is auth
|
pankso@5
|
140 check_auth() {
|
pankso@5
|
141 auth="$(COOKIE auth)"
|
pankso@5
|
142 user="$(echo $auth | cut -d ":" -f 1)"
|
pankso@5
|
143 md5cookie="$(echo $auth | cut -d ":" -f 2)"
|
pankso@5
|
144 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
|
pankso@5
|
145 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
|
pankso@5
|
146 . $PEOPLE/$user/account.conf
|
pankso@5
|
147 return 0
|
pankso@5
|
148 else
|
pankso@5
|
149 return 1
|
pankso@5
|
150 fi
|
pankso@5
|
151 }
|
pankso@5
|
152
|
pankso@28
|
153 # Check if user is admin
|
pankso@28
|
154 admin_user() {
|
pankso@106
|
155 grep -w -q "$user" ${ADMIN_USERS}
|
pankso@28
|
156 }
|
pankso@28
|
157
|
paul@64
|
158 # Authenticated or not
|
pankso@5
|
159 user_box() {
|
pankso@5
|
160 if check_auth; then
|
pankso@5
|
161 cat << EOT
|
pankso@5
|
162
|
pankso@5
|
163 <div id="user">
|
pankso@5
|
164 <a href="$script?user=$user">$(get_gravatar $MAIL 20)</a>
|
pankso@5
|
165 <a href="$script?logout">Logout</a>
|
pankso@5
|
166 </div>
|
pankso@5
|
167
|
pankso@5
|
168 EOT
|
pankso@5
|
169 else
|
pankso@5
|
170 cat << EOT
|
pankso@5
|
171
|
pankso@5
|
172 <div id="user">
|
pankso@5
|
173 <a href="$script?login"><img src="images/avatar.png" alt="[ User ]" /></a>
|
pankso@5
|
174 <a href="$script?login">Login</a>
|
pankso@5
|
175 </div>
|
pankso@5
|
176
|
pankso@5
|
177 EOT
|
pankso@5
|
178 fi
|
pankso@5
|
179 cat << EOT
|
pankso@5
|
180 <!--
|
pankso@5
|
181 <div id="search">
|
pankso@5
|
182 <form method="get" action="$script">
|
pankso@5
|
183 <input type="text" name="search" placeholder="$(gettext "Search")" />
|
pankso@5
|
184 </form>
|
pankso@5
|
185 </div>
|
pankso@5
|
186 -->
|
pankso@5
|
187 EOT
|
pankso@5
|
188 }
|
pankso@5
|
189
|
pankso@5
|
190 # Link for online signup if enabled.
|
pankso@5
|
191 online_signup() {
|
pankso@5
|
192 if [ "$ONLINE_SIGNUP" == "yes" ]; then
|
pankso@5
|
193 echo -n "<p><a href='$script?signup'>"
|
pankso@5
|
194 gettext "Create a new account"
|
pankso@5
|
195 echo '</a></p>'
|
pankso@5
|
196 fi
|
pankso@5
|
197 }
|
pankso@5
|
198
|
pankso@5
|
199 # Login page
|
pankso@5
|
200 login_page() {
|
pankso@5
|
201 cat << EOT
|
pankso@5
|
202 <h2>$(gettext "Login")</h2>
|
pankso@5
|
203
|
pankso@5
|
204 <div id="account-info">
|
paul@61
|
205 $(gettext "No account yet or trouble with your account? Please send
|
pankso@5
|
206 a request to $ADMIN_MAIL with your real name, user name, mail and password.")
|
pankso@5
|
207 $(online_signup)
|
pankso@5
|
208 </div>
|
pankso@5
|
209
|
pankso@5
|
210 <div id="login">
|
pankso@5
|
211 <form method="post" action="$script">
|
pankso@5
|
212 <input type="text" name="auth" placeholder="$(gettext "User name")" />
|
pankso@5
|
213 <input type="password" name="pass" placeholder="$(gettext "Password")" />
|
pankso@5
|
214 <div>
|
pankso@5
|
215 <input type="submit" value="Login" /> $error
|
pankso@5
|
216 </div>
|
pankso@5
|
217 </form>
|
pankso@5
|
218 </div>
|
pankso@5
|
219
|
pankso@5
|
220 <div style="clear: both;"></div>
|
pankso@5
|
221 EOT
|
pankso@5
|
222 }
|
pankso@5
|
223
|
pankso@5
|
224 # Signup page
|
pankso@5
|
225 signup_page() {
|
pankso@5
|
226 cat << EOT
|
pankso@5
|
227
|
pankso@5
|
228 <div id="signup">
|
pankso@5
|
229 <form method="post" name="signup" action="$script" onsubmit="return checkSignup();">
|
pankso@5
|
230 <input type="hidden" name="signup" value="new" />
|
pankso@5
|
231 <input type="text" name="name" placeholder="$(gettext "Real name")" />
|
pankso@5
|
232 <input type="text" name="user" placeholder="$(gettext "User name")" />
|
pankso@5
|
233 <input type="text" name="mail" placeholder="$(gettext "Email")" />
|
pankso@5
|
234 <input type="password" name="pass" placeholder="$(gettext "Password")" />
|
pankso@5
|
235 <div>
|
pankso@5
|
236 <input type="submit" value="$(gettext "Create new account")" />
|
pankso@5
|
237 </div>
|
pankso@5
|
238 </form>
|
pankso@5
|
239 </div>
|
pankso@5
|
240
|
pankso@5
|
241 EOT
|
pankso@5
|
242 }
|
pankso@5
|
243
|
pankso@5
|
244 # Create a new user in AUTH_FILE and PEOPLE
|
pankso@5
|
245 new_user_config() {
|
pankso@106
|
246 if [ ! -f "$AUTH_FILE" ]; then
|
pankso@106
|
247 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
|
pankso@20
|
248 fi
|
pankso@5
|
249 echo "$user:$pass" >> $AUTH_FILE
|
pankso@106
|
250 mkdir -pm0700 $PEOPLE/${user}
|
pankso@5
|
251 cat > $PEOPLE/$user/account.conf << EOT
|
pankso@104
|
252 # User configuration
|
pankso@5
|
253 NAME="$name"
|
pankso@5
|
254 USER="$user"
|
pankso@5
|
255 MAIL="$mail"
|
pankso@5
|
256 EOT
|
pankso@106
|
257 chmod 0600 $PEOPLE/$user/account.conf
|
pankso@28
|
258 # First created user is admin
|
pankso@28
|
259 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
|
pankso@104
|
260 echo "$user" > ${ADMIN_USERS}
|
pankso@28
|
261 fi
|
pankso@5
|
262 }
|
pankso@5
|
263
|
paul@64
|
264 # The CM style parser. Just a title, simple text formatting and internal
|
paul@8
|
265 # links, as well as images and use HTML for other stuff. Keep it fast!
|
pankso@5
|
266 # To make TinyCM as easy as possible we have a small HTML editor/helper
|
pankso@5
|
267 # written in Javascript
|
pankso@5
|
268 wiki_parser() {
|
pankso@5
|
269 doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
|
pankso@5
|
270 sed \
|
pankso@5
|
271 -e s"#====\([^']*\)====#<h2>\1</h2>#"g \
|
pankso@5
|
272 -e s"#===\([^']*\)===#<h3>\1</h3>#"g \
|
pankso@5
|
273 -e s"#==\([^']*\)==#<h4>\1</h4>#"g \
|
pankso@13
|
274 -e s"#\*\*\([^']*\)\*\*#<b>\1</b>#"g \
|
pankso@5
|
275 -e s"#''\([^']*\)''#<em>\1</em>#"g \
|
pankso@5
|
276 -e s"#__\([^']*\)__#<u>\1</u>#"g \
|
pankso@5
|
277 -e s"#\[\([^]]*\)|\($doc\)\]#<a href='$script?d=\2'>\1</a>#"g \
|
pankso@17
|
278 -e s"#\[\([^]]*\)!\($doc\)\]#<a href='\2'>\1</a>#"g \
|
pankso@17
|
279 -e s"#\[\(http://*[^]]*.png\)\]#<img src='\1' />#"g \
|
pankso@91
|
280 -e s"#\[\([^]]*.png\)\]#<img src='content/cloud/\1' />#"g \
|
pankso@91
|
281 -e s"#@\([^']*\)@#<a href='$script?user=\1'>\1</a>#"g
|
pankso@5
|
282 }
|
pankso@5
|
283
|
pankso@5
|
284 link_user() {
|
pankso@15
|
285 echo "<a href='$(basename $script)?user=$user'>$user</a>"
|
pankso@5
|
286 }
|
pankso@5
|
287
|
pankso@5
|
288 # Save a document. Do we need more than 1 backup and diff ?
|
pankso@5
|
289 save_document() {
|
pankso@5
|
290 mkdir -p $cache/$d $(dirname $wiki/$d)
|
pankso@5
|
291 # May be a new page.
|
pankso@5
|
292 if [ ! -f "$wiki/$d.txt" ]; then
|
pankso@5
|
293 new=0
|
pankso@5
|
294 touch $wiki/$d.txt
|
pankso@5
|
295 fi
|
pankso@5
|
296 cp $wiki/$d.txt $cache/$d/last.bak
|
pankso@5
|
297 sed "s/$(echo -en '\r') /\n/g" > $wiki/$d.txt << EOT
|
pankso@5
|
298 $(GET content)
|
pankso@5
|
299 EOT
|
pankso@5
|
300 diff $cache/$d/last.bak $wiki/$d.txt > $cache/$d/last.diff
|
pankso@5
|
301 # Log
|
pankso@5
|
302 if [ "$new" ]; then
|
pankso@5
|
303 echo "Page created by: $(link_user)" | log
|
pankso@31
|
304 echo "New document: <a href='$script?d=$d'>$d</a>" | log_activity
|
pankso@5
|
305 if [ "$HG" == "yes" ]; then
|
pankso@5
|
306 cd $content && hg -q add
|
pankso@5
|
307 hg commit -q -u "$NAME <$MAIL>" -m "Created new document: $d"
|
pankso@5
|
308 cd $tiny
|
pankso@5
|
309 fi
|
pankso@5
|
310 else
|
pankso@28
|
311 # Here we may clean log: cat && tail -n 40
|
pankso@5
|
312 echo "Page edited by: $(link_user)" | log
|
pankso@5
|
313 if [ "$HG" == "yes" ]; then
|
pankso@5
|
314 cd $content && hg commit -q -u "$NAME <$MAIL>" \
|
pankso@5
|
315 -m "Edited document: $d"
|
pankso@5
|
316 cd $tiny
|
pankso@5
|
317 fi
|
pankso@5
|
318 fi
|
pankso@5
|
319 }
|
pankso@5
|
320
|
pankso@52
|
321 # CM tools (edit, diff, etc) for auth users
|
pankso@5
|
322 wiki_tools() {
|
pankso@52
|
323 if check_auth; then
|
pankso@52
|
324 cat << EOT
|
pankso@5
|
325 <div id="tools">
|
pankso@5
|
326 <a href="$script?edit=$d">$(gettext "Edit document")</a>
|
pankso@59
|
327 <a href="$script?log=$d">$(gettext "File log")</a>
|
pankso@5
|
328 <a href="$script?diff=$d">$(gettext "Last diff")</a>
|
pankso@59
|
329 $PLUGINS_TOOLS
|
pankso@52
|
330 EOT
|
pankso@52
|
331 [ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>"
|
pankso@52
|
332 echo "</div>"
|
pankso@52
|
333 fi
|
pankso@52
|
334 }
|
pankso@52
|
335
|
pankso@59
|
336 # Built-in tools such as log/ls and PLUGINS_TOOLS
|
pankso@59
|
337 tiny_tools() {
|
pankso@52
|
338 if check_auth; then
|
pankso@52
|
339 cat << EOT
|
pankso@52
|
340 <div id='tools'>
|
pankso@52
|
341 <a href='$script?log'>Activity log</a>
|
pankso@52
|
342 <a href='$script?ls'>Pages list</a>
|
pankso@59
|
343 $PLUGINS_TOOLS
|
pankso@5
|
344 </div>
|
pankso@5
|
345 EOT
|
pankso@52
|
346 fi
|
pankso@5
|
347 }
|
pankso@5
|
348
|
pankso@5
|
349 # Get and display Gravatar image: get_gravatar email size
|
pankso@5
|
350 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
|
pankso@5
|
351 get_gravatar() {
|
pankso@5
|
352 email=$1
|
pankso@5
|
353 size=$2
|
pankso@5
|
354 [ "$size" ] || size=48
|
pankso@5
|
355 url="http://www.gravatar.com/avatar"
|
pankso@5
|
356 md5=$(md5crypt $email)
|
pankso@5
|
357 echo "<img src='$url/$md5?d=identicon&s=$size' alt='∗' />"
|
pankso@5
|
358 }
|
pankso@5
|
359
|
pankso@5
|
360 # List hg logs
|
pankso@5
|
361 hg_log() {
|
pankso@5
|
362 cd $content
|
pankso@5
|
363 cat << EOT
|
pankso@5
|
364 <table>
|
pankso@5
|
365 <thead>
|
pankso@5
|
366 <td>$(gettext "User")</td>
|
pankso@5
|
367 <td>$(gettext "Description")</td>
|
pankso@5
|
368 <td>$(gettext "Revision")</td>
|
pankso@5
|
369 </thead>
|
pankso@5
|
370 EOT
|
pankso@5
|
371 hg log --template "<tr><td>{author}</td><td>{desc}</td><td>{rev}</td></tr>\n"
|
pankso@5
|
372 echo '</table>'
|
pankso@5
|
373 }
|
pankso@5
|
374
|
pankso@5
|
375 #
|
pankso@5
|
376 # POST actions
|
pankso@5
|
377 #
|
pankso@5
|
378
|
pankso@5
|
379 case " $(POST) " in
|
pankso@5
|
380 *\ auth\ *)
|
pankso@5
|
381 # Authenticate user. Create a session file in $sessions to be used
|
pankso@5
|
382 # by check_auth. We have the user login name and a peer session
|
pankso@5
|
383 # md5 string in the COOKIE.
|
pankso@5
|
384 user="$(POST auth)"
|
pankso@5
|
385 pass="$(md5crypt "$(POST pass)")"
|
pankso@5
|
386 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
|
pankso@5
|
387 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
|
pankso@5
|
388 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
|
pankso@5
|
389 [ -d $sessions ] || mkdir -p $sessions
|
pankso@36
|
390 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
|
pankso@5
|
391 echo "$md5session" > $sessions/$user
|
pankso@5
|
392 header "Location: $script" \
|
pankso@5
|
393 "Set-Cookie: auth=$user:$md5session; HttpOnly"
|
pankso@5
|
394 else
|
pankso@5
|
395 header "Location: $script?login&error"
|
pankso@5
|
396 fi ;;
|
pankso@5
|
397 *\ signup\ *)
|
pankso@5
|
398 # POST action for signup
|
pankso@5
|
399 name="$(POST name)"
|
pankso@5
|
400 user="$(POST user)"
|
pankso@5
|
401 mail="$(POST mail)"
|
pankso@5
|
402 pass="$(md5crypt "$(POST pass)")"
|
pankso@5
|
403 if ! grep "^${user}:" $AUTH_FILE; then
|
pankso@5
|
404 new_user_config
|
pankso@5
|
405 header "Location: $script?login"
|
pankso@5
|
406 else
|
pankso@5
|
407 header
|
pankso@5
|
408 html_header
|
pankso@5
|
409 user_box
|
pankso@44
|
410 echo "<h2>$(gettext 'User already exists:') $user</h2>"
|
pankso@5
|
411 html_footer
|
pankso@5
|
412 fi ;;
|
pankso@5
|
413 esac
|
pankso@5
|
414
|
pankso@5
|
415 #
|
pankso@5
|
416 # Plugins
|
pankso@5
|
417 #
|
pankso@5
|
418 for p in $(ls -1 $plugins)
|
pankso@5
|
419 do
|
pankso@5
|
420 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
|
pankso@5
|
421 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
|
pankso@5
|
422 done
|
pankso@5
|
423
|
pankso@5
|
424 #
|
pankso@5
|
425 # GET actions
|
pankso@5
|
426 #
|
pankso@5
|
427
|
pankso@5
|
428 case " $(GET) " in
|
pankso@5
|
429 *\ edit\ *)
|
pankso@5
|
430 d="$(GET edit)"
|
pankso@5
|
431 header
|
pankso@5
|
432 html_header
|
pankso@5
|
433 user_box
|
pankso@5
|
434 get_lang
|
pankso@59
|
435 wiki_tools
|
pankso@5
|
436 if check_auth; then
|
pankso@5
|
437 cat << EOT
|
pankso@5
|
438 <h2>$(gettext "Edit $doc [ $i18n ]")</h2>
|
pankso@5
|
439
|
pankso@5
|
440 <div id="edit">
|
pankso@5
|
441
|
pankso@5
|
442 <form method="get" action="$script" name="editor">
|
pankso@5
|
443 <input type="hidden" name="save" value="$d" />
|
pankso@5
|
444 <textarea name="content">$(cat "$wiki/$d.txt")</textarea>
|
pankso@5
|
445 <input type="submit" value="$(gettext "Save document")" />
|
pankso@5
|
446 $(gettext "Code Helper:")
|
pankso@5
|
447 $(cat lib/jseditor.html)
|
pankso@5
|
448 </form>
|
pankso@5
|
449
|
pankso@5
|
450 </div>
|
pankso@5
|
451 EOT
|
pankso@5
|
452 else
|
paul@8
|
453 gettext "You must be logged in to edit pages"
|
pankso@5
|
454 fi
|
pankso@5
|
455 html_footer ;;
|
pankso@15
|
456
|
pankso@5
|
457 *\ save\ *)
|
pankso@5
|
458 d="$(GET save)"
|
pankso@5
|
459 if check_auth; then
|
pankso@76
|
460 save_document
|
pankso@5
|
461 fi
|
pankso@5
|
462 header "Location: $script?d=$d" ;;
|
pankso@15
|
463
|
pankso@5
|
464 *\ log\ *)
|
pankso@5
|
465 d="$(GET log)"
|
pankso@5
|
466 header
|
pankso@5
|
467 html_header
|
pankso@5
|
468 user_box
|
pankso@28
|
469 # Main activity
|
pankso@28
|
470 if [ "$d" == "log" ]; then
|
pankso@59
|
471 tiny_tools
|
pankso@52
|
472 echo "<h2>$(gettext "Activity log")</h2>"
|
pankso@28
|
473 echo '<pre>'
|
pankso@28
|
474 if [ -f "$cache/log/activity.log" ]; then
|
pankso@28
|
475 IFS="|"
|
pankso@28
|
476 tac $cache/log/activity.log | while read USER DATE LOG
|
pankso@28
|
477 do
|
pankso@28
|
478 . ${PEOPLE}/${USER}/account.conf
|
pankso@28
|
479 cat << EOT
|
pankso@28
|
480 <a href='$script?user=$USER'>$(get_gravatar $MAIL 24)</a>\
|
pankso@28
|
481 <span class='date'>$DATE -</span> $LOG
|
pankso@28
|
482 EOT
|
pankso@28
|
483 done
|
pankso@28
|
484 unset IFS
|
pankso@28
|
485 else
|
pankso@28
|
486 gettext "No activity log yet"; echo
|
pankso@28
|
487 fi
|
pankso@28
|
488 echo '</pre>'
|
pankso@28
|
489 html_footer && exit 0
|
pankso@28
|
490 fi
|
pankso@52
|
491 # Document activity
|
pankso@5
|
492 get_lang
|
pankso@52
|
493 wiki_tools
|
pankso@5
|
494 echo "<h2>$(gettext "Activity for:") <a href='$script?d=$d'>$d</a></h2>"
|
pankso@5
|
495 echo '<pre>'
|
pankso@5
|
496 if [ -f "$cache/$d/activity.log" ]; then
|
pankso@5
|
497 tac $cache/$d/activity.log
|
pankso@5
|
498 else
|
pankso@5
|
499 gettext "No log for: $d"; echo
|
pankso@5
|
500 fi
|
pankso@5
|
501 echo '</pre>'
|
pankso@5
|
502 html_footer ;;
|
pankso@28
|
503
|
pankso@28
|
504 *\ ls\ *)
|
pankso@28
|
505 d="Document list"
|
pankso@28
|
506 header
|
pankso@28
|
507 html_header
|
pankso@28
|
508 user_box
|
pankso@59
|
509 tiny_tools
|
pankso@59
|
510 [ ! check_auth ] && auth=0
|
pankso@48
|
511 echo "<h2>$(gettext "Pages list")</h2>"
|
pankso@28
|
512 echo '<pre>'
|
pankso@28
|
513 cd ${wiki}
|
pankso@28
|
514 for d in $(find . -type f | sed s'/.\///')
|
pankso@28
|
515 do
|
pankso@65
|
516 echo -n "<a href='$script?d=${d%.txt}'>${d%.txt}</a>"
|
pankso@65
|
517 if [ "$auth" ]; then
|
pankso@65
|
518 cat << EOT
|
pankso@65
|
519 : <a href="$script?edit=$d">$(gettext "Edit")</a> || \
|
pankso@65
|
520 <a href="$script?rm=$d">$(gettext "Remove")</a>
|
pankso@48
|
521 EOT
|
pankso@65
|
522 else
|
pankso@65
|
523 echo ""
|
pankso@65
|
524 fi
|
pankso@59
|
525 done && unset auth
|
pankso@28
|
526 echo '</pre>'
|
pankso@28
|
527 html_footer ;;
|
pankso@48
|
528
|
pankso@48
|
529 *\ rm\ *)
|
pankso@59
|
530 [ ! check_auth ] && exit 1
|
pankso@48
|
531 d="$(GET rm)"
|
pankso@48
|
532 rm ${wiki}/"${d}"
|
pankso@48
|
533 rm -rf ${cache}/"${d%.txt}"
|
pankso@48
|
534 header "Location: $script?ls" ;;
|
pankso@15
|
535
|
pankso@5
|
536 *\ diff\ *)
|
pankso@5
|
537 d="$(GET diff)"
|
pankso@5
|
538 date="last"
|
pankso@5
|
539 header
|
pankso@5
|
540 html_header
|
pankso@5
|
541 user_box
|
pankso@5
|
542 get_lang
|
pankso@52
|
543 wiki_tools
|
pankso@5
|
544 echo "<h2>$(gettext "Diff for:") <a href='$script?d=$d'>$d</a></h2>"
|
pankso@5
|
545 echo '<pre>'
|
pankso@5
|
546 if [ -f "$cache/$d/$date.diff" ]; then
|
pankso@5
|
547 cat $cache/$d/$date.diff | sed \
|
pankso@5
|
548 -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \
|
pankso@5
|
549 -e s"#^-\([^']*\).#<span style='color: red;'>\0</span>#"g \
|
pankso@5
|
550 -e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \
|
pankso@5
|
551 -e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g
|
pankso@5
|
552 else
|
pankso@59
|
553 gettext "No diff for:"; echo " $d"
|
pankso@5
|
554 fi
|
pankso@5
|
555 echo '</pre>'
|
pankso@5
|
556 html_footer ;;
|
pankso@15
|
557
|
pankso@5
|
558 *\ login\ *)
|
pankso@5
|
559 # The login page
|
pankso@5
|
560 d="Login"
|
pankso@5
|
561 [ "$(GET error)" ] && \
|
pankso@5
|
562 error="<p class="error">$(gettext "Bad login or pass")</p>"
|
pankso@5
|
563 header
|
pankso@5
|
564 html_header
|
pankso@5
|
565 user_box
|
pankso@5
|
566 login_page
|
pankso@5
|
567 html_footer ;;
|
pankso@15
|
568
|
pankso@5
|
569 *\ signup\ *)
|
pankso@5
|
570 # The login page
|
pankso@5
|
571 d="$(gettext "Sign Up")"
|
pankso@5
|
572 header
|
pankso@5
|
573 html_header
|
pankso@5
|
574 user_box
|
pankso@5
|
575 echo "<h2>$d</h2>"
|
pankso@5
|
576 if [ "$ONLINE_SIGNUP" == "yes" ]; then
|
pankso@5
|
577 signup_page
|
pankso@5
|
578 else
|
paul@8
|
579 gettext "Online registration is disabled"
|
pankso@5
|
580 fi
|
pankso@5
|
581 html_footer ;;
|
pankso@15
|
582
|
pankso@5
|
583 *\ logout\ *)
|
pankso@5
|
584 # Set a Cookie in the past to logout.
|
pankso@5
|
585 expires="Expires=Wed, 01-Jan-1980 00:00:00 GMT"
|
pankso@5
|
586 if check_auth; then
|
pankso@5
|
587 rm -f "$sessions/$user"
|
pankso@5
|
588 header "Location: $script" "Set-Cookie: auth=none; $expires; HttpOnly"
|
pankso@5
|
589 fi ;;
|
pankso@15
|
590
|
pankso@5
|
591 *\ user\ *)
|
pankso@76
|
592 # Basic user profile. Use the users plugin for more functions
|
pankso@15
|
593 d="$(GET user)"
|
pankso@36
|
594 last="$(cat $PEOPLE/"$(GET user)"/last)"
|
pankso@5
|
595 header
|
pankso@5
|
596 html_header
|
pankso@5
|
597 user_box
|
pankso@5
|
598 . $PEOPLE/"$(GET user)"/account.conf
|
pankso@36
|
599 cat << EOT
|
pankso@36
|
600 <h2>$(get_gravatar $MAIL) $NAME</h2>
|
pankso@36
|
601
|
pankso@36
|
602 <pre>
|
pankso@36
|
603 $(gettext "User name :") $USER
|
pankso@36
|
604 $(gettext "Last login :") $last
|
pankso@76
|
605 </pre>
|
pankso@36
|
606 EOT
|
pankso@5
|
607 html_footer ;;
|
pankso@15
|
608
|
pankso@59
|
609 *\ hg\ *)
|
pankso@59
|
610 d="Hg Log"
|
pankso@5
|
611 header
|
pankso@5
|
612 html_header
|
pankso@5
|
613 user_box
|
pankso@5
|
614 [ "$HG" != "yes" ] && gettext "Hg is disabled" && exit 0
|
pankso@5
|
615 [ ! -x /usr/bin/hg ] && gettext "Hg is not installed" && exit 0
|
pankso@5
|
616 echo "<h2>$d</h2>"
|
pankso@5
|
617 case " $(GET hg) " in
|
pankso@5
|
618 *\ init\ *)
|
pankso@5
|
619 if check_auth; then
|
pankso@5
|
620 [ -d "$content/.hg" ] && exit 0
|
pankso@5
|
621 echo '<pre>'
|
pankso@5
|
622 gettext "Executing: hg init"; echo
|
pankso@5
|
623 cd $content/ && hg init
|
pankso@5
|
624 echo '[hooks]' > .hg/hgrc
|
pankso@5
|
625 echo 'incoming = hg update' >> .hg/hgrc
|
paul@8
|
626 gettext "Adding current content and committing"; echo
|
pankso@59
|
627 [ ! -f "$wiki/index.txt" ] && default_index
|
pankso@5
|
628 hg add && hg commit -u "$NAME <$MAIL>" \
|
paul@22
|
629 -m "Initial commit with current content"
|
pankso@5
|
630 echo '</pre>' && cd ..
|
pankso@5
|
631 fi ;;
|
pankso@5
|
632 esac
|
pankso@5
|
633 hg_log
|
pankso@5
|
634 html_footer ;;
|
pankso@15
|
635
|
pankso@5
|
636 *)
|
pankso@5
|
637 # Display requested page
|
pankso@5
|
638 d="$(GET d)"
|
pankso@5
|
639 [ "$d" ] || d=$index
|
pankso@5
|
640 header
|
pankso@5
|
641 html_header
|
pankso@5
|
642 user_box
|
pankso@5
|
643 get_lang
|
pankso@52
|
644
|
pankso@34
|
645 # Generate a default index on first run
|
pankso@11
|
646 if [ ! -f "$wiki/$index.txt" ]; then
|
pankso@34
|
647 if ! default_index; then
|
paul@64
|
648 echo "<pre class='error'>Directory : content/ is not writeable</pre>"
|
pankso@32
|
649 html_footer && exit 0
|
pankso@32
|
650 fi
|
pankso@11
|
651 fi
|
pankso@52
|
652
|
pankso@34
|
653 # Check cache dir
|
pankso@34
|
654 if [ ! -w "$cache" ]; then
|
paul@64
|
655 echo "<pre class='error'>Directory : cache/ is not writeable"
|
pankso@34
|
656 echo "Command : install -m 0777 -d $tiny/cache</pre>"
|
pankso@34
|
657 html_footer && exit 0
|
pankso@34
|
658 fi
|
pankso@52
|
659
|
pankso@59
|
660 # Hg warning if enabled but not initiated
|
pankso@52
|
661 if [ "$HG" == "yes" ] && [ ! -d "$content/.hg" ]; then
|
pankso@52
|
662 echo '<p class="error box">'
|
pankso@52
|
663 gettext "Mercurial is enabled but no repository found"
|
pankso@59
|
664 echo ": <a href='$script?hg=init'>Hg init</a>"
|
pankso@52
|
665 echo '</p>'
|
pankso@52
|
666 fi
|
pankso@52
|
667
|
pankso@52
|
668 # Wiki tools
|
pankso@52
|
669 wiki_tools
|
pankso@52
|
670
|
pankso@34
|
671 # Wiki document
|
pankso@5
|
672 if [ ! -f "$wiki/$d.txt" ]; then
|
pankso@5
|
673 echo "<h2>$d</h2>"
|
pankso@5
|
674 gettext "The document does not exist. You can create it or read the"
|
pankso@59
|
675 echo " <a href='$script?d=en/help'>help</a>"
|
pankso@5
|
676 else
|
pankso@26
|
677 if fgrep -q [NOWIKI] $wiki/$d.txt; then
|
pankso@35
|
678 cat $wiki/$d.txt | sed '/\[NOWIKI\]/'d
|
pankso@5
|
679 else
|
pankso@5
|
680 cat $wiki/$d.txt | wiki_parser
|
pankso@5
|
681 fi
|
pankso@5
|
682 fi
|
pankso@5
|
683 html_footer ;;
|
pankso@5
|
684 esac
|
pankso@5
|
685
|
pankso@5
|
686 exit 0
|