⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 host.java

📁 sifi-0.1.6.tar.gz 出自http://www.ifi.unizh.ch/ikm/SINUS/firewall/ 一个linux的防火墙工具。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* ----------------------------------------------------------------------   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 java.io.*;import com.sun.java.swing.*;/** * This class implements host objects. It describes the properties * of general hosts, firewalls and servers.  * @version 1.0 03 Dec 1996 * @author Roland E. Schmid */public class Host	extends IconObject {  /**   * Initialize host and host icon   */  public Host() {    // implicit call to super()		if(checkConfig()) // check consistency			setOKIcon(null);		else 			setNOKIcon(null);    hostTemplates = new boolean[Templates.numberServer + Templates.numberFirewall];    for (int i=0; i < hostTemplates.length; i++)      hostTemplates[i] = Templates.defaultActivate[i+Templates.startServer];  }  /**   * Load the actual configuration data from the firewall   * @return true if successful, false otherwise   */  public boolean loadDynamicConfig() {    isLoaded = false;    if (!Communicator.readFwConfig(this)) {      if (Communicator.commError == Communicator.COMM_OK) {        // retry once, server connection may be reestablished now        if (!Communicator.readFwConfig(this))          return false;      }      else        return false;    }    isLoaded = true;    return true;  }  /**   * Load the active TCP connections from the firewall   * @return true if successful, false otherwise   */  public boolean loadTcpConns() {    if (!Communicator.readTcpConns(this)) {      if (Communicator.commError == Communicator.COMM_OK) {        // retry once, server connection may be reestablished now        if (!Communicator.readTcpConns(this))          return false;      }      else        return false;    }    return true;  }	public boolean checkConfig() {		return checkConfig(null);	}	public boolean checkConfig(Frame parent) {		if (!super.checkConfig())			return false;		if (HostAddresses.empty()) {			if (parent != null)      	UserDialog.ErrorBox("No addresses assigned to host!");			return false;		}		if (HostAddresses.hasBroadcastAddr() || HostAddresses.hasNetworkAddr()) {			if (parent != null)      	UserDialog.ErrorBox("Network or broadcast address assigned to host!");			return false;		}		return true;	}	public boolean canConnectTo(DragDropObj ddo) {		if (ddo instanceof Host)			return false;		return true;	}	public void connectError(Frame parent) {    UserDialog.ErrorBox("Can't connect two hosts!");		return;	}	public void setOKIcon(DragDrop dd) {		if (dd != null)			erase(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y);		if (isFirewall) {			if (bFirewallSource == null)				bFirewallSource = new cpuFirewallImageSource();			icon = Toolkit.getDefaultToolkit().createImage(bFirewallSource);		}		else {			if (bServerSource == null)				bServerSource = new cpuServerImageSource();			icon = Toolkit.getDefaultToolkit().createImage(bServerSource);		}		if (dd != null)			draw(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y); 	}		public void setNOKIcon(DragDrop dd) {		if (dd != null)			erase(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y);    if (bCpuSource == null)    	bCpuSource = new cpu1ImageSource();    icon = Toolkit.getDefaultToolkit().createImage(bCpuSource);		if (dd != null)			draw(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y);	}   /**   * Show the host properties dialog. The drag and drop panel calls this   * method when the user double clicks on the host icon in edit mode.   * @param parent Parent frame (drag and drop panel)   */  public void execute(DragDrop dd) {    HostProperties hp;		Frame parent = Utils.getParentFrame(dd);		    if (objectID.length() > 0)      hp = new HostProperties(parent, "Host "+objectID, this);    else      hp = new HostProperties(parent, "Host properties", this);    hp.setVisible(true);		if(checkConfig(parent)) // check consistency			setOKIcon(dd);		else 			setNOKIcon(dd);  }  /**   * Show the firewall action window. The drag and drop panel calls this   * method when the user double click on the host icon and edit mode   * is diabled.   * @param parent Parent frame (drag and drop panel)   * @param g Graphics context of the drag and drop canvas   * @param x_offset Horizontal offset of the virtual viewport   * @param y_offset Vertical offset of the virtual viewport   */  public void userAction(Frame parent, Graphics g, int x_offset, int y_offset) {    if (!isFirewall) {      UserDialog.NoticeBox("This is not a firewall!");      return;    }    parent.setCursor(new Cursor(Cursor.WAIT_CURSOR));		Connection conn = Communicator.openServer(HostAddresses.getFirstAddress());    if (conn == null) {      UserDialog.ErrorBox("Cannot connect to "+        Communicator.resolveIP(HostAddresses.getFirstAddress()));      parent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));      return;    }    if (actionFrame == null) {      actionFrame = new FirewallAction(this);      Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();      actionFrame.setSize(screensize.width/6*5, screensize.height/4*3);     }    actionFrame.setVisible(true);    parent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));  }  /**   * Generate firewall configuration file and write it to the firewall   * @return true on success, false otherwise   */  public boolean generateConfig() {    if (!isFirewall)      return false;    try {      ServerOutputStream ros = new ServerOutputStream        (HostAddresses.getFirstAddress(), ManageControl.custom.getProperty("GENERATE_CONFIG"));      PrintWriter ps = new PrintWriter(ros, true);      ps.println("#");      ps.println("# sf firewall configuration file");      ps.println("# ------------------------------");      ps.println("# automatically generated "+(new Date())+" for "+objectID);      ps.println("# DO NOT EDIT THIS FILE!");      ps.println("#");      ps.println();      ps.println("setup");      ps.println();      if (!internalAddresses.empty()) {        ps.println("internalnets");        internalAddresses.printAddressesFormatted(ps, 2, Macro.MACRO_FIRSTPORT, Macro.MACRO_LASTPORT);        ps.println(";");        ps.println();      }      ps.println("mail_default \""+mgDomain.defaultMail+"\";");      ps.println();      int ownidx = mgDomain.Firewalls.indexOf(this);      Enumeration en = mgDomain.Rules.elements();      Rule r;      boolean hasRules = false;      while (en.hasMoreElements()) {        r = (Rule)en.nextElement();        if (r.priority && r.validFor[ownidx]) {          if (!hasRules) {            hasRules = true;            ps.println("priority_rules");            ps.println();          }          r.printRule(ps, mgDomain, this);        }      }      ps.println("rules");      ps.println();      en = mgDomain.Rules.elements();      while (en.hasMoreElements()) {        r = (Rule)en.nextElement();        if (!r.priority && r.validFor[ownidx])          r.printRule(ps, mgDomain, this);      }      ps.println("notification");      ps.println();      Notification.printAllLevels(ps, mgDomain.NLevels);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -