tazbug annotate web/bugs.cgi @ rev 9

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