PacketMonitorPage.cpp
上传用户:zhuzhu0204
上传日期:2020-07-13
资源大小:13165k
文件大小:4k
源码类别:
防火墙与安全工具
开发平台:
Visual C++
- // PacketMonitorPage.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyFireWall.h"
- #include "PacketMonitorPage.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CMyFireWallApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CPacketMonitorPage property page
- IMPLEMENT_DYNCREATE(CPacketMonitorPage, CPropertyPage)
- CPacketMonitorPage::CPacketMonitorPage() : CPropertyPage(CPacketMonitorPage::IDD)
- {
- //{{AFX_DATA_INIT(CPacketMonitorPage)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CPacketMonitorPage::~CPacketMonitorPage()
- {
- }
- void CPacketMonitorPage::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPacketMonitorPage)
- DDX_Control(pDX, IDC_PACKET_MONITOR_LIST, m_PacketMonitorList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPacketMonitorPage, CPropertyPage)
- //{{AFX_MSG_MAP(CPacketMonitorPage)
- ON_NOTIFY(NM_RCLICK, IDC_PACKET_MONITOR_LIST, OnRclickPacketMonitorList)
- ON_BN_CLICKED(IDC_ADD_KER_RULE, OnAddKerRule)
- ON_BN_CLICKED(IDC_MODIFY_KER_RULE, OnModifyKerRule)
- ON_BN_CLICKED(IDC_DEL_KER_RULE, OnDelKerRule)
- //}}AFX_MSG_MAP
- ON_COMMAND(IDM_ADD_KER_RULE, OnAddKerRule)
- ON_COMMAND(IDM_MODIFY_KER_RULE, OnModifyKerRule)
- ON_COMMAND(IDM_DEL_KER_RULE, OnDelKerRule)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPacketMonitorPage message handlers
- BOOL CPacketMonitorPage::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- // TODO: Add extra initialization here
- m_PacketMonitorList.InsertColumn(0,L"源IP地址",LVCFMT_LEFT,130,-1);
- m_PacketMonitorList.InsertColumn(1,L"源端口",LVCFMT_LEFT,70,-1);
- m_PacketMonitorList.InsertColumn(2,L"目的IP地址",LVCFMT_LEFT,130,-1);
- m_PacketMonitorList.InsertColumn(3,L"目的端口",LVCFMT_LEFT,70,-1);
- m_PacketMonitorList.InsertColumn(4,L"协议",LVCFMT_LEFT,80,-1);
- m_PacketMonitorList.InsertColumn(5,L"状态",LVCFMT_LEFT,80,-1);
- m_PacketMonitorList.ModifyStyle(LVS_TYPEMASK,LVS_REPORT);
- m_PacketMonitorList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CPacketMonitorPage::OnRclickPacketMonitorList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CMenu menu,*pSubMenu;
- menu.LoadMenu(IDR_KER_MENU);
- pSubMenu=menu.GetSubMenu(0);
- CPoint point;
- GetCursorPos(&point);
- pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
- *pResult = 0;
- }
- void CPacketMonitorPage::OnAddKerRule()
- {
- // TODO: Add your control notification handler code here
- CKerRuleSettingDlg KerRuleSettingDlg;
- if (KerRuleSettingDlg.DoModal() == IDCANCEL)
- {
- return;
- }
- // 将核心层规则添加到规则文件中
- if (!g_RuleFile.AddKerRules(&KerRuleSettingDlg.m_RuleItem, 1))
- {
- AfxMessageBox(L"添加核心层规则失败!");
- return;
- }
- if (!g_RuleFile.SaveRules())
- {
- AfxMessageBox(L"核心层规则保存失败!");
- return;
- }
- // 将规则应用到核心层模块
- theApp.ApplyKerRules();
- // 将新添加的核心层规则在 PacketMonitorList 上显示
- ::PostMessage(g_hMainWnd, UPDATE_PACKET_MONITOR_LIST, 0, 0);
- }
- void CPacketMonitorPage::OnModifyKerRule()
- {
- // TODO: Add your control notification handler code here
- int nItem = m_PacketMonitorList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- CString strTemp;
- strTemp = m_PacketMonitorList.GetItemText(nItem, 0);
- }
- void CPacketMonitorPage::OnDelKerRule()
- {
- // TODO: Add your control notification handler code here
- // 获得选中的行号
- int nItem = m_PacketMonitorList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- // 删除规则
- g_RuleFile.DelKerRule(nItem);
- // 将规则保存到文件
- g_RuleFile.SaveRules();
- // 将规则在 AccessCtrlList 控件上显示出来
- ::PostMessage(g_hMainWnd, UPDATE_PACKET_MONITOR_LIST, 0, 0);
- // 将规则应用到核心层模块
- theApp.ApplyKerRules();
- }