tazbug diff web/plugins/users/users.cgi @ 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 39a59a1271e5
children 7bf28563c0f6
line diff
     1.1 --- a/web/plugins/users/users.cgi	Sun Feb 12 09:09:36 2017 +0000
     1.2 +++ b/web/plugins/users/users.cgi	Tue Feb 21 00:51:31 2017 +0100
     1.3 @@ -13,23 +13,30 @@
     1.4  	cat << EOT
     1.5  Email      : $MAIL
     1.6  </pre>
     1.7 -EOT
     1.8 -	# Each user can have personal profile page
     1.9 -	if [ -f "$PEOPLE/$USER/profile.txt" ]; then
    1.10 -		cat << EOT
    1.11 +
    1.12  <div id="tools">
    1.13 +	$PLUGINS_TOOLS
    1.14  	<a href="$script?modprofile">$(gettext "Modify profile")</a>
    1.15 -	<a href="$script?dashboard">Dashboard</a>
    1.16  </div>
    1.17  EOT
    1.18 -	else
    1.19 -		cat << EOT
    1.20 -<div id="tools">
    1.21 -	<a href="$script?modprofile">$(gettext "Create a profile page")</a>
    1.22 -	<a href="$script?dashboard">Dashboard</a>
    1.23 -</div>
    1.24 +}
    1.25 +
    1.26 +# List last active users. Usage: last_users NB
    1.27 +list_last_users() {
    1.28 +	count=${1}
    1.29 +	echo "<h3>Last $count active users</h3>"
    1.30 +	echo "<pre>"
    1.31 +	find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last;
    1.32 +	do
    1.33 +		dir="$(dirname $last)"
    1.34 +		date="$(cat $last)"
    1.35 +		u=$(basename $dir)
    1.36 +		. "${PEOPLE}/${u}/account.conf"
    1.37 +	cat << EOT
    1.38 +$(get_gravatar $MAIL 24) $date  : <a href="?user=$u">$u</a> | $NAME
    1.39  EOT
    1.40 -	fi
    1.41 +	done
    1.42 +	echo "</pre>"
    1.43  }
    1.44  
    1.45  case " $(GET) " in
    1.46 @@ -38,28 +45,54 @@
    1.47  		header
    1.48  		html_header
    1.49  		user_box
    1.50 -		if check_auth && ! admin_user; then
    1.51 -			gettext "You must be admin to manage users" && exit 0
    1.52 +		# Admin only
    1.53 +		if admin_user; then
    1.54 +			tools="<a href='$script?userslist'>Users list</a>"
    1.55  		fi
    1.56 -		cat << EOT
    1.57 -<h2>Users admin</h2>
    1.58 +		# Logged users
    1.59 +		if check_auth; then
    1.60 +			cat << EOT
    1.61  <div id="tools">
    1.62  	<a href="$script?dashboard">Dashboard</a>
    1.63 -	<a href='$script?loggedusers'>Logged users</a>
    1.64 -	<a href='$script?userslist'>Users list</a>
    1.65 +	<a href='$script?lastusers'>Last users</a>
    1.66 +	$tools
    1.67  </div>
    1.68 +<h2>${d}</h2>
    1.69  <pre>
    1.70  User accounts   : $(ls -1 $PEOPLE | wc -l)
    1.71  Logged users    : $(ls $sessions | wc -l)
    1.72 +</pre>
    1.73 +EOT
    1.74 +			list_last_users 5
    1.75 +			
    1.76 +			# Admin only
    1.77 +			if admin_user; then
    1.78 +				cat << EOT
    1.79 +<h3>Config paths</h3>
    1.80 +<pre>
    1.81  People DB       : $PEOPLE
    1.82 -Auth file       : $AUTH_FILE
    1.83 +Authfile        : $AUTH_FILE
    1.84 +Admin users     : $ADMIN_USERS
    1.85 +</pre>
    1.86  EOT
    1.87 -		
    1.88 -		echo "</pre>"
    1.89 +				# Get the list of administrators
    1.90 +				echo "<h3>Admin users</h3>"
    1.91 +				echo "<pre>"
    1.92 +				for u in $(cat $ADMIN_USERS)
    1.93 +				do
    1.94 +					. ${PEOPLE}/${u}/account.conf
    1.95 +					echo "<a href='?user=$u'>$u</a> - $NAME"
    1.96 +				done
    1.97 +				echo "</pre>"
    1.98 +			fi
    1.99 +			
   1.100 +		else
   1.101 +			gettext "You must be logged to check or admin users"
   1.102 +		fi
   1.103  		html_footer && exit 0 ;;
   1.104  		
   1.105  	*\ userslist\ *)
   1.106 -		# List all users (slow if a lot a of accounts)
   1.107 +		# List all users
   1.108  		d="Users"
   1.109  		header
   1.110  		html_header
   1.111 @@ -70,13 +103,18 @@
   1.112  		fi
   1.113  		users=$(ls -1 $PEOPLE | wc -l)
   1.114  		cat << EOT
   1.115 -<h2>Users: $users</h2>
   1.116  <div id="tools">
   1.117  	<a href="$script?dashboard">Dashboard</a>
   1.118 -	<a href="$script?users">Users admin</a>
   1.119 -	<a href='$script?loggedusers'>Logged users</a>
   1.120 +	<a href="$script?users">Users</a>
   1.121 +	<a href='$script?lastusers'>Last users</a>
   1.122  </div>
   1.123 -<pre>
   1.124 +<h2>Users: $users</h2>
   1.125 +<div id="users">
   1.126 +<table>
   1.127 +	<thead>
   1.128 +		<td>$(gettext "Username")</td>
   1.129 +		<td>$(gettext "Action")</td>
   1.130 +	</thead>
   1.131  EOT
   1.132  		for u in $(ls $PEOPLE)
   1.133  		do
   1.134 @@ -85,20 +123,22 @@
   1.135  				echo "${u} : Missing account.conf"
   1.136  				continue
   1.137  			fi
   1.138 -			. "${PEOPLE}/${u}/account.conf"
   1.139  			cat << EOT
   1.140 -$(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL
   1.141 +	<tr>
   1.142 +		<td><a href="$script?user=$u">$u</a></td>
   1.143 +		<td>TODO</td>
   1.144 +	</tr>
   1.145  EOT
   1.146  # deluser link --> use 'tazu' on SliTaz
   1.147  #: <a href="?users&amp;deluser=$USER">$(gettext "delete")</a>
   1.148  			unset NAME USER 
   1.149  		done
   1.150 -		echo "</pre>" 
   1.151 +		echo "</table></div>"
   1.152  		html_footer && exit 0 ;;
   1.153  	
   1.154 -	*\ loggedusers\ *)
   1.155 +	*\ lastusers\ *)
   1.156  		# Show online users based on sessions files.
   1.157 -		d="Logged users"
   1.158 +		d="Last users"
   1.159  		header
   1.160  		html_header
   1.161  		user_box
   1.162 @@ -106,15 +146,17 @@
   1.163  			gettext "You must be logged in to view online users"
   1.164  			exit 0
   1.165  		fi
   1.166 -		logged="$(ls $sessions | wc -l)"
   1.167  		cat << EOT
   1.168 -<h2>Logged users: $logged</h2>
   1.169  <div id="tools">
   1.170  	<a href="$script?dashboard">Dashboard</a>
   1.171 -	<a href="$script?users">Users admin</a>
   1.172 +	<a href="$script?users">Users</a>
   1.173  </div>
   1.174 -<pre>
   1.175  EOT
   1.176 +		list_last_users 15
   1.177 +		
   1.178 +		# Active cookies
   1.179 +		echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>"
   1.180 +		echo "<pre>"
   1.181  		for u in $(ls $sessions)
   1.182  		do
   1.183  			. "${PEOPLE}/${u}/account.conf"
   1.184 @@ -132,7 +174,15 @@
   1.185  		header
   1.186  		html_header
   1.187  		user_box
   1.188 -		. $PEOPLE/"$(GET user)"/account.conf
   1.189 +		account_config="$PEOPLE/$(GET user)/account.conf"
   1.190 +		profile_config="$PEOPLE/$(GET user)/profile.conf"
   1.191 +		if [ ! -f "$account_config" ]; then
   1.192 +			echo "No user profile for: $(GET user)"
   1.193 +			html_footer && exit 0
   1.194 +		else
   1.195 +			. ${account_config}
   1.196 +		fi
   1.197 +		[ -f "$profile_config" ] && . ${profile_config}
   1.198  cat << EOT
   1.199  <h2>$(get_gravatar $MAIL) $NAME</h2>
   1.200  
   1.201 @@ -147,6 +197,18 @@
   1.202  			. $PEOPLE/"$(GET user)"/account.conf
   1.203  			public_people
   1.204  		fi
   1.205 +		
   1.206 +		# Messages plugin integration
   1.207 +		if [ -x "$plugins/messages/messages.cgi" ]; then
   1.208 +			if check_auth && [ "$(GET user)" != "$user" ]; then
   1.209 +				cat << EOT
   1.210 +<div id="tools">
   1.211 +<a href="$script?messages&amp;to=$(GET user)">$(gettext "Send message")</a>
   1.212 +</div>
   1.213 +EOT
   1.214 +			fi
   1.215 +		fi
   1.216 +		
   1.217  		# Display personal user profile
   1.218  		if [ -f "$PEOPLE/$USER/profile.txt" ]; then
   1.219  			echo "<h2>$(gettext "About me")</h2>"