tinycm rev 101
users plugin: speed up listing and improve ?lastusers page
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Feb 20 14:36:57 2017 +0100 (2017-02-20) |
parents | d6c0da38715f |
children | 69214a677729 |
files | plugins/dashboard/dashboard.cgi plugins/users/users.cgi style.css |
line diff
1.1 --- a/plugins/dashboard/dashboard.cgi Mon Feb 20 13:33:04 2017 +0100 1.2 +++ b/plugins/dashboard/dashboard.cgi Mon Feb 20 14:36:57 2017 +0100 1.3 @@ -47,6 +47,7 @@ 1.4 # List all plugins 1.5 cat << EOT 1.6 <h3>$(gettext "Plugins:") $(ls $plugins | wc -l)</h3> 1.7 +<div id="plugins"> 1.8 <table> 1.9 <thead> 1.10 <td>$(gettext "Name")</td> 1.11 @@ -65,7 +66,7 @@ 1.12 </tr> 1.13 EOT 1.14 done 1.15 - echo "</table>" 1.16 + echo "</table></div>" 1.17 fi 1.18 else 1.19 gettext "You must be logged in to view the dashboard"
2.1 --- a/plugins/users/users.cgi Mon Feb 20 13:33:04 2017 +0100 2.2 +++ b/plugins/users/users.cgi Mon Feb 20 14:36:57 2017 +0100 2.3 @@ -21,6 +21,24 @@ 2.4 EOT 2.5 } 2.6 2.7 +# List last active users. Usage: last_users NB 2.8 +list_last_users() { 2.9 + count=${1} 2.10 + echo "<h3>Last $count active users</h3>" 2.11 + echo "<pre>" 2.12 + find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last; 2.13 + do 2.14 + dir="$(dirname $last)" 2.15 + date="$(cat $last)" 2.16 + u=$(basename $dir) 2.17 + . "${PEOPLE}/${u}/account.conf" 2.18 + cat << EOT 2.19 +$(get_gravatar $MAIL 24) $date : <a href="?user=$u">$u</a> | $NAME 2.20 +EOT 2.21 + done 2.22 + echo "</pre>" 2.23 +} 2.24 + 2.25 case " $(GET) " in 2.26 *\ users\ *) 2.27 d="Users" 2.28 @@ -36,7 +54,7 @@ 2.29 cat << EOT 2.30 <div id="tools"> 2.31 <a href="$script?dashboard">Dashboard</a> 2.32 - <a href='$script?loggedusers'>Logged users</a> 2.33 + <a href='$script?lastusers'>Last users</a> 2.34 $tools 2.35 </div> 2.36 <h2>${d}</h2> 2.37 @@ -45,22 +63,7 @@ 2.38 Logged users : $(ls $sessions | wc -l) 2.39 </pre> 2.40 EOT 2.41 - 2.42 - # Last active user 2.43 - count=10 2.44 - echo "<h3>Last active users</h3>" 2.45 - echo "<pre>" 2.46 - find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last; 2.47 - do 2.48 - dir="$(dirname $last)" 2.49 - date="$(cat $last)" 2.50 - u=$(basename $dir) 2.51 - . "${PEOPLE}/${u}/account.conf" 2.52 - cat << EOT 2.53 -$(get_gravatar $MAIL 24) $date : <a href="?user=$u">$u</a> | $NAME 2.54 -EOT 2.55 - done 2.56 - echo "</pre>" 2.57 + list_last_users 5 2.58 2.59 # Admin only 2.60 if admin_user; then 2.61 @@ -87,7 +90,7 @@ 2.62 html_footer && exit 0 ;; 2.63 2.64 *\ userslist\ *) 2.65 - # List all users (slow if a lot a of accounts) 2.66 + # List all users 2.67 d="Users" 2.68 header 2.69 html_header 2.70 @@ -100,11 +103,16 @@ 2.71 cat << EOT 2.72 <div id="tools"> 2.73 <a href="$script?dashboard">Dashboard</a> 2.74 - <a href="$script?users">Users admin</a> 2.75 - <a href='$script?loggedusers'>Logged users</a> 2.76 + <a href="$script?users">Users</a> 2.77 + <a href='$script?lastusers'>Last users</a> 2.78 </div> 2.79 <h2>Users: $users</h2> 2.80 -<pre> 2.81 +<div id="users"> 2.82 +<table> 2.83 + <thead> 2.84 + <td>$(gettext "Username")</td> 2.85 + <td>$(gettext "Action")</td> 2.86 + </thead> 2.87 EOT 2.88 for u in $(ls $PEOPLE) 2.89 do 2.90 @@ -113,20 +121,22 @@ 2.91 echo "${u} : Missing account.conf" 2.92 continue 2.93 fi 2.94 - . "${PEOPLE}/${u}/account.conf" 2.95 cat << EOT 2.96 -$(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL 2.97 + <tr> 2.98 + <td><a href='?$u'>$u</a></td> 2.99 + <td>TODO</td> 2.100 + </tr> 2.101 EOT 2.102 # deluser link --> use 'tazu' on SliTaz 2.103 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> 2.104 unset NAME USER 2.105 done 2.106 - echo "</pre>" 2.107 + echo "</table></div>" 2.108 html_footer && exit 0 ;; 2.109 2.110 - *\ loggedusers\ *) 2.111 + *\ lastusers\ *) 2.112 # Show online users based on sessions files. 2.113 - d="Logged users" 2.114 + d="Last users" 2.115 header 2.116 html_header 2.117 user_box 2.118 @@ -134,15 +144,17 @@ 2.119 gettext "You must be logged in to view online users" 2.120 exit 0 2.121 fi 2.122 - logged="$(ls $sessions | wc -l)" 2.123 cat << EOT 2.124 <div id="tools"> 2.125 <a href="$script?dashboard">Dashboard</a> 2.126 <a href="$script?users">Users</a> 2.127 </div> 2.128 -<h2>Logged users: $logged</h2> 2.129 -<pre> 2.130 EOT 2.131 + list_last_users 15 2.132 + 2.133 + # Active cookies 2.134 + echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>" 2.135 + echo "<pre>" 2.136 for u in $(ls $sessions) 2.137 do 2.138 . "${PEOPLE}/${u}/account.conf"
3.1 --- a/style.css Mon Feb 20 13:33:04 2017 +0100 3.2 +++ b/style.css Mon Feb 20 14:36:57 2017 +0100 3.3 @@ -339,3 +339,10 @@ 3.4 padding: 10px; 3.5 } 3.6 3.7 +/* Users & Dashboard */ 3.8 +#users table, #plugins table { border-collapse: collapse; } 3.9 +#users tr, #plugins tr { 3.10 + padding:.3em 1em; 3.11 + border-bottom: 1px solid #ddd; 3.12 +} 3.13 +#users td, #plugins td { padding: 4px 0; }