tazbug view web/bugs.cgi @ rev 133
Get page generation time and back to fgrep for admin_user (faster) since httphelper.sh is now up-to-date on Tank
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Feb 21 17:29:18 2017 +0100 (2017-02-21) |
parents | 2499947037cf |
children | b5f62d54152e |
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"
17 timestamp="$(date -u +%s)"
19 # Content negotiation for Gettext
20 IFS=","
21 for lang in $HTTP_ACCEPT_LANGUAGE
22 do
23 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
24 case "$lang" in
25 en) LANG="C" && break ;;
26 de) LANG="de_DE" && break ;;
27 es) LANG="es_ES" && break ;;
28 fr) LANG="fr_FR" && break ;;
29 it) LANG="it_IT" && break ;;
30 pt) LANG="pt_BR" && break ;;
31 ru) LANG="ru_RU" && break ;;
32 zh) LANG="zh_TW" && break ;;
33 esac
34 done
35 unset IFS
36 export LANG LC_ALL=$LANG
38 # Internationalization: $(gettext "")
39 . /usr/bin/gettext.sh
40 TEXTDOMAIN='tazbug'
41 export TEXTDOMAIN
43 #
44 # Functions
45 #
47 # HTML 5 header.
48 html_header() {
49 cat lib/header.html
50 }
52 # HTML 5 footer.
53 html_footer() {
54 gentime=$(( $(date -u +%s) - ${timestamp} ))
55 cat << EOT
56 </div>
58 <div id="footer">
59 <a href="$script">SliTaz Bugs</a> -
60 <a href="$script?README">README</a>
61 - Page generated in ${gentime}s
62 </div>
64 </body>
65 </html>
66 EOT
67 }
69 GETfiltered() {
70 GET $1 | sed -e "s/'/\'/g; s|\n|<br/>|g; s/\t/\	/g;s/\%22/\\\"/g"
71 }
73 js_redirection_to() {
74 js_log "Redirecting to $1"
75 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
76 }
78 js_log() {
79 echo "<script type=\"text/javascript\">console.log('$1')</script>";
80 }
82 js_set_cookie() {
83 name=$1
84 value=$2
85 js_log 'Setting cookie.'
86 cat << EOT
87 <script type="text/javascript">
88 document.cookie = '$name=$value; expires=0; path=/';
89 </script>
90 EOT
91 }
93 js_unset_cookie() {
94 name=$1
95 js_log 'Unsetting cookie.'
96 cat << EOT
97 <script type="text/javascript">
98 document.cookie = '$1=""; expires=-1; path=/;'
99 </script>
100 EOT
101 }
103 # Check if user is auth
104 check_auth() {
105 auth="$(COOKIE auth)"
106 user="$(echo $auth | cut -d ":" -f 1)"
107 md5cookie="$(echo $auth | cut -d ":" -f 2)"
108 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
109 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
110 return 0
111 else
112 return 1
113 fi
114 }
116 # Check if user is admin
117 admin_user() {
118 fgrep -w -q "$user" ${ADMIN_USERS}
119 }
121 # Authenticated or not
122 user_box() {
124 IDLOC=""
125 if [[ "$(GET id)" ]] ;then
126 IDLOC="&id=$(GET id)"
127 fi
129 if check_auth; then
130 . $PEOPLE/$user/account.conf
131 cat << EOT
132 <div id="user">
133 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
134 <a href="?logout">$(gettext 'Logout')</a>
135 </div>
136 EOT
137 else
138 cat << EOT
139 <div id="user">
140 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
141 <a href="?login$IDLOC">$(gettext 'Login')</a>
142 </div>
143 EOT
144 fi
145 cat << EOT
147 <div id="search">
148 <form method="get" action="$script">
149 <input type="text" name="search" placeholder="$(gettext 'Search')" />
150 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
151 </form>
152 </div>
154 <!-- Content -->
155 <div id="content">
157 EOT
158 }
160 # Signup page
161 signup_page() {
162 cat << EOT
164 <div id="signup">
165 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
166 <input type="hidden" name="signup" value="new" />
167 <input type="text" name="name" placeholder="$(gettext "Real name")" />
168 <input type="text" name="user" placeholder="$(gettext "User name")" />
169 <input type="text" name="mail" placeholder="$(gettext "Email")" />
170 <input type="password" name="pass" placeholder="$(gettext "Password")" />
171 <div>
172 <input type="submit" value="$(gettext "Create new account")" />
173 </div>
174 </form>
175 </div>
177 EOT
178 }
180 # Link for online signup if enabled.
181 online_signup() {
182 if [ "$ONLINE_SIGNUP" == "yes" ]; then
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?")</p>
196 $(online_signup)
197 <p>$(gettext "Tip: to attach big files or images, you can use SliTaz Paste \
198 services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a></p>
199 </div>
201 <div id="login">
202 <form method="post" action="$script">
203 <div>
204 <input type="text" name="auth" placeholder="$(gettext 'User name')" />
205 </div>
206 <input type="password" name="pass" placeholder="$(gettext 'Password')" />
207 <div>
208 <input type="hidden" name="id" value="$(GET id)" />
209 <input type="submit" value="$(gettext 'Log in')" />
210 $error
211 </div>
212 </form>
213 </div>
215 <div style="clear: both;"></div>
216 EOT
217 }
219 # Usage: list_bug ID
220 list_bug() {
221 id="$1"
222 . ${bugdir}/${id}/bug.conf
223 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
224 . ${PEOPLE}/${CREATOR}/account.conf
225 cat << EOT
226 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
227 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
228 EOT
229 unset CREATOR USER MAIL
230 }
232 # Usage: list_bugs STATUS
233 list_bugs() {
234 status="$1"
235 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
236 echo "<pre>"
237 for pr in critical standard
238 do
239 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
240 do
241 . $bug
242 id=$(basename $(dirname $bug))
243 if [ "$PRIORITY" == "$pr" ]; then
244 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
245 . ${PEOPLE}/${CREATOR}/account.conf
246 cat << EOT
247 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
248 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
249 EOT
250 fi
251 unset CREATOR USER MAIL
252 done
253 done
254 }
256 # Usage: list_msg path
257 list_msg() {
258 msg="$1"
259 dir=$(dirname $msg)
260 id=$(basename $dir)
261 . ${msg}
262 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
263 . ${PEOPLE}/${USER}/account.conf
264 cat << EOT
265 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
266 ID: <a href="?id=$id">Bug $id</a> by $USER <span class="date">- $DATE</span>
267 EOT
268 unset CREATOR USER MAIL
269 }
271 # Stripped down Wiki parser for bug desc and messages which are simply
272 # displayed in <pre>
273 wiki_parser() {
274 sed \
275 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
276 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
277 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
278 }
280 # Bug page
281 bug_page() {
282 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
283 . $PEOPLE/$CREATOR/account.conf
284 else
285 MAIL="default"
286 fi
287 cat << EOT
288 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
290 <p>
291 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
292 </p>
293 <p>
294 $(gettext "Date:") $DATE -
295 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
296 $(eval_gettext 'Priority $PRIORITY') -
297 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
298 </p>
300 <pre>
301 $(cat $bugdir/$id/desc.txt | 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&close">$(gettext "Close bug")</a>
310 EOT
311 # Only original user and admin can edit a bug
312 if [ "$user" == "$CREATOR" ] || admin_user; then
313 cat << EOT
314 <a href="?editbug=$id">$(gettext "Edit bug")</a>
315 EOT
316 fi
317 else
318 cat << EOT
319 <a href="?id=$id&open">$(gettext "Re open bug")</a>
320 EOT
321 fi
322 fi
323 cat << EOT
324 </div>
326 <h3>$(gettext "Messages")</h3>
327 EOT
328 [ "$msgs" == "0" ] && gettext "No messages"
329 for msg in $(ls -1tr $bugdir/$id/msg.*)
330 do
331 . $msg
332 if [ "$MSG" ]; then
333 msgid=$(echo $msg | cut -d "." -f 2)
334 del=""
335 # User can delete his post as well as admin.
336 if [ "$user" == "$USER" ] || admin_user; then
337 del="<a href=\"?id=$id&delmsg=$msgid\">delete</a>"
338 fi
339 cat << EOT
340 <p><strong>$USER</strong> $DATE $del</p>
341 <pre>
342 $(echo "$MSG" | wiki_parser)
343 </pre>
344 EOT
345 fi
346 unset USER DATE MSG
347 done
348 if check_auth; then
349 cat << EOT
350 <div>
351 <h3>$(gettext "New message")</h3>
352 <form method="get" action="$script">
353 <input type="hidden" name="id" value="$id" />
354 <textarea name="msg" rows="8"></textarea>
355 <p><input type="submit" value="$(gettext 'Send message')" /></p>
356 </form>
357 </div>
358 EOT
359 fi
360 }
362 # Write a new message
363 new_msg() {
364 date=$(date "+%Y-%m-%d %H:%M")
365 msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1)
366 count=$(($msgs + 1))
367 if check_auth; then
368 USER="$user"
369 fi
370 js_log "Will write message in $bugdir/$id/msg.$count "
371 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
372 USER="$USER"
373 DATE="$date"
374 MSG="$(GETfiltered msg)"
375 EOT
376 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
377 rm -f $bugdir/$id/msg.$count.tmp
378 }
380 # Create a new Bug. ID is set by counting dirs in bug/ + 1
381 new_bug() {
382 count=$(ls $bugdir | sort -g | tail -n 1)
383 count=$(($count +1))
384 date=$(date "+%Y-%m-%d %H:%M")
385 # Sanity check, JS may be disabled.
386 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
387 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
388 if check_auth; then
389 USER="$user"
390 fi
391 mkdir -p $bugdir/$count
392 # bug.conf
393 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
394 # SliTaz Bug configuration
396 BUG="$(GETfiltered bug)"
397 STATUS="OPEN"
398 PRIORITY="$(GET priority)"
399 CREATOR="$USER"
400 DATE="$date"
401 PKGS="$(GETfiltered pkgs)"
402 EOT
403 # desc.txt
404 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/desc.tmp << EOT
405 $(GETfiltered desc)
406 EOT
407 fold -s -w 80 $bugdir/$count/desc.tmp > $bugdir/$count/desc.txt
408 rm -f $bugdir/$count/*.tmp
409 }
411 # New bug page for the web interface
412 new_bug_page() {
413 cat << EOT
414 <h2>$(gettext "New Bug")</h2>
415 <div id="newbug">
417 <form method="get" action="$script" onsubmit="return checkNewBug();">
418 <input type="hidden" name="addbug" />
419 <table>
420 <tbody>
421 <tr>
422 <td>$(gettext "Bug title")*</td>
423 <td><input type="text" name="bug" /></td>
424 </tr>
425 <tr>
426 <td>$(gettext "Description")*</td>
427 <td><textarea name="desc"></textarea></td>
428 </tr>
429 <tr>
430 <td>$(gettext "Packages")</td>
431 <td><input type="text" name="pkgs" /></td>
432 </tr>
433 <tr>
434 <td>$(gettext "Priority")</td>
435 <td>
436 <select name="priority">
437 <option value="standard">$(gettext "Standard")</option>
438 <option value="critical">$(gettext "Critical")</option>
439 </select>
440 <input type="submit" value="$(gettext "Create Bug")" />
441 </td>
442 </tr>
443 </tbody>
444 </table>
445 </form>
447 <p>
448 $(gettext "* field is obligatory. You can also specify affected packages.")
449 </p>
451 </div>
452 EOT
453 }
455 # Edit/Save a bug
456 edit_bug() {
457 . $bugdir/$id/bug.conf
458 if admin_user || [ "$user" == "$CREATOR" ]; then
459 continue
460 else
461 gettext "You can't edit someone else's bug!" && exit 0
462 fi
463 cat << EOT
464 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
465 <div id="editbug">
467 <form method="get" action="$script">
468 <input type="hidden" name="savebug" />
469 <input type="hidden" name="id" value="$id" />
470 <input type="hidden" name="creator" value="$CREATOR" />
471 <input type="hidden" name="date" value="$DATE" />
472 <table>
473 <tbody>
474 <tr>
475 <td>$(gettext "Bug title")</td>
476 <td><input type="text" name="bug" value="$BUG" /></td>
477 </tr>
478 <tr>
479 <td>$(gettext "Description")</td>
480 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
481 </tr>
482 <tr>
483 <td>$(gettext "Packages")</td>
484 <td><input type="text" name="pkgs" value="$PKGS" /></td>
485 </tr>
486 <tr>
487 <td>$(gettext "Priority")</td>
488 <td>
489 <select name="priority">
490 <option value="$PRIORITY">$PRIORITY</option>
491 <option value="standard">$(gettext "Standard")</option>
492 <option value="critical">$(gettext "Critical")</option>
493 </select>
494 <input type="submit" value="$(gettext 'Save configuration')" />
495 </td>
496 </tr>
497 </tbody>
498 </table>
499 </form>
501 </div>
502 EOT
503 }
505 save_bug() {
506 id="$(GET id)"
507 # bug.conf
508 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
509 # SliTaz Bug configuration
511 BUG="$(GETfiltered bug)"
512 STATUS="OPEN"
513 PRIORITY="$(GET priority)"
514 CREATOR="$(GET creator)"
515 DATE="$(GET date)"
516 PKGS="$(GETfiltered pkgs)"
517 EOT
518 # desc.txt
519 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
520 $(GETfiltered desc)
521 EOT
522 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
523 rm -f $bugdir/$id/*.tmp
524 }
526 # Close a fixed bug
527 close_bug() {
528 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
529 }
531 # Re open an old bug
532 open_bug() {
533 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
534 }
536 # Get and display Gravatar image: get_gravatar email size
537 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
538 get_gravatar() {
539 email=$1
540 size=$2
541 [ "$size" ] || size=48
542 url="http://www.gravatar.com/avatar"
543 md5=$(md5crypt $email)
544 echo "<img src=\"$url/$md5?d=identicon&s=$size\" alt=\"\" />"
545 }
547 # Create a new user in AUTH_FILE and PEOPLE
548 new_user_config() {
549 if [ ! -f "$AUTH_FILE" ]; then
550 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
551 fi
552 echo "$user:$pass" >> $AUTH_FILE
553 mkdir -pm0700 $PEOPLE/${user}
554 cat > $PEOPLE/$user/account.conf << EOT
555 # User configuration
556 NAME="$name"
557 USER="$user"
558 MAIL="$mail"
559 EOT
560 chmod 0600 $PEOPLE/$user/account.conf
561 # First created user is admin
562 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
563 echo "$user" > ${ADMIN_USERS}
564 fi
565 }
567 ########################################################################
568 # POST actions #
569 ########################################################################
571 case " $(POST) " in
572 *\ auth\ *)
573 header
574 html_header
575 # Authenticate user. Create a session file in $sessions to be used
576 # by check_auth. We have the user login name and a peer session
577 # md5 string in the COOKIE.
578 user="$(POST auth)"
579 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
581 IDLOC=""
582 if [[ "$(POST id)" ]] ;then
583 IDLOC="&id=$(POST id)"
584 fi
586 if [ ! -f $AUTH_FILE ] ; then
587 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
588 js_redirection_to "$script?login$IDLOC"
589 fi;
591 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
592 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
593 if [[ "$(POST id)" ]] ;then
594 IDLOC="?id=$(POST id)"
595 fi
596 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
597 mkdir -p $sessions
598 # Log last login
599 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
600 echo "$md5session" > $sessions/$user
601 js_set_cookie 'auth' "$user:$md5session"
602 js_log "Login authentication has been executed & accepted :)"
603 js_redirection_to "$script$IDLOC"
604 else
605 js_log "Login authentication has been executed & refused"
606 js_redirection_to "$script?login&error$IDLOC"
607 fi
608 html_footer ;;
609 *\ signup\ *)
610 # POST action for online signup
611 name="$(POST name)"
612 user="$(POST user)"
613 mail="$(POST mail)"
614 pass="$(md5crypt "$(POST pass)")"
615 if ! grep "^${user}:" $AUTH_FILE; then
616 online="yes"
617 new_user_config
618 header "Location: $SCRIPT_NAME?login"
619 else
620 header
621 html_header
622 user_box
623 echo "<h2>$(gettext "User already exists:") $user</h2>"
624 html_footer && exit 0
625 fi ;;
626 esac
628 #
629 # Plugins Now!
630 #
632 for p in $(ls -1 $plugins)
633 do
634 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
635 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
636 done
638 ########################################################################
639 # GET actions #
640 ########################################################################
642 case " $(GET) " in
643 *\ README\ *)
644 header
645 html_header
646 user_box
647 echo '<h2>README</h2>'
648 echo '<pre>'
649 if [ -f "README" ]; then
650 cat README
651 else
652 cat /usr/share/doc/tazbug/README
653 fi
654 echo '</pre>'
655 html_footer ;;
656 *\ closed\ *)
657 # Show all closed bugs.
658 header
659 html_header
660 user_box
661 list_bugs CLOSED
662 echo "</pre>"
663 html_footer ;;
664 *\ login\ *)
665 # The login page
666 [ "$(GET error)" ] && \
667 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
668 header
669 html_header
670 user_box
671 login_page
672 html_footer ;;
673 *\ logout\ *)
674 header
675 html_header
676 if check_auth; then
677 rm -f "$sessions/$user"
678 js_unset_cookie 'auth'
679 js_redirection_to "$script"
680 fi ;;
681 *\ user\ *)
682 # User profile. Use the users plugin for more functions
683 last="$(cat $PEOPLE/"$(GET user)"/last)"
684 header
685 html_header
686 user_box
687 . $PEOPLE/"$(GET user)"/account.conf
688 cat << EOT
689 <h2>$(get_gravatar $MAIL) $NAME</h2>
691 <pre>
692 $(gettext "User name :") $USER
693 $(gettext "Last login :") $last
694 </pre>
695 EOT
696 html_footer ;;
697 *\ newbug\ *)
698 # Create a bug from web interface.
699 header
700 html_header
701 user_box
702 if check_auth; then
703 new_bug_page
704 else
705 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
706 fi
707 html_footer ;;
708 *\ addbug\ *)
709 # Save a new bug from web interface.
710 header
711 html_header
712 if check_auth; then
713 new_bug
714 js_redirection_to "$script?id=$count"
715 fi ;;
716 *\ editbug\ *)
717 # Edit existing bug
718 id="$(GET editbug)"
719 header
720 html_header
721 user_box
722 edit_bug
723 html_footer ;;
724 *\ savebug\ *)
725 header
726 html_header
727 if check_auth; then
728 save_bug
729 js_redirection_to "$script?id=$id"
730 fi ;;
731 *\ id\ *)
732 header
733 html_header
734 id="$(GET id)"
735 [ "$(GET close)" ] && close_bug
736 [ "$(GET open)" ] && open_bug
737 [ "$(GET msg)" ] && new_msg
738 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
739 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
740 user_box
741 . $bugdir/$id/bug.conf
742 bug_page
743 html_footer ;;
744 *\ signup\ *)
745 # Signup
746 header
747 html_header
748 user_box
749 echo "<h2>$(gettext "Sign Up")</h2>"
750 if [ "$ONLINE_SIGNUP" == "yes" ]; then
751 signup_page
752 else
753 gettext "Online registration is disabled"
754 fi
755 html_footer ;;
757 *\ search\ *)
758 found=0
759 header
760 html_header
761 user_box
762 cat << EOT
763 <h2>$(gettext "Search")</h2>
764 <form method="get" action="$script">
765 <input type="text" name="search" />
766 <input type="submit" value="$(gettext 'Search')" />
767 </form>
768 <div>
769 EOT
770 cd $bugdir
771 for bug in *
772 do
773 result=$(fgrep -i -h "$(GET search)" $bug/*)
774 if [ "$result" ]; then
775 found=$(($found + 1))
776 id=${bug}
777 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
778 echo '<pre>'
779 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
780 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
781 echo '</pre>'
782 fi
783 done
784 if [ "$found" == "0" ]; then
785 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
786 else
787 echo "<p> $found $(gettext 'results found')</p>"
788 fi
789 echo '</div>'
790 html_footer ;;
791 *)
792 # Default page.
793 bugs=$(ls -1 $bugdir | wc -l)
794 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
795 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
796 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
797 pct=0
798 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
799 header
800 html_header
801 user_box
803 cat << EOT
805 <h2>$(gettext "Summary")</h2>
807 <p>
808 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
809 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
810 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
811 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
812 </p>
814 <div class="pctbar">
815 <div class="pct" style="width: ${pct}%;">${pct}%</div>
816 </div>
818 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
819 more information. You may also be interested by the SliTaz \
820 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
821 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
822 enter your term and press ENTER.")
823 </p>
825 <div id="tools">
826 $BUGS_TOOLS
827 <a href="?closed">$(gettext 'Closed bugs')</a>
828 EOT
829 if check_auth; then
830 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
831 echo "$PLUGINS_TOOLS"
832 fi
833 cat << EOT
834 </div>
836 <h3>$(gettext "Latest Bugs")</h3>
837 EOT
838 # List last 4 bugs
839 echo "<pre>"
840 for lb in $(ls ${bugdir} | sort -r -n | head -n 4)
841 do
842 list_bug ${lb}
843 done
844 echo "</pre>"
845 # List last 4 messages
846 echo "<h3>$(gettext "Latest Messages")</h3>"
847 echo "<pre>"
848 for msg in $(ls -t ${bugdir}/*/msg.* | head -n 4)
849 do
850 list_msg ${msg}
851 done
852 echo "</pre>"
853 list_bugs OPEN
854 echo "</pre>"
855 html_footer ;;
856 esac
858 exit 0