PacketMonitorPage.cpp
上传用户:zhuzhu0204
上传日期:2020-07-13
资源大小:13165k
文件大小:4k
开发平台:

Visual C++

  1. // PacketMonitorPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyFireWall.h"
  5. #include "PacketMonitorPage.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. extern CMyFireWallApp theApp;
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPacketMonitorPage property page
  14. IMPLEMENT_DYNCREATE(CPacketMonitorPage, CPropertyPage)
  15. CPacketMonitorPage::CPacketMonitorPage() : CPropertyPage(CPacketMonitorPage::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CPacketMonitorPage)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. CPacketMonitorPage::~CPacketMonitorPage()
  22. {
  23. }
  24. void CPacketMonitorPage::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CPacketMonitorPage)
  28. DDX_Control(pDX, IDC_PACKET_MONITOR_LIST, m_PacketMonitorList);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CPacketMonitorPage, CPropertyPage)
  32. //{{AFX_MSG_MAP(CPacketMonitorPage)
  33. ON_NOTIFY(NM_RCLICK, IDC_PACKET_MONITOR_LIST, OnRclickPacketMonitorList)
  34. ON_BN_CLICKED(IDC_ADD_KER_RULE, OnAddKerRule)
  35. ON_BN_CLICKED(IDC_MODIFY_KER_RULE, OnModifyKerRule)
  36. ON_BN_CLICKED(IDC_DEL_KER_RULE, OnDelKerRule)
  37. //}}AFX_MSG_MAP
  38. ON_COMMAND(IDM_ADD_KER_RULE, OnAddKerRule)
  39. ON_COMMAND(IDM_MODIFY_KER_RULE, OnModifyKerRule)
  40. ON_COMMAND(IDM_DEL_KER_RULE, OnDelKerRule)
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CPacketMonitorPage message handlers
  44. BOOL CPacketMonitorPage::OnInitDialog() 
  45. {
  46. CPropertyPage::OnInitDialog();
  47. // TODO: Add extra initialization here
  48. m_PacketMonitorList.InsertColumn(0,L"源IP地址",LVCFMT_LEFT,130,-1);
  49. m_PacketMonitorList.InsertColumn(1,L"源端口",LVCFMT_LEFT,70,-1);
  50. m_PacketMonitorList.InsertColumn(2,L"目的IP地址",LVCFMT_LEFT,130,-1);
  51. m_PacketMonitorList.InsertColumn(3,L"目的端口",LVCFMT_LEFT,70,-1);
  52. m_PacketMonitorList.InsertColumn(4,L"协议",LVCFMT_LEFT,80,-1);
  53. m_PacketMonitorList.InsertColumn(5,L"状态",LVCFMT_LEFT,80,-1);
  54. m_PacketMonitorList.ModifyStyle(LVS_TYPEMASK,LVS_REPORT);
  55. m_PacketMonitorList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  56. return TRUE;  // return TRUE unless you set the focus to a control
  57.               // EXCEPTION: OCX Property Pages should return FALSE
  58. }
  59. void CPacketMonitorPage::OnRclickPacketMonitorList(NMHDR* pNMHDR, LRESULT* pResult) 
  60. {
  61. // TODO: Add your control notification handler code here
  62. CMenu menu,*pSubMenu;
  63. menu.LoadMenu(IDR_KER_MENU);
  64. pSubMenu=menu.GetSubMenu(0);
  65. CPoint point;
  66. GetCursorPos(&point);
  67. pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
  68. *pResult = 0;
  69. }
  70. void CPacketMonitorPage::OnAddKerRule() 
  71. {
  72. // TODO: Add your control notification handler code here
  73. CKerRuleSettingDlg KerRuleSettingDlg;
  74. if (KerRuleSettingDlg.DoModal() == IDCANCEL)
  75. {
  76. return;
  77. }
  78. // 将核心层规则添加到规则文件中
  79. if (!g_RuleFile.AddKerRules(&KerRuleSettingDlg.m_RuleItem, 1))
  80. {
  81. AfxMessageBox(L"添加核心层规则失败!");
  82. return;
  83. }
  84. if (!g_RuleFile.SaveRules())
  85. {
  86. AfxMessageBox(L"核心层规则保存失败!");
  87. return;
  88. }
  89. // 将规则应用到核心层模块
  90. theApp.ApplyKerRules();
  91. // 将新添加的核心层规则在 PacketMonitorList 上显示
  92. ::PostMessage(g_hMainWnd, UPDATE_PACKET_MONITOR_LIST, 0, 0);
  93. }
  94. void CPacketMonitorPage::OnModifyKerRule() 
  95. {
  96. // TODO: Add your control notification handler code here
  97. int nItem = m_PacketMonitorList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  98. CString strTemp;
  99. strTemp = m_PacketMonitorList.GetItemText(nItem, 0);
  100. }
  101. void CPacketMonitorPage::OnDelKerRule() 
  102. {
  103. // TODO: Add your control notification handler code here
  104. // 获得选中的行号
  105. int nItem = m_PacketMonitorList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  106. // 删除规则
  107. g_RuleFile.DelKerRule(nItem);
  108. // 将规则保存到文件
  109. g_RuleFile.SaveRules();
  110. // 将规则在 AccessCtrlList 控件上显示出来
  111. ::PostMessage(g_hMainWnd, UPDATE_PACKET_MONITOR_LIST, 0, 0);
  112. // 将规则应用到核心层模块
  113. theApp.ApplyKerRules();
  114. }