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