MyFireWallDlg.cpp
上传用户:zhuzhu0204
上传日期:2020-07-13
资源大小:13165k
文件大小:23k
源码类别:
防火墙与安全工具
开发平台:
Visual C++
- // MyFireWallDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyFireWall.h"
- #include "MyFireWallDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CMyFireWallApp theApp;
- #define IDM_SHOW_WINDOW 11 //显示主界面
- DWORD WINAPI GetFlowRateThread(LPVOID lpParam)
- {
- CMyFireWallDlg *pMyFireWallDlg = (CMyFireWallDlg *)lpParam;
- HANDLE hControlDevice = PtOpenControlDevice();
- CIMAdapters adapters;
- if(!adapters.EnumAdapters(hControlDevice))
- return ERROR_SUCCESS;
- HANDLE hAdapter;
- while (TRUE)
- {
- PassthruStatistics PassthruStats;
- for(int i=0; i<adapters.m_nAdapters; i++)
- {
- // 打开下层适配器
- hAdapter = PtOpenAdapter(adapters.m_pwszAdapterName[i]);
- if(hAdapter != INVALID_HANDLE_VALUE)
- {
- PassthruStatistics Stats;
- BOOL bRet = PtQueryStatistics(hAdapter, &Stats);
- if(bRet == FALSE)
- {
- AfxMessageBox(L"返回值位 FALSE");
- ::CloseHandle(hAdapter);
- ::CloseHandle(hControlDevice);
- break;
- }
- PassthruStats.nSendFlowRate = Stats.nSendFlowRate;
- PassthruStats.nRecvFlowRate = Stats.nRecvFlowRate;
- PassthruStats.nMPSendPktsCt = Stats.nMPSendPktsCt;
- PassthruStats.nMPSendPktsDropped = Stats.nMPSendPktsDropped;
- PassthruStats.nPTRcvCt = Stats.nPTRcvCt;
- PassthruStats.nPTRcvDropped = Stats.nPTRcvDropped;
- PassthruStats.nPTRcvPktCt = Stats.nPTRcvPktCt;
- PassthruStats.nPTRcvPktDropped = Stats.nPTRcvPktDropped;
- ::CloseHandle(hAdapter);
- }
- }
- //
- // CString strFlowRate;
- // strFlowRate.Format(L"发送流量:%d kbpsrn接收流量:%d KbpsrnnMPSendPktsCt: %drnnMPSendPktsDropped: %drnnPTRcvCt: %drnnPTRcvDropped: %drnnPTRcvPktCt: %drnnPTRcvPktDropped: %d",
- // PassthruStats.nSendFlowRate*8/1024,
- // PassthruStats.nRecvFlowRate*8/1024,
- // PassthruStats.nMPSendPktsCt,
- // PassthruStats.nMPSendPktsDropped,
- // PassthruStats.nPTRcvCt,
- // PassthruStats.nPTRcvDropped,
- // PassthruStats.nPTRcvPktCt,
- // PassthruStats.nPTRcvPktDropped
- // );
- // pMyFireWallDlg->m_WorkStatusPage.SetDlgItemText(IDC_FLOW_RATE, strFlowRate);
- //
- Sleep(1000);
- }
- ::CloseHandle(hControlDevice);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyFireWallDlg dialog
- CMyFireWallDlg::CMyFireWallDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyFireWallDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMyFireWallDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMyFireWallDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyFireWallDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyFireWallDlg, CDialog)
- //{{AFX_MSG_MAP(CMyFireWallDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_COMMAND(IDM_BLUE, OnSkinBlue)
- ON_COMMAND(IDM_GREEN, OnSkinGreen)
- ON_COMMAND(IDM_WHITE, OnSkinWhite)
- ON_COMMAND(IDM_EXIT, OnMenuExit)
- ON_COMMAND(IDM_LSP_RULE, OnMenuLspRule)
- ON_COMMAND(IDM_KER_RULE, OnMenuKerRule)
- ON_COMMAND(IDM_CUTDOWN_NETWORK, OnMenuCutdownNetwork)
- ON_COMMAND(IDM_STOP_PROTECT, OnMenuStopProtect)
- //}}AFX_MSG_MAP
- ON_MESSAGE(PM_QUERY_ACL_NOTIFY, OnQueryAcl)
- ON_MESSAGE(PM_SESSION_NOTIFY, OnSessionNotify)
- ON_MESSAGE(QUERY_DLG_DESTROY, OnQueryDlgDestroy)
- ON_MESSAGE(UPDATE_ACCESS_CTRL_LIST, OnUpdateAccessCtrlList)
- ON_MESSAGE(UPDATE_PACKET_MONITOR_LIST, OnUpdatePacketMonitorList)
- ON_MESSAGE(UPDATE_WEBSITE_LIST, OnUpdateWebSiteList)
- ON_MESSAGE(UPDATE_IPRULE_LIST, OnUpdateIPRuleList)
- ON_COMMAND(IDM_SHOW_WINDOW,ShowMainWindow)
- ON_MESSAGE(WM_TO_TRAY,OnShowTask)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyFireWallDlg message handlers
- BOOL CMyFireWallDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- // 设置 DLL 对应的主对话框句柄
- TCHAR szPath[256];
- ::GetModuleFileName(NULL, szPath, 256);
- g_pIoControl->SetInstance(m_hWnd, szPath);
- // 保存主对话框句柄到一个全局变量
- g_hMainWnd = m_hWnd;
- m_pQueryDlg = NULL;
- m_pStartQueryDlg = NULL;
- m_Sheet.AddPage(&m_WorkStatusPage);
- m_Sheet.AddPage(&m_AppMonitorPage);
- m_Sheet.AddPage(&m_AccessCtrlPage);
- m_Sheet.AddPage(&m_PacketMonitorPage);
- m_Sheet.AddPage(&m_IPRulePage);
- m_Sheet.AddPage(&m_WebSiteSettingPage);
- m_Sheet.AddPage(&m_ARPRulePage);
- m_Sheet.Create(this,WS_CHILD|WS_VISIBLE,0);
- m_Sheet.ModifyStyleEx(0,WS_EX_CONTROLPARENT);
- m_Sheet.ModifyStyle(0,WS_TABSTOP);
- CRect rect;
- m_Sheet.GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_Sheet.SetWindowPos(NULL,rect.left-4,rect.top-5,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
- m_Sheet.SetActivePage(&m_ARPRulePage);
- m_Sheet.SetActivePage(&m_WebSiteSettingPage);
- m_Sheet.SetActivePage(&m_IPRulePage);
- m_Sheet.SetActivePage(&m_PacketMonitorPage);
- m_Sheet.SetActivePage(&m_AccessCtrlPage);
- m_Sheet.SetActivePage(&m_AppMonitorPage);
- m_Sheet.SetActivePage(&m_WorkStatusPage);
- // 显示应用层规则到 AccessCtrlList
- OnUpdateAccessCtrlList(0, 0);
- // 显示核心层规则到 PacketMonitorList
- OnUpdatePacketMonitorList(0, 0);
- // 显示网站黑名单到 WebSiteList
- OnUpdateWebSiteList(0, 0);
- // 获得日志文件路径
- char szPathName[256];
- sprintf(szPathName, ("%s%s"), strCurrentPath, ("MyFireWall.log"));
- // 打开日志文件
- if((g_pLogFile = fopen(szPathName, "a")) == NULL)
- {
- AfxMessageBox(_T("MyFireWall.exe 打开日志文件出错!"));
- }
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CMyFireWallDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CMyFireWallDlg::OnPaint()
- {
- // 设置 DLL 对应的主对话框句柄
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMyFireWallDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMyFireWallDlg::OnSkinBlue()
- {
- // TODO: Add your command handler code here
- LoadSkin("Minimized.ssk");
- // 保存日志文件
- SaveLogFile("用户将防火墙皮肤设置为蓝色。");
- }
- void CMyFireWallDlg::OnSkinGreen()
- {
- // TODO: Add your command handler code here
- LoadSkin("Topax.ssk");
- // 保存日志文件
- SaveLogFile("用户将防火墙皮肤设置为绿色。");
- }
- void CMyFireWallDlg::OnSkinWhite()
- {
- // TODO: Add your command handler code here
- LoadSkin("dogmax.ssk");
- // 保存日志文件
- SaveLogFile("用户将防火墙皮肤设置为白色。");
- }
- void CMyFireWallDlg::OnSessionNotify(WPARAM wParam, LPARAM lParam)
- {
- SESSION session;
- //获取Dll发送来的 Session
- g_pIoControl->GetSession(&session, wParam);
- //解析出消息类型
- int nCode = lParam;
- switch(nCode)
- {
- case CODE_CHANGE_SESSION: //一个会话的属性改变了
- m_AppMonitorPage.AddSession(&session);
- break;
- case CODE_DELETE_SESSION: //一个会话被删除
- m_AppMonitorPage.DeleteSession(&session, FALSE);
- break;
- case CODE_APP_EXIT: //一个应用程序退出,我们要删除此应用程序的所有会话
- m_AppMonitorPage.DeleteSession(&session,TRUE);
- break;
- }
- }
- void CMyFireWallDlg::OnQueryAcl(WPARAM wParam, LPARAM lParam)
- {
- CQueryDlg *pQueryDlg = new CQueryDlg;
- /*******************************************************************************************/
- CRect DlgRect,ScreenRect;
- SystemParametersInfo(SPI_GETWORKAREA,0,&ScreenRect,0); //检索工作区大小,工作区是指没有被任务遮盖的屏幕部分。
- // 传递应用程序会话
- g_pIoControl->GetQuerySession(&pQueryDlg->m_Session, wParam);
- pQueryDlg->m_nIndex = wParam;
- pQueryDlg->Create(IDD_QUERY_DLG);
- pQueryDlg->GetWindowRect(&DlgRect);
- pQueryDlg->SetWindowPos(&wndTopMost,ScreenRect.Width()-DlgRect.Width(),ScreenRect.Height()-DlgRect.Height(),DlgRect.Width(),DlgRect.Height(),SWP_NOSIZE);
- pQueryDlg->m_pNext = NULL;
- /*******************************************************************************************/
- if (m_pStartQueryDlg == NULL)
- {
- m_pStartQueryDlg = pQueryDlg;
- m_pQueryDlg = pQueryDlg;
- // 使用淡出效果显示对话框
- // AnimateWindow(dlg.m_hWnd,1000,AW_ACTIVATE|AW_CENTER|AW_BLEND);
- m_pStartQueryDlg->ShowWindow(SW_SHOW);
- }
- else
- {
- m_pQueryDlg->m_pNext = pQueryDlg;
- m_pQueryDlg = pQueryDlg;
- }
- }
- void CMyFireWallDlg::OnQueryDlgDestroy(WPARAM wParam, LPARAM lParam)
- {
- CQueryDlg *pTemp = m_pStartQueryDlg;
- m_pStartQueryDlg = m_pStartQueryDlg->m_pNext;
- delete pTemp;
- if (m_pStartQueryDlg != NULL)
- {
- // 显示下一个询问对话框
- m_pStartQueryDlg->ShowWindow(SW_SHOW);
- }
- }
- void CMyFireWallDlg::OnUpdateAccessCtrlList(WPARAM wParam, LPARAM lParam)
- {
- CString ss;
- ss.Format(L"DEBUG输出: ulLspRuleCount = %d",g_RuleFile.m_header.ulLspRuleCount);
- m_AccessCtrlPage.SetDlgItemText(IDC_DEBUG, ss);
- int nItem;
- CString strTemp;
- m_AccessCtrlPage.ImageList.DeleteImageList();
- m_AccessCtrlPage.ImageList.Create(18, 18, ILC_COLOR8, 30, 10);
- m_AccessCtrlPage.m_AccessCtrlList.SetImageList(&m_AccessCtrlPage.ImageList, LVSIL_SMALL);
- //清除原来的显示内容
- m_AccessCtrlPage.m_AccessCtrlList.DeleteAllItems();
- for(int i=0; i < (int)g_RuleFile.m_header.ulLspRuleCount; i++)
- {
- //设置应用程序的图标
- SHFILEINFOW stFileInfo;
- if( ::SHGetFileInfo(g_RuleFile.m_pLspRules[i].szApplication, 0, &stFileInfo, sizeof(stFileInfo), SHGFI_ICON))
- {
- m_AccessCtrlPage.ImageList.Add(stFileInfo.hIcon);
- }
- //设置应用程序名称
- nItem = m_AccessCtrlPage.m_AccessCtrlList.InsertItem(i, GetFileName(g_RuleFile.m_pLspRules[i].szApplication), i);
- //设置采取的动作
- if(g_RuleFile.m_pLspRules[i].ucAction == RULE_ACTION_PASS)
- {
- strTemp = L" 允许 ";
- }
- else if(g_RuleFile.m_pLspRules[i].ucAction == RULE_ACTION_DENY)
- {
- strTemp = L" 禁止 ";
- }
- m_AccessCtrlPage.m_AccessCtrlList.SetItemText(nItem, 1, strTemp);
- //设置协议类型
- switch(g_RuleFile.m_pLspRules[i].ucServiceType)
- {
- case RULE_SERVICE_TYPE_ALL:
- strTemp.Format(L"%s",L"所有");
- break;
- case RULE_SERVICE_TYPE_TCP:
- strTemp.Format(L"%s",L"TCP");
- break;
- case RULE_SERVICE_TYPE_UDP:
- strTemp.Format(L"%s",L"UDP");
- break;
- case RULE_SERVICE_TYPE_FTP:
- strTemp.Format(L"%s",L"FTP");
- break;
- case RULE_SERVICE_TYPE_TELNET:
- strTemp.Format(L"%s",L"TELNET");
- break;
- case RULE_SERVICE_TYPE_HTTP:
- strTemp.Format(L"%s",L"HTTP");
- break;
- case RULE_SERVICE_TYPE_NNTP:
- strTemp.Format(L"%s",L"NNTP");
- break;
- case RULE_SERVICE_TYPE_SMTP:
- strTemp.Format(L"%s",L"SMTP");
- break;
- }
- m_AccessCtrlPage.m_AccessCtrlList.SetItemText(nItem, 2, strTemp);
- //设置应用程序路径
- m_AccessCtrlPage.m_AccessCtrlList.SetItemText(nItem, 3, g_RuleFile.m_pLspRules[i].szApplication);
- //设置应用程序的描述
- m_AccessCtrlPage.m_AccessCtrlList.SetItemText(nItem, 4, g_RuleFile.m_pLspRules[i].sDemo);
- }
- }
- void CMyFireWallDlg::OnUpdatePacketMonitorList(WPARAM wParam, LPARAM lParam)
- {
- int nItem;
- WCHAR wszTemp[6];
- BYTE *pByte = new BYTE;
- CString strIP, strTemp;
- PPassthruFilter pItem = new PassthruFilter;
- //清除原来的显示内容
- m_PacketMonitorPage.m_PacketMonitorList.DeleteAllItems();
- for (int i = 0; i < (int)g_RuleFile.m_header.ulKerRuleCount; i++)
- {
- pItem = &g_RuleFile.m_pKerRules[i];
- // 源IP地址
- pByte = (BYTE *)&pItem->sourceIP;
- strIP.Format(L"%d.%d.%d.%d", pByte[3], pByte[2], pByte[1], pByte[0]);
- strTemp = (pItem->sourceIP == 0)? L"所有" : strIP;
- nItem = m_PacketMonitorPage.m_PacketMonitorList.InsertItem(i, strTemp);
- /*
- // 源IP掩码
- pByte = (BYTE *)&pItem->sourceMask;
- strTemp.Format(L"%d.%d.%d.%d", pByte[3], pByte[2], pByte[1], pByte[0]);
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 1, strTemp);
- */
- // 源端口号
- strTemp = (pItem->sourcePort == 0)? L"所有" : ::_itot(pItem->sourcePort, wszTemp, 10);
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 1, strTemp);
- // 目的IP地址
- pByte = (BYTE *)&pItem->destinationIP;
- strIP.Format(L"%d.%d.%d.%d", pByte[3], pByte[2], pByte[1], pByte[0]);
- strTemp = (pItem->destinationIP == 0)? L"所有" : strIP;
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 2, strTemp);
- /*
- // 目的IP掩码
- pByte = (BYTE *)&pItem->destinationMask;
- strTemp.Format(L"%d.%d.%d.%d", pByte[3], pByte[2], pByte[1], pByte[0]);
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 4, strTemp);
- */
- // 目的端口号
- strTemp = (pItem->destinationPort == 0)? L"所有" : ::_itot(pItem->destinationPort, wszTemp, 10);
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 3, strTemp);
- // 协议
- switch(pItem->protocol)
- {
- case 1:
- strTemp = L"ICMP";
- break;
- case 6:
- strTemp = L"TCP";
- break;
- case 17:
- strTemp = L"UDP";
- break;
- default:
- strTemp = L"所有";
- }
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 4, strTemp);
- //动作
- strTemp = pItem->bDrop? L"禁止" : L"允许";
- m_PacketMonitorPage.m_PacketMonitorList.SetItemText(nItem, 5, strTemp);
- }
- }
- void CMyFireWallDlg::OnUpdateWebSiteList(WPARAM wParam, LPARAM lParam)
- {
- int nItem;
- int nIndex = 0;
- BYTE *pByte = new BYTE;
- CString strIP, strTemp;
- PPassthruFilter pItem = new PassthruFilter;
- //清除原来的显示内容
- m_WebSiteSettingPage.m_WebSiteList.DeleteAllItems();
- for (int i = 0; i < (int)g_RuleFile.m_header.ulKerRuleCount; i++)
- {
- pItem = &g_RuleFile.m_pKerRules[i];
- if (_tcscmp(pItem->szWebSiteURL, L"") == 0)
- {
- continue ;
- }
- // 网站URL
- nItem = m_WebSiteSettingPage.m_WebSiteList.InsertItem(nIndex, pItem->szWebSiteURL);
- // 网站IP地址
- pByte = (BYTE *)&pItem->destinationIP;
- strIP.Format(L"%d.%d.%d.%d", pByte[3], pByte[2], pByte[1], pByte[0]);
- strTemp = (pItem->destinationIP == 0)? L"所有" : strIP;
- m_WebSiteSettingPage.m_WebSiteList.SetItemText(nItem, 1, strTemp);
- // 网站描述信息
- m_WebSiteSettingPage.m_WebSiteList.SetItemText(nItem, 2, pItem->szDescription);
- nIndex++;
- }
- }
- void CMyFireWallDlg::OnUpdateIPRuleList(WPARAM wParam, LPARAM lParam)
- {
- int nItem;
- CString strTemp;
- // 应用 CImageList 从另一种角度上增加 IPRuleList 的列宽
- CImageList ImageList;
- ImageList.Create(1, 18, ILC_COLOR8, 0, 0);
- m_IPRulePage.m_IPRuleList.SetImageList(&ImageList, LVSIL_SMALL);
- // 删除以前全部内容
- m_IPRulePage.m_IPRuleList.DeleteAllItems();
- // Ping入规则
- nItem = m_IPRulePage.m_IPRuleList.InsertItem(0, L"Ping入");
- strTemp = g_RuleFile.m_pIPRules[0].bState? L" 允许 " : L" 拒绝 ";
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 1, strTemp);
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 2, L"ICMP");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 3, L"任意");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 4, g_RuleFile.m_pIPRules[0].description);
- // Ping出规则
- nItem = m_IPRulePage.m_IPRuleList.InsertItem(1, L"Ping出");
- strTemp = g_RuleFile.m_pIPRules[1].bState? L" 允许 " : L" 拒绝 ";
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 1, strTemp);
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 2, L"ICMP");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 3, L"任意");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 4, g_RuleFile.m_pIPRules[1].description);
- // RPC(Remote Procedurce call: 远程过程调用)规则
- nItem = m_IPRulePage.m_IPRuleList.InsertItem(2, L"RPC(远程过程调用)");
- strTemp = g_RuleFile.m_pIPRules[2].bState? L" 允许 " : L" 拒绝 ";
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 1, strTemp);
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 2, L"TCP");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 3, L"135");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 4, g_RuleFile.m_pIPRules[2].description);
- // DNS(域名服务)规则
- nItem = m_IPRulePage.m_IPRuleList.InsertItem(3, L"DNS(域名服务)");
- strTemp = g_RuleFile.m_pIPRules[3].bState? L" 允许 " : L" 拒绝 ";
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 1, strTemp);
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 2, L"UDP");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 3, L"53");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 4, g_RuleFile.m_pIPRules[3].description);
- // 局域网共享规则
- nItem = m_IPRulePage.m_IPRuleList.InsertItem(4, L"局域网共享");
- strTemp = g_RuleFile.m_pIPRules[4].bState? L" 允许 " : L" 拒绝 ";
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 1, strTemp);
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 2, L"TCP");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 3, L"139,445");
- m_IPRulePage.m_IPRuleList.SetItemText(nItem, 4, g_RuleFile.m_pIPRules[4].description);
- }
- void CMyFireWallDlg::OnMenuCutdownNetwork()
- {
- // TODO: Add your command handler code here
- CString strItem;
- GetMenu()->GetMenuString(IDM_CUTDOWN_NETWORK, strItem, MF_BYCOMMAND);
- if (strItem == L"断开网络")
- {
- int nWorkMode = IM_DENY_ALL;
- PtSetWorkMode(&nWorkMode);
- // 显示“连接网络”
- GetMenu()->GetSubMenu(0)->ModifyMenu(IDM_CUTDOWN_NETWORK, MF_BYCOMMAND, IDM_CUTDOWN_NETWORK, L"连接网络");
- // 在“工作状态”标签上改变核心层工作模式
- m_WorkStatusPage.SetDlgItemText(IDC_KER_MODE, L"禁止所有");
- // 保存日志文件
- SaveLogFile("用户断开网络。");
- }
- else
- {
- int nWorkMode = g_RuleFile.m_header.ucKerWorkMode;
- PtSetWorkMode(&nWorkMode);
- // 显示“断开网络”
- GetMenu()->GetSubMenu(0)->ModifyMenu(IDM_CUTDOWN_NETWORK, MF_BYCOMMAND, IDM_CUTDOWN_NETWORK, L"断开网络");
- // 在“工作状态”标签上改变核心层工作模式
- m_WorkStatusPage.UpdateWorkMode();
- // 保存日志文件
- SaveLogFile("用户连接网络。");
- }
- }
- void CMyFireWallDlg::OnMenuStopProtect()
- {
- // TODO: Add your command handler code here
- CString strItem;
- GetMenu()->GetMenuString(IDM_STOP_PROTECT, strItem, MF_BYCOMMAND);
- if (strItem == L"停止保护")
- {
- // 应用层放行所有
- g_pIoControl->SetWorkMode(PF_PASS_ALL);
- // 驱动层放行所有
- int nWorkMode = IM_PASS_ALL;
- PtSetWorkMode(&nWorkMode);
- // 显示“开启保护”
- GetMenu()->GetSubMenu(0)->ModifyMenu(IDM_STOP_PROTECT, MF_BYCOMMAND, IDM_STOP_PROTECT, L"开启保护");
- // 在“工作状态”标签上改变应用层和核心层工作模式
- m_WorkStatusPage.SetDlgItemText(IDC_LSP_MODE, L"允许所有");
- m_WorkStatusPage.SetDlgItemText(IDC_KER_MODE, L"允许所有");
- // 保存日志文件
- SaveLogFile("用户停止防火墙保护。");
- }
- else
- {
- // 应用层过滤所有
- g_pIoControl->SetWorkMode(g_RuleFile.m_header.ucLspWorkMode);
- // 驱动层过滤所有
- int nWorkMode = g_RuleFile.m_header.ucKerWorkMode;
- PtSetWorkMode(&nWorkMode);
- // 显示“停止保护”
- GetMenu()->GetSubMenu(0)->ModifyMenu(IDM_STOP_PROTECT, MF_BYCOMMAND, IDM_STOP_PROTECT, L"停止保护");
- // 在“工作状态”标签上还原应用层和核心层工作模式
- m_WorkStatusPage.UpdateWorkMode();
- // 保存日志文件
- SaveLogFile("用户开启防火墙保护。");
- }
- }
- void CMyFireWallDlg::OnMenuExit()
- {
- // TODO: Add your command handler code here
- RemoveProvider();
- // 保存日志文件
- SaveLogFile("用户关闭防火墙。");
- exit(0);
- }
- void CMyFireWallDlg::OnMenuLspRule()
- {
- // TODO: Add your command handler code here
- m_Sheet.SetActivePage(&m_AccessCtrlPage);
- }
- void CMyFireWallDlg::OnMenuKerRule()
- {
- // TODO: Add your command handler code here
- m_Sheet.SetActivePage(&m_PacketMonitorPage);
- }
- void CMyFireWallDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
- nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
- nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
- nid.hWnd=this->m_hWnd;
- nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
- nid.uID=IDR_MAINFRAME;
- nid.uCallbackMessage=WM_TO_TRAY;
- wsprintf(nid.szTip, _T("%s"), _T("MyFireWall 正在保护您的网络……"));
- Shell_NotifyIcon(NIM_ADD,&nid);
- ShowWindow(SW_HIDE);
- }
- void CMyFireWallDlg::OnShowTask(WPARAM wParam, LPARAM lParam)
- {
- UINT uID; //发出该消息的图标的ID
- UINT uMouseMsg; //鼠标动作
- uID=(UINT) wParam;
- uMouseMsg=(UINT) lParam;
- if(uID!=IDR_MAINFRAME)
- {
- return;
- }
- switch(uMouseMsg)
- {
- case WM_LBUTTONDBLCLK:
- ShowWindow(SW_SHOW);
- break;
- case WM_RBUTTONUP:
- POINT point;
- //得到鼠标坐标
- GetCursorPos(&point);
- //创建弹出菜单
- CMenu menu;
- menu.CreatePopupMenu();
- //增加菜单项“启动”,点击则发送消息WM_DESTROY给主窗口,打开主界面。
- menu.AppendMenu(MF_STRING, IDM_SHOW_WINDOW, _T(" 启 动 "));
- //增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口,将程序结束。
- menu.AppendMenu(MF_STRING,IDM_EXIT, _T(" 关 闭 "));
- //将程序设置为前端窗口
- SetForegroundWindow();
- //确定弹出菜单的位置
- menu.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
- //资源回收
- HMENU hMenu=menu.Detach();
- menu.DestroyMenu();
- break;
- }
- return;
- }
- void CMyFireWallDlg::ShowMainWindow()
- {
- ShowWindow(SW_SHOW);
- }