📄 host.java
字号:
ps.println("end."); ros.close(); ps.close(); return Communicator.checkConfig(HostAddresses.getFirstAddress()); } // try catch (Exception e) { return false; } } /** * Reconfigure firewall. * @return true on success, false otherwise */ public boolean reconfig() { return Communicator.reconfig(HostAddresses.getFirstAddress()); } // persistence methods /** * Write object data to a persistent output stream * @param ps Stream * @see PersistentOutputStream */ public void write(PersistentOutputStream ps) { super.write(ps); ps.writePersistent("HostAddresses=", HostAddresses); ps.writePersistent("internalAddresses=", internalAddresses); ps.writeBoolean("isFirewall=", isFirewall); ps.writeBoolean("transparent=", transparent); ps.writeBoolean("isServer=", isServer); ps.writeBoolean("publicServer=", publicServer); ps.writeInt("NumberOfTemplates=", hostTemplates.length); for (int i=0; i < hostTemplates.length; i++) ps.writeBoolean("TemplateItem=", hostTemplates[i]); } /** * Read object data from a persistent input stream * @param ps Stream * @see PersistentInputStream */ public void read(PersistentInputStream ps) throws java.io.IOException { super.read(ps); HostAddresses = (AddrList)ps.readPersistent("HostAddresses="); internalAddresses = (AddrList)ps.readPersistent("internalAddresses="); isFirewall = ps.readBoolean("isFirewall="); transparent = ps.readBoolean("transparent="); isServer = ps.readBoolean("isServer="); publicServer = ps.readBoolean("publicServer="); int tlen = ps.readInt("NumberOfTemplates="); boolean btmp[] = new boolean[tlen]; for (int i=0; i < tlen; i++) btmp[i] = ps.readBoolean("TemplateItem="); if (tlen == hostTemplates.length) hostTemplates = btmp; } // overriding Object methods /** * @return string describing the host */ public String toString() { return "Host: "+objectInfo(); } private static java.awt.image.ImageProducer bCpuSource = null; private static java.awt.image.ImageProducer bFirewallSource = null; private static java.awt.image.ImageProducer bServerSource = null; // host properties protected boolean isConsistent = false; // is configuration consistent? protected AddrList HostAddresses = new AddrList(); protected AddrList internalAddresses = null; // automatically calculated protected boolean isFirewall = false; // is this host a firewall? protected boolean transparent = true; // route traffic from outside to outside protected boolean isServer = false; // is this host a server (e.g.WWW) ? protected boolean publicServer = true; // is this server a public server, // i.e. access from the internet allowed? protected boolean hostTemplates[]; // variables for sfc show data protected transient boolean isLoaded = false; protected transient byte addr[][]; protected transient byte mask[][]; protected transient short port[]; protected transient short prend[]; protected transient Vector rules; protected transient String varnames[]; protected transient int varvalues[][]; protected transient byte varaddr[][][]; protected transient Date vartimeout[][]; protected transient Vector tcpconns; protected transient Date actDate; // server time and date when reading tcp connections private transient FirewallAction actionFrame = null;} // Host// Dialog to enter the host settingsclass HostProperties extends Dialog implements ActionListener, ItemListener, TextListener { public HostProperties(Frame parent, String title, Host hst) { super(parent, title, true); host = hst; GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(5,5,5,5); setLayout(gbl); // Name panel Utils.add_component(this, new JLabel(new ImageIcon(host.icon)), gbl, gbc, 0, 0, 1, 1, 0, 0); Utils.add_component(this, new Label("Identifier: "), gbl, gbc, 1, 0, 1, 1, 0, 0); IDtext = new TextField(host.objectID); IDtext.addTextListener(this); Utils.add_component(this, IDtext, gbl, gbc, 2, 0, 3, 1, 100, 0); // Address panel Panel ap = host.HostAddresses.editPanel(); Utils.add_component(this, ap, gbl, gbc, 0, 1, 3, 8, 80, 100); // Host type panel FirewallBox = new Checkbox("Firewall", host.isFirewall); FirewallBox.addItemListener(this); FirewallMore = new Button("More..."); FirewallMore.addActionListener(this); Utils.add_component(this, FirewallBox, gbl, gbc, 3, 2, 1, 1, 0, 0); Utils.add_component(this, FirewallMore, gbl, gbc, 4, 2, 1, 1, 0, 0); ServerBox = new Checkbox("Server", host.isServer); ServerBox.addItemListener(this); ServerMore = new Button("More..."); ServerMore.addActionListener(this); Utils.add_component(this, ServerBox, gbl, gbc, 3, 3, 1, 1, 0, 0); Utils.add_component(this, ServerMore, gbl, gbc, 4, 3, 1, 1, 0, 0); // Buttons OKbutton = new Button("OK"); OKbutton.addActionListener(this); gbc.fill = GridBagConstraints.NONE; Utils.add_component(this, OKbutton, gbl, gbc, 0, 9, 5, 1, 0, 0); // Window size Graphics g = parent.getGraphics(); FontMetrics fm = g.getFontMetrics(); setSize(fm.stringWidth("255.255.255.255/255.255.255.255 ") * 2, fm.getHeight() * 20 ); g.dispose(); addWindowListener(new HPAdapter()); } // Handle Windowclosingclass HPAdapter extends WindowAdapter { public void WindowClosing(WindowEvent we) { if (isEnabled()) dispose(); return; }} // HPAdapter // Process Buttons public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); // Process OKbutton if (source==OKbutton) { host.objectID = IDtext.getText().trim(); dispose(); return; } // Process FirewallMore else if (source==FirewallMore) { if (host.isFirewall) { AutoconfSettings as = new AutoconfSettings( Utils.getParentFrame(this), "Firewall Settings", host, Templates.startFirewall, Templates.numberFirewall); as.setVisible(true); } return; } // Process ServerMore else if (source==ServerMore) { if (host.isServer) { AutoconfSettings as = new AutoconfSettings( Utils.getParentFrame(this), "Server Settings", host, Templates.startServer, Templates.numberServer); as.setVisible(true); } return; } } // actionPerformed // Process Checkboxes public void itemStateChanged(ItemEvent ie) { Object source = ie.getSource(); // Process FirewallBox if (source==FirewallBox) { host.isFirewall = FirewallBox.getState(); return; } // Process ServerBox else if (source==ServerBox) { host.isServer = ServerBox.getState(); return; } } // itemStateChanged // Process TextFields public void textValueChanged(TextEvent te) { Object source = te.getSource(); // Process IDtext if (source==IDtext) { host.objectID = (((TextComponent)source).getText().trim()); setTitle("Host "+host.objectID); return; } } // textValueChanged public boolean isFirewall() { return FirewallBox.getState(); } // isFirewall private Host host; private Button OKbutton; private TextField IDtext; private Checkbox FirewallBox; private Checkbox ServerBox; private Button FirewallMore; private Button ServerMore;} // HostProperties// Dialog to enter the firewall and server access profilesclass AutoconfSettings extends Dialog implements ActionListener, ItemListener { public AutoconfSettings(Frame p, String title, Host hst, int st, int no) { super(p, title, true); start = st; number = no; host = hst; GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(5,5,5,5); setLayout(gbl); // Checkboxes gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.NORTHWEST; if (start == Templates.startServer) { // server dialog publicServerBox = new Checkbox("Public access to this server", host.publicServer); publicServerBox.addItemListener(this); Utils.add_component(this, publicServerBox, gbl, gbc, 0, 0, 4, 1, 0, 0); } if (start == Templates.startFirewall) { // firewall dialog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -