📄 firewallaction.java
字号:
/* ---------------------------------------------------------------------- The SINUS Firewall -- a TCP/IP packet filter for Linux Written within the SINUS project at the University of Zurich, SWITCH, Telekurs Payserv AG, ETH Zurich. originally based on the sf Firewall Software (C) 1996 by Robert Muchsel and Roland Schmid. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. SINUS Firewall resources: SINUS Homepage: http://www.ifi.unizh.ch/ikm/SINUS/ Firewall Homepage: http://www.ifi.unizh.ch/ikm/SINUS/firewall.html Frequently asked questions: http://www.ifi.unizh.ch/ikm/SINUS/sf_faq.html Mailing list for comments, questions, bug reports: firewall@ifi.unizh.ch ---------------------------------------------------------------------- */package sfclasses;import java.awt.*;import java.awt.event.*;import java.net.*;import java.util.*;import com.sun.java.swing.*;/** * Frame for Firewall Administration.<br> * This is the GUI class providing access to all firewall configuration * and administration functions. The frame is constructed by the userAction * function of the host class when the user double clicks on a firewall * object. * @see Host#userAction * @version 1.0 16 Dec 1996 * @author Roland E. Schmid */public class FirewallAction extends Frame implements Runnable, ActionListener { /** * Initialize firewall action frame for host fw. * @param fw Firewall */ public FirewallAction(Host fw) { firewall = fw; setTitle(firewall.getObjectID()); setLayout(new BorderLayout()); // create menus mbar = new MenuBar(); FileMenu = new Menu("File"); FileMenu.add(FileClose = new MenuItem("Close")); mbar.add(FileMenu); AdminMenu = new Menu("Administration"); Menu ac = new Menu("Active Configuration"); ac.add(AdminLoadC = new MenuItem("Load Configuration")); ac.add(AdminShowC = new MenuItem("Show Configuration")); ac.add(AdminShowV = new MenuItem("Show Variables")); AdminMenu.add(ac); Menu tc = new Menu("TCP Connections"); tc.add(TCPShow = new MenuItem("Show Connections")); tc.add(TCPKill = new MenuItem("Kill Connection")); AdminMenu.add(tc); AdminMenu.add(AdminReset = new MenuItem("Reset Usage Counter")); Menu lg = new Menu("Logfiles"); lg.add(LogMain = new MenuItem("Main")); lg.add(LogSpy = new MenuItem("Spy")); lg.add(LogReport = new MenuItem("Report")); AdminMenu.add(lg); mbar.add(AdminMenu); ConfigMenu = new Menu("Configuration"); ConfigMenu.add(ConfGenerate = new MenuItem("Generate Config File")); ConfigMenu.add(ConfRestart = new MenuItem("Restart Firewall")); mbar.add(ConfigMenu); HelpMenu = new Menu("Help"); HelpMenu.add(HelpGuide = new MenuItem("User's Guide")); HelpMenu.add(HelpAbout = new MenuItem("About")); mbar.add(HelpMenu); mbar.setHelpMenu(HelpMenu); FileClose.addActionListener(this); AdminLoadC.addActionListener(this); AdminShowC.addActionListener(this); AdminShowV.addActionListener(this); AdminReset.addActionListener(this); TCPShow.addActionListener(this); TCPKill.addActionListener(this); LogMain.addActionListener(this); LogSpy.addActionListener(this); LogReport.addActionListener(this); ConfGenerate.addActionListener(this); ConfRestart.addActionListener(this); HelpGuide.addActionListener(this); HelpAbout.addActionListener(this); setMenuBar(mbar); addWindowListener(new FAAdapter()); } // The Menus MenuItem FileClose; MenuItem AdminLoadC, AdminShowC, AdminShowV, AdminReset; MenuItem TCPShow, TCPKill; MenuItem ConfGenerate, ConfRestart; MenuItem LogMain, LogSpy, LogReport; MenuItem HelpGuide, HelpAbout; class FAAdapter extends WindowAdapter { public void WindowClosing(WindowEvent we) { if (isEnabled()) { if (tcpPanelAdded) { tcpThread.stop(); remove(tcpPanel); tcpPanelAdded = false; } setVisible(false); } } } // class FAAdapter public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (!isEnabled()) return; // Process "Close" if (source == FirewallAction.FileClose) { if (tcpPanelAdded) if (tcpPanelAdded) { tcpThread.stop(); remove(tcpPanel); tcpPanelAdded = false; } setVisible(false); return; } // Process "Load Configuration" else if (source == AdminLoadC) { if (rulePanelAdded) { remove(rulePanel); rulePanelAdded = false; validate(); } if (tcpPanelAdded) { tcpThread.stop(); remove(tcpPanel); tcpPanelAdded = false; validate(); } actionCommand = LOAD_CONFIG; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "Show Configuration" else if (source == AdminShowC) { if (tcpPanelAdded) { tcpThread.stop(); remove(tcpPanel); tcpPanelAdded = false; validate(); } if (rulePanelAdded) return; if (configLoaded) { add("Center", rulePanel); validate(); rulePanelAdded = true; return; } actionCommand = LOAD_CONFIG; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "Show Variables" else if (source == AdminShowV) { if (!configLoaded) { UserDialog.ErrorBox("Configuration not loaded!"); return; } if (varShowing) { varDialog.setVisible(true); return; } varDialog = new VariableDialog(this, firewall); varDialog.setVisible(true); return; } // Process "Show Connections" else if (source == TCPShow) { if (tcpPanelAdded) { tcpThread.stop(); remove(tcpPanel); tcpPanelAdded = false; validate(); } if (rulePanelAdded) { remove(rulePanel); rulePanelAdded = false; validate(); } actionCommand = LOAD_TCP; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); tcpThread = actionThread; actionThread.start(); return; } // Process "Kill Connection" else if (source == TCPKill) { actionCommand = KILL_TCP; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "Reset Usage Counter" else if (source == AdminReset) { actionCommand = RESET_USAGE; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process Log Submenus else if ((source == LogMain) || (source == LogSpy) || (source == LogReport)) { filename = new String(ManageControl.custom.getProperty("LOG_DIR")); if (source == LogMain) filename += ManageControl.custom.getProperty("LOG"); if (source == LogSpy) filename += ManageControl.custom.getProperty("SPY_LOG"); if (source == LogReport) filename += ManageControl.custom.getProperty("REPORT"); actionCommand = LOAD_LOG; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "Generate Config File" else if (source == ConfGenerate) { actionCommand = GENERATE_CONFIG; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "Restart Firewall" else if (source == ConfRestart) { actionCommand = RECONFIG; setEnabled(false); setCursor(new Cursor(Cursor.WAIT_CURSOR)); actionThread = new Thread(this); actionThread.start(); return; } // Process "About" else if (source == HelpAbout) { AboutDialog ab = new AboutDialog(this); ab.setVisible(true); return; } // Process "User's Guide" else if (source == HelpGuide) { UserDialog.NoticeBox("Documentation only available as a PostScript file."); return; } } // actionPerformed // thread private String filename; private int actionCommand = 0; private static final int GENERATE_CONFIG = 1; // generate firewall configuration file private static final int RECONFIG = 2; // reconfigure firewall private static final int LOAD_CONFIG = 3; // load the active configuration from the firewall private static final int LOAD_LOG = 4; // load a log file from the firewall private static final int LOAD_TCP = 5; // load the active TCP connections from the firewall private static final int KILL_TCP = 6; // kill a TCP connection private static final int RESET_USAGE = 7; // reset the usage counter /** * The administration functions are executed in a separate thread. * The run() method contains the thread code. */ public void run() { BusyBox bb; boolean success; int answer; while (true) { switch (actionCommand) { case GENERATE_CONFIG: bb = new BusyBox("Generating configuration file. Please wait."); bb.start(); success = firewall.generateConfig(); bb.done(); if (success) { answer = JOptionPane.showConfirmDialog(null, "Success. Do you want to restart the firewall?", "User Information", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { actionCommand = RECONFIG; continue; } } else UserDialog.WarningBox("Error generating the configuration file! ("+Communicator.commError+")"); break; case RECONFIG: bb = new BusyBox("Restarting firewall. Please wait."); bb.start(); success = firewall.reconfig(); bb.done(); if (success) UserDialog.NoticeBox("Firewall restarted successfully."); else UserDialog.WarningBox("Error restarting the firewall! ("+Communicator.commError+")"); break; case LOAD_CONFIG: success = firewall.loadDynamicConfig(); if (success) { ruleCanvas = new ShowCanvas(firewall); ruleHeader = new ShowHeader(ruleCanvas); rulePanel = new ListPanel(ruleCanvas, ruleHeader); add("Center", rulePanel); validate(); rulePanelAdded = true; configLoaded = true; if (varShowing) varDialog.refresh(); } else UserDialog.ErrorBox("Cannot load configuration data! ("+Communicator.commError+")"); break; case LOAD_LOG: bb = new BusyBox("Loading log file. Please wait."); bb.start(); String temp = Communicator.getTempFile(firewall.HostAddresses.getFirstAddress(), filename); bb.done(); if (temp == null) { UserDialog.ErrorBox("Cannot read "+filename+"! ("+Communicator.commError+")"); break; } Frame f = new TextView(temp); break; case LOAD_TCP: boolean firstRun = true; TcpConnection oldsel = null; while (true) { success = firewall.loadTcpConns(); if (success) { if (!firstRun) { int share[] = tcpCanvas.getShare(); oldsel = (TcpConnection)tcpCanvas.getSelectedEntry(); remove(tcpPanel); tcpCanvas = new TcpCanvas(firewall, share); } else tcpCanvas = new TcpCanvas(firewall); tcpHeader = new TcpHeader(tcpCanvas, firewall); tcpPanel = new ListPanel(tcpCanvas, tcpHeader); add("Center", tcpPanel); validate(); if (oldsel != null) { int oldid = oldsel.id; Enumeration en = firewall.tcpconns.elements(); while (en.hasMoreElements()) { oldsel = (TcpConnection)en.nextElement(); if (oldsel.id == oldid) { tcpCanvas.selectEntry(oldsel); break; } } } tcpPanelAdded = true; } if (!success) { if (!firstRun) { remove(tcpPanel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -