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