tazbug view web/bugs.cgi @ rev 147

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