📄 macro.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.util.*;import java.awt.*;import java.io.*;import java.awt.event.*;/** * This class implements address and service macros. An object of this * class holds all information about one macro. The static parts of * the class take care of the macro vectors and of static macros. * Static macros are stored in the vector <i>staticMacros</i> and are * inserted into that vector in a static initializer. Dynamic macros * are stored in a vector in the ManageDomain class. * @version 1.0 10 Jan 1997 * @author Roland E. Schmid */public class Macro implements Persistent { /** * Initialize empty macro. This is used when loading data from a * persistent input stream. */ public Macro() { } /** * Initialize macro. * @param number Macro number */ public Macro(int number) { macroNumber = number; } /** * Open a dialog to edit the macro. * @param co Calling object, will be notified when the edit dialog is closed. * @param p Parent frame * @param md ManageDomain object holding the configuration data * @param newMacro The macro is being created and not changed. If the user * cancels the operation, the macro will be deleted from the vector. * @see Refreshable */ public void edit(Refreshable co, Frame p, ManageDomain md, boolean newMacro) { MacroDialog d = new MacroDialog(co, p, this, md, newMacro); d.setVisible(true); if (macroNumber <= Rule.SF_FIRSTMACRO && macroNumber > firstDynamic) UserDialog.WarningBox("Static macro. Changes will not be saved!"); } // persistence /** * Write object data to a persistent output stream * @param ps Stream * @see PersistentOutputStream */ public void write(PersistentOutputStream ps) { ps.writeInt("Macro=", macroNumber); ps.writeString("Name=", macroName); ps.writeInt("Type=", macroType); ps.writeInt("Port=", port); ps.writeInt("Prend=", prend); ps.writePersistent("Addresses=", addresses); } /** * Read object data from a persistent input stream * @param ps Stream * @see PersistentInputStream */ public void read(PersistentInputStream ps) throws java.io.IOException { macroNumber = ps.readInt("Macro="); macroName = ps.readString("Name="); macroType = ps.readInt("Type="); port = ps.readInt("Port="); prend = ps.readInt("Prend="); addresses = (AddrList)ps.readPersistent("Addresses="); } // data public int macroNumber; public String macroName = new String(); public int macroType = MACRO_ADDRESSLIST; /** * macroType: use addresses */ public static final int MACRO_ADDRESSLIST = 1; /** * macroType: inside */ public static final int MACRO_INSIDE = 2; /** * macroType: outside */ public static final int MACRO_OUTSIDE = 3; /** * macroType: check for ports only */ public static final int MACRO_PORTS_ONLY = 4; /** * macroType: own addresses of the firewall */ public static final int MACRO_OWNADDR = 5; public int macroSpecial = 0; /** * macroSpecial: insert addresses of all firewalls */ public static final int MACRO_FIREWALLS = 1; // firewall addresses inserted automatically /** * macroSpecial: insert addresses of all authorized configuration clients */ public static final int MACRO_CONFCLIENTS = 2; // configuration client addresses inserted automatically /** * macroSpecial: macro is generated automatically from server template */ public static final int MACRO_TEMPLATE = 3; // macro generated automatically from server template public int port = MACRO_FIRSTPORT; public int prend = MACRO_LASTPORT; public static final int MACRO_FIRSTPORT = 0; public static final int MACRO_LASTPORT = 65535; public AddrList addresses = new AddrList(); // static info // =========== /** * Get static macro with given number * @param number Number of macro * @return macro */ public static Macro staticMacro(int number) { Enumeration en = staticMacros.elements(); Macro m; while (en.hasMoreElements()) { m = (Macro)en.nextElement(); if (m.macroNumber == number) return m; } return null; } /** * Get static macro with given name * @param name name of macro * @return macro */ public static Macro staticMacro(String name) { Enumeration en = staticMacros.elements(); Macro m; while (en.hasMoreElements()) { m = (Macro)en.nextElement(); if (m.macroName.equals(name)) return m; } return null; } /** * Get macro with given name. First the static macros are searched and * then the dynamic macros are searched. * @param name Macro name * @param dynMacros Vector containing the dynamic macros */ public static Macro getMacro(String name, Vector dynMacros) { Macro m = staticMacro(name); if (m == null) { Enumeration en = dynMacros.elements(); while (en.hasMoreElements()) { m = (Macro)en.nextElement(); if (m.macroName.equals(name)) return m; } } else return m; return null; } /** * Get macro with given number. First the static macros are searched and * then the dynamic macros are searched. * @param number Macro number * @param dynMacros Vector containing the dynamic macros */ public static Macro getMacro(int number, Vector dynMacros) { Macro m = staticMacro(number); if (m == null) { Enumeration en = dynMacros.elements(); while (en.hasMoreElements()) { m = (Macro)en.nextElement(); if (m.macroNumber == number) return m; } } else return m; return null; } /** * Construct list box containing all macros. * @param l List box * @param dynMacros Vector containing the dynamic macros * @param macronum Number of macro that is selected initially */ public static void constructList(List l, Vector dynMacros, int macronum) { Enumeration en = staticMacros.elements(); Macro m; while (en.hasMoreElements()) { m = (Macro)en.nextElement(); l.add(m.macroName); if (m.macroNumber == macronum) { l.select(l.getItemCount()-1); l.makeVisible(l.getItemCount()-1); } } en = dynMacros.elements(); while (en.hasMoreElements()) { m = (Macro)en.nextElement(); l.add(m.macroName); if (m.macroNumber == macronum) { l.select(l.getItemCount()-1); l.makeVisible(l.getItemCount()-1); } } } /** * Construct list box containing all macros. * @param l List box * @param dynMacros Vector containing the dynamic macros */ public static void constructList(List l, Vector dynMacros) { constructList(l, dynMacros, 0); } public static final int STATIC_INSIDE_OUTSIDE = -100; public static final int STATIC_SERVER = -101; public static final int STATIC_FIREWALLS = -102; public static final int STATIC_FIREWALLS_UNPRIV = -103; public static final int STATIC_FIREWALLS_CONFPORT = -104; public static final int STATIC_FIREWALLS_IDENTPORT= -105; public static final int STATIC_FIREWALLS_TRACEROUTEPORTS = -106; public static final int STATIC_CONFIG_CLIENTS = -107; public static final int STATIC_INSIDE = -108; public static final int STATIC_OUTSIDE = -109; public static final int STATIC_LOCALHOST = -110; public static final int STATIC_SMTPPORT = -111; public static final int STATIC_IDENTPORT = -112; public static final int STATIC_RUSERPORT = -113; public static final int STATIC_DNSPORT = -114; public static final int STATIC_FTPPORT = -115; public static final int STATIC_TELNETPORT = -116; public static final int STATIC_SSHPORT = -117; public static final int STATIC_HTTPPORTS = -118; public static final int STATIC_HTTPSPORTS = -119; public static final int STATIC_TRACEROUTEPORTS = -120; public static final int STATIC_INSIDE_IDENTPORT = -121; public static final int STATIC_INSIDE_TRACEROUTEPORTS = -122; public static final int STATIC_OWNADDRESSES = -123; public static final int STATIC_OWNADDRESSES_FWPORT = -124; public static final int STATIC_FINGERPORT = -125; public static Vector staticMacros = new Vector(30,10); public static final int firstDynamic = -200; static { Macro m; m = new Macro(STATIC_FIREWALLS); m.macroName = "FIREWALLS"; m.macroType = MACRO_ADDRESSLIST; m.macroSpecial = MACRO_FIREWALLS; // addresses will be filled in automatically staticMacros.addElement(m); m = new Macro(STATIC_FIREWALLS_UNPRIV); m.macroName = "FW-UNPRIV"; m.macroType = MACRO_ADDRESSLIST; m.macroSpecial = MACRO_FIREWALLS; m.port = 1024; // addresses will be filled in automatically staticMacros.addElement(m); m = new Macro(STATIC_FIREWALLS_CONFPORT); m.macroName = "FW-CONFPORT"; m.macroType = MACRO_ADDRESSLIST; m.macroSpecial = MACRO_FIREWALLS; m.port = 7227; m.prend = 7227;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -