tazbug view web/bugs.cgi @ rev 160
bugs.cgi: filter '*' too
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Nov 28 10:25:47 2019 +0100 (2019-11-28) |
parents | 8fcbcf75a882 |
children |
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; " \
71 -e "s/\"/\\\\&/g; s/\*/\\\\&/g;"
72 }
74 js_redirection_to() {
75 js_log "Redirecting to $1"
76 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
77 }
79 js_log() {
80 echo "<script type=\"text/javascript\">console.log('$1')</script>";
81 }
83 js_set_cookie() {
84 name=$1
85 value=$2
86 js_log 'Setting cookie.'
87 cat << EOT
88 <script type="text/javascript">
89 document.cookie = '$name=$value; expires=0; path=/';
90 </script>
91 EOT
92 }
94 js_unset_cookie() {
95 name=$1
96 js_log 'Unsetting cookie.'
97 cat << EOT
98 <script type="text/javascript">
99 document.cookie = '$1=""; expires=-1; path=/;'
100 </script>
101 EOT
102 }
104 # Check if user is auth
105 check_auth() {
106 auth="$(COOKIE auth)"
107 user="$(echo $auth | cut -d ":" -f 1)"
108 md5cookie="$(echo $auth | cut -d ":" -f 2)"
109 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
110 if [ "$md5cookie" = "$md5session" ] && [ "$auth" ]; then
111 return 0
112 else
113 return 1
114 fi
115 }
117 # Check if user is admin
118 admin_user() {
119 grep -w -q "$user" ${ADMIN_USERS}
120 }
122 # Authenticated or not (login/logout are not translated to keep css width)
123 user_box() {
125 IDLOC=""
126 if [[ "$(GET id)" ]] ;then
127 IDLOC="&id=$(GET id)"
128 fi
130 if check_auth; then
131 . $PEOPLE/$user/account.conf
132 cat << EOT
133 <div id="user">
134 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
135 <a href="?logout">Logout</a>
136 </div>
137 EOT
138 else
139 cat << EOT
140 <div id="user">
141 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
142 <a href="?login$IDLOC">Login</a>
143 </div>
144 EOT
145 fi
146 cat << EOT
148 <div id="search">
149 <form method="get" action="$script">
150 <input type="text" name="search" placeholder="$(gettext 'Search')" />
151 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
152 </form>
153 </div>
155 <!-- Content -->
156 <div id="content">
158 EOT
159 }
161 # Signup page
162 signup_page() {
163 cat << EOT
165 <div id="signup">
166 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
167 <input type="hidden" name="signup" value="new" />
168 <input type="text" name="name" placeholder="$(gettext "Real name")" />
169 <input type="text" name="user" placeholder="$(gettext "User name")" />
170 <input type="text" name="mail" placeholder="$(gettext "Email")" />
171 <input type="password" name="pass" placeholder="$(gettext "Password")" />
172 <div>
173 <input type="submit" value="$(gettext "Create new account")" />
174 </div>
175 </form>
176 </div>
178 EOT
179 }
181 # Link for online signup if enabled.
182 online_signup() {
183 if [ "$ONLINE_SIGNUP" = "yes" ]; then
184 echo -n "<a href='$script?signup&online'>"
185 gettext "Sign Up Online"
186 echo '</a></p>'
187 fi
188 }
190 # Login page
191 login_page() {
192 cat << EOT
193 <h2>$(gettext 'Login')</h2>
195 <div id="account-info">
196 <p>$(gettext "No account yet?")</p>
197 $(online_signup)
198 <p>$(gettext "Tip: to attach big files or images, you can use SliTaz Paste \
199 services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a></p>
200 </div>
202 <div id="login">
203 <form method="post" action="$script">
204 <div>
205 <input type="text" name="auth" placeholder="$(gettext 'User name')" />
206 </div>
207 <input type="password" name="pass" placeholder="$(gettext 'Password')" />
208 <div>
209 <input type="hidden" name="id" value="$(GET id)" />
210 <input type="submit" value="$(gettext 'Log in')" />
211 $error
212 </div>
213 </form>
214 </div>
216 <div style="clear: both;"></div>
217 EOT
218 }
220 # Set open/closed bug path: set_bugpath ID
221 set_bugpath() {
222 if [ -d "$bugdir/closed/$1" ]; then
223 bugpath="$bugdir/closed/$1"
224 else
225 bugpath="$bugdir/open/$1"
226 fi
227 }
228 set_bugdir() {
229 if [ -d "$bugdir/closed/$1" ]; then
230 bugdir="$bugdir/closed"
231 else
232 bugdir="$bugdir/open"
233 fi
234 }
236 # Nice ls output for open and closed bugs
237 ls_bugs() {
238 ls $bugdir/open
239 ls $bugdir/closed
240 }
242 # Usage: list_bug ID
243 list_bug() {
244 id="$1"
245 set_bugpath ${id}
246 . ${bugpath}/bug.conf
247 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
248 . ${PEOPLE}/${CREATOR}/account.conf
249 cat << EOT
250 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
251 Bug $id: <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
252 EOT
253 unset CREATOR USER MAIL bugpath
254 }
256 # Usage: list_bugs [open|closed]
257 list_bugs() {
258 status="$1"
259 echo "<h3>$(gettext 'Bugs:') $status</h3>"
260 echo "<pre>"
261 for pr in critical standard
262 do
263 for id in $(ls $bugdir/$status)
264 do
265 . $bugdir/$status/$id/bug.conf
266 if [ "$PRIORITY" = "$pr" ]; then
267 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
268 . ${PEOPLE}/${CREATOR}/account.conf
269 cat << EOT
270 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
271 Bug $id: <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
272 EOT
273 fi
274 unset CREATOR USER MAIL BUG
275 done
276 done
277 }
279 # Usage: list_msg path
280 list_msg() {
281 msg="$1"
282 msgid=$(echo $msg | cut -d "." -f 2)
283 dir=$(dirname $msg)
284 id=$(basename $dir)
285 resume="$(fgrep MSG= $msg | cut -d \" -f 2 | cut -c 1-40)"
286 . ${msg}
287 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
288 . ${PEOPLE}/${USER}/account.conf
289 cat << EOT
290 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
291 <a href="?id=$id">Bug $id</a>: <span class="date">$DATE</span> \
292 <a href="?id=$id#msg${msgid}">${resume}...</a>
293 EOT
294 unset CREATOR USER MAIL
295 }
297 # Stripped down Wiki parser for bug desc and messages which are simply
298 # displayed in <pre>
299 wiki_parser() {
300 sed \
301 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
302 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
303 -e 's#\\\\n##g;s#\\"#"#g;s#%22#"#g;s#%21#!#g'
304 }
306 # Bug page
307 bug_page() {
308 . $bugdir/$id/bug.conf
309 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
310 . $PEOPLE/$CREATOR/account.conf
311 else
312 MAIL="default"
313 fi
314 cat << EOT
315 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
317 <h3>$(get_gravatar $MAIL 32) $BUG</h3>
318 <p>
319 $(gettext "Date:") $DATE -
320 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
321 $(eval_gettext 'Priority $PRIORITY') -
322 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
323 </p>
325 <pre>
326 $(cat $bugdir/$id/desc.txt | wiki_parser)
327 </pre>
328 EOT
329 if [ "$PKGS" ] && [ -x "$plugins/packages/packages.cgi" ]; then
330 echo "<p style='vertical-align: middle;'>"
331 echo "<strong>$(gettext 'Affected package(s):')</strong>"
332 for pkg in $PKGS; do
333 echo "<a href='?pkg=$pkg'>$pkg</a>"
334 done
335 echo "</p>"
336 fi
337 echo '<div id="tools">'
338 if check_auth; then
339 if [ "$STATUS" = "OPEN" ]; then
340 cat << EOT
341 <a href="?id=$id&close">$(gettext "Close bug")</a>
342 EOT
343 # Only original user and admin can edit a bug
344 if [ "$user" = "$CREATOR" ] || admin_user; then
345 cat << EOT
346 <a href="?editbug=$id">$(gettext "Edit bug")</a>
347 EOT
348 fi
349 else
350 cat << EOT
351 <a href="?id=$id&open">$(gettext "Re open bug")</a>
352 EOT
353 fi
354 fi
355 cat << EOT
356 </div>
358 <h3>$(gettext "Messages")</h3>
359 EOT
360 [ "$msgs" = "0" ] && gettext "No messages"
361 for msg in $(ls -1tr $bugdir/$id/msg.*)
362 do
363 #
364 # MSG="`tazlocale` should do the work..." make msg.N unsourcable
365 # Move to text file for msg content, ex: msg.1.conf msg.1.txt
366 #
367 if ! . ${msg}; then
368 echo "<pre>"
369 echo "<span class='error'>ERROR: sourcing $(basename $msg)</span>"
370 cat ${msg}
371 echo "</pre>"
372 fi
373 if [ "$MSG" ]; then
374 msgid=$(echo $msg | cut -d "." -f 2)
375 del=""
376 # User can delete his post as well as admin.
377 if [ "$user" = "$USER" ] || admin_user; then
378 del="- <a href=\"?id=$id&delmsg=$msgid\">delete</a>"
379 fi
380 cat << EOT
381 <h4 id="msg${msgid}">$(gettext "By:") <a href="?user=$USER">$USER</a> on $DATE $del</h4>
382 <pre>
383 $(echo "$MSG" | wiki_parser)
384 </pre>
385 EOT
386 #
387 # BUG: $(echo "$MSG" | wiki_parser)
388 #
389 fi
390 unset USER DATE MSG
391 done
392 if check_auth; then
393 cat << EOT
394 <div>
395 <h3>$(gettext "New message")</h3>
396 <form method="get" action="$script">
397 <input type="hidden" name="id" value="$id" />
398 <textarea name="msg" rows="8"></textarea>
399 <p><input type="submit" value="$(gettext 'Send message')" /></p>
400 </form>
401 </div>
402 EOT
403 fi
404 }
406 # Write a new message
407 new_msg() {
408 date=$(date "+%Y-%m-%d %H:%M")
409 msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1)
410 count=$(($msgs + 1))
411 if check_auth; then
412 USER="$user"
413 fi
414 js_log "Will write message in $bugdir/$id/msg.$count "
415 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
416 USER="$USER"
417 DATE="$date"
418 MSG="$(GETfiltered msg)"
419 EOT
420 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
421 rm -f $bugdir/$id/msg.$count.tmp
422 }
424 # Create a new Bug. ID is set by counting dirs in bug/ + 1
425 new_bug() {
426 count=$(ls_bugs | sort -g | tail -n 1)
427 id=$(($count +1))
428 date=$(date "+%Y-%m-%d")
429 # Sanity check, JS may be disabled.
430 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
431 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
432 if check_auth; then
433 USER="$user"
434 fi
435 mkdir -p $bugdir/open/$id
436 # bug.conf
437 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/bug.conf << EOT
438 # SliTaz Bug configuration
440 BUG="$(GETfiltered bug)"
441 STATUS="OPEN"
442 PRIORITY="$(GET priority)"
443 CREATOR="$USER"
444 DATE="$date"
445 PKGS="$(GETfiltered pkgs)"
446 EOT
447 # desc.txt
448 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/desc.tmp << EOT
449 $(GETfiltered desc)
450 EOT
451 fold -s -w 80 $bugdir/open/$id/desc.tmp > $bugdir/open/$id/desc.txt
452 rm -f $bugdir/open/$id/*.tmp
453 }
455 # New bug page for the web interface
456 new_bug_page() {
457 cat << EOT
458 <h2>$(gettext "New Bug")</h2>
459 <div id="newbug">
461 <form method="get" action="$script" onsubmit="return checkNewBug();">
462 <input type="hidden" name="addbug" />
463 <table>
464 <tbody>
465 <tr>
466 <td>$(gettext "Bug title")*</td>
467 <td><input type="text" name="bug" /></td>
468 </tr>
469 <tr>
470 <td>$(gettext "Description")*</td>
471 <td><textarea name="desc"></textarea></td>
472 </tr>
473 <tr>
474 <td>$(gettext "Packages")</td>
475 <td><input type="text" name="pkgs" /></td>
476 </tr>
477 <tr>
478 <td>$(gettext "Priority")</td>
479 <td>
480 <select name="priority">
481 <option value="standard">$(gettext "Standard")</option>
482 <option value="critical">$(gettext "Critical")</option>
483 </select>
484 <input type="submit" value="$(gettext "Create Bug")" />
485 </td>
486 </tr>
487 </tbody>
488 </table>
489 </form>
491 <p>
492 $(gettext "* field is obligatory. You can also specify affected packages.")
493 </p>
495 </div>
496 EOT
497 }
499 # Edit/Save a bug
500 edit_bug() {
501 . $bugdir/$id/bug.conf
502 if admin_user || [ "$user" = "$CREATOR" ]; then
503 continue
504 else
505 gettext "You can't edit someone else's bug!" && exit 0
506 fi
507 cat << EOT
508 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
509 <div id="editbug">
511 <form method="get" action="$script">
512 <input type="hidden" name="savebug" />
513 <input type="hidden" name="id" value="$id" />
514 <input type="hidden" name="creator" value="$CREATOR" />
515 <input type="hidden" name="date" value="$DATE" />
516 <table>
517 <tbody>
518 <tr>
519 <td>$(gettext "Bug title")</td>
520 <td><input type="text" name="bug" value="$${BUG//\"/"}" /></td>
521 </tr>
522 <tr>
523 <td>$(gettext "Description")</td>
524 <td><textarea name="desc">$(sed 's|\\"|\"|' $bugdir/$id/desc.txt)</textarea></td>
525 </tr>
526 <tr>
527 <td>$(gettext "Packages")</td>
528 <td><input type="text" name="pkgs" value="$PKGS" /></td>
529 </tr>
530 <tr>
531 <td>$(gettext "Priority")</td>
532 <td>
533 <select name="priority">
534 <option value="$PRIORITY">$PRIORITY</option>
535 <option value="standard">$(gettext "Standard")</option>
536 <option value="critical">$(gettext "Critical")</option>
537 </select>
538 <input type="submit" value="$(gettext 'Save configuration')" />
539 </td>
540 </tr>
541 </tbody>
542 </table>
543 </form>
545 </div>
546 EOT
547 }
549 save_bug() {
550 id="$(GET id)"
551 set_bugdir ${id}
552 # bug.conf
553 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
554 # SliTaz Bug configuration
556 BUG="$(GETfiltered bug)"
557 STATUS="OPEN"
558 PRIORITY="$(GET priority)"
559 CREATOR="$(GET creator)"
560 DATE="$(GET date)"
561 PKGS="$(GETfiltered pkgs)"
562 EOT
563 # desc.txt
564 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
565 $(GETfiltered desc)
566 EOT
567 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
568 rm -f $bugdir/$id/*.tmp
569 }
571 # Close a fixed bug
572 close_bug() {
573 sed -i s'/OPEN/CLOSED/' $bugdir/open/$id/bug.conf
574 mv $bugdir/open/$id $bugdir/closed/$id
575 }
577 # Re open an old bug
578 open_bug() {
579 sed -i s'/CLOSED/OPEN/' $bugdir/closed/$id/bug.conf
580 mv $bugdir/closed/$id $bugdir/open/$id
581 }
583 # Get and display Gravatar image: get_gravatar email size
584 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
585 get_gravatar() {
586 email=$1
587 size=$2
588 [ "$size" ] || size=48
589 url="http://www.gravatar.com/avatar"
590 md5=$(md5crypt $email)
591 echo "<img src='$url/$md5?d=identicon&s=$size' alt='' />"
592 }
594 # Create a new user in AUTH_FILE and PEOPLE
595 new_user_config() {
596 if [ ! -f "$AUTH_FILE" ]; then
597 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
598 fi
599 echo "$user:$pass" >> $AUTH_FILE
600 mkdir -pm0700 $PEOPLE/${user}
601 cat > $PEOPLE/$user/account.conf << EOT
602 # User configuration
603 NAME="$name"
604 USER="$user"
605 MAIL="$mail"
606 EOT
607 chmod 0600 $PEOPLE/$user/account.conf
608 # First created user is admin
609 if [ $(ls ${PEOPLE} | wc -l) = "1" ]; then
610 echo "$user" > ${ADMIN_USERS}
611 fi
612 }
614 ########################################################################
615 # POST actions #
616 ########################################################################
618 case " $(POST) " in
619 *\ auth\ *)
620 header
621 html_header
622 # Authenticate user. Create a session file in $sessions to be used
623 # by check_auth. We have the user login name and a peer session
624 # md5 string in the COOKIE.
625 user="$(POST auth)"
626 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
628 IDLOC=""
629 if [[ "$(POST id)" ]] ;then
630 IDLOC="&id=$(POST id)"
631 fi
633 if [ ! -f $AUTH_FILE ] ; then
634 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
635 js_redirection_to "$script?login$IDLOC"
636 fi;
638 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
639 if [ "$pass" = "$valid" ] && [ "$pass" != "" ]; then
640 if [[ "$(POST id)" ]] ;then
641 IDLOC="?id=$(POST id)"
642 fi
643 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
644 mkdir -p $sessions
645 # Log last login
646 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
647 echo "$md5session" > $sessions/$user
648 js_set_cookie 'auth' "$user:$md5session"
649 js_log "Login authentication has been executed & accepted :)"
650 js_redirection_to "$script$IDLOC"
651 else
652 js_log "Login authentication has been executed & refused"
653 js_redirection_to "$script?login&error$IDLOC"
654 fi
655 html_footer ;;
656 *\ signup\ *)
657 # POST action for online signup
658 name="$(POST name)"
659 user="$(POST user)"
660 mail="$(POST mail)"
661 pass="$(md5crypt "$(POST pass)")"
662 if ! grep "^${user}:" $AUTH_FILE; then
663 online="yes"
664 new_user_config
665 header "Location: $SCRIPT_NAME?login"
666 else
667 header
668 html_header
669 user_box
670 echo "<h2>$(gettext "User already exists:") $user</h2>"
671 html_footer && exit 0
672 fi ;;
673 esac
675 #
676 # Plugins Now!
677 #
679 for p in $(ls -1 $plugins)
680 do
681 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
682 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
683 done
685 ########################################################################
686 # GET actions #
687 ########################################################################
689 case " $(GET) " in
690 *\ README\ *)
691 header
692 html_header
693 user_box
694 echo '<h2>README</h2>'
695 echo '<pre>'
696 if [ -f "README" ]; then
697 cat README
698 else
699 cat /usr/share/doc/tazbug/README
700 fi
701 echo '</pre>'
702 html_footer ;;
704 *\ closed\ *)
705 # Show all closed bugs.
706 header
707 html_header
708 user_box
709 list_bugs "closed"
710 echo "</pre>"
711 html_footer ;;
713 *\ login\ *)
714 # The login page
715 [ "$(GET error)" ] && \
716 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
717 header
718 html_header
719 user_box
720 login_page
721 html_footer ;;
723 *\ logout\ *)
724 header
725 html_header
726 if check_auth; then
727 rm -f "$sessions/$user"
728 js_unset_cookie 'auth'
729 js_redirection_to "$script"
730 fi ;;
732 *\ user\ *)
733 # User profile. Use the users plugin for more functions
734 last="$(cat $PEOPLE/"$(GET user)"/last)"
735 header
736 html_header
737 user_box
738 . $PEOPLE/"$(GET user)"/account.conf
739 cat << EOT
740 <h2>$(get_gravatar $MAIL) $NAME</h2>
742 <pre>
743 $(gettext "User name :") $USER
744 $(gettext "Last login :") $last
745 </pre>
746 EOT
747 html_footer ;;
749 *\ newbug\ *)
750 # Create a bug from web interface.
751 header
752 html_header
753 user_box
754 if check_auth; then
755 new_bug_page
756 else
757 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
758 fi
759 html_footer ;;
761 *\ addbug\ *)
762 # Save a new bug
763 header
764 html_header
765 if check_auth; then
766 new_bug
767 js_redirection_to "$script?id=$id"
768 fi ;;
770 *\ editbug\ *)
771 # Edit existing bug
772 header
773 html_header
774 id="$(GET editbug)"
775 set_bugdir ${id}
776 user_box
777 edit_bug
778 html_footer ;;
780 *\ savebug\ *)
781 if check_auth; then
782 save_bug
783 js_redirection_to "$script?id=$id"
784 fi ;;
786 *\ id\ *)
787 header
788 html_header
789 user_box
790 id="$(GET id)"
791 [ "$(GET close)" ] && close_bug
792 [ "$(GET open)" ] && open_bug
793 set_bugdir ${id}
794 [ "$(GET msg)" ] && new_msg
795 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
796 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
797 bug_page
798 html_footer ;;
800 *\ signup\ *)
801 # Signup
802 header
803 html_header
804 user_box
805 echo "<h2>$(gettext "Sign Up")</h2>"
806 if [ "$ONLINE_SIGNUP" = "yes" ]; then
807 signup_page
808 else
809 gettext "Online registration is disabled"
810 fi
811 html_footer ;;
813 *\ search\ *)
814 found=0
815 header
816 html_header
817 user_box
818 cat << EOT
819 <h2>$(gettext "Search")</h2>
820 <form method="get" action="$script">
821 <input type="text" name="search" />
822 <input type="submit" value="$(gettext 'Search')" />
823 </form>
824 <div>
825 <p>
826 $(gettext 'Search by pattern, package or user')
827 </p>
828 EOT
829 if [ ! "$(GET search)" ]; then
830 html_footer && exit 0
831 else
832 echo "<h3>$(gettext 'Result for:') $(GET search)</h3>"
833 fi
834 for id in $(ls_bugs)
835 do
836 set_bugdir "$id"
837 result=$(fgrep -i -h "$(GET search)" $bugdir/$id/*)
838 if [ "$result" ]; then
839 found=$(($found + 1))
840 echo "<p><strong>Bug $id</strong> - <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
841 echo '<pre>'
842 echo "$result" | \
843 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
844 echo '</pre>'
845 fi
846 bugdir=$(dirname $bugdir)
847 done
848 if [ "$found" = "0" ]; then
849 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
850 else
851 echo "<p> $found $(gettext 'results found')</p>"
852 fi
853 echo '</div>' && html_footer ;;
855 *)
856 # Default page.
857 bugs=$(ls_bugs | wc -l)
858 close=$(ls $bugdir/closed | wc -l)
859 fixme=$(ls $bugdir/open | wc -l)
860 msgs=$(find $bugdir -name msg.* | wc -l)
861 pct=0
862 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
863 header
864 html_header
865 user_box
867 cat << EOT
869 <h2>$(gettext "Summary")</h2>
871 <p>
872 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
873 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
874 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
875 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
876 </p>
878 <div class="pctbar">
879 <div class="pct" style="width: ${pct}%;">${pct}%</div>
880 </div>
882 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
883 more information. You may also be interested by the SliTaz \
884 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
885 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
886 enter your term and press ENTER.")
887 </p>
889 <div id="tools">
890 $BUGS_TOOLS
891 <a href="?closed">$(gettext 'Closed bugs')</a>
892 EOT
893 if check_auth; then
894 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
895 echo "$PLUGINS_TOOLS"
896 fi
897 cat << EOT
898 </div>
900 <h3>$(gettext "Latest bugs")</h3>
901 EOT
902 # List last 4 bugs
903 echo "<pre>"
904 for lb in $(ls_bugs | sort -n -r | head -n 4)
905 do
906 list_bug ${lb}
907 done
908 echo "</pre>"
910 # List last 4 messages
911 echo "<h3>$(gettext "Latest messages")</h3>"
912 echo "<pre>"
913 for msg in $(ls -lt $bugdir/*/*/msg.* | awk '{print $9}' | head -n 4)
914 do
915 list_msg ${msg}
916 done
917 echo "</pre>"
918 list_bugs open
919 echo "</pre>"
920 html_footer ;;
921 esac
923 exit 0