Comment puis-je changer le proxy de Firefox à partir de l'application Terminal ? Pas les paramètres de proxy de tout l'ordinateur (ceux de l'onglet Réseau), mais seulement ceux de Firefox.
Réponse
Trop de publicités?
Shen En Chen
Points
11
Voici un shell script que j'ai rédigé pour Mac OS X pour utiliser SOCKS, qui fonctionne bien pour moi. Vous pouvez le modifier en fonction de vos besoins. Pour vous, vous devrez modifier les valeurs de network.proxy.http et network.proxy.http_port dans prefs.js
#!/bin/bash
FIREFOX="/Applications/Firefox.app/Contents/MacOS/firefox"
PREDIR="$(ls $HOME/Library/Application\ Support/Firefox/Profiles/ | grep release)"
PREFILE="prefs.js"
FULLPATH="$HOME/Library/Application Support/Firefox/Profiles/$PREDIR/$PREFILE"
#IPADDR="localhost"
#PORT="7777"
#PROXYTYPE="1"
IPADDR="$1"
PORT="$2"
PROXYTYPE="$3"
TMPSOCKS="/tmp/network.proxy.socks.tmp"
TMPSOCKSPORT="/tmp/network.proxy.socks_port.tmp"
# Insert an ip into firefox for the proxy if there isn't one
if ! grep 'network.proxy.socks\"' "$FULLPATH"
then
echo "no network.proxy.socks defined"
echo "no need to save value"
echo 'user_pref("network.proxy.socks", "'"$IPADDR"'");' >> "$FULLPATH"
echo 'user_pref("network.proxy.socks", "'"$IPADDR"'");' placed in $FULLPATH
else
echo "network.proxy.socks exists, preserving value ..."
grep 'network.proxy.socks\"' "$FULLPATH" > "$TMPSOCKS"
sed -i '' 's/^.*network.proxy.socks".*$/user_pref("network.proxy.socks", "'"$IPADDR"'");/' "$FULLPATH"
echo replaced network.proxy.socks to $IPADDR
fi
# Set the port
if ! grep network.proxy.socks_port "$FULLPATH"
then
echo "no network.proxy.socks_port value defined"
echo "no need to save value"
echo 'user_pref("network.proxy.socks_port", '''$PORT''');' >> "$FULLPATH"
echo 'user_pref("network.proxy.socks_port", '''$PORT''');' placed in "$FULLPATH"
else
echo "network.proxy.socks_port found, preserving value ..."
grep network.proxy.socks_port "$FULLPATH" > $TMPSOCKSPORT
sed -i '' 's/^.*network.proxy.socks_port.*$/user_pref("network.proxy.socks_port", '''$PORT''');/' "$FULLPATH"
echo inserted port $PORT to network.proxy.socks_port
fi
# Turn on the proxy
if ! grep network.proxy.type "$FULLPATH"
then echo 'user_pref("network.proxy.type", '''$PROXYTYPE''');' >> "$FULLPATH"
else sed -i '' 's/^.*network.proxy.type.*$/user_pref("network.proxy.type", '''$PROXYTYPE''');/' "$FULLPATH"
fi
# Open Firefox ...
/Applications/Firefox.app/Contents/MacOS/firefox
# After Firefox is closed, need to replace the original value
if [ -f "$TMPSOCKS" ];
then
ORGSOCKS=`cat $TMPSOCKS`
sed -i '' 's/^.*network.proxy.socks".*$/'''$ORGSOCKS'''/' "$FULLPATH"
fi
if [ -f "$TMPSOCKSPORT" ];
then
ORGSOCKSPORT=`cat $TMPSOCKSPORT`
sed -i '' 's/^.*network.proxy.socks_port.*$/'''$ORGSOCKSPORT'''/' "$FULLPATH"
fi
# Turn off the proxy
if ! grep network.proxy.type "$FULLPATH"
then echo 'user_pref("network.proxy.type", 0);' >> "$FULLPATH"
else sed -i '' 's/^.*network.proxy.type.*$/user_pref("network.proxy.type", 0);/' "$FULLPATH"
fi