[Javanetsim-cvs] javaNetSim/guiUI GuiExternalNAT.java, NONE, 1.1 PosixTelnetClientGUI.java, NONE,
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-11-08 14:27:35
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1984/guiUI Modified Files: ApplicationLayerDevice.java MainScreen.java MenuBar.java SandBox.java SetTCPIPPropertiesDialog.java TelnetEmulator.java Added Files: GuiExternalNAT.java PosixTelnetClientGUI.java Log Message: --- NEW FILE: GuiExternalNAT.java --- /* Java Firewall Simulator (jFirewallSim) Copyright (c) 2004, jFirewallSim development team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Canberra Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package guiUI; /** * <P>The GuiRouter class is used to instantiate new Routers on the GUI</P> * * @author VC2 Team. * @since 15th November 2004 * @version v0.20 */ public class GuiExternalNAT extends NetworkLayerDevice { /** * @param inName The name of the router * @param inMainscreen The JFrame that the router will be created on */ public GuiExternalNAT(String inName, MainScreen inMainScreen){ super(inName, inMainScreen,"images/simulation/network_local.png"); } } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/ApplicationLayerDevice.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ApplicationLayerDevice.java 25 Feb 2006 22:48:34 -0000 1.8 --- ApplicationLayerDevice.java 8 Nov 2006 14:27:29 -0000 1.9 *************** *** 29,32 **** --- 29,33 ---- private JMenuItem mnuTelnetNoListen = new JMenuItem("Stop telnet server."); private JMenuItem mnuTelnetConnect = new JMenuItem("Telnet client."); + private JMenuItem mnuPosixTelnet = new JMenuItem("RFC(line) telnet client."); private JMenu mnuAppLayer = new JMenu("Applications"); private JMenuItem mnuSNMPStartAgent = new JMenuItem("Start SNMP agent"); *************** *** 104,107 **** --- 105,115 ---- } }); + + mnuPosixTelnet.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + controller.PosixTelnet(lblNodeName.getText()); + } + }); + mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuSNMPStartAgent); *************** *** 112,115 **** --- 120,125 ---- mnuAppLayer.add(mnuTelnetNoListen); mnuAppLayer.add(mnuTelnetConnect); + mnuAppLayer.addSeparator(); + mnuAppLayer.add(mnuPosixTelnet); } } Index: TelnetEmulator.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/TelnetEmulator.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TelnetEmulator.java 5 Sep 2006 21:04:36 -0000 1.8 --- TelnetEmulator.java 8 Nov 2006 14:27:29 -0000 1.9 *************** *** 87,90 **** --- 87,92 ---- private JTextArea terminal; private String text; + private String Host; + private int Port; private KeyListener kl; MainScreen parent; *************** *** 95,98 **** --- 97,102 ---- this.telnet = telnet; this.parent = parent; + this.Host = Host; + this.Port = Port; *************** *** 143,146 **** --- 147,155 ---- scrollpane.setViewportView(terminal); + + } + + + public void start(){ try{ this.telnet.TelnetConnect(this, Host, Port); *************** *** 169,177 **** /// ! } ! } - - public void recvData(String Data){ --- 178,183 ---- /// ! } } public void recvData(String Data){ Index: SetTCPIPPropertiesDialog.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SetTCPIPPropertiesDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SetTCPIPPropertiesDialog.java 26 Oct 2006 17:06:11 -0000 1.3 --- SetTCPIPPropertiesDialog.java 8 Nov 2006 14:27:29 -0000 1.4 *************** *** 372,376 **** try { ! if(NodeName != null && Interface != null && IPAddress != null){ Sim.setIPAddress(NodeName,Interface,IPAddress); controller.addToConsole(NodeName +"'s IP Address has been set to " + IPAddress + " on interface "+Interface+"\n"); --- 372,376 ---- try { ! if(NodeName != null && Interface != null && IPAddress != null && !ErrorFlag){ Sim.setIPAddress(NodeName,Interface,IPAddress); controller.addToConsole(NodeName +"'s IP Address has been set to " + IPAddress + " on interface "+Interface+"\n"); *************** *** 380,391 **** controller.addToConsole(NodeName +"'s Subnet Address has been set to " + SubnetMask + " on interface "+Interface+"\n"); ! } ! ! if(NodeName != null){ Sim.setDefaultGateway(NodeName,DefaultGWAddress); controller.addToConsole(NodeName +"'s Default Gateway Address has been set to " + DefaultGWAddress +"\n"); ! } ! ! this.dispose(); } catch (Exception e) { e.printStackTrace(); --- 380,391 ---- controller.addToConsole(NodeName +"'s Subnet Address has been set to " + SubnetMask + " on interface "+Interface+"\n"); ! ! if(NodeName != null){ Sim.setDefaultGateway(NodeName,DefaultGWAddress); controller.addToConsole(NodeName +"'s Default Gateway Address has been set to " + DefaultGWAddress +"\n"); ! } ! ! this.dispose(); ! } } catch (Exception e) { e.printStackTrace(); *************** *** 566,580 **** String tempip = txtIpAddress.getText(); ! if(Simulation.validateDecIP(tempip)){ if(txtSubnetMask.getText().equals("Enter Subnet Mask") || txtSubnetMask.getText() == null || txtSubnetMask.getText().equals("0.0.0.0")){ String tempSubnet = Simulation.getDefaultSubnetMask(tempip); txtSubnetMask.setText(tempSubnet); txtSubnetMask.setEnabled(true); } btnOk.setEnabled(true); ! }else{ txtSubnetMask.setText("Enter Subnet Mask"); txtSubnetMask.setEnabled(false); ! } } } --- 566,582 ---- String tempip = txtIpAddress.getText(); ! //if(Simulation.validateDecIP(tempip)){ if(txtSubnetMask.getText().equals("Enter Subnet Mask") || txtSubnetMask.getText() == null || txtSubnetMask.getText().equals("0.0.0.0")){ String tempSubnet = Simulation.getDefaultSubnetMask(tempip); txtSubnetMask.setText(tempSubnet); + txtSubnetMask.setEnabled(true); } btnOk.setEnabled(true); ! ! /*}else{ txtSubnetMask.setText("Enter Subnet Mask"); txtSubnetMask.setEnabled(false); ! }*/ } } Index: SandBox.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SandBox.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SandBox.java 8 Nov 2005 04:04:23 -0000 1.1.1.1 --- SandBox.java 8 Nov 2006 14:27:29 -0000 1.2 *************** *** 50,53 **** --- 50,54 ---- public static final int SWITCH_CURSOR = 2; public static final int HUB_CURSOR = 3; + public static final int EXTERNALNAT_CURSOR = 4; private Cursor csrDefault = new Cursor(Cursor.DEFAULT_CURSOR); *************** *** 73,76 **** --- 74,80 ---- Image hubImage = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/simulation/hub_large.gif")); Cursor customHubCursor = Toolkit.getDefaultToolkit().createCustomCursor(hubImage, cursorLocation, "hubCursor"); + + Image externalnatImage = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/simulation/network_local.png")); + Cursor customExternalNATCursor = Toolkit.getDefaultToolkit().createCustomCursor(externalnatImage, cursorLocation, "externalnatCursor"); public SandBox(MainScreen inMainScreen){ *************** *** 188,191 **** --- 192,199 ---- Point NodeLocation = new Point(e.getX(), e.getY()); controller.addHub(NodeLocation); + }else if(this.getCursor() == customExternalNATCursor){ + this.setCursor(csrDefault); + Point NodeLocation = new Point(e.getX(), e.getY()); + controller.addExternalNAT(NodeLocation); } } *************** *** 209,212 **** --- 217,222 ---- }else if(cursorType == HUB_CURSOR){ this.setCursor(customHubCursor); + }else if(cursorType == EXTERNALNAT_CURSOR){ + this.setCursor(customExternalNATCursor); } Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** MainScreen.java 26 Oct 2006 17:06:11 -0000 1.49 --- MainScreen.java 8 Nov 2006 14:27:29 -0000 1.50 *************** *** 716,720 **** } ! /** --- 716,780 ---- } ! /** ! ! * This method will create a Hub within the simulation and add it to the sandbox ! ! * @author Luke Hamilton ! ! * ! ! */ ! ! public void addExternalNAT(Point inPoint){ ! ! String result = JOptionPane.showInputDialog(this,"Please enter a NAT Gateway to External network name:","Create New NAT Gateway to External network", JOptionPane.PLAIN_MESSAGE); ! ! if(result != null){ ! ! result = result.trim(); ! ! if (!result.equalsIgnoreCase("")){ ! ! try { ! ! Sim.addExternalNAT(result); ! ! GuiExternalNAT tempEN = new GuiExternalNAT(result,this); ! ! tempEN.setNodeLocation(inPoint); ! ! GUInodeTable.put(result,tempEN); ! ! this.Sandbox.add(tempEN); ! ! Sandbox.setLayer(tempEN,3,0); ! ! isDirty = true; ! ! this.setAllHighlightsOff(); ! ! pnlConsole.append("Added Hub "+result+" to simulation\n"); ! ! } catch (InvalidNodeNameException e) { ! ! JOptionPane.showMessageDialog(this, "Invalid name entered. Node with name: '" + result+"' all ready exist within Simulation","Invalid Hub name", JOptionPane.ERROR_MESSAGE); ! ! } ! ! ! ! }else{ ! ! JOptionPane.showMessageDialog(this, "Device name not entered","Name not entered",JOptionPane.WARNING_MESSAGE); ! ! } ! ! } ! ! this.setAllHighlightsOff(); ! ! this.refreshNodeInformationTab(); ! ! } /** *************** *** 2153,2156 **** --- 2213,2232 ---- GUInodeTable.put(strNodeName,tempRouter); + }else if(strClassName.contains("GuiExternalNAT")){ + + deviceType = 2; + + Sim.addExternalNAT(strNodeName); + + GuiExternalNAT tempRouter = new GuiExternalNAT(strNodeName,this); + + tempRouter.setNodeLocation(pnt); + + Sandbox.add(tempRouter); + + Sandbox.setLayer(tempRouter,3,0); + + GUInodeTable.put(strNodeName,tempRouter); + } *************** *** 3327,3330 **** --- 3403,3407 ---- t.pack(); t.setVisible(true); + t.start(); }catch(Exception e){ addToConsole(e.toString()); *************** *** 3336,3339 **** --- 3413,3436 ---- } + + public void PosixTelnet(String inNodeName){ + String ip = JOptionPane.showInputDialog(this, "Server IP:", "Telnet connect to...", JOptionPane.QUESTION_MESSAGE); + if(ip!=null){ + String port = JOptionPane.showInputDialog(this, "Server Port:", "Telnet connect to...", JOptionPane.QUESTION_MESSAGE); + if(port!=null) { + try{ + printNetworkStart(); + PosixTelnetClientGUI t = new PosixTelnetClientGUI(this, ((core.ApplicationLayerDevice)Sim.getNode(inNodeName)),ip,Integer.valueOf(port).intValue()); + t.pack(); + t.setVisible(true); + t.start(); + }catch(Exception e){ + addToConsole(e.toString()); + } + addHeader(); + printLayerInfo(false); + } + } + } /** * Print routes table on throws node *************** *** 3370,3374 **** try{ ! if(Sim.getNode(inNodeName) instanceof core.NetworkLayerDevice){ msg = "Counters: \n\n Recieved IP Packets: " + Integer.valueOf(inIPCount).toString() + "\n Sent IP Packets: " + Integer.valueOf(outIPCount).toString() + --- 3467,3471 ---- try{ ! if(Sim.getNode(inNodeName) instanceof core.NetworkLayerDevice && !(Sim.getNode(inNodeName) instanceof core.ApplicationLayerDevice)){ msg = "Counters: \n\n Recieved IP Packets: " + Integer.valueOf(inIPCount).toString() + "\n Sent IP Packets: " + Integer.valueOf(outIPCount).toString() + --- NEW FILE: PosixTelnetClientGUI.java --- /* * TelnetEmulator.java * * Created on 22 Feb 2006, 16:38 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package guiUI; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.GridBagLayout; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JScrollPane; import javax.swing.JTextArea; import java.awt.Insets; import java.awt.GridBagConstraints; import java.awt.BorderLayout; import javax.swing.JButton; import java.awt.Dimension; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import core.Simulation; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.Color; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.util.Arrays; import java.awt.Component; import javax.swing.SwingConstants; import core.protocolsuite.tcp_ip.Telnet_client; import core.CommunicationException; import core.LowLinkException; import core.InvalidNetworkLayerDeviceException; import core.TransportLayerException; import java.awt.Font; import java.awt.event.KeyListener; import java.util.regex.*; import core.protocolsuite.tcp_ip.*; import java.util.Vector; /** * * @author key */ public class PosixTelnetClientGUI extends JFrame { private JPanel panel; private JScrollPane scrollpane; private JTextArea terminal; private JTextField cmdline; private String text; private KeyListener kl; private core.NetworkLayerDevice device; MainScreen parent; private Vector<String> history = new Vector<String>(0); private int pos_history=0; private final static int max_history = 128; private PosixTelnetClient ptc; private String Host; private int port; public boolean busy; /** Creates a new instance of TelnetEmulator */ public PosixTelnetClientGUI(MainScreen parent, core.ApplicationLayerDevice dev, String Host, int port) { super("Console: " + dev.NodeProtocolStack.getParentNodeName()); device = dev; this.Host = Host; this.port = port; this.parent = parent; ptc = (PosixTelnetClient) dev.getApp(10023); text = "Connecting to " + Host + ":" + port + "...\n"; panel = new JPanel(); scrollpane = new JScrollPane(); terminal = new JTextArea(text); cmdline = new JTextField(); this.setContentPane(panel); panel.setLayout(new java.awt.BorderLayout()); panel.add(scrollpane); panel.add(cmdline, BorderLayout.SOUTH); panel.setPreferredSize(new java.awt.Dimension(600,500)); scrollpane.setViewportView(terminal); terminal.setEnabled(true); terminal.setEditable(false); terminal.setBackground(Color.BLACK); terminal.setForeground(Color.WHITE); terminal.setFont(new Font("Courier New", Font.PLAIN, 12)); cmdline.setFocusable(true); cmdline.addKeyListener( kl = new KeyAdapter(){ // terminal.addKeyListener( kl = new KeyAdapter(){ public void keyPressed(KeyEvent e) { char c = e.getKeyChar(); switch(c) { case 0x0A: { if(cmdline.getText().compareTo("")!=0) { if(history.size()>=max_history) history.remove(0); history.add(cmdline.getText()); pos_history = history.size(); } String toSend = cmdline.getText() + "\n"; try{ ptc.SendData(toSend); }catch(Exception exc){ } text += cmdline.getText() + "\n"; cmdline.setText(""); printInfo(); break; } case 0x04: { exitWindow(); break; } case 0x1B: { cmdline.setText(""); break; } default: { if(c>=65535) { int i = e.getKeyCode(); switch(i) { case 0x26: { if(history.size()>0) { if(pos_history == history.size() && cmdline.getText().compareTo("")!=0) { if(history.size()>=max_history) history.remove(0); history.add(cmdline.getText()); pos_history = history.size()-1; } if(pos_history>0) { cmdline.setText(history.get(--pos_history)); } else if(pos_history>0) { cmdline.setText(history.get(pos_history-1)); } } break; } case 0x28: { if(history.size()>0) { if(pos_history+1<history.size()) { cmdline.setText(history.get(++pos_history)); } } break; } default: //terminal.setText(text+"\n"+Integer.toHexString(i)); } } else { pos_history = history.size(); } break; } } } }); this.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent winEvt) { printInfo(); } }); } public void start(){ try{ ptc.Telnet(this, Host, port); }catch(Exception e){ } } public void recvData(String Data){ busy = true; text += Data + "\n"; terminal.setText(text); busy = false; //try{ // ptc.SendData(""); //}catch(Exception e){ //} } public void exitWindow() { printInfo(); this.dispose(); } public void printInfo(){ parent.printLayerInfo(false); //!!!!!: add more headers here } private String removeSpaces(String s) { while(s.startsWith(" ")) s = s.substring(1); while(s.endsWith(" ")) s = s.substring(0, s.length()-1); return s; } } Index: MenuBar.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MenuBar.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MenuBar.java 12 Oct 2006 17:26:26 -0000 1.7 --- MenuBar.java 8 Nov 2006 14:27:29 -0000 1.8 *************** *** 55,58 **** --- 55,59 ---- private JMenuItem mnuHub = new JMenuItem("Hub ..."); private JMenuItem mnuSwitch = new JMenuItem("Switch ..."); + private JMenuItem mnuExternalNAT = new JMenuItem("NAT Gateway to External Network..."); //Tools submenu *************** *** 125,128 **** --- 126,130 ---- mnuAdd.add(mnuHub); mnuAdd.add(mnuSwitch); + //mnuAdd.add(mnuExternalNAT); mnuSimulation.add(mnuTools); *************** *** 214,217 **** --- 216,227 ---- }); + //Add action listener to new hub + mnuExternalNAT.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + controller.setAllHighlightsOff(); + controller.addingNode(SandBox.EXTERNALNAT_CURSOR); + } + }); + mnuMsgLinkLayer.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ |