tazbug view web/bugs.cgi @ rev 105

Overall improvments
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 10 18:12:00 2017 +0100 (2017-02-10)
parents 60234e42d5c4
children 1a43d9e16913
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/'/\&#39;/g; s|\n|<br/>|g; s/\t/\&#09;/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&amp;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 # Display user public profile.
221 public_people() {
222 cat << EOT
223 </pre>
224 EOT
225 }
227 # Display authenticated user profile. TODO: change password
228 auth_people() {
229 cat << EOT
230 Email : $MAIL
231 Secure key : $KEY
232 </pre>
233 EOT
234 }
236 # Usage: list_bug ID
237 list_bug() {
238 id="$1"
239 . ${bugdir}/${id}/bug.conf
240 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
241 . ${PEOPLE}/${CREATOR}/account.conf
242 cat << EOT
243 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
244 ID: $id <a href="?id=$id">$BUG</a> <span class="date">$DATE</span>
245 EOT
246 unset CREATOR USER MAIL
247 }
249 # Usage: list_bugs STATUS
250 list_bugs() {
251 status="$1"
252 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
253 echo "<pre>"
254 for pr in critical standard
255 do
256 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
257 do
258 . $bug
259 id=$(basename $(dirname $bug))
260 if [ "$PRIORITY" == "$pr" ]; then
261 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
262 . ${PEOPLE}/${CREATOR}/account.conf
263 cat << EOT
264 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
265 ID: $id <a href="?id=$id">$BUG</a> <span class="date">$DATE</span>
266 EOT
267 fi
268 unset CREATOR USER MAIL
269 done
270 done
271 }
273 # Stripped down Wiki parser for bug desc and messages which are simply
274 # displayed in <pre>
275 wiki_parser() {
276 sed \
277 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
278 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
279 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
280 }
282 # Bug page
283 bug_page() {
284 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
285 . $PEOPLE/$CREATOR/account.conf
286 else
287 MAIL="default"
288 fi
289 cat << EOT
290 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
292 <p>
293 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
294 </p>
295 <p>
296 $(gettext "Date:") $DATE -
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&amp;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="?edit=$id">$(gettext "Edit bug")</a>
316 EOT
317 fi
318 else
319 cat << EOT
320 <a href="?id=$id&amp;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&amp;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="edit">
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&amp;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
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 EOT
706 if check_auth && [ "$(GET user)" == "$user" ]; then
707 auth_people
708 else
709 # check_auth will set VARS to current logged user: re-source
710 . $PEOPLE/"$(GET user)"/account.conf
711 public_people
712 fi
713 html_footer ;;
714 *\ newbug\ *)
715 # Create a bug from web interface.
716 header
717 html_header
718 user_box
719 if check_auth; then
720 new_bug_page
721 else
722 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
723 fi
724 html_footer ;;
725 *\ addbug\ *)
726 # Save a new bug from web interface.
727 header
728 html_header
729 if check_auth; then
730 new_bug
731 js_redirection_to "$script?id=$count"
732 fi ;;
733 *\ edit\ *)
734 # Edit existing bug
735 id="$(GET edit)"
736 header
737 html_header
738 user_box
739 edit_bug
740 html_footer ;;
741 *\ savebug\ *)
742 header
743 html_header
744 if check_auth; then
745 save_bug
746 js_redirection_to "$script?id=$id"
747 fi ;;
748 *\ id\ *)
749 # Empty deleted messages to keep msg count working.
750 header
751 html_header
752 id="$(GET id)"
753 [ "$(GET close)" ] && close_bug
754 [ "$(GET open)" ] && open_bug
755 [ "$(GET msg)" ] && new_msg
756 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
757 touch $bugdir/$id/msg.$(GET delmsg)
758 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
759 user_box
760 . $bugdir/$id/bug.conf
761 bug_page
762 html_footer ;;
763 *\ signup\ *)
764 # Signup
765 if [ "$(GET online)" ];then
766 header
767 html_header
768 user_box
769 echo "<h2>$(gettext "Sign Up")</h2>"
770 if [ "$ONLINE_SIGNUP" == "yes" ]; then
771 signup_page
772 else
773 gettext "Online registration is disabled"
774 fi
775 html_footer && exit 0
776 else
777 header "Content-type: text/plain;"
778 user="$(GET signup)"
779 echo "Requested user login : $user"
780 if fgrep -q "$user:" $AUTH_FILE; then
781 echo "ERROR: User already exists" && exit 1
782 else
783 echo "Creating account for : $(GET name)"
784 new_user_config
785 fi
786 fi ;;
787 *\ key\ *)
788 # Let user post new bug or message with crypted key (no gettext)
789 #
790 # Testing only and is security acceptable ?
791 #
792 key="$(GET key)"
793 id="$(GET bug)"
794 header "Content-type: text/plain;"
795 echo "Checking secure key..."
796 if fgrep -qH $key $PEOPLE/*/account.conf; then
797 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
798 . $conf
799 echo "Authenticated: $NAME ($USER)"
800 case " $(GET) " in
801 *\ msg\ *)
802 [ ! "$id" ] && echo "Missing bug ID" && exit 0
803 echo "Posting new message to bug: $id"
804 echo "Message: $(GET msg)"
805 new_msg ;;
806 *\ bug\ *)
807 echo "Adding new bug: $(GET bug)"
808 echo "Description: $(GET desc)"
809 new_bug ;;
810 esac
811 else
812 echo "Not a valid SliTaz user key"
813 exit 0
814 fi ;;
815 *\ search\ *)
816 found=0
817 header
818 html_header
819 user_box
820 cat << EOT
821 <h2>$(gettext "Search")</h2>
822 <form method="get" action="$script">
823 <input type="text" name="search" />
824 <input type="submit" value="$(gettext 'Search')" />
825 </form>
826 <div>
827 EOT
828 cd $bugdir
829 for bug in *
830 do
831 result=$(fgrep -i -h "$(GET search)" $bug/*)
832 if [ "$result" ]; then
833 found=$(($found + 1))
834 id=${bug}
835 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
836 echo '<pre>'
837 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
838 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
839 echo '</pre>'
840 fi
841 done
842 if [ "$found" == "0" ]; then
843 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
844 else
845 echo "<p> $found $(gettext 'results found')</p>"
846 fi
847 echo '</div>'
848 html_footer ;;
849 *)
850 # Default page.
851 bugs=$(ls -1 $bugdir | wc -l)
852 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
853 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
854 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
855 pct=0
856 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
857 header
858 html_header
859 user_box
861 cat << EOT
863 <h2>$(gettext "Summary")</h2>
865 <p>
866 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
867 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
868 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
869 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
870 </p>
872 <div class="pctbar">
873 <div class="pct" style="width: ${pct}%;">${pct}%</div>
874 </div>
876 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
877 more information. You may also be interested by the SliTaz \
878 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
879 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
880 enter your term and press ENTER.")
881 </p>
883 <div id="tools">
884 $BUGS_TOOLS
885 <a href="?closed">$(gettext 'View closed bugs')</a>
886 EOT
887 if check_auth; then
888 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
889 echo "$PLUGINS_TOOLS"
890 fi
891 cat << EOT
892 </div>
894 <h3>$(gettext "Latest Bugs")</h3>
895 EOT
896 # List last 3 bugs
897 echo "<pre>"
898 for lb in $(ls ${bugdir} | sort -r -n | head -n 3)
899 do
900 list_bug ${lb}
901 done
902 echo "</pre>"
903 list_bugs OPEN
904 echo "</pre>"
905 html_footer ;;
906 esac
908 exit 0