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