tazbug view web/bugs.cgi @ rev 137

Update all plugins to use new storage paths
author Christophe Lincoln <pankso@slitaz.org>
date Wed Feb 22 14:59:49 2017 +0100 (2017-02-22)
parents b5f62d54152e
children 2a172aca8228
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/'/\&#39;/g; s|\n|<br/>|g; s/\t/\&#09;/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&amp;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>"
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&amp;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&amp;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&amp;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&amp;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 ;;
687 *\ closed\ *)
688 # Show all closed bugs.
689 header
690 html_header
691 user_box
692 list_bugs "closed"
693 echo "</pre>"
694 html_footer ;;
695 *\ login\ *)
696 # The login page
697 [ "$(GET error)" ] && \
698 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
699 header
700 html_header
701 user_box
702 login_page
703 html_footer ;;
704 *\ logout\ *)
705 header
706 html_header
707 if check_auth; then
708 rm -f "$sessions/$user"
709 js_unset_cookie 'auth'
710 js_redirection_to "$script"
711 fi ;;
712 *\ user\ *)
713 # User profile. Use the users plugin for more functions
714 last="$(cat $PEOPLE/"$(GET user)"/last)"
715 header
716 html_header
717 user_box
718 . $PEOPLE/"$(GET user)"/account.conf
719 cat << EOT
720 <h2>$(get_gravatar $MAIL) $NAME</h2>
722 <pre>
723 $(gettext "User name :") $USER
724 $(gettext "Last login :") $last
725 </pre>
726 EOT
727 html_footer ;;
728 *\ newbug\ *)
729 # Create a bug from web interface.
730 header
731 html_header
732 user_box
733 if check_auth; then
734 new_bug_page
735 else
736 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
737 fi
738 html_footer ;;
739 *\ addbug\ *)
740 # Save a new bug
741 header
742 html_header
743 if check_auth; then
744 new_bug
745 js_redirection_to "$script?id=$id"
746 fi ;;
747 *\ editbug\ *)
748 # Edit existing bug
749 header
750 html_header
751 id="$(GET editbug)"
752 set_bugdir ${id}
753 user_box
754 edit_bug
755 html_footer ;;
756 *\ savebug\ *)
757 header
758 html_header
759 if check_auth; then
760 save_bug
761 js_redirection_to "$script?id=$id"
762 fi ;;
763 *\ id\ *)
764 header
765 html_header
766 id="$(GET id)"
767 [ "$(GET close)" ] && close_bug
768 [ "$(GET open)" ] && open_bug
769 set_bugdir ${id}
770 [ "$(GET msg)" ] && new_msg
771 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
772 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
773 user_box
774 bug_page
775 html_footer ;;
776 *\ signup\ *)
777 # Signup
778 header
779 html_header
780 user_box
781 echo "<h2>$(gettext "Sign Up")</h2>"
782 if [ "$ONLINE_SIGNUP" == "yes" ]; then
783 signup_page
784 else
785 gettext "Online registration is disabled"
786 fi
787 html_footer ;;
789 *\ search\ *)
790 found=0
791 header
792 html_header
793 user_box
794 cat << EOT
795 <h2>$(gettext "Search")</h2>
796 <form method="get" action="$script">
797 <input type="text" name="search" />
798 <input type="submit" value="$(gettext 'Search')" />
799 </form>
800 <div>
801 <p>
802 $(gettext 'Search by pattern, package or user')
803 </p>
804 EOT
805 if [ ! "$(GET search)" ]; then
806 html_footer && exit 0
807 else
808 echo "<h3>$(gettext 'Result for:') $(GET search)</h3>"
809 fi
810 for id in $(ls_bugs)
811 do
812 set_bugdir "$id"
813 result=$(fgrep -i -h "$(GET search)" $bugdir/$id/*)
814 if [ "$result" ]; then
815 found=$(($found + 1))
816 echo "<p><strong>Bug $id</strong> - <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
817 echo '<pre>'
818 echo "$result" | \
819 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
820 echo '</pre>'
821 fi
822 bugdir=$(dirname $bugdir)
823 done
824 if [ "$found" == "0" ]; then
825 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
826 else
827 echo "<p> $found $(gettext 'results found')</p>"
828 fi
829 echo '</div>' && html_footer ;;
831 *)
832 # Default page.
833 bugs=$(ls_bugs | wc -l)
834 close=$(ls $bugdir/closed | wc -l)
835 fixme=$(ls $bugdir/open | wc -l)
836 msgs=$(find $bugdir -name msg.* | wc -l)
837 pct=0
838 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
839 header
840 html_header
841 user_box
843 cat << EOT
845 <h2>$(gettext "Summary")</h2>
847 <p>
848 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
849 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
850 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
851 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
852 </p>
854 <div class="pctbar">
855 <div class="pct" style="width: ${pct}%;">${pct}%</div>
856 </div>
858 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
859 more information. You may also be interested by the SliTaz \
860 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
861 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
862 enter your term and press ENTER.")
863 </p>
865 <div id="tools">
866 $BUGS_TOOLS
867 <a href="?closed">$(gettext 'Closed bugs')</a>
868 EOT
869 if check_auth; then
870 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
871 echo "$PLUGINS_TOOLS"
872 fi
873 cat << EOT
874 </div>
876 <h3>$(gettext "Latest Bugs")</h3>
877 EOT
878 # List last 4 bugs
879 echo "<pre>"
880 for lb in $(ls_bugs | sort -n -r | head -n 4)
881 do
882 list_bug ${lb}
883 done
884 echo "</pre>"
886 # List last 4 messages
887 echo "<h3>$(gettext "Latest Messages")</h3>"
888 echo "<pre>"
890 for msg in $(ls -r $bugdir/*/*/msg.* | head -n 4)
891 do
892 list_msg ${msg}
893 done
894 echo "</pre>"
895 list_bugs open
896 echo "</pre>"
897 html_footer ;;
898 esac
900 exit 0