tazbug view web/bugs.cgi @ rev 96
Fix ID incrementation (bug folders can be removed)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Feb 09 18:08:31 2017 +0100 (2017-02-09) |
parents | b73d5d055f8c |
children | 60234e42d5c4 |
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/ + 1
377 new_bug() {
378 count=$(ls $bugdir | sort -g | tail -n 1)
379 count=$(($count +1))
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/$count/bug.tmp > $bugdir/$count/bug.conf
401 rm -f $bugdir/$count/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|\"|'|" | 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&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 $BUGS_TOOLS
832 <a href="?closed">$(gettext 'View closed bugs')</a>
833 EOT
834 if check_auth; then
835 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
836 echo "$PLUGINS_TOOLS"
837 fi
838 cat << EOT
839 </div>
841 <h3>$(gettext "Latest Bugs")</h3>
842 EOT
843 # List last 3 bugs
844 echo "<pre>"
845 for lb in $(ls ${bugdir} | sort -r -n | head -n 3)
846 do
847 list_bug ${lb}
848 done
849 echo "</pre>"
850 list_bugs OPEN
851 echo "</pre>"
852 html_footer ;;
853 esac
855 exit 0