Last active
July 20, 2020 08:42
-
-
Save etenzy/d542f3fad7a3ae59ce828178122a0aa6 to your computer and use it in GitHub Desktop.
Automatically step thru ssh proxies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
on trim(theseCharacters, someText) | |
if class of someText is text and length of someText > 0 then | |
-- default values (all whitespace) | |
if theseCharacters is true then ¬ | |
set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0} | |
repeat until first character of someText is not in theseCharacters | |
set someText to text 2 thru -1 of someText | |
end repeat | |
repeat until last character of someText is not in theseCharacters | |
set someText to text 1 thru -2 of someText | |
end repeat | |
end if | |
return someText | |
end trim | |
on run input | |
set proxyUser to "PROXY_USER" | |
set proxyHost to "PROXY_HOST" | |
set proxyPass to "PROXY_PASSWORD" | |
# 0 - 255 | |
set RED to 0 | |
set GREEN to 0 | |
set BLUE to 0 | |
# 0 - 100 % | |
set OPACITY to 50 | |
if (count input) = 4 then | |
set user to item 1 of input | |
set hostname to item 2 of input | |
# set a password is against the rules ;) | |
set ninja to item 3 of input | |
set type to item 4 of input | |
else | |
return "Usage: ssh-proxy user hostname password {prod|qs}" | |
end if | |
if type = "prod" then | |
set RED to 61 | |
set GREEN to 0 | |
set BLUE to 0 | |
set OPACITY to 40 | |
else | |
if type = "qs" then | |
set RED to 0 | |
set GREEN to 61 | |
set BLUE to 0 | |
set OPACITY to 40 | |
end if | |
end if | |
tell application "iTerm2" | |
activate | |
tell current session of current window | |
set background color to {(RED*65535/255), (GREEN*65535/255), (BLUE*65535/255), (OPACITY*65535/100)} | |
set a to 0 | |
repeat until (a = 1) | |
if (is processing = false) | |
set a to 1 | |
end if | |
end repeat | |
write text "ssh " & (proxyUser) & "@" & (proxyHost) | |
set b to 0 | |
repeat until (b = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set b to 1 | |
end if | |
end repeat | |
write text (proxyPass) | |
set c to 0 | |
repeat until (c = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Auswahl?")) | |
set c to 1 | |
end if | |
end repeat | |
write text "9" | |
set d to 0 | |
repeat until (d = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Benutzername?")) | |
set d to 1 | |
end if | |
end repeat | |
write text (user) | |
set e to 0 | |
repeat until (e = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Hostname?")) | |
set e to 1 | |
end if | |
end repeat | |
write text (hostname) | |
set f to 0 | |
repeat until (f = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set f to 1 | |
end if | |
end repeat | |
write text (ninja) | |
end tell | |
end tell | |
end run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
on trim(theseCharacters, someText) | |
if class of someText is text and length of someText > 0 then | |
-- default values (all whitespace) | |
if theseCharacters is true then ¬ | |
set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0} | |
repeat until first character of someText is not in theseCharacters | |
set someText to text 2 thru -1 of someText | |
end repeat | |
repeat until last character of someText is not in theseCharacters | |
set someText to text 1 thru -2 of someText | |
end repeat | |
end if | |
return someText | |
end trim | |
on run input | |
set proxyUser to "PROXY_USER" | |
set proxyHost to "PROXY_HOST" | |
set proxyPass to "PROXY_PASSWORD" | |
# 0 - 255 | |
set RED to 0 | |
set GREEN to 0 | |
set BLUE to 0 | |
# 0 - 100 % | |
set OPACITY to 50 | |
if (count input) = 4 then | |
set user to item 1 of input | |
set hostname to item 2 of input | |
# set a password is against the rules ;) | |
set ninja to item 3 of input | |
set type to item 4 of input | |
else | |
return "Usage: ssh-proxy user hostname password {prod|qs}" | |
end if | |
if type = "prod" then | |
set RED to 61 | |
set GREEN to 0 | |
set BLUE to 0 | |
set OPACITY to 40 | |
else | |
if type = "qs" then | |
set RED to 0 | |
set GREEN to 61 | |
set BLUE to 0 | |
set OPACITY to 40 | |
end if | |
end if | |
tell application "iTerm2" | |
activate | |
tell current window | |
set newTab to (create tab with default profile) | |
tell current session of newTab | |
set background color to {(RED*65535/255), (GREEN*65535/255), (BLUE*65535/255), (OPACITY*65535/100)} | |
set a to 0 | |
repeat until (a = 1) | |
if (is processing = false) | |
set a to 1 | |
end if | |
end repeat | |
write text "ssh " & (proxyUser) & "@" & (proxyHost) | |
set b to 0 | |
repeat until (b = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set b to 1 | |
end if | |
end repeat | |
write text (proxyPass) | |
set c to 0 | |
repeat until (c = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Auswahl?")) | |
set c to 1 | |
end if | |
end repeat | |
write text "9" | |
set d to 0 | |
repeat until (d = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Benutzername?")) | |
set d to 1 | |
end if | |
end repeat | |
write text (user) | |
set e to 0 | |
repeat until (e = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Hostname?")) | |
set e to 1 | |
end if | |
end repeat | |
write text (hostname) | |
set f to 0 | |
repeat until (f = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set f to 1 | |
end if | |
end repeat | |
write text (ninja) | |
end tell | |
end tell | |
end tell | |
end run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
on trim(theseCharacters, someText) | |
if class of someText is text and length of someText > 0 then | |
-- default values (all whitespace) | |
if theseCharacters is true then ¬ | |
set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0} | |
repeat until first character of someText is not in theseCharacters | |
set someText to text 2 thru -1 of someText | |
end repeat | |
repeat until last character of someText is not in theseCharacters | |
set someText to text 1 thru -2 of someText | |
end repeat | |
end if | |
return someText | |
end trim | |
on run input | |
set proxyUser to "PROXY_USER" | |
set proxyHost to "PROXY_HOST" | |
set proxyPass to "PROXY_PASSWORD" | |
# 0 - 255 | |
set RED to 0 | |
set GREEN to 0 | |
set BLUE to 0 | |
# 0 - 100 % | |
set OPACITY to 50 | |
if (count input) = 4 then | |
set user to item 1 of input | |
set hostname to item 2 of input | |
# set a password is against the rules ;) | |
set ninja to item 3 of input | |
set type to item 4 of input | |
else | |
return "Usage: ssh-proxy user hostname password {prod|qs}" | |
end if | |
if type = "prod" then | |
set RED to 61 | |
set GREEN to 0 | |
set BLUE to 0 | |
set OPACITY to 40 | |
else | |
if type = "qs" then | |
set RED to 0 | |
set GREEN to 61 | |
set BLUE to 0 | |
set OPACITY to 40 | |
end if | |
end if | |
tell application "iTerm2" | |
activate | |
set newWindow to (create window with default profile) | |
tell current session of newWindow | |
set background color to {(RED*65535/255), (GREEN*65535/255), (BLUE*65535/255), (OPACITY*65535/100)} | |
set a to 0 | |
repeat until (a = 1) | |
if (is processing = false) | |
set a to 1 | |
end if | |
end repeat | |
write text "ssh " & (proxyUser) & "@" & (proxyHost) | |
set b to 0 | |
repeat until (b = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set b to 1 | |
end if | |
end repeat | |
write text (proxyPass) | |
set c to 0 | |
repeat until (c = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Auswahl?")) | |
set c to 1 | |
end if | |
end repeat | |
write text "9" | |
set d to 0 | |
repeat until (d = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Benutzername?")) | |
set d to 1 | |
end if | |
end repeat | |
write text (user) | |
set e to 0 | |
repeat until (e = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Hostname?")) | |
set e to 1 | |
end if | |
end repeat | |
write text (hostname) | |
set f to 0 | |
repeat until (f = 1) | |
if ((is processing = false) and (my trim(true, contents) ends with "Password:")) | |
set f to 1 | |
end if | |
end repeat | |
write text (ninja) | |
end tell | |
end tell | |
end run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SCRIPT="ssh-proxy-tab" | |
USER="DESTINATION_USER" | |
HOSTNAME="DESTINATION_HOST" | |
PASSWORD="DESTINATION_PASSWORD" | |
TYPE="prod" | |
if [ -n "$1" ]; then | |
if [ "$1" == "qs" ]; then | |
HOSTNAME="DESTINATION_HOST_QS" | |
TYPE="qs" | |
fi | |
fi | |
if [ -n "$2" ]; then | |
if [ "$2" == "window" ]; then | |
SCRIPT="ssh-proxy-window" | |
fi | |
if [ "$2" == "current" ]; then | |
SCRIPT="ssh-proxy-current" | |
fi | |
fi | |
${SCRIPT} ${USER} ${HOSTNAME} ${PASSWORD} ${TYPE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment