tazbug view web/bugs.cgi @ rev 70

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