Open hadifarnoud opened 10 years ago
please be more specific.
I have a bash script like this:
#!/bin/bash
disable_proxy()
{
networksetup -setsocksfirewallproxystate Wi-Fi off
networksetup -setsocksfirewallproxystate Ethernet off
echo "SOCKS proxy disabled."
}
trap disable_proxy INT
networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 8080
networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 8080
networksetup -setsocksfirewallproxystate Wi-Fi on
networksetup -setsocksfirewallproxystate Ethernet on
echo "SOCKS proxy enabled."
echo "Tunneling..."
ssh -ND 8080 user@yourserver.com&
because of ssh and trap template, this script does not work properly in Alfred. Since I know Ruby a bit too, I wonder if I can do this with Ruby?
I want to start a ruby script by an alfred keyword (e.g. "socks on") and terminate the script with another keyword e.g. "socks off". this way I can revert the settings and disconnect SSH tunnel. terminating the ssh tunnel in alfred is very difficult with bash (using 'expect' and all that).
terminating the ssh tunnel in alfred is very difficult with bash (using 'expect' and all that).
why expect? because you need to enter password?
yes. I know I can edit sudoer with NOPASS but I want to keep it simple so others can use this workflow too
check out https://github.com/zhaocai/alfred2-top-workflow . It has a Authenticate.app
you can copy to your project and use.
use the sudo.sh
to run command. the first time it will ask for password, then it will be memorized in keychain.
#!/usr/bin/env zsh
PASS=$(Authenticate.app/Contents/MacOS/Authenticate -get password)
if [ "$PASS" = "(null)" ] ; then
Authenticate.app/Contents/MacOS/Authenticate
PASS=$(Authenticate.app/Contents/MacOS/Authenticate -get password)
fi
echo $PASS | sudo -S "$@"
use mac built in security
command. This is a better solution but I do not have a code snippet right now.
I want to write a workflow in Ruby. It was written in shell script. see here: http://www.alfredforum.com/topic/3289-need-help-with-set-socks-proxy-workflow-i-wrote/
I wonder if I can run anything in background? for this specific example, I want to be able to have an ssh connection until user turns SOCKS proxy off.