tazbug annotate web/bugs.cgi @ rev 113

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