📄 configdialog.java
字号:
"Experienced Users Only");
PanelGBL rdvrouterPanel = pages.addPage("Rendezvous/Relays",
"Experienced Users Only");
PanelGBL securityPanel = pages.addPage("Security",
"Security Settings");
advancedPanel.add(debugPanel, fillInsetConstr);
advancedPanel.add(tcpPanel, fillInsetConstr);
advancedPanel.add(httpPanel, fillInsetConstr);
rdvrouterPanel.add(rdvPanel, fillInsetConstr);
rdvrouterPanel.add(routerPanel, fillInsetConstr);
Button loadButton =
new Button("Download relay and rendezvous lists");
rdvrouterPanel.add(loadButton, fillInsetConstr);
GridBagConstraints centerWConstr =
(GridBagConstraints) centerConstr.clone();
centerWConstr.weighty = 1;
basicsPanel.add(idPanel, centerWConstr);
securityPanel.add(secPanel, centerWConstr);
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
add(helpLabel, fillConstr);
add(pages, fillInsetConstr);
add(okPanel, centerLastConstr);
loadButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AutoLoader a =
new AutoLoader(mainFrame,
rdvPanel.tcp,
rdvPanel.http,
routerPanel.remote,
"",
"http://rdv.jxtahosts.net/cgi-bin/httpRdvsProd.cgi",
"http://rdv.jxtahosts.net/cgi-bin/routersProd.cgi",
false);
}
});
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveValues();
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
beCanceled();
}
});
helpLabel.addMouseListener(this);
pack();
show();
}
boolean done = false;
boolean canceled = false;
public synchronized boolean untilDone() {
try {
while (! done) wait();
} catch (Exception e) {
}
if (canceled) throw new JxtaError("Canceled during configuration");
return (done);
}
private synchronized void beDone() {
done = true;
notify();
dispose();
}
private synchronized void beCanceled() {
canceled = true;
done = true;
notify();
dispose();
}
private boolean verifyPort(String portName, String ports) {
int p1;
try {
p1 = Integer.parseInt(ports);
} catch(Exception ex) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText(portName+" port number must be an integer: "+ports);
return false;
}
if (p1 > 65535|| p1 < 0) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText(portName + " port number must be an integer between 0 and "
+ "65535 found "+p1);
return false;
}
return true;
}
private boolean loadBootStrapping(String urlString, HostListPanel list) {
if (urlString.equals("")) return true;
helpLabel.setForeground(Color.black);
helpLabel.setText("Trying " + urlString + "...");
InputStream inp = null;
try {
inp = (new URL(urlString)).openStream();
BufferedReader l
= new BufferedReader(new InputStreamReader(inp));
String s;
int valid = 0;
while ((s = l.readLine()) != null) {
if (list.addItem(s)) ++valid;
}
if (valid == 0) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText(urlString + ": not a valid list.");
return false;
}
} catch (MalformedURLException e) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText(urlString + ": malformed URL.");
return false;
} catch (IOException e) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText(urlString + ": not accessible. " +
(idPanel.proxyPanel.getState() ? "" :
"You might need a proxy."));
return false;
}
try {
inp.close();
} catch (Exception e) {
}
helpLabel.setForeground(Color.black);
helpLabel.setText("Done loading Boostrapping info");
return true;
}
private boolean verifyInput() {
if (idPanel.getName().equals("")) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("A peer name is required.");
return false;
}
// Verify security parameters if we are not initialized
// Password and principal
if (! secPanel.getAlreadyInitialized()) {
String principal = secPanel.getPrincipal();
String passwd = secPanel.getPasswd();
String vpasswd = secPanel.getVerifyPasswd();
// Secure username is required
if (principal.length() == 0) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("Please configure your secure username via the Security panel");
// Clear text box
secPanel.clearPrincipal();
pages.showPage("Security");
return false;
}
// Verify password
// must be at least 8 chars a la unix
if (passwd.length() < 8) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("Password requires at least 8 letters");
// Clear password text boxes
secPanel.clearPasswds();
pages.showPage("Security");
return false;
}
// must be identical
if (passwd.compareTo(vpasswd) != 0) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("Password does not match Verify Password");
// Clear password text boxes
secPanel.clearPasswds();
pages.showPage("Security");
return false;
}
}
if ((httpPanel.getState() == false)
&& (tcpPanel.getState() == false)) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("At least one of TCP or HTTP must be enabled.");
return false;
}
if (!verifyPort("HTTP proxy", idPanel.proxyPanel.getPort())
|| !verifyPort("public router", routerPanel.publicAddr.getPort())
|| !verifyPort("TCP public", tcpPanel.getPublicPort())
|| !verifyPort("TCP local", tcpPanel.getLocalPort())
|| !verifyPort("HTTP local", httpPanel.getLocalPort()))
return false;
if (! httpPanel.getState() || ! routerPanel.remote.getState()) {
return true;
}
// For now routers and http rdv are inseparable. You need both or
// Neither.
String[] routers = routerPanel.remote.getItems();
String[] httpRdvs = rdvPanel.http.getItems();
int i = httpRdvs.length;
while (i-->0) {
int j = routers.length;
while (j-->0) {
// ignore :port_number
String s1=httpRdvs[i].substring(0,httpRdvs[i].indexOf(":"));
String s2=routers[j].substring(0,routers[j].indexOf(":"));
if (s1.equals(s2)) return true;
}
}
try {
// XXX under JDK 1.x, system properties can not be set during
// runtime
if (idPanel.proxyPanel.getState()) {
//PDA requirements 19.02.2002
//java.lang.System.setProperty(String key, String value) vas not presented in jdk 1.1.8
//System.setProperty("http.proxyHost",
//idPanel.proxyPanel.getHost());
//System.setProperty("http.proxyPort",
//idPanel.proxyPanel.getPort());
Properties props = System.getProperties();
props.put("http.proxyHost", idPanel.proxyPanel.getHost());
props.put("http.proxyPort", idPanel.proxyPanel.getPort());
System.setProperties(props);
//PDA requirements 19.02.2002
}
} catch(Exception ee) {
helpLabel.setForeground(Color.red.darker());
helpLabel.setText("Cannot turn-on proxying w/ JDK 1.1. "
+ "you must edit your system properties.");
return false;
}
if (!loadBootStrapping("http://rdv.jxtahosts.net/cgi-bin/httpRdvsProd.cgi",rdvPanel.http))
return false;
if (!loadBootStrapping("http://rdv.jxtahosts.net/cgi-bin/routersProd.cgi",
routerPanel.remote ))
return false;
if (!loadBootStrapping("", rdvPanel.tcp ))
return false;
routers = routerPanel.remote.getItems();
httpRdvs = rdvPanel.http.getItems();
i = httpRdvs.length;
while (i-->0) {
int j = routers.length;
while (j-->0) {
if (httpRdvs[i].equals(routers[j])) return true;
}
}
return false;
}
private void saveValues() {
if (! verifyInput())return;
try {
httpAdv.setInterfaceAddress(httpPanel.getInterfaceAddress());
httpAdv.setPort(httpPanel.getLocalPort());
httpAdv.setConfigMode(httpPanel.getConfigMode());
if (idPanel.proxyPanel.getHost().equals("")) {
httpAdv.setProxy(null);
} else {
httpAdv.setProxyEnabled(idPanel.proxyPanel.getState());
httpAdv.setProxy(idPanel.proxyPanel.getHost()
+ ":"
+ idPanel.proxyPanel.getPort());
}
String[] routers = routerPanel.remote.getItems();
if (routers.length == 0) {
httpAdv.setRouters(null);
} else {
Vector routersVect = new Vector();
int i = routers.length;
while (i-->0) routersVect.addElement(routers[i]);
httpAdv.setRouters(routersVect);
}
// Router enabled is a bit special, we have to set it to off
// explicitly, otherwise it will remain unchanged even if we save
// an empty list. This is so that we are able to set it ON as
// an initial fool proof default.
httpAdv.setRouterEnabled(routerPanel.remote.getState());
tcpAdv.setPort(tcpPanel.getLocalPort());
tcpAdv.setInterfaceAddress(tcpPanel.getInterfaceAddress());
if (tcpPanel.getPublicAddress().equals("")) {
tcpAdv.setServer(null);
} else {
tcpAdv.setServer(tcpPanel.getPublicAddress()
+ ":"
+ tcpPanel.getPublicPort());
}
tcpAdv.setConfigMode(tcpPanel.getConfigMode());
// If you turn off either tcp or http we have to loose your
// otherwise preferrence for being a router, because httpTransport
// does not know weither tcp is on or off, so we have to tell
// it explicitly what to do. Alternatively, we could create an
// extra flag to remember your preferrence...later.
// If there's nothing interresting inthere, do not save it.
if (routerPanel.publicAddr.getHost().equals("")) {
httpAdv.setServer(null);
} else {
httpAdv.setServerEnabled(httpPanel.getState()
&& tcpPanel.getState()
&& routerPanel.publicAddr.getState());
httpAdv.setServer(routerPanel.publicAddr.getHost()
+ ":"
+ routerPanel.publicAddr.getPort());
}
configAdv.setName(idPanel.getName());
// If we initialized security, then check the values.
// Otherwise they come from the security login dialog
if (!secPanel.getAlreadyInitialized()) {
// Set the user's password
//PDA requirements 19.02.2002
//java.lang.System.setProperty(String key, String value) vas not presented in jdk 1.1.8
//System.setProperty("net.jxta.tls.password",secPanel.getPasswd());
// Set the Secure user name
//System.setProperty("net.jxta.tls.principal",secPanel.getPrincipal());
Properties props = System.getProperties();
props.put("net.jxta.tls.password", secPanel.getPasswd());
props.put("net.jxta.tls.principal", secPanel.getPrincipal());
System.setProperties(props);
//PDA requirements 19.02.2002
}
// We do not want to drop any address that the user has left
// in the list, so we just re-order them: If http is on,
// then it comes first, otherwise tcp addresses come first.
int i;
String[] rdvs;
StructuredTextDocument pdoc = (StructuredTextDocument)
StructuredDocumentFactory.newStructuredDocument(
new MimeMediaType("text", "xml"),
"Parm");
if (httpPanel.getState()) {
rdvs = rdvPanel.http.getItems();
i = rdvs.length;
while (i-- > 0) {
Element e = pdoc.createElement("Addr",
"http://" +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -