tazbug annotate web/bugs.cgi @ rev 44

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