tazbug view web/bugs.cgi @ rev 155

fix wiki_parser for "
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jan 10 10:36:26 2019 +0100 (3 months ago)
parents 5ce0583b6113
children 8fcbcf75a882
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/\"/\\\\&/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 <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#\\"#"#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 #
363 # MSG="`tazlocale` should do the work..." make msg.N unsourcable
364 # Move to text file for msg content, ex: msg.1.conf msg.1.txt
365 #
366 if ! . ${msg}; then
367 echo "<pre>"
368 echo "<span class='error'>ERROR: sourcing $(basename $msg)</span>"
369 cat ${msg}
370 echo "</pre>"
371 fi
372 if [ "$MSG" ]; then
373 msgid=$(echo $msg | cut -d "." -f 2)
374 del=""
375 # User can delete his post as well as admin.
376 if [ "$user" == "$USER" ] || admin_user; then
377 del="- <a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
378 fi
379 cat << EOT
380 <h4 id="msg${msgid}">$(gettext "By:") <a href="?user=$USER">$USER</a> on $DATE $del</h4>
381 <pre>
382 $(echo "$MSG" | wiki_parser)
383 </pre>
384 EOT
385 #
386 # BUG: $(echo "$MSG" | wiki_parser)
387 #
388 fi
389 unset USER DATE MSG
390 done
391 if check_auth; then
392 cat << EOT
393 <div>
394 <h3>$(gettext "New message")</h3>
395 <form method="get" action="$script">
396 <input type="hidden" name="id" value="$id" />
397 <textarea name="msg" rows="8"></textarea>
398 <p><input type="submit" value="$(gettext 'Send message')" /></p>
399 </form>
400 </div>
401 EOT
402 fi
403 }
405 # Write a new message
406 new_msg() {
407 date=$(date "+%Y-%m-%d %H:%M")
408 msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1)
409 count=$(($msgs + 1))
410 if check_auth; then
411 USER="$user"
412 fi
413 js_log "Will write message in $bugdir/$id/msg.$count "
414 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
415 USER="$USER"
416 DATE="$date"
417 MSG="$(GETfiltered msg)"
418 EOT
419 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
420 rm -f $bugdir/$id/msg.$count.tmp
421 }
423 # Create a new Bug. ID is set by counting dirs in bug/ + 1
424 new_bug() {
425 count=$(ls_bugs | sort -g | tail -n 1)
426 id=$(($count +1))
427 date=$(date "+%Y-%m-%d")
428 # Sanity check, JS may be disabled.
429 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
430 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
431 if check_auth; then
432 USER="$user"
433 fi
434 mkdir -p $bugdir/open/$id
435 # bug.conf
436 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/bug.conf << EOT
437 # SliTaz Bug configuration
439 BUG="$(GETfiltered bug)"
440 STATUS="OPEN"
441 PRIORITY="$(GET priority)"
442 CREATOR="$USER"
443 DATE="$date"
444 PKGS="$(GETfiltered pkgs)"
445 EOT
446 # desc.txt
447 sed "s/$(echo -en '\r') /\n/g" > $bugdir/open/$id/desc.tmp << EOT
448 $(GETfiltered desc)
449 EOT
450 fold -s -w 80 $bugdir/open/$id/desc.tmp > $bugdir/open/$id/desc.txt
451 rm -f $bugdir/open/$id/*.tmp
452 }
454 # New bug page for the web interface
455 new_bug_page() {
456 cat << EOT
457 <h2>$(gettext "New Bug")</h2>
458 <div id="newbug">
460 <form method="get" action="$script" onsubmit="return checkNewBug();">
461 <input type="hidden" name="addbug" />
462 <table>
463 <tbody>
464 <tr>
465 <td>$(gettext "Bug title")*</td>
466 <td><input type="text" name="bug" /></td>
467 </tr>
468 <tr>
469 <td>$(gettext "Description")*</td>
470 <td><textarea name="desc"></textarea></td>
471 </tr>
472 <tr>
473 <td>$(gettext "Packages")</td>
474 <td><input type="text" name="pkgs" /></td>
475 </tr>
476 <tr>
477 <td>$(gettext "Priority")</td>
478 <td>
479 <select name="priority">
480 <option value="standard">$(gettext "Standard")</option>
481 <option value="critical">$(gettext "Critical")</option>
482 </select>
483 <input type="submit" value="$(gettext "Create Bug")" />
484 </td>
485 </tr>
486 </tbody>
487 </table>
488 </form>
490 <p>
491 $(gettext "* field is obligatory. You can also specify affected packages.")
492 </p>
494 </div>
495 EOT
496 }
498 # Edit/Save a bug
499 edit_bug() {
500 . $bugdir/$id/bug.conf
501 if admin_user || [ "$user" == "$CREATOR" ]; then
502 continue
503 else
504 gettext "You can't edit someone else's bug!" && exit 0
505 fi
506 cat << EOT
507 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
508 <div id="editbug">
510 <form method="get" action="$script">
511 <input type="hidden" name="savebug" />
512 <input type="hidden" name="id" value="$id" />
513 <input type="hidden" name="creator" value="$CREATOR" />
514 <input type="hidden" name="date" value="$DATE" />
515 <table>
516 <tbody>
517 <tr>
518 <td>$(gettext "Bug title")</td>
519 <td><input type="text" name="bug" value="$${BUG//\"/&#34}" /></td>
520 </tr>
521 <tr>
522 <td>$(gettext "Description")</td>
523 <td><textarea name="desc">$(sed 's|\\"|\&#34|' $bugdir/$id/desc.txt)</textarea></td>
524 </tr>
525 <tr>
526 <td>$(gettext "Packages")</td>
527 <td><input type="text" name="pkgs" value="$PKGS" /></td>
528 </tr>
529 <tr>
530 <td>$(gettext "Priority")</td>
531 <td>
532 <select name="priority">
533 <option value="$PRIORITY">$PRIORITY</option>
534 <option value="standard">$(gettext "Standard")</option>
535 <option value="critical">$(gettext "Critical")</option>
536 </select>
537 <input type="submit" value="$(gettext 'Save configuration')" />
538 </td>
539 </tr>
540 </tbody>
541 </table>
542 </form>
544 </div>
545 EOT
546 }
548 save_bug() {
549 id="$(GET id)"
550 set_bugdir ${id}
551 # bug.conf
552 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
553 # SliTaz Bug configuration
555 BUG="$(GETfiltered bug)"
556 STATUS="OPEN"
557 PRIORITY="$(GET priority)"
558 CREATOR="$(GET creator)"
559 DATE="$(GET date)"
560 PKGS="$(GETfiltered pkgs)"
561 EOT
562 # desc.txt
563 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
564 $(GETfiltered desc)
565 EOT
566 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
567 rm -f $bugdir/$id/*.tmp
568 }
570 # Close a fixed bug
571 close_bug() {
572 sed -i s'/OPEN/CLOSED/' $bugdir/open/$id/bug.conf
573 mv $bugdir/open/$id $bugdir/closed/$id
574 }
576 # Re open an old bug
577 open_bug() {
578 sed -i s'/CLOSED/OPEN/' $bugdir/closed/$id/bug.conf
579 mv $bugdir/closed/$id $bugdir/open/$id
580 }
582 # Get and display Gravatar image: get_gravatar email size
583 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
584 get_gravatar() {
585 email=$1
586 size=$2
587 [ "$size" ] || size=48
588 url="http://www.gravatar.com/avatar"
589 md5=$(md5crypt $email)
590 echo "<img src='$url/$md5?d=identicon&amp;s=$size' alt='' />"
591 }
593 # Create a new user in AUTH_FILE and PEOPLE
594 new_user_config() {
595 if [ ! -f "$AUTH_FILE" ]; then
596 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
597 fi
598 echo "$user:$pass" >> $AUTH_FILE
599 mkdir -pm0700 $PEOPLE/${user}
600 cat > $PEOPLE/$user/account.conf << EOT
601 # User configuration
602 NAME="$name"
603 USER="$user"
604 MAIL="$mail"
605 EOT
606 chmod 0600 $PEOPLE/$user/account.conf
607 # First created user is admin
608 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
609 echo "$user" > ${ADMIN_USERS}
610 fi
611 }
613 ########################################################################
614 # POST actions #
615 ########################################################################
617 case " $(POST) " in
618 *\ auth\ *)
619 header
620 html_header
621 # Authenticate user. Create a session file in $sessions to be used
622 # by check_auth. We have the user login name and a peer session
623 # md5 string in the COOKIE.
624 user="$(POST auth)"
625 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
627 IDLOC=""
628 if [[ "$(POST id)" ]] ;then
629 IDLOC="&id=$(POST id)"
630 fi
632 if [ ! -f $AUTH_FILE ] ; then
633 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
634 js_redirection_to "$script?login$IDLOC"
635 fi;
637 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
638 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
639 if [[ "$(POST id)" ]] ;then
640 IDLOC="?id=$(POST id)"
641 fi
642 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
643 mkdir -p $sessions
644 # Log last login
645 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
646 echo "$md5session" > $sessions/$user
647 js_set_cookie 'auth' "$user:$md5session"
648 js_log "Login authentication has been executed & accepted :)"
649 js_redirection_to "$script$IDLOC"
650 else
651 js_log "Login authentication has been executed & refused"
652 js_redirection_to "$script?login&error$IDLOC"
653 fi
654 html_footer ;;
655 *\ signup\ *)
656 # POST action for online signup
657 name="$(POST name)"
658 user="$(POST user)"
659 mail="$(POST mail)"
660 pass="$(md5crypt "$(POST pass)")"
661 if ! grep "^${user}:" $AUTH_FILE; then
662 online="yes"
663 new_user_config
664 header "Location: $SCRIPT_NAME?login"
665 else
666 header
667 html_header
668 user_box
669 echo "<h2>$(gettext "User already exists:") $user</h2>"
670 html_footer && exit 0
671 fi ;;
672 esac
674 #
675 # Plugins Now!
676 #
678 for p in $(ls -1 $plugins)
679 do
680 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
681 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
682 done
684 ########################################################################
685 # GET actions #
686 ########################################################################
688 case " $(GET) " in
689 *\ README\ *)
690 header
691 html_header
692 user_box
693 echo '<h2>README</h2>'
694 echo '<pre>'
695 if [ -f "README" ]; then
696 cat README
697 else
698 cat /usr/share/doc/tazbug/README
699 fi
700 echo '</pre>'
701 html_footer ;;
703 *\ closed\ *)
704 # Show all closed bugs.
705 header
706 html_header
707 user_box
708 list_bugs "closed"
709 echo "</pre>"
710 html_footer ;;
712 *\ login\ *)
713 # The login page
714 [ "$(GET error)" ] && \
715 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
716 header
717 html_header
718 user_box
719 login_page
720 html_footer ;;
722 *\ logout\ *)
723 header
724 html_header
725 if check_auth; then
726 rm -f "$sessions/$user"
727 js_unset_cookie 'auth'
728 js_redirection_to "$script"
729 fi ;;
731 *\ user\ *)
732 # User profile. Use the users plugin for more functions
733 last="$(cat $PEOPLE/"$(GET user)"/last)"
734 header
735 html_header
736 user_box
737 . $PEOPLE/"$(GET user)"/account.conf
738 cat << EOT
739 <h2>$(get_gravatar $MAIL) $NAME</h2>
741 <pre>
742 $(gettext "User name :") $USER
743 $(gettext "Last login :") $last
744 </pre>
745 EOT
746 html_footer ;;
748 *\ newbug\ *)
749 # Create a bug from web interface.
750 header
751 html_header
752 user_box
753 if check_auth; then
754 new_bug_page
755 else
756 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
757 fi
758 html_footer ;;
760 *\ addbug\ *)
761 # Save a new bug
762 header
763 html_header
764 if check_auth; then
765 new_bug
766 js_redirection_to "$script?id=$id"
767 fi ;;
769 *\ editbug\ *)
770 # Edit existing bug
771 header
772 html_header
773 id="$(GET editbug)"
774 set_bugdir ${id}
775 user_box
776 edit_bug
777 html_footer ;;
779 *\ savebug\ *)
780 if check_auth; then
781 save_bug
782 js_redirection_to "$script?id=$id"
783 fi ;;
785 *\ id\ *)
786 header
787 html_header
788 user_box
789 id="$(GET id)"
790 [ "$(GET close)" ] && close_bug
791 [ "$(GET open)" ] && open_bug
792 set_bugdir ${id}
793 [ "$(GET msg)" ] && new_msg
794 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
795 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
796 bug_page
797 html_footer ;;
799 *\ signup\ *)
800 # Signup
801 header
802 html_header
803 user_box
804 echo "<h2>$(gettext "Sign Up")</h2>"
805 if [ "$ONLINE_SIGNUP" == "yes" ]; then
806 signup_page
807 else
808 gettext "Online registration is disabled"
809 fi
810 html_footer ;;
812 *\ search\ *)
813 found=0
814 header
815 html_header
816 user_box
817 cat << EOT
818 <h2>$(gettext "Search")</h2>
819 <form method="get" action="$script">
820 <input type="text" name="search" />
821 <input type="submit" value="$(gettext 'Search')" />
822 </form>
823 <div>
824 <p>
825 $(gettext 'Search by pattern, package or user')
826 </p>
827 EOT
828 if [ ! "$(GET search)" ]; then
829 html_footer && exit 0
830 else
831 echo "<h3>$(gettext 'Result for:') $(GET search)</h3>"
832 fi
833 for id in $(ls_bugs)
834 do
835 set_bugdir "$id"
836 result=$(fgrep -i -h "$(GET search)" $bugdir/$id/*)
837 if [ "$result" ]; then
838 found=$(($found + 1))
839 echo "<p><strong>Bug $id</strong> - <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
840 echo '<pre>'
841 echo "$result" | \
842 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
843 echo '</pre>'
844 fi
845 bugdir=$(dirname $bugdir)
846 done
847 if [ "$found" == "0" ]; then
848 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
849 else
850 echo "<p> $found $(gettext 'results found')</p>"
851 fi
852 echo '</div>' && html_footer ;;
854 *)
855 # Default page.
856 bugs=$(ls_bugs | wc -l)
857 close=$(ls $bugdir/closed | wc -l)
858 fixme=$(ls $bugdir/open | wc -l)
859 msgs=$(find $bugdir -name msg.* | wc -l)
860 pct=0
861 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
862 header
863 html_header
864 user_box
866 cat << EOT
868 <h2>$(gettext "Summary")</h2>
870 <p>
871 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
872 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
873 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
874 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
875 </p>
877 <div class="pctbar">
878 <div class="pct" style="width: ${pct}%;">${pct}%</div>
879 </div>
881 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
882 more information. You may also be interested by the SliTaz \
883 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
884 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
885 enter your term and press ENTER.")
886 </p>
888 <div id="tools">
889 $BUGS_TOOLS
890 <a href="?closed">$(gettext 'Closed bugs')</a>
891 EOT
892 if check_auth; then
893 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
894 echo "$PLUGINS_TOOLS"
895 fi
896 cat << EOT
897 </div>
899 <h3>$(gettext "Latest bugs")</h3>
900 EOT
901 # List last 4 bugs
902 echo "<pre>"
903 for lb in $(ls_bugs | sort -n -r | head -n 4)
904 do
905 list_bug ${lb}
906 done
907 echo "</pre>"
909 # List last 4 messages
910 echo "<h3>$(gettext "Latest messages")</h3>"
911 echo "<pre>"
912 for msg in $(ls -lt $bugdir/*/*/msg.* | awk '{print $9}' | head -n 4)
913 do
914 list_msg ${msg}
915 done
916 echo "</pre>"
917 list_bugs open
918 echo "</pre>"
919 html_footer ;;
920 esac
922 exit 0