# HG changeset patch # User Christophe Lincoln # Date 1487634691 -3600 # Node ID 039c90c6049422ad4c8970f343a53b0fb98341fc # Parent 3698cf81f88409882aced6eb2778df8d781282fa Use new admin config and up users plugins from TinyCM diff -r 3698cf81f884 -r 039c90c60494 web/bugs.cgi --- a/web/bugs.cgi Mon Feb 13 17:45:24 2017 +0100 +++ b/web/bugs.cgi Tue Feb 21 00:51:31 2017 +0100 @@ -4,7 +4,7 @@ # # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License # -. /usr/lib/slitaz/httphelper +. /usr/lib/slitaz/httphelper.sh # Source config file . ./config.cgi @@ -112,7 +112,7 @@ # Check if user is admin admin_user() { - fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf + fgrep -w -q "$user" ${ADMIN_USERS} } # Authenticated or not @@ -543,30 +543,21 @@ # Create a new user in AUTH_FILE and PEOPLE new_user_config() { - if [ ! "$online" ]; then - name="$(GET name)" - mail="$(GET mail)" - pass="$(GET pass)" - echo "Creating Server Key..." + if [ ! -f "$AUTH_FILE" ]; then + touch $AUTH_FILE && chmod 0600 $AUTH_FILE fi - #key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}') echo "$user:$pass" >> $AUTH_FILE - mkdir -pm0700 $PEOPLE/$user/ + mkdir -pm0700 $PEOPLE/${user} cat > $PEOPLE/$user/account.conf << EOT -# SliTaz user configuration -# - +# User configuration NAME="$name" USER="$user" MAIL="$mail" - -LOCATION="$(GET location)" -RELEASES="$(GET releases)" -PACKAGES="$(GET packages)" EOT chmod 0600 $PEOPLE/$user/account.conf - if [ ! -f $PEOPLE/$user/account.conf ]; then - echo "ERROR: User creation failed!" + # First created user is admin + if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then + echo "$user" > ${ADMIN_USERS} fi } diff -r 3698cf81f884 -r 039c90c60494 web/config.cgi --- a/web/config.cgi Mon Feb 13 17:45:24 2017 +0100 +++ b/web/config.cgi Tue Feb 21 00:51:31 2017 +0100 @@ -1,12 +1,12 @@ # SliTaz Bug Tracker Web interface configuration. # -# TazBug URL for redirection and RSS -WEB_URL="http://localhost/bugs/bugs.cgi" - # Auth file for user AUTH_FILE="/var/lib/slitaz/auth/people" +# Admin users file list +ADMIN_USERS="/var/lib/slitaz/auth/admin" + # People config files PEOPLE="/var/lib/slitaz/people" diff -r 3698cf81f884 -r 039c90c60494 web/plugins/dashboard/dashboard.cgi --- a/web/plugins/dashboard/dashboard.cgi Mon Feb 13 17:45:24 2017 +0100 +++ b/web/plugins/dashboard/dashboard.cgi Tue Feb 21 00:51:31 2017 +0100 @@ -26,55 +26,42 @@ fi if check_auth; then cat << EOT -

Dashboard

-
$DASHBOARD_TOOLS $ADMIN_TOOLS
- +

Dashboard

 Bugs count       : $bugs
 Database size    : $bugsize
 Server uptime    :$(uptime | cut -d "," -f 1-2)
 
- -

Admin users

EOT - - # Get the list of administrators - fgrep -l "ADMIN_USER=" $PEOPLE/*/account.conf | while read file; - do - . ${file} - echo "$USER" - unset NAME USER - done - + # Only for admins if check_auth && admin_user; then # List all plugins cat << EOT -

$(gettext "Plugins")

-
-	
-		
-			
-			
-			
-		
+

$(gettext "Plugins:") $(ls $plugins | wc -l)

+
+
$(gettext "Name")$(gettext "Description")$(gettext "Action")
+ + + + + EOT for p in $(ls -1 $plugins) do . $plugins/$p/$p.conf cat << EOT - - - - - + + + + + EOT done - echo "
$(gettext "Name")$(gettext "Description")$(gettext "Action")
$PLUGIN$SHORT_DESCTODO
$PLUGIN$SHORT_DESCTODO
" - echo "
" + echo "" fi else gettext "You must be logged in to view the dashboard" diff -r 3698cf81f884 -r 039c90c60494 web/plugins/debug/debug.cgi --- a/web/plugins/debug/debug.cgi Mon Feb 13 17:45:24 2017 +0100 +++ b/web/plugins/debug/debug.cgi Tue Feb 21 00:51:31 2017 +0100 @@ -13,10 +13,10 @@ exit 0 fi cat << EOT -

Debug interface

Dashboard
+

Debug interface

EOT # Handle ?debug&del request if [ "$(GET del)" ]; then diff -r 3698cf81f884 -r 039c90c60494 web/plugins/users/users.cgi --- a/web/plugins/users/users.cgi Mon Feb 13 17:45:24 2017 +0100 +++ b/web/plugins/users/users.cgi Tue Feb 21 00:51:31 2017 +0100 @@ -13,23 +13,30 @@ cat << EOT Email : $MAIL -EOT - # Each user can have personal profile page - if [ -f "$PEOPLE/$USER/profile.txt" ]; then - cat << EOT +
+ $PLUGINS_TOOLS $(gettext "Modify profile") - Dashboard
EOT - else - cat << EOT -
- $(gettext "Create a profile page") - Dashboard -
+} + +# List last active users. Usage: last_users NB +list_last_users() { + count=${1} + echo "

Last $count active users

" + echo "
"
+	find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last;
+	do
+		dir="$(dirname $last)"
+		date="$(cat $last)"
+		u=$(basename $dir)
+		. "${PEOPLE}/${u}/account.conf"
+	cat << EOT
+$(get_gravatar $MAIL 24) $date  : $u | $NAME
 EOT
-	fi
+	done
+	echo "
" } case " $(GET) " in @@ -38,28 +45,54 @@ header html_header user_box - if check_auth && ! admin_user; then - gettext "You must be admin to manage users" && exit 0 + # Admin only + if admin_user; then + tools="Users list" fi - cat << EOT -

Users admin

+ # Logged users + if check_auth; then + cat << EOT
Dashboard - Logged users - Users list + Last users + $tools
+

${d}

 User accounts   : $(ls -1 $PEOPLE | wc -l)
 Logged users    : $(ls $sessions | wc -l)
+
+EOT + list_last_users 5 + + # Admin only + if admin_user; then + cat << EOT +

Config paths

+
 People DB       : $PEOPLE
-Auth file       : $AUTH_FILE
+Authfile        : $AUTH_FILE
+Admin users     : $ADMIN_USERS
+
EOT - - echo "" + # Get the list of administrators + echo "

Admin users

" + echo "
"
+				for u in $(cat $ADMIN_USERS)
+				do
+					. ${PEOPLE}/${u}/account.conf
+					echo "$u - $NAME"
+				done
+				echo "
" + fi + + else + gettext "You must be logged to check or admin users" + fi html_footer && exit 0 ;; *\ userslist\ *) - # List all users (slow if a lot a of accounts) + # List all users d="Users" header html_header @@ -70,13 +103,18 @@ fi users=$(ls -1 $PEOPLE | wc -l) cat << EOT -

Users: $users

Dashboard - Users admin - Logged users + Users + Last users
-
+

Users: $users

+
+ + + + + EOT for u in $(ls $PEOPLE) do @@ -85,20 +123,22 @@ echo "${u} : Missing account.conf" continue fi - . "${PEOPLE}/${u}/account.conf" cat << EOT -$(get_gravatar $MAIL 24) $USER | $NAME | $MAIL + + + + EOT # deluser link --> use 'tazu' on SliTaz #: $(gettext "delete") unset NAME USER done - echo "" + echo "
$(gettext "Username")$(gettext "Action")
$uTODO
" html_footer && exit 0 ;; - *\ loggedusers\ *) + *\ lastusers\ *) # Show online users based on sessions files. - d="Logged users" + d="Last users" header html_header user_box @@ -106,15 +146,17 @@ gettext "You must be logged in to view online users" exit 0 fi - logged="$(ls $sessions | wc -l)" cat << EOT -

Logged users: $logged

-
 EOT
+		list_last_users 15
+		
+		# Active cookies
+		echo "

Session cookies: $(ls $sessions | wc -l)

" + echo "
"
 		for u in $(ls $sessions)
 		do
 			. "${PEOPLE}/${u}/account.conf"
@@ -132,7 +174,15 @@
 		header
 		html_header
 		user_box
-		. $PEOPLE/"$(GET user)"/account.conf
+		account_config="$PEOPLE/$(GET user)/account.conf"
+		profile_config="$PEOPLE/$(GET user)/profile.conf"
+		if [ ! -f "$account_config" ]; then
+			echo "No user profile for: $(GET user)"
+			html_footer && exit 0
+		else
+			. ${account_config}
+		fi
+		[ -f "$profile_config" ] && . ${profile_config}
 cat << EOT
 

$(get_gravatar $MAIL) $NAME

@@ -147,6 +197,18 @@ . $PEOPLE/"$(GET user)"/account.conf public_people fi + + # Messages plugin integration + if [ -x "$plugins/messages/messages.cgi" ]; then + if check_auth && [ "$(GET user)" != "$user" ]; then + cat << EOT + +EOT + fi + fi + # Display personal user profile if [ -f "$PEOPLE/$USER/profile.txt" ]; then echo "

$(gettext "About me")

" diff -r 3698cf81f884 -r 039c90c60494 web/plugins/users/users.conf --- a/web/plugins/users/users.conf Mon Feb 13 17:45:24 2017 +0100 +++ b/web/plugins/users/users.conf Tue Feb 21 00:51:31 2017 +0100 @@ -6,9 +6,7 @@ # Authenticated users PLUGINS_TOOLS="${PLUGINS_TOOLS}" -DASHBOARD_TOOLS="${DASHBOARD_TOOLS}" +DASHBOARD_TOOLS="${DASHBOARD_TOOLS} Users" # Admin only in Dashboard -ADMIN_TOOLS="${ADMIN_TOOLS} Users" - -# Configurable variables used in plugin.cgi +ADMIN_TOOLS="${ADMIN_TOOLS}" diff -r 3698cf81f884 -r 039c90c60494 web/style.css --- a/web/style.css Mon Feb 13 17:45:24 2017 +0100 +++ b/web/style.css Tue Feb 21 00:51:31 2017 +0100 @@ -220,3 +220,11 @@ } #footer a { padding: 0 2px; } + +/* Users & Dashboard */ +#users table, #plugins table { border-collapse: collapse; } +#users tr, #plugins tr { + padding:.3em 1em; + border-bottom: 1px solid #ddd; +} +#users td, #plugins td { padding: 4px 0; }