tazbug diff web/plugins/debug/debug.cgi @ rev 132

Bettercount of messages and del file + debug empty messages
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 21 16:39:16 2017 +0100 (2017-02-21)
parents 039c90c60494
children f07cd117feed
line diff
     1.1 --- a/web/plugins/debug/debug.cgi	Tue Feb 21 00:51:31 2017 +0100
     1.2 +++ b/web/plugins/debug/debug.cgi	Tue Feb 21 16:39:16 2017 +0100
     1.3 @@ -9,14 +9,16 @@
     1.4  	html_header
     1.5  	user_box
     1.6  	if check_auth && ! admin_user; then
     1.7 -		gettext "You must be admin to debug"
     1.8 -		exit 0
     1.9 +		echo "You must be admin to debug" && exit 0
    1.10  	fi
    1.11  	cat << EOT
    1.12  <div id="tools">
    1.13  	<a href="$script?dashboard">Dashboard</a>
    1.14  </div>
    1.15  <h2>Debug interface</h2>
    1.16 +<p>
    1.17 +	Check for corrupted config files and empty messages.
    1.18 +</p>
    1.19  EOT
    1.20  	# Handle ?debug&del request
    1.21  	if [ "$(GET del)" ]; then
    1.22 @@ -34,13 +36,64 @@
    1.23  	do
    1.24  		if [ $(cat ${bugdir}/${id}/bug.conf | wc -l) != 8 ]; then
    1.25  			echo "<pre>"
    1.26 -			echo -e "ERROR: bug ID $id - <a href='?edit=$id'>Edit</a>\
    1.27 - - <a href='?debug&amp;del=$id'>Delete</a>\n"
    1.28 +			echo -n "ERROR: bug ID $id"
    1.29 +			# Missing bug.conf
    1.30 +			if [ ! -f "${bugdir}/${id}/bug.conf" ]; then
    1.31 +				echo -n " - Missing: bug.conf"
    1.32 +			fi
    1.33 +			# Empty bug.conf
    1.34 +			if [ -s "${bugdir}/${id}/bug.conf" ]; then
    1.35 +				echo -n " - <a href='?editbug=$id'>Edit</a>"
    1.36 +			else
    1.37 +				echo -n " - Empty: bug.conf"
    1.38 +			fi
    1.39 +			echo " - <a href='?debug&amp;del=$id'>Delete</a>"
    1.40  			cat ${bugdir}/${id}/bug.conf
    1.41  			echo "</pre>"
    1.42 +		else
    1.43 +			# Empty values
    1.44 +			. ${bugdir}/${id}/bug.conf
    1.45 +			[ -n "$BUG" ] || miss="1"
    1.46 +			[ -n "$STATUS" ] || miss="1"
    1.47 +			[ -n "$PRIORITY" ] || miss="1"
    1.48 +			[ -n "$CREATOR" ] || miss="1"
    1.49 +			[ -n "$DATE" ] || miss="1"
    1.50 +			if [ "$miss" ]; then
    1.51 +				echo "<pre>"
    1.52 +				echo "ERROR: bug ID $id - Empty variable(s) - <a href='?debug&amp;del=$id'>Delete</a>"
    1.53 +				cat ${bugdir}/${id}/bug.conf
    1.54 +				echo "</pre>"
    1.55 +			fi
    1.56  		fi
    1.57 +		unset miss
    1.58  	done
    1.59  	echo "$(ls -1 $bugdir | wc -l) bugs scanned"
    1.60  	
    1.61 +	# Check for messages consistency
    1.62 +	echo "<h3>Checking for empty messages</h3>"
    1.63 +	msgs=$(find $bugdir -name msg.* | wc -l)
    1.64 +	empty=$(find $bugdir -name msg.* -size 0)
    1.65 +	if  [ "$empty" ]; then
    1.66 +		echo "<pre>"
    1.67 +		cd ${bugdir}
    1.68 +		for msg in */msg.*
    1.69 +		do
    1.70 +			if [ ! -s "$msg" ]; then
    1.71 +				# Delete msg ?
    1.72 +				if [ "$(GET delmsgs)" ]; then
    1.73 +					echo "Deleting empty message: $(basename $bugdir)/$msg"
    1.74 +					rm -f ${bugdir}/${msg}
    1.75 +				else
    1.76 +					echo "Found empty message: $(basename $bugdir)/$msg"
    1.77 +				fi
    1.78 +			fi
    1.79 +		done
    1.80 +		if [ ! "$(GET delmsgs)" ]; then
    1.81 +			echo "--&gt; <a href='?debug&amp;delmsgs'>Delete empty messages</a>"
    1.82 +		fi
    1.83 +		echo "</pre>"
    1.84 +	fi
    1.85 +	echo "$msgs messages scanned"
    1.86 +	
    1.87  	html_footer & exit 0
    1.88  fi