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

📄 host.javatemp

📁 sifi-0.1.6.tar.gz 出自http://www.ifi.unizh.ch/ikm/SINUS/firewall/ 一个linux的防火墙工具。
💻 JAVATEMP
📖 第 1 页 / 共 5 页
字号:
/*  ----------------------------------------------------------------------   sf Control Panel - A management software for sf Firewall   Copyright (C) 1997 Roland E. Schmid <schmid@acm.org>   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.   Please address all correspondence concerning the software to    firewall-bugs@switch.ch.   ----------------------------------------------------------------------  */package sfclasses;import java.awt.*;import java.awt.event.*;import java.net.*;import java.util.*;import java.io.*;import Acme.Widgets.*;/** * 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 (bSource == null)      bSource = new cpu1ImageSource();    icon = Toolkit.getDefaultToolkit().createImage(bSource);    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;  }  /**   * 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(Frame parent) {    HostProperties hp;    if (objectID.length() > 0)      hp = new HostProperties(parent, "Host "+objectID, this);    else      hp = new HostProperties(parent, "Host properties", this);    hp.setVisible(true);  }  /**   * 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) {      NoticeBox nb = new NoticeBox(parent, "This is not a firewall!");      nb.setVisible(true);      return;    }    parent.setCursor(new Cursor(Cursor.WAIT_CURSOR));    if (!Communicator.openServer(HostAddresses.getFirstAddress())) {      if (Communicator.commError == Communicator.COMM_NOCONN) {        ErrorBox eb = new ErrorBox(parent, "Cannot connect to sfrelay!");        eb.setVisible(true);        parent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));        return;      }      else {        ErrorBox eb = new ErrorBox(parent, "Cannot connect to "+          Communicator.resolveIP(HostAddresses.getFirstAddress()));        eb.setVisible(true);        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 {      RelayOutputStream ros = new RelayOutputStream        (HostAddresses.getFirstAddress(), Custom.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);      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);    ps.writeBoolean(",", transparent);    ps.writeBoolean(",", isServer);    ps.writeBoolean(",", publicServer);    ps.writeInt(",Templates=", hostTemplates.length);    for (int i=0; i < hostTemplates.length; i++)      ps.writeBoolean(",", 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(",");    transparent = ps.readBoolean(",");    isServer = ps.readBoolean(",");    publicServer = ps.readBoolean(",");    int tlen = ps.readInt(",Templates=");    boolean btmp[] = new boolean[tlen];    for (int i=0; i < tlen; i++)      btmp[i] = ps.readBoolean(",");    if (tlen == hostTemplates.length)      hostTemplates = btmp;  }  // overriding Object methods

⌨️ 快捷键说明

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