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