tazbug view web/bugs.cgi @ rev 78

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