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