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