Exemplo n.º 1
0
bool MakeRunParamStringByID(std::list<string> & lrun, const string & entityID, string entityTplId="")
{
	string szRun(""), szDeviceType(entityTplId);
	MAPNODE mainnode;
	if(entityTplId.empty())
	{
		OBJECT objDevice = Cache_GetEntity(entityID);
		if(objDevice == INVALID_VALUE)
			return false;

		mainnode = GetEntityMainAttribNode(objDevice);
		if(mainnode == INVALID_VALUE)
			return false;
		szDeviceType.clear();
		if(!FindNodeValue(mainnode, "sv_devicetype", szDeviceType))
			return false;
	}

	map<string, string, less<string> > lsDeviceParam;
	OBJECT objDeviceTmp = Cache_GetEntityTemplet(szDeviceType);
	if(objDeviceTmp != INVALID_VALUE)
	{
		LISTITEM lsItem;
		if( FindETContrlFirst(objDeviceTmp, lsItem))
		{
			MAPNODE objNode;
			while( (objNode = FindNext(lsItem)) != INVALID_VALUE )
			{
				string szName (""), szRun ("");
				string szType ("");
				// 得到参数名称,是否是必要参数,以及数据类型
				FindNodeValue(objNode, "sv_name",	szName);
				FindNodeValue(objNode, "sv_run",	szRun);
				FindNodeValue(objNode, "sv_type",	szType);
				if(szRun == "true")
					lsDeviceParam[szName] = szType;
			}
		}
	}

	// 在当前设备中枚举每一个必要运行参数
	map<string, string, less<string> >::iterator lstItem;
	for(lstItem = lsDeviceParam.begin(); lstItem != lsDeviceParam.end(); lstItem ++)
	{
		string szValue ("");
		FindNodeValue(mainnode, (lstItem->first), szValue);
		if((lstItem->second).compare("password") == 0)
		{
			char szOutput[2048] = {0};
			Des des;
			if(des.Decrypt(szValue.c_str(), szOutput))
				szValue = szOutput;
		}
		//szValue = url_Encode(szValue.c_str());
		szRun = (lstItem->first) + "=" + szValue;
		lrun.push_back(szRun);
	}
	return true;
}
Exemplo n.º 2
0
int main(int argc, char **argv){

    clock_t start;
    double dur;

    start = clock();
    Des *d = new Des(argv[2]);

    // check for proper input
    if(argc == 3) {

        if(!strcmp(argv[1], E_FLAG)) d->run('e');
        else if(!strcmp(argv[1], D_FLAG)) d->run('d');
        else cout << "Invalid input. Refere to README." << endl;
    }
    else {
        cout << "Invalid input. Refer to README." << endl;
    }

    dur = (clock() - start) / (double) CLOCKS_PER_SEC;
    cout << "Execution time: " << dur << endl;
    return 0;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
BOOL AcceptPrintf(char * pidEventName)
{
	char **initialEnv = environ;
	SYSTEMTIME mytime;

	//read from register to obtain ECC web root path, usually:  c:\siteview\siteview ecc\fcg-bin
	std::string szPath = GetSiteViewRootPath();
	szPath += "\\data\\svdbconfig.ini";

	INIFile theINI = LoadIni(szPath.c_str());

	//set language code (English or Chinese)
	std::string szTSec = GetIniSetting(theINI, "svdb", "DefaultLanguage");
	szTSec += "_code";
	std::string m_code = GetIniSetting(theINI, "svdb", szTSec.c_str());

	//WriteLog("before accept");
	if(FCGI_Accept()>=0)
	{

		char  wcookie[256];
		char *qrystr;
		char  *p;
		int   nSvsid;
		

		//char szWrite[256];

		char ** myenviron;
		myenviron =FCGI_GetEnv();
	
		char myenviron1[4096]={0};

		
		for(int i=0 ;myenviron[i];++i)
		{
			strcpy(myenviron1,myenviron[i]);
			putenv(myenviron[i]);
		}

		//check if the remoteIP is allowed to log into the system
		std::string strAcceptIp;
		strAcceptIp = GetIniFileString("IPCheck","IPAddress","", "general.ini");
		int nIsChecked;
		nIsChecked = GetIniFileInt("IPCheck","isCheck",0, "general.ini");
		char *ca,*cb,*cc;
		char *szAcceptIp;
		int nSize;
		

		char *remoteip=NULL;
		remoteip = getenv("REMOTE_ADDR");
		OutputDebugString(remoteip);
		OutputDebugString("\n");
		
		bool bAccept =false;
		nSize = static_cast<int>(strAcceptIp.size());

		if( (nIsChecked==1)&&(nSize>0)&&(remoteip!=NULL) )
		{
			
			szAcceptIp = new char[nSize+1];
			memset(szAcceptIp,0,nSize);
			strcpy(szAcceptIp,strAcceptIp.c_str());
			
			//remoteip = "192.168.5.6";
			//remoteip = "127.0.0.1";
			if(strcmp(remoteip,"127.0.0.1")!=0)
			{
				ca =szAcceptIp;
				//cb =szAcceptIp;
				//cc =szAcceptIp;
				while(ca)
				{
					cb= strchr(ca,',');
					if(cb)
							*cb=0;
					cc= strchr(ca,'*');
					if(cc)
							*cc=0;
					if(strstr(remoteip,ca) !=NULL)
					{
						bAccept= true;
					}
					if(!cb||bAccept==true)
						break;
					if(cb)
						ca=cb+1;
				}

			}else bAccept= true;
			delete(szAcceptIp);
		}
		else bAccept =true;//no need to check IP

			
		//Get方式
		qrystr=getenv("HTTP_COOKIE");
		nSvsid =0;
		if(qrystr)
		{
			if(strlen(qrystr)>0)
			{
				sprintf(wcookie,"%s",qrystr);
				p=strstr(wcookie,"svsid=");
				if(p!=NULL)
				{
					sscanf(p,"svsid=%d",&nSvsid);
				}
			}
		}

		if(nSvsid==0)
			nSvsid =GetCurrentProcessId();
		//Post方式
		string strPost = FuncGetDataByPostMethod();
		
		WriteLog("poststring:\n");
		WriteLog(strPost.c_str());

		//取值 
#if 1
		CSVQueryString strQuery(strPost.c_str());
		string strAccountVlaue;
		string strPwdVlaue ;
		
		#ifdef ShanTou
			strAccountVlaue= strQuery.Get_KeyValue("Account");
			strPwdVlaue = strQuery.Get_KeyValue("Password");
			strIsEipVlaue = strQuery.Get_KeyValue("IsEip");
		#else
			strAccountVlaue= strQuery.Get_KeyValue("Account");
			strPwdVlaue = strQuery.Get_KeyValue("Password");
		#endif

#else
		string strAccountVlaue="admin";
		string strPwdVlaue  ="1111" ;
#endif
		
		string str = "";
		//验证
		char strUserId[20];
		if((bAccept==false) || !IsLogin(strAccountVlaue.c_str(), strPwdVlaue.c_str(),strUserId))
		{//用户名/密码认证失败
			//标准头
			printf("Content-type: text/html charset=gb2312 \r\n");
			printf("Content-Language: zh-CN\r\n");
			printf("Set-Cookie: svsid=%d\r\n" ,nSvsid   );
			printf("\r\n");			
			if(strIsEipVlaue == "true")
			{
				printf("User Account Or Passsword is Error!");
			}
			else
			{
				printf("nameerror");
			}

			return FALSE;

		}
		else //用户名/密码登陆成功
		{
			SafeDog pSafeDog;

			bool IsDogExit=false;
			if(pSafeDog.DogOnUsb(IsDogExit) == 0)
			{
				if(IsDogExit == true)
				{//加密狗认证失败
					TTime mStopTime;
					if(pSafeDog.GetStopTime(mStopTime) == 0 )
					{
						TTime mNowTime;
						mNowTime = TTime::GetCurrentTimeEx();	
						
						if(mStopTime < mNowTime)
						{//过期了
							//标准头
							printf("Content-type: text/html charset=gb2312 \r\n");
							printf("Content-Language: zh-CN\r\n");
							printf("Set-Cookie: svsid=%d\r\n" ,nSvsid   );
							printf("\r\n");

							if(strIsEipVlaue == "true")
							{
								printf("System Is OverDue!");
							}
							else
							{
								printf("sysout");
							}
							
							return FALSE;
						}
					}
					else
					{
						Des OneDes;
						char strDes[1024]={0};
						std::string strDataNum = GetIniFileString("license", "starttime", "",  "general.ini");
						if(strDataNum.size()>0)
						{
							if( OneDes.Decrypt(strDataNum.c_str(),strDes) )
							{
								strDataNum=strDes;
								if(!strDataNum.empty())
								{
									std::string LastData = GetIniFileString("license", "lasttime", "",  "general.ini");
									if(!LastData.empty())
									{
										if( OneDes.Decrypt(LastData.c_str(),strDes) )
										{
											LastData=strDes;
											TTime mStopTime(atoi(strDataNum.substr(0,4).c_str()),atoi(strDataNum.substr(5,2).c_str()),atoi(strDataNum.substr(8,2).c_str()),0,0,0);
											TTimeSpan AddData(atoi(LastData.c_str()),0,0,0);
											mStopTime += AddData;

											TTime mNowTime;
											mNowTime = TTime::GetCurrentTimeEx();	
											
											if(mStopTime < mNowTime)
											{
												//标准头
												printf("Content-type: text/html charset=gb2312 \r\n");
												printf("Content-Language: zh-CN\r\n");
												printf("Set-Cookie: svsid=%d\r\n" ,nSvsid   );
												printf("\r\n");
												if(strIsEipVlaue == "true")
												{
													printf("System Is OverDue!");
												}
												else
												{
													printf("sysout");
												}
												return FALSE;
											}
										}
									}
								}
							}		
						}
					}		
				}
				IsDogExit=false;
			}
			else
			{
				Des OneDes;
				char strDes[1024]={0};
				std::string strDataNum = GetIniFileString("license", "starttime", "",  "general.ini");

				if(strDataNum.size()>0)
				{
					if( OneDes.Decrypt(strDataNum.c_str(),strDes) )
					{
						strDataNum=strDes;
						if(!strDataNum.empty())
						{
							std::string LastData = GetIniFileString("license", "lasttime", "",  "general.ini");

							if(!LastData.empty())
							{
								if( OneDes.Decrypt(LastData.c_str(),strDes) )
								{
									LastData=strDes;
                                    int nYear = 0, nMonth = 0, nDay = 0, nHour = 0, nMin = 0, nSec = 0;
									sscanf(strDataNum.c_str(), "%d-%d-%d", &nYear, &nMonth, &nDay);
									char buf[100]={0};
									sprintf(buf,"year:%d,mouth:%d,day:%d\n",nYear,nMonth,nDay);

									TTime mStopTime(nYear, nMonth, nDay, 0,0,0);
								   
    							    TTimeSpan AddData(atoi(LastData.c_str()),0,0,0);
									mStopTime += AddData;

									TTime mNowTime;
									mNowTime = TTime::GetCurrentTimeEx();	
									
									if(mStopTime < mNowTime)
									{
										//标准头
										printf("Content-type: text/html charset=gb2312 \r\n");
										printf("Content-Language: zh-CN\r\n");
										printf("Set-Cookie: svsid=%d\r\n" ,nSvsid   );
										printf("\r\n");
										if(strIsEipVlaue == "true")
										{
											printf("System Is OverDue!");
										}
										else
										{
											printf("sysout");
										}
										return FALSE;
									}
								}
							}
						}
					}
				}
			}
			
			//登陆成功
			printf("Content-type: text/html\r\n");
			printf("Set-Cookie: svsid=%d\r\n" ,nSvsid );
			#ifdef IDC_Version			
				string strIdcUserId = GetIniFileString(strUserId, "IdcUserId", "", "idcuser.ini");	
				printf("Set-Cookie: idcuserid=%s\r\n" ,strIdcUserId.c_str());
			#endif	
			printf("Set-Cookie: userid=%s\r\n" ,strUserId);

			printf("\r\n");

			if(strIsEipVlaue == "true")
			{
				printf("<script type='text/javascript'>");
				printf("location.replace(\"/fcgi-bin/showhtm.cgi?nav.htm\")");
				printf("</script>");		
			}
			else
			{
				printf("true");
			}
			
		}

		FCGI_Finish();
		
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
Exemplo n.º 6
0
//验证用户
bool IsLogin(string strAccount, string strPwd,char* strUserId)
{
	OutputDebugString("IsLogin");
	OutputDebugString("\n");

	WriteLog("IsLogin");
	WriteLog("\n");
	//去空格
	strAccount.erase(strAccount.begin(),strAccount.begin() + strAccount.find_first_not_of('+'));
	strAccount.erase(strAccount.begin(),strAccount.begin() + strAccount.find_first_not_of(' '));
	strAccount.erase(strAccount.begin() + strAccount.find_last_not_of('+') + 1,strAccount.end());
	strAccount.erase(strAccount.begin() + strAccount.find_last_not_of(' ') + 1,strAccount.end());
	
	//转换成小写
	transform(strAccount.begin(),strAccount.end(),strAccount.begin(),(int(*)(int))tolower);	

	if(strAccount == "" && strPwd == "")
		return false;

	std::list<string> keylist;
	std::list<string>::iterator keyitem;
	string strUserName, strUserPwd;
	bool bExist = false;
	//从ini获取用户列表
	#ifdef IDC_Version
		if(GetIniFileSections(keylist, "idcuser.ini"))
	#else
		if(GetIniFileSections(keylist, "user.ini"))
	#endif
	{
		//从ini初始化用户列表
		for(keyitem = keylist.begin(); keyitem != keylist.end(); keyitem ++)	
		{
			//从ini读数据			
			#ifdef IDC_Version
				strUserName = GetIniFileString((*keyitem), "LoginName", "", "idcuser.ini");
			#else
				strUserName = GetIniFileString((*keyitem), "LoginName", "", "user.ini");
			#endif

			
			//转换成小写
			transform(strUserName.begin(),strUserName.end(),strUserName.begin(),(int(*)(int))tolower);
			#ifdef IDC_Version
				strUserPwd = GetIniFileString((*keyitem), "Password", "", "idcuser.ini");	
			#else
				strUserPwd = GetIniFileString((*keyitem), "Password", "", "user.ini");	
			#endif
			
			Des mydes;
			char dechar[1024]={0};
			if(strPwd.size()>0)
			{
				mydes.Decrypt(strUserPwd.c_str(),dechar);
				strUserPwd =  dechar;
			}
			
		//汕头版本 用MD5解密strUserPwd
		#ifdef ShanTou
			if(strIsEipVlaue == "true")
			{

				//OutputDebugString(strUserPwd.c_str());	
				//OutputDebugString("\n");
				
				WriteLog(strUserPwd.c_str());	
				WriteLog("\n");
				
				string strTmpPwd = strUserPwd;
				//strTmpPwd = "test";

				int ilen = strTmpPwd.length();
				unsigned char output[16];
				MD5(output, (const unsigned char *)strTmpPwd.c_str(), ilen);
				
				strUserPwd = "";

				//strPwd = output;			
				//strUserPwd.append((char*)output);
				//OutputDebugString((char*)output);

				char tmpbuf[2];
				for(int i =0; i< 16;i++)
				{
					sprintf(tmpbuf, "%02x", output[i]);										
					//WriteLog((char*)tmpbuf);
					strUserPwd.append((char*)tmpbuf);
				}			
				
				for(int i=0;i<strUserPwd.length();i++)
				{
					strUserPwd[i]=toupper(strUserPwd[i]);
				}
				//OutputDebugString(strUserPwd.c_str());
				//OutputDebugString("\n");
				WriteLog(strUserPwd.c_str());	
				WriteLog("\n");

			}
			else
			{
			
			}				
			if(strUserName == strAccount && strUserPwd == strPwd)
		#else
			if(strUserName == strAccount && strUserPwd == strPwd)
		#endif
			{
				//是否禁用?...
			#ifdef IDC_Version
				int nIsUse = GetIniFileInt((*keyitem), "nIsUse", -1, "idcuser.ini");
			#else
				int nIsUse = GetIniFileInt((*keyitem), "nIsUse", -1, "user.ini");
			#endif
				
				if(nIsUse == -1)
				{
					//禁用
					bExist = false;
				}
				else
				{
					//可用
					bExist = true;
					sprintf(strUserId,"%s",keyitem->c_str());
					//strUserId=keyitem->c_str();
				}

				//bExist = true;
				break;
			}
		}
	}

	return bExist;	
}