tinycm rev 100

Improve users plugin (list last active users)
author Christophe Lincoln <pankso@slitaz.org>
date Mon Feb 20 13:33:04 2017 +0100 (2017-02-20)
parents 95673a3de4e4
children 35354740250d
files plugins/dashboard/dashboard.cgi plugins/users/users.cgi plugins/users/users.conf
line diff
     1.1 --- a/plugins/dashboard/dashboard.cgi	Mon Feb 20 02:20:44 2017 +0100
     1.2 +++ b/plugins/dashboard/dashboard.cgi	Mon Feb 20 13:33:04 2017 +0100
     1.3 @@ -37,24 +37,16 @@
     1.4  <pre>
     1.5  Wiki docs        : $docs ($wikisize)
     1.6  Cache size       : $cachesize
     1.7 +Users account    : $(ls $PEOPLE | wc -l)
     1.8  Mercurial        : $hg
     1.9  </pre>
    1.10 -
    1.11 -<h3>Admin users</h3>
    1.12  EOT
    1.13 -		# Get the list of administrators
    1.14 -		fgrep -l "ADMIN_USER=" $PEOPLE/*/account.conf | while read file;
    1.15 -		do
    1.16 -			. ${file}
    1.17 -			echo "<a href='?user=$USER'>$USER</a>"
    1.18 -			unset NAME USER
    1.19 -		done
    1.20  		
    1.21  		# Only for admins
    1.22 -		if check_auth && admin_user; then
    1.23 +		if admin_user; then
    1.24  			# List all plugins
    1.25  			cat << EOT
    1.26 -<h3>$(gettext "Plugins")</h3>
    1.27 +<h3>$(gettext "Plugins:") $(ls $plugins | wc -l)</h3>
    1.28  <table>
    1.29  	<thead>
    1.30  		<td>$(gettext "Name")</td>
     2.1 --- a/plugins/users/users.cgi	Mon Feb 20 02:20:44 2017 +0100
     2.2 +++ b/plugins/users/users.cgi	Mon Feb 20 13:33:04 2017 +0100
     2.3 @@ -27,24 +27,63 @@
     2.4  		header
     2.5  		html_header
     2.6  		user_box
     2.7 -		if check_auth && ! admin_user; then
     2.8 -			gettext "You must be admin to manage users" && exit 0
     2.9 +		# Admin only
    2.10 +		if admin_user; then
    2.11 +			tools="<a href='$script?userslist'>Users list</a>"
    2.12  		fi
    2.13 -		cat << EOT
    2.14 -<h2>Users admin</h2>
    2.15 +		# Logged users
    2.16 +		if check_auth; then
    2.17 +			cat << EOT
    2.18  <div id="tools">
    2.19  	<a href="$script?dashboard">Dashboard</a>
    2.20  	<a href='$script?loggedusers'>Logged users</a>
    2.21 -	<a href='$script?userslist'>Users list</a>
    2.22 +	$tools
    2.23  </div>
    2.24 +<h2>${d}</h2>
    2.25  <pre>
    2.26  User accounts   : $(ls -1 $PEOPLE | wc -l)
    2.27  Logged users    : $(ls $sessions | wc -l)
    2.28 +</pre>
    2.29 +EOT
    2.30 +		
    2.31 +			# Last active user
    2.32 +			count=10
    2.33 +			echo "<h3>Last active users</h3>"
    2.34 +			echo "<pre>"
    2.35 +			find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last;
    2.36 +			do
    2.37 +				dir="$(dirname $last)"
    2.38 +				date="$(cat $last)"
    2.39 +				u=$(basename $dir)
    2.40 +				. "${PEOPLE}/${u}/account.conf"
    2.41 +			cat << EOT
    2.42 +$(get_gravatar $MAIL 24) $date  : <a href="?user=$u">$u</a> | $NAME
    2.43 +EOT
    2.44 +			done
    2.45 +			echo "</pre>"
    2.46 +			
    2.47 +			# Admin only
    2.48 +			if admin_user; then
    2.49 +				cat << EOT
    2.50 +<h3>Config paths</h3>
    2.51 +<pre>
    2.52  People DB       : $PEOPLE
    2.53  Auth file       : $AUTH_FILE
    2.54 +</pre>
    2.55  EOT
    2.56 -		
    2.57 -		echo "</pre>"
    2.58 +				# Get the list of administrators
    2.59 +				echo "<h3>Admin users</h3>"
    2.60 +				fgrep -l "ADMIN_USER=" $PEOPLE/*/account.conf | while read file;
    2.61 +				do
    2.62 +					. ${file}
    2.63 +					echo "<a href='?user=$USER'>$USER</a>"
    2.64 +					unset NAME USER
    2.65 +				done
    2.66 +			fi
    2.67 +			
    2.68 +		else
    2.69 +			gettext "You must be logged to check or admin users"
    2.70 +		fi
    2.71  		html_footer && exit 0 ;;
    2.72  		
    2.73  	*\ userslist\ *)
    2.74 @@ -59,12 +98,12 @@
    2.75  		fi
    2.76  		users=$(ls -1 $PEOPLE | wc -l)
    2.77  		cat << EOT
    2.78 -<h2>Users: $users</h2>
    2.79  <div id="tools">
    2.80  	<a href="$script?dashboard">Dashboard</a>
    2.81  	<a href="$script?users">Users admin</a>
    2.82  	<a href='$script?loggedusers'>Logged users</a>
    2.83  </div>
    2.84 +<h2>Users: $users</h2>
    2.85  <pre>
    2.86  EOT
    2.87  		for u in $(ls $PEOPLE)
    2.88 @@ -97,11 +136,11 @@
    2.89  		fi
    2.90  		logged="$(ls $sessions | wc -l)"
    2.91  		cat << EOT
    2.92 -<h2>Logged users: $logged</h2>
    2.93  <div id="tools">
    2.94  	<a href="$script?dashboard">Dashboard</a>
    2.95 -	<a href="$script?users">Users admin</a>
    2.96 +	<a href="$script?users">Users</a>
    2.97  </div>
    2.98 +<h2>Logged users: $logged</h2>
    2.99  <pre>
   2.100  EOT
   2.101  		for u in $(ls $sessions)
     3.1 --- a/plugins/users/users.conf	Mon Feb 20 02:20:44 2017 +0100
     3.2 +++ b/plugins/users/users.conf	Mon Feb 20 13:33:04 2017 +0100
     3.3 @@ -6,7 +6,7 @@
     3.4  
     3.5  # Authenticated users
     3.6  PLUGINS_TOOLS="${PLUGINS_TOOLS}"
     3.7 -DASHBOARD_TOOLS="${DASHBOARD_TOOLS}"
     3.8 +DASHBOARD_TOOLS="${DASHBOARD_TOOLS} <a href='?users'>Users</a>"
     3.9  
    3.10  # Admin only in Dashboard
    3.11 -ADMIN_TOOLS="${ADMIN_TOOLS} <a href='?users'>Users</a>"
    3.12 +ADMIN_TOOLS="${ADMIN_TOOLS}"