Esempio n. 1
0
BOOL CUsersDlgIpFilter::SaveUser(t_user *pUser)
{
    if (!pUser)
        return FALSE;

    UpdateData(TRUE);

    pUser->disallowedIPs.clear();
    pUser->allowedIPs.clear();

    ParseIPFilter(m_DisallowedAddresses, &pUser->disallowedIPs);
    ParseIPFilter(m_AllowedAddresses, &pUser->allowedIPs);

    return TRUE;
}
Esempio n. 2
0
CString CUsersDlgIpFilter::Validate()
{
    UpdateData(TRUE);

    if (!ParseIPFilter(m_DisallowedAddresses))
    {
        GetDlgItem(IDC_USERS_IPFILTER_DISALLOWED)->SetFocus();
        return _T("Invalid IP address/range/mask");
    }

    if (!ParseIPFilter(m_AllowedAddresses))
    {
        GetDlgItem(IDC_USERS_IPFILTER_ALLOWED)->SetFocus();
        return _T("Invalid IP address/range/mask");
    }

    return _T("");
}
Esempio n. 3
0
BOOL COptionsAdminInterfacePage::IsDataValid()
{
	USES_CONVERSION;

	if (!UpdateData(TRUE))
		return FALSE;

	if (_ttoi(m_Port) < 1 || _ttoi(m_Port) > 65535)
	{
		m_pOptionsDlg->ShowPage(this);
		GetDlgItem(IDC_OPTIONS_ADMININTERFACE_PORT)->SetFocus();
		AfxMessageBox(_T("The port for the admin interface has to be in the range from 1 to 65535."));
		return FALSE;
	}

	CString bindIPs = m_IpBindings;
	CString sub;
	std::list<CString> ipBindList;
	for (int i = 0; i<bindIPs.GetLength(); i++)
	{
		TCHAR cur = bindIPs[i];
		if ((cur < '0' || cur > '9') && cur != '.')
		{
			if (sub == _T("") && cur == '*')
			{
				ipBindList.clear();
				ipBindList.push_back(_T("*"));
				break;
			}

			if (sub != _T(""))
			{
				//Parse IP
				SOCKADDR_IN sockAddr{};
				sockAddr.sin_family = AF_INET;
				sockAddr.sin_addr.s_addr = inet_addr(T2A(sub));

				if (sockAddr.sin_addr.s_addr != INADDR_NONE) {
					sub = inet_ntoa(sockAddr.sin_addr);
					std::list<CString>::iterator iter;
					for (iter = ipBindList.begin(); iter != ipBindList.end(); ++iter)
						if (*iter == sub)
							break;
					if (iter == ipBindList.end())
						ipBindList.push_back(sub);
				}
				sub = _T("");
			}
		}
		else
			sub += cur;
	}
	if (!sub.IsEmpty()) {
		//Parse IP
		SOCKADDR_IN sockAddr{};
		sockAddr.sin_family = AF_INET;
		sockAddr.sin_addr.s_addr = inet_addr(T2A(sub));

		if (sockAddr.sin_addr.s_addr != INADDR_NONE) {
			sub = inet_ntoa(sockAddr.sin_addr);
			std::list<CString>::iterator iter;
			for (iter = ipBindList.begin(); iter != ipBindList.end(); ++iter)
				if (*iter==sub)
					break;
			if (iter == ipBindList.end())
				ipBindList.push_back(sub);
		}
		sub = _T("");
	}
	bindIPs = _T("");
	for (std::list<CString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); ++iter)
		if (*iter != _T("127.0.0.1"))
			bindIPs += *iter + _T(" ");

	bindIPs.TrimRight(_T(" "));
	m_IpBindingsResult = bindIPs;

	if (!ParseIPFilter(m_IpAddresses))
	{
		GetDlgItem(IDC_OPTIONS_ADMININTERFACE_IPADDRESSES)->SetFocus();
		AfxMessageBox(_T("Invalid IP address/range/mask"));
		return FALSE;
	}

	if (m_bChangePass)
	{
		if (m_NewPass == _T("") && m_NewPass2 == _T(""))
			return TRUE;
		if (m_NewPass.GetLength() < 6)
		{
			m_pOptionsDlg->ShowPage(this);
			GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
			AfxMessageBox(_T("The admin password has to be at least 6 characters long,"));
			return FALSE;
		}
		if (m_NewPass != m_NewPass2)
		{
			m_pOptionsDlg->ShowPage(this);
			GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
			AfxMessageBox(_T("Admin passwords do not match."));
			return FALSE;
		}
	}
	return TRUE;
}