tazbug view web/bugs.cgi @ rev 123

Use new admin config and up users plugins from TinyCM
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 21 00:51:31 2017 +0100 (2017-02-21)
parents b19dbd851223
children 4dab1a5b9cb6
line source
1 #!/bin/sh
2 #
3 # TazBug Web interface
4 #
5 # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
6 #
7 . /usr/lib/slitaz/httphelper.sh
9 # Source config file
10 . ./config.cgi
12 # Internal variable
13 bugdir="$PWD/bug"
14 plugins="plugins"
15 sessions="/tmp/bugs/sessions"
16 script="$SCRIPT_NAME"
18 # Content negotiation for Gettext
19 IFS=","
20 for lang in $HTTP_ACCEPT_LANGUAGE
21 do
22 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
23 case "$lang" in
24 en) LANG="C" && break ;;
25 de) LANG="de_DE" && break ;;
26 es) LANG="es_ES" && break ;;
27 fr) LANG="fr_FR" && break ;;
28 it) LANG="it_IT" && break ;;
29 pt) LANG="pt_BR" && break ;;
30 ru) LANG="ru_RU" && break ;;
31 zh) LANG="zh_TW" && break ;;
32 esac
33 done
34 unset IFS
35 export LANG LC_ALL=$LANG
37 # Internationalization: $(gettext "")
38 . /usr/bin/gettext.sh
39 TEXTDOMAIN='tazbug'
40 export TEXTDOMAIN
42 #
43 # Functions
44 #
46 # HTML 5 header.
47 html_header() {
48 cat lib/header.html
49 }
51 # HTML 5 footer.
52 html_footer() {
53 cat << EOT
54 </div>
56 <div id="footer">
57 <a href="$script">SliTaz Bugs</a> -
58 <a href="$script?README">README</a>
59 </div>
61 </body>
62 </html>
63 EOT
64 }
66 GETfiltered() {
67 GET $1 | sed -e "s/'/\&#39;/g; s|\n|<br/>|g; s/\t/\&#09;/g;s/\%22/\\\"/g"
68 }
70 js_redirection_to() {
71 js_log "Redirecting to $1"
72 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
73 }
75 js_log() {
76 echo "<script type=\"text/javascript\">console.log('$1')</script>";
77 }
79 js_set_cookie() {
80 name=$1
81 value=$2
82 js_log 'Setting cookie.'
83 cat << EOT
84 <script type="text/javascript">
85 document.cookie = '$name=$value; expires=0; path=/';
86 </script>
87 EOT
88 }
90 js_unset_cookie() {
91 name=$1
92 js_log 'Unsetting cookie.'
93 cat << EOT
94 <script type="text/javascript">
95 document.cookie = '$1=""; expires=-1; path=/;'
96 </script>
97 EOT
98 }
100 # Check if user is auth
101 check_auth() {
102 auth="$(COOKIE auth)"
103 user="$(echo $auth | cut -d ":" -f 1)"
104 md5cookie="$(echo $auth | cut -d ":" -f 2)"
105 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
106 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
107 return 0
108 else
109 return 1
110 fi
111 }
113 # Check if user is admin
114 admin_user() {
115 fgrep -w -q "$user" ${ADMIN_USERS}
116 }
118 # Authenticated or not
119 user_box() {
121 IDLOC=""
122 if [[ "$(GET id)" ]] ;then
123 IDLOC="&id=$(GET id)"
124 fi
126 if check_auth; then
127 . $PEOPLE/$user/account.conf
128 cat << EOT
129 <div id="user">
130 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
131 <a href="?logout">$(gettext 'Logout')</a>
132 </div>
133 EOT
134 else
135 cat << EOT
136 <div id="user">
137 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
138 <a href="?login$IDLOC">$(gettext 'Login')</a>
139 </div>
140 EOT
141 fi
142 cat << EOT
144 <div id="search">
145 <form method="get" action="$script">
146 <input type="text" name="search" placeholder="$(gettext 'Search')" />
147 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
148 </form>
149 </div>
151 <!-- Content -->
152 <div id="content">
154 EOT
155 }
157 # Signup page
158 signup_page() {
159 cat << EOT
161 <div id="signup">
162 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
163 <input type="hidden" name="signup" value="new" />
164 <input type="text" name="name" placeholder="$(gettext "Real name")" />
165 <input type="text" name="user" placeholder="$(gettext "User name")" />
166 <input type="text" name="mail" placeholder="$(gettext "Email")" />
167 <input type="password" name="pass" placeholder="$(gettext "Password")" />
168 <div>
169 <input type="submit" value="$(gettext "Create new account")" />
170 </div>
171 </form>
172 </div>
174 EOT
175 }
177 # Link for online signup if enabled.
178 online_signup() {
179 if [ "$ONLINE_SIGNUP" == "yes" ]; then
180 echo -n "<a href='$script?signup&amp;online'>"
181 gettext "Sign Up Online"
182 echo '</a></p>'
183 fi
184 }
186 # Login page
187 login_page() {
188 cat << EOT
189 <h2>$(gettext 'Login')</h2>
191 <div id="account-info">
192 <p>$(gettext "No account yet?")</p>
193 $(online_signup)
194 <p>$(gettext "Tip: to attach big files or images, you can use SliTaz Paste \
195 services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a></p>
196 </div>
198 <div id="login">
199 <form method="post" action="$script">
200 <div>
201 <input type="text" name="auth" placeholder="$(gettext 'User name')" />
202 </div>
203 <input type="password" name="pass" placeholder="$(gettext 'Password')" />
204 <div>
205 <input type="hidden" name="id" value="$(GET id)" />
206 <input type="submit" value="$(gettext 'Log in')" />
207 $error
208 </div>
209 </form>
210 </div>
212 <div style="clear: both;"></div>
213 EOT
214 }
216 # Usage: list_bug ID
217 list_bug() {
218 id="$1"
219 . ${bugdir}/${id}/bug.conf
220 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
221 . ${PEOPLE}/${CREATOR}/account.conf
222 cat << EOT
223 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
224 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
225 EOT
226 unset CREATOR USER MAIL
227 }
229 # Usage: list_bugs STATUS
230 list_bugs() {
231 status="$1"
232 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
233 echo "<pre>"
234 for pr in critical standard
235 do
236 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
237 do
238 . $bug
239 id=$(basename $(dirname $bug))
240 if [ "$PRIORITY" == "$pr" ]; then
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 fi
248 unset CREATOR USER MAIL
249 done
250 done
251 }
253 # Usage: list_msg path
254 list_msg() {
255 msg="$1"
256 dir=$(dirname $msg)
257 id=$(basename $dir)
258 . ${msg}
259 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
260 . ${PEOPLE}/${USER}/account.conf
261 cat << EOT
262 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
263 ID: <a href="?id=$id">Bug $id</a> by $USER <span class="date">- $DATE</span>
264 EOT
265 unset CREATOR USER MAIL
266 }
268 # Stripped down Wiki parser for bug desc and messages which are simply
269 # displayed in <pre>
270 wiki_parser() {
271 sed \
272 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
273 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
274 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
275 }
277 # Bug page
278 bug_page() {
279 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
280 . $PEOPLE/$CREATOR/account.conf
281 else
282 MAIL="default"
283 fi
284 cat << EOT
285 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
287 <p>
288 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
289 </p>
290 <p>
291 $(gettext "Date:") $DATE -
292 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
293 $(eval_gettext 'Priority $PRIORITY') -
294 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
295 </p>
297 <pre>
298 $(cat $bugdir/$id/desc.txt | wiki_parser)
299 </pre>
301 <div id="tools">
302 EOT
303 if check_auth; then
304 if [ "$STATUS" == "OPEN" ]; then
305 cat << EOT
306 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
307 EOT
308 # Only original user and admin can edit a bug
309 if [ "$user" == "$CREATOR" ] || admin_user; then
310 cat << EOT
311 <a href="?editbug=$id">$(gettext "Edit bug")</a>
312 EOT
313 fi
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. ID is set by counting dirs in bug/ + 1
378 new_bug() {
379 count=$(ls $bugdir | sort -g | tail -n 1)
380 count=$(($count +1))
381 date=$(date "+%Y-%m-%d %H:%M")
382 # Sanity check, JS may be disabled.
383 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
384 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
385 if check_auth; then
386 USER="$user"
387 fi
388 mkdir -p $bugdir/$count
389 # bug.conf
390 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
391 # SliTaz Bug configuration
393 BUG="$(GETfiltered bug)"
394 STATUS="OPEN"
395 PRIORITY="$(GET priority)"
396 CREATOR="$USER"
397 DATE="$date"
398 PKGS="$(GETfiltered pkgs)"
399 EOT
400 # desc.txt
401 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/desc.tmp << EOT
402 $(GETfiltered desc)
403 EOT
404 fold -s -w 80 $bugdir/$count/desc.tmp > $bugdir/$count/desc.txt
405 rm -f $bugdir/$count/*.tmp
406 }
408 # New bug page for the web interface
409 new_bug_page() {
410 cat << EOT
411 <h2>$(gettext "New Bug")</h2>
412 <div id="newbug">
414 <form method="get" action="$script" onsubmit="return checkNewBug();">
415 <input type="hidden" name="addbug" />
416 <table>
417 <tbody>
418 <tr>
419 <td>$(gettext "Bug title")*</td>
420 <td><input type="text" name="bug" /></td>
421 </tr>
422 <tr>
423 <td>$(gettext "Description")*</td>
424 <td><textarea name="desc"></textarea></td>
425 </tr>
426 <tr>
427 <td>$(gettext "Packages")</td>
428 <td><input type="text" name="pkgs" /></td>
429 </tr>
430 <tr>
431 <td>$(gettext "Priority")</td>
432 <td>
433 <select name="priority">
434 <option value="standard">$(gettext "Standard")</option>
435 <option value="critical">$(gettext "Critical")</option>
436 </select>
437 <input type="submit" value="$(gettext "Create Bug")" />
438 </td>
439 </tr>
440 </tbody>
441 </table>
442 </form>
444 <p>
445 $(gettext "* field is obligatory. You can also specify affected packages.")
446 </p>
448 </div>
449 EOT
450 }
452 # Edit/Save a bug
453 edit_bug() {
454 . $bugdir/$id/bug.conf
455 if admin_user || [ "$user" == "$CREATOR" ]; then
456 continue
457 else
458 gettext "You can't edit someone else's bug!" && exit 0
459 fi
460 cat << EOT
461 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
462 <div id="editbug">
464 <form method="get" action="$script">
465 <input type="hidden" name="savebug" />
466 <input type="hidden" name="id" value="$id" />
467 <input type="hidden" name="creator" value="$CREATOR" />
468 <input type="hidden" name="date" value="$DATE" />
469 <table>
470 <tbody>
471 <tr>
472 <td>$(gettext "Bug title")</td>
473 <td><input type="text" name="bug" value="$BUG" /></td>
474 </tr>
475 <tr>
476 <td>$(gettext "Description")</td>
477 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
478 </tr>
479 <tr>
480 <td>$(gettext "Packages")</td>
481 <td><input type="text" name="pkgs" value="$PKGS" /></td>
482 </tr>
483 <tr>
484 <td>$(gettext "Priority")</td>
485 <td>
486 <select name="priority">
487 <option value="$PRIORITY">$PRIORITY</option>
488 <option value="standard">$(gettext "Standard")</option>
489 <option value="critical">$(gettext "Critical")</option>
490 </select>
491 <input type="submit" value="$(gettext 'Save configuration')" />
492 </td>
493 </tr>
494 </tbody>
495 </table>
496 </form>
498 </div>
499 EOT
500 }
502 save_bug() {
503 id="$(GET id)"
504 # bug.conf
505 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
506 # SliTaz Bug configuration
508 BUG="$(GETfiltered bug)"
509 STATUS="OPEN"
510 PRIORITY="$(GET priority)"
511 CREATOR="$(GET creator)"
512 DATE="$(GET date)"
513 PKGS="$(GETfiltered pkgs)"
514 EOT
515 # desc.txt
516 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
517 $(GETfiltered desc)
518 EOT
519 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
520 rm -f $bugdir/$id/*.tmp
521 }
523 # Close a fixed bug
524 close_bug() {
525 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
526 }
528 # Re open an old bug
529 open_bug() {
530 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
531 }
533 # Get and display Gravatar image: get_gravatar email size
534 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
535 get_gravatar() {
536 email=$1
537 size=$2
538 [ "$size" ] || size=48
539 url="http://www.gravatar.com/avatar"
540 md5=$(md5crypt $email)
541 echo "<img src=\"$url/$md5?d=identicon&amp;s=$size\" alt=\"\" />"
542 }
544 # Create a new user in AUTH_FILE and PEOPLE
545 new_user_config() {
546 if [ ! -f "$AUTH_FILE" ]; then
547 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
548 fi
549 echo "$user:$pass" >> $AUTH_FILE
550 mkdir -pm0700 $PEOPLE/${user}
551 cat > $PEOPLE/$user/account.conf << EOT
552 # User configuration
553 NAME="$name"
554 USER="$user"
555 MAIL="$mail"
556 EOT
557 chmod 0600 $PEOPLE/$user/account.conf
558 # First created user is admin
559 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
560 echo "$user" > ${ADMIN_USERS}
561 fi
562 }
564 ########################################################################
565 # POST actions #
566 ########################################################################
568 case " $(POST) " in
569 *\ auth\ *)
570 header
571 html_header
572 # Authenticate user. Create a session file in $sessions to be used
573 # by check_auth. We have the user login name and a peer session
574 # md5 string in the COOKIE.
575 user="$(POST auth)"
576 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
578 IDLOC=""
579 if [[ "$(POST id)" ]] ;then
580 IDLOC="&id=$(POST id)"
581 fi
583 if [ ! -f $AUTH_FILE ] ; then
584 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
585 js_redirection_to "$script?login$IDLOC"
586 fi;
588 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
589 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
590 if [[ "$(POST id)" ]] ;then
591 IDLOC="?id=$(POST id)"
592 fi
593 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
594 mkdir -p $sessions
595 # Log last login
596 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
597 echo "$md5session" > $sessions/$user
598 js_set_cookie 'auth' "$user:$md5session"
599 js_log "Login authentication has been executed & accepted :)"
600 js_redirection_to "$script$IDLOC"
601 else
602 js_log "Login authentication has been executed & refused"
603 js_redirection_to "$script?login&error$IDLOC"
604 fi
605 html_footer ;;
606 *\ signup\ *)
607 # POST action for online signup
608 name="$(POST name)"
609 user="$(POST user)"
610 mail="$(POST mail)"
611 pass="$(md5crypt "$(POST pass)")"
612 if ! grep "^${user}:" $AUTH_FILE; then
613 online="yes"
614 new_user_config
615 header "Location: $SCRIPT_NAME?login"
616 else
617 header
618 html_header
619 user_box
620 echo "<h2>$(gettext "User already exists:") $user</h2>"
621 html_footer && exit 0
622 fi ;;
623 esac
625 #
626 # Plugins Now!
627 #
629 for p in $(ls -1 $plugins)
630 do
631 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
632 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
633 done
635 ########################################################################
636 # GET actions #
637 ########################################################################
639 case " $(GET) " in
640 *\ README\ *)
641 header
642 html_header
643 user_box
644 echo '<h2>README</h2>'
645 echo '<pre>'
646 if [ -f "README" ]; then
647 cat README
648 else
649 cat /usr/share/doc/tazbug/README
650 fi
651 echo '</pre>'
652 html_footer ;;
653 *\ closed\ *)
654 # Show all closed bugs.
655 header
656 html_header
657 user_box
658 list_bugs CLOSED
659 echo "</pre>"
660 html_footer ;;
661 *\ login\ *)
662 # The login page
663 [ "$(GET error)" ] && \
664 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
665 header
666 html_header
667 user_box
668 login_page
669 html_footer ;;
670 *\ logout\ *)
671 header
672 html_header
673 if check_auth; then
674 rm -f "$sessions/$user"
675 js_unset_cookie 'auth'
676 js_redirection_to "$script"
677 fi ;;
678 *\ user\ *)
679 # User profile. Use the users plugin for more functions
680 last="$(cat $PEOPLE/"$(GET user)"/last)"
681 header
682 html_header
683 user_box
684 . $PEOPLE/"$(GET user)"/account.conf
685 cat << EOT
686 <h2>$(get_gravatar $MAIL) $NAME</h2>
688 <pre>
689 $(gettext "User name :") $USER
690 $(gettext "Last login :") $last
691 </pre>
692 EOT
693 html_footer ;;
694 *\ newbug\ *)
695 # Create a bug from web interface.
696 header
697 html_header
698 user_box
699 if check_auth; then
700 new_bug_page
701 else
702 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
703 fi
704 html_footer ;;
705 *\ addbug\ *)
706 # Save a new bug from web interface.
707 header
708 html_header
709 if check_auth; then
710 new_bug
711 js_redirection_to "$script?id=$count"
712 fi ;;
713 *\ editbug\ *)
714 # Edit existing bug
715 id="$(GET editbug)"
716 header
717 html_header
718 user_box
719 edit_bug
720 html_footer ;;
721 *\ savebug\ *)
722 header
723 html_header
724 if check_auth; then
725 save_bug
726 js_redirection_to "$script?id=$id"
727 fi ;;
728 *\ id\ *)
729 # Empty deleted messages to keep msg count working.
730 header
731 html_header
732 id="$(GET id)"
733 [ "$(GET close)" ] && close_bug
734 [ "$(GET open)" ] && open_bug
735 [ "$(GET msg)" ] && new_msg
736 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
737 touch $bugdir/$id/msg.$(GET delmsg)
738 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
739 user_box
740 . $bugdir/$id/bug.conf
741 bug_page
742 html_footer ;;
743 *\ signup\ *)
744 # Signup
745 header
746 html_header
747 user_box
748 echo "<h2>$(gettext "Sign Up")</h2>"
749 if [ "$ONLINE_SIGNUP" == "yes" ]; then
750 signup_page
751 else
752 gettext "Online registration is disabled"
753 fi
754 html_footer ;;
756 *\ search\ *)
757 found=0
758 header
759 html_header
760 user_box
761 cat << EOT
762 <h2>$(gettext "Search")</h2>
763 <form method="get" action="$script">
764 <input type="text" name="search" />
765 <input type="submit" value="$(gettext 'Search')" />
766 </form>
767 <div>
768 EOT
769 cd $bugdir
770 for bug in *
771 do
772 result=$(fgrep -i -h "$(GET search)" $bug/*)
773 if [ "$result" ]; then
774 found=$(($found + 1))
775 id=${bug}
776 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
777 echo '<pre>'
778 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
779 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
780 echo '</pre>'
781 fi
782 done
783 if [ "$found" == "0" ]; then
784 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
785 else
786 echo "<p> $found $(gettext 'results found')</p>"
787 fi
788 echo '</div>'
789 html_footer ;;
790 *)
791 # Default page.
792 bugs=$(ls -1 $bugdir | wc -l)
793 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
794 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
795 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
796 pct=0
797 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
798 header
799 html_header
800 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 $BUGS_TOOLS
826 <a href="?closed">$(gettext 'View closed bugs')</a>
827 EOT
828 if check_auth; then
829 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
830 echo "$PLUGINS_TOOLS"
831 fi
832 cat << EOT
833 </div>
835 <h3>$(gettext "Latest Bugs")</h3>
836 EOT
837 # List last 4 bugs
838 echo "<pre>"
839 for lb in $(ls ${bugdir} | sort -r -n | head -n 4)
840 do
841 list_bug ${lb}
842 done
843 echo "</pre>"
844 # List last 4 messages
845 echo "<h3>$(gettext "Latest Messages")</h3>"
846 echo "<pre>"
847 for msg in $(ls -t ${bugdir}/*/msg.* | head -n 4)
848 do
849 list_msg ${msg}
850 done
851 echo "</pre>"
852 list_bugs OPEN
853 echo "</pre>"
854 html_footer ;;
855 esac
857 exit 0