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