• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1050
  • Last Modified:

Change PROXY

how can i change my proxy server useing javascript
0
frosty5656
Asked:
frosty5656
  • 13
  • 6
  • 4
  • +2
1 Solution
 
snakehollywoodCommented:
You do not change this via Javascript, it is part of your browser settings.
You must goto tool --> internet options and setup your proxy server here.
0
 
Michel PlungjanIT ExpertCommented:
Ns Only:

function readPref(pref) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

return navigator.preference(pref);

}

function writePref(pref,val) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesWrite");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

navigator.preference(pref,val);
}


network.proxy.type
Sets the type of proxy server connection to use. The default is 3, which connects to Internet hosts directly, without going through proxy servers. Other values are: 1, configure proxy settings manually (using the manual proxy-setting preferences below); 2, point to an automatic proxy configuration URL containing proxy settings. If this preference is set to 2, specify the URL with network.proxy.autoconfig_url. Note that option 2 (an automatic configuration URL) doesn't apply when configuring through a centralized AutoConfig resource such as a config.jsc file.

network.proxy.http
Specifies the host name or IP address of an HTTP proxy server. The default is an empty string. If not using the default HTTP port number of 80, specify the port number with network.proxy.http_port.
network.proxy.http_port Specifies the non-default port number of an HTTP proxy server. This preference isn't needed when using the default port number of 80. The default is 0. The correct port number is determined at the server.

network.proxy.ssl
Specifies the host name or IP address of an HTTP proxy server that is accessed by SSL. The default is an empty string. If not using the default SSL proxy server port number of 443, specify the port number with network.proxy.ssl_port. This preference is lockable, applies to
Communicator 4.0 and later versions, and is available on all platforms.

network.proxy.ssl_port
Specifies the non-default port number of an SSL proxy server. This preference isn't needed when using the default port number of 443. The correct port number is determined at the server. This preference is lockable, applies to Communicator 4.0 and later versions, and is available on all platforms.
network.proxy.ftp Specifies the host name or IP address of an FTP proxy server. The default is an empty string. If not using the default FTP port number of 20, specify the port number with network.proxy.ftp_port.

network.proxy.ftp_port
Specifies the non-default port number of an FTP proxy server. This preference isn't needed when using the default port number of 20. The default is 0. The correct port number is determined at the server. network.hosts.socks_server Specifies the host name or IP address of a SOCKS server. The default is an empty string. If not using the default SOCKS port number of 1080, specify the port number with
network.hosts.socks_serverport.

network.hosts.socks_serverport
Specifies the non-default port number of a SOCKS server. This preference isn't needed when using the default port number of 1080. The default is 1080. The correct port number is determined at the server.

network.proxy.gopher
Specifies the host name or IP address of a GOPHER proxy server. The default is an empty string. If not using the default GOPHER port number of 70, specify the port number with network.proxy.gopher_port.
network.proxy.gopher_port Specifies the non-default port number of a GOPHER proxy server. This preference isn't needed when using the default port number of 70. The default is 0. The correct port number is determined at the server.

network.proxy.wais
Specifies the host name or IP address of a WAIS proxy server. The default is an empty string. There is no default WAIS port number, so it is necessary to specify one with network.proxy.wais_port.
network.proxy.wais_port Specifies the port number of a WAIS proxy server. This preference must be set when setting network.proxy.wais because there is no default WAIS proxy server port number. The correct port number is determined at the server.

network.proxy.no_proxies_on
Specifies domains to exclude when working through proxy servers. The values for this preference are formatted as a semicolon-delimited list of domains. The default is an empty string. Note that wildcards can't be used in the domain list.

network.proxy.autoconfig_url
Specifies the URL to use for automatic proxy configuration if
network.proxy.type is set to 2. The default is an empty string.
0
 
snakehollywoodCommented:
Alas I don't think NS only code is useful to anyone. Who uses NS only???
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gegegeCommented:
to do it with ie you will need an activex control that can write to the registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer  "serverName:portnumber"

<Script language="JavaScript">
try{
var wsh = new ActiveXObject("WScript.Shell")
var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer", "ServerName:80"  
}catch(e){
 alert("An Error Occured: \r\n\t\t" + e.description)

}

</Script>

this is ie only - so if you mix this with the netscape solution you should be alright.
0
 
gegegeCommented:
ps - win32 only - not mac ie or win3.x
0
 
Michel PlungjanIT ExpertCommented:
Well all our staff does - so for intranet it is useful.

Why would I say "No Way" ot keep quit if there was a way for at least one browser - perhaps frosty is on an intranet... AOL and Compuserve's new browsers will be Netscape based too

For IE one would need WSH and look at

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
ProxyServer
0
 
Michel PlungjanIT ExpertCommented:
as gegege managed to tell before I had found the key to look at ;-)
0
 
Michel PlungjanIT ExpertCommented:
So it IS possible.

gegege should have some points too

<html>
<head>
<title>Proxy</title>
<script>
function setNSProxy(server,port) {
   var targ = netscape.security.Target.findTarget("UniversalPreferencesWrite");
   var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
   mgr.enablePrivilege(targ);
   navigator.preference(network.proxy.http,server);
   navigator.preference(network.proxy.http_port,port);
}
function setIEProxy() {
   alert('Sorry, can only be done in IE5+');
}
</script>
<script language="JavaScript1.3">
function setIEProxy(server,port) {
  try{
     var wsh = new ActiveXObject("WScript.Shell")
     var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer",
     server+":"+port);  
  }catch(e){
     alert("An Error Occured: \r\n\t\t" + e.description)
  }
}
</script>

</head>

<body>

<a href="#"
onClick="
server=prompt('Server?');
port=prompt('Port',80);
if (document.all) setIEProxy(server,port);
else if (document.layers||document.getElementById) setNSProxy(server,port);
return false">Set proxy</a>

</body>
</html>
0
 
Michel PlungjanIT ExpertCommented:
PS: If you need netscape's script to work on the net, you need to purchase a certificate and SIGN the script

Michel
0
 
frosty5656Author Commented:
is there script that will output my detected proxy so i know if it is working?
0
 
Michel PlungjanIT ExpertCommented:

function readPref(pref) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

return navigator.preference(pref);

}

if (document.all)
alert(wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer")

else alert(readPref('network.proxy.http'))


and the other script also need quotes - sorry:

navigator.preference('network.proxy.http',server);
navigator.preference('network.proxy.http_port',port);
0
 
frosty5656Author Commented:
i am getting an error when i try to change proxies: "automation server can't create object" Does this script run on your cpu? if it does could you tell me what type of browser your useing? Also is the code that shows what proxy that you are useing, is that real time? and by reading the code i think it is being desplayed in an alert pop-up, is it possible to desplay that in a field? I don't know that much javascript so please bare with me. Thank You.
0
 
Michel PlungjanIT ExpertCommented:
This work on windows NT.

NONE of the IE stuff will work on MAC!!!


<head>
     <title>Untitled</title>
<script>

function readPref(pref) {
   var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
   var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
   mgr.enablePrivilege(targ);
   return navigator.preference(pref);
}


function showProxy() {
   prox = "";
   if (document.all) {
      var wsh = new ActiveXObject("WScript.Shell");
      prox = wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer");
   }
   else prox =readPref('network.proxy.http');
   return prox;
}

</script>
 
</head>
<body>
<form name="myForm">
<input type="text" name="prox" value="">
<input type="button" onClick="this.form.prox.value=showProxy()" value="Proxy">
</form>


</body>
0
 
frosty5656Author Commented:
i still recieve the same error. I am running windows 98 on a 56kb modem, and IE 5. would it be possible to change the proxy within the javascript and it would read from a list of proxies so you would not have to enter in any values. Once it has changed to the first proxy, it will procced to the next when the function is called.
0
 
Michel PlungjanIT ExpertCommented:
That is a corrupt IE5 installation.

Michel
0
 
frosty5656Author Commented:
don't think that IE is corrupted because i've tried it on three different computers and they all give me the same error. could there be another problem?
0
 
Michel PlungjanIT ExpertCommented:
Do you perhaps have turned off WSH?

Michel
0
 
frosty5656Author Commented:
sorry.. but could you define WSH? Thanks.
0
 
Michel PlungjanIT ExpertCommented:
0
 
frosty5656Author Commented:
i downloaded that program and installed it and i still recieve errors. Could you visit my web-page and tell me what i am doing wrong:

www.angelfire.com/fl5/top2002/index.html

Thanks.
0
 
gegegeCommented:
frosty5656, there are two problems,

the first where it says "Automation server can't create object" is because of the users security settings - they are too high, you need to get them to allow or prompt on "Initialize and Script ActiveX Controls not marked as safe".  

If you can't get the to lower their security settings then you will need to use c++ or vb to wrap the control inside your own control which you do mark as safe, then digitally sign it and see if people wll install it when they go to your web site - changing their security settings or getting them to put your site in the "Trusted zones" is best.

the second problem is if a user doesn't have a proxy server set up then it gives an error about reading the registry key and not being able to find it.

If you wrap them in try catch blocks it should fix the problem, just change it from an alert to doing something in your code like returning a dummy proxy or no proxy:

    try{
     var wsh = new ActiveXObject("WScript.Shell");
     prox = wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer");
     }catch(e)
          {
          alert(An Error Occured\r\n\r\n\t" + e.description);
          }
0
 
Michel PlungjanIT ExpertCommented:
Looks remarkably like my


 try{
    var wsh = new ActiveXObject("WScript.Shell")
    var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer",

    server+":"+port);  
 }catch(e){
    alert("An Error Occured: \r\n\t\t" + e.description)
 }

except the read is write.

Later I do have a read though ;-)

Michel
0
 
gegegeCommented:
i know - but it looks just like the code i posted first, and i like it, so i posted it again.
0
 
Michel PlungjanIT ExpertCommented:
haha
0
 
Michel PlungjanIT ExpertCommented:
Sorry. - lost my track there ;-)
0
 
Asta CuCommented:
Please update the experts here who have so willingly stepped in to help you, since much time has passed since your last comments, and Email notifications may not have been generated to the participating experts here due to some problems at that time.

Somewhat off-topic, but important.

****************************** ALERT********************************
WindowsUpdate - Critical Update alert March 28, 2002 from Microsoft
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/ms02-015.asp
Synopsis:
Microsoft Security Bulletin MS02-015  
28 March 2002 Cumulative Patch for Internet Explorer
Originally posted: March 28, 2002
Summary
Who should read this bulletin: Customers using Microsoft® Internet Explorer
Impact of vulnerability: Two vulnerabilities, the most serious of which would allow script to run in the Local Computer Zone.
Maximum Severity Rating: Critical
Recommendation: Consumers using the affected version of IE should install the patch immediately.
Affected Software:
Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6.0

Thought you'd appreciate knowing this.
":0)
Asta
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 13
  • 6
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now