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

📄 ccamsview.cpp

📁 一个网络监视的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 函 数 名:ListFile
// 功能描述:读取数据库存中的 File 记录, 在列表框中显示出来
// 输入参数:void
// 输出参数:void
// 创建日期:04-7-20
// 修改日期:04-7-20
// 作    者:陈欢
// 调用函数: non
// 被调函数: InitList
// 附加说明:引用全局变量 g_criFileAccess, gm_setFile
//===============================================================
void CCCAMSView::ListFile()
{
	extern CRITICAL_SECTION g_criFileAccess;
	extern	CSetFile	gm_setFile;
	EnterCriticalSection( &g_criFileAccess );

try
{
	if ( !gm_setFile.IsOpen() )
		gm_setFile.Open();
	gm_setFile.Requery();

	int i = 0;
	CString strFilter = GetDocument()->m_strCurClient;
	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT;

	while ( !gm_setFile.IsEOF() )
	{
		CString ip = gm_setFile.m_client.GetBuffer(0);
		if ( !strFilter.IsEmpty() && ip != strFilter )
		{
			gm_setFile.MoveNext();
			continue;
		}
		
		// who
		lvi.iItem = i;
		lvi.iSubItem = 0;
		lvi.pszText = ip.GetBuffer(0);
		m_listHis.InsertItem( &lvi );

		// when
		m_listHis.SetItemText( i, 1, gm_setFile.m_time );

		// what
		CString str = "File  " + gm_setFile.m_action + "  " + gm_setFile.m_path;
		m_listHis.SetItemText( i, 2, str );

		i++;
		gm_setFile.MoveNext();
	}
}
catch(...) {}
	gm_setFile.Close();
	LeaveCriticalSection( &g_criFileAccess );
}

//===============================================================
// 函 数 名:ListMail
// 功能描述:读取数据库存中的 Mail 记录, 在列表框中显示出来
// 输入参数:void
// 输出参数:void
// 创建日期:04-7-20
// 修改日期:04-7-20
// 作    者:陈欢
// 调用函数: non
// 被调函数: InitList
// 附加说明:引用全局变量 g_criMailAccess, gm_setMail
//===============================================================
void CCCAMSView::ListMail()
{
	extern CRITICAL_SECTION g_criMailAccess;
	extern	CSetMail	gm_setMail;
	EnterCriticalSection( &g_criMailAccess );

try
{
	if ( !gm_setMail.IsOpen() )
		gm_setMail.Open();
	gm_setMail.Requery();

	int i = 0;
	CString strFilter = GetDocument()->m_strCurClient;
	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT;

	while ( !gm_setMail.IsEOF() )
	{
		CString ip = gm_setMail.m_client.GetBuffer(0);
		if ( !strFilter.IsEmpty() && ip != strFilter )
		{
			gm_setMail.MoveNext();
			continue;
		}

		// who
		lvi.iItem = i;
		lvi.iSubItem = 0;
		lvi.pszText = ip.GetBuffer(0);
		m_listHis.InsertItem( &lvi );

		// when
		m_listHis.SetItemText( i, 1, gm_setMail.m_time );

		// what
		CString str = "Mail  " + gm_setMail.m_subject + " From: " + gm_setMail.m_sender +
			" To: " + gm_setMail.m_recipient + " Attachment: " + gm_setMail.m_attach;
		m_listHis.SetItemText( i, 2, str );

		i++;
		gm_setMail.MoveNext();
	}
}
catch(...){}

	gm_setMail.Close();
	LeaveCriticalSection( &g_criMailAccess );
}

//===============================================================
// 函 数 名:ListNet
// 功能描述:读取数据库存中的 Net 记录, 在列表框中显示出来
// 输入参数:void
// 输出参数:void
// 创建日期:04-7-20
// 修改日期:04-7-20
// 作    者:陈欢
// 调用函数: non
// 被调函数: InitList
// 附加说明:引用全局变量 g_criNetAccess, gm_setNet
//===============================================================
void CCCAMSView::ListNet()
{
	extern CRITICAL_SECTION g_criNetAccess;
	extern	CSetNet		gm_setNet;
	EnterCriticalSection( &g_criNetAccess );

	if ( !gm_setNet.IsOpen() )
		gm_setNet.Open();
	gm_setNet.Requery();

try
{
	int i = 0;
	CString strFilter = GetDocument()->m_strCurClient;
	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT;

		while ( !gm_setNet.IsEOF() )
		{
			CString ip = gm_setNet.m_client.GetBuffer(0);
			if ( !strFilter.IsEmpty() && ip != strFilter )
			{
				gm_setNet.MoveNext();
				continue;
			}
	
			// who
			lvi.iItem = i;
			lvi.iSubItem = 0;
			lvi.pszText = ip.GetBuffer(0);
			m_listHis.InsertItem( &lvi );

			// when
			m_listHis.SetItemText( i, 1, gm_setNet.m_time );

			// what
			CString rep;		rep.Format( "%d", gm_setNet.m_repeat );
			CString size;		size.Format( "%d", gm_setNet.m_size );
			CString tcpflag;	tcpflag.Format( "%d", gm_setNet.m_tcpflag );
			CString port;		port.Format( "%d", gm_setNet.m_port );
			CString str = "Net  Repeat: " + rep + " " + gm_setNet.m_direction + " " +
				gm_setNet.m_protocol + " " + tcpflag + " " + gm_setNet.m_address +
				" Port: " + port + " Size: " + size + " bytes";
			m_listHis.SetItemText( i, 2, str );

			i++;
			gm_setNet.MoveNext();
		}
}
catch(...) {}
	gm_setNet.Close();
	LeaveCriticalSection( &g_criNetAccess );
}

//===============================================================
// 函 数 名:ListProcess
// 功能描述:读取数据库存中的 Process 记录, 在列表框中显示出来
// 输入参数:void
// 输出参数:void
// 创建日期:04-7-20
// 修改日期:04-7-20
// 作    者:陈欢
// 调用函数: non
// 被调函数: InitList
// 附加说明:引用全局变量 g_criProcAccess, gm_setProc
//===============================================================
void CCCAMSView::ListProcess()
{
	extern CRITICAL_SECTION g_criProcAccess;
	extern	CSetProc	gm_setProc;
	EnterCriticalSection( &g_criProcAccess );

try
{
	if ( !gm_setProc.IsOpen() )
		gm_setProc.Open();
	gm_setProc.Requery();

	int i = 0;
	CString strFilter = GetDocument()->m_strCurClient;
	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT;

		while ( !gm_setProc.IsEOF() )
		{
			CString ip = gm_setProc.m_client.GetBuffer(0);
			if ( !strFilter.IsEmpty() && ip != strFilter )
			{
				gm_setProc.MoveNext();
				continue;
			}
	
			// who
			lvi.iItem = i;
			lvi.iSubItem = 0;
			lvi.pszText = ip.GetBuffer(0);
			m_listHis.InsertItem( &lvi );

			// when
			m_listHis.SetItemText( i, 1, gm_setProc.m_time );

			// what
			CString str = "Process  " + gm_setProc.m_action + "  " + gm_setProc.m_path;
			m_listHis.SetItemText( i, 2, str );

			i++;
			gm_setProc.MoveNext();
		}
}
catch(...) {}
	gm_setProc.Close();
	LeaveCriticalSection( &g_criProcAccess );
}

//===============================================================
// 函 数 名:OnTimer
// 功能描述:根据用户的选择更新 Diagram, 每十秒执行一次
// 输入参数:nIDEvent
// 输出参数:void
// 创建日期:04-7-20
// 修改日期:04-7-20
// 作    者:陈欢
// 调用函数: non
// 被调函数: 系统定时器
// 附加说明:引用全局变量 g_criActiveClientList, theActiveClientList
//===============================================================
void CCCAMSView::OnTimer(UINT nIDEvent) 
{
	extern CRITICAL_SECTION g_criActiveClientList;
	extern ActivClient theActiveClientList;

	// 选择了新的查看对象, 重新开始显示
	CString strCurClient = GetDocument()->m_strCurDiagramClient;
	if ( strCurClient != m_strPreClient )
	{
		m_strPreClient = strCurClient;
		m_Plot.ClearData();
	}

	EnterCriticalSection( &g_criActiveClientList );

	// 没有活动主机时退出
	if ( theActiveClientList.GetCount() == 0 )
	{
		m_Plot.ClearData();
		GetDocument()->m_strCurDiagramClient.Empty();
		LeaveCriticalSection( &g_criActiveClientList );
		if ( GetDocument()->m_nCurView == 1 )
			Invalidate();
		return;
	}

	// 选择查看全部用户, 计算统计信息
	if ( strCurClient.IsEmpty() )
	{
		int cout = theActiveClientList.GetCount();
		double sum = 0;
		// CPU, 求平均值
		for ( int i = 0; i < cout; i++ )
		{
			sum += ( theActiveClientList.m_nDataSum[i][0] / 3 );
		}
		sum /= cout;
		//sum = (double)( abs(rand()) % 100);	// for test
		m_Plot.AddPoint(0, CTime::GetCurrentTime(), sum);

		// File, Mail, Net, Process
		for ( i=1; i<5; i++ )
		{
			sum = 0;
			for ( int j = 0; j < cout; j++ )
				sum += theActiveClientList.m_nDataSum[j][i];
			//sum = (double)( abs(rand()) % 100);	// for test
			m_Plot.AddPoint(i, CTime::GetCurrentTime(), sum);
		}
	}

	// 选择查看单个用户
	else
	{
		int index = theActiveClientList.IsOnLine( strCurClient );
		if ( index == -1 )
		{
			for ( int i=0; i<5; i++ )
				m_Plot.AddPoint(i, CTime::GetCurrentTime(), 0);
		}
		else
		{
			// CPU
			m_Plot.AddPoint(0, CTime::GetCurrentTime(), 
				theActiveClientList.m_nDataSum[index][0]/3);
			// File, Mail, Net, Process
			for ( int i = 1; i < 5; i++ )
				m_Plot.AddPoint(i, CTime::GetCurrentTime(), 
						theActiveClientList.m_nDataSum[index][i]);
		}
	}

	theActiveClientList.ReSet();
	LeaveCriticalSection( &g_criActiveClientList );

	if ( GetDocument()->m_nCurView == 1 )
		Invalidate();
	CFormView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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