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