View Single Post
laasonen's Avatar
Posts: 565 | Thanked: 618 times | Joined on Jun 2010 @ Finland
#1
I made simple script which notifies about users trying to connect or disconnect to SSH-server. I thought that some others might be also interested what someones are trying to do with our phones.

Phone version
How?
  • apt-get install sysklogd sudser
  • Uncomment the line about /var/log/auth.log from /etc/syslog.conf
  • stop sysklogd; start sysklogd
  • Run the script
Problems:
  • Sysklogd doesn't give disconnecter's name so only ip is shown when user disconnects from the server
Script:
Code:
sudo tail -f /var/log/auth.log | while read line; do
	id=$((id+1));
	if [[ $id -gt 10 ]]; then
		if [[ `echo $line | awk '{print $5}' | awk -F [ '{print $1}'` == "sshd" ]]; then
			if [[ `echo $line | awk '{print $6}'` == Failed ]]; then
			dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"`echo $line | awk '{print $9}'` failed to log in to SSH from `echo $line | awk '{print $11}'`";
			else
				if [[ `echo $line | awk '{print $6}'` == Accepted ]]; then
					dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"`echo $line | awk '{print $9}'` succefully logged in to SSH from `echo $line | awk '{print $11}'`";
				else
					if [[ `echo $line | awk '{print $6}'` == Received ]] && [[ `echo $line | awk '{print $7}'` == disconnect ]]; then
						dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"`echo $line | awk '{print $9}' | awk -F : '{print $1}'` disconnected from SSH";
					fi
				fi
			fi
		fi
	fi
done
Screenshot:


Desktop version
Requirements:
  • syslog-ng
  • >=bash
  • libnotify
Script:
Code:
ip=""
sudo tail -f /var/log/auth.log | while read line; do
	id=$((id+1));
	if [[ $id -gt 10 ]]; then
		if [ -n "$ip" ]; then
			notify-send "SSH Notifier" "`echo $line | awk '{print $11}'` disconnected from SSH from $ip!";
			ip=""
		else
			if [[ `echo $line | awk '{print $5}'` == sshd* ]]; then
				if [[ `echo $line | awk '{print $6}'` == Failed ]]; then
					notify-send "SSH Notifier" "`echo $line | awk '{print $9}'` failed to log in to SSH from `echo $line | awk '{print $11}'`!";
				else
					if [[ `echo $line | awk '{print $6}'` == Accepted ]]; then
						notify-send "SSH Notifier" "`echo $line | awk '{print $9}'` succefully logged in to SSH from `echo $line | awk '{print $11}'`!";
					else
						if [[ `echo $line | awk '{print $6}'` == Received ]] && [[ `echo $line | awk '{print $7}'` == disconnect ]]; then
							ip=`echo $line | awk '{print $9}' | awk -F : '{print $1}'`
						fi
					fi
				fi
			fi
		fi
	fi
done
Screenshot:
__________________
Couple of my applications:
ConnLock - Advanced phone lock
Sanakirja.org - A Sanakirja.org dictionary client
Wlan Driver Selector Applet - Switch easily between stock and bleeding edge drivers

Last edited by laasonen; 2011-06-11 at 15:31.
 

The Following 6 Users Say Thank You to laasonen For This Useful Post: