tazbug annotate web/bugs.cgi @ rev 29

Add plugins support
author Christophe Lincoln <pankso@slitaz.org>
date Wed Apr 11 17:42:48 2012 +0200 (2012-04-11)
parents c308afab2f37
children ea58d117d71a
rev   line source
pankso@9 1 #!/bin/sh
pankso@9 2 #
pankso@9 3 # TazBug Web interface
pankso@9 4 #
pankso@9 5 # Copyright (C) 2012 SliTaz GNU/Linux - BSD License
pankso@9 6 #
pankso@9 7 . /usr/lib/slitaz/httphelper
pankso@9 8 [ -f "/etc/slitaz/tazbug.conf" ] && . /etc/slitaz/tazbug.conf
pankso@9 9 [ -f "../tazbug.conf" ] && . ../tazbug.conf
pankso@9 10
pankso@9 11 # Internal variable
pankso@9 12 bugdir="bug"
pankso@29 13 plugins="plugins"
pankso@9 14 sessions="/tmp/tazbug/sessions"
pankso@9 15
pankso@9 16 # Content negotiation for Gettext
pankso@9 17 IFS=","
pankso@9 18 for lang in $HTTP_ACCEPT_LANGUAGE
pankso@9 19 do
pankso@9 20 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
pankso@9 21 [ -d "$lang" ] && break
pankso@9 22 case "$lang" in
pankso@9 23 en) lang="C" ;;
pankso@9 24 fr) lang="fr_FR" ;;
pankso@23 25 ru) lang="ru_RU" ;;
pankso@9 26 esac
pankso@9 27 done
pankso@9 28 unset IFS
pankso@9 29 export LANG=$lang LC_ALL=$lang
pankso@9 30
pankso@9 31 # Internationalization: $(gettext "")
pankso@9 32 . /usr/bin/gettext.sh
pankso@9 33 TEXTDOMAIN='tazbug'
pankso@9 34 export TEXTDOMAIN
pankso@9 35
pankso@9 36 #
pankso@9 37 # Functions
pankso@9 38 #
pankso@9 39
pankso@9 40 # HTML 5 header.
pankso@9 41 html_header() {
pankso@9 42 cat lib/header.html
pankso@9 43 }
pankso@9 44
pankso@9 45 # HTML 5 footer.
pankso@9 46 html_footer() {
pankso@9 47 cat << EOT
pankso@9 48 </div>
pankso@9 49
pankso@9 50 <div id="footer">
pankso@9 51 <a href="./">SliTaz Bugs</a> -
pankso@9 52 <a href="./?README">README</a>
pankso@9 53 </div>
pankso@9 54
pankso@9 55 </body>
pankso@9 56 </html>
pankso@9 57 EOT
pankso@9 58 }
pankso@9 59
pankso@9 60 # Check if user is auth
pankso@9 61 check_auth() {
pankso@9 62 auth="$(COOKIE auth)"
pankso@9 63 user="$(echo $auth | cut -d ":" -f 1)"
pankso@9 64 md5cookie="$(echo $auth | cut -d ":" -f 2)"
pankso@9 65 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
pankso@9 66 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
pankso@9 67 return 0
pankso@9 68 else
pankso@9 69 return 1
pankso@9 70 fi
pankso@9 71 }
pankso@9 72
pankso@9 73 # Authentified or not
pankso@9 74 user_box() {
pankso@9 75 if check_auth; then
pankso@26 76 . $PEOPLE/$user/account.conf
pankso@9 77 cat << EOT
pankso@9 78 <div id="user">
pankso@24 79 <a href="?user=$user">$(get_gravatar $MAIL 20)</a>
pankso@9 80 <a href="?logout">Logout</a>
pankso@9 81 </div>
pankso@9 82 EOT
pankso@9 83 else
pankso@9 84 cat << EOT
pankso@9 85 <div id="user">
pankso@26 86 <a href="?login"><img src="images/avatar.png" alt="[ User ]" /></a>
pankso@9 87 <a href="?login">Login</a>
pankso@9 88 </div>
pankso@9 89 EOT
pankso@9 90 fi
pankso@9 91 cat << EOT
pankso@9 92
pankso@24 93 <div id="search">
pankso@24 94 <form method="get" action="./">
pankso@24 95 <input type="text" name="search" placeholder="$(gettext "Search")" />
pankso@24 96 <!-- <input type="submit" value="$(gettext "Search")" /> -->
pankso@24 97 </form>
pankso@24 98 </div>
pankso@24 99
pankso@9 100 <!-- Content -->
pankso@9 101 <div id="content">
pankso@9 102
pankso@9 103 EOT
pankso@9 104 }
pankso@9 105
pankso@9 106 # Login page
pankso@9 107 login_page() {
pankso@9 108 cat << EOT
pankso@9 109 <!-- Content -->
pankso@9 110 <div id="content">
pankso@9 111
pankso@9 112 <h2>$(gettext "Login")</h2>
pankso@9 113
pankso@9 114 <div id="account-info">
paul@18 115 $(gettext "No account yet? Please signup using the SliTaz Bugs reporter
paul@17 116 on your SliTaz system. <p>Tip: to attach big files or images, you can use
paul@17 117 SliTaz Paste services:") <a href="http://paste.slitaz.org/">paste.slitaz.org</a>
pankso@9 118 </p>
pankso@9 119 </div>
pankso@9 120
pankso@9 121 <div id="login">
pankso@9 122 <form method="post" action="$SCRIPT_NAME">
pankso@21 123 <input type="text" name="auth" placeholder="$(gettext "User name")" />
pankso@21 124 <input type="password" name="pass" placeholder="$(gettext "Password")" />
pankso@21 125 <div>
pankso@21 126 <input type="submit" value="Login" />
pankso@21 127 $error
pankso@21 128 </div>
pankso@9 129 </form>
pankso@9 130 </div>
pankso@9 131
pankso@9 132 <div style="clear: both;"></div>
pankso@9 133 EOT
pankso@9 134 }
pankso@9 135
pankso@9 136 # Display user public profile.
pankso@9 137 public_people() {
pankso@9 138 cat << EOT
pankso@9 139 <pre>
pankso@9 140 Real name : $NAME
pankso@9 141 </pre>
pankso@9 142 EOT
pankso@9 143 }
pankso@9 144
pankso@9 145 # Display authentified user profile. TODO: change password
pankso@9 146 auth_people() {
pankso@9 147 cat << EOT
pankso@9 148 <pre>
pankso@9 149 Real name : $NAME
pankso@9 150 Email : $MAIL
pankso@9 151 Secure key : $KEY
pankso@9 152 </pre>
pankso@9 153 EOT
pankso@9 154 }
pankso@9 155
pankso@9 156 # Usage: list_bugs STATUS
pankso@9 157 list_bugs() {
pankso@9 158 echo "<h3>$1 Bugs</h3>"
pankso@9 159 for pr in critical standard
pankso@9 160 do
pankso@9 161 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
pankso@9 162 do
pankso@9 163 . $bug
pankso@9 164 id=$(dirname $bug | cut -d "/" -f 2)
pankso@9 165 if [ "$PRIORITY" == "$pr" ]; then
pankso@9 166 cat << EOT
pankso@9 167 <pre>
pankso@21 168 Bug title : <strong>$BUG</strong> <a href="?id=$id">Show</a>
pankso@9 169 ID - Date : $id - $DATE
pankso@21 170 Creator : <a href="?user=$CREATOR">$CREATOR</a>
pankso@9 171 </pre>
pankso@9 172 EOT
pankso@9 173 fi
pankso@9 174 done
pankso@9 175 done
pankso@9 176 }
pankso@9 177
paul@17 178 # Stripped down Wiki parser for bug desc and messages which are simply
paul@17 179 # displayed in <pre>
pankso@9 180 wiki_parser() {
pankso@9 181 sed \
pankso@9 182 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
pankso@9 183 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g
pankso@9 184 }
pankso@9 185
pankso@9 186 # Bug page
pankso@9 187 bug_page() {
pankso@26 188 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
pankso@26 189 . $PEOPLE/$CREATOR/account.conf
pankso@9 190 else
pankso@15 191 MAIL="default"
pankso@9 192 fi
pankso@9 193 cat << EOT
pankso@9 194 <h2>Bug $id</h2>
pankso@9 195 <form method="get" action="./">
pankso@9 196
pankso@9 197 <p>
pankso@9 198 $(get_gravatar $MAIL 32) <strong>$STATUS</strong> $BUG - $DATE - Priority $PRIORITY
pankso@9 199 - $msgs messages
pankso@9 200 </p>
pankso@9 201
pankso@9 202 <pre>
pankso@9 203 $(echo "$DESC" | wiki_parser)
pankso@9 204 </pre>
pankso@9 205
pankso@9 206 <div id="tools">
pankso@9 207 EOT
pankso@9 208 if check_auth; then
pankso@9 209 if [ "$STATUS" == "OPEN" ]; then
pankso@9 210 cat << EOT
pankso@9 211 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
pankso@9 212 <a href="?edit=$id">$(gettext "Edit bug")</a>
pankso@9 213 EOT
pankso@9 214 else
pankso@9 215 cat << EOT
pankso@9 216 <a href="?id=$id&amp;open">$(gettext "Re open bug")</a>
pankso@9 217 EOT
pankso@9 218 fi
pankso@9 219 fi
pankso@9 220 cat << EOT
pankso@9 221 </div>
pankso@9 222
pankso@9 223 <h3>$(gettext "Messages")</h3>
pankso@9 224 EOT
pankso@9 225 [ "$msgs" == "0" ] && gettext "No messages"
pankso@9 226 for msg in $(ls -1tr $bugdir/$id/msg.*)
pankso@9 227 do
pankso@9 228 . $msg
pankso@9 229 if [ "$MSG" ]; then
pankso@9 230 msgid=$(echo $msg | cut -d "." -f 2)
pankso@9 231 del=""
pankso@9 232 # User can delete his post.
pankso@9 233 [ "$user" == "$USER" ] && \
pankso@9 234 del="<a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
pankso@9 235 cat << EOT
pankso@9 236 <p><strong>$USER</strong> $DATE $del</p>
pankso@9 237 <pre>
pankso@9 238 $(echo "$MSG" | wiki_parser)
pankso@9 239 </pre>
pankso@9 240 EOT
pankso@9 241 fi
pankso@9 242 unset NAME DATE MSG
pankso@9 243 done
pankso@9 244 if check_auth; then
pankso@9 245 cat << EOT
pankso@9 246 <div>
pankso@9 247 <h3>$(gettext "New message")</h3>
pankso@9 248
pankso@9 249 <input type="hidden" name="id" value="$id" />
pankso@9 250 <textarea name="msg" rows="8"></textarea>
pankso@9 251 <p><input type="submit" value="$(gettext "Send message")" /></p>
pankso@9 252 </form>
pankso@9 253 </div>
pankso@9 254 EOT
pankso@9 255 fi
pankso@9 256 }
pankso@9 257
pankso@9 258 # Write a new message
pankso@9 259 new_msg() {
pankso@9 260 date=$(date "+%Y-%m-%d %H:%M")
pankso@9 261 msgs=$(ls -1 $bugdir/$id/msg.* | wc -l)
pankso@9 262 count=$(($msgs + 1))
pankso@9 263 if check_auth; then
pankso@9 264 USER="$user"
pankso@9 265 fi
pankso@9 266 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count << EOT
pankso@9 267 USER="$USER"
pankso@9 268 DATE="$date"
pankso@9 269 MSG="$(GET msg)"
pankso@9 270 EOT
pankso@9 271 }
pankso@9 272
pankso@9 273 # Create a new Bug
pankso@9 274 new_bug() {
pankso@9 275 count=$(ls -1 $bugdir | wc -l)
pankso@9 276 date=$(date "+%Y-%m-%d %H:%M")
pankso@9 277 # Sanity check, JS may be disabled.
pankso@9 278 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
pankso@9 279 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
pankso@9 280 if check_auth; then
pankso@9 281 USER="$user"
pankso@9 282 fi
pankso@9 283 mkdir -p $bugdir/$count
pankso@9 284 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
pankso@9 285 # SliTaz Bug configuration
pankso@9 286
pankso@9 287 BUG="$(GET bug)"
pankso@9 288 STATUS="OPEN"
pankso@9 289 PRIORITY="$(GET priority)"
pankso@9 290 CREATOR="$USER"
pankso@9 291 DATE="$date"
pankso@9 292 PKGS="$(GET pkgs)"
pankso@9 293
pankso@9 294 DESC="$(GET desc)"
pankso@9 295 EOT
pankso@9 296 }
pankso@9 297
pankso@9 298 # New bug page for the web interface
pankso@9 299 new_bug_page() {
pankso@9 300 cat << EOT
pankso@9 301 <h2>$(gettext "New Bug")</h2>
pankso@9 302 <div id="newbug">
pankso@9 303
pankso@9 304 <form method="get" action="./" onsubmit="return checkNewBug();">
pankso@9 305 <input type="hidden" name="addbug" />
pankso@9 306 <table>
pankso@9 307 <tbody>
pankso@9 308 <tr>
pankso@9 309 <td>$(gettext "Bug title")*</td>
pankso@9 310 <td><input type="text" name="bug" /></td>
pankso@9 311 </tr>
pankso@9 312 <tr>
pankso@9 313 <td>$(gettext "Description")*</td>
pankso@9 314 <td><textarea name="desc"></textarea></td>
pankso@9 315 </tr>
pankso@9 316 <tr>
pankso@9 317 <td>$(gettext "Packages")</td>
pankso@9 318 <td><input type="text" name="pkgs" /></td>
pankso@9 319 </tr>
pankso@9 320 <tr>
pankso@9 321 <td>$(gettext "Priority")</td>
pankso@9 322 <td>
pankso@9 323 <select name="priority">
pankso@9 324 <option value="standard">$(gettext "Standard")</option>
pankso@9 325 <option value="critical">$(gettext "Critical")</option>
pankso@9 326 </select>
pankso@9 327 <input type="submit" value="$(gettext "Create Bug")" />
pankso@9 328 </td>
pankso@9 329 </tr>
pankso@9 330 </tbody>
pankso@9 331 </table>
pankso@9 332 </form>
pankso@9 333
pankso@9 334 <p>
al@19 335 $(gettext "* field is obligatory. You can also specify affected packages.")
pankso@9 336 </p>
pankso@9 337
pankso@9 338 </div>
pankso@9 339 EOT
pankso@9 340 }
pankso@9 341
pankso@9 342 # Edit/Save a bug configuration file
pankso@9 343 edit_bug() {
pankso@9 344 cat << EOT
pankso@9 345 <h2>$(gettext "Edit Bug $bug")</h2>
pankso@9 346 <div id="edit">
pankso@9 347
pankso@9 348 <form method="get" action="./">
pankso@9 349 <textarea name="bugconf">$(cat $bugdir/$bug/bug.conf)</textarea>
pankso@9 350 <input type="hidden" name="bug" value="$bug" />
pankso@9 351 <input type="submit" value="$(gettext "Save configuration")" />
pankso@9 352 </form>
pankso@9 353
pankso@9 354 </div>
pankso@9 355 EOT
pankso@9 356 }
pankso@9 357
pankso@9 358 save_bug() {
pankso@9 359 bug="$(GET bug)"
pankso@9 360 content="$(GET bugconf)"
pankso@9 361 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$bug/bug.conf << EOT
pankso@9 362 $content
pankso@9 363 EOT
pankso@9 364 }
pankso@9 365
pankso@9 366 # Close a fixed bug
pankso@9 367 close_bug() {
pankso@9 368 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
pankso@9 369 }
pankso@9 370
pankso@9 371 # Re open an old bug
pankso@9 372 open_bug() {
pankso@9 373 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
pankso@9 374 }
pankso@9 375
pankso@9 376 # Get and display Gravatar image: get_gravatar email size
pankso@9 377 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
pankso@9 378 get_gravatar() {
pankso@9 379 email=$1
pankso@9 380 size=$2
pankso@9 381 [ "$size" ] || size=48
pankso@9 382 url="http://www.gravatar.com/avatar"
pankso@29 383 md5=$(md5crypt $email)
pankso@9 384 echo "<img src='$url/$md5?d=identicon&s=$size' alt='' />"
pankso@9 385 }
pankso@9 386
pankso@21 387 # Create a new user in AUTH_FILE and PEOPLE
pankso@9 388 new_user_config() {
pankso@9 389 mail="$(GET mail)"
pankso@9 390 pass="$(GET pass)"
pankso@9 391 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
pankso@9 392 echo "$user:$pass" >> $AUTH_FILE
pankso@9 393 mkdir -p $PEOPLE/$user/
pankso@26 394 cat > $PEOPLE/$user/account.conf << EOT
pankso@9 395 # SliTaz user configuration
pankso@9 396 #
pankso@9 397
pankso@9 398 NAME="$(GET name)"
pankso@9 399 USER="$user"
pankso@9 400 MAIL="$mail"
pankso@9 401 KEY="$key"
pankso@9 402
pankso@9 403 COMMUNITY="$(GET scn)"
pankso@9 404 LOCATION="$(GET location)"
pankso@9 405 RELEASES="$(GET releases)"
pankso@9 406 PACKAGES="$(GET packages)"
pankso@9 407 EOT
pankso@26 408 chmod 0600 $PEOPLE/$user/account.conf
pankso@9 409 }
pankso@9 410
pankso@9 411 #
pankso@9 412 # POST actions
pankso@9 413 #
pankso@9 414
pankso@9 415 case " $(POST) " in
pankso@9 416 *\ auth\ *)
pankso@9 417 # Authenticate user. Create a session file in $sessions to be used
pankso@9 418 # by check_auth. We have the user login name and a peer session
pankso@9 419 # md5 string in the COOKIE.
pankso@9 420 user="$(POST auth)"
pankso@29 421 pass="$(md5crypt "$(POST pass)")"
pankso@9 422 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
pankso@9 423 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
pankso@9 424 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
pankso@9 425 mkdir -p $sessions
pankso@9 426 echo "$md5session" > $sessions/$user
pankso@9 427 header "Location: $WEB_URL" \
pankso@9 428 "Set-Cookie: auth=$user:$md5session; HttpOnly"
pankso@9 429 else
pankso@9 430 header "Location: $WEB_URL?login&error"
pankso@9 431 fi ;;
pankso@9 432 esac
pankso@9 433
pankso@9 434 #
pankso@29 435 # Plugins
pankso@29 436 #
pankso@29 437 for p in $(ls -1 $plugins)
pankso@29 438 do
pankso@29 439 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
pankso@29 440 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
pankso@29 441 done
pankso@29 442
pankso@29 443 #
pankso@9 444 # GET actions
pankso@9 445 #
pankso@9 446
pankso@9 447 case " $(GET) " in
pankso@9 448 *\ README\ *)
pankso@9 449 header
pankso@9 450 html_header
pankso@9 451 user_box
pankso@9 452 echo '<h2>README</h2>'
pankso@9 453 echo '<pre>'
pankso@9 454 cat /usr/share/doc/tazbug/README
pankso@9 455 echo '</pre>'
pankso@9 456 html_footer ;;
pankso@9 457 *\ closed\ *)
pankso@9 458 # Show all closed bugs.
pankso@9 459 header
pankso@9 460 html_header
pankso@9 461 user_box
pankso@9 462 list_bugs CLOSED
pankso@9 463 html_footer ;;
pankso@9 464 *\ login\ *)
pankso@9 465 # The login page
pankso@9 466 [ "$(GET error)" ] && \
pankso@9 467 error="<span class="error">$(gettext "Bad login or pass")</span>"
pankso@9 468 header
pankso@9 469 html_header
pankso@21 470 user_box
pankso@9 471 login_page
pankso@9 472 html_footer ;;
pankso@9 473 *\ logout\ *)
pankso@9 474 # Set a Cookie in the past to logout.
pankso@9 475 expires="Expires=Wed, 01-Jan-1980 00:00:00 GMT"
pankso@9 476 if check_auth; then
pankso@9 477 rm -f "$sessions/$user"
pankso@9 478 header "Location: $WEB_URL" "Set-Cookie: auth=none; $expires; HttpOnly"
pankso@9 479 fi ;;
pankso@9 480 *\ user\ *)
pankso@9 481 # User profile
pankso@9 482 header
pankso@9 483 html_header
pankso@9 484 user_box
pankso@26 485 . $PEOPLE/"$(GET user)"/account.conf
pankso@9 486 echo "<h2>$(get_gravatar $MAIL) $(GET user)</h2>"
pankso@9 487 if check_auth && [ "$(GET user)" == "$user" ]; then
pankso@9 488 auth_people
pankso@9 489 else
pankso@9 490 public_people
pankso@9 491 fi
pankso@9 492 html_footer ;;
pankso@9 493 *\ newbug\ *)
pankso@9 494 # Add a bug from web interface.
pankso@9 495 header
pankso@9 496 html_header
pankso@9 497 user_box
pankso@9 498 if check_auth; then
pankso@9 499 new_bug_page
pankso@9 500 else
paul@17 501 echo "<p>$(gettext "You must be logged in to post a new bug")</p>"
pankso@9 502 fi
pankso@9 503 html_footer ;;
pankso@9 504 *\ addbug\ *)
pankso@9 505 # Add a bug from web interface.
pankso@9 506 if check_auth; then
pankso@9 507 new_bug
pankso@9 508 header "Location: $WEB_URL?id=$count"
pankso@9 509 fi ;;
pankso@9 510 *\ edit\ *)
pankso@9 511 bug="$(GET edit)"
pankso@9 512 header
pankso@9 513 html_header
pankso@9 514 user_box
pankso@9 515 edit_bug
pankso@9 516 html_footer ;;
pankso@9 517 *\ bugconf\ *)
pankso@9 518 if check_auth; then
pankso@9 519 save_bug
pankso@9 520 header "Location: $WEB_URL?id=$bug"
pankso@9 521 fi ;;
pankso@9 522 *\ id\ *)
pankso@9 523 # Empty deleted messages to keep msg count working.
pankso@9 524 id="$(GET id)"
pankso@9 525 [ "$(GET close)" ] && close_bug
pankso@9 526 [ "$(GET open)" ] && open_bug
pankso@9 527 [ "$(GET msg)" ] && new_msg
pankso@9 528 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg) && \
pankso@9 529 touch $bugdir/$id/msg.$(GET delmsg)
pankso@9 530 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
pankso@9 531 header
pankso@9 532 html_header
pankso@9 533 user_box
pankso@9 534 . $bugdir/$id/bug.conf
pankso@9 535 bug_page
pankso@9 536 html_footer ;;
pankso@9 537 *\ signup\ *)
pankso@9 538 # Signup
pankso@9 539 header "Content-type: text/plain;"
pankso@9 540 user="$(GET signup)"
pankso@9 541 echo "Requested user login : $user"
pankso@9 542 if fgrep -q "$user:" $AUTH_FILE; then
paul@17 543 echo "ERROR: User already exists" && exit 1
pankso@9 544 else
pankso@9 545 echo "Creating account for : $(GET name)"
pankso@9 546 new_user_config
pankso@9 547 fi ;;
pankso@9 548 *\ key\ *)
pankso@9 549 # Let user post new bug or message with crypted key (no gettext)
pankso@9 550 #
pankso@9 551 # Testing only and is security acceptable ?
pankso@9 552 #
pankso@9 553 key="$(GET key)"
pankso@9 554 id="$(GET bug)"
pankso@9 555 header "Content-type: text/plain;"
pankso@9 556 echo "Checking secure key..."
pankso@26 557 if fgrep -qH $key $PEOPLE/*/account.conf; then
pankso@26 558 conf=$(fgrep -H $key $PEOPLE/*/account.conf | cut -d ":" -f 1)
pankso@9 559 . $conf
pankso@9 560 echo "Authentified: $NAME ($USER)"
pankso@9 561 case " $(GET) " in
pankso@9 562 *\ msg\ *)
pankso@9 563 [ ! "$id" ] && echo "Missing bug ID" && exit 0
pankso@9 564 echo "Posting new message to bug: $id"
pankso@9 565 echo "Message: $(GET msg)"
pankso@9 566 new_msg ;;
pankso@9 567 *\ bug\ *)
pankso@9 568 echo "Adding new bug: $(GET bug)"
pankso@9 569 echo "Description: $(GET desc)"
pankso@9 570 new_bug ;;
pankso@9 571 esac
pankso@9 572 else
pankso@9 573 echo "Not a valid SliTaz user key"
pankso@9 574 exit 0
pankso@9 575 fi ;;
pankso@9 576 *\ search\ *)
pankso@9 577 header
pankso@9 578 html_header
pankso@9 579 user_box
pankso@9 580 cat << EOT
pankso@9 581 <h2>$(gettext "Search")</h2>
pankso@9 582 <form method="get" action="./">
pankso@9 583 <input type="text" name="search" />
pankso@9 584 <input type="submit" value="$(gettext "Search")" />
pankso@9 585 </form>
pankso@21 586 <div>
pankso@9 587 EOT
pankso@21 588
pankso@21 589 #found=0 JS to notify or write results nb under the search box.
pankso@21 590 for bug in $bugdir/*
pankso@9 591 do
pankso@21 592 result=$(fgrep -i "$(GET search)" $bug/*)
pankso@21 593 if [ "$result" ]; then
pankso@21 594 #found=$(($found + 1))
pankso@21 595 id=${bug#bug/}
pankso@21 596 echo "<p><strong>Bug $id</strong> <a href='?id=$id'>$(gettext "Show")</a></p>"
pankso@21 597 echo '<pre>'
pankso@21 598 fgrep -i "$(GET search)" $bugdir/$id/* | \
pankso@21 599 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
pankso@21 600 echo '</pre>'
pankso@21 601 else
pankso@21 602 gettext "<p>No result found for:"; echo " $(GET search)</p>"
pankso@21 603 fi
pankso@9 604 done
pankso@21 605 echo '</div>'
pankso@9 606 html_footer ;;
pankso@9 607 *)
pankso@9 608 # Default page.
pankso@9 609 bugs=$(ls -1 $bugdir | wc -l)
pankso@9 610 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
pankso@9 611 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
pankso@9 612 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
pankso@9 613 pct=0
pankso@9 614 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
pankso@9 615 header
pankso@9 616 html_header
pankso@9 617 user_box
pankso@9 618 cat << EOT
pankso@9 619
pankso@9 620 <h2>$(gettext "Summary")</h2>
pankso@9 621
pankso@9 622 <p>
pankso@9 623 Bugs: $bugs in total - $close fixed - $fixme to fix - $msgs messages
pankso@9 624 </p>
pankso@9 625
pankso@9 626 <div class="pctbar">
pankso@9 627 <div class="pct" style="width: ${pct}%;">${pct}%</div>
pankso@9 628 </div>
pankso@9 629
pankso@9 630 <p>
pankso@24 631 Please read the <a href="?README">README</a> for help and more
pankso@24 632 information. You may also be interested by the SliTaz
pankso@24 633 <a href="http://roadmap.slitaz.org/">Roadmap</a> and the packages
pankso@24 634 <a href="http://cook.slitaz.org/">Cooker</a>. To perform a search
pankso@24 635 enter your term and press ENTER.
pankso@9 636 </p>
pankso@9 637
pankso@9 638 <div id="tools">
pankso@9 639 <a href="?closed">View closed bugs</a>
pankso@9 640 EOT
pankso@9 641 if check_auth; then
pankso@9 642 echo "<a href='?newbug'>$(gettext "Create a new bug")</a>"
pankso@9 643 fi
pankso@9 644 cat << EOT
pankso@9 645 </div>
pankso@9 646 EOT
pankso@9 647 list_bugs OPEN
pankso@9 648 html_footer ;;
pankso@9 649 esac
pankso@9 650
pankso@9 651 exit 0