📄 fwclientframe.java~212~
字号:
package fwserver;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.text.SimpleDateFormat;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* Copyright: Copyright (c) 2005 CH 版权所有
* 生成日期 2005-6-5
* 作者姓名 崔灏
* 类的名称 FwClientFrame
* 功能描述
* 字段清单 IP ; 服务器地址
* RuleVec ;存储防火墙规则
* 方法清单 private void jbInit() throws Exception
* public void CreatLocalReportFile()
* private String GetTheRule()
* @version 1.0
*/
public class FwClientFrame extends JFrame implements ItemListener {
private fwClientThread client;
JButton jBtnAdd = new JButton();
XYLayout xYLayout1 = new XYLayout();
JLabel jLbelName = new JLabel();
JTextField jtxtName = new JTextField();
JLabel jLbelIp = new JLabel();
JTextField jtxtIp = new JTextField();
JLabel jLbelPort = new JLabel();
JTextField jtxtPort = new JTextField();
JLabel jLbelType = new JLabel();
JComboBox jComboxType = new JComboBox();
JCheckBox jCheckBoxIP = new JCheckBox();
JCheckBox jCheckBoxPort = new JCheckBox();
JLabel jLbelMode = new JLabel();
JComboBox jComboBoxMode = new JComboBox();
JLabel jLbelDuration = new JLabel();
JComboBox jComboBoxDuration = new JComboBox();
ButtonGroup group = new ButtonGroup();
JButton jBtnClose = new JButton();
private String IP = "127.0.0.1";
private long length_now = 0;
private long length_last = 0;
public Vector RuleVec = new Vector();
JButton jBtnAuto = new JButton();
JTextField jtxtIP = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jtxtHost = new JTextField();
JLabel jLabel3 = new JLabel();
JTextField jtxtServerIP = new JTextField();
JButton jbtnCreatFile = new JButton();
public FwClientFrame() {
try {
jbInit();
myInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**************************************************************
*函数名称: private void myInit()
*功能描述:类FwClientFrame的方法,完初始化界面下拉项的内容的功能
*入口参数:无
*出口参数:无
*返回值:无
*调用者:函数public FwServerFrame()
**************************************************************/
private void myInit() {
jComboBoxDuration.addItem("Hour");
jComboBoxDuration.addItem("Day");
jComboBoxDuration.addItem("Month");
jComboBoxDuration.addItem("Forever");
jComboBoxMode.addItem("Accept");
jComboBoxMode.addItem("Reject");
jComboxType.addItem("IP");
jComboxType.addItem("TCP");
jComboxType.addItem("UDP");
}
/**************************************************************
*函数名称:private void jbInit() throws Exception
*功能描述:类FwClientFrame的方法,完初始化界面显示的功能
*入口参数:无
*出口参数:无
*返回值:无
*调用者:函数public FwClientFrame()
**************************************************************/
private void jbInit() {
jBtnAdd.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jBtnAdd.setText("手动添加");
jBtnAdd.addActionListener(new FwClientFrame_jBtnAdd_actionAdapter(this));
//jBtnAdd.addActionListener(new FwClientFrame_jButton1_actionAdapter(this));
this.getContentPane().setLayout(xYLayout1);
jtxtName.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jtxtName.setText(" ");
jLbelIp.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLbelIp.setText(" IP ");
jtxtIp.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jtxtIp.setText("");
jLbelPort.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLbelPort.setText("Port ");
jLbelType.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLbelType.setText("Type ");
jComboxType.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jComboxType.setToolTipText("");
jtxtPort.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jCheckBoxIP.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jCheckBoxIP.setText("All Address");
jCheckBoxIP.addChangeListener(new
FwClientFrame_jCheckBoxIP_changeAdapter(this));
jCheckBoxIP.addItemListener(this);
jCheckBoxPort.addItemListener(this);
jCheckBoxPort.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jCheckBoxPort.setText("All For");
jCheckBoxPort.addChangeListener(new
FwClientFrame_jCheckBoxPort_changeAdapter(this));
jLbelMode.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLbelMode.setText("Mode ");
jLbelDuration.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jLbelDuration.setText("Duration ");
jLbelName.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
this.setResizable(false);
this.addWindowListener(new FwClientFrame_this_windowAdapter(this));
jLbelName.setText("Name ");
jBtnClose.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jBtnClose.setText("关机"); //jBtnClose.addActionListener(new FwClientFrame_jButton3_actionAdapter(this));
jBtnClose.addActionListener(new FwClientFrame_jBtnClose_actionAdapter(this));
jBtnAuto.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jBtnAuto.setText("自动添加"); //jBtnAuto.addActionListener(new FwClientFrame_jButton6_actionAdapter(this));
jBtnAuto.addActionListener(new FwClientFrame_jBtnAuto_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jLabel1.setText("关机IP");
jtxtHost.setText("");
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jLabel2.setText("目标主机IP");
jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jLabel3.setText("主机IP ");
jbtnCreatFile.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jbtnCreatFile.setText("生成文件");
jbtnCreatFile.addActionListener(new
FwClientFrame_jbtnCreatFile_actionAdapter(this));
this.getContentPane().add(jLabel1, new XYConstraints(34, 350, 43, -1));
this.getContentPane().add(jLbelDuration,
new XYConstraints(31, 255, -1, -1));
this.getContentPane().add(jComboBoxDuration,
new XYConstraints(121, 255, 162, 21));
this.getContentPane().add(jLbelMode, new XYConstraints(31, 219, -1, -1));
this.getContentPane().add(jComboBoxMode,
new XYConstraints(120, 218, 163, 21));
this.getContentPane().add(jLbelType, new XYConstraints(30, 179, -1, -1));
this.getContentPane().add(jComboxType,
new XYConstraints(121, 180, 163, -1));
this.getContentPane().add(jLbelPort, new XYConstraints(30, 143, -1, -1));
this.getContentPane().add(jtxtPort, new XYConstraints(119, 141, 130, -1));
this.getContentPane().add(jCheckBoxPort,
new XYConstraints(256, 141, -1, 21));
this.getContentPane().add(jLbelIp, new XYConstraints(28, 101, 73, -1));
this.getContentPane().add(jtxtIp, new XYConstraints(121, 97, 129, -1));
this.getContentPane().add(jCheckBoxIP,
new XYConstraints(254, 97, 135, 21));
this.getContentPane().add(jtxtName, new XYConstraints(118, 59, 157, -1));
this.getContentPane().add(jLbelName, new XYConstraints(34, 59, -1, -1));
this.getContentPane().add(jLabel2, new XYConstraints(32, 26, -1, -1));
this.getContentPane().add(jtxtHost,
new XYConstraints(119, 25, 154, -1));
this.getContentPane().add(jBtnAdd, new XYConstraints(27, 300, -1, -1));
this.getContentPane().add(jtxtIP, new XYConstraints(77, 348, 130, -1));
this.getContentPane().add(jLabel3, new XYConstraints(31, 388, -1, -1));
this.getContentPane().add(jtxtServerIP,
new XYConstraints(77, 385, 129, -1));
this.getContentPane().add(jBtnClose, new XYConstraints(217, 345, 81, -1));
this.getContentPane().add(jbtnCreatFile,
new XYConstraints(219, 384, 82, -1));
this.getContentPane().add(jBtnAuto, new XYConstraints(216, 302, -1, -1));
}
public void itemStateChanged(ItemEvent e) {
if (e.getItemSelectable() == jCheckBoxIP) {
jtxtIp.setEditable(false);
} else if (e.getItemSelectable() == jCheckBoxPort) {
jtxtPort.setEditable(false);
}
}
/**
* Get the Report From The ReportServer
* Creat A File About Tne Report
*/
/**************************************************************
*函数名称:public void CreatLocalReportFile()
*功能描述:类FwClientFrame的方法,根据报警日志在本地建立报警文件,同时与服务器建立连接
*入口参数:无
*出口参数:无
*返回值:无
**************************************************************/
public void CreatLocalReportFile() {
int Index = 0;
String strRule = null;
String strAction = "Reject";
String strIP_port = " ";
String name = "Default";
String strwhenSet = " ";
String strwhenExpire = " ";
String precedence = "1000";
String strwhoSet = "unknown";
try {
//建立文件
File reporttxt = new File("/D:", "report.txt");
if (!reporttxt.exists()) {
if (reporttxt.createNewFile()) {
System.err.println("Create OK");
}
}
ServerSocket sockets = new ServerSocket(2121);
System.out.println("Listening");
Socket ReportSock = sockets.accept();
sockets.close();
InputStreamReader input = new InputStreamReader(ReportSock.
getInputStream());
BufferedReader bufreaderin = new BufferedReader(input);
StringBuffer bufferServerStr = new StringBuffer();
String sss = bufreaderin.readLine();
while (sss != null) {
bufferServerStr.append(sss + "\r\n");
sss = bufreaderin.readLine();
}
FileWriter fout = new FileWriter("report.txt");
fout.write(bufferServerStr.toString());
input.close();
fout.close();
ReportSock.close();
//bufferServerStr.delete(0, bufferServerStr.length());
} catch (Exception dd) {
System.err.println("Get Report Server Error" + dd);
}
try {
File file = new File("report.txt");
length_now = file.length();
FileReader filereader = new FileReader("report.txt");
BufferedReader filebuffer = new BufferedReader(filereader);
if (length_last != 0) {
filebuffer.skip(length_last + 4);
}
System.err.println("length_last1 = " + length_last);
length_last = length_now;
System.err.println("length_last2 = " + length_last);
Index = 0;
RuleVec.clear();
String strLinetxt = filebuffer.readLine();
Index = Index + 1;
//根据报警生成规则
while (strLinetxt != null) {
if (Index == 11) {
Index = 0;
}
if (Index == 3) {
int FirstblankIndex = strLinetxt.indexOf(" ");
int flagIndex = strLinetxt.indexOf("->");
strIP_port = strLinetxt.substring(FirstblankIndex,
flagIndex - 1);
///////////////////////////////////
strRule = "[MANUAL UDP low REJECT]\r\n" + strAction +
", " + strIP_port + ", " + name +
", " + strwhenSet + ", " + strwhenExpire +
", " +
precedence + ", " + strwhoSet + "\r\n";
RuleVec.add(strRule);
IP = strIP_port.trim();
try {
// Thread.sleep(100);
Socket socket12 = new Socket(IP, 1234);
String temp;
String strinfo;
String temprule;
int number = 0;
number = RuleVec.size();
String strnumber = String.valueOf(number);
strnumber = strnumber + "\r\n";
Vector strvec = new Vector();
strvec.add(strnumber);
for (int i = 0; i < number; i++) {
temprule = (String) RuleVec.elementAt(i);
strvec.add(temprule);
}
temp = strvec.toString();
strinfo = temp.substring(1, temp.length() - 1);
OutputStreamWriter ps = new OutputStreamWriter(
socket12.
getOutputStream());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -