예제 #1
0
BOOL CSetProxServer::CheckIp( ATL::CString& str )//检查IP地址是否合法
{
	LPCWSTR   lpIpString = str.GetBuffer(-1);
	str.ReleaseBuffer(-1);
	int      nStrLen = 0; 
	int      nDotCount = 0; 

	nStrLen = wcslen(lpIpString); 
	if((nStrLen > 15) || (nStrLen < 7)) 
		return FALSE; 

	for(int i=0; i < nStrLen; ++i) 
	{ 
		if( lpIpString[i] == L'.' ) 
		{ 
			if( (lpIpString[i+1] == '.') || (i==0) || (i==nStrLen-1))
				return FALSE; 
			nDotCount++; 
			continue; 
		} 

		if( (lpIpString[i] < L'0') || (lpIpString[i] > L'9') )
			return   FALSE; 
	} 

	if( nDotCount == 3) 
	{ 
		if(inet_addr(CW2A(str.GetBuffer(-1))) != INADDR_NONE) 
		{ 
			return TRUE; 
		} 
	} 

	return FALSE;
}
예제 #2
0
ATL::CString GetStringValue(CRegKey& rk, const ATL::CString& valueName)
{
	ATL::CString result;
	DWORD dwLen = 1024;
	rk.QueryStringValue(valueName, result.GetBuffer(dwLen), &dwLen);
	result.ReleaseBuffer();
	return result;
}
예제 #3
0
inline void MakeFilterString(ATL::CString& str)
{
	char *pch = str.GetBuffer();
	for(int i = 0; i < str.GetLength(); ++i)
		if(pch[i] == '|') pch[i] = '\0';
}
예제 #4
0
BOOL CSetProxServer::doApplySetting()
{
	//写配置文件	
	CIniFile IniFile(m_strFilePath);
	ATL::CString strHttp	= L"";
	int			 nType;
	ATL::CString strVerify	= L"";
	int			 nVerify;
	ATL::CString strAddr	= L"";
	ATL::CString strPort	= L"";
	int			 nPort;
	ATL::CString strAccount = L"";
	ATL::CString strPass	= L"";
	HRESULT hr;
	EM_KXE_NETPROXY_TYPE emType;
	int nIndex = m_ComBoHttp.GetCurSel();
	if ( nIndex!= -1)
	{
		int n = m_ComBoHttp.GetLBTextLen( nIndex );
		m_ComBoHttp.GetLBText( nIndex, strHttp.GetBuffer(n) );
		strHttp.ReleaseBuffer();
	}
	nIndex = m_ComBoVerify.GetCurSel();
	if (nIndex != -1)
	{
		int n = m_ComBoVerify.GetLBTextLen( nIndex );
		m_ComBoVerify.GetLBText( nIndex, strVerify.GetBuffer(n) );
		strVerify.ReleaseBuffer();
	}
	//获得地址
	m_wndEditAddr.GetWindowText(strAddr);
	//ip地址过滤
	if ((strAddr == L"" || !CheckIp(strAddr)) && m_ComBoHttp.GetCurSel() != 0)
	{
		CBkSafeMsgBox2::ShowMultLine( L"IP地址为空或者不合法,请您重新输入!", L"金山卫士",  MB_OK|MB_ICONWARNING);
		return FALSE;
	}
	
	m_wndEditPort.GetWindowText(strPort);
	//port检测
	if (strPort == L"" && m_ComBoHttp.GetCurSel() != 0)
	{
		CBkSafeMsgBox2::ShowMultLine( L"端口设置不能为空,请您重新输入!", L"金山卫士",  MB_OK|MB_ICONWARNING);
		return FALSE;
	}
	m_wndEditAccount.GetWindowText(strAccount);
	m_wndEditPass.GetWindowText(strPass);	
	nType   = readInt(strHttp);
	nVerify = readInt(strVerify);
	if (strPort == L"")
		nPort = -1;
	else
		nPort = _ttoi(strPort);
	//判断验证情况下  用户名和密码是否为空
	if (nVerify == 1)//需要验证的情况
	{
		if (strAccount == L"" || strPass == L"")
		{
			CBkSafeMsgBox2::ShowMultLine( L"用户名或者密码不能为空,请您重新输入!", L"金山卫士",  MB_OK|MB_ICONWARNING);
			return FALSE;
		}
	}
	//写配置
	if (CBkSafeMsgBox2::ShowMultLine( L"您确定要对您刚修改的配置进行保存吗?", L"金山卫士",  MB_OKCANCEL|MB_ICONWARNING) == IDOK)
	{
		//向后台进行设置
		if (nType == 0)
			emType = EM_KXE_NETPROXY_TYPE_NOPROXY;
		if (nType == 1)
			emType = EM_KXE_NETPROXY_TYPE_HTTP;
		else if (nType == 2)
			emType = EM_KXE_NETPROXY_TYPE_SOCKET5;

		std::wstring sHost(strAddr);
		std::wstring sUser(strAccount);
		std::wstring sPass(strPass);
		KXE_CLOUD_PROXY_INFO ProxInfo;
		ProxInfo.emProxyType = emType;
		ProxInfo.strProxyHost = sHost;
		ProxInfo.dwProxyPort = nPort;
		ProxInfo.strProxyUsername = sUser;
		ProxInfo.strProxyPassword = sPass;
		hr = m_kwsScanner.SetCloudProxyInfo(ProxInfo);
		if (hr != 0)//设置失败
		{
			CBkSafeMsgBox2::ShowMultLine( L"保存失败,请您重新设置?", L"金山卫士",  MB_OKCANCEL|MB_ICONWARNING);
			return FALSE;  
		}
		//后台设置成功后  再写配置文件
		IniFile.SetIntValue(TEXT("proxy"),TEXT("type"),		nType);
		IniFile.SetStrValue(TEXT("proxy"),TEXT("host"),		strAddr);
		IniFile.SetIntValue(TEXT("proxy"),TEXT("port"),		nPort);
		IniFile.SetIntValue(TEXT("proxy"),TEXT("validate"), nVerify);
		IniFile.SetStrValue(TEXT("proxy"),TEXT("user"),		strAccount);
		IniFile.SetStrValue(TEXT("proxy"),TEXT("password"), strPass);
		NotifyDownModuleProxyChange( nType, strAddr, nPort, (BOOL)nVerify, strAccount, strPass );
		GetParent().PostMessage( MSG_PROXY_CHANGE, NULL, NULL );
	}
	else
	{
		return FALSE;
	}
	
	return TRUE;
}