Generic handling of SSH_FORWARDED overrides.
authorIain Patterson <me@iain.cx>
Wed, 22 Apr 2009 18:39:01 +0000 (14:39 -0400)
committerIain Patterson <me@iain.cx>
Wed, 22 Apr 2009 18:45:50 +0000 (14:45 -0400)
Check if the remote IP address matches a regular expression from
~/.ssh/forwarded and append " (from <hostname>)" to the PROMPT_COMMAND
only if not.

.profile.d/prompt.bashrc

index a80c615..6398e3d 100644 (file)
@@ -1,13 +1,18 @@
-# Set the title of an xterm to the hostname.
-#
-
-SSH_FORWARDED=$(get_remote_ip -n)
+# Set the title of an xterm to the hostname unless the remote IP is matched by 
+# a regular expression in ~/.ssh/forwarded.
+SSH_FORWARDED=$(get_remote_ip)
 if [ ! -z "$SSH_FORWARDED" ]; then
 if [ ! -z "$SSH_FORWARDED" ]; then
-  if [ ! "$SSH_FORWARDED" = "62.189.242.202" -a ! "$SSH_FORWARDED" = "62.189.241.202" -a ! "$SSH_FORWARDED" = "193.128.72.68" -a ! "$SSH_FORWARDED" = "localhost" ]; then
-    SSH_FORWARDED=" (from $SSH_FORWARDED)"
-  else
+  if [ "$SSH_FORWARDED" = "localhost" ]; then
     SSH_FORWARDED=
     SSH_FORWARDED=
+  elif [ -f ~/.ssh/forwarded ]; then
+    for forwarded in $(< ~/.ssh/forwarded); do
+      if echo "$SSH_FORWARDED" | grep "$forwarded" &>/dev/null; then
+        SSH_FORWARDED=
+      fi
+    done
+    unset forwarded
   fi
   fi
+  [ ! -z "$SSH_FORWARDED" ] && SSH_FORWARDED=" (from $(get_remote_ip -n))"
 fi
 
 # Unscientific check for grid jobs.
 fi
 
 # Unscientific check for grid jobs.