tazbug view web/bugs.cgi @ rev 139
Fix getting last 4 message in DB
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Feb 22 19:03:30 2017 +0100 (2017-02-22) |
parents | 2a172aca8228 |
children | d98dc7dce8d4 |
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 grep -w -q "$user" ${ADMIN_USERS}
119 }
121 # Authenticated or not (login/logout are not translated to keep css width)
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">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">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 # Set open/closed bug path: set_bugpath ID
220 set_bugpath() {
221 if [ -d "$bugdir/closed/$1" ]; then
222 bugpath="$bugdir/closed/$1"
223 else
224 bugpath="$bugdir/open/$1"
225 fi
226 }
227 set_bugdir() {
228 if [ -d "$bugdir/closed/$1" ]; then
229 bugdir="$bugdir/closed"
230 else
231 bugdir="$bugdir/open"
232 fi
233 }
235 # Nice ls output for open and closed bugs
236 ls_bugs() {
237 ls $bugdir/open
238 ls $bugdir/closed
239 }
241 # Usage: list_bug ID
242 list_bug() {
243 id="$1"
244 set_bugpath ${id}
245 . ${bugpath}/bug.conf
246 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
247 . ${PEOPLE}/${CREATOR}/account.conf
248 cat << EOT
249 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
250 Bug $id: <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
251 EOT
252 unset CREATOR USER MAIL bugpath
253 }
255 # Usage: list_bugs [open|closed]
256 list_bugs() {
257 status="$1"
258 echo "<h3>$(gettext 'Bugs:') $status</h3>"
259 echo "<pre>"
260 for pr in critical standard
261 do
262 for id in $(ls $bugdir/$status)
263 do
264 . $bugdir/$status/$id/bug.conf
265 if [ "$PRIORITY" == "$pr" ]; then
266 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
267 . ${PEOPLE}/${CREATOR}/account.conf
268 cat << EOT
269 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
270 Bug $id: <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
271 EOT
272 fi
273 unset CREATOR USER MAIL BUG
274 done
275 done
276 }
278 # Usage: list_msg path
279 list_msg() {
280 msg="$1"
281 dir=$(dirname $msg)
282 id=$(basename $dir)
283 . ${msg}
284 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
285 . ${PEOPLE}/${USER}/account.conf
286 cat << EOT
287 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
288 <a href="?id=$id">Bug $id</a>: by $USER <span class="date">- $DATE</span>
289 EOT
290 unset CREATOR USER MAIL
291 }
293 # Stripped down Wiki parser for bug desc and messages which are simply
294 # displayed in <pre>
295 wiki_parser() {
296 sed \
297 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
298 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
299 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
300 }
302 # Bug page
303 bug_page() {
304 . $bugdir/$id/bug.conf
305 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
306 . $PEOPLE/$CREATOR/account.conf
307 else
308 MAIL="default"
309 fi
310 cat << EOT
311 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
313 <h3>$(get_gravatar $MAIL 32) $BUG</h3>
314 <p>
315 $(gettext "Date:") $DATE -
316 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
317 $(eval_gettext 'Priority $PRIORITY') -
318 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
319 </p>
321 <pre>
322 $(cat $bugdir/$id/desc.txt | wiki_parser)
323 </pre>
324 EOT
325 if [ "$PKGS" ] && [ -x "$plugins/packages/packages.cgi" ]; then
326 echo "<p style='vertical-align: middle;'>"
327 echo "<strong>$(gettext 'Affected package(s):')</strong>"
328 for pkg in $PKGS; do
329 echo "<a href='?pkg=$pkg'>$pkg</a>"
330 done
331 echo "</p>"
332 fi
333 echo '<div id="tools">'
334 if check_auth; then
335 if [ "$STATUS" == "OPEN" ]; then
336 cat << EOT
337 <a href="?id=$id&close">$(gettext "Close bug")</a>
338 EOT
339 # Only original user and admin can edit a bug
340 if [ "$user" == "$CREATOR" ] || admin_user; then
341 cat << EOT
342 <a href="?editbug=$id">$(gettext "Edit bug")</a>
343 EOT
344 fi
345 else
346 cat << EOT
347 <a href="?id=$id&open">$(gettext "Re open bug")</a>
348 EOT
349 fi
350 fi
351 cat << EOT
352 </div>
354 <h3>$(gettext "Messages")</h3>
355 EOT
356 [ "$msgs" == "0" ] && gettext "No messages"
357 for msg in $(ls -1tr $bugdir/$id/msg.*)
358 do
359 . $msg
360 if [ "$MSG" ]; then
361 msgid=$(echo $msg | cut -d "." -f 2)
362 del=""
363 # User can delete his post as well as admin.
364 if [ "$user" == "$USER" ] || admin_user; then
365 del="<a href=\"?id=$id&delmsg=$msgid\">delete</a>"
366 fi
367 cat << EOT
368 <p><strong>$USER</strong> $DATE $del</p>
369 <pre>
370 $(echo "$MSG" | wiki_parser)
371 </pre>
372 EOT
373 fi
374 unset USER DATE MSG
375 done
376 if check_auth; then
377 cat << EOT
378 <div>
379 <h3>$(gettext "New message")</h3>
380 <form method="get" action="$script">
381 <input type="hidden" name="id" value="$id" />
382 <textarea name="msg" rows="8"></textarea>
383 <p><input type="submit" value="$(gettext 'Send message')" /></p>
384 </form>
385 </div>
386 EOT
387 fi
388 }
390 # Write a new message
391 new_msg() {
392 date=$(date "+%Y-%m-%d %H:%M")
393 msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1)
394 count=$(($msgs + 1))
395 if check_auth; then
396 USER="$user"
397 fi
398 js_log "Will write message in $bugdir/$id/msg.$count "
399 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
400 USER="$USER"
401 DATE="$date"
402 MSG="$(GETfiltered msg)"
403 EOT
404 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
405 rm -f $bugdir/$id/msg.$count.tmp
406 }
408 # Create a new Bug. ID is set by counting dirs in bug/ + 1
409 new_bug() {
410 count=$(ls_bugs | sort -g | tail -n 1)
411 id=$(($count +1))
412 date=$(date "+%Y-%m-%d")
413 # Sanity check, JS may be disabled.
414 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
415 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
416 if check_auth; then
417 USER="$user"
418 fi
419 mkdir -p $bugdir/open/$id
420 # bug.conf
421 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/bug.conf << EOT
422 # SliTaz Bug configuration
424 BUG="$(GETfiltered bug)"
425 STATUS="OPEN"
426 PRIORITY="$(GET priority)"
427 CREATOR="$USER"
428 DATE="$date"
429 PKGS="$(GETfiltered pkgs)"
430 EOT
431 # desc.txt
432 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/desc.tmp << EOT
433 $(GETfiltered desc)
434 EOT
435 fold -s -w 80 $bugdir/open/$id/desc.tmp > $bugdir/open/$id/desc.txt
436 rm -f $bugdir/open/$id/*.tmp
437 }
439 # New bug page for the web interface
440 new_bug_page() {
441 cat << EOT
442 <h2>$(gettext "New Bug")</h2>
443 <div id="newbug">
445 <form method="get" action="$script" onsubmit="return checkNewBug();">
446 <input type="hidden" name="addbug" />
447 <table>
448 <tbody>
449 <tr>
450 <td>$(gettext "Bug title")*</td>
451 <td><input type="text" name="bug" /></td>
452 </tr>
453 <tr>
454 <td>$(gettext "Description")*</td>
455 <td><textarea name="desc"></textarea></td>
456 </tr>
457 <tr>
458 <td>$(gettext "Packages")</td>
459 <td><input type="text" name="pkgs" /></td>
460 </tr>
461 <tr>
462 <td>$(gettext "Priority")</td>
463 <td>
464 <select name="priority">
465 <option value="standard">$(gettext "Standard")</option>
466 <option value="critical">$(gettext "Critical")</option>
467 </select>
468 <input type="submit" value="$(gettext "Create Bug")" />
469 </td>
470 </tr>
471 </tbody>
472 </table>
473 </form>
475 <p>
476 $(gettext "* field is obligatory. You can also specify affected packages.")
477 </p>
479 </div>
480 EOT
481 }
483 # Edit/Save a bug
484 edit_bug() {
485 . $bugdir/$id/bug.conf
486 if admin_user || [ "$user" == "$CREATOR" ]; then
487 continue
488 else
489 gettext "You can't edit someone else's bug!" && exit 0
490 fi
491 cat << EOT
492 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
493 <div id="editbug">
495 <form method="get" action="$script">
496 <input type="hidden" name="savebug" />
497 <input type="hidden" name="id" value="$id" />
498 <input type="hidden" name="creator" value="$CREATOR" />
499 <input type="hidden" name="date" value="$DATE" />
500 <table>
501 <tbody>
502 <tr>
503 <td>$(gettext "Bug title")</td>
504 <td><input type="text" name="bug" value="$BUG" /></td>
505 </tr>
506 <tr>
507 <td>$(gettext "Description")</td>
508 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
509 </tr>
510 <tr>
511 <td>$(gettext "Packages")</td>
512 <td><input type="text" name="pkgs" value="$PKGS" /></td>
513 </tr>
514 <tr>
515 <td>$(gettext "Priority")</td>
516 <td>
517 <select name="priority">
518 <option value="$PRIORITY">$PRIORITY</option>
519 <option value="standard">$(gettext "Standard")</option>
520 <option value="critical">$(gettext "Critical")</option>
521 </select>
522 <input type="submit" value="$(gettext 'Save configuration')" />
523 </td>
524 </tr>
525 </tbody>
526 </table>
527 </form>
529 </div>
530 EOT
531 }
533 save_bug() {
534 id="$(GET id)"
535 set_bugdir ${id}
536 # bug.conf
537 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
538 # SliTaz Bug configuration
540 BUG="$(GETfiltered bug)"
541 STATUS="OPEN"
542 PRIORITY="$(GET priority)"
543 CREATOR="$(GET creator)"
544 DATE="$(GET date)"
545 PKGS="$(GETfiltered pkgs)"
546 EOT
547 # desc.txt
548 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
549 $(GETfiltered desc)
550 EOT
551 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
552 rm -f $bugdir/$id/*.tmp
553 }
555 # Close a fixed bug
556 close_bug() {
557 sed -i s'/OPEN/CLOSED/' $bugdir/open/$id/bug.conf
558 mv $bugdir/open/$id $bugdir/closed/$id
559 }
561 # Re open an old bug
562 open_bug() {
563 sed -i s'/CLOSED/OPEN/' $bugdir/closed/$id/bug.conf
564 mv $bugdir/closed/$id $bugdir/open/$id
565 }
567 # Get and display Gravatar image: get_gravatar email size
568 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
569 get_gravatar() {
570 email=$1
571 size=$2
572 [ "$size" ] || size=48
573 url="http://www.gravatar.com/avatar"
574 md5=$(md5crypt $email)
575 echo "<img src='$url/$md5?d=identicon&s=$size' alt='' />"
576 }
578 # Create a new user in AUTH_FILE and PEOPLE
579 new_user_config() {
580 if [ ! -f "$AUTH_FILE" ]; then
581 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
582 fi
583 echo "$user:$pass" >> $AUTH_FILE
584 mkdir -pm0700 $PEOPLE/${user}
585 cat > $PEOPLE/$user/account.conf << EOT
586 # User configuration
587 NAME="$name"
588 USER="$user"
589 MAIL="$mail"
590 EOT
591 chmod 0600 $PEOPLE/$user/account.conf
592 # First created user is admin
593 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
594 echo "$user" > ${ADMIN_USERS}
595 fi
596 }
598 ########################################################################
599 # POST actions #
600 ########################################################################
602 case " $(POST) " in
603 *\ auth\ *)
604 header
605 html_header
606 # Authenticate user. Create a session file in $sessions to be used
607 # by check_auth. We have the user login name and a peer session
608 # md5 string in the COOKIE.
609 user="$(POST auth)"
610 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
612 IDLOC=""
613 if [[ "$(POST id)" ]] ;then
614 IDLOC="&id=$(POST id)"
615 fi
617 if [ ! -f $AUTH_FILE ] ; then
618 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
619 js_redirection_to "$script?login$IDLOC"
620 fi;
622 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
623 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
624 if [[ "$(POST id)" ]] ;then
625 IDLOC="?id=$(POST id)"
626 fi
627 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
628 mkdir -p $sessions
629 # Log last login
630 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
631 echo "$md5session" > $sessions/$user
632 js_set_cookie 'auth' "$user:$md5session"
633 js_log "Login authentication has been executed & accepted :)"
634 js_redirection_to "$script$IDLOC"
635 else
636 js_log "Login authentication has been executed & refused"
637 js_redirection_to "$script?login&error$IDLOC"
638 fi
639 html_footer ;;
640 *\ signup\ *)
641 # POST action for online signup
642 name="$(POST name)"
643 user="$(POST user)"
644 mail="$(POST mail)"
645 pass="$(md5crypt "$(POST pass)")"
646 if ! grep "^${user}:" $AUTH_FILE; then
647 online="yes"
648 new_user_config
649 header "Location: $SCRIPT_NAME?login"
650 else
651 header
652 html_header
653 user_box
654 echo "<h2>$(gettext "User already exists:") $user</h2>"
655 html_footer && exit 0
656 fi ;;
657 esac
659 #
660 # Plugins Now!
661 #
663 for p in $(ls -1 $plugins)
664 do
665 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
666 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
667 done
669 ########################################################################
670 # GET actions #
671 ########################################################################
673 case " $(GET) " in
674 *\ README\ *)
675 header
676 html_header
677 user_box
678 echo '<h2>README</h2>'
679 echo '<pre>'
680 if [ -f "README" ]; then
681 cat README
682 else
683 cat /usr/share/doc/tazbug/README
684 fi
685 echo '</pre>'
686 html_footer ;;
688 *\ closed\ *)
689 # Show all closed bugs.
690 header
691 html_header
692 user_box
693 list_bugs "closed"
694 echo "</pre>"
695 html_footer ;;
697 *\ login\ *)
698 # The login page
699 [ "$(GET error)" ] && \
700 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
701 header
702 html_header
703 user_box
704 login_page
705 html_footer ;;
707 *\ logout\ *)
708 header
709 html_header
710 if check_auth; then
711 rm -f "$sessions/$user"
712 js_unset_cookie 'auth'
713 js_redirection_to "$script"
714 fi ;;
716 *\ user\ *)
717 # User profile. Use the users plugin for more functions
718 last="$(cat $PEOPLE/"$(GET user)"/last)"
719 header
720 html_header
721 user_box
722 . $PEOPLE/"$(GET user)"/account.conf
723 cat << EOT
724 <h2>$(get_gravatar $MAIL) $NAME</h2>
726 <pre>
727 $(gettext "User name :") $USER
728 $(gettext "Last login :") $last
729 </pre>
730 EOT
731 html_footer ;;
733 *\ newbug\ *)
734 # Create a bug from web interface.
735 header
736 html_header
737 user_box
738 if check_auth; then
739 new_bug_page
740 else
741 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
742 fi
743 html_footer ;;
745 *\ addbug\ *)
746 # Save a new bug
747 header
748 html_header
749 if check_auth; then
750 new_bug
751 js_redirection_to "$script?id=$id"
752 fi ;;
754 *\ editbug\ *)
755 # Edit existing bug
756 header
757 html_header
758 id="$(GET editbug)"
759 set_bugdir ${id}
760 user_box
761 edit_bug
762 html_footer ;;
764 *\ savebug\ *)
765 if check_auth; then
766 save_bug
767 js_redirection_to "$script?id=$id"
768 fi ;;
770 *\ id\ *)
771 header
772 html_header
773 user_box
774 id="$(GET id)"
775 [ "$(GET close)" ] && close_bug
776 [ "$(GET open)" ] && open_bug
777 set_bugdir ${id}
778 [ "$(GET msg)" ] && new_msg
779 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
780 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
781 bug_page
782 html_footer ;;
784 *\ signup\ *)
785 # Signup
786 header
787 html_header
788 user_box
789 echo "<h2>$(gettext "Sign Up")</h2>"
790 if [ "$ONLINE_SIGNUP" == "yes" ]; then
791 signup_page
792 else
793 gettext "Online registration is disabled"
794 fi
795 html_footer ;;
797 *\ search\ *)
798 found=0
799 header
800 html_header
801 user_box
802 cat << EOT
803 <h2>$(gettext "Search")</h2>
804 <form method="get" action="$script">
805 <input type="text" name="search" />
806 <input type="submit" value="$(gettext 'Search')" />
807 </form>
808 <div>
809 <p>
810 $(gettext 'Search by pattern, package or user')
811 </p>
812 EOT
813 if [ ! "$(GET search)" ]; then
814 html_footer && exit 0
815 else
816 echo "<h3>$(gettext 'Result for:') $(GET search)</h3>"
817 fi
818 for id in $(ls_bugs)
819 do
820 set_bugdir "$id"
821 result=$(fgrep -i -h "$(GET search)" $bugdir/$id/*)
822 if [ "$result" ]; then
823 found=$(($found + 1))
824 echo "<p><strong>Bug $id</strong> - <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
825 echo '<pre>'
826 echo "$result" | \
827 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
828 echo '</pre>'
829 fi
830 bugdir=$(dirname $bugdir)
831 done
832 if [ "$found" == "0" ]; then
833 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
834 else
835 echo "<p> $found $(gettext 'results found')</p>"
836 fi
837 echo '</div>' && html_footer ;;
839 *)
840 # Default page.
841 bugs=$(ls_bugs | wc -l)
842 close=$(ls $bugdir/closed | wc -l)
843 fixme=$(ls $bugdir/open | wc -l)
844 msgs=$(find $bugdir -name msg.* | wc -l)
845 pct=0
846 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
847 header
848 html_header
849 user_box
851 cat << EOT
853 <h2>$(gettext "Summary")</h2>
855 <p>
856 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
857 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
858 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
859 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
860 </p>
862 <div class="pctbar">
863 <div class="pct" style="width: ${pct}%;">${pct}%</div>
864 </div>
866 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
867 more information. You may also be interested by the SliTaz \
868 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
869 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
870 enter your term and press ENTER.")
871 </p>
873 <div id="tools">
874 $BUGS_TOOLS
875 <a href="?closed">$(gettext 'Closed bugs')</a>
876 EOT
877 if check_auth; then
878 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
879 echo "$PLUGINS_TOOLS"
880 fi
881 cat << EOT
882 </div>
884 <h3>$(gettext "Latest Bugs")</h3>
885 EOT
886 # List last 4 bugs
887 echo "<pre>"
888 for lb in $(ls_bugs | sort -n -r | head -n 4)
889 do
890 list_bug ${lb}
891 done
892 echo "</pre>"
894 # List last 4 messages
895 echo "<h3>$(gettext "Latest Messages")</h3>"
896 echo "<pre>"
897 for msg in $(ls -lt $bugdir/*/*/msg.* | awk '{print $9}' | head -n 4)
898 do
899 list_msg ${msg}
900 done
901 echo "</pre>"
902 list_bugs open
903 echo "</pre>"
904 html_footer ;;
905 esac
907 exit 0