Solved

Change PROXY

Posted on 2001-09-09
26
1,025 Views
Last Modified: 2008-02-01
how can i change my proxy server useing javascript
0
Comment
Question by:frosty5656
  • 13
  • 6
  • 4
  • +2
26 Comments
 
LVL 1

Expert Comment

by:snakehollywood
ID: 6469046
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6470150
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
 
LVL 1

Expert Comment

by:snakehollywood
ID: 6470266
Alas I don't think NS only code is useful to anyone. Who uses NS only???
0
 
LVL 1

Expert Comment

by:gegege
ID: 6470312
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
 
LVL 1

Expert Comment

by:gegege
ID: 6470315
ps - win32 only - not mac ie or win3.x
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6470318
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6470319
as gegege managed to tell before I had found the key to look at ;-)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6470334
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6470338
PS: If you need netscape's script to work on the net, you need to purchase a certificate and SIGN the script

Michel
0
 

Author Comment

by:frosty5656
ID: 6475184
is there script that will output my detected proxy so i know if it is working?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6475204

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
 

Author Comment

by:frosty5656
ID: 6475554
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6476039
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:frosty5656
ID: 6480744
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6480806
That is a corrupt IE5 installation.

Michel
0
 

Author Comment

by:frosty5656
ID: 6484078
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6484843
Do you perhaps have turned off WSH?

Michel
0
 

Author Comment

by:frosty5656
ID: 6488720
sorry.. but could you define WSH? Thanks.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6488942
0
 

Author Comment

by:frosty5656
ID: 6500485
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
 
LVL 1

Accepted Solution

by:
gegege earned 200 total points
ID: 6501218
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6501239
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
 
LVL 1

Expert Comment

by:gegege
ID: 6501918
i know - but it looks just like the code i posted first, and i like it, so i posted it again.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6502523
haha
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6502524
Sorry. - lost my track there ;-)
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 6906969
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now