tazbug view web/bugs.cgi @ rev 79

Update POT file and msgmerge + small fixes
author Christophe Lincoln <pankso@slitaz.org>
date Wed Feb 05 21:12:44 2014 +0100 (2014-02-05)
parents be084688e724
children 7426a4db30d3
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" && 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
248 }
250 # Usage: list_bugs STATUS
251 list_bugs() {
252 status="$1"
253 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
254 echo "<pre>"
255 for pr in critical standard
256 do
257 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
258 do
259 . $bug
260 id=$(basename $(dirname $bug))
261 if [ "$PRIORITY" == "$pr" ]; then
262 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
263 . ${PEOPLE}/${CREATOR}/account.conf
264 cat << EOT
265 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
266 ID: $id <a href="?id=$id">$BUG</a> <span class="date">$DATE</span>
267 EOT
268 fi
269 unset CREATOR USER MAIL
270 done
271 done
272 }
274 # Stripped down Wiki parser for bug desc and messages which are simply
275 # displayed in <pre>
276 wiki_parser() {
277 sed \
278 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
279 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
280 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
281 }
283 # Bug page
284 bug_page() {
285 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
286 . $PEOPLE/$CREATOR/account.conf
287 else
288 MAIL="default"
289 fi
290 cat << EOT
291 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
293 <p>
294 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
295 </p>
296 <p>
297 $(gettext "Date:") $DATE -
298 $(eval_gettext 'Priority $PRIORITY') -
299 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
300 </p>
302 <pre>
303 $(echo "$DESC" | wiki_parser)
304 </pre>
306 <div id="tools">
307 EOT
308 if check_auth; then
309 if [ "$STATUS" == "OPEN" ]; then
310 cat << EOT
311 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
312 <a href="?edit=$id">$(gettext "Edit bug")</a>
313 EOT
314 else
315 cat << EOT
316 <a href="?id=$id&amp;open">$(gettext "Re open bug")</a>
317 EOT
318 fi
319 fi
320 cat << EOT
321 </div>
323 <h3>$(gettext "Messages")</h3>
324 EOT
325 [ "$msgs" == "0" ] && gettext "No messages"
326 for msg in $(ls -1tr $bugdir/$id/msg.*)
327 do
328 . $msg
329 if [ "$MSG" ]; then
330 msgid=$(echo $msg | cut -d "." -f 2)
331 del=""
332 # User can delete his post as well as admin.
333 if [ "$user" == "$USER" ] || admin_user; then
334 del="<a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
335 fi
336 cat << EOT
337 <p><strong>$USER</strong> $DATE $del</p>
338 <pre>
339 $(echo "$MSG" | wiki_parser)
340 </pre>
341 EOT
342 fi
343 unset NAME DATE MSG
344 done
345 if check_auth; then
346 cat << EOT
347 <div>
348 <h3>$(gettext "New message")</h3>
349 <form method="get" action="$script">
350 <input type="hidden" name="id" value="$id" />
351 <textarea name="msg" rows="8"></textarea>
352 <p><input type="submit" value="$(gettext 'Send message')" /></p>
353 </form>
354 </div>
355 EOT
356 fi
357 }
359 # Write a new message
360 new_msg() {
361 date=$(date "+%Y-%m-%d %H:%M")
362 msgs=$(ls -1 $bugdir/$id/msg.* | wc -l)
363 count=$(($msgs + 1))
364 if check_auth; then
365 USER="$user"
366 fi
367 js_log "Will write message in $bugdir/$id/msg.$count "
368 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
369 USER="$USER"
370 DATE="$date"
371 MSG="$(GETfiltered msg)"
372 EOT
373 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
374 rm -f $bugdir/$id/msg.$count.tmp
375 }
377 # Create a new Bug
378 new_bug() {
379 count=$(ls -1 $bugdir | wc -l)
380 date=$(date "+%Y-%m-%d %H:%M")
381 # Sanity check, JS may be disabled.
382 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
383 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
384 if check_auth; then
385 USER="$user"
386 fi
387 mkdir -p $bugdir/$count
388 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.tmp << EOT
389 # SliTaz Bug configuration
391 BUG="$(GETfiltered bug)"
392 STATUS="OPEN"
393 PRIORITY="$(GET priority)"
394 CREATOR="$USER"
395 DATE="$date"
396 PKGS="$(GETfiltered pkgs)"
398 DESC="$(GETfiltered desc)"
399 EOT
400 fold -s -w 80 $bugdir/$bug/bug.tmp > $bugdir/$bug/bug.conf
401 rm -f $bugdir/$bug/bug.tmp
402 }
404 # New bug page for the web interface
405 new_bug_page() {
406 cat << EOT
407 <h2>$(gettext "New Bug")</h2>
408 <div id="newbug">
410 <form method="get" action="$script" onsubmit="return checkNewBug();">
411 <input type="hidden" name="addbug" />
412 <table>
413 <tbody>
414 <tr>
415 <td>$(gettext "Bug title")*</td>
416 <td><input type="text" name="bug" /></td>
417 </tr>
418 <tr>
419 <td>$(gettext "Description")*</td>
420 <td><textarea name="desc"></textarea></td>
421 </tr>
422 <tr>
423 <td>$(gettext "Packages")</td>
424 <td><input type="text" name="pkgs" /></td>
425 </tr>
426 <tr>
427 <td>$(gettext "Priority")</td>
428 <td>
429 <select name="priority">
430 <option value="standard">$(gettext "Standard")</option>
431 <option value="critical">$(gettext "Critical")</option>
432 </select>
433 <input type="submit" value="$(gettext "Create Bug")" />
434 </td>
435 </tr>
436 </tbody>
437 </table>
438 </form>
440 <p>
441 $(gettext "* field is obligatory. You can also specify affected packages.")
442 </p>
444 </div>
445 EOT
446 }
449 # Edit/Save a bug configuration file
450 edit_bug() {
451 cat << EOT
452 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
453 <div id="edit">
455 <form method="get" action="$script">
456 <textarea name="bugconf">$(cat $bugdir/$bug/bug.conf)</textarea>
457 <input type="hidden" name="bug" value="$bug" />
458 <input type="submit" value="$(gettext 'Save configuration')" />
459 </form>
461 </div>
462 EOT
463 }
465 save_bug() {
466 bug="$(GET bug)"
467 content="$(GET bugconf)"
468 sed "s|\"|'|" | fold -s | sed "s/$(echo -en '\r') /\n/g" > $bugdir/$bug/bug.tmp << EOT
469 $content
470 EOT
471 fold -s -w 80 $bugdir/$bug/bug.tmp > $bugdir/$bug/bug.conf
472 rm -f $bugdir/$bug/bug.tmp
473 }
475 # Close a fixed bug
476 close_bug() {
477 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
478 }
480 # Re open an old bug
481 open_bug() {
482 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
483 }
485 # Get and display Gravatar image: get_gravatar email size
486 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
487 get_gravatar() {
488 email=$1
489 size=$2
490 [ "$size" ] || size=48
491 url="http://www.gravatar.com/avatar"
492 md5=$(md5crypt $email)
493 echo "<img src=\"$url/$md5?d=identicon&amp;s=$size\" alt=\"\" />"
494 }
496 # Create a new user in AUTH_FILE and PEOPLE
497 new_user_config() {
498 if [ ! "$online" ]; then
499 name="$(GET name)"
500 mail="$(GET mail)"
501 pass="$(GET pass)"
502 echo "Creating Server Key..."
503 fi
504 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
505 echo "$user:$pass" >> $AUTH_FILE
506 mkdir -pm0700 $PEOPLE/$user/
507 cat > $PEOPLE/$user/account.conf << EOT
508 # SliTaz user configuration
509 #
511 NAME="$name"
512 USER="$user"
513 MAIL="$mail"
514 KEY="$key"
516 LOCATION="$(GET location)"
517 RELEASES="$(GET releases)"
518 PACKAGES="$(GET packages)"
519 EOT
520 chmod 0600 $PEOPLE/$user/account.conf
521 if [ ! -f $PEOPLE/$user/account.conf ]; then
522 echo "ERROR: User creation failed!"
523 fi
524 }
526 ########################################################################
527 # POST actions #
528 ########################################################################
530 case " $(POST) " in
531 *\ auth\ *)
532 header
533 html_header
534 # Authenticate user. Create a session file in $sessions to be used
535 # by check_auth. We have the user login name and a peer session
536 # md5 string in the COOKIE.
537 user="$(POST auth)"
538 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
540 IDLOC=""
541 if [[ "$(POST id)" ]] ;then
542 IDLOC="&id=$(POST id)"
543 fi
545 if [ ! -f $AUTH_FILE ] ; then
546 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
547 js_redirection_to "$script?login$IDLOC"
548 fi;
550 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
551 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
552 if [[ "$(POST id)" ]] ;then
553 IDLOC="?id=$(POST id)"
554 fi
555 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
556 mkdir -p $sessions
557 # Log last login
558 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
559 echo "$md5session" > $sessions/$user
560 js_set_cookie 'auth' "$user:$md5session"
561 js_log "Login authentication has been executed & accepted :)"
562 js_redirection_to "$script$IDLOC"
563 else
564 js_log "Login authentication has been executed & refused"
565 js_redirection_to "$script?login&error$IDLOC"
566 fi
567 html_footer ;;
568 *\ signup\ *)
569 # POST action for online signup
570 name="$(POST name)"
571 user="$(POST user)"
572 mail="$(POST mail)"
573 pass="$(md5crypt "$(POST pass)")"
574 if ! grep "^${user}:" $AUTH_FILE; then
575 online="yes"
576 new_user_config
577 header "Location: $SCRIPT_NAME?login"
578 else
579 header
580 html_header
581 user_box
582 echo "<h2>$(gettext "User already exists:") $user</h2>"
583 html_footer && exit 0
584 fi ;;
585 esac
587 #
588 # Plugins Now!
589 #
591 for p in $(ls -1 $plugins)
592 do
593 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
594 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
595 done
597 ########################################################################
598 # GET actions #
599 ########################################################################
601 case " $(GET) " in
602 *\ README\ *)
603 header
604 html_header
605 user_box
606 echo '<h2>README</h2>'
607 echo '<pre>'
608 if [ -f "README" ]; then
609 cat README
610 else
611 cat /usr/share/doc/tazbug/README
612 fi
613 echo '</pre>'
614 html_footer ;;
615 *\ closed\ *)
616 # Show all closed bugs.
617 header
618 html_header
619 user_box
620 list_bugs CLOSED
621 echo "</pre>"
622 html_footer ;;
623 *\ login\ *)
624 # The login page
625 [ "$(GET error)" ] && \
626 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
627 header
628 html_header
629 user_box
630 login_page
631 html_footer ;;
632 *\ logout\ *)
633 header
634 html_header
635 if check_auth; then
636 rm -f "$sessions/$user"
637 js_unset_cookie 'auth'
638 js_redirection_to "$script"
639 fi ;;
640 *\ user\ *)
641 # User profile
642 last="$(cat $PEOPLE/"$(GET user)"/last)"
643 header
644 html_header
645 user_box
646 . $PEOPLE/"$(GET user)"/account.conf
647 cat << EOT
648 <h2>$(get_gravatar $MAIL) $NAME</h2>
650 <pre>
651 $(gettext "User name :") $USER
652 $(gettext "Last login :") $last
653 EOT
654 if check_auth && [ "$(GET user)" == "$user" ]; then
655 auth_people
656 else
657 # check_auth will set VARS to current logged user: re-source
658 . $PEOPLE/"$(GET user)"/account.conf
659 public_people
660 fi
661 html_footer ;;
662 *\ newbug\ *)
663 # Add a bug from web interface.
664 header
665 html_header
666 user_box
667 if check_auth; then
668 new_bug_page
669 else
670 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
671 fi
672 html_footer ;;
673 *\ addbug\ *)
674 # Add a bug from web interface.
675 header
676 html_header
677 if check_auth; then
678 new_bug
679 js_redirection_to "$script?id=$count"
680 fi ;;
681 *\ edit\ *)
682 bug="$(GET edit)"
683 header
684 html_header
685 user_box
686 edit_bug
687 html_footer ;;
688 *\ bugconf\ *)
689 header
690 html_header
691 if check_auth; then
692 save_bug
693 js_redirection_to "$script?id=$bug"
694 fi ;;
695 *\ id\ *)
696 # Empty deleted messages to keep msg count working.
697 header
698 html_header
699 id="$(GET id)"
700 [ "$(GET close)" ] && close_bug
701 [ "$(GET open)" ] && open_bug
702 [ "$(GET msg)" ] && new_msg
703 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
704 touch $bugdir/$id/msg.$(GET delmsg)
705 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
706 user_box
707 . $bugdir/$id/bug.conf
708 bug_page
709 html_footer ;;
710 *\ signup\ *)
711 # Signup
712 if [ "$(GET online)" ];then
713 header
714 html_header
715 user_box
716 echo "<h2>$(gettext "Sign Up")</h2>"
717 if [ "$ONLINE_SIGNUP" == "yes" ]; then
718 signup_page
719 else
720 gettext "Online registration is disabled"
721 fi
722 html_footer && exit 0
723 else
724 header "Content-type: text/plain;"
725 user="$(GET signup)"
726 echo "Requested user login : $user"
727 if fgrep -q "$user:" $AUTH_FILE; then
728 echo "ERROR: User already exists" && exit 1
729 else
730 echo "Creating account for : $(GET name)"
731 new_user_config
732 fi
733 fi ;;
734 *\ key\ *)
735 # Let user post new bug or message with crypted key (no gettext)
736 #
737 # Testing only and is security acceptable ?
738 #
739 key="$(GET key)"
740 id="$(GET bug)"
741 header "Content-type: text/plain;"
742 echo "Checking secure key..."
743 if fgrep -qH $key $PEOPLE/*/account.conf; then
744 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
745 . $conf
746 echo "Authenticated: $NAME ($USER)"
747 case " $(GET) " in
748 *\ msg\ *)
749 [ ! "$id" ] && echo "Missing bug ID" && exit 0
750 echo "Posting new message to bug: $id"
751 echo "Message: $(GET msg)"
752 new_msg ;;
753 *\ bug\ *)
754 echo "Adding new bug: $(GET bug)"
755 echo "Description: $(GET desc)"
756 new_bug ;;
757 esac
758 else
759 echo "Not a valid SliTaz user key"
760 exit 0
761 fi ;;
762 *\ search\ *)
763 found=0
764 header
765 html_header
766 user_box
767 cat << EOT
768 <h2>$(gettext "Search")</h2>
769 <form method="get" action="$script">
770 <input type="text" name="search" />
771 <input type="submit" value="$(gettext 'Search')" />
772 </form>
773 <div>
774 EOT
775 cd $bugdir
776 for bug in *
777 do
778 result=$(fgrep -i -h "$(GET search)" $bug/*)
779 if [ "$result" ]; then
780 found=$(($found + 1))
781 id=${bug}
782 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
783 echo '<pre>'
784 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
785 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
786 echo '</pre>'
787 fi
788 done
789 if [ "$found" == "0" ]; then
790 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
791 else
792 echo "<p> $found $(gettext 'results found')</p>"
793 fi
794 echo '</div>'
795 html_footer ;;
796 *)
797 # Default page.
798 bugs=$(ls -1 $bugdir | wc -l)
799 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
800 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
801 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
802 pct=0
803 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
804 header
805 html_header
806 user_box
808 cat << EOT
810 <h2>$(gettext "Summary")</h2>
812 <p>
813 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
814 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
815 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
816 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
817 </p>
819 <div class="pctbar">
820 <div class="pct" style="width: ${pct}%;">${pct}%</div>
821 </div>
823 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
824 more information. You may also be interested by the SliTaz \
825 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
826 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
827 enter your term and press ENTER.")
828 </p>
830 <div id="tools">
831 <a href="?closed">$(gettext 'View closed bugs')</a>
832 EOT
833 if check_auth; then
834 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
835 echo "$PLUGINS_TOOLS"
836 fi
837 cat << EOT
838 </div>
840 <h3>$(gettext "Latest Bugs")</h3>
841 EOT
842 # List last 3 bugs
843 echo "<pre>"
844 for lb in $(ls ${bugdir} | sort -r -n | head -n 3)
845 do
846 list_bug ${lb}
847 done
848 echo "</pre>"
849 list_bugs OPEN
850 echo "</pre>"
851 html_footer ;;
852 esac
854 exit 0