Example #1
0
/**
 * service会话结束的时候处理函数,一般这儿用来给用户回报,发送运营日志等清理操作
 */
int CISecRegService::OnFinish(int iErrCode)
{
    LOG_TRACE("OnFinish TknSeq|%llu| ErrCode|%d|", m_stReq.ullTknSeq, iErrCode);

    AddMonitor(iErrCode); //增加监控

    if(RT_MSEC_SUCCESS == iErrCode)
    {
    	MyMonitor(ATTR_IREG_SUCCESS);
    }

    uint8_t aucPkg[512] = {0};
    int iPkgBufLen      = sizeof(aucPkg);
    tMPushIosRegDeviceRsp  stRsp;
    bzero(&stRsp, sizeof(stRsp));

    stRsp.stBHead.ulRetCode = iErrCode;
    m_stHead.usMsgType = MSG_TYPE_ISEC_REG_DEVICE_RSP;

    int iRet = msec_pack(m_stHead, stRsp, aucPkg, iPkgBufLen);
    if(iRet != 0)
    {
    	LOG_ERR("TknSeq|%llu| push pack Rsp package error|%d|", m_stReq.ullTknSeq, iRet);
    	return 0;
    }

    //那里来回那里去
    iRet = SrvFrameworkSendUdp(m_stServiceContext.iAddrName, &m_stServiceContext.stConnAddr, aucPkg, iPkgBufLen);
    ASSERT(iRet == 0);

    return 0;
}
Example #2
0
//
// 为ICMP监视列表增加记录
//
void AddIcmp(CListCtrl* pList, PPACKET_LOG pLog, int nMaxCount, BOOL IsSeleted, BOOL IsShowDate)
{
	CString sString[MONITOR_ICMP_HEADER_COUNT];

	sString[0] = ACL_QUERY_TEXT[pLog->bAction];
	sString[1] = GetName(pLog->sProcessName);
	sString[2].Format("%s", pLog->tStartTime.Format(IsShowDate ? "%Y-%m-%d %H:%M:%S" : "%H:%M:%S"));
	sString[3].Format("%s/%u", SEND_OR_RECV[pLog->SendOrRecv], pLog->dwRecvData + pLog->dwSendData);
	sString[4].Format("%s", GUI_DIRECTION[pLog->bDirection]);
	sString[5].Format("%s -> %s; %s", DIPToSIP(&pLog->dwLocalIp), DIPToSIP(&pLog->dwRemoteIp), pLog->sMemo);

	AddMonitor(pList, (LPCTSTR*)sString, MONITOR_ICMP_HEADER_COUNT, nMaxCount, IsSeleted);
}
Example #3
0
//
// 为网上邻居监视列表增加记录
//
void AddNnb(CListCtrl* pList, PPACKET_LOG pLog, int nMaxCount, BOOL IsSeleted, BOOL IsShowDate)
{
	CString sString[MONITOR_NNB_HEADER_COUNT];

	sString[0] = ACL_QUERY_TEXT[pLog->bAction];
	sString[1] = GetName(pLog->sProcessName);
	sString[2].Format("%s/%u", pLog->sLocalHost, pLog->wLocalPort);
	sString[3].Format("%s/%u", pLog->sRemoteHost, pLog->wRemotePort);
	sString[4].Format("%s/%u", SEND_OR_RECV[pLog->SendOrRecv], pLog->dwRecvData + pLog->dwSendData);
	sString[5].Format("%s/%s", GUI_SERVICE_TYPE[pLog->bProtocol], GUI_DIRECTION[pLog->bDirection]);
	sString[6].Format("%s", pLog->tStartTime.Format(IsShowDate ? "%Y-%m-%d %H:%M:%S" : "%H:%M:%S"));
	sString[7] = pLog->sMemo;

	AddMonitor(pList, (LPCTSTR*)sString, MONITOR_NNB_HEADER_COUNT, nMaxCount, IsSeleted);
}
Example #4
0
//
// 为应用程序监视列表增加记录
//
void AddApp(CListCtrl* pList, PPACKET_LOG pLog, int nMaxCount, BOOL IsSeleted, BOOL IsShowDate)
{
	CString sString[MONITOR_APP_HEADER_COUNT];

	sString[0] = ACL_QUERY_TEXT[pLog->bAction];
	sString[1] = GetName(pLog->sProcessName);
	sString[2].Format("%s", pLog->tEndTime.Format(IsShowDate ? "%Y-%m-%d %H:%M:%S" : "%H:%M:%S"));
	sString[3].Format("%s/%u", DIPToSIP(&pLog->dwRemoteIp), pLog->wRemotePort);
	sString[4].Format("%u/%u", pLog->dwSendData, pLog->dwRecvData);
	sString[5].Format("%s/%s", GUI_SERVICE_TYPE[pLog->bProtocol], GUI_DIRECTION[pLog->bDirection]);
	sString[6].Format("%s/%u", DIPToSIP(&pLog->dwLocalIp), pLog->wLocalPort);
	sString[7] = pLog->sMemo;

	AddMonitor(pList, (LPCTSTR*)sString, MONITOR_APP_HEADER_COUNT, nMaxCount, IsSeleted);
}
Example #5
0
void* EpollMonitor::WaitAcceptEvent( void *pData )
{
#ifndef WIN32
	epoll_event *events = new epoll_event[m_nMaxMonitor];	//epoll事件
	Socket sock;
	Socket sockClient;
	SOCKET hSock;
	/* 等待有事件发生 */
	while ( !m_bStop )
	{
		int nPollCount = epoll_wait(m_hEPollAccept, events, m_nMaxMonitor, -1 );
		if ( -1 == nPollCount ) break;
		/* 处理所有事件,nfds 为返回发生事件数 */
		int i = 0;
		for ( i = 0; i < nPollCount; i++ ) 
		{
			if ( m_epollExit == events[i].data.fd ) 
			{
				::closesocket(m_epollExit);
				break;
			}
			
			sock.Detach();
			sock.Attach(events[i].data.fd);
			while ( true )
			{
				sock.Accept( sockClient );
				if ( INVALID_SOCKET == sockClient.GetSocket() ) break;
				sockClient.SetSockMode();
				hSock = sockClient.Detach();
				AddMonitor(hSock);
				while ( !m_acceptEvents->Push((void*)hSock) ) m_sigWaitAcceptSpace.Wait();
				m_ioSignal.Notify();
			}
		}
	}
	delete[]events;
#endif
	return NULL;
}
Example #6
0
// EntityEx提交至ECC
bool CNNM2ECC::SubmitEntityExToEcc(EntityEx* pEx)
{
	if(pEx==NULL)
		return false;

	if(m_nnmGroupid.empty())
		InitNNMGroup();
	OBJECT objgroup= Cache_GetGroup( m_nnmGroupid.getword() );
	if(objgroup==INVALID_VALUE)
	{
		InitNNMGroup();
		objgroup= Cache_GetGroup( m_nnmGroupid.getword() );
		if(objgroup==INVALID_VALUE)
		{
			InitNNMGroup();
			myWriteLog->WriteLog( "InitNNMGroup Error!" );
			printf("InitNNMGroup Error!\n");
			return false;
		}
	}

	Entity* pEn = NULL;
	//新Entity标志
	bool bNewEn = false;
	//是否已转化过
	
	//获取 entity, 或者创建新 entity
	string eccEntityID= pEx->GetEccEntityID().getword();
	OBJECT objentity= Cache_GetEntity(eccEntityID);
	if(eccEntityID.empty() || objentity==INVALID_VALUE )
	{
		objentity= CreateEntity();
		bNewEn = true;
	}
	if(objentity==INVALID_VALUE)
		return false;
	pEn= reinterpret_cast<Entity *>(objentity);
	if(pEn==NULL)
		return false;


#ifdef _DEBUG
	//pEx->DisplayAllData();
#endif

	//如果设备名为空,那么直接返回,不发送到ECC中去
	if (pEx->GetProperty()["_MachineName"].empty()) 
		return true;
	
	(pEn->GetProperty())["sv_devicetype"] = pEx->GetType();							//设备类型	
	(pEn->GetProperty())["_MachineName"] = pEx->GetProperty()["_MachineName"];		//IP	
	(pEn->GetProperty())["_sysObjectID"] = pEx->GetProperty()["_sysObjectID"];		//sysObjectID	
	(pEn->GetProperty())["_Port"] = pEx->GetProperty()["_Port"];					//SNMP Port
	(pEn->GetProperty())["ifNumber"] = pEx->GetProperty()["ifNumber"];				//ifNumber 接口数量

	//获得组号
	word groupid = "";
	std::string stype = pEx->GetProperty()["type"].getword();
	int index= atoi( stype.c_str() );
	if( index==0 && stype.compare("0")!=0 )
		stype.clear();

	if( stype.empty() || index<0 || index>6 )
		groupid = m_nnmGroupid;
	else
		groupid = m_nnmSubGroupid[index];


	//共同体
	// Luowan 2007.5.23
	std::string strcomm = "public";
		
	try
	{
		strcomm = pEx->GetProperty()["_Community"].getword();
	}
	catch(...)
	{
	}

	if(strcomm.length()<=0)
		strcomm =  "public";

	char outbuf[512] = {0};
	if(!strcomm.empty())
	{
		Des des;
		des.Encrypt(strcomm.c_str(),outbuf);
		strcomm = outbuf;
	}

	(pEn->GetProperty())["_Community"] = strcomm.c_str();

	char pBuf[260];

	sprintf(pBuf, "community:%s",strcomm.c_str());
	myWriteLog->WriteLog(pBuf);

	//(pEn->GetProperty())["_Community"] = pEx->GetProperty()["_Community"];
	if(bNewEn)
	{
		myWriteLog->WriteLog("New Entity");

		svutil::buffer buftmp;
		
		buftmp.resetsize(2048);
		buftmp.zerobuf();			

		//sprintf(buftmp.getbuffer(),"%s %s",pEx->GetProperty()["manufact"].getword(),pEx->GetProperty()["model"].getword());
		//std::string svname = buftmp.getbuffer();

		string svname = (pEx->GetProperty()["name"].empty()) ? pEx->GetProperty()["ip"] : pEx->GetProperty()["name"];
		if(svname.length()<2)
		{
			svname = pEx->GetProperty()["ip"];
		}

		if(svname.empty())
			svname = "Hub或其他";

		//设备中文名
		(pEn->GetProperty())["sv_name"] = svname;

		myWriteLog->WriteLog("End of processing New entity.");
	}
	else
	{
		myWriteLog->WriteLog("Entity that already exists.");

		std::string svname1 = pEx->GetProperty()["nameCN"];
		if(svname1.length()<2)
		{	
			svname1 = pEx->GetProperty()["ip"];
		}

		if(svname1.empty())
			svname1 = "Hub或其他";

		(pEn->GetProperty())["sv_name"] = svname1;
	}

	//保存数据,submit 等 ,以上部分为设置 entity 数据
	word entityid;
	if(bNewEn)					
	{
		entityid= AddNewEntity( objentity,groupid.getword() );
		pEn->PutID(entityid);
	}
	else
		entityid = pEn->GetID();
	cout<<"entityid: \""<<entityid.getword()<<"\""<<endl;
	bool ret = SubmitEntity(objentity);
	if( ret )
	{
		myWriteLog->WriteLog("SubmitEntity 成功。");
		pEx->PutEccEntityID(entityid);
	}
	else
		myWriteLog->WriteLog("SubmitEntity 失败。");

	
	// Luowan 2007.6.26 注释掉了以下5行
	if(bNewEn)
	{
		myWriteLog->WriteLog("this->AddMonitor(pEn)");
		AddMonitor(pEn);
	}
	if(bNewEn)
		CloseEntity(objentity);

	myWriteLog->WriteLog("End of SubmitEntityExToEcc()");
	return ret;
}
Example #7
0
bool SVGroupview::triggerSlot(WObject *sender, const WSlot_ *slot, void **args)
{
  if (slot == slots_ + 0) {
    sender_ = sender;    MenuItemRequestProc(*((MENU_REQUEST *)args[0]));
    return true;
  }
  if (slot == slots_ + 1) {
    sender_ = sender;    backParent();
    return true;
  }
  if (slot == slots_ + 2) {
    sender_ = sender;    AddNewGroup();
    return true;
  }
  if (slot == slots_ + 3) {
    sender_ = sender;    EditGroupParam(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 4) {
    sender_ = sender;    showIconView();
    return true;
  }
  if (slot == slots_ + 5) {
    sender_ = sender;    showListView();
    return true;
  }
  if (slot == slots_ + 6) {
    sender_ = sender;    AddGroupData(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 7) {
    sender_ = sender;    EditGroupData(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 8) {
    sender_ = sender;    ChangeGroupState(*((string *)args[0]), *((int *)args[1]));
    return true;
  }
  if (slot == slots_ + 9) {
    sender_ = sender;    showMainView();
    return true;
  }
  if (slot == slots_ + 10) {
    sender_ = sender;    AddNewDevice();
    return true;
  }
  if (slot == slots_ + 11) {
    sender_ = sender;    AddDevice2nd(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 12) {
    sender_ = sender;    EnumDevice(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 13) {
    sender_ = sender;    EditDeviceByIndex(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 14) {
    sender_ = sender;    AddNewDeviceSucc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 15) {
    sender_ = sender;    EditDeviceSuccByID(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 16) {
    sender_ = sender;    ChangeDeviceState(*((string *)args[0]), *((int *)args[1]));
    return true;
  }
  if (slot == slots_ + 17) {
    sender_ = sender;    EnterDeviceByID(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 18) {
    sender_ = sender;    EnterNewDeviceByID(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 19) {
    sender_ = sender;    AddMonitor(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 20) {
    sender_ = sender;    CancelAddMonitor();
    return true;
  }
  if (slot == slots_ + 21) {
    sender_ = sender;    AddNewMonitorByType(*((int *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 22) {
    sender_ = sender;    AddMonitorSucc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 23) {
    sender_ = sender;    EditMonitorSuccByID(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 24) {
    sender_ = sender;    EditMonitorByIndex(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 25) {
    sender_ = sender;    BackMonitorList();
    return true;
  }
  if (slot == slots_ + 26) {
    sender_ = sender;    BackGroupDeviceList(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 27) {
    sender_ = sender;    EditSVSESuccByIndex(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 28) {
    sender_ = sender;    EditSVSEByIndex(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 29) {
    sender_ = sender;    enterSVSE(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 30) {
    sender_ = sender;    enterGroup(*((string *)args[0]));
    return true;
  }
  if (slot == slots_ + 31) {
    sender_ = sender;    backSVSEView();
    return true;
  }
  if (slot == slots_ + 32) {
    sender_ = sender;    DelDeviceByIdProc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 33) {
    sender_ = sender;    DelGroupByIdProc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 34) {
    sender_ = sender;    BatchAddMonitor();
    return true;
  }
  if (slot == slots_ + 35) {
    sender_ = sender;    ReloadCurrentView();
    return true;
  }
  if (slot == slots_ + 36) {
    sender_ = sender;    SortObjects(*((int *)args[0]));
    return true;
  }
  if (slot == slots_ + 37) {
    sender_ = sender;    RefreshCurrentList();
    return true;
  }
  if (slot == slots_ + 38) {
    sender_ = sender;    enterGroupByID(*((const std::string *)args[0]));
    return true;
  }
  if (slot == slots_ + 39) {
    sender_ = sender;    Translate();
    return true;
  }
  if (slot == slots_ + 40) {
    sender_ = sender;    ExChange();
    return true;
  }
  if (slot == slots_ + 41) {
    sender_ = sender;    CopyNewDeviceSucc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  if (slot == slots_ + 42) {
    sender_ = sender;    CopyNewMonitorSucc(*((string *)args[0]), *((string *)args[1]));
    return true;
  }
  return WContainerWidget::triggerSlot(sender, slot, args);
}
Example #8
0
int PASCAL 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
DWORD version = GetVersion();
     phInstance = hInstance;
     if ((HIWORD(version) & 0x8000)==0)
	  is_winnt = TRUE;
     if (LOBYTE(LOWORD(version)) >= 4)
	  is_win4 = TRUE;

     if (lstrlen(lpszCmdLine))
	  silent = TRUE;

     LoadString(phInstance, IDS_TITLE, title, sizeof(title)/sizeof(TCHAR)-1);
     LoadString(phInstance, IDS_MONITORNAME, monitorname, 
	sizeof(monitorname)/sizeof(TCHAR)-1);

#ifdef BETA
     if (beta_warn())
	return 0;
#endif
     mi2.pName = monitorname;
     mi2.pEnvironment = is_winnt ? MONITORENVNT : MONITORENV95;
     mi2.pDLLName =     is_winnt ? MONITORDLLNT : MONITORDLL95 ;

     /* Check if already installed */
     if (EnumMonitors(NULL, 1, (LPBYTE)buffer, sizeof(buffer), 
	&needed, &returned)) {
	  mi = (MONITOR_INFO_1 *)buffer;
	  for (i=0; i<returned; i++) {
	  if (lstrcmp(mi[i].pName, monitorname) == 0)
	       return message(IDS_ALREADY_INSTALLED);
	   }
     }
     else
	  return message(IDS_ENUMMONITORS_FAILED);

     /* Warn user about what we are about to do */
     if (!silent) {
         TCHAR buf[256];
	 LoadString(phInstance, IDS_INTRO, buf, sizeof(buf)/sizeof(TCHAR)-1);
         if (MessageBox(HWND_DESKTOP, buf, title, MB_YESNO) != IDYES)
	     return 0;
     }

     /* copy files to Windows system directory */
     if (!GetSystemDirectory(sysdir, sizeof(sysdir)))
	  return message(IDS_NOSYSDIR);
     lstrcat(sysdir, "\\");

     /* get path to EXE */
     GetModuleFileName(hInstance, exepath, sizeof(exepath));
     if ((p = strrchr(exepath,'\\')) != (char *)NULL)
	  p++;
     else
	  p = exepath;
     *p = '\0';

     lstrcpy(destination, sysdir);
     lstrcat(destination, mi2.pDLLName);
     lstrcpy(source, exepath);
     lstrcat(source, mi2.pDLLName);
     if (!CopyFile(source, destination, FALSE))
	  return message(IDS_ERROR_COPY_DLL);
     lstrcpy(destination, sysdir);
     lstrcat(destination, MONITORHLP);
     lstrcpy(source, exepath);
     lstrcat(source, MONITORHLP);
     if (!CopyFile(source, destination, FALSE))
	  return message(IDS_ERROR_COPY_HELP);
     lstrcpy(destination, sysdir);
     lstrcat(destination, REDCONF);
     lstrcpy(source, exepath);
     lstrcat(source, REDCONF);
     if (!CopyFile(source, destination, FALSE))
         return message(IDS_ERROR_COPY_REDCONF);
     lstrcpy(destination, sysdir);
     lstrcat(destination, UNINSTALLPROG);
     lstrcpy(source, exepath);
     lstrcat(source, UNINSTALLPROG);
     if (!CopyFile(source, destination, FALSE))
	  return message(IDS_ERROR_COPY_UNINSTALL);

     if (!AddMonitor(NULL, 2, (LPBYTE)&mi2)) {
	  return message(IDS_ADDMONITOR_FAILED);
     }

     /* write registry entries for uninstall */
     if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINSTALLKEY, 0, 
	  KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS) {
	/* failed to open key, so try to create it */
        rc = RegCreateKey(HKEY_LOCAL_MACHINE, UNINSTALLKEY, &hkey);
     }
     if (rc == ERROR_SUCCESS) {
	  if (RegCreateKey(hkey, MONITORKEY, &hsubkey) == ERROR_SUCCESS) {
	       lstrcpy(buffer, title);
	       RegSetValueEx(hsubkey, DISPLAYNAMEKEY, 0, REG_SZ,
		    (CONST BYTE *)buffer, lstrlen(buffer)+1);
	       lstrcpy(buffer, sysdir);
	       lstrcat(buffer, UNINSTALLPROG);
	       RegSetValueEx(hsubkey, UNINSTALLSTRINGKEY, 0, REG_SZ,
		    (CONST BYTE *)buffer, lstrlen(buffer)+1);
	       RegCloseKey(hsubkey);
	  }
	  RegCloseKey(hkey);
     }

     /* Disable removing of uninstall program, in case someone 
      * uninstalls then installs again without rebooting Windows.
      */
     wsprintf(source, TEXT("%s%s"), sysdir, UNINSTALLPROG);
     if (is_winnt) {
#define RENAME_KEY "PendingFileRenameOperations"
	 if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
	    "SYSTEM\\CurrentControlSet\\Control\\Session Manager",
	    0, KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) {
	      DWORD dwType = REG_MULTI_SZ;
	      DWORD dwLength;
	      if ( (rc = RegQueryValueEx(hkey, RENAME_KEY, NULL, &dwType, 
		    buffer, &dwLength)) == ERROR_SUCCESS ) {
		/* look to see if unredmon.exe is mentioned */
		LPSTR p = buffer;
		LPSTR q;
		while (*p) {
		    q = p;
		    q += strlen(q) + 1;	/* skip existing name */
		    q += strlen(q) + 1;	/* skip new name */
		    if (lstrcmp(p, source) == 0) {
			MoveMemory(p, q, dwLength - (q - buffer));
			dwLength -= (q-p);
		    }
		    else
			p = q;
		}
		RegSetValueEx(hkey, RENAME_KEY, 0, dwType, 
		    buffer, dwLength); 
	      }
	 }
#undef RENAME_KEY
     }
     else {
	char ini_name[256];
	GetWindowsDirectory(ini_name, sizeof(ini_name));
	lstrcat(ini_name, "\\wininit.ini");
	GetPrivateProfileString("Rename", "NUL", "", 
	    buffer, sizeof(buffer), ini_name);
	if (lstrcmp(source, buffer) == 0) {
	    WritePrivateProfileString("Rename", "NUL", NULL, ini_name);
	}
	SetLastError(0);
     }

#ifdef UNUSED
     if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
	"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
	0, KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) {
	  RegDeleteValue(hkey, MONITORKEY);
     }
#endif

     message(IDS_INSTALL_OK);

     return 0;
}