📄 rule.java
字号:
macroButton2 = new Button("New address macro..."); macroButton2.addActionListener(this); Utils.add_component(ap, macroButton2, agbl, agbc, 0, 2, 1, 1, 0, 0); // add protocol specific panel // =========================== validPanel = null; if ((pallBox.getState() || ptcpBox.getState()) && acceptBox.getState()) { Utils.add_component(this, FTPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = FTPPanel; } if (picmpBox.getState()) { Utils.add_component(this, ICMPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = ICMPPanel; } if (pigmpBox.getState()) { Utils.add_component(this, IGMPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = IGMPPanel; } if (pripBox.getState()) { Utils.add_component(this, RIPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = RIPPanel; } // Others Panel: From, To, Priority, Valid for // =========================================== if (useBorderPanel) ap = new BorderPanel(BorderPanel.OUT); else ap = new Panel(); othersPanel = ap; agbl = new GridBagLayout(); agbc = new GridBagConstraints(); agbc.fill = GridBagConstraints.NONE; agbc.anchor = GridBagConstraints.NORTHWEST; agbc.insets = new Insets(3,3,3,3); ap.setLayout(agbl); fromList = new List(minListSize, false); fromList.addItemListener(this); Macro.constructList(fromList, mgDomain.Macros, rule.fw_src_idx); Utils.add_component(ap, new Label("From"), agbl, agbc, 0, 0, 1, 1, 0, 0); Utils.add_component(ap, fromList, agbl, agbc, 1, 0, 1, 1, 0, 0); toList = new List(minListSize, false); toList.addItemListener(this); Macro.constructList(toList, mgDomain.Macros, rule.fw_dst_idx); Utils.add_component(ap, new Label("To"), agbl, agbc, 0, 1, 1, 1, 0, 0); Utils.add_component(ap, toList, agbl, agbc, 1, 1, 1, 1, 0, 0); macroButton = new Button("New address macro..."); macroButton.addActionListener(this); Utils.add_component(ap, macroButton, agbl, agbc, 0, 2, 2, 1, 0, 0); notificationList = new List(minListSize, false); notificationList.addItemListener(this); Notification.constructList(notificationList, mgDomain.NLevels, rule.level_num); Utils.add_component(ap, new Label("Notification"), agbl, agbc, 0, 4, 1, 1, 0, 0); Utils.add_component(ap, notificationList, agbl, agbc, 1, 4, 1, 1, 0, 0); notificationButton = new Button("New level..."); notificationButton.addActionListener(this); Utils.add_component(ap, notificationButton, agbl, agbc, 0, 5, 2, 1, 0, 0); priorityBox = new Checkbox("Priority rule"); priorityBox.addItemListener(this); priorityBox.setState(rule.priority); Utils.add_component(ap, priorityBox, agbl, agbc, 0, 7, 2, 1, 0, 0); firewallList = new List(3, true); firewallList.addItemListener(this); for (int i=0; i < mgDomain.Firewalls.size(); i++) { firewallList.add(((Host)mgDomain.Firewalls.elementAt(i)).objectID); if (rule.validFor[i]) firewallList.select(i); } Utils.add_component(ap, new Label("Rule valid on:"), agbl, agbc, 0, 9, 2, 1, 0, 0); Utils.add_component(ap, firewallList, agbl, agbc, 0, 10, 2, 3, 100, 100); Utils.add_component(this, ap, gbl, gbc, 12, 0, 4, 12, 25, 100); // Description // =========== Utils.add_component(this, new Label("Description:"), gbl, gbc, 0, 12, 3, 1, 0, 0); descText = new TextField(rule.comment); Utils.add_component(this, descText, gbl, gbc, 3, 12, 13, 1, 100, 0); // Buttons // ======= gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; Panel pa = new Panel(); OKbutton = new Button("OK"); OKbutton.addActionListener(this); pa.add(OKbutton); Cancelbutton = new Button("Cancel"); Cancelbutton.addActionListener(this); pa.add(Cancelbutton); Utils.add_component(this, pa, gbl, gbc, 0, 13, 16, 1, 0, 0); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; // Window size pack(); addWindowListener(new RDAdapter()); }class RDAdapter extends WindowAdapter implements Serializable { public void WindowClosing(WindowEvent we) { if (isEnabled()) dispose(); return; }} // class RDAdapter public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); // Process OKbutton if (source == OKbutton) { // get the information back into the rule structure if (collectData()) dispose(); if (callingObject != null) callingObject.refresh(); return; } // Process Cancelbutton else if (source == Cancelbutton) { if (newRule) mgDomain.Rules.removeElement(rule); dispose(); if (callingObject != null) callingObject.refresh(); return; } // Macro Buttons else if (source == macroButton || source == macroButton2) { Macro ln; try { ln = (Macro)mgDomain.Macros.lastElement(); } catch (NoSuchElementException e) { ln = null; } Macro m = new Macro (ln == null ? Macro.firstDynamic : ln.macroNumber - 1); mgDomain.Macros.addElement(m); addingMacro = true; m.edit(this, parent, mgDomain, true); return; } // Process notificationButton else if (source == notificationButton) { Notification ln; try { ln = (Notification)mgDomain.NLevels.lastElement(); } catch (NoSuchElementException e) { ln = null; } Notification not = new Notification (ln == null ? Notification.firstDynamic : ln.levelNumber + 1); mgDomain.NLevels.addElement(not); addingNoti = true; not.edit(this, parent, mgDomain, true); return; } } // actionPerformed public void itemStateChanged(ItemEvent ie) { Object source = ie.getSource(); // Process acceptBox if (source == acceptBox) { if ((pallBox.getState() || ptcpBox.getState()) && validPanel == null) { Utils.add_component(this, FTPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = FTPPanel; pack(); validate(); } return; } // Process blockBox, rejectBox, observeBox else if (source == blockBox || source == rejectBox || source == observeBox) { if (validPanel == FTPPanel) { remove(validPanel); validPanel = null; pack(); validate(); } return; } // Process pallBox, ptcpBox else if (source == pallBox || source == ptcpBox) { if (validPanel != FTPPanel) { boolean ch = false; if (validPanel != null) { ch = true; remove(validPanel); validPanel = null; } if (acceptBox.getState()) { ch = true; Utils.add_component(this, FTPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = FTPPanel; } if (ch) { pack(); validate(); } } return; } // Process picmpBox else if (source == picmpBox) { if (validPanel != ICMPPanel) { if (validPanel != null) remove(validPanel); Utils.add_component(this, ICMPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = ICMPPanel; pack(); validate(); } return; } // Process pigmpBox else if (source == pigmpBox) { if (validPanel != IGMPPanel) { if (validPanel != null) remove(validPanel); Utils.add_component(this, IGMPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = IGMPPanel; pack(); validate(); } return; } // Process pripBox else if (source == pripBox) { if (validPanel != RIPPanel) { if (validPanel != null) remove(validPanel); Utils.add_component(this, RIPPanel, gbl, gbc, 8, 0, 4, 12, 25, 100); validPanel = RIPPanel; pack(); validate(); } return; } // Process pudpBox, pnumBox else if (source == pudpBox || source == pnumBox) { if (validPanel != null) { remove(validPanel); validPanel = null; pack(); validate(); } return; } } // itemStateChanged public void textValueChanged(TextEvent te) { Object source = te.getSource(); // Process pnumText if (source == pnumText) { try { int pn = Integer.parseInt(pnumText.getText().trim()); if (pn > 0 && pn <= Rule.MAX_PROTOCOL) pnumLabel.setText("("+Rule.protocols[pn]+")"); else pnumLabel.setText(""); } catch (NumberFormatException e) { pnumLabel.setText(""); } validate(); return; } } // textValueChanged public void refresh() { if (addingNoti) { notificationList.removeAll(); Notification.constructList(notificationList, mgDomain.NLevels, 0); notificationList.select(notificationList.getItemCount()-1); notificationList.makeVisible(notificationList.getItemCount()-1); addingNoti = false; } if (addingMacro) { Macro newMacro = (Macro)mgDomain.Macros.lastElement(); toList.add(newMacro.macroName); fromList.add(newMacro.macroName); ripList.add(newMacro.macroName); addingMacro = false; } validate(); } // refresh private boolean collectData() { Macro m; rule.fw_flags = 0; // return code if (acceptBox.getState()) rule.fw_rc = Rule.FW_ACCEPT; else if (blockBox.getState()) rule.fw_rc = Rule.FW_BLOCK; else if (observeBox.getState()) rule.fw_rc = Rule.SF_RC_OBSERVE; else if (rejectBox.getState()) rule.fw_rc = rejectRC[rejectChoice.getSelectedIndex()]; // IP options if (optionsBox.getState()) { int selidx[] = optionsList.getSelectedIndexes(); for (int i=0; i < selidx.length; i++) rule.fw_flags |= optionsFlags[selidx[i]]; } if (ttlBox.getState()) { rule.fw_flags |= ttlFlags[ttlChoice.getSelectedIndex()]; boolean ttlerr = false; try { rule.ttl = Integer.parseInt(ttlValue.getText().trim()); } catch (NumberFormatException e) { ttlerr = true; } if (ttlerr || rule.ttl < 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -