Moved RegisteredFrame.

Fixed ssl certificate ui to only be shown once.
Added a special rate tracker for bandwidth (rate / 1024).
Fixed some repaint() issues with labels and buttons.
Enabled updating router info.
This commit is contained in:
dev
2011-07-19 11:35:08 +00:00
parent 6592ae110a
commit 10b91cd5a7
14 changed files with 376 additions and 143 deletions

View File

@ -38,6 +38,7 @@ import net.i2p.itoopie.i2pcontrol.methods.RouterRunner.ROUTER_RUNNER;
import net.i2p.itoopie.i2pcontrol.methods.SetNetworkSetting; import net.i2p.itoopie.i2pcontrol.methods.SetNetworkSetting;
import net.i2p.itoopie.i2pcontrol.methods.SetRouterRunner; import net.i2p.itoopie.i2pcontrol.methods.SetRouterRunner;
import net.i2p.itoopie.security.CertificateHelper; import net.i2p.itoopie.security.CertificateHelper;
import net.i2p.itoopie.security.ItoopieHostnameVerifier;
/** /**
* The main class of the application. * The main class of the application.
@ -70,7 +71,7 @@ public class Main {
System.setProperty("java.awt.headless", "false"); System.setProperty("java.awt.headless", "false");
_conf = ConfigurationManager.getInstance(); _conf = ConfigurationManager.getInstance();
_log = LogFactory.getLog(Main.class); _log = LogFactory.getLog(Main.class);
HttpsURLConnection.setDefaultHostnameVerifier(CertificateHelper.getHostnameVerifier()); HttpsURLConnection.setDefaultHostnameVerifier(new ItoopieHostnameVerifier());
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -92,7 +93,7 @@ public class Main {
// Popup Main window. // Popup Main window.
WindowHandler.toggleFrames(); WindowHandler.toggleFrames();
testStuff(); // Delete Me //testStuff(); // Delete Me
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@ -125,7 +126,7 @@ public class Main {
private static void testStuff(){ private static void testStuff(){
_conf.parseConfigStr("server.hostname=127.0.0.1"); _conf.parseConfigStr("server.hostname=127.0.0.1");
_conf.parseConfigStr("server.port=7560"); _conf.parseConfigStr("server.port=7650");
_conf.parseConfigStr("server.target=jsonrpc"); _conf.parseConfigStr("server.target=jsonrpc");

View File

@ -13,51 +13,59 @@ import net.i2p.itoopie.security.CertificateHelper;
import net.i2p.itoopie.security.CertificateManager; import net.i2p.itoopie.security.CertificateManager;
public class CertificateGUI { public class CertificateGUI {
private static boolean isVerifying = false;
public static void main(String[] args){ public static void main(String[] args){
System.out.println("Save new cert: " + saveNewCert(null,null)); System.out.println("Save new cert: " + saveNewCert(null,null));
System.out.println("Overwrite cert: " + overwriteCert(null,null)); System.out.println("Overwrite cert: " + overwriteCert(null,null));
} }
public static boolean saveNewCert(String hostname, X509Certificate cert){ public static boolean saveNewCert(String hostname, X509Certificate cert){
JFrame frame = new JFrame(); if (!isVerifying){
frame.setLayout(new BorderLayout()); isVerifying = true;
JButton bt = new JButton(); JFrame frame = new JFrame();
bt.setText("text"); frame.setLayout(new BorderLayout());
frame.add(bt, BorderLayout.NORTH); JButton bt = new JButton();
bt.setText("text");
String title = Transl._("New remote host detected"); frame.add(bt, BorderLayout.NORTH);
String hostString = Transl._("Would you like permanently trust the certificate from the remote host " + hostname + "?");
String title = Transl._("New remote host detected");
String certName = "N/A"; String hostString = Transl._("Would you like permanently trust the certificate from the remote host " + hostname + "?");
String certAlgo = "N/A";
String certSerial = "N/A"; String certName = "N/A";
String certThumb = "N/A"; String certAlgo = "N/A";
if (cert != null){ String certSerial = "N/A";
certName = cert.getSubjectDN().getName(); String certThumb = "N/A";
String certString = cert.getPublicKey().toString(); if (cert != null){
certAlgo = certString.substring(0,certString.indexOf("\n")); certName = cert.getSubjectDN().getName();
certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); String certString = cert.getPublicKey().toString();
certThumb = CertificateHelper.getThumbPrint(cert); certAlgo = certString.substring(0,certString.indexOf("\n"));
} certSerial = String.valueOf(cert.getPublicKey().serialVersionUID);
String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" + certThumb = CertificateHelper.getThumbPrint(cert);
Transl._("Name: ") + certName + "<br>" + }
Transl._("Algorithm: ") + certAlgo + "<br>" + String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" +
Transl._("Serial: ") + certSerial + "<br>" + Transl._("Name: ") + certName + "<br>" +
Transl._("SHA-1 ID-hash: ") + certThumb; Transl._("Algorithm: ") + certAlgo + "<br>" +
Transl._("Serial: ") + certSerial + "<br>" +
String textContent = certInfo + "<br><br>" + hostString; Transl._("SHA-1 ID-hash: ") + certThumb;
int n = JOptionPane.showConfirmDialog( String textContent = certInfo + "<br><br>" + hostString;
frame,
textContent, int n = JOptionPane.showConfirmDialog(
title, frame,
JOptionPane.YES_NO_OPTION, textContent,
JOptionPane.INFORMATION_MESSAGE); title,
JOptionPane.YES_NO_OPTION,
if (n == JOptionPane.YES_OPTION){ JOptionPane.INFORMATION_MESSAGE);
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert));
return true; if (n == JOptionPane.YES_OPTION){
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert));
isVerifying = false;
return true;
} else {
isVerifying = false;
return false;
}
} else { } else {
return false; return false;
} }
@ -65,53 +73,59 @@ public class CertificateGUI {
public static boolean overwriteCert(String hostname, X509Certificate cert){ public static boolean overwriteCert(String hostname, X509Certificate cert){
JFrame frame = new JFrame(); if (!isVerifying){
JFrame frame = new JFrame();
String title = Transl._("Warning, new remote host detected");
String hostString = Transl._("The certificate of " + hostname + " has changed! <br>" + String title = Transl._("Warning, new remote host detected");
"Are you sure you like permanently trust the new certificate from the remote host?"); String hostString = Transl._("The certificate of " + hostname + " has changed! <br>" +
"Are you sure you like permanently trust the new certificate from the remote host?");
String certName = "N/A";
String certAlgo = "N/A"; String certName = "N/A";
String certSerial = "N/A"; String certAlgo = "N/A";
String certThumb = "N/A"; String certSerial = "N/A";
if (cert != null){ String certThumb = "N/A";
certName = cert.getSubjectDN().getName(); if (cert != null){
String certString = cert.getPublicKey().toString(); certName = cert.getSubjectDN().getName();
certAlgo = certString.substring(0,certString.indexOf("\n")); String certString = cert.getPublicKey().toString();
certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); certAlgo = certString.substring(0,certString.indexOf("\n"));
certThumb = CertificateHelper.getThumbPrint(cert); certSerial = String.valueOf(cert.getPublicKey().serialVersionUID);
} certThumb = CertificateHelper.getThumbPrint(cert);
String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" + }
Transl._("Name: ") + certName + "<br>" + String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" +
Transl._("Algorithm: ") + certAlgo + "<br>" + Transl._("Name: ") + certName + "<br>" +
Transl._("Serial: ") + certSerial + "<br>" + Transl._("Algorithm: ") + certAlgo + "<br>" +
Transl._("SHA-1 ID-hash: ") + certThumb; Transl._("Serial: ") + certSerial + "<br>" +
Transl._("SHA-1 ID-hash: ") + certThumb;
String textContent = certInfo + "<br><br>" + hostString;
String textContent = certInfo + "<br><br>" + hostString;
int n = JOptionPane.showConfirmDialog(
frame, int n = JOptionPane.showConfirmDialog(
textContent, frame,
title, textContent,
JOptionPane.YES_NO_OPTION, title,
JOptionPane.WARNING_MESSAGE); JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (n == JOptionPane.YES_OPTION){
n = JOptionPane.showConfirmDialog(
frame,
Transl._("Are you sure that you trust the new certificate?"),
Transl._("Is that you final answer?"),
JOptionPane.YES_NO_OPTION,
JOptionPane.ERROR_MESSAGE);
if (n == JOptionPane.YES_OPTION){ if (n == JOptionPane.YES_OPTION){
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); n = JOptionPane.showConfirmDialog(
return true; // Confirmation positive frame,
Transl._("Are you sure that you trust the new certificate?"),
Transl._("Is that you final answer?"),
JOptionPane.YES_NO_OPTION,
JOptionPane.ERROR_MESSAGE);
if (n == JOptionPane.YES_OPTION){
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert));
isVerifying = false;
return true; // Confirmation positive
} else {
isVerifying = false;
return false; // Confirmation negative
}
} else { } else {
return false; // Confirmation negative return false; // No
} }
} else { } else {
return false; // No return false;
} }
} }
} }

View File

@ -9,6 +9,9 @@ import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -33,6 +36,8 @@ import net.i2p.itoopie.i18n.Transl;
import net.i2p.itoopie.i2pcontrol.InvalidParametersException; import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException; import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
import net.i2p.itoopie.i2pcontrol.methods.GetNetworkSetting; import net.i2p.itoopie.i2pcontrol.methods.GetNetworkSetting;
import net.i2p.itoopie.i2pcontrol.methods.RouterRunner.ROUTER_RUNNER;
import net.i2p.itoopie.i2pcontrol.methods.SetRouterRunner;
import net.i2p.itoopie.i2pcontrol.methods.NetworkSetting.NETWORK_SETTING; import net.i2p.itoopie.i2pcontrol.methods.NetworkSetting.NETWORK_SETTING;
import net.i2p.itoopie.i2pcontrol.methods.SetNetworkSetting; import net.i2p.itoopie.i2pcontrol.methods.SetNetworkSetting;
@ -97,11 +102,20 @@ public class ConfigurationTab extends TabLogoPanel {
@Override @Override
public void run() { public void run() {
applyNewSettings(); applyNewSettings();
btnApply.repaint(); // Removes a transparent ring around button after clicks.
} }
}); });
} }
}); });
btnApply.addMouseListener(new MouseAdapter(){
@Override
public void mouseEntered(MouseEvent arg0) {
getRootPane().repaint(); // Removes a transparent ring around button after mouse hovering.
}
@Override
public void mouseExited(MouseEvent arg0) {
getRootPane().repaint(); // Removes a transparent ring around button after mouse hovering.
}
});
validate(); validate();
@ -371,6 +385,24 @@ public class ConfigurationTab extends TabLogoPanel {
switch (saveSettings()){ switch (saveSettings()){
case SAVED_RESTART_NEEDED: case SAVED_RESTART_NEEDED:
StatusHandler.setStatus(SAVE_STATUS.SAVED_RESTART_NEEDED.toString()); StatusHandler.setStatus(SAVE_STATUS.SAVED_RESTART_NEEDED.toString());
int n = JOptionPane.showConfirmDialog(
this,
Transl._("The new settings have been applied,\r\n" + "" +
"but the I2P router needs to be restarted for some to take effect.\r\n" +
"\r\nWould you like to restart the I2P router now?"),
Transl._("Restart needed for new settings."),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (n == JOptionPane.YES_OPTION){
try {
SetRouterRunner.execute(ROUTER_RUNNER.RESTART);
StatusHandler.setStatus(Transl._("Restarting I2P node.. "));
} catch (InvalidPasswordException e) {
StatusHandler.setStatus(Transl._("Restart failed: ") + DEFAULT_STATUS.INVALID_PASSWORD);
} catch (JSONRPC2SessionException e) {
StatusHandler.setStatus(Transl._("Restart failed: ") + DEFAULT_STATUS.NOT_CONNECTED);
}
}
break; break;
case SAVED_OK: case SAVED_OK:
StatusHandler.setStatus(SAVE_STATUS.SAVED_OK.toString()); StatusHandler.setStatus(SAVE_STATUS.SAVED_OK.toString());

View File

@ -22,6 +22,7 @@ import javax.swing.ImageIcon;
import net.i2p.itoopie.gui.component.BandwidthChart; import net.i2p.itoopie.gui.component.BandwidthChart;
import net.i2p.itoopie.gui.component.LogoPanel; import net.i2p.itoopie.gui.component.LogoPanel;
import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart; import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart;
import net.i2p.itoopie.gui.component.RegisteredFrame;
import net.i2p.itoopie.gui.component.TabLogoPanel; import net.i2p.itoopie.gui.component.TabLogoPanel;
import net.i2p.itoopie.gui.component.util.TabChangeListener; import net.i2p.itoopie.gui.component.util.TabChangeListener;
import net.i2p.itoopie.util.IconLoader; import net.i2p.itoopie.util.IconLoader;
@ -120,8 +121,9 @@ public class Main {
} }
}); });
frame.validate();
frame.repaint(); // Force repaint to make sure that Logo is loaded.
frame.setVisible(true); frame.setVisible(true);
//frame.repaint(); // Force repaint to make sure that Logo is loaded.
} }
} }

View File

@ -2,6 +2,7 @@ package net.i2p.itoopie.gui;
import java.awt.Color; import java.awt.Color;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.util.EnumMap;
import info.monitorenter.gui.chart.Chart2D; import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.views.ChartPanel; import info.monitorenter.gui.chart.views.ChartPanel;
@ -10,16 +11,27 @@ import javax.swing.BorderFactory;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.gui.StatusHandler.DEFAULT_STATUS;
import net.i2p.itoopie.gui.component.BandwidthChart; import net.i2p.itoopie.gui.component.BandwidthChart;
import net.i2p.itoopie.gui.component.MultiLineLabel; import net.i2p.itoopie.gui.component.MultiLineLabel;
import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart; import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart;
import net.i2p.itoopie.gui.component.TabLogoPanel; import net.i2p.itoopie.gui.component.TabLogoPanel;
import net.i2p.itoopie.gui.component.multilinelabel.MultiLineLabelUI; import net.i2p.itoopie.gui.component.multilinelabel.MultiLineLabelUI;
import net.i2p.itoopie.i18n.Transl; import net.i2p.itoopie.i18n.Transl;
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
import net.i2p.itoopie.i2pcontrol.methods.GetRouterInfo;
import net.i2p.itoopie.i2pcontrol.methods.RouterInfo.ROUTER_INFO;
public class OverviewTab extends TabLogoPanel { public class OverviewTab extends TabLogoPanel {
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
private final static int DEFAULT_INFO_UPDATE_INTERVAL = 30*1000; // Milliseconds.
JLabel lblI2P; JLabel lblI2P;
JLabel lblVersion; JLabel lblVersion;
JLabel lblVersionSpecified; JLabel lblVersionSpecified;
@ -64,7 +76,7 @@ public class OverviewTab extends TabLogoPanel {
add(lblVersionSpecified); add(lblVersionSpecified);
lblVersionSpecified.setBounds(395, 50, 140, 15); lblVersionSpecified.setBounds(395, 50, 140, 15);
lblVersionSpecified.setHorizontalAlignment(SwingConstants.LEFT); lblVersionSpecified.setHorizontalAlignment(SwingConstants.LEFT);
lblVersionSpecified.setText("0.8.7-48rc"); // Delete Me // lblVersionSpecified.setText("0.8.7-48rc"); // Delete Me
lblUptime = new JLabel(); lblUptime = new JLabel();
@ -77,7 +89,7 @@ public class OverviewTab extends TabLogoPanel {
add(lblUptimeSpecified); add(lblUptimeSpecified);
lblUptimeSpecified.setBounds(395, 70, 140, 15); lblUptimeSpecified.setBounds(395, 70, 140, 15);
lblUptimeSpecified.setHorizontalAlignment(SwingConstants.LEFT); lblUptimeSpecified.setHorizontalAlignment(SwingConstants.LEFT);
lblUptimeSpecified.setText("93 min"); // Delete Me // lblUptimeSpecified.setText("93 min"); // Delete Me
lblStatus = new JLabel(); lblStatus = new JLabel();
@ -90,7 +102,7 @@ public class OverviewTab extends TabLogoPanel {
add(lblStatusSpecified); add(lblStatusSpecified);
lblStatusSpecified.setBounds(395, 90, 140, 15); lblStatusSpecified.setBounds(395, 90, 140, 15);
lblStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT); lblStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT);
lblStatusSpecified.setText("Rejecting Tunnels"); // Delete Me // lblStatusSpecified.setText("Rejecting Tunnels"); // Delete Me
lblNetworkStatus = new JLabel(); lblNetworkStatus = new JLabel();
add(lblNetworkStatus); add(lblNetworkStatus);
@ -103,14 +115,53 @@ public class OverviewTab extends TabLogoPanel {
lblNetworkStatusSpecified.setBounds(395, 110, 130, 60); lblNetworkStatusSpecified.setBounds(395, 110, 130, 60);
lblNetworkStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT); lblNetworkStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT);
lblNetworkStatusSpecified.setVerticalTextAlignment(JLabel.TOP); lblNetworkStatusSpecified.setVerticalTextAlignment(JLabel.TOP);
lblNetworkStatusSpecified.setText("WARN-Firewalled with Inbound TCP Enabled".replace('-', ' ')); // Delete Me // lblNetworkStatusSpecified.setText("WARN-Firewalled with Inbound TCP Enabled".replace('-', ' ')); // Delete Me
validate(); validate();
final int updateInterval = _conf.getConf("overview.info.updateinterval", DEFAULT_INFO_UPDATE_INTERVAL);
(new Thread(){
@Override
public void run() {
while (true) {
populateInfo();
try {
Thread.sleep(updateInterval);
} catch (InterruptedException e){} // Doesn't matter.
}
}
}).start();
} }
private void populateInfo(){
try {
EnumMap<ROUTER_INFO, Object> em = GetRouterInfo.execute(ROUTER_INFO.VERSION,
ROUTER_INFO.UPTIME, ROUTER_INFO.STATUS, ROUTER_INFO.NETWORK_STATUS);
lblVersionSpecified.setText((String) em.get(ROUTER_INFO.VERSION));
lblUptimeSpecified.setText((String) em.get(ROUTER_INFO.UPTIME));
lblUptimeSpecified.revalidate();
lblStatusSpecified.setText((String) em.get(ROUTER_INFO.STATUS));
lblNetworkStatusSpecified.setText(((String) em.get(ROUTER_INFO.NETWORK_STATUS)).replace("-", " "));
this.getRootPane().repaint(); // Repainting jlabel or jpanel is not enough.
StatusHandler.setDefaultStatus(DEFAULT_STATUS.CONNECTED);
} catch (InvalidPasswordException e) {
StatusHandler.setDefaultStatus(DEFAULT_STATUS.INVALID_PASSWORD);
} catch (JSONRPC2SessionException e) {
StatusHandler.setDefaultStatus(DEFAULT_STATUS.NOT_CONNECTED);
}
}
@Override @Override
public void onTabFocus(ChangeEvent e) { public void onTabFocus(ChangeEvent e) {
// Do thigns when shown? populateInfo();
} }
/** /**
@ -131,4 +182,7 @@ public class OverviewTab extends TabLogoPanel {
} }
}); });
} }
} }

View File

@ -1,6 +1,9 @@
package net.i2p.itoopie.gui; package net.i2p.itoopie.gui;
import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
@ -19,9 +22,12 @@ import javax.swing.JSeparator;
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException; import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
import net.i2p.itoopie.configuration.ConfigurationManager; import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.gui.component.RegisteredFrame;
import net.i2p.itoopie.i18n.Transl; import net.i2p.itoopie.i18n.Transl;
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException; import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
import net.i2p.itoopie.i2pcontrol.JSONRPC2Interface; import net.i2p.itoopie.i2pcontrol.JSONRPC2Interface;
import net.i2p.itoopie.security.ItoopieHostnameVerifier;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -137,10 +143,14 @@ public class SettingsFrame extends RegisteredFrame{
networkPanel.add(passwordField); networkPanel.add(passwordField);
JButton btnDone = new JButton("Done"); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
btnDone.setAlignmentY(Component.BOTTOM_ALIGNMENT); buttonPanel.setAlignmentY(BOTTOM_ALIGNMENT);
btnDone.setAlignmentX(Component.RIGHT_ALIGNMENT); buttonPanel.setMaximumSize(new Dimension(2000, 24));
getContentPane().add(btnDone); getContentPane().add(buttonPanel);
JButton btnDone = new JButton("Apply");
buttonPanel.add(btnDone);
btnDone.addActionListener(new ActionListener(){ btnDone.addActionListener(new ActionListener(){
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
@ -152,8 +162,21 @@ public class SettingsFrame extends RegisteredFrame{
} }
}); });
JButton btnClose = new JButton(Transl._("Discard"));
buttonPanel.add(btnClose);
btnClose.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
// Run on init. // Run on init.
populateSettings(); populateSettings();
validate();
} }
@Override @Override
@ -166,14 +189,15 @@ public class SettingsFrame extends RegisteredFrame{
private void populateSettings(){ private void populateSettings(){
textFieldRouterIP.setText(_conf.getConf("server.hostname", "127.0.0.1")); textFieldRouterIP.setText(_conf.getConf("server.hostname", "127.0.0.1"));
textFieldRouterPort.setText(_conf.getConf("server.port", 7560)+""); textFieldRouterPort.setText(_conf.getConf("server.port", 7650)+"");
passwordField.setText(_conf.getConf("server.password", "itoopie")); passwordField.setText(_conf.getConf("server.password", "itoopie"));
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
private int saveSettings(){ private int saveSettings(){
ItoopieHostnameVerifier.clearRecentlyDenied();
String oldIP = _conf.getConf("server.hostname", "127.0.0.1"); String oldIP = _conf.getConf("server.hostname", "127.0.0.1");
int oldPort = _conf.getConf("server.port", 7560); int oldPort = _conf.getConf("server.port", 7650);
String oldPW = _conf.getConf("server.password", "itoopie"); String oldPW = _conf.getConf("server.password", "itoopie");
@ -238,12 +262,13 @@ public class SettingsFrame extends RegisteredFrame{
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return SAVE_ERROR; return SAVE_ERROR;
} }
_conf.setConf("server.hostname", ipText); _conf.setConf("server.hostname", ipText);
_conf.setConf("server.port", port); _conf.setConf("server.port", port);
_conf.setConf("server.password", pwText); _conf.setConf("server.password", pwText);
_log.debug("Ip old->new: \""+_conf.getConf("server.hostname","127.0.0.1")+"\"->\"" + ipText + "\""); _log.debug("Ip old->new: \""+_conf.getConf("server.hostname","127.0.0.1")+"\"->\"" + ipText + "\"");
_log.debug("Port old->new: \""+_conf.getConf("server.port",7560)+"\"->\"" + portText + "\""); _log.debug("Port old->new: \""+_conf.getConf("server.port",7650)+"\"->\"" + portText + "\"");
_log.debug("Password old->new: \""+oldPW+"\"->\"" + pwText + "\""); _log.debug("Password old->new: \""+oldPW+"\"->\"" + pwText + "\"");
StatusHandler.setStatus("Settings saved"); StatusHandler.setStatus("Settings saved");

View File

@ -22,6 +22,7 @@ import java.text.SimpleDateFormat;
import javax.swing.JFrame; import javax.swing.JFrame;
import net.i2p.itoopie.configuration.ConfigurationManager; import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.gui.component.chart.BandwidthTracker;
import net.i2p.itoopie.gui.component.chart.DummyDataCollector; import net.i2p.itoopie.gui.component.chart.DummyDataCollector;
import net.i2p.itoopie.gui.component.chart.RateStatTracker; import net.i2p.itoopie.gui.component.chart.RateStatTracker;
import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter; import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter;
@ -30,7 +31,7 @@ import net.i2p.itoopie.i18n.Transl;
public class BandwidthChart { public class BandwidthChart {
private static ConfigurationManager _conf = ConfigurationManager.getInstance(); private static ConfigurationManager _conf = ConfigurationManager.getInstance();
private final static int DEFAULT_UPDATE_INTERVAL =1000; // Update every 1000th ms private final static int DEFAULT_UPDATE_INTERVAL = 2500; // Update every 2500th ms
private final static int DEFAULT_GRAPH_INTERVAL = 2*3600; // The graph will cover a maximum of 2hrs private final static int DEFAULT_GRAPH_INTERVAL = 2*3600; // The graph will cover a maximum of 2hrs
private final static String DATE_FORMAT = "HH:mm:ss"; private final static String DATE_FORMAT = "HH:mm:ss";
@ -70,12 +71,12 @@ public class BandwidthChart {
chart.getAxisY().setAxisTitle(new AxisTitle("")); chart.getAxisY().setAxisTitle(new AxisTitle(""));
// force ranges: // force ranges:
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20))); chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 5)));
//new ObjRecorder2Trace2DAdapter(dataBWIn, new RateStatTracker("bw.sendRate", 3600000L), "m_value", updateInterval); new ObjRecorder2Trace2DAdapter(dataBWIn, new BandwidthTracker("bw.sendRate", 60*1000L), "m_value", updateInterval);
new ObjRecorder2Trace2DAdapter(dataBWIn, new DummyDataCollector(0.5, 1000), "m_number", updateInterval); // new ObjRecorder2Trace2DAdapter(dataBWIn, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
//new ObjRecorder2Trace2DAdapter(dataBWOut, new RateStatTracker("bw.recvRate", 3600000L), "m_value", updateInterval); new ObjRecorder2Trace2DAdapter(dataBWOut, new BandwidthTracker("bw.recvRate", 60*1000L), "m_value", updateInterval);
new ObjRecorder2Trace2DAdapter(dataBWOut, new DummyDataCollector(0.5, 1000), "m_number", updateInterval); // new ObjRecorder2Trace2DAdapter(dataBWOut, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
return chart; return chart;
} }

View File

@ -64,8 +64,8 @@ public class ParticipatingTunnelsChart {
// force ranges: // force ranges:
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20))); chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20)));
//new ObjRecorder2Trace2DAdapter(dataPartTunnels, new RateStatTracker("tunnel.participatingTunnels", 3600000L), "m_value", updateInterval); new ObjRecorder2Trace2DAdapter(dataPartTunnels, new RateStatTracker("tunnel.participatingTunnels", 3600000L), "m_value", updateInterval);
new ObjRecorder2Trace2DAdapter(dataPartTunnels, new DummyDataCollector(0.5, 1000), "m_number", updateInterval); //new ObjRecorder2Trace2DAdapter(dataPartTunnels, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
return chart; return chart;
} }

View File

@ -1,10 +1,11 @@
package net.i2p.itoopie.gui; package net.i2p.itoopie.gui.component;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import javax.swing.JFrame; import javax.swing.JFrame;
import net.i2p.itoopie.gui.WindowHandler;
import net.i2p.itoopie.util.IconLoader; import net.i2p.itoopie.util.IconLoader;
public class RegisteredFrame extends JFrame implements WindowListener{ public class RegisteredFrame extends JFrame implements WindowListener{

View File

@ -0,0 +1,59 @@
package net.i2p.itoopie.gui.component.chart;
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
import net.i2p.itoopie.i2pcontrol.methods.GetRateStat;
public class BandwidthTracker extends Thread {
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
/** Last read bw */
private double m_value = 0;
/** Poll router for current ratestat every updateInterval seconds */
private final static int DEFAULT_UPDATE_INTERVAL = 100; // Update every 100th ms
private int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
/** Which RateStat to measure from the router */
private String rateStat;
/** Which period of a stat to measure */
private long period;
/**
* Start daemon that checks to current inbound bandwidth of the router.
*/
public BandwidthTracker(String rateStat, long period) {
this.rateStat = rateStat;
this.period = period;
this.setDaemon(true);
this.start();
}
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
while (true) {
try {
m_value = GetRateStat.execute(rateStat, period) / 1024; //Bytes -> KBytes
} catch (InvalidPasswordException e) {
} catch (JSONRPC2SessionException e) {
} catch (InvalidParametersException e) {
}
try {
Thread.sleep(updateInterval);
} catch (InterruptedException e) {
// nop
}
}
}
}

View File

@ -10,6 +10,7 @@ import javax.net.ssl.HttpsURLConnection;
import net.i2p.itoopie.configuration.ConfigurationManager; import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.i2pcontrol.methods.Authenticate; import net.i2p.itoopie.i2pcontrol.methods.Authenticate;
import net.i2p.itoopie.security.CertificateHelper; import net.i2p.itoopie.security.CertificateHelper;
import net.i2p.itoopie.security.ItoopieHostnameVerifier;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -57,7 +58,7 @@ public class JSONRPC2Interface {
} }
public static void testSettings() throws InvalidPasswordException, JSONRPC2SessionException{ public static void testSettings() throws InvalidPasswordException, JSONRPC2SessionException{
HttpsURLConnection.setDefaultHostnameVerifier(CertificateHelper.getHostnameVerifier()); HttpsURLConnection.setDefaultHostnameVerifier(new ItoopieHostnameVerifier());
setupSession(); setupSession();
Authenticate.execute(); Authenticate.execute();
} }

View File

@ -1,5 +1,6 @@
package net.i2p.itoopie.i2pcontrol.methods; package net.i2p.itoopie.i2pcontrol.methods;
import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -33,11 +34,24 @@ public class GetRateStat{
try { try {
resp = JSONRPC2Interface.sendReq(req); resp = JSONRPC2Interface.sendReq(req);
HashMap inParams = (HashMap) resp.getResult(); HashMap inParams = (HashMap) resp.getResult();
Double dbl = (Double) inParams.get("Result");
return dbl;
try {
Double dbl = (Double) inParams.get("Result");
return dbl;
} catch (ClassCastException e){
_log.debug("Error: Tried to cast a BigDecimal as Double");
}
try {
BigDecimal bigNum = (BigDecimal) inParams.get("Result");
Double dbl = bigNum.doubleValue();
return dbl;
} catch (ClassCastException e){
_log.debug("Error: Tried to cast a double as a BigDecimal");
}
}catch (UnrecoverableFailedRequestException e) { }catch (UnrecoverableFailedRequestException e) {
_log.error("getRateStat failed.", e); _log.error("getRateStat failed.", e);
} }
return null; return new Double(0);
} }
} }

View File

@ -22,7 +22,7 @@ import org.apache.commons.logging.LogFactory;
public class CertificateHelper { public class CertificateHelper {
private static Log _log; private static Log _log;
static { static {
@ -108,34 +108,4 @@ public class CertificateHelper {
return buf.toString(); return buf.toString();
} }
public static HostnameVerifier getHostnameVerifier(){
return new HostnameVerifier(){
public boolean verify(String urlHostName, SSLSession session) {
String serverHost = session.getPeerHost() + ":" + session.getPeerPort();
try {
javax.security.cert.X509Certificate[] certs = session.getPeerCertificateChain();
if (CertificateManager.contains(serverHost)){
if (CertificateManager.verifyCert(serverHost, CertificateHelper.convert(certs[0]))){
return true; // Remote host has provided valid certificate that is store locally.
} else {
// Remote host has provided a certificate that != the stored certificate for this host
return CertificateGUI.overwriteCert(serverHost, certs[0]);
}
} else {
// GUI, Add new host! new host
return CertificateGUI.saveNewCert(serverHost, certs[0]);
}
} catch (SSLPeerUnverifiedException e) {
_log.fatal("Remote host could not be verified, possibly due to using not using athentication");
return false;
}
}
};
}
} }

View File

@ -0,0 +1,59 @@
package net.i2p.itoopie.security;
import java.util.HashSet;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.security.cert.X509Certificate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.i2p.itoopie.gui.CertificateGUI;
public class ItoopieHostnameVerifier implements HostnameVerifier{
private static final Log _log = LogFactory.getLog(ItoopieHostnameVerifier.class);
private static final HashSet<String> recentlyDeniedHosts = new HashSet<String>();
public boolean verify(String urlHostName, SSLSession session) {
String serverHost = session.getPeerHost() + ":" + session.getPeerPort();
try {
javax.security.cert.X509Certificate[] certs = session.getPeerCertificateChain();
if (recentlyDeniedHosts.contains(session.getPeerHost() + ":" + session.getPeerPort())){
return false; // Deny recently denied hosts.
}
if (CertificateManager.contains(serverHost)) {
if (CertificateManager.verifyCert(serverHost,
CertificateHelper.convert(certs[0]))) {
return true; // Remote host has provided valid certificate that is store locally.
} else {
// Remote host has provided a certificate that != the stored certificate for this host
if (CertificateGUI.overwriteCert(serverHost, certs[0])){
return true;
} else {
recentlyDeniedHosts.add(session.getPeerHost() + ":" + session.getPeerPort());
return false;
}
}
} else {
// GUI, Add new host! new host
if (CertificateGUI.saveNewCert(serverHost, certs[0])){
return true;
} else {
recentlyDeniedHosts.add(session.getPeerHost() + ":" + session.getPeerPort());
return false;
}
}
} catch (SSLPeerUnverifiedException e) {
_log.fatal("Remote host could not be verified, possibly due to using not using athentication");
return false;
}
}
public static void clearRecentlyDenied(){
recentlyDeniedHosts.clear();
}
}