tazbug view web/bugs.cgi @ rev 81
web: fix new bug creation
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Feb 17 22:58:22 2014 +0100 (2014-02-17) |
parents | 7426a4db30d3 |
children | b73d5d055f8c |
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/'/\'/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 # 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 $(echo "$DESC" | 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 <a href="?edit=$id">$(gettext "Edit bug")</a>
312 EOT
313 else
314 cat << EOT
315 <a href="?id=$id&open">$(gettext "Re open bug")</a>
316 EOT
317 fi
318 fi
319 cat << EOT
320 </div>
322 <h3>$(gettext "Messages")</h3>
323 EOT
324 [ "$msgs" == "0" ] && gettext "No messages"
325 for msg in $(ls -1tr $bugdir/$id/msg.*)
326 do
327 . $msg
328 if [ "$MSG" ]; then
329 msgid=$(echo $msg | cut -d "." -f 2)
330 del=""
331 # User can delete his post as well as admin.
332 if [ "$user" == "$USER" ] || admin_user; then
333 del="<a href=\"?id=$id&delmsg=$msgid\">delete</a>"
334 fi
335 cat << EOT
336 <p><strong>$USER</strong> $DATE $del</p>
337 <pre>
338 $(echo "$MSG" | wiki_parser)
339 </pre>
340 EOT
341 fi
342 unset NAME DATE MSG
343 done
344 if check_auth; then
345 cat << EOT
346 <div>
347 <h3>$(gettext "New message")</h3>
348 <form method="get" action="$script">
349 <input type="hidden" name="id" value="$id" />
350 <textarea name="msg" rows="8"></textarea>
351 <p><input type="submit" value="$(gettext 'Send message')" /></p>
352 </form>
353 </div>
354 EOT
355 fi
356 }
358 # Write a new message
359 new_msg() {
360 date=$(date "+%Y-%m-%d %H:%M")
361 msgs=$(ls -1 $bugdir/$id/msg.* | wc -l)
362 count=$(($msgs + 1))
363 if check_auth; then
364 USER="$user"
365 fi
366 js_log "Will write message in $bugdir/$id/msg.$count "
367 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
368 USER="$USER"
369 DATE="$date"
370 MSG="$(GETfiltered msg)"
371 EOT
372 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
373 rm -f $bugdir/$id/msg.$count.tmp
374 }
376 # Create a new Bug. ID is set by counting dirs in bug/ including bug/0
377 new_bug() {
378 count=$(ls $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.tmp << 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 fold -s -w 80 $bugdir/$count/bug.tmp > $bugdir/$count/bug.conf
400 rm -f $bugdir/$count/bug.tmp
401 }
403 # New bug page for the web interface
404 new_bug_page() {
405 cat << EOT
406 <h2>$(gettext "New Bug")</h2>
407 <div id="newbug">
409 <form method="get" action="$script" onsubmit="return checkNewBug();">
410 <input type="hidden" name="addbug" />
411 <table>
412 <tbody>
413 <tr>
414 <td>$(gettext "Bug title")*</td>
415 <td><input type="text" name="bug" /></td>
416 </tr>
417 <tr>
418 <td>$(gettext "Description")*</td>
419 <td><textarea name="desc"></textarea></td>
420 </tr>
421 <tr>
422 <td>$(gettext "Packages")</td>
423 <td><input type="text" name="pkgs" /></td>
424 </tr>
425 <tr>
426 <td>$(gettext "Priority")</td>
427 <td>
428 <select name="priority">
429 <option value="standard">$(gettext "Standard")</option>
430 <option value="critical">$(gettext "Critical")</option>
431 </select>
432 <input type="submit" value="$(gettext "Create Bug")" />
433 </td>
434 </tr>
435 </tbody>
436 </table>
437 </form>
439 <p>
440 $(gettext "* field is obligatory. You can also specify affected packages.")
441 </p>
443 </div>
444 EOT
445 }
448 # Edit/Save a bug configuration file
449 edit_bug() {
450 cat << EOT
451 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
452 <div id="edit">
454 <form method="get" action="$script">
455 <textarea name="bugconf">$(cat $bugdir/$bug/bug.conf)</textarea>
456 <input type="hidden" name="bug" value="$bug" />
457 <input type="submit" value="$(gettext 'Save configuration')" />
458 </form>
460 </div>
461 EOT
462 }
464 save_bug() {
465 bug="$(GET bug)"
466 content="$(GET bugconf)"
467 sed "s|\"|'|" | sed "s/$(echo -en '\r') /\n/g" > $bugdir/$bug/bug.tmp << EOT
468 $content
469 EOT
470 fold -s -w 80 $bugdir/$bug/bug.tmp > $bugdir/$bug/bug.conf
471 rm -f $bugdir/$bug/bug.tmp
472 }
474 # Close a fixed bug
475 close_bug() {
476 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
477 }
479 # Re open an old bug
480 open_bug() {
481 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
482 }
484 # Get and display Gravatar image: get_gravatar email size
485 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
486 get_gravatar() {
487 email=$1
488 size=$2
489 [ "$size" ] || size=48
490 url="http://www.gravatar.com/avatar"
491 md5=$(md5crypt $email)
492 echo "<img src=\"$url/$md5?d=identicon&s=$size\" alt=\"\" />"
493 }
495 # Create a new user in AUTH_FILE and PEOPLE
496 new_user_config() {
497 if [ ! "$online" ]; then
498 name="$(GET name)"
499 mail="$(GET mail)"
500 pass="$(GET pass)"
501 echo "Creating Server Key..."
502 fi
503 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
504 echo "$user:$pass" >> $AUTH_FILE
505 mkdir -pm0700 $PEOPLE/$user/
506 cat > $PEOPLE/$user/account.conf << EOT
507 # SliTaz user configuration
508 #
510 NAME="$name"
511 USER="$user"
512 MAIL="$mail"
513 KEY="$key"
515 LOCATION="$(GET location)"
516 RELEASES="$(GET releases)"
517 PACKAGES="$(GET packages)"
518 EOT
519 chmod 0600 $PEOPLE/$user/account.conf
520 if [ ! -f $PEOPLE/$user/account.conf ]; then
521 echo "ERROR: User creation failed!"
522 fi
523 }
525 ########################################################################
526 # POST actions #
527 ########################################################################
529 case " $(POST) " in
530 *\ auth\ *)
531 header
532 html_header
533 # Authenticate user. Create a session file in $sessions to be used
534 # by check_auth. We have the user login name and a peer session
535 # md5 string in the COOKIE.
536 user="$(POST auth)"
537 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
539 IDLOC=""
540 if [[ "$(POST id)" ]] ;then
541 IDLOC="&id=$(POST id)"
542 fi
544 if [ ! -f $AUTH_FILE ] ; then
545 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
546 js_redirection_to "$script?login$IDLOC"
547 fi;
549 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
550 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
551 if [[ "$(POST id)" ]] ;then
552 IDLOC="?id=$(POST id)"
553 fi
554 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
555 mkdir -p $sessions
556 # Log last login
557 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
558 echo "$md5session" > $sessions/$user
559 js_set_cookie 'auth' "$user:$md5session"
560 js_log "Login authentication has been executed & accepted :)"
561 js_redirection_to "$script$IDLOC"
562 else
563 js_log "Login authentication has been executed & refused"
564 js_redirection_to "$script?login&error$IDLOC"
565 fi
566 html_footer ;;
567 *\ signup\ *)
568 # POST action for online signup
569 name="$(POST name)"
570 user="$(POST user)"
571 mail="$(POST mail)"
572 pass="$(md5crypt "$(POST pass)")"
573 if ! grep "^${user}:" $AUTH_FILE; then
574 online="yes"
575 new_user_config
576 header "Location: $SCRIPT_NAME?login"
577 else
578 header
579 html_header
580 user_box
581 echo "<h2>$(gettext "User already exists:") $user</h2>"
582 html_footer && exit 0
583 fi ;;
584 esac
586 #
587 # Plugins Now!
588 #
590 for p in $(ls -1 $plugins)
591 do
592 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
593 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
594 done
596 ########################################################################
597 # GET actions #
598 ########################################################################
600 case " $(GET) " in
601 *\ README\ *)
602 header
603 html_header
604 user_box
605 echo '<h2>README</h2>'
606 echo '<pre>'
607 if [ -f "README" ]; then
608 cat README
609 else
610 cat /usr/share/doc/tazbug/README
611 fi
612 echo '</pre>'
613 html_footer ;;
614 *\ closed\ *)
615 # Show all closed bugs.
616 header
617 html_header
618 user_box
619 list_bugs CLOSED
620 echo "</pre>"
621 html_footer ;;
622 *\ login\ *)
623 # The login page
624 [ "$(GET error)" ] && \
625 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
626 header
627 html_header
628 user_box
629 login_page
630 html_footer ;;
631 *\ logout\ *)
632 header
633 html_header
634 if check_auth; then
635 rm -f "$sessions/$user"
636 js_unset_cookie 'auth'
637 js_redirection_to "$script"
638 fi ;;
639 *\ user\ *)
640 # User profile
641 last="$(cat $PEOPLE/"$(GET user)"/last)"
642 header
643 html_header
644 user_box
645 . $PEOPLE/"$(GET user)"/account.conf
646 cat << EOT
647 <h2>$(get_gravatar $MAIL) $NAME</h2>
649 <pre>
650 $(gettext "User name :") $USER
651 $(gettext "Last login :") $last
652 EOT
653 if check_auth && [ "$(GET user)" == "$user" ]; then
654 auth_people
655 else
656 # check_auth will set VARS to current logged user: re-source
657 . $PEOPLE/"$(GET user)"/account.conf
658 public_people
659 fi
660 html_footer ;;
661 *\ newbug\ *)
662 # Add a bug from web interface.
663 header
664 html_header
665 user_box
666 if check_auth; then
667 new_bug_page
668 else
669 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
670 fi
671 html_footer ;;
672 *\ addbug\ *)
673 # Add a bug from web interface.
674 header
675 html_header
676 if check_auth; then
677 new_bug
678 js_redirection_to "$script?id=$count"
679 fi ;;
680 *\ edit\ *)
681 bug="$(GET edit)"
682 header
683 html_header
684 user_box
685 edit_bug
686 html_footer ;;
687 *\ bugconf\ *)
688 header
689 html_header
690 if check_auth; then
691 save_bug
692 js_redirection_to "$script?id=$bug"
693 fi ;;
694 *\ id\ *)
695 # Empty deleted messages to keep msg count working.
696 header
697 html_header
698 id="$(GET id)"
699 [ "$(GET close)" ] && close_bug
700 [ "$(GET open)" ] && open_bug
701 [ "$(GET msg)" ] && new_msg
702 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
703 touch $bugdir/$id/msg.$(GET delmsg)
704 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
705 user_box
706 . $bugdir/$id/bug.conf
707 bug_page
708 html_footer ;;
709 *\ signup\ *)
710 # Signup
711 if [ "$(GET online)" ];then
712 header
713 html_header
714 user_box
715 echo "<h2>$(gettext "Sign Up")</h2>"
716 if [ "$ONLINE_SIGNUP" == "yes" ]; then
717 signup_page
718 else
719 gettext "Online registration is disabled"
720 fi
721 html_footer && exit 0
722 else
723 header "Content-type: text/plain;"
724 user="$(GET signup)"
725 echo "Requested user login : $user"
726 if fgrep -q "$user:" $AUTH_FILE; then
727 echo "ERROR: User already exists" && exit 1
728 else
729 echo "Creating account for : $(GET name)"
730 new_user_config
731 fi
732 fi ;;
733 *\ key\ *)
734 # Let user post new bug or message with crypted key (no gettext)
735 #
736 # Testing only and is security acceptable ?
737 #
738 key="$(GET key)"
739 id="$(GET bug)"
740 header "Content-type: text/plain;"
741 echo "Checking secure key..."
742 if fgrep -qH $key $PEOPLE/*/account.conf; then
743 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
744 . $conf
745 echo "Authenticated: $NAME ($USER)"
746 case " $(GET) " in
747 *\ msg\ *)
748 [ ! "$id" ] && echo "Missing bug ID" && exit 0
749 echo "Posting new message to bug: $id"
750 echo "Message: $(GET msg)"
751 new_msg ;;
752 *\ bug\ *)
753 echo "Adding new bug: $(GET bug)"
754 echo "Description: $(GET desc)"
755 new_bug ;;
756 esac
757 else
758 echo "Not a valid SliTaz user key"
759 exit 0
760 fi ;;
761 *\ search\ *)
762 found=0
763 header
764 html_header
765 user_box
766 cat << EOT
767 <h2>$(gettext "Search")</h2>
768 <form method="get" action="$script">
769 <input type="text" name="search" />
770 <input type="submit" value="$(gettext 'Search')" />
771 </form>
772 <div>
773 EOT
774 cd $bugdir
775 for bug in *
776 do
777 result=$(fgrep -i -h "$(GET search)" $bug/*)
778 if [ "$result" ]; then
779 found=$(($found + 1))
780 id=${bug}
781 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
782 echo '<pre>'
783 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
784 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
785 echo '</pre>'
786 fi
787 done
788 if [ "$found" == "0" ]; then
789 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
790 else
791 echo "<p> $found $(gettext 'results found')</p>"
792 fi
793 echo '</div>'
794 html_footer ;;
795 *)
796 # Default page.
797 bugs=$(ls -1 $bugdir | wc -l)
798 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
799 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
800 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
801 pct=0
802 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
803 header
804 html_header
805 user_box
807 cat << EOT
809 <h2>$(gettext "Summary")</h2>
811 <p>
812 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
813 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
814 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
815 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
816 </p>
818 <div class="pctbar">
819 <div class="pct" style="width: ${pct}%;">${pct}%</div>
820 </div>
822 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
823 more information. You may also be interested by the SliTaz \
824 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
825 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
826 enter your term and press ENTER.")
827 </p>
829 <div id="tools">
830 $BUGS_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