in reply to Re: Scripting setting the connection settings in Mozilla
in thread Scripting Proxy Settings in IE and Firefox

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

Replies are listed 'Best First'.
Re^3: Scripting setting the connection settings in Mozilla
by Anonymous Monk on Feb 21, 2010 at 21:32 UTC
    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.