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