Index: nxserver
===================================================================
--- nxserver	(revision 204)
+++ nxserver	(working copy)
@@ -31,7 +31,17 @@
 return 0
 }
 
+search ()
+{
+	if egrep $1 $2 >/dev/null 2>&1;
+	then
+		return 0
+	else
+		return 1
+	fi
+}
 
+
 ############### PACKAGE passdb.bm #######################
 #
 # Library of passdb functions (outsource)
@@ -55,8 +65,8 @@
 	PASSDB_PASS=$(egrep "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords 2>/dev/null | cut -d":" -f2)
 	if [ "$ENABLE_PASSDB_AUTHENTICATION" = "1" ]
 	then
-		egrep -q "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords 2>/dev/null && echo $PASSDB_PASS
-		egrep -q "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords 2>/dev/null || echo "NOT_VALID"
+		search "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords && echo $PASSDB_PASS
+		search "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords || echo "NOT_VALID"
 	else
 		echo "NOT_VALID"
 	fi
@@ -73,7 +83,7 @@
 passdb_user_exists()
 {
 	PASSDB_CHUSER="$1"
-	egrep -q "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords 2>/dev/null
+	search "^$PASSDB_CHUSER:" $NX_ETC_DIR/passwords
 }
 
 
@@ -135,7 +145,7 @@
 
 session_find_id_user()
 {
-	[ -f $NX_SESS_DIR/running/sessionId"{$1}" ] && egrep -q "^userName=$2$" $NX_SESS_DIR/running/sessionId"{$1}" && return 0
+	[ -f $NX_SESS_DIR/running/sessionId"{$1}" ] && search "^userName=$2$" $NX_SESS_DIR/running/sessionId"{$1}" && return 0
 	return 1
 }
 
@@ -145,7 +155,7 @@
 	for i in $NX_SESS_DIR/running/*
 	do
 		[ -f $i ] || break
-		egrep -q "^userName=$1$" $i && echo $i
+		search "^userName=$1$" $i && echo $i
 	done
 }
 
@@ -155,7 +165,7 @@
 	for i in $NX_SESS_DIR/running/*
 	do
 		[ -f $i ] || break
-		egrep -q "^display=$1$" $i && echo $i
+		search "^display=$1$" $i && echo $i
 	done
 }
 
@@ -181,7 +191,7 @@
 	for i in $NX_SESS_DIR/running/*
 	do
 		[ -f $i ] || break
-		if egrep -q "^userName=$1$" $i && egrep -q "^status=$2$" $i
+		if search "^userName=$1$" $i && search "^status=$2$" $i
 		then
 			CMDLINE=$(session_get_cmdline $i)
 			echo "$(getparam sessionId)"
@@ -202,7 +212,7 @@
 	do
 		[ -f $i ] || break
 		let SESSION_COUNT=$SESSION_COUNT+1
-		egrep -q "^userName=$1$" $i && let SESSION_COUNT_USER=$SESSION_COUNT_USER+1
+		search "^userName=$1$" $i && let SESSION_COUNT_USER=$SESSION_COUNT_USER+1
 	done
 }
 
@@ -229,7 +239,7 @@
 	do
 		[ -f $i ] || break
 		let SESSION_COUNT=$SESSION_COUNT+1
-		if egrep -q "^userName=$1$" $i && egrep -q "^status=$2$" $i #&& grep -q "screeninfo=$3" $i
+		if search "^userName=$1$" $i && search "^status=$2$" $i #&& grep -q "screeninfo=$3" $i
 		then
 			CMDLINE=$(session_get_cmdline $i)
 			depth=$(getparam screeninfo | cut -d "x" -f3 | cut -d "+" -f1 )
@@ -255,7 +265,7 @@
 			fi
 			printf "%-7s %-16s %32s %8s %5s %-14s %-11s %s\n" "$(getparam display)" "$(getparam type)" "$(getparam sessionId)" "$options" "$depth" "$geom" "$available" "$(getparam sessionName)" >> $TMPFILE
 		fi
-		egrep -q "^userName=$1$" $i && let SESSION_COUNT_USER=$SESSION_COUNT_USER+1
+		search "^userName=$1$" $i && let SESSION_COUNT_USER=$SESSION_COUNT_USER+1
 	done
 	echo "" >> $TMPFILE
 	echo "" >> $TMPFILE
@@ -278,10 +288,14 @@
 	for i in $NX_SESS_DIR/running/*
 	do
 		[ -f $i ] || break
-		if egrep -q "^userName=$1$" $i
+		if search "^userName=$1$" $i
 		then
 			CMDLINE=$(session_get_cmdline $i)
-			echo -e "$(getparam display)\t$(getparam userName)\t$(getparam foreignAddress)\t$(getparam sessionId)"
+			printf "%-7s %-15s %-15s %-32s\n" \
+			$(getparam display) \
+			$(getparam userName) \
+			$(getparam foreignAddress) \
+			$(getparam sessionId)
 		fi
 	done
 }
@@ -294,7 +308,7 @@
 	echo
 	echo "Display Username        Remote IP       Session ID                       Date                Status"
 	echo "------- --------------- --------------- -------------------------------- ------------------- -----------"
-	for j in $(ls --time-style +%s -la "$NX_SESS_DIR"/{closed,failed,running} | awk '/sessionId/ { print $6 " " $7 }' | sort -n | cut -d" " -f2)
+        for j in $(ls -at $NX_SESS_DIR/* | awk '/sessionId/ { print $1 }')
 	do
 		if [ -n "$sessionId" ]
 		then
@@ -307,7 +321,13 @@
 		then
 			[ "$userName" = "$(getparam userName)" ] || continue
 		fi
-		echo -e "$(getparam display)\t$(getparam userName)\t$(getparam foreignAddress)\t$(getparam sessionId)\t$(ls --time-style="+%F %X" -l $i | awk '/sessionId/ { print $6 " " $7 }')\t$(getparam status)"
+                date="$(ls -l $i | awk '/sessionId/ { print $6 " " $7 " " $8 }')"
+		printf "%-7s %-15s %-15s %-32s %-19s %-11s\n" \
+			"$(getparam display)" \
+			"$(getparam userName)" \
+			"$(getparam foreignAddress)" \
+			"$(getparam sessionId)" \
+			"$date" "$(getparam status)"
 	done
 }
 
@@ -330,7 +350,11 @@
 	do
 		[ -f $i ] || break
 		CMDLINE=$(session_get_cmdline $i)
-		echo -e "$(getparam display)\t$(getparam userName)\t$(getparam foreignAddress)\t$(getparam sessionId)"
+		printf "%-7s %-15s %-15s %-32s\n" \
+			$(getparam display) \
+			$(getparam userName) \
+			$(getparam foreignAddress) \
+			$(getparam sessionId)
 	done
 }
 
@@ -1311,7 +1335,7 @@
 cmd_passwd()
 {
 	CMD_CHUSER=$2
-	egrep -q "^$CMD_CHUSER:" $NX_ETC_DIR/passwords || cmd_abort "Error: User $CMD_CHUSER not found in database."
+	search "^$CMD_CHUSER:" $NX_ETC_DIR/passwords || cmd_abort "Error: User $CMD_CHUSER not found in database."
 	echo -n "New password: "
 	read -s CMD_NEWPASS
 	echo
@@ -1325,7 +1349,7 @@
 	CMD_CHUSER=$2
 	
 	[ ${#CMD_CHUSER} -ge 32 ] && cmd_abort "Error: User $CMD_CHUSER must be shorter than 32 characters."
-	egrep -q "^$CMD_CHUSER:" $NX_ETC_DIR/passwords && cmd_abort "Error: User $CMD_CHUSER already in database."
+	search "^$CMD_CHUSER:" $NX_ETC_DIR/passwords && cmd_abort "Error: User $CMD_CHUSER already in database."
 	getent passwd "$CMD_CHUSER" >/dev/null || cmd_abort "Error: User $CMD_CHUSER not existing on local system. Can't add."
 	passdb_add_user "$CMD_CHUSER"
 }
@@ -1333,7 +1357,7 @@
 cmd_deluser()
 {
 	CMD_CHUSER=$2
-	egrep -q "^$CMD_CHUSER:" $NX_ETC_DIR/passwords || cmd_abort "Error: User $CMD_CHUSER not found in database."
+	search "^$CMD_CHUSER:" $NX_ETC_DIR/passwords || cmd_abort "Error: User $CMD_CHUSER not found in database."
 	passdb_remove_user "$CMD_CHUSER"
 }
 
