tazbug annotate web/bugs.cgi @ rev 138

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