tazbug view web/bugs.cgi @ rev 63

Add online users in dashboard and misc changes
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jan 07 22:22:25 2014 +0100 (2014-01-07)
parents 10f3f4d09e09
children 72256c35d685
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" ;;
27 de) LANG="de_DE" ;;
28 es) LANG="es_ES" ;;
29 fr) LANG="fr_FR" ;;
30 it) LANG="it_IT" ;;
31 pt) LANG="pt_BR" ;;
32 ru) LANG="ru_RU" ;;
33 zh) LANG="zh_TW" ;;
34 esac
35 if echo "$po" | fgrep -q "$lang"; then
36 break
37 fi
38 done
39 unset IFS
40 export LANG LC_ALL=$LANG
42 # Internationalization: $(gettext "")
43 . /usr/bin/gettext.sh
44 TEXTDOMAIN='tazbug'
45 export TEXTDOMAIN
47 #
48 # Functions
49 #
51 # HTML 5 header.
52 html_header() {
53 cat lib/header.html
54 }
56 # HTML 5 footer.
57 html_footer() {
58 cat << EOT
59 </div>
61 <div id="footer">
62 <a href="$script">SliTaz Bugs</a> -
63 <a href="$script?README">README</a>
64 </div>
66 </body>
67 </html>
68 EOT
69 }
71 GETfiltered() {
72 GET $1 | sed -e "s/'/\&#39;/g; s|\n|<br/>|g; s/\t/\&#09;/g;s/\%22/\"/g"
73 }
75 js_redirection_to() {
76 js_log "Redirecting to $1"
77 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
78 }
80 js_log() {
81 echo "<script type=\"text/javascript\">console.log('$1')</script>";
82 }
84 js_set_cookie() {
85 name=$1
86 value=$2
87 js_log 'Setting cookie.'
88 echo "<script type=\"text/javascript\">"
89 echo "document.cookie = \"$name=$value; expires=0; path=/\"";
90 echo "</script>"
91 }
93 js_unset_cookie() {
94 name=$1
95 js_log 'Unsetting cookie.'
96 echo "<script type=\"text/javascript\">"
97 echo "document.cookie = \"$1=\"\"; expires=-1; path=/";
98 echo "</script>"
99 }
101 # Check if user is auth
102 check_auth() {
103 auth="$(COOKIE auth)"
104 user="$(echo $auth | cut -d ":" -f 1)"
105 md5cookie="$(echo $auth | cut -d ":" -f 2)"
106 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
107 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
108 return 0
109 else
110 return 1
111 fi
112 }
114 # Check if user is admin
115 admin_user() {
116 fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf
117 }
119 # Authentified or not
120 user_box() {
122 IDLOC=""
123 if [[ "$(GET id)" ]] ;then
124 IDLOC="&id=$(GET id)"
125 fi
127 if check_auth; then
128 . $PEOPLE/$user/account.conf
129 cat << EOT
130 <div id="user">
131 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
132 <a href="?logout">$(gettext 'Logout')</a>
133 </div>
134 EOT
135 else
136 cat << EOT
137 <div id="user">
138 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
139 <a href="?login$IDLOC">$(gettext 'Log in')</a>
140 </div>
141 EOT
142 fi
143 cat << EOT
145 <div id="search">
146 <form method="get" action="$script">
147 <input type="text" name="search" placeholder="$(gettext 'Search')" />
148 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
149 </form>
150 </div>
152 <!-- Content -->
153 <div id="content">
155 EOT
156 }
158 # Signup page
159 signup_page() {
160 cat << EOT
162 <div id="signup">
163 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
164 <input type="hidden" name="signup" value="new" />
165 <input type="text" name="name" placeholder="$(gettext "Real name")" />
166 <input type="text" name="user" placeholder="$(gettext "User name")" />
167 <input type="text" name="mail" placeholder="$(gettext "Email")" />
168 <input type="password" name="pass" placeholder="$(gettext "Password")" />
169 <div>
170 <input type="submit" value="$(gettext "Create new account")" />
171 </div>
172 </form>
173 </div>
175 EOT
176 }
178 # Link for online signup if enabled.
179 online_signup() {
180 if [ "$ONLINE_SIGNUP" == "yes" ]; then
181 echo -n "<p>" && gettext "Or:"; echo -n " "
182 echo -n "<a href='$script?signup&amp;online'>"
183 gettext "Sign Up Online"
184 echo '</a></p>'
185 fi
186 }
188 # Login page
189 login_page() {
191 IDLOC=""
192 if [[ "$(GET id)" ]] ;then
193 IDLOC="?id=$(GET id)"
194 fi
195 cat << EOT
196 <h2>$(gettext 'Login')</h2>
198 <div id="account-info">
199 <p>$(gettext "No account yet? You can signup using the SliTaz Bugs reporter \
200 on your SliTaz system.")</p>
201 $(online_signup)
202 <p>$(gettext "Tip: to attach big files or images, you can use SliTaz Paste \
203 services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a></p>
204 </div>
206 <div id="login">
207 <form method="post" action="$script">
208 <input type="text" name="auth" placeholder="$(gettext 'User name')" />
209 <input type="password" name="pass" placeholder="$(gettext 'Password')" />
210 <div>
211 <input type="submit" value="$(gettext 'Log in')" />
212 $error
213 </div>
214 </form>
215 </div>
217 <div style="clear: both;"></div>
218 EOT
219 }
221 # Display user public profile.
222 public_people() {
223 cat << EOT
224 </pre>
225 EOT
226 }
228 # Display authentified user profile. TODO: change password
229 auth_people() {
230 cat << EOT
231 Email : $MAIL
232 Secure key : $KEY
233 </pre>
234 EOT
235 }
237 # Usage: list_bug ID
238 list_bug() {
239 id="$1"
240 . ${bugdir}/${id}/bug.conf
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 <strong><a href="?id=$id">$BUG</a></strong> \
246 <span class="date">$DATE</span>
247 EOT
248 unset CREATOR USER MAIL
250 }
252 # Usage: list_bugs STATUS
253 list_bugs() {
254 status="$1"
255 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
256 echo "<pre>"
257 for pr in critical standard
258 do
259 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
260 do
261 . $bug
262 id=$(basename $(dirname $bug))
263 if [ "$PRIORITY" == "$pr" ]; then
264 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
265 . ${PEOPLE}/${CREATOR}/account.conf
266 cat << EOT
267 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
268 ID: $id <strong><a href="?id=$id">$BUG</a></strong> \
269 <span class="date">$DATE</span>
270 EOT
271 fi
272 unset CREATOR USER MAIL
273 done
274 done
275 }
277 # Stripped down Wiki parser for bug desc and messages which are simply
278 # displayed in <pre>
279 wiki_parser() {
280 sed \
281 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
282 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
283 -e 's#\\\\n#\n#g;s#%22#"#g;s#%21#!#g'
284 }
286 # Bug page
287 bug_page() {
288 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
289 . $PEOPLE/$CREATOR/account.conf
290 else
291 MAIL="default"
292 fi
293 cat << EOT
294 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
295 <form method="get" action="$script">
297 <p>
298 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
299 </p>
300 <p>
301 $(gettext "Date:") $DATE -
302 $(eval_gettext 'Priority $PRIORITY') -
303 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
304 </p>
306 <pre>
307 $(echo "$DESC" | wiki_parser)
308 </pre>
310 <div id="tools">
311 EOT
312 if check_auth; then
313 if [ "$STATUS" == "OPEN" ]; then
314 cat << EOT
315 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
316 <a href="?edit=$id">$(gettext "Edit bug")</a>
317 EOT
318 else
319 cat << EOT
320 <a href="?id=$id&amp;open">$(gettext "Re open bug")</a>
321 EOT
322 fi
323 fi
324 cat << EOT
325 </div>
327 <h3>$(gettext "Messages")</h3>
328 EOT
329 [ "$msgs" == "0" ] && gettext "No messages"
330 for msg in $(ls -1tr $bugdir/$id/msg.*)
331 do
332 . $msg
333 if [ "$MSG" ]; then
334 msgid=$(echo $msg | cut -d "." -f 2)
335 del=""
336 # User can delete his post.
337 [ "$user" == "$USER" ] && \
338 del="<a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
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 NAME DATE MSG
347 done
348 if check_auth; then
349 cat << EOT
350 <div>
351 <h3>$(gettext "New message")</h3>
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.* | wc -l)
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 << EOT
372 USER="$USER"
373 DATE="$date"
374 MSG="$(GETfiltered msg)"
375 EOT
376 }
378 # Create a new Bug
379 new_bug() {
380 count=$(ls -1 $bugdir | wc -l)
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 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
390 # SliTaz Bug configuration
392 BUG="$(GETfiltered bug)"
393 STATUS="OPEN"
394 PRIORITY="$(GET priority)"
395 CREATOR="$USER"
396 DATE="$date"
397 PKGS="$(GETfiltered pkgs)"
399 DESC="$(GETfiltered desc)"
400 EOT
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 }
465 save_bug() {
466 bug="$(GET bug)"
467 content="$(GET bugconf)"
468 sed "s|\"|'|" | sed "s/$(echo -en '\r') /\n/g" > $bugdir/$bug/bug.conf << EOT
469 $content
470 EOT
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 [[ "$(GET id)" ]] ;then
540 IDLOC="&id=$(GET 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 [[ "$(GET id)" ]] ;then
551 IDLOC="?id=$(GET 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 authentification has been executed & accepted :)"
560 js_redirection_to "$script$IDLOC"
561 else
562 js_log "Login authentification 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 #
588 for p in $(ls -1 $plugins)
589 do
590 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
591 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
592 done
594 ########################################################################
595 # GET actions #
596 ########################################################################
598 case " $(GET) " in
599 *\ README\ *)
600 header
601 html_header
602 user_box
603 echo '<h2>README</h2>'
604 echo '<pre>'
605 if [ -f "README" ]; then
606 cat README
607 else
608 cat /usr/share/doc/tazbug/README
609 fi
610 echo '</pre>'
611 html_footer ;;
612 *\ closed\ *)
613 # Show all closed bugs.
614 header
615 html_header
616 user_box
617 list_bugs CLOSED
618 echo "</pre>"
619 html_footer ;;
620 *\ login\ *)
621 # The login page
622 [ "$(GET error)" ] && \
623 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
624 header
625 html_header
626 user_box
627 login_page
628 html_footer ;;
629 *\ logout\ *)
630 header
631 html_header
632 if check_auth; then
633 rm -f "$sessions/$user"
634 js_unset_cookie 'auth'
635 js_redirection_to "$script"
636 fi ;;
637 *\ user\ *)
638 # User profile
639 last="$(cat $PEOPLE/"$(GET user)"/last)"
640 header
641 html_header
642 user_box
643 . $PEOPLE/"$(GET user)"/account.conf
644 cat << EOT
645 <h2>$(get_gravatar $MAIL) $NAME</h2>
647 <pre>
648 $(gettext "User name :") $USER
649 $(gettext "Last login :") $last
650 EOT
651 if check_auth && [ "$(GET user)" == "$user" ]; then
652 auth_people
653 else
654 # check_auth will set VARS to current logged user: re-source
655 . $PEOPLE/"$(GET user)"/account.conf
656 public_people
657 fi
658 html_footer ;;
659 *\ newbug\ *)
660 # Add a bug from web interface.
661 header
662 html_header
663 user_box
664 if check_auth; then
665 new_bug_page
666 else
667 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
668 fi
669 html_footer ;;
670 *\ addbug\ *)
671 # Add a bug from web interface.
672 header
673 html_header
674 if check_auth; then
675 new_bug
676 js_redirection_to "$script?id=$count"
677 fi ;;
678 *\ edit\ *)
679 bug="$(GET edit)"
680 header
681 html_header
682 user_box
683 edit_bug
684 html_footer ;;
685 *\ bugconf\ *)
686 header
687 html_header
688 if check_auth; then
689 save_bug
690 js_redirection_to "$script?id=$bug"
691 fi ;;
692 *\ id\ *)
693 # Empty deleted messages to keep msg count working.
694 header
695 html_header
696 id="$(GET id)"
697 [ "$(GET close)" ] && close_bug
698 [ "$(GET open)" ] && open_bug
699 [ "$(GET msg)" ] && new_msg
700 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
701 touch $bugdir/$id/msg.$(GET delmsg)
702 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
703 user_box
704 . $bugdir/$id/bug.conf
705 bug_page
706 html_footer ;;
707 *\ signup\ *)
708 # Signup
709 if [ "$(GET online)" ];then
710 header
711 html_header
712 user_box
713 echo "<h2>$(gettext "Sign Up")</h2>"
714 if [ "$ONLINE_SIGNUP" == "yes" ]; then
715 signup_page
716 else
717 gettext "Online registration is disabled"
718 fi
719 html_footer && exit 0
720 else
721 header "Content-type: text/plain;"
722 user="$(GET signup)"
723 echo "Requested user login : $user"
724 if fgrep -q "$user:" $AUTH_FILE; then
725 echo "ERROR: User already exists" && exit 1
726 else
727 echo "Creating account for : $(GET name)"
728 new_user_config
729 fi
730 fi ;;
731 *\ key\ *)
732 # Let user post new bug or message with crypted key (no gettext)
733 #
734 # Testing only and is security acceptable ?
735 #
736 key="$(GET key)"
737 id="$(GET bug)"
738 header "Content-type: text/plain;"
739 echo "Checking secure key..."
740 if fgrep -qH $key $PEOPLE/*/account.conf; then
741 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
742 . $conf
743 echo "Authentified: $NAME ($USER)"
744 case " $(GET) " in
745 *\ msg\ *)
746 [ ! "$id" ] && echo "Missing bug ID" && exit 0
747 echo "Posting new message to bug: $id"
748 echo "Message: $(GET msg)"
749 new_msg ;;
750 *\ bug\ *)
751 echo "Adding new bug: $(GET bug)"
752 echo "Description: $(GET desc)"
753 new_bug ;;
754 esac
755 else
756 echo "Not a valid SliTaz user key"
757 exit 0
758 fi ;;
759 *\ search\ *)
760 found=0
761 header
762 html_header
763 user_box
764 cat << EOT
765 <h2>$(gettext "Search")</h2>
766 <form method="get" action="$script">
767 <input type="text" name="search" />
768 <input type="submit" value="$(gettext 'Search')" />
769 </form>
770 <div>
771 EOT
772 cd $bugdir
773 for bug in *
774 do
775 result=$(fgrep -i -h "$(GET search)" $bug/*)
776 if [ "$result" ]; then
777 found=$(($found + 1))
778 id=${bug}
779 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
780 echo '<pre>'
781 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
782 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
783 echo '</pre>'
784 fi
785 done
786 if [ "$found" == "0" ]; then
787 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
788 else
789 echo "<p> $found $(gettext 'results found')</p>"
790 fi
791 echo '</div>'
792 html_footer ;;
793 *)
794 # Default page.
795 bugs=$(ls -1 $bugdir | wc -l)
796 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
797 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
798 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
799 pct=0
800 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
801 header
802 html_header
803 user_box
804 cat << EOT
806 <h2>$(gettext "Summary")</h2>
808 <p>
809 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
810 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
811 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
812 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
813 </p>
815 <div class="pctbar">
816 <div class="pct" style="width: ${pct}%;">${pct}%</div>
817 </div>
819 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
820 more information. You may also be interested by the SliTaz \
821 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
822 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
823 enter your term and press ENTER.")
824 </p>
826 <div id="tools">
827 <a href="?closed">$(gettext 'View closed bugs')</a>
828 EOT
829 if check_auth; then
830 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
831 echo "$PLUGINS_TOOLS"
832 fi
833 cat << EOT
834 </div>
836 <h3>$(gettext "Latest Bugs")</h3>
837 EOT
838 # List last 3 bugs
839 echo "<pre>"
840 for lb in $(ls ${bugdir} | sort -r -n | head -n 3)
841 do
842 list_bug ${lb}
843 done
844 echo "</pre>"
845 list_bugs OPEN
846 echo "</pre>"
847 html_footer ;;
848 esac
850 exit 0