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