tazbug rev 123
Use new admin config and up users plugins from TinyCM
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Feb 21 00:51:31 2017 +0100 (2017-02-21) |
parents | 3698cf81f884 |
children | 4dab1a5b9cb6 |
files | web/bugs.cgi web/config.cgi web/plugins/dashboard/dashboard.cgi web/plugins/debug/debug.cgi web/plugins/users/users.cgi web/plugins/users/users.conf web/style.css |
line diff
1.1 --- a/web/bugs.cgi Mon Feb 13 17:45:24 2017 +0100 1.2 +++ b/web/bugs.cgi Tue Feb 21 00:51:31 2017 +0100 1.3 @@ -4,7 +4,7 @@ 1.4 # 1.5 # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License 1.6 # 1.7 -. /usr/lib/slitaz/httphelper 1.8 +. /usr/lib/slitaz/httphelper.sh 1.9 1.10 # Source config file 1.11 . ./config.cgi 1.12 @@ -112,7 +112,7 @@ 1.13 1.14 # Check if user is admin 1.15 admin_user() { 1.16 - fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf 1.17 + fgrep -w -q "$user" ${ADMIN_USERS} 1.18 } 1.19 1.20 # Authenticated or not 1.21 @@ -543,30 +543,21 @@ 1.22 1.23 # Create a new user in AUTH_FILE and PEOPLE 1.24 new_user_config() { 1.25 - if [ ! "$online" ]; then 1.26 - name="$(GET name)" 1.27 - mail="$(GET mail)" 1.28 - pass="$(GET pass)" 1.29 - echo "Creating Server Key..." 1.30 + if [ ! -f "$AUTH_FILE" ]; then 1.31 + touch $AUTH_FILE && chmod 0600 $AUTH_FILE 1.32 fi 1.33 - #key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}') 1.34 echo "$user:$pass" >> $AUTH_FILE 1.35 - mkdir -pm0700 $PEOPLE/$user/ 1.36 + mkdir -pm0700 $PEOPLE/${user} 1.37 cat > $PEOPLE/$user/account.conf << EOT 1.38 -# SliTaz user configuration 1.39 -# 1.40 - 1.41 +# User configuration 1.42 NAME="$name" 1.43 USER="$user" 1.44 MAIL="$mail" 1.45 - 1.46 -LOCATION="$(GET location)" 1.47 -RELEASES="$(GET releases)" 1.48 -PACKAGES="$(GET packages)" 1.49 EOT 1.50 chmod 0600 $PEOPLE/$user/account.conf 1.51 - if [ ! -f $PEOPLE/$user/account.conf ]; then 1.52 - echo "ERROR: User creation failed!" 1.53 + # First created user is admin 1.54 + if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then 1.55 + echo "$user" > ${ADMIN_USERS} 1.56 fi 1.57 } 1.58
2.1 --- a/web/config.cgi Mon Feb 13 17:45:24 2017 +0100 2.2 +++ b/web/config.cgi Tue Feb 21 00:51:31 2017 +0100 2.3 @@ -1,12 +1,12 @@ 2.4 # SliTaz Bug Tracker Web interface configuration. 2.5 # 2.6 2.7 -# TazBug URL for redirection and RSS 2.8 -WEB_URL="http://localhost/bugs/bugs.cgi" 2.9 - 2.10 # Auth file for user 2.11 AUTH_FILE="/var/lib/slitaz/auth/people" 2.12 2.13 +# Admin users file list 2.14 +ADMIN_USERS="/var/lib/slitaz/auth/admin" 2.15 + 2.16 # People config files 2.17 PEOPLE="/var/lib/slitaz/people" 2.18
3.1 --- a/web/plugins/dashboard/dashboard.cgi Mon Feb 13 17:45:24 2017 +0100 3.2 +++ b/web/plugins/dashboard/dashboard.cgi Tue Feb 21 00:51:31 2017 +0100 3.3 @@ -26,55 +26,42 @@ 3.4 fi 3.5 if check_auth; then 3.6 cat << EOT 3.7 -<h2>Dashboard</h2> 3.8 - 3.9 <div id="tools"> 3.10 $DASHBOARD_TOOLS $ADMIN_TOOLS 3.11 </div> 3.12 - 3.13 +<h2>Dashboard</h2> 3.14 <pre> 3.15 Bugs count : $bugs 3.16 Database size : $bugsize 3.17 Server uptime :$(uptime | cut -d "," -f 1-2) 3.18 </pre> 3.19 - 3.20 -<h3>Admin users</h3> 3.21 EOT 3.22 - 3.23 - # Get the list of administrators 3.24 - fgrep -l "ADMIN_USER=" $PEOPLE/*/account.conf | while read file; 3.25 - do 3.26 - . ${file} 3.27 - echo "<a href='?user=$USER'>$USER</a>" 3.28 - unset NAME USER 3.29 - done 3.30 - 3.31 + 3.32 # Only for admins 3.33 if check_auth && admin_user; then 3.34 # List all plugins 3.35 cat << EOT 3.36 -<h3>$(gettext "Plugins")</h3> 3.37 -<pre> 3.38 - <table> 3.39 - <thead> 3.40 - <td>$(gettext "Name")</td> 3.41 - <td>$(gettext "Description")</td> 3.42 - <td>$(gettext "Action")</td> 3.43 - </thead> 3.44 +<h3>$(gettext "Plugins:") $(ls $plugins | wc -l)</h3> 3.45 +<div id="plugins"> 3.46 +<table> 3.47 + <thead> 3.48 + <td>$(gettext "Name")</td> 3.49 + <td>$(gettext "Description")</td> 3.50 + <td>$(gettext "Action")</td> 3.51 + </thead> 3.52 EOT 3.53 for p in $(ls -1 $plugins) 3.54 do 3.55 . $plugins/$p/$p.conf 3.56 cat << EOT 3.57 - <tr> 3.58 - <td><a href='?$p'>$PLUGIN</a></td> 3.59 - <td>$SHORT_DESC</td> 3.60 - <td>TODO</td> 3.61 - </tr> 3.62 + <tr> 3.63 + <td><a href='?$p'>$PLUGIN</a></td> 3.64 + <td>$SHORT_DESC</td> 3.65 + <td>TODO</td> 3.66 + </tr> 3.67 EOT 3.68 done 3.69 - echo " </table>" 3.70 - echo "</pre>" 3.71 + echo "</table></div>" 3.72 fi 3.73 else 3.74 gettext "You must be logged in to view the dashboard"
4.1 --- a/web/plugins/debug/debug.cgi Mon Feb 13 17:45:24 2017 +0100 4.2 +++ b/web/plugins/debug/debug.cgi Tue Feb 21 00:51:31 2017 +0100 4.3 @@ -13,10 +13,10 @@ 4.4 exit 0 4.5 fi 4.6 cat << EOT 4.7 -<h2>Debug interface</h2> 4.8 <div id="tools"> 4.9 <a href="$script?dashboard">Dashboard</a> 4.10 </div> 4.11 +<h2>Debug interface</h2> 4.12 EOT 4.13 # Handle ?debug&del request 4.14 if [ "$(GET del)" ]; then
5.1 --- a/web/plugins/users/users.cgi Mon Feb 13 17:45:24 2017 +0100 5.2 +++ b/web/plugins/users/users.cgi Tue Feb 21 00:51:31 2017 +0100 5.3 @@ -13,23 +13,30 @@ 5.4 cat << EOT 5.5 Email : $MAIL 5.6 </pre> 5.7 -EOT 5.8 - # Each user can have personal profile page 5.9 - if [ -f "$PEOPLE/$USER/profile.txt" ]; then 5.10 - cat << EOT 5.11 + 5.12 <div id="tools"> 5.13 + $PLUGINS_TOOLS 5.14 <a href="$script?modprofile">$(gettext "Modify profile")</a> 5.15 - <a href="$script?dashboard">Dashboard</a> 5.16 </div> 5.17 EOT 5.18 - else 5.19 - cat << EOT 5.20 -<div id="tools"> 5.21 - <a href="$script?modprofile">$(gettext "Create a profile page")</a> 5.22 - <a href="$script?dashboard">Dashboard</a> 5.23 -</div> 5.24 +} 5.25 + 5.26 +# List last active users. Usage: last_users NB 5.27 +list_last_users() { 5.28 + count=${1} 5.29 + echo "<h3>Last $count active users</h3>" 5.30 + echo "<pre>" 5.31 + find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last; 5.32 + do 5.33 + dir="$(dirname $last)" 5.34 + date="$(cat $last)" 5.35 + u=$(basename $dir) 5.36 + . "${PEOPLE}/${u}/account.conf" 5.37 + cat << EOT 5.38 +$(get_gravatar $MAIL 24) $date : <a href="?user=$u">$u</a> | $NAME 5.39 EOT 5.40 - fi 5.41 + done 5.42 + echo "</pre>" 5.43 } 5.44 5.45 case " $(GET) " in 5.46 @@ -38,28 +45,54 @@ 5.47 header 5.48 html_header 5.49 user_box 5.50 - if check_auth && ! admin_user; then 5.51 - gettext "You must be admin to manage users" && exit 0 5.52 + # Admin only 5.53 + if admin_user; then 5.54 + tools="<a href='$script?userslist'>Users list</a>" 5.55 fi 5.56 - cat << EOT 5.57 -<h2>Users admin</h2> 5.58 + # Logged users 5.59 + if check_auth; then 5.60 + cat << EOT 5.61 <div id="tools"> 5.62 <a href="$script?dashboard">Dashboard</a> 5.63 - <a href='$script?loggedusers'>Logged users</a> 5.64 - <a href='$script?userslist'>Users list</a> 5.65 + <a href='$script?lastusers'>Last users</a> 5.66 + $tools 5.67 </div> 5.68 +<h2>${d}</h2> 5.69 <pre> 5.70 User accounts : $(ls -1 $PEOPLE | wc -l) 5.71 Logged users : $(ls $sessions | wc -l) 5.72 +</pre> 5.73 +EOT 5.74 + list_last_users 5 5.75 + 5.76 + # Admin only 5.77 + if admin_user; then 5.78 + cat << EOT 5.79 +<h3>Config paths</h3> 5.80 +<pre> 5.81 People DB : $PEOPLE 5.82 -Auth file : $AUTH_FILE 5.83 +Authfile : $AUTH_FILE 5.84 +Admin users : $ADMIN_USERS 5.85 +</pre> 5.86 EOT 5.87 - 5.88 - echo "</pre>" 5.89 + # Get the list of administrators 5.90 + echo "<h3>Admin users</h3>" 5.91 + echo "<pre>" 5.92 + for u in $(cat $ADMIN_USERS) 5.93 + do 5.94 + . ${PEOPLE}/${u}/account.conf 5.95 + echo "<a href='?user=$u'>$u</a> - $NAME" 5.96 + done 5.97 + echo "</pre>" 5.98 + fi 5.99 + 5.100 + else 5.101 + gettext "You must be logged to check or admin users" 5.102 + fi 5.103 html_footer && exit 0 ;; 5.104 5.105 *\ userslist\ *) 5.106 - # List all users (slow if a lot a of accounts) 5.107 + # List all users 5.108 d="Users" 5.109 header 5.110 html_header 5.111 @@ -70,13 +103,18 @@ 5.112 fi 5.113 users=$(ls -1 $PEOPLE | wc -l) 5.114 cat << EOT 5.115 -<h2>Users: $users</h2> 5.116 <div id="tools"> 5.117 <a href="$script?dashboard">Dashboard</a> 5.118 - <a href="$script?users">Users admin</a> 5.119 - <a href='$script?loggedusers'>Logged users</a> 5.120 + <a href="$script?users">Users</a> 5.121 + <a href='$script?lastusers'>Last users</a> 5.122 </div> 5.123 -<pre> 5.124 +<h2>Users: $users</h2> 5.125 +<div id="users"> 5.126 +<table> 5.127 + <thead> 5.128 + <td>$(gettext "Username")</td> 5.129 + <td>$(gettext "Action")</td> 5.130 + </thead> 5.131 EOT 5.132 for u in $(ls $PEOPLE) 5.133 do 5.134 @@ -85,20 +123,22 @@ 5.135 echo "${u} : Missing account.conf" 5.136 continue 5.137 fi 5.138 - . "${PEOPLE}/${u}/account.conf" 5.139 cat << EOT 5.140 -$(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL 5.141 + <tr> 5.142 + <td><a href="$script?user=$u">$u</a></td> 5.143 + <td>TODO</td> 5.144 + </tr> 5.145 EOT 5.146 # deluser link --> use 'tazu' on SliTaz 5.147 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> 5.148 unset NAME USER 5.149 done 5.150 - echo "</pre>" 5.151 + echo "</table></div>" 5.152 html_footer && exit 0 ;; 5.153 5.154 - *\ loggedusers\ *) 5.155 + *\ lastusers\ *) 5.156 # Show online users based on sessions files. 5.157 - d="Logged users" 5.158 + d="Last users" 5.159 header 5.160 html_header 5.161 user_box 5.162 @@ -106,15 +146,17 @@ 5.163 gettext "You must be logged in to view online users" 5.164 exit 0 5.165 fi 5.166 - logged="$(ls $sessions | wc -l)" 5.167 cat << EOT 5.168 -<h2>Logged users: $logged</h2> 5.169 <div id="tools"> 5.170 <a href="$script?dashboard">Dashboard</a> 5.171 - <a href="$script?users">Users admin</a> 5.172 + <a href="$script?users">Users</a> 5.173 </div> 5.174 -<pre> 5.175 EOT 5.176 + list_last_users 15 5.177 + 5.178 + # Active cookies 5.179 + echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>" 5.180 + echo "<pre>" 5.181 for u in $(ls $sessions) 5.182 do 5.183 . "${PEOPLE}/${u}/account.conf" 5.184 @@ -132,7 +174,15 @@ 5.185 header 5.186 html_header 5.187 user_box 5.188 - . $PEOPLE/"$(GET user)"/account.conf 5.189 + account_config="$PEOPLE/$(GET user)/account.conf" 5.190 + profile_config="$PEOPLE/$(GET user)/profile.conf" 5.191 + if [ ! -f "$account_config" ]; then 5.192 + echo "No user profile for: $(GET user)" 5.193 + html_footer && exit 0 5.194 + else 5.195 + . ${account_config} 5.196 + fi 5.197 + [ -f "$profile_config" ] && . ${profile_config} 5.198 cat << EOT 5.199 <h2>$(get_gravatar $MAIL) $NAME</h2> 5.200 5.201 @@ -147,6 +197,18 @@ 5.202 . $PEOPLE/"$(GET user)"/account.conf 5.203 public_people 5.204 fi 5.205 + 5.206 + # Messages plugin integration 5.207 + if [ -x "$plugins/messages/messages.cgi" ]; then 5.208 + if check_auth && [ "$(GET user)" != "$user" ]; then 5.209 + cat << EOT 5.210 +<div id="tools"> 5.211 +<a href="$script?messages&to=$(GET user)">$(gettext "Send message")</a> 5.212 +</div> 5.213 +EOT 5.214 + fi 5.215 + fi 5.216 + 5.217 # Display personal user profile 5.218 if [ -f "$PEOPLE/$USER/profile.txt" ]; then 5.219 echo "<h2>$(gettext "About me")</h2>"
6.1 --- a/web/plugins/users/users.conf Mon Feb 13 17:45:24 2017 +0100 6.2 +++ b/web/plugins/users/users.conf Tue Feb 21 00:51:31 2017 +0100 6.3 @@ -6,9 +6,7 @@ 6.4 6.5 # Authenticated users 6.6 PLUGINS_TOOLS="${PLUGINS_TOOLS}" 6.7 -DASHBOARD_TOOLS="${DASHBOARD_TOOLS}" 6.8 +DASHBOARD_TOOLS="${DASHBOARD_TOOLS} <a href='?users'>Users</a>" 6.9 6.10 # Admin only in Dashboard 6.11 -ADMIN_TOOLS="${ADMIN_TOOLS} <a href='?users'>Users</a>" 6.12 - 6.13 -# Configurable variables used in plugin.cgi 6.14 +ADMIN_TOOLS="${ADMIN_TOOLS}"
7.1 --- a/web/style.css Mon Feb 13 17:45:24 2017 +0100 7.2 +++ b/web/style.css Tue Feb 21 00:51:31 2017 +0100 7.3 @@ -220,3 +220,11 @@ 7.4 } 7.5 7.6 #footer a { padding: 0 2px; } 7.7 + 7.8 +/* Users & Dashboard */ 7.9 +#users table, #plugins table { border-collapse: collapse; } 7.10 +#users tr, #plugins tr { 7.11 + padding:.3em 1em; 7.12 + border-bottom: 1px solid #ddd; 7.13 +} 7.14 +#users td, #plugins td { padding: 4px 0; }