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