[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Telnet_client.java,1.4,1.5 Telnet_server.java,
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-02-25 00:00:10
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6308/core/protocolsuite/tcp_ip Modified Files: Telnet_client.java Telnet_server.java Log Message: Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Telnet_client.java 24 Feb 2006 15:41:44 -0000 1.4 --- Telnet_client.java 25 Feb 2006 00:00:03 -0000 1.5 *************** *** 23,26 **** --- 23,27 ---- import guiUI.TelnetEmulator; + import core.ApplicationLayerDevice; /** *************** *** 31,41 **** public class Telnet_client extends Application{ ! private byte ConnectionAttempts=5; private TelnetEmulator terminal; private int counts; /** Creates a new instance of Telnet Server */ ! public Telnet_client(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); counts = 0; } --- 32,44 ---- public class Telnet_client extends Application{ ! private int ConnectionAttempts=1; ! private ApplicationLayerDevice mDevice; private TelnetEmulator terminal; private int counts; /** Creates a new instance of Telnet Server */ ! public Telnet_client(ApplicationLayerDevice dev, ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); + mDevice = dev; counts = 0; } *************** *** 78,82 **** LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); protInfo2.setLayer("Application "); protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); --- 81,85 ---- LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Telnet Protocol Data"); protInfo2.setLayer("Application "); protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); *************** *** 110,114 **** */ ! public void DisconnectEvent(){ } /** --- 113,119 ---- */ ! public void DisconnectEvent(){ ! System.out.print("\n---------------------------\n\nIT WORKS!!!\n\n----------------------------------\n"); ! } /** *************** *** 127,131 **** LayerInfo protInfo3 = new LayerInfo(getClass().getName()); protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Echo Protocol Data"); protInfo3.setLayer("Application "); if(appType==0){ --- 132,136 ---- LayerInfo protInfo3 = new LayerInfo(getClass().getName()); protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Telnet Protocol Data"); protInfo3.setLayer("Application "); if(appType==0){ *************** *** 172,176 **** LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); protInfo.setLayer("Application "); protInfo.setDescription("Recieving echo message '" + Data + "' from server."); --- 177,181 ---- LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); protInfo.setLayer("Application "); protInfo.setDescription("Recieving echo message '" + Data + "' from server."); *************** *** 185,189 **** if(Data.compareTo("\nQUIT")==0) { ! Close(); } terminal.recvData(Data); --- 190,194 ---- if(Data.compareTo("\nQUIT")==0) { ! Disconnect(); } terminal.recvData(Data); Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Telnet_server.java 24 Feb 2006 10:20:11 -0000 1.4 --- Telnet_server.java 25 Feb 2006 00:00:03 -0000 1.5 *************** *** 19,24 **** import core.Packet; ! import core.Simulation; /** --- 19,25 ---- import core.Packet; ! import core.ApplicationLayerDevice; import core.Simulation; + import java.util.regex.*; /** *************** *** 29,33 **** public class Telnet_server extends Application{ ! private byte ConnectionAttempts=5; private int counts; private String cmdline=""; --- 30,35 ---- public class Telnet_server extends Application{ ! private int ConnectionAttempts=1; ! private ApplicationLayerDevice mDevice; private int counts; private String cmdline=""; *************** *** 35,45 **** private boolean islogin=false; private boolean ispass=false; private String password = "123"; private String login = "root"; ! private String userlogin = ""; /** Creates a new instance of Telnet Server */ ! public Telnet_server(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); counts = 0; } --- 37,50 ---- private boolean islogin=false; private boolean ispass=false; + private boolean isprompt=true; + private boolean isnewpass=false; private String password = "123"; private String login = "root"; ! private String temp = ""; /** Creates a new instance of Telnet Server */ ! public Telnet_server(ApplicationLayerDevice dev, ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); + mDevice = dev; counts = 0; } *************** *** 92,96 **** */ ! public void DisconnectEvent(){ } /** --- 97,117 ---- */ ! public void DisconnectEvent(){ ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! try{ ! Close(); ! printInfo("Server closing connection"); ! try{ ! Listen(); ! printInfo("Server listening on port " + listenPort); ! } ! catch(TransportLayerException e){ ! printInfo("Server can not listen on port " + listenPort); ! } ! } ! catch(TransportLayerException e){ ! printInfo("Server can not close connection"); ! } ! } /** *************** *** 105,120 **** }catch(Exception e){ ///*TODO*: here to catch ! } - LayerInfo protInfo3 = new LayerInfo(getClass().getName()); - protInfo3.setObjectName(mParentStack.getParentNodeName()); - protInfo3.setDataType("Echo Protocol Data"); - protInfo3.setLayer("Application "); if(appType==0){ ! protInfo3.setDescription("Application closing connection."); }else{ ! protInfo3.setDescription("Application closing connection. Now listening on " + listenPort + "."); } - Simulation.addLayerInfo(protInfo3); mParentStack.CloseTCP(this); --- 126,136 ---- }catch(Exception e){ ///*TODO*: here to catch ! } if(appType==0){ ! printInfo("Application closing connection."); }else{ ! printInfo("Application closing connection. Now listening on port" + listenPort + "."); } mParentStack.CloseTCP(this); *************** *** 151,178 **** //server processing recieve ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from client."); ! Simulation.addLayerInfo(protInfo); ! ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Sending echo message '" + Data + "' to client."); ! Simulation.addLayerInfo(protInfo2); String outData=""; if(isenter && Data.compareTo("\n")==0) { ! outData = "\nlogin: "; islogin = true; isenter = false; } ! else { int ch = (char)Data.charAt(0); switch(ch) { - case 0x03: case 0x04: { outData = "\nQUIT"; --- 167,182 ---- //server processing recieve ! printInfo("Recieving echo message '" + Data + "' from client."); String outData=""; if(isenter && Data.compareTo("\n")==0) { ! outData = "login: "; islogin = true; isenter = false; } ! else ! { int ch = (char)Data.charAt(0); switch(ch) { case 0x04: { outData = "\nQUIT"; *************** *** 180,185 **** } case 0x08: { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); break; } --- 184,191 ---- } case 0x08: { ! if(cmdline.length() > 0) { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); ! } break; } *************** *** 187,191 **** if(islogin) { islogin = false; ! userlogin = cmdline; ispass = true; outData = "\npassword: "; --- 193,197 ---- if(islogin) { islogin = false; ! temp = cmdline; ispass = true; outData = "\npassword: "; *************** *** 193,198 **** else if(ispass) { ispass = false; ! if(userlogin.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\nWelcome to " + mParentStack.getParentNodeName() + "\n"; } else { --- 199,204 ---- else if(ispass) { ispass = false; ! if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\nWelcome to " + mParentStack.getParentNodeName() + "\n" + runcmd(""); } else { *************** *** 206,209 **** --- 212,232 ---- } } + else if(isnewpass) { + if(temp.compareTo("")==0) { + temp = cmdline; + outData = "\nRetype new password: "; + } + else { + if(temp.compareTo(cmdline)==0) { + password = temp; + outData = "\n" + runcmd(""); + } + else { + outData = "\n Password is not identical\n" + runcmd(""); + } + isnewpass = false; + temp=""; + } + } else { cmdline = removeSpaces(cmdline); *************** *** 214,230 **** } // case 0x1B: outData="ESC"; break; - case 0x20: { - if(ispass) { - outData="*"; - } - else { - outData=" "; - } - break; - } default: ! if(ch>=0x30 && ch<0x80) { ! if(ispass) { outData = "*"; } --- 237,244 ---- } // case 0x1B: outData="ESC"; break; default: ! if(ch>=0x20 && ch<0x80) { ! if(ispass || isnewpass) { outData = "*"; } *************** *** 239,246 **** } } ! try { SendData(outData); if(outData.compareTo("\nQUIT")==0) { Close(); isenter = true; } --- 253,262 ---- } } ! try { ! printInfo("Sending echo message '" + outData + "' to client."); SendData(outData); if(outData.compareTo("\nQUIT")==0) { Close(); + Listen(); isenter = true; } *************** *** 275,282 **** private String runcmd(String cmd) { ! if(cmd.compareToIgnoreCase("quit")==0) { return "QUIT"; } ! return "bad command\n"; } --- 291,396 ---- private String runcmd(String cmd) { ! String out=""; ! if(cmd.compareTo("")==0) { ! //nothing ! } ! else if(cmd.compareTo("?")==0) { ! out += "route \t\t show/edit route table\n"; ! out += "arp \t\t show/edit arp table"; ! out += "snmp \t\t on/off snmp agent\n"; ! out += "counters \t\t show network counters\n"; ! out += "passwd \t\t change password\n"; ! out += "quit \t\t close terminal session\n"; ! out += "? \t\t show this screen\n"; ! } ! else if(cmd.compareToIgnoreCase("quit")==0) { return "QUIT"; } ! else { ! String tokens[]=cmd.split(" "); ! Matcher m; ! // if(m.find()) { ! // if(m.group(1).compareTo("route")==0); ! // } ! if(tokens[0].compareTo("route")==0){ ! if((m=Pattern.compile(" +print$").matcher(cmd)).find()) { ! ! String routes[] = mParentStack.getRouteTableEntries(); ! out += "IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\n"; ! for(int i=0; i<routes.length - 1; i++){ ! Route_entry r = mParentStack.getRouteTableEntry(routes[i]); ! out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"; ! } ! } ! else if((m=Pattern.compile(" +add +([^ ]+) +([^ ]+) +([^ ]+)( +([^ ]+|\\*))?$").matcher(cmd)).find()) { ! String a = m.group(5); ! String b = m.group(4); ! Route_entry r = new Route_entry(m.group(1), m.group(5), m.group(3), m.group(2), 0); ! mParentStack.addRoute(r); ! out+="Route added.\n"; ! } ! else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { ! mParentStack.removeRoute(m.group(1)); ! out+="Route to " + tokens[2] + "removed.\n"; ! } ! else{ ! out+="Unknown route command. Usage:\n"; ! out+="route add (host_ip|network_ip) target_interface netmask (gateway|*) \n"; ! out+="route del (host_ip|network_ip) \n"; ! out+="route print \n"; ! } ! } ! else if(tokens[0].compareTo("snmp")==0){ ! if((m=Pattern.compile(" +(on|\\d+)( +([^ ]+))?$").matcher(cmd)).find()) { ! int l_port=161; ! String l_pass="public"; ! if(m.group(1).compareTo("on")!=0) l_port = Integer.parseInt(m.group(1)); ! if(m.group(2).compareTo("")!=0) l_pass = m.group(2); ! SNMP snmpa = (SNMP) mDevice.getApp(161); ! snmpa.setPassword(l_pass); ! snmpa.setPort(l_port); ! try{ ! snmpa.Listen(); ! } ! catch(TransportLayerException e) { ! out+="Unable to open connection on SNMP agent\n"; ! } ! } ! else if((m=Pattern.compile(" +off$").matcher(cmd)).find()) { ! SNMP snmpa = (SNMP) mDevice.getApp(161); ! try{ ! snmpa.Close(); ! } ! catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\n"; ! } ! } ! } ! else if(tokens[0].compareTo("passwd")==0){ ! temp=""; ! isnewpass=true; ! out="Type new password: "; ! return out; ! } ! else if(tokens[0].compareTo("counters")==0){ ! out += " Recieved IP Packets: " + Integer.valueOf(mParentStack.getinputIPCount()).toString() + ! "\n Sent IP Packets: " + Integer.valueOf(mParentStack.getoutputIPCount()).toString() + ! "\n ARP Packets: " + Integer.valueOf(mParentStack.getARPCount()).toString() + ! "\n Recieved TCP segments: " + Integer.valueOf(mParentStack.getTCPinputCount()).toString() + ! "\n Sent TCP segments: " + Integer.valueOf(mParentStack.getTCPoutputCount()).toString() + ! "\n Sent TCP ACK's: " + Integer.valueOf(mParentStack.getTCPACKCount()).toString() + ! "\n Sent TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPSDCount()).toString() + ! "\n Recieved TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPRDCount()).toString() + ! "\n Recieved UDP segments: " + Integer.valueOf(mParentStack.getUDPinputCount()).toString() + ! "\n Sent UDP segments: " + Integer.valueOf(mParentStack.getUDPoutputCount()).toString() + ! "\n"; ! } ! else if(tokens[0].compareTo("arp")==0){ ! ! } ! else out = tokens[0] + ": command not found\n"; ! } ! out+=mParentStack.getParentNodeName() + " # "; ! return out; } *************** *** 286,289 **** --- 400,412 ---- return s; } + + private void printInfo(String s) { + LayerInfo protInfo3 = new LayerInfo(getClass().getName()); + protInfo3.setObjectName(mParentStack.getParentNodeName()); + protInfo3.setDataType("Telnet Protocol Data"); + protInfo3.setLayer("Application "); + protInfo3.setDescription(s); + Simulation.addLayerInfo(protInfo3); + } } |