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