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