tazbug annotate web/bugs.cgi @ rev 133

Get page generation time and back to fgrep for admin_user (faster) since httphelper.sh is now up-to-date on Tank
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 21 17:29:18 2017 +0100 (2017-02-21)
parents 2499947037cf
children b5f62d54152e
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@133 118 fgrep -w -q "$user" ${ADMIN_USERS}
pankso@49 119 }
xfred222@34 120
paul@78 121 # Authenticated or not
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@48 134 <a href="?logout">$(gettext '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@69 141 <a href="?login$IDLOC">$(gettext '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@55 219 # Usage: list_bug ID
pankso@55 220 list_bug() {
pankso@55 221 id="$1"
pankso@55 222 . ${bugdir}/${id}/bug.conf
pankso@55 223 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
pankso@81 224 . ${PEOPLE}/${CREATOR}/account.conf
pankso@55 225 cat << EOT
pankso@55 226 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
pankso@106 227 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
pankso@55 228 EOT
pankso@55 229 unset CREATOR USER MAIL
pankso@55 230 }
pankso@55 231
pankso@9 232 # Usage: list_bugs STATUS
pankso@9 233 list_bugs() {
pankso@55 234 status="$1"
pankso@55 235 echo "<h3>$(eval_gettext '$status Bugs')</h3>"
pankso@51 236 echo "<pre>"
pankso@9 237 for pr in critical standard
pankso@9 238 do
pankso@9 239 for bug in $(fgrep -H "$1" $bugdir/*/bug.conf | cut -d ":" -f 1)
pankso@9 240 do
pankso@9 241 . $bug
xfred222@34 242 id=$(basename $(dirname $bug))
pankso@9 243 if [ "$PRIORITY" == "$pr" ]; then
pankso@51 244 [ -f "${PEOPLE}/${CREATOR}/account.conf" ] && \
pankso@51 245 . ${PEOPLE}/${CREATOR}/account.conf
pankso@9 246 cat << EOT
pankso@51 247 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
pankso@106 248 ID: $id <a href="?id=$id">$BUG</a> <span class="date">- $DATE</span>
pankso@9 249 EOT
pankso@9 250 fi
pankso@51 251 unset CREATOR USER MAIL
pankso@9 252 done
pankso@9 253 done
pankso@9 254 }
pankso@9 255
pankso@106 256 # Usage: list_msg path
pankso@106 257 list_msg() {
pankso@106 258 msg="$1"
pankso@106 259 dir=$(dirname $msg)
pankso@106 260 id=$(basename $dir)
pankso@106 261 . ${msg}
pankso@106 262 [ -f "${PEOPLE}/${USER}/account.conf" ] && \
pankso@107 263 . ${PEOPLE}/${USER}/account.conf
pankso@106 264 cat << EOT
pankso@106 265 <a href="?user=$USER">$(get_gravatar "$MAIL" 24)</a> \
pankso@108 266 ID: <a href="?id=$id">Bug $id</a> by $USER <span class="date">- $DATE</span>
pankso@106 267 EOT
pankso@106 268 unset CREATOR USER MAIL
pankso@106 269 }
pankso@106 270
paul@17 271 # Stripped down Wiki parser for bug desc and messages which are simply
paul@17 272 # displayed in <pre>
pankso@9 273 wiki_parser() {
pankso@9 274 sed \
pankso@9 275 -e s"#http://\([^']*\).png#<img src='\0' alt='[ Image ]' />#"g \
pascal@44 276 -e s"#http://\([^']*\).*# <a href='\0'>\1</a>#"g \
pankso@75 277 -e 's#\\\\n##g;s#%22#"#g;s#%21#!#g'
pankso@9 278 }
pankso@9 279
pankso@9 280 # Bug page
pankso@9 281 bug_page() {
pankso@26 282 if [ -f "$PEOPLE/$CREATOR/account.conf" ]; then
pankso@26 283 . $PEOPLE/$CREATOR/account.conf
pankso@9 284 else
pankso@15 285 MAIL="default"
pankso@9 286 fi
pankso@9 287 cat << EOT
pankso@51 288 <h2>$(eval_gettext 'Bug $id: $STATUS')</h2>
pankso@9 289
pankso@9 290 <p>
pankso@51 291 $(get_gravatar $MAIL 32) <strong>$BUG</strong>
pankso@51 292 </p>
pankso@51 293 <p>
pankso@51 294 $(gettext "Date:") $DATE -
pankso@106 295 $(gettext "Creator:") <a href="?user=$CREATOR">$CREATOR</a> -
al@31 296 $(eval_gettext 'Priority $PRIORITY') -
al@31 297 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
pankso@9 298 </p>
pankso@9 299
pankso@9 300 <pre>
pankso@98 301 $(cat $bugdir/$id/desc.txt | wiki_parser)
pankso@9 302 </pre>
pankso@9 303
pankso@9 304 <div id="tools">
pankso@9 305 EOT
pankso@9 306 if check_auth; then
pankso@9 307 if [ "$STATUS" == "OPEN" ]; then
pankso@30 308 cat << EOT
pankso@9 309 <a href="?id=$id&amp;close">$(gettext "Close bug")</a>
pankso@105 310 EOT
pankso@105 311 # Only original user and admin can edit a bug
pankso@105 312 if [ "$user" == "$CREATOR" ] || admin_user; then
pankso@105 313 cat << EOT
pankso@106 314 <a href="?editbug=$id">$(gettext "Edit bug")</a>
pankso@9 315 EOT
pankso@105 316 fi
pankso@9 317 else
pankso@9 318 cat << EOT
pankso@9 319 <a href="?id=$id&amp;open">$(gettext "Re open bug")</a>
pankso@9 320 EOT
pankso@9 321 fi
pankso@9 322 fi
pankso@9 323 cat << EOT
pankso@9 324 </div>
pankso@9 325
pankso@9 326 <h3>$(gettext "Messages")</h3>
pankso@9 327 EOT
pankso@9 328 [ "$msgs" == "0" ] && gettext "No messages"
pankso@9 329 for msg in $(ls -1tr $bugdir/$id/msg.*)
pankso@9 330 do
pankso@9 331 . $msg
pankso@9 332 if [ "$MSG" ]; then
pankso@9 333 msgid=$(echo $msg | cut -d "." -f 2)
pankso@9 334 del=""
paul@78 335 # User can delete his post as well as admin.
pankso@76 336 if [ "$user" == "$USER" ] || admin_user; then
pankso@9 337 del="<a href=\"?id=$id&amp;delmsg=$msgid\">delete</a>"
pankso@76 338 fi
pankso@9 339 cat << EOT
pankso@9 340 <p><strong>$USER</strong> $DATE $del</p>
pankso@9 341 <pre>
pankso@9 342 $(echo "$MSG" | wiki_parser)
pankso@9 343 </pre>
pankso@9 344 EOT
pankso@9 345 fi
pankso@130 346 unset USER DATE MSG
pankso@9 347 done
pankso@9 348 if check_auth; then
pankso@9 349 cat << EOT
pankso@9 350 <div>
pankso@9 351 <h3>$(gettext "New message")</h3>
pankso@75 352 <form method="get" action="$script">
pankso@9 353 <input type="hidden" name="id" value="$id" />
pankso@9 354 <textarea name="msg" rows="8"></textarea>
al@31 355 <p><input type="submit" value="$(gettext 'Send message')" /></p>
pankso@9 356 </form>
pankso@9 357 </div>
pankso@9 358 EOT
pankso@9 359 fi
pankso@9 360 }
pankso@9 361
pankso@9 362 # Write a new message
pankso@9 363 new_msg() {
pankso@9 364 date=$(date "+%Y-%m-%d %H:%M")
pankso@132 365 msgs=$(ls -1 $bugdir/$id/msg.* | cut -d "." -f 2 | sort -n | tail -n 1)
pankso@9 366 count=$(($msgs + 1))
pankso@9 367 if check_auth; then
pankso@9 368 USER="$user"
pankso@9 369 fi
xfred222@34 370 js_log "Will write message in $bugdir/$id/msg.$count "
pankso@75 371 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/msg.$count.tmp << EOT
pascal@39 372 USER="$USER"
pankso@9 373 DATE="$date"
pascal@39 374 MSG="$(GETfiltered msg)"
pankso@9 375 EOT
pankso@75 376 fold -s -w 80 $bugdir/$id/msg.$count.tmp > $bugdir/$id/msg.$count
pankso@75 377 rm -f $bugdir/$id/msg.$count.tmp
pankso@9 378 }
pankso@9 379
pankso@96 380 # Create a new Bug. ID is set by counting dirs in bug/ + 1
pankso@9 381 new_bug() {
pankso@96 382 count=$(ls $bugdir | sort -g | tail -n 1)
pankso@96 383 count=$(($count +1))
pankso@9 384 date=$(date "+%Y-%m-%d %H:%M")
pankso@9 385 # Sanity check, JS may be disabled.
pankso@9 386 [ ! "$(GET bug)" ] && echo "Missing bug title" && exit 1
pankso@9 387 [ ! "$(GET desc)" ] && echo "Missing bug description" && exit 1
pankso@9 388 if check_auth; then
pankso@9 389 USER="$user"
pankso@9 390 fi
pankso@9 391 mkdir -p $bugdir/$count
pankso@98 392 # bug.conf
pankso@98 393 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/bug.conf << EOT
pankso@9 394 # SliTaz Bug configuration
pankso@9 395
pascal@39 396 BUG="$(GETfiltered bug)"
pankso@9 397 STATUS="OPEN"
pankso@9 398 PRIORITY="$(GET priority)"
pankso@9 399 CREATOR="$USER"
pankso@9 400 DATE="$date"
pascal@39 401 PKGS="$(GETfiltered pkgs)"
pankso@9 402 EOT
pankso@98 403 # desc.txt
pankso@98 404 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$count/desc.tmp << EOT
pankso@98 405 $(GETfiltered desc)
pankso@98 406 EOT
pankso@98 407 fold -s -w 80 $bugdir/$count/desc.tmp > $bugdir/$count/desc.txt
pankso@98 408 rm -f $bugdir/$count/*.tmp
pankso@9 409 }
pankso@9 410
pankso@9 411 # New bug page for the web interface
pankso@9 412 new_bug_page() {
pankso@9 413 cat << EOT
pankso@9 414 <h2>$(gettext "New Bug")</h2>
pankso@9 415 <div id="newbug">
pankso@9 416
pankso@53 417 <form method="get" action="$script" onsubmit="return checkNewBug();">
pankso@9 418 <input type="hidden" name="addbug" />
pankso@9 419 <table>
pankso@9 420 <tbody>
pankso@9 421 <tr>
pankso@9 422 <td>$(gettext "Bug title")*</td>
pankso@9 423 <td><input type="text" name="bug" /></td>
pankso@9 424 </tr>
pankso@9 425 <tr>
pankso@9 426 <td>$(gettext "Description")*</td>
pankso@9 427 <td><textarea name="desc"></textarea></td>
pankso@9 428 </tr>
pankso@9 429 <tr>
pankso@9 430 <td>$(gettext "Packages")</td>
pankso@9 431 <td><input type="text" name="pkgs" /></td>
pankso@9 432 </tr>
pankso@9 433 <tr>
pankso@9 434 <td>$(gettext "Priority")</td>
pankso@9 435 <td>
pankso@9 436 <select name="priority">
pankso@9 437 <option value="standard">$(gettext "Standard")</option>
pankso@9 438 <option value="critical">$(gettext "Critical")</option>
pankso@9 439 </select>
pankso@9 440 <input type="submit" value="$(gettext "Create Bug")" />
pankso@9 441 </td>
pankso@9 442 </tr>
pankso@9 443 </tbody>
pankso@9 444 </table>
pankso@9 445 </form>
pankso@9 446
pankso@9 447 <p>
al@19 448 $(gettext "* field is obligatory. You can also specify affected packages.")
pankso@9 449 </p>
pankso@9 450
pankso@9 451 </div>
pankso@9 452 EOT
pankso@9 453 }
pankso@9 454
pankso@98 455 # Edit/Save a bug
pankso@9 456 edit_bug() {
pankso@98 457 . $bugdir/$id/bug.conf
pankso@105 458 if admin_user || [ "$user" == "$CREATOR" ]; then
pankso@105 459 continue
pankso@105 460 else
paul@115 461 gettext "You can't edit someone else's bug!" && exit 0
pankso@105 462 fi
pankso@9 463 cat << EOT
al@31 464 <h2>$(eval_gettext 'Edit Bug $bug')</h2>
pankso@106 465 <div id="editbug">
pankso@9 466
pankso@53 467 <form method="get" action="$script">
pankso@98 468 <input type="hidden" name="savebug" />
pankso@98 469 <input type="hidden" name="id" value="$id" />
pankso@98 470 <input type="hidden" name="creator" value="$CREATOR" />
pankso@98 471 <input type="hidden" name="date" value="$DATE" />
pankso@98 472 <table>
pankso@98 473 <tbody>
pankso@98 474 <tr>
pankso@98 475 <td>$(gettext "Bug title")</td>
pankso@98 476 <td><input type="text" name="bug" value="$BUG" /></td>
pankso@98 477 </tr>
pankso@98 478 <tr>
pankso@98 479 <td>$(gettext "Description")</td>
pankso@98 480 <td><textarea name="desc">$(cat $bugdir/$id/desc.txt)</textarea></td>
pankso@98 481 </tr>
pankso@98 482 <tr>
pankso@98 483 <td>$(gettext "Packages")</td>
pankso@98 484 <td><input type="text" name="pkgs" value="$PKGS" /></td>
pankso@98 485 </tr>
pankso@98 486 <tr>
pankso@98 487 <td>$(gettext "Priority")</td>
pankso@98 488 <td>
pankso@98 489 <select name="priority">
pankso@98 490 <option value="$PRIORITY">$PRIORITY</option>
pankso@98 491 <option value="standard">$(gettext "Standard")</option>
pankso@98 492 <option value="critical">$(gettext "Critical")</option>
pankso@98 493 </select>
pankso@98 494 <input type="submit" value="$(gettext 'Save configuration')" />
pankso@98 495 </td>
pankso@98 496 </tr>
pankso@98 497 </tbody>
pankso@98 498 </table>
pankso@9 499 </form>
pankso@9 500
pankso@9 501 </div>
pankso@9 502 EOT
pankso@9 503 }
pankso@9 504
pankso@9 505 save_bug() {
pankso@98 506 id="$(GET id)"
pankso@98 507 # bug.conf
pankso@98 508 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/bug.conf << EOT
pankso@98 509 # SliTaz Bug configuration
pankso@98 510
pankso@98 511 BUG="$(GETfiltered bug)"
pankso@98 512 STATUS="OPEN"
pankso@98 513 PRIORITY="$(GET priority)"
pankso@98 514 CREATOR="$(GET creator)"
pankso@98 515 DATE="$(GET date)"
pankso@98 516 PKGS="$(GETfiltered pkgs)"
pankso@9 517 EOT
pankso@98 518 # desc.txt
pankso@98 519 sed "s/$(echo -en '\r') /\n/g" > $bugdir/$id/desc.tmp << EOT
pankso@98 520 $(GETfiltered desc)
pankso@98 521 EOT
pankso@98 522 fold -s -w 80 $bugdir/$id/desc.tmp > $bugdir/$id/desc.txt
pankso@98 523 rm -f $bugdir/$id/*.tmp
pankso@9 524 }
pankso@9 525
pankso@9 526 # Close a fixed bug
pankso@9 527 close_bug() {
pankso@9 528 sed -i s'/OPEN/CLOSED/' $bugdir/$id/bug.conf
pankso@9 529 }
pankso@9 530
pankso@9 531 # Re open an old bug
pankso@9 532 open_bug() {
pankso@9 533 sed -i s'/CLOSED/OPEN/' $bugdir/$id/bug.conf
pankso@9 534 }
pankso@9 535
pankso@9 536 # Get and display Gravatar image: get_gravatar email size
pankso@9 537 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
pankso@9 538 get_gravatar() {
pankso@9 539 email=$1
pankso@9 540 size=$2
pankso@9 541 [ "$size" ] || size=48
pankso@9 542 url="http://www.gravatar.com/avatar"
pankso@29 543 md5=$(md5crypt $email)
al@31 544 echo "<img src=\"$url/$md5?d=identicon&amp;s=$size\" alt=\"\" />"
pankso@9 545 }
pankso@9 546
pankso@21 547 # Create a new user in AUTH_FILE and PEOPLE
pankso@9 548 new_user_config() {
pankso@123 549 if [ ! -f "$AUTH_FILE" ]; then
pankso@123 550 touch $AUTH_FILE && chmod 0600 $AUTH_FILE
pankso@48 551 fi
pankso@9 552 echo "$user:$pass" >> $AUTH_FILE
pankso@123 553 mkdir -pm0700 $PEOPLE/${user}
pankso@26 554 cat > $PEOPLE/$user/account.conf << EOT
pankso@123 555 # User configuration
pankso@48 556 NAME="$name"
pankso@9 557 USER="$user"
pankso@9 558 MAIL="$mail"
pankso@9 559 EOT
pankso@26 560 chmod 0600 $PEOPLE/$user/account.conf
pankso@123 561 # First created user is admin
pankso@123 562 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
pankso@123 563 echo "$user" > ${ADMIN_USERS}
pankso@48 564 fi
pankso@48 565 }
pankso@9 566
pankso@48 567 ########################################################################
pankso@48 568 # POST actions #
pankso@48 569 ########################################################################
pankso@9 570
pankso@9 571 case " $(POST) " in
pankso@9 572 *\ auth\ *)
xfred222@34 573 header
xfred222@34 574 html_header
pankso@9 575 # Authenticate user. Create a session file in $sessions to be used
pankso@9 576 # by check_auth. We have the user login name and a peer session
pankso@9 577 # md5 string in the COOKIE.
pankso@9 578 user="$(POST auth)"
xfred222@34 579 pass="$(echo -n "$(POST pass)" | md5sum | awk '{print $1}')"
xfred222@34 580
xfred222@34 581 IDLOC=""
pankso@73 582 if [[ "$(POST id)" ]] ;then
pankso@73 583 IDLOC="&id=$(POST id)"
pankso@48 584 fi
xfred222@34 585
xfred222@34 586 if [ ! -f $AUTH_FILE ] ; then
paul@50 587 js_log "$AUTH_FILE (defined in \$AUTH_FILE) has not been found."
pankso@53 588 js_redirection_to "$script?login$IDLOC"
xfred222@34 589 fi;
xfred222@34 590
pankso@9 591 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
pankso@9 592 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
pankso@73 593 if [[ "$(POST id)" ]] ;then
pankso@73 594 IDLOC="?id=$(POST id)"
xfred222@34 595 fi
pankso@9 596 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
pankso@9 597 mkdir -p $sessions
pankso@63 598 # Log last login
pankso@63 599 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
pankso@9 600 echo "$md5session" > $sessions/$user
xfred222@34 601 js_set_cookie 'auth' "$user:$md5session"
paul@70 602 js_log "Login authentication has been executed & accepted :)"
pankso@53 603 js_redirection_to "$script$IDLOC"
pankso@9 604 else
paul@70 605 js_log "Login authentication has been executed & refused"
pankso@53 606 js_redirection_to "$script?login&error$IDLOC"
xfred222@34 607 fi
pankso@48 608 html_footer ;;
pankso@48 609 *\ signup\ *)
pankso@48 610 # POST action for online signup
pankso@48 611 name="$(POST name)"
pankso@48 612 user="$(POST user)"
pankso@48 613 mail="$(POST mail)"
pankso@48 614 pass="$(md5crypt "$(POST pass)")"
pankso@48 615 if ! grep "^${user}:" $AUTH_FILE; then
pankso@48 616 online="yes"
pankso@48 617 new_user_config
pankso@48 618 header "Location: $SCRIPT_NAME?login"
pankso@48 619 else
pankso@48 620 header
pankso@48 621 html_header
pankso@48 622 user_box
pankso@49 623 echo "<h2>$(gettext "User already exists:") $user</h2>"
pankso@48 624 html_footer && exit 0
pankso@48 625 fi ;;
pankso@9 626 esac
pankso@9 627
pankso@49 628 #
pankso@49 629 # Plugins Now!
pankso@49 630 #
pankso@73 631
pankso@49 632 for p in $(ls -1 $plugins)
pankso@49 633 do
pankso@49 634 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
pankso@49 635 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
pankso@49 636 done
xfred222@34 637
pankso@48 638 ########################################################################
pankso@48 639 # GET actions #
pankso@48 640 ########################################################################
pankso@9 641
pankso@9 642 case " $(GET) " in
pankso@9 643 *\ README\ *)
pankso@9 644 header
pankso@9 645 html_header
pankso@9 646 user_box
pankso@9 647 echo '<h2>README</h2>'
pankso@9 648 echo '<pre>'
pankso@55 649 if [ -f "README" ]; then
pankso@55 650 cat README
pankso@55 651 else
pankso@55 652 cat /usr/share/doc/tazbug/README
pankso@55 653 fi
pankso@30 654 echo '</pre>'
pankso@9 655 html_footer ;;
pankso@9 656 *\ closed\ *)
pankso@9 657 # Show all closed bugs.
pankso@9 658 header
pankso@9 659 html_header
pankso@9 660 user_box
pankso@9 661 list_bugs CLOSED
pankso@51 662 echo "</pre>"
pankso@9 663 html_footer ;;
pankso@9 664 *\ login\ *)
pankso@9 665 # The login page
pankso@9 666 [ "$(GET error)" ] && \
al@31 667 error="<span class='error'>$(gettext 'Bad login or pass')</span>"
pankso@30 668 header
pankso@9 669 html_header
pankso@21 670 user_box
xfred222@33 671 login_page
pankso@9 672 html_footer ;;
pankso@9 673 *\ logout\ *)
xfred222@34 674 header
xfred222@34 675 html_header
pankso@9 676 if check_auth; then
pankso@9 677 rm -f "$sessions/$user"
xfred222@34 678 js_unset_cookie 'auth'
pankso@53 679 js_redirection_to "$script"
pankso@9 680 fi ;;
pankso@9 681 *\ user\ *)
pankso@112 682 # User profile. Use the users plugin for more functions
pankso@63 683 last="$(cat $PEOPLE/"$(GET user)"/last)"
pankso@9 684 header
pankso@9 685 html_header
pankso@9 686 user_box
pankso@26 687 . $PEOPLE/"$(GET user)"/account.conf
pankso@63 688 cat << EOT
pankso@63 689 <h2>$(get_gravatar $MAIL) $NAME</h2>
pankso@63 690
pankso@63 691 <pre>
pankso@63 692 $(gettext "User name :") $USER
pankso@63 693 $(gettext "Last login :") $last
pankso@112 694 </pre>
pankso@63 695 EOT
pankso@9 696 html_footer ;;
pankso@9 697 *\ newbug\ *)
pankso@98 698 # Create a bug from web interface.
pankso@9 699 header
pankso@9 700 html_header
pankso@9 701 user_box
pankso@9 702 if check_auth; then
pankso@9 703 new_bug_page
pankso@9 704 else
al@31 705 echo "<p>$(gettext 'You must be logged in to post a new bug')</p>"
pankso@9 706 fi
pankso@9 707 html_footer ;;
pankso@9 708 *\ addbug\ *)
pankso@98 709 # Save a new bug from web interface.
xfred222@34 710 header
xfred222@34 711 html_header
pankso@9 712 if check_auth; then
pankso@9 713 new_bug
pankso@53 714 js_redirection_to "$script?id=$count"
pankso@9 715 fi ;;
pankso@106 716 *\ editbug\ *)
pankso@98 717 # Edit existing bug
pankso@106 718 id="$(GET editbug)"
pankso@9 719 header
pankso@9 720 html_header
pankso@9 721 user_box
pankso@9 722 edit_bug
pankso@9 723 html_footer ;;
pankso@98 724 *\ savebug\ *)
xfred222@34 725 header
xfred222@34 726 html_header
pankso@9 727 if check_auth; then
pankso@9 728 save_bug
pankso@98 729 js_redirection_to "$script?id=$id"
pankso@9 730 fi ;;
pankso@9 731 *\ id\ *)
xfred222@34 732 header
xfred222@34 733 html_header
pankso@9 734 id="$(GET id)"
pankso@9 735 [ "$(GET close)" ] && close_bug
pankso@9 736 [ "$(GET open)" ] && open_bug
pankso@9 737 [ "$(GET msg)" ] && new_msg
pankso@132 738 [ "$(GET delmsg)" ] && rm -f $bugdir/$id/msg.$(GET delmsg)
pankso@9 739 msgs=$(fgrep MSG= $bugdir/$id/msg.* | wc -l)
pankso@30 740 user_box
pankso@9 741 . $bugdir/$id/bug.conf
pankso@9 742 bug_page
pankso@9 743 html_footer ;;
pankso@9 744 *\ signup\ *)
pankso@9 745 # Signup
pankso@118 746 header
pankso@118 747 html_header
pankso@118 748 user_box
pankso@118 749 echo "<h2>$(gettext "Sign Up")</h2>"
pankso@118 750 if [ "$ONLINE_SIGNUP" == "yes" ]; then
pankso@118 751 signup_page
pankso@9 752 else
pankso@118 753 gettext "Online registration is disabled"
pankso@118 754 fi
pankso@118 755 html_footer ;;
pankso@118 756
pankso@9 757 *\ search\ *)
pankso@59 758 found=0
pankso@9 759 header
pankso@9 760 html_header
pankso@9 761 user_box
pankso@9 762 cat << EOT
pankso@9 763 <h2>$(gettext "Search")</h2>
pankso@53 764 <form method="get" action="$script">
pankso@9 765 <input type="text" name="search" />
al@31 766 <input type="submit" value="$(gettext 'Search')" />
pankso@9 767 </form>
pankso@21 768 <div>
pankso@9 769 EOT
pankso@59 770 cd $bugdir
pankso@59 771 for bug in *
pankso@9 772 do
pankso@61 773 result=$(fgrep -i -h "$(GET search)" $bug/*)
pankso@21 774 if [ "$result" ]; then
pankso@59 775 found=$(($found + 1))
pankso@59 776 id=${bug}
al@31 777 echo "<p><strong>Bug $id</strong> <a href=\"?id=$id\">"$(gettext 'Show')"</a></p>"
pankso@21 778 echo '<pre>'
pankso@62 779 fgrep -i -h "$(GET search)" $bugdir/$id/* | \
pankso@21 780 sed s"/$(GET search)/<span class='ok'>$(GET search)<\/span>/"g
pankso@21 781 echo '</pre>'
pankso@21 782 fi
pankso@9 783 done
pankso@59 784 if [ "$found" == "0" ]; then
pankso@59 785 echo "<p>$(gettext 'No result found for') : $(GET search)</p>"
pankso@59 786 else
pankso@59 787 echo "<p> $found $(gettext 'results found')</p>"
pankso@59 788 fi
pankso@21 789 echo '</div>'
pankso@9 790 html_footer ;;
pankso@9 791 *)
pankso@9 792 # Default page.
pankso@9 793 bugs=$(ls -1 $bugdir | wc -l)
pankso@9 794 close=$(fgrep "CLOSED" $bugdir/*/bug.conf | wc -l)
pankso@9 795 fixme=$(fgrep "OPEN" $bugdir/*/bug.conf | wc -l)
pankso@9 796 msgs=$(find $bugdir -name msg.* ! -size 0 | wc -l)
pankso@9 797 pct=0
pankso@9 798 [ $bugs -gt 0 ] && pct=$(( ($close * 100) / $bugs ))
pankso@9 799 header
pankso@9 800 html_header
pankso@9 801 user_box
pankso@73 802
pankso@9 803 cat << EOT
pankso@9 804
pankso@9 805 <h2>$(gettext "Summary")</h2>
pankso@9 806
pankso@9 807 <p>
al@31 808 $(eval_ngettext 'Bug: $bugs in total -' 'Bugs: $bugs in total -' $bugs)
al@31 809 $(eval_ngettext '$close fixed -' '$close fixed -' $close)
al@31 810 $(eval_ngettext '$fixme to fix -' '$fixme to fix -' $fixme)
al@31 811 $(eval_ngettext '$msgs message' '$msgs messages' $msgs)
pankso@9 812 </p>
pankso@9 813
pankso@9 814 <div class="pctbar">
pankso@9 815 <div class="pct" style="width: ${pct}%;">${pct}%</div>
pankso@9 816 </div>
pankso@9 817
pankso@49 818 <p>$(gettext "Please read the <a href=\"?README\">README</a> for help and \
pankso@49 819 more information. You may also be interested by the SliTaz \
al@31 820 <a href=\"http://roadmap.slitaz.org/\">Roadmap</a> and the packages \
al@31 821 <a href=\"http://cook.slitaz.org/\">Cooker</a>. To perform a search \
al@31 822 enter your term and press ENTER.")
pankso@9 823 </p>
pankso@9 824
pankso@9 825 <div id="tools">
pankso@80 826 $BUGS_TOOLS
pankso@124 827 <a href="?closed">$(gettext 'Closed bugs')</a>
pankso@9 828 EOT
pankso@9 829 if check_auth; then
pankso@124 830 echo "<a href='?newbug'>$(gettext 'Create bug')</a>"
pankso@49 831 echo "$PLUGINS_TOOLS"
pankso@9 832 fi
pankso@9 833 cat << EOT
pankso@9 834 </div>
pankso@55 835
pankso@55 836 <h3>$(gettext "Latest Bugs")</h3>
pankso@9 837 EOT
pankso@108 838 # List last 4 bugs
pankso@55 839 echo "<pre>"
pankso@108 840 for lb in $(ls ${bugdir} | sort -r -n | head -n 4)
pankso@55 841 do
pankso@55 842 list_bug ${lb}
pankso@55 843 done
pankso@55 844 echo "</pre>"
pankso@108 845 # List last 4 messages
pankso@106 846 echo "<h3>$(gettext "Latest Messages")</h3>"
pankso@106 847 echo "<pre>"
pankso@108 848 for msg in $(ls -t ${bugdir}/*/msg.* | head -n 4)
pankso@106 849 do
pankso@106 850 list_msg ${msg}
pankso@106 851 done
pankso@106 852 echo "</pre>"
pankso@9 853 list_bugs OPEN
pankso@51 854 echo "</pre>"
pankso@9 855 html_footer ;;
pankso@9 856 esac
pankso@9 857
pankso@9 858 exit 0