tazbug view web/bugs.cgi @ rev 98

Use desc.txt for bug description
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 10 14:54:49 2017 +0100 (2017-02-10)
parents 2228e0785489
children 5102774d2794
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
9 # Source config file
10 [ -f "/etc/slitaz/tazbug.conf" ] && . /etc/slitaz/tazbug.conf
11 # Web interface can have different setting than cmdline tools
12 [ -f "/etc/slitaz/bugs.conf" ] && . /etc/slitaz/bugs.conf
14 # Internal variable
15 bugdir="$PWD/bug"
16 plugins="plugins"
17 sessions="/tmp/bugs/sessions"
18 script="$SCRIPT_NAME"
20 # Content negotiation for Gettext
21 IFS=","
22 for lang in $HTTP_ACCEPT_LANGUAGE
23 do
24 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
25 case "$lang" in
26 en) LANG="C" && break ;;
27 de) LANG="de_DE" && break ;;
28 es) LANG="es_ES" && break ;;
29 fr) LANG="fr_FR" && break ;;
30 it) LANG="it_IT" && break ;;
31 pt) LANG="pt_BR" && break ;;
32 ru) LANG="ru_RU" && break ;;
33 zh) LANG="zh_TW" && break ;;
34 esac
35 done
36 unset IFS
37 export LANG LC_ALL=$LANG
39 # Internationalization: $(gettext "")
40 . /usr/bin/gettext.sh
41 TEXTDOMAIN='tazbug'
42 export TEXTDOMAIN
44 #
45 # Functions
46 #
48 # HTML 5 header.
49 html_header() {
50 cat lib/header.html
51 }
53 # HTML 5 footer.
54 html_footer() {
55 cat << EOT
56 </div>
58 <div id="footer">
59 <a href="$script">SliTaz Bugs</a> -
60 <a href="$script?README">README</a>
61 </div>
63 </body>
64 </html>
65 EOT
66 }
68 GETfiltered() {
69 GET $1 | sed -e "s/'/\&#39;/g; s|\n|<br/>|g; s/\t/\&#09;/g;s/\%22/\\\"/g"
70 }
72 js_redirection_to() {
73 js_log "Redirecting to $1"
74 echo "<script type=\"text/javascript\"> document.location = \"$1\"; </script>"
75 }
77 js_log() {
78 echo "<script type=\"text/javascript\">console.log('$1')</script>";
79 }
81 js_set_cookie() {
82 name=$1
83 value=$2
84 js_log 'Setting cookie.'
85 cat << EOT
86 <script type="text/javascript">
87 document.cookie = '$name=$value; expires=0; path=/';
88 </script>
89 EOT
90 }
92 js_unset_cookie() {
93 name=$1
94 js_log 'Unsetting cookie.'
95 cat << EOT
96 <script type="text/javascript">
97 document.cookie = '$1=""; expires=-1; path=/;'
98 </script>
99 EOT
100 }
102 # Check if user is auth
103 check_auth() {
104 auth="$(COOKIE auth)"
105 user="$(echo $auth | cut -d ":" -f 1)"
106 md5cookie="$(echo $auth | cut -d ":" -f 2)"
107 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
108 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
109 return 0
110 else
111 return 1
112 fi
113 }
115 # Check if user is admin
116 admin_user() {
117 fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf
118 }
120 # Authenticated or not
121 user_box() {
123 IDLOC=""
124 if [[ "$(GET id)" ]] ;then
125 IDLOC="&id=$(GET id)"
126 fi
128 if check_auth; then
129 . $PEOPLE/$user/account.conf
130 cat << EOT
131 <div id="user">
132 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
133 <a href="?logout">$(gettext 'Logout')</a>
134 </div>
135 EOT
136 else
137 cat << EOT
138 <div id="user">
139 <a href="?login$IDLOC"><img src="images/avatar.png" alt="[ User ]" /></a>
140 <a href="?login$IDLOC">$(gettext 'Login')</a>
141 </div>
142 EOT
143 fi
144 cat << EOT
146 <div id="search">
147 <form method="get" action="$script">
148 <input type="text" name="search" placeholder="$(gettext 'Search')" />
149 <!-- <input type="submit" value="$(gettext 'Search')" /> -->
150 </form>
151 </div>
153 <!-- Content -->
154 <div id="content">
156 EOT
157 }
159 # Signup page
160 signup_page() {
161 cat << EOT
163 <div id="signup">
164 <form method="post" name="signup" action="$SCRIPT_NAME" onsubmit="return checkSignup();">
165 <input type="hidden" name="signup" value="new" />
166 <input type="text" name="name" placeholder="$(gettext "Real name")" />
167 <input type="text" name="user" placeholder="$(gettext "User name")" />
168 <input type="text" name="mail" placeholder="$(gettext "Email")" />
169 <input type="password" name="pass" placeholder="$(gettext "Password")" />
170 <div>
171 <input type="submit" value="$(gettext "Create new account")" />
172 </div>
173 </form>
174 </div>
176 EOT
177 }
179 # Link for online signup if enabled.
180 online_signup() {
181 if [ "$ONLINE_SIGNUP" == "yes" ]; then
182 echo -n "<p>" && gettext "Or:"; echo -n " "
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? You can signup using the SliTaz Bugs reporter \
196 on your SliTaz system.")</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 # Display user public profile.
221 public_people() {
222 cat << EOT
223 </pre>
224 EOT
225 }
227 # Display authenticated user profile. TODO: change password
228 auth_people() {
229 cat << EOT
230 Email : $MAIL
231 Secure key : $KEY
232 </pre>
233 EOT
234 }
236 # Usage: list_bug ID
237 list_bug() {
238 id="$1"
239 . ${bugdir}/${id}/bug.conf
240 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
241 . ${PEOPLE}/${CREATOR}/account.conf
242 cat << EOT
243 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
244 ID: $id <a href="?id=$id">$BUG</a> <span class="date">$DATE</span>
245 EOT
246 unset CREATOR USER MAIL
247 }
249 # Usage: list_bugs STATUS
250 list_bugs() {
251 status="$1"
252 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
253 echo "<pre>"
254 for pr in critical standard
255 do
256 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
257 do
258 . $bug
259 id=$(basename $(dirname $bug))
260 if [ "$PRIORITY" == "$pr" ]; then
261 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
262 . ${PEOPLE}/${CREATOR}/account.conf
263 cat << EOT
264 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
265 ID: $id <a href="?id=$id">$BUG</a> <span class="date">$DATE</span>
266 EOT
267 fi
268 unset CREATOR USER MAIL
269 done
270 done
271 }
273 # Stripped down Wiki parser for bug desc and messages which are simply
274 # displayed in <pre>
275 wiki_parser() {
276 sed \
277 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
278 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
279 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
280 }
282 # Bug page
283 bug_page() {
284 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
285 . $PEOPLE/$CREATOR/account.conf
286 else
287 MAIL="default"
288 fi
289 cat << EOT
290 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
292 <p>
293 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
294 </p>
295 <p>
296 $(gettext "Date:") $DATE -
297 $(eval_gettext 'Priority $PRIORITY') -
298 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
299 </p>
301 <pre>
302 $(cat $bugdir/$id/desc.txt | wiki_parser)
303 </pre>
305 <div id="tools">
306 EOT
307 if check_auth; then
308 if [ "$STATUS" == "OPEN" ]; then
309 cat << EOT
310 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
311 <a href="?edit=$id">$(gettext "Edit bug")</a>
312 EOT
313 else
314 cat << EOT
315 <a href="?id=$id&amp;open">$(gettext "Re open bug")</a>
316 EOT
317 fi
318 fi
319 cat << EOT
320 </div>
322 <h3>$(gettext "Messages")</h3>
323 EOT
324 [ "$msgs" == "0" ] && gettext "No messages"
325 for msg in $(ls -1tr $bugdir/$id/msg.*)
326 do
327 . $msg
328 if [ "$MSG" ]; then
329 msgid=$(echo $msg | cut -d "." -f 2)
330 del=""
331 # User can delete his post as well as admin.
332 if [ "$user" == "$USER" ] || admin_user; then
333 del="<a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
334 fi
335 cat << EOT
336 <p><strong>$USER</strong> $DATE $del</p>
337 <pre>
338 $(echo "$MSG" | wiki_parser)
339 </pre>
340 EOT
341 fi
342 unset NAME DATE MSG
343 done
344 if check_auth; then
345 cat << EOT
346 <div>
347 <h3>$(gettext "New message")</h3>
348 <form method="get" action="$script">
349 <input type="hidden" name="id" value="$id" />
350 <textarea name="msg" rows="8"></textarea>
351 <p><input type="submit" value="$(gettext 'Send message')" /></p>
352 </form>
353 </div>
354 EOT
355 fi
356 }
358 # Write a new message
359 new_msg() {
360 date=$(date "+%Y-%m-%d %H:%M")
361 msgs=$(ls -1 $bugdir/$id/msg.* | wc -l)
362 count=$(($msgs + 1))
363 if check_auth; then
364 USER="$user"
365 fi
366 js_log "Will write message in $bugdir/$id/msg.$count "
367 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
368 USER="$USER"
369 DATE="$date"
370 MSG="$(GETfiltered msg)"
371 EOT
372 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
373 rm -f $bugdir/$id/msg.$count.tmp
374 }
376 # Create a new Bug. ID is set by counting dirs in bug/ + 1
377 new_bug() {
378 count=$(ls $bugdir | sort -g | tail -n 1)
379 count=$(($count +1))
380 date=$(date "+%Y-%m-%d %H:%M")
381 # Sanity check, JS may be disabled.
382 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
383 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
384 if check_auth; then
385 USER="$user"
386 fi
387 mkdir -p $bugdir/$count
388 # bug.conf
389 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
390 # SliTaz Bug configuration
392 BUG="$(GETfiltered bug)"
393 STATUS="OPEN"
394 PRIORITY="$(GET priority)"
395 CREATOR="$USER"
396 DATE="$date"
397 PKGS="$(GETfiltered pkgs)"
398 EOT
399 # desc.txt
400 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/desc.tmp << EOT
401 $(GETfiltered desc)
402 EOT
403 fold -s -w 80 $bugdir/$count/desc.tmp > $bugdir/$count/desc.txt
404 rm -f $bugdir/$count/*.tmp
405 }
407 # New bug page for the web interface
408 new_bug_page() {
409 cat << EOT
410 <h2>$(gettext "New Bug")</h2>
411 <div id="newbug">
413 <form method="get" action="$script" onsubmit="return checkNewBug();">
414 <input type="hidden" name="addbug" />
415 <table>
416 <tbody>
417 <tr>
418 <td>$(gettext "Bug title")*</td>
419 <td><input type="text" name="bug" /></td>
420 </tr>
421 <tr>
422 <td>$(gettext "Description")*</td>
423 <td><textarea name="desc"></textarea></td>
424 </tr>
425 <tr>
426 <td>$(gettext "Packages")</td>
427 <td><input type="text" name="pkgs" /></td>
428 </tr>
429 <tr>
430 <td>$(gettext "Priority")</td>
431 <td>
432 <select name="priority">
433 <option value="standard">$(gettext "Standard")</option>
434 <option value="critical">$(gettext "Critical")</option>
435 </select>
436 <input type="submit" value="$(gettext "Create Bug")" />
437 </td>
438 </tr>
439 </tbody>
440 </table>
441 </form>
443 <p>
444 $(gettext "* field is obligatory. You can also specify affected packages.")
445 </p>
447 </div>
448 EOT
449 }
452 # Edit/Save a bug
453 edit_bug() {
454 . $bugdir/$id/bug.conf
455 cat << EOT
456 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
457 <div id="edit">
459 <form method="get" action="$script">
460 <input type="hidden" name="savebug" />
461 <input type="hidden" name="id" value="$id" />
462 <input type="hidden" name="creator" value="$CREATOR" />
463 <input type="hidden" name="date" value="$DATE" />
464 <table>
465 <tbody>
466 <tr>
467 <td>$(gettext "Bug title")</td>
468 <td><input type="text" name="bug" value="$BUG" /></td>
469 </tr>
470 <tr>
471 <td>$(gettext "Description")</td>
472 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
473 </tr>
474 <tr>
475 <td>$(gettext "Packages")</td>
476 <td><input type="text" name="pkgs" value="$PKGS" /></td>
477 </tr>
478 <tr>
479 <td>$(gettext "Priority")</td>
480 <td>
481 <select name="priority">
482 <option value="$PRIORITY">$PRIORITY</option>
483 <option value="standard">$(gettext "Standard")</option>
484 <option value="critical">$(gettext "Critical")</option>
485 </select>
486 <input type="submit" value="$(gettext 'Save configuration')" />
487 </td>
488 </tr>
489 </tbody>
490 </table>
491 </form>
493 </div>
494 EOT
495 }
497 save_bug() {
498 id="$(GET id)"
499 # bug.conf
500 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
501 # SliTaz Bug configuration
503 BUG="$(GETfiltered bug)"
504 STATUS="OPEN"
505 PRIORITY="$(GET priority)"
506 CREATOR="$(GET creator)"
507 DATE="$(GET date)"
508 PKGS="$(GETfiltered pkgs)"
509 EOT
510 # desc.txt
511 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
512 $(GETfiltered desc)
513 EOT
514 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
515 rm -f $bugdir/$id/*.tmp
516 }
518 # Close a fixed bug
519 close_bug() {
520 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
521 }
523 # Re open an old bug
524 open_bug() {
525 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
526 }
528 # Get and display Gravatar image: get_gravatar email size
529 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
530 get_gravatar() {
531 email=$1
532 size=$2
533 [ "$size" ] || size=48
534 url="http://www.gravatar.com/avatar"
535 md5=$(md5crypt $email)
536 echo "<img src=\"$url/$md5?d=identicon&amp;s=$size\" alt=\"\" />"
537 }
539 # Create a new user in AUTH_FILE and PEOPLE
540 new_user_config() {
541 if [ ! "$online" ]; then
542 name="$(GET name)"
543 mail="$(GET mail)"
544 pass="$(GET pass)"
545 echo "Creating Server Key..."
546 fi
547 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
548 echo "$user:$pass" >> $AUTH_FILE
549 mkdir -pm0700 $PEOPLE/$user/
550 cat > $PEOPLE/$user/account.conf << EOT
551 # SliTaz user configuration
552 #
554 NAME="$name"
555 USER="$user"
556 MAIL="$mail"
557 KEY="$key"
559 LOCATION="$(GET location)"
560 RELEASES="$(GET releases)"
561 PACKAGES="$(GET packages)"
562 EOT
563 chmod 0600 $PEOPLE/$user/account.conf
564 if [ ! -f $PEOPLE/$user/account.conf ]; then
565 echo "ERROR: User creation failed!"
566 fi
567 }
569 ########################################################################
570 # POST actions #
571 ########################################################################
573 case " $(POST) " in
574 *\ auth\ *)
575 header
576 html_header
577 # Authenticate user. Create a session file in $sessions to be used
578 # by check_auth. We have the user login name and a peer session
579 # md5 string in the COOKIE.
580 user="$(POST auth)"
581 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
583 IDLOC=""
584 if [[ "$(POST id)" ]] ;then
585 IDLOC="&id=$(POST id)"
586 fi
588 if [ ! -f $AUTH_FILE ] ; then
589 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
590 js_redirection_to "$script?login$IDLOC"
591 fi;
593 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
594 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
595 if [[ "$(POST id)" ]] ;then
596 IDLOC="?id=$(POST id)"
597 fi
598 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
599 mkdir -p $sessions
600 # Log last login
601 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
602 echo "$md5session" > $sessions/$user
603 js_set_cookie 'auth' "$user:$md5session"
604 js_log "Login authentication has been executed & accepted :)"
605 js_redirection_to "$script$IDLOC"
606 else
607 js_log "Login authentication has been executed & refused"
608 js_redirection_to "$script?login&error$IDLOC"
609 fi
610 html_footer ;;
611 *\ signup\ *)
612 # POST action for online signup
613 name="$(POST name)"
614 user="$(POST user)"
615 mail="$(POST mail)"
616 pass="$(md5crypt "$(POST pass)")"
617 if ! grep "^${user}:" $AUTH_FILE; then
618 online="yes"
619 new_user_config
620 header "Location: $SCRIPT_NAME?login"
621 else
622 header
623 html_header
624 user_box
625 echo "<h2>$(gettext "User already exists:") $user</h2>"
626 html_footer && exit 0
627 fi ;;
628 esac
630 #
631 # Plugins Now!
632 #
634 for p in $(ls -1 $plugins)
635 do
636 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
637 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
638 done
640 ########################################################################
641 # GET actions #
642 ########################################################################
644 case " $(GET) " in
645 *\ README\ *)
646 header
647 html_header
648 user_box
649 echo '<h2>README</h2>'
650 echo '<pre>'
651 if [ -f "README" ]; then
652 cat README
653 else
654 cat /usr/share/doc/tazbug/README
655 fi
656 echo '</pre>'
657 html_footer ;;
658 *\ closed\ *)
659 # Show all closed bugs.
660 header
661 html_header
662 user_box
663 list_bugs CLOSED
664 echo "</pre>"
665 html_footer ;;
666 *\ login\ *)
667 # The login page
668 [ "$(GET error)" ] && \
669 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
670 header
671 html_header
672 user_box
673 login_page
674 html_footer ;;
675 *\ logout\ *)
676 header
677 html_header
678 if check_auth; then
679 rm -f "$sessions/$user"
680 js_unset_cookie 'auth'
681 js_redirection_to "$script"
682 fi ;;
683 *\ user\ *)
684 # User profile
685 last="$(cat $PEOPLE/"$(GET user)"/last)"
686 header
687 html_header
688 user_box
689 . $PEOPLE/"$(GET user)"/account.conf
690 cat << EOT
691 <h2>$(get_gravatar $MAIL) $NAME</h2>
693 <pre>
694 $(gettext "User name :") $USER
695 $(gettext "Last login :") $last
696 EOT
697 if check_auth && [ "$(GET user)" == "$user" ]; then
698 auth_people
699 else
700 # check_auth will set VARS to current logged user: re-source
701 . $PEOPLE/"$(GET user)"/account.conf
702 public_people
703 fi
704 html_footer ;;
705 *\ newbug\ *)
706 # Create a bug from web interface.
707 header
708 html_header
709 user_box
710 if check_auth; then
711 new_bug_page
712 else
713 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
714 fi
715 html_footer ;;
716 *\ addbug\ *)
717 # Save a new bug from web interface.
718 header
719 html_header
720 if check_auth; then
721 new_bug
722 js_redirection_to "$script?id=$count"
723 fi ;;
724 *\ edit\ *)
725 # Edit existing bug
726 id="$(GET edit)"
727 header
728 html_header
729 user_box
730 edit_bug
731 html_footer ;;
732 *\ savebug\ *)
733 header
734 html_header
735 if check_auth; then
736 save_bug
737 js_redirection_to "$script?id=$id"
738 fi ;;
739 *\ id\ *)
740 # Empty deleted messages to keep msg count working.
741 header
742 html_header
743 id="$(GET id)"
744 [ "$(GET close)" ] && close_bug
745 [ "$(GET open)" ] && open_bug
746 [ "$(GET msg)" ] && new_msg
747 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
748 touch $bugdir/$id/msg.$(GET delmsg)
749 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
750 user_box
751 . $bugdir/$id/bug.conf
752 bug_page
753 html_footer ;;
754 *\ signup\ *)
755 # Signup
756 if [ "$(GET online)" ];then
757 header
758 html_header
759 user_box
760 echo "<h2>$(gettext "Sign Up")</h2>"
761 if [ "$ONLINE_SIGNUP" == "yes" ]; then
762 signup_page
763 else
764 gettext "Online registration is disabled"
765 fi
766 html_footer && exit 0
767 else
768 header "Content-type: text/plain;"
769 user="$(GET signup)"
770 echo "Requested user login : $user"
771 if fgrep -q "$user:" $AUTH_FILE; then
772 echo "ERROR: User already exists" && exit 1
773 else
774 echo "Creating account for : $(GET name)"
775 new_user_config
776 fi
777 fi ;;
778 *\ key\ *)
779 # Let user post new bug or message with crypted key (no gettext)
780 #
781 # Testing only and is security acceptable ?
782 #
783 key="$(GET key)"
784 id="$(GET bug)"
785 header "Content-type: text/plain;"
786 echo "Checking secure key..."
787 if fgrep -qH $key $PEOPLE/*/account.conf; then
788 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
789 . $conf
790 echo "Authenticated: $NAME ($USER)"
791 case " $(GET) " in
792 *\ msg\ *)
793 [ ! "$id" ] && echo "Missing bug ID" && exit 0
794 echo "Posting new message to bug: $id"
795 echo "Message: $(GET msg)"
796 new_msg ;;
797 *\ bug\ *)
798 echo "Adding new bug: $(GET bug)"
799 echo "Description: $(GET desc)"
800 new_bug ;;
801 esac
802 else
803 echo "Not a valid SliTaz user key"
804 exit 0
805 fi ;;
806 *\ search\ *)
807 found=0
808 header
809 html_header
810 user_box
811 cat << EOT
812 <h2>$(gettext "Search")</h2>
813 <form method="get" action="$script">
814 <input type="text" name="search" />
815 <input type="submit" value="$(gettext 'Search')" />
816 </form>
817 <div>
818 EOT
819 cd $bugdir
820 for bug in *
821 do
822 result=$(fgrep -i -h "$(GET search)" $bug/*)
823 if [ "$result" ]; then
824 found=$(($found + 1))
825 id=${bug}
826 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
827 echo '<pre>'
828 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
829 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
830 echo '</pre>'
831 fi
832 done
833 if [ "$found" == "0" ]; then
834 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
835 else
836 echo "<p> $found $(gettext 'results found')</p>"
837 fi
838 echo '</div>'
839 html_footer ;;
840 *)
841 # Default page.
842 bugs=$(ls -1 $bugdir | wc -l)
843 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
844 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
845 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
846 pct=0
847 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
848 header
849 html_header
850 user_box
852 cat << EOT
854 <h2>$(gettext "Summary")</h2>
856 <p>
857 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
858 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
859 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
860 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
861 </p>
863 <div class="pctbar">
864 <div class="pct" style="width: ${pct}%;">${pct}%</div>
865 </div>
867 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
868 more information. You may also be interested by the SliTaz \
869 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
870 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
871 enter your term and press ENTER.")
872 </p>
874 <div id="tools">
875 $BUGS_TOOLS
876 <a href="?closed">$(gettext 'View closed bugs')</a>
877 EOT
878 if check_auth; then
879 echo "<a href='?newbug'>$(gettext 'Create a new bug')</a>"
880 echo "$PLUGINS_TOOLS"
881 fi
882 cat << EOT
883 </div>
885 <h3>$(gettext "Latest Bugs")</h3>
886 EOT
887 # List last 3 bugs
888 echo "<pre>"
889 for lb in $(ls ${bugdir} | sort -r -n | head -n 3)
890 do
891 list_bug ${lb}
892 done
893 echo "</pre>"
894 list_bugs OPEN
895 echo "</pre>"
896 html_footer ;;
897 esac
899 exit 0