Example #1
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 #2
0
bool TryDecryptValue2(ForestMap & fmap, string section, string type, string & estr, bool isDecrypt)
{

	if(section.empty() || type.empty() )
		return false;

	std::set<string> encoded; 
	if(!prepareToDecryptValue(encoded,fmap,section,type,estr))
		return false;

	ForestMap::const_iterator mit= fmap.find(section);
	if(mit == fmap.end())
	{
		estr+=  "  cannot find section in fmap.  ";
		return false;
	}

	std::set<string>::iterator eit;
	string name,value,putin,strret;
	for(NodeData::const_iterator nit= mit->second.begin(); nit!=mit->second.end(); ++nit)
	{
		name= nit->first;
		value= nit->second;

		char temp1[50]={0};
		char temp2[50]={0};
		sprintf(temp1, "name = %s", name.c_str());
		myPrintLog(temp1);
		
		sprintf(temp2, "value = %s", value.c_str());
		myPrintLog(temp2);

		if(value.empty())
			continue;

		int signal(0);
		eit= encoded.find(name);
		if(eit!=encoded.end())
		{
			char temp3[50]={0};
			sprintf(temp3,"===isDecrypt = %d ===find name = %s", isDecrypt, name.c_str());
			myPrintLog(temp3);

			Des mydes;
			char out[2048]={0};
			if( isDecrypt && mydes.Decrypt( value.c_str(), out) )
			{
				myPrintLog("解密");
				strret=out; 
				char temp[50];
				sprintf(temp, "===解strret = %s", strret.c_str());
				myPrintLog(temp);
				PutReturnForestMap(fmap,section,name,strret);
			}
			if( !isDecrypt && mydes.Encrypt( value.c_str(), out) )
			{
				myPrintLog("加密");
				strret=out; 
				char temp[50];
				sprintf(temp, "===加strret = %s", strret.c_str());
				myPrintLog(temp);
				PutReturnForestMap(fmap,section,name,strret);
			}
		}
	}		

	return true;
}