tazbug view web/bugs.cgi @ rev 112
Small fixes
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Feb 11 00:00:17 2017 +0100 (2017-02-11) |
parents | 3a01dfb5ed7d |
children | d24cd6951458 |
line source
1 #!/bin/sh
2 #
3 # TazBug Web interface
4 #
5 # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
6 #
7 . /usr/lib/slitaz/httphelper
9 # Source config file
10 [ -f "/etc/slitaz/tazbug.conf" ] && . /etc/slitaz/tazbug.conf
11 # Web interface can have different setting than cmdline tools
12 [ -f "/etc/slitaz/bugs.conf" ] && . /etc/slitaz/bugs.conf
14 # Internal variable
15 bugdir="$PWD/bug"
16 plugins="plugins"
17 sessions="/tmp/bugs/sessions"
18 script="$SCRIPT_NAME"
20 # Content negotiation for Gettext
21 IFS=","
22 for lang in $HTTP_ACCEPT_LANGUAGE
23 do
24 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
25 case "$lang" in
26 en) LANG="C" && break ;;
27 de) LANG="de_DE" && break ;;
28 es) LANG="es_ES" && break ;;
29 fr) LANG="fr_FR" && break ;;
30 it) LANG="it_IT" && break ;;
31 pt) LANG="pt_BR" && break ;;
32 ru) LANG="ru_RU" && break ;;
33 zh) LANG="zh_TW" && break ;;
34 esac
35 done
36 unset IFS
37 export LANG LC_ALL=$LANG
39 # Internationalization: $(gettext "")
40 . /usr/bin/gettext.sh
41 TEXTDOMAIN='tazbug'
42 export TEXTDOMAIN
44 #
45 # Functions
46 #
48 # HTML 5 header.
49 html_header() {
50 cat lib/header.html
51 }
53 # HTML 5 footer.
54 html_footer() {
55 cat << EOT
56 </div>
58 <div id="footer">
59 <a href="$script">SliTaz Bugs</a> -
60 <a href="$script?README">README</a>
61 </div>
63 </body>
64 </html>
65 EOT
66 }
68 GETfiltered() {
69 GET $1 | sed -e "s/'/\'/g; s|\n|<br/>|g; s/\t/\	/g;s/\%22/\\\"/g"
70 }
72 js_redirection_to() {
73 js_log "Redirecting to $1"
74 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
75 }
77 js_log() {
78 echo "<script type=\"text/javascript\">console.log('$1')</script>";
79 }
81 js_set_cookie() {
82 name=$1
83 value=$2
84 js_log 'Setting cookie.'
85 cat << EOT
86 <script type="text/javascript">
87 document.cookie = '$name=$value; expires=0; path=/';
88 </script>
89 EOT
90 }
92 js_unset_cookie() {
93 name=$1
94 js_log 'Unsetting cookie.'
95 cat << EOT
96 <script type="text/javascript">
97 document.cookie = '$1=""; expires=-1; path=/;'
98 </script>
99 EOT
100 }
102 # Check if user is auth
103 check_auth() {
104 auth="$(COOKIE auth)"
105 user="$(echo $auth | cut -d ":" -f 1)"
106 md5cookie="$(echo $auth | cut -d ":" -f 2)"
107 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
108 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
109 return 0
110 else
111 return 1
112 fi
113 }
115 # Check if user is admin
116 admin_user() {
117 fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf
118 }
120 # Authenticated or not
121 user_box() {
123 IDLOC=""
124 if [[ "$(GET id)" ]] ;then
125 IDLOC="&id=$(GET id)"
126 fi
128 if check_auth; then
129 . $PEOPLE/$user/account.conf
130 cat << EOT
131 <div id="user">
132 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
133 <a href="?logout">$(gettext 'Logout')</a>
134 </div>
135 EOT
136 else
137 cat << EOT
138 <div id="user">
139 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
140 <a href="?login$IDLOC">$(gettext 'Login')</a>
141 </div>
142 EOT
143 fi
144 cat << EOT
146 <div id="search">
147 <form method="get" action="$script">
148 <input type="text" name="search" placeholder="$(gettext 'Search')" />
149 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
150 </form>
151 </div>
153 <!-- Content -->
154 <div id="content">
156 EOT
157 }
159 # Signup page
160 signup_page() {
161 cat << EOT
163 <div id="signup">
164 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
165 <input type="hidden" name="signup" value="new" />
166 <input type="text" name="name" placeholder="$(gettext "Real name")" />
167 <input type="text" name="user" placeholder="$(gettext "User name")" />
168 <input type="text" name="mail" placeholder="$(gettext "Email")" />
169 <input type="password" name="pass" placeholder="$(gettext "Password")" />
170 <div>
171 <input type="submit" value="$(gettext "Create new account")" />
172 </div>
173 </form>
174 </div>
176 EOT
177 }
179 # Link for online signup if enabled.
180 online_signup() {
181 if [ "$ONLINE_SIGNUP" == "yes" ]; then
182 echo -n "<p>" && gettext "Or:"; echo -n " "
183 echo -n "<a href='$script?signup&online'>"
184 gettext "Sign Up Online"
185 echo '</a></p>'
186 fi
187 }
189 # Login page
190 login_page() {
191 cat << EOT
192 <h2>$(gettext 'Login')</h2>
194 <div id="account-info">
195 <p>$(gettext "No account yet? You can signup using the SliTaz Bugs reporter \
196 on your SliTaz system.")</p>
197 $(online_signup)
198 <p>$(gettext "Tip: to attach big files or images, you can use SliTaz Paste \
199 services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a></p>
200 </div>
202 <div id="login">
203 <form method="post" action="$script">
204 <div>
205 <input type="text" name="auth" placeholder="$(gettext 'User name')" />
206 </div>
207 <input type="password" name="pass" placeholder="$(gettext 'Password')" />
208 <div>
209 <input type="hidden" name="id" value="$(GET id)" />
210 <input type="submit" value="$(gettext 'Log in')" />
211 $error
212 </div>
213 </form>
214 </div>
216 <div style="clear: both;"></div>
217 EOT
218 }
220 # Usage: list_bug ID
221 list_bug() {
222 id="$1"
223 . ${bugdir}/${id}/bug.conf
224 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
225 . ${PEOPLE}/${CREATOR}/account.conf
226 cat << EOT
227 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
228 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
229 EOT
230 unset CREATOR USER MAIL
231 }
233 # Usage: list_bugs STATUS
234 list_bugs() {
235 status="$1"
236 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
237 echo "<pre>"
238 for pr in critical standard
239 do
240 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
241 do
242 . $bug
243 id=$(basename $(dirname $bug))
244 if [ "$PRIORITY" == "$pr" ]; then
245 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
246 . ${PEOPLE}/${CREATOR}/account.conf
247 cat << EOT
248 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
249 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
250 EOT
251 fi
252 unset CREATOR USER MAIL
253 done
254 done
255 }
257 # Usage: list_msg path
258 list_msg() {
259 msg="$1"
260 dir=$(dirname $msg)
261 id=$(basename $dir)
262 . ${msg}
263 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
264 . ${PEOPLE}/${USER}/account.conf
265 cat << EOT
266 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
267 ID: <a href="?id=$id">Bug $id</a> by $USER <span class="date">- $DATE</span>
268 EOT
269 unset CREATOR USER MAIL
270 }
272 # Stripped down Wiki parser for bug desc and messages which are simply
273 # displayed in <pre>
274 wiki_parser() {
275 sed \
276 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
277 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
278 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
279 }
281 # Bug page
282 bug_page() {
283 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
284 . $PEOPLE/$CREATOR/account.conf
285 else
286 MAIL="default"
287 fi
288 cat << EOT
289 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
291 <p>
292 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
293 </p>
294 <p>
295 $(gettext "Date:") $DATE -
296 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
297 $(eval_gettext 'Priority $PRIORITY') -
298 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
299 </p>
301 <pre>
302 $(cat $bugdir/$id/desc.txt | wiki_parser)
303 </pre>
305 <div id="tools">
306 EOT
307 if check_auth; then
308 if [ "$STATUS" == "OPEN" ]; then
309 cat << EOT
310 <a href="?id=$id&close">$(gettext "Close bug")</a>
311 EOT
312 # Only original user and admin can edit a bug
313 if [ "$user" == "$CREATOR" ] || admin_user; then
314 cat << EOT
315 <a href="?editbug=$id">$(gettext "Edit bug")</a>
316 EOT
317 fi
318 else
319 cat << EOT
320 <a href="?id=$id&open">$(gettext "Re open bug")</a>
321 EOT
322 fi
323 fi
324 cat << EOT
325 </div>
327 <h3>$(gettext "Messages")</h3>
328 EOT
329 [ "$msgs" == "0" ] && gettext "No messages"
330 for msg in $(ls -1tr $bugdir/$id/msg.*)
331 do
332 . $msg
333 if [ "$MSG" ]; then
334 msgid=$(echo $msg | cut -d "." -f 2)
335 del=""
336 # User can delete his post as well as admin.
337 if [ "$user" == "$USER" ] || admin_user; then
338 del="<a href=\"?id=$id&delmsg=$msgid\">delete</a>"
339 fi
340 cat << EOT
341 <p><strong>$USER</strong> $DATE $del</p>
342 <pre>
343 $(echo "$MSG" | wiki_parser)
344 </pre>
345 EOT
346 fi
347 unset NAME DATE MSG
348 done
349 if check_auth; then
350 cat << EOT
351 <div>
352 <h3>$(gettext "New message")</h3>
353 <form method="get" action="$script">
354 <input type="hidden" name="id" value="$id" />
355 <textarea name="msg" rows="8"></textarea>
356 <p><input type="submit" value="$(gettext 'Send message')" /></p>
357 </form>
358 </div>
359 EOT
360 fi
361 }
363 # Write a new message
364 new_msg() {
365 date=$(date "+%Y-%m-%d %H:%M")
366 msgs=$(ls -1 $bugdir/$id/msg.* | wc -l)
367 count=$(($msgs + 1))
368 if check_auth; then
369 USER="$user"
370 fi
371 js_log "Will write message in $bugdir/$id/msg.$count "
372 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
373 USER="$USER"
374 DATE="$date"
375 MSG="$(GETfiltered msg)"
376 EOT
377 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
378 rm -f $bugdir/$id/msg.$count.tmp
379 }
381 # Create a new Bug. ID is set by counting dirs in bug/ + 1
382 new_bug() {
383 count=$(ls $bugdir | sort -g | tail -n 1)
384 count=$(($count +1))
385 date=$(date "+%Y-%m-%d %H:%M")
386 # Sanity check, JS may be disabled.
387 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
388 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
389 if check_auth; then
390 USER="$user"
391 fi
392 mkdir -p $bugdir/$count
393 # bug.conf
394 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
395 # SliTaz Bug configuration
397 BUG="$(GETfiltered bug)"
398 STATUS="OPEN"
399 PRIORITY="$(GET priority)"
400 CREATOR="$USER"
401 DATE="$date"
402 PKGS="$(GETfiltered pkgs)"
403 EOT
404 # desc.txt
405 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/desc.tmp << EOT
406 $(GETfiltered desc)
407 EOT
408 fold -s -w 80 $bugdir/$count/desc.tmp > $bugdir/$count/desc.txt
409 rm -f $bugdir/$count/*.tmp
410 }
412 # New bug page for the web interface
413 new_bug_page() {
414 cat << EOT
415 <h2>$(gettext "New Bug")</h2>
416 <div id="newbug">
418 <form method="get" action="$script" onsubmit="return checkNewBug();">
419 <input type="hidden" name="addbug" />
420 <table>
421 <tbody>
422 <tr>
423 <td>$(gettext "Bug title")*</td>
424 <td><input type="text" name="bug" /></td>
425 </tr>
426 <tr>
427 <td>$(gettext "Description")*</td>
428 <td><textarea name="desc"></textarea></td>
429 </tr>
430 <tr>
431 <td>$(gettext "Packages")</td>
432 <td><input type="text" name="pkgs" /></td>
433 </tr>
434 <tr>
435 <td>$(gettext "Priority")</td>
436 <td>
437 <select name="priority">
438 <option value="standard">$(gettext "Standard")</option>
439 <option value="critical">$(gettext "Critical")</option>
440 </select>
441 <input type="submit" value="$(gettext "Create Bug")" />
442 </td>
443 </tr>
444 </tbody>
445 </table>
446 </form>
448 <p>
449 $(gettext "* field is obligatory. You can also specify affected packages.")
450 </p>
452 </div>
453 EOT
454 }
456 # Edit/Save a bug
457 edit_bug() {
458 . $bugdir/$id/bug.conf
459 if admin_user || [ "$user" == "$CREATOR" ]; then
460 continue
461 else
462 gettext "You can't edit someone else bug!" && exit 0
463 fi
464 cat << EOT
465 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
466 <div id="editbug">
468 <form method="get" action="$script">
469 <input type="hidden" name="savebug" />
470 <input type="hidden" name="id" value="$id" />
471 <input type="hidden" name="creator" value="$CREATOR" />
472 <input type="hidden" name="date" value="$DATE" />
473 <table>
474 <tbody>
475 <tr>
476 <td>$(gettext "Bug title")</td>
477 <td><input type="text" name="bug" value="$BUG" /></td>
478 </tr>
479 <tr>
480 <td>$(gettext "Description")</td>
481 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
482 </tr>
483 <tr>
484 <td>$(gettext "Packages")</td>
485 <td><input type="text" name="pkgs" value="$PKGS" /></td>
486 </tr>
487 <tr>
488 <td>$(gettext "Priority")</td>
489 <td>
490 <select name="priority">
491 <option value="$PRIORITY">$PRIORITY</option>
492 <option value="standard">$(gettext "Standard")</option>
493 <option value="critical">$(gettext "Critical")</option>
494 </select>
495 <input type="submit" value="$(gettext 'Save configuration')" />
496 </td>
497 </tr>
498 </tbody>
499 </table>
500 </form>
502 </div>
503 EOT
504 }
506 save_bug() {
507 id="$(GET id)"
508 # bug.conf
509 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
510 # SliTaz Bug configuration
512 BUG="$(GETfiltered bug)"
513 STATUS="OPEN"
514 PRIORITY="$(GET priority)"
515 CREATOR="$(GET creator)"
516 DATE="$(GET date)"
517 PKGS="$(GETfiltered pkgs)"
518 EOT
519 # desc.txt
520 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
521 $(GETfiltered desc)
522 EOT
523 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
524 rm -f $bugdir/$id/*.tmp
525 }
527 # Close a fixed bug
528 close_bug() {
529 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
530 }
532 # Re open an old bug
533 open_bug() {
534 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
535 }
537 # Get and display Gravatar image: get_gravatar email size
538 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
539 get_gravatar() {
540 email=$1
541 size=$2
542 [ "$size" ] || size=48
543 url="http://www.gravatar.com/avatar"
544 md5=$(md5crypt $email)
545 echo "<img src=\"$url/$md5?d=identicon&s=$size\" alt=\"\" />"
546 }
548 # Create a new user in AUTH_FILE and PEOPLE
549 new_user_config() {
550 if [ ! "$online" ]; then
551 name="$(GET name)"
552 mail="$(GET mail)"
553 pass="$(GET pass)"
554 echo "Creating Server Key..."
555 fi
556 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
557 echo "$user:$pass" >> $AUTH_FILE
558 mkdir -pm0700 $PEOPLE/$user/
559 cat > $PEOPLE/$user/account.conf << EOT
560 # SliTaz user configuration
561 #
563 NAME="$name"
564 USER="$user"
565 MAIL="$mail"
566 KEY="$key"
568 LOCATION="$(GET location)"
569 RELEASES="$(GET releases)"
570 PACKAGES="$(GET packages)"
571 EOT
572 chmod 0600 $PEOPLE/$user/account.conf
573 if [ ! -f $PEOPLE/$user/account.conf ]; then
574 echo "ERROR: User creation failed!"
575 fi
576 }
578 ########################################################################
579 # POST actions #
580 ########################################################################
582 case " $(POST) " in
583 *\ auth\ *)
584 header
585 html_header
586 # Authenticate user. Create a session file in $sessions to be used
587 # by check_auth. We have the user login name and a peer session
588 # md5 string in the COOKIE.
589 user="$(POST auth)"
590 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
592 IDLOC=""
593 if [[ "$(POST id)" ]] ;then
594 IDLOC="&id=$(POST id)"
595 fi
597 if [ ! -f $AUTH_FILE ] ; then
598 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
599 js_redirection_to "$script?login$IDLOC"
600 fi;
602 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
603 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
604 if [[ "$(POST id)" ]] ;then
605 IDLOC="?id=$(POST id)"
606 fi
607 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
608 mkdir -p $sessions
609 # Log last login
610 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
611 echo "$md5session" > $sessions/$user
612 js_set_cookie 'auth' "$user:$md5session"
613 js_log "Login authentication has been executed & accepted :)"
614 js_redirection_to "$script$IDLOC"
615 else
616 js_log "Login authentication has been executed & refused"
617 js_redirection_to "$script?login&error$IDLOC"
618 fi
619 html_footer ;;
620 *\ signup\ *)
621 # POST action for online signup
622 name="$(POST name)"
623 user="$(POST user)"
624 mail="$(POST mail)"
625 pass="$(md5crypt "$(POST pass)")"
626 if ! grep "^${user}:" $AUTH_FILE; then
627 online="yes"
628 new_user_config
629 header "Location: $SCRIPT_NAME?login"
630 else
631 header
632 html_header
633 user_box
634 echo "<h2>$(gettext "User already exists:") $user</h2>"
635 html_footer && exit 0
636 fi ;;
637 esac
639 #
640 # Plugins Now!
641 #
643 for p in $(ls -1 $plugins)
644 do
645 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
646 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
647 done
649 ########################################################################
650 # GET actions #
651 ########################################################################
653 case " $(GET) " in
654 *\ README\ *)
655 header
656 html_header
657 user_box
658 echo '<h2>README</h2>'
659 echo '<pre>'
660 if [ -f "README" ]; then
661 cat README
662 else
663 cat /usr/share/doc/tazbug/README
664 fi
665 echo '</pre>'
666 html_footer ;;
667 *\ closed\ *)
668 # Show all closed bugs.
669 header
670 html_header
671 user_box
672 list_bugs CLOSED
673 echo "</pre>"
674 html_footer ;;
675 *\ login\ *)
676 # The login page
677 [ "$(GET error)" ] && \
678 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
679 header
680 html_header
681 user_box
682 login_page
683 html_footer ;;
684 *\ logout\ *)
685 header
686 html_header
687 if check_auth; then
688 rm -f "$sessions/$user"
689 js_unset_cookie 'auth'
690 js_redirection_to "$script"
691 fi ;;
692 *\ user\ *)
693 # User profile. Use the users plugin for more functions
694 last="$(cat $PEOPLE/"$(GET user)"/last)"
695 header
696 html_header
697 user_box
698 . $PEOPLE/"$(GET user)"/account.conf
699 cat << EOT
700 <h2>$(get_gravatar $MAIL) $NAME</h2>
702 <pre>
703 $(gettext "User name :") $USER
704 $(gettext "Last login :") $last
705 </pre>
706 EOT
707 html_footer ;;
708 *\ newbug\ *)
709 # Create a bug from web interface.
710 header
711 html_header
712 user_box
713 if check_auth; then
714 new_bug_page
715 else
716 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
717 fi
718 html_footer ;;
719 *\ addbug\ *)
720 # Save a new bug from web interface.
721 header
722 html_header
723 if check_auth; then
724 new_bug
725 js_redirection_to "$script?id=$count"
726 fi ;;
727 *\ editbug\ *)
728 # Edit existing bug
729 id="$(GET editbug)"
730 header
731 html_header
732 user_box
733 edit_bug
734 html_footer ;;
735 *\ savebug\ *)
736 header
737 html_header
738 if check_auth; then
739 save_bug
740 js_redirection_to "$script?id=$id"
741 fi ;;
742 *\ id\ *)
743 # Empty deleted messages to keep msg count working.
744 header
745 html_header
746 id="$(GET id)"
747 [ "$(GET close)" ] && close_bug
748 [ "$(GET open)" ] && open_bug
749 [ "$(GET msg)" ] && new_msg
750 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
751 touch $bugdir/$id/msg.$(GET delmsg)
752 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
753 user_box
754 . $bugdir/$id/bug.conf
755 bug_page
756 html_footer ;;
757 *\ signup\ *)
758 # Signup
759 if [ "$(GET online)" ];then
760 header
761 html_header
762 user_box
763 echo "<h2>$(gettext "Sign Up")</h2>"
764 if [ "$ONLINE_SIGNUP" == "yes" ]; then
765 signup_page
766 else
767 gettext "Online registration is disabled"
768 fi
769 html_footer && exit 0
770 else
771 header "Content-type: text/plain;"
772 user="$(GET signup)"
773 echo "Requested user login : $user"
774 if fgrep -q "$user:" $AUTH_FILE; then
775 echo "ERROR: User already exists" && exit 1
776 else
777 echo "Creating account for : $(GET name)"
778 new_user_config
779 fi
780 fi ;;
781 *\ key\ *)
782 # Let user post new bug or message with crypted key (no gettext)
783 #
784 # Testing only and is security acceptable ?
785 #
786 key="$(GET key)"
787 id="$(GET bug)"
788 header "Content-type: text/plain;"
789 echo "Checking secure key..."
790 if fgrep -qH $key $PEOPLE/*/account.conf; then
791 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
792 . $conf
793 echo "Authenticated: $NAME ($USER)"
794 case " $(GET) " in
795 *\ msg\ *)
796 [ ! "$id" ] && echo "Missing bug ID" && exit 0
797 echo "Posting new message to bug: $id"
798 echo "Message: $(GET msg)"
799 new_msg ;;
800 *\ bug\ *)
801 echo "Adding new bug: $(GET bug)"
802 echo "Description: $(GET desc)"
803 new_bug ;;
804 esac
805 else
806 echo "Not a valid SliTaz user key"
807 exit 0
808 fi ;;
809 *\ search\ *)
810 found=0
811 header
812 html_header
813 user_box
814 cat << EOT
815 <h2>$(gettext "Search")</h2>
816 <form method="get" action="$script">
817 <input type="text" name="search" />
818 <input type="submit" value="$(gettext 'Search')" />
819 </form>
820 <div>
821 EOT
822 cd $bugdir
823 for bug in *
824 do
825 result=$(fgrep -i -h "$(GET search)" $bug/*)
826 if [ "$result" ]; then
827 found=$(($found + 1))
828 id=${bug}
829 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
830 echo '<pre>'
831 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
832 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
833 echo '</pre>'
834 fi
835 done
836 if [ "$found" == "0" ]; then
837 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
838 else
839 echo "<p> $found $(gettext 'results found')</p>"
840 fi
841 echo '</div>'
842 html_footer ;;
843 *)
844 # Default page.
845 bugs=$(ls -1 $bugdir | wc -l)
846 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
847 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
848 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
849 pct=0
850 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
851 header
852 html_header
853 user_box
855 cat << EOT
857 <h2>$(gettext "Summary")</h2>
859 <p>
860 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
861 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
862 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
863 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
864 </p>
866 <div class="pctbar">
867 <div class="pct" style="width: ${pct}%;">${pct}%</div>
868 </div>
870 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
871 more information. You may also be interested by the SliTaz \
872 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
873 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
874 enter your term and press ENTER.")
875 </p>
877 <div id="tools">
878 $BUGS_TOOLS
879 <a href="?closed">$(gettext 'View closed bugs')</a>
880 EOT
881 if check_auth; then
882 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
883 echo "$PLUGINS_TOOLS"
884 fi
885 cat << EOT
886 </div>
888 <h3>$(gettext "Latest Bugs")</h3>
889 EOT
890 # List last 4 bugs
891 echo "<pre>"
892 for lb in $(ls ${bugdir} | sort -r -n | head -n 4)
893 do
894 list_bug ${lb}
895 done
896 echo "</pre>"
897 # List last 4 messages
898 echo "<h3>$(gettext "Latest Messages")</h3>"
899 echo "<pre>"
900 for msg in $(ls -t ${bugdir}/*/msg.* | head -n 4)
901 do
902 list_msg ${msg}
903 done
904 echo "</pre>"
905 list_bugs OPEN
906 echo "</pre>"
907 html_footer ;;
908 esac
910 exit 0