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