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

📄 fwclientframe.java~212~

📁 Firewall Application & source code.
💻 JAVA~212~
📖 第 1 页 / 共 2 页
字号:
                        ps.write(strinfo);
                        ps.flush();
                        RuleVec.clear();
                    } catch (Exception ee) {
                        System.err.print("ssdsd" + ee);
                    }

                }
                strLinetxt = filebuffer.readLine();
                Index = Index + 1;
            }

        } catch (Exception e) {
            System.err.println("Error " + e);
        }

        System.err.println("Task!!!");

    }

    /**************************************************************
     *函数名称: private String GetTheRule()
     *功能描述:类FwClientFrame的方法,根据界面的内容 生成防火墙规则
     *入口参数:无
     *出口参数:无
     *返回值:无
     **************************************************************/
    private String GetTheRule() {
        String strRule = null;
        String strName = jtxtName.getText();
        if (jtxtName.getText().equals("")) {
            strName = "Default";
        }
        String strIP = jtxtIp.getText();
        String strPort = jtxtPort.getText();
        //生成本地时间
        Date dtCurrTime = new Date();
        //格式化日志时间
        SimpleDateFormat syOutput = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String strStartTime = syOutput.format(dtCurrTime);

        String strType = (String) jComboxType.getSelectedItem();
        String strMode = (String) jComboBoxMode.getSelectedItem();
        String strDuration = (String) jComboBoxDuration.getSelectedItem();
        String strEndTime = "PERPETUAL";

        if (strDuration.equals("Hour")) {
            int hh = dtCurrTime.getHours();
            dtCurrTime.setHours(hh + 1);
            strEndTime = syOutput.format(dtCurrTime);
        }
        if (strDuration.equals("Day")) {
            int dd = dtCurrTime.getDate();
            dtCurrTime.setDate(dd + 1);
            strEndTime = syOutput.format(dtCurrTime);

        }
        if (strDuration.equals("Month")) {
            int mm = dtCurrTime.getMonth();
            dtCurrTime.setMonth(mm + 1);
            strEndTime = syOutput.format(dtCurrTime);

        }
        strRule = strMode + ", " + "0 - 1023, " + strName + ", " + strStartTime +
                  ", " + strEndTime + ", ";
        return strRule;
    }


    public void this_windowClosed(WindowEvent e) {
        this.dispose();
    }



    public void jCheckBoxIP_stateChanged(ChangeEvent e) {
        if (!jCheckBoxIP.isSelected()) {
            jtxtIp.setEditable(true);
            jCheckBoxPort.setEnabled(true);
        } else {
            jCheckBoxPort.setEnabled(false);
        }
    }

    public void jCheckBoxPort_stateChanged(ChangeEvent e) {
        if (!jCheckBoxPort.isSelected()) {
            jtxtPort.setEditable(true);
            jCheckBoxIP.setEnabled(true);
        } else {
            jCheckBoxIP.setEnabled(false);
        }
    }



    /**************************************************************
     *函数名称:public void jbtnCreatFile_actionPerformed(ActionEvent e)
     *功能描述:根据指定IP在本地建立服务器的防火墙配置文件
     *入口参数:无
     *出口参数:无
     *返回值:无
     *调用者:系统
     **************************************************************/

    public void jbtnCreatFile_actionPerformed(ActionEvent e) {
        try {
            String strIP = jtxtServerIP.getText();
            strIP = strIP.trim();
            Thread.sleep(200);
            Socket socket = new Socket(strIP, 1234);
            String temp;
            // temp = "[ShutDownPC]\r\n";
            temp = "1\r\n[CreatFile]\r\naaa\r\n";
            OutputStreamWriter ps = new OutputStreamWriter(socket.
                    getOutputStream());
            ps.write(temp);
            ps.flush();
            /****************
             * Get The Server's Fire Rule
             */
            try {
                InputStreamReader input = new InputStreamReader(socket.
                        getInputStream());
                BufferedReader bufferinput = new BufferedReader(input);

                StringBuffer bufferServerStr = new StringBuffer();

                String sss = bufferinput.readLine();
                while (sss != null) {
                    bufferServerStr.append(sss + "\r\n");
                    sss = bufferinput.readLine();
                }

                // jTxtArea.setText(bufferServerStr.toString());
                File reporttxt = new File("/D:", strIP + "firewall.txt");
                if (!reporttxt.exists()) {
                    if (reporttxt.createNewFile()) {
                        System.err.println("Create OK");
                    }
                }
                FileWriter fout = new FileWriter("/D:" + strIP + "firewall.txt");
                fout.write(bufferServerStr.toString());
                fout.close();
                input.close();

            } catch (Exception dd) {
                System.err.println("Get Server Error");
            }

        } catch (Exception ee) {
            System.err.print(ee);
        }

    }
    /**************************************************************
     *函数名称:public void jBtnAdd_actionPerformed(ActionEvent e)
     *功能描述:根据界面内容形成防火墙规则
     *入口参数:无
     *出口参数:无
     *返回值:无
     *调用者:系统
     **************************************************************/
    public void jBtnAdd_actionPerformed(ActionEvent e) {
        try {
            String strIP = jtxtHost.getText();
            strIP = strIP.trim();
            Socket socket = new Socket(strIP, 1234);
            String temp;
            temp = "[MANUAL UDP low REJECT]\r\n";
            temp = temp + GetTheRule() + "\r\n";
            byte buf[] = temp.getBytes();
            OutputStreamWriter ps = new OutputStreamWriter(socket.
                    getOutputStream());
            ps.write(temp);
            ps.flush();

        } catch (Exception ee) {
            System.err.print(ee);
        }
    }
    /**************************************************************
     *函数名称:public void jBtnAdd_actionPerformed(ActionEvent e)
     *功能描述:建立线程,自动建立防火墙规则,发送到相应的服务器端
     *入口参数:无
     *出口参数:无
     *返回值:无
     *调用者:系统
     **************************************************************/
    public void jBtnAuto_actionPerformed(ActionEvent e) {
        client = new fwClientThread();
    }

    /**************************************************************
     *函数名称:public void jBtnAdd_actionPerformed(ActionEvent e)
     *功能描述:关闭远程主机
     *入口参数:无
     *出口参数:无
     *返回值:无
     *调用者:系统
     **************************************************************/
    public void jBtnClose_actionPerformed(ActionEvent e) {
        try {
            String strIP = jtxtIP.getText();
            strIP = strIP.trim();
            Thread.sleep(200);
            Socket socket = new Socket(strIP, 1234);
            String temp;
            temp = "1\r\n[ShutDownPC]\r\naaa\r\n";
            OutputStreamWriter ps = new OutputStreamWriter(socket.
                    getOutputStream());
            ps.write(temp);
            ps.flush();

        } catch (Exception ee) {
            System.err.print(ee);
        }
    }
}


class FwClientFrame_jBtnClose_actionAdapter implements ActionListener {
    private FwClientFrame adaptee;
    FwClientFrame_jBtnClose_actionAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {

        adaptee.jBtnClose_actionPerformed(e);
    }
}


class FwClientFrame_jBtnAuto_actionAdapter implements ActionListener {
    private FwClientFrame adaptee;
    FwClientFrame_jBtnAuto_actionAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {

        adaptee.jBtnAuto_actionPerformed(e);
    }
}


class FwClientFrame_jBtnAdd_actionAdapter implements ActionListener {
    private FwClientFrame adaptee;
    FwClientFrame_jBtnAdd_actionAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {

        adaptee.jBtnAdd_actionPerformed(e);
    }
}


class FwClientFrame_jbtnCreatFile_actionAdapter implements ActionListener {
    private FwClientFrame adaptee;
    FwClientFrame_jbtnCreatFile_actionAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jbtnCreatFile_actionPerformed(e);
    }
}



class FwClientFrame_jCheckBoxIP_changeAdapter implements ChangeListener {
    private FwClientFrame adaptee;
    FwClientFrame_jCheckBoxIP_changeAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void stateChanged(ChangeEvent e) {
        adaptee.jCheckBoxIP_stateChanged(e);
    }
}


class FwClientFrame_jCheckBoxPort_changeAdapter implements ChangeListener {
    private FwClientFrame adaptee;
    FwClientFrame_jCheckBoxPort_changeAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void stateChanged(ChangeEvent e) {

        adaptee.jCheckBoxPort_stateChanged(e);
    }
}


class FwClientFrame_this_windowAdapter extends WindowAdapter {
    private FwClientFrame adaptee;
    FwClientFrame_this_windowAdapter(FwClientFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void windowClosed(WindowEvent e) {
        adaptee.this_windowClosed(e);
    }
}

⌨️ 快捷键说明

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