tazbug annotate web/bugs.cgi @ rev 107

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