Posts tagged ‘proxy’

Vimperator: Plugin to set proxies from the command line

There are firefox addons to set proxies. These can be useful if you are dealing with a small and fixed set of proxies. Since they generally form part of the menuing system, they can be got at using the emenu command in vimperator. One such example is foxyproxy.

However, if you use a *lot* of proxies this can all become somewhat unwieldy. An alternative is to add the following code to your vimperatorrc file. (Or bundle it up as a plugin, if you prefer).

js >>EOF
var pref = services.services.pref;

function set_proxy(host, port){
    liberator.echo(host + ':' + port);
    pref.setCharPref('network.proxy.http', host);
    pref.setIntPref('network.proxy.http_port', port);
    pref.setBoolPref('network.proxy.share_proxy_settings', true);
    pref.setIntPref('network.proxy.type', 1);
}

function get_proxy_string(){
    proxyType = pref.getIntPref('network.proxy.type');
    if (proxyType == 0){
        return 'no_proxy';
    } else if (proxyType == 1) {
        host = pref.getCharPref('network.proxy.http');
        port = pref.getIntPref('network.proxy.http_port');
        return host + ':' + port;
    } else {
        return 'non_http_proxy';
    }
}

commands.addUserCommand(['noproxy'],
    'Switch off proxy',
    function (args) {
        pref.setIntPref('network.proxy.type', 0);
    },
    {},
    true
);
commands.addUserCommand(['proxy'],
    'Set the proxy',
    function (args){
        switch (args.length) {
            case 0:
                liberator.echo(get_proxy_string());
                break;
            case 1:
                [host] = args;
                port = 3128;
                set_proxy(host, port);
                break;
            case 2:
                [host, port] = args;
                set_proxy(host, port);
                break;
            default:
                liberator.echo('proxy host port')
        }
    },
    {}, true);
EOF

This gives you the commands proxy [host [port]] to get and set the current proxy. And noproxy to clear proxies.

December 30, 2010 at 1:18 pm Leave a comment

Setting preferences in vimperator

I found out recently that vimperator has builtin commands to set preferences from its command line.

So, for example:

set! network.proxy.http = ‘myproxy.com’

followed by

set! network.proxy.type = 1

will switch on an existing http proxy.

Things are slightly different if you want to do things from javascript addons. Here you need to use the XPCOM interfaces. The following javascript code adds a noproxy command to clear your proxy settings.

js <<EOF
commands.addUserCommand(['noproxy'],
    'Switch off proxy',
    function (args) {
        pref.setIntPref('network.proxy.type', 0);
    },
    {},
    true
);
EOF

December 16, 2010 at 2:57 pm Leave a comment


August 2017
M T W T F S S
« Nov    
 123456
78910111213
14151617181920
21222324252627
28293031