in reply to Scripting Proxy Settings in IE and Firefox

Hi
Just have a look at http://www.mozilla.org/support/firefox/edit:
Everything you can see if you point your mozilla-browser to about:config you can set by changing values in ~/.mozilla/firefox/xxxxxxxx.default/prefs.js including the proxy settings. Check the link for detailed info for other plattforms (I was talking about Linux, but it works for Windows, too).

Regards,
Timo
  • Comment on Re: Scripting setting the connection settings in Mozilla

Replies are listed 'Best First'.
Re^2: Scripting setting the connection settings in Mozilla
by slloyd (Hermit) on Mar 21, 2006 at 16:21 UTC
    Thanks for the replies! Here is the final code that sets both IE and Firefox proxy settings.
    use strict; use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 ); &setProxy(); ############### sub setProxy{ #Set access to use proxy server (IE) #http://nscsysop.hypermart.net/setproxy.html my $server=shift || "localhost"; my $port=shift || 8080; my $enable=shift || 1; my $override=shift || "127.0.0.1;<local>"; #set IE Proxy my $rkey=$Registry->{"CUser/Software/Microsoft/Windows/CurrentVers +ion/Internet Settings"}; $rkey->SetValue( "ProxyServer" , "$server\:port" , "REG_SZ" + ); $rkey->SetValue( "ProxyEnable" ,pack("L",$enable) , "REG_DWOR +D" ); $rkey->SetValue( "ProxyOverride" , $override , "REG_SZ" + ); #Change prefs.js file for mozilla #http://www.mozilla.org/support/firefox/edit if(-d "$ENV{APPDATA}\\Mozilla\\Firefox\\Profiles"){ my $mozdir="$ENV{APPDATA}\\Mozilla\\Firefox\\Profiles"; opendir(DIR,$mozdir) || return "opendir Error: $!"; my @pdirs=grep(/\w/,readdir(DIR)); close(DIR); foreach my $pdir (@pdirs){ next if !-d "$mozdir\\$pdir"; next if $pdir !~/\.default$/is; my @lines=(); my %Prefs=( "network\.proxy\.http" => "\"$server\"", "network\.proxy\.http_port" => $port, "network\.proxy\.type" => $enable, ); if(open(FH,"$mozdir\\$pdir\\prefs.js")){ @lines=<FH>; close(FH); my $cnt=@lines; #Remove existing proxy settings for(my $x=0;$x<$cnt;$x++){ my $line=strip($lines[$x]); next if $line !~/^user_pref/is; foreach my $key (%Prefs){ if($line=~/\"$key\"/is){ delete($lines[$x]); } } } } if(open(FH,">$mozdir\\$pdir\\prefs.js")){ binmode(FH); #print "Writing $mozdir\\$pdir\\prefs.js\n"; foreach my $line (@lines){ $line=strip($line); print FH "$line\r\n"; } foreach my $key (sort(keys(%Prefs))){ print FH qq|user_pref("$key",$Prefs{$key});\r\n|; } close(FH); return 1; } } } return 0; } ############### sub strip{ #usage: $str=strip($str); #info: strips off beginning and endings returns, newlines, tabs, a +nd spaces my $str=shift; if(length($str)==0){return;} $str=~s/^[\r\n\s\t]+//s; $str=~s/[\r\n\s\t]+$//s; return $str; }

    -------------------------------
    by me
    http://www.basgetti.com
    http://www.kidlins.com

      hm... how to use this script?
        The same as any other script ? :)

        please tell us on how to use this script. Where to edit the server IP for IE & Firefox and the port number

    A reply falls below the community's threshold of quality. You may see it by logging in.