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