⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configdialog.cpp

📁 VPN拨号程序源码(from sourceforge.net)
💻 CPP
字号:
// ConfigDialog.cpp : implementation file
//

/*******************************************************************************
 *                                                                             *
 *  This file is part of VPNDialer.                                            *
 *                                                                             *
 *  VPNDialer is free software; you can redistribute it and/or modify          *
 *  it under the terms of the GNU General Public License as published by       *
 *  the Free Software Foundation; either version 2 of the License, or          *
 *  (at your option) any later version.                                        *
 *                                                                             *
 *  VPNDialer is distributed in the hope that it will be useful,               *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 *  GNU General Public License for more details.                               *
 *                                                                             *
 *  You should have received a copy of the GNU General Public License          *
 *  along with VPNDialer; if not, write to the Free Software                   *
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  *
 *                                                                             *
 *  Copyright (c) 2003 Evidian GmbH, written by Thomas Kriener                 *
 *                                                                             *
 *******************************************************************************/

#include "stdafx.h"
#include "VPNDialer.h"
#include "VPNConfig.h"
#include "ConfigDialog.h"
#include "UT_RAS.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConfigDialog dialog


CConfigDialog::CConfigDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CConfigDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConfigDialog)
	m_useRAS = FALSE;
	m_useL2TP = FALSE;
	m_authValue = _T("");
	m_authType = 0;
	m_ipsecMode = -1;
	m_ipsecEncryption = -1;
	m_ipsecAuth = -1;
	m_ipsecPFS = FALSE;
	m_ipsecRekeyData = 0;
	m_ipsecRekeyTime = 0;
	m_destinationAny = FALSE;
	m_blockNonIPSec = FALSE;
	//}}AFX_DATA_INIT
}


void CConfigDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigDialog)
	DDX_Control(pDX, IDC_CHECK_LOCAL, m_buttonAllowLocalTraffic);
	DDX_Control(pDX, IDC_COMBO_L2TP, m_l2tpCtrl);
	DDX_Control(pDX, IDC_COMBO_RAS, m_rasCtrl);
	DDX_Control(pDX, IDC_IPADDRESS_NETWORK, m_networkCtrl);
	DDX_Control(pDX, IDC_IPADDRESS_NETMASK, m_netmaskCtrl);
	DDX_Control(pDX, IDC_IPADDRESS_GATEWAY, m_gatewayCtrl);
	DDX_Control(pDX, IDC_COMBO_CONNECTION, m_connectionCtrl);
	DDX_Check(pDX, IDC_CHECK_RAS, m_useRAS);
	DDX_Check(pDX, IDC_CHECK_L2TP, m_useL2TP);
	DDX_Text(pDX, IDC_AUTHVALUE, m_authValue);
	DDX_Radio(pDX, IDC_RADIO_PSK, m_authType);
	DDX_CBIndex(pDX, IDC_COMBO_MODE, m_ipsecMode);
	DDX_CBIndex(pDX, IDC_COMBO_ENCRYPTION, m_ipsecEncryption);
	DDX_CBIndex(pDX, IDC_COMBO_AUTHENTICATION, m_ipsecAuth);
	DDX_Check(pDX, IDC_CHECK_PFS, m_ipsecPFS);
	DDX_Text(pDX, IDC_REKEY_DATA, m_ipsecRekeyData);
	DDX_Text(pDX, IDC_REKEY_TIME, m_ipsecRekeyTime);
	DDX_Check(pDX, IDC_DESTINATION_ANY, m_destinationAny);
	DDX_Check(pDX, IDC_CHECK_BLOCKNONIPSEC, m_blockNonIPSec);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigDialog, CDialog)
	//{{AFX_MSG_MAP(CConfigDialog)
	ON_BN_CLICKED(IDC_CHECK_L2TP, OnCheckL2tp)
	ON_BN_CLICKED(IDC_CHECK_RAS, OnCheckRas)
	ON_CBN_SELCHANGE(IDC_COMBO_CONNECTION, OnSelchangeComboConnection)
	ON_BN_CLICKED(IDC_FLOPPY_BUTTON, OnFloppyButton)
	ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
	ON_BN_CLICKED(IDC_NEW_BUTTON, OnNewButton)
	ON_BN_CLICKED(IDC_DESTINATION_ANY, OnDestinationAny)
	ON_BN_CLICKED(IDC_CHECK_BLOCKNONIPSEC, OnCheckBlockNonIPSec)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigDialog message handlers

void CConfigDialog::OnCheckL2tp() 
{
	UpdateData();
	m_l2tpCtrl.SetCurSel(0);
	m_l2tpCtrl.EnableWindow(m_useL2TP);
}

void CConfigDialog::OnCheckRas() 
{
	UpdateData();
	m_rasCtrl.SetCurSel(0);
	m_rasCtrl.EnableWindow(m_useRAS);
}

void CConfigDialog::OnOK() 
{
	// Save Config
	if(m_vpnConfig->SaveConfig()!=0)
		AfxMessageBox(IDS_ERRORSAVINGCONFIG,MB_OK|MB_ICONERROR);
	
	CDialog::OnOK();
}

BOOL CConfigDialog::OnInitDialog() 
{

	CDialog::OnInitDialog();

	for(int i=0;i<m_vpnConfig->m_vpnSessions.GetSize();i++)
	{
		m_connectionCtrl.AddString(m_vpnConfig->m_vpnSessions[i].m_name);
	}

	m_connectionCtrl.SetCurSel(0);

	// Read Connections from Windows
	fillL2tpCtrl();
	fillRasCtrl();



	updateDialog();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CConfigDialog::fillL2tpCtrl()
{
	CUT_RAS      rasConfig;
	RASENTRYNAME rasEntryName;
	RASENTRY*    rasEntry;
	DWORD        size;

	m_l2tpCtrl.ResetContent();
	rasConfig.EnumEntries();
	for(int i=0;i<rasConfig.GetEntryCount();i++)
	{
		rasConfig.GetEntry(&rasEntryName,i);
		size=sizeof(RASENTRY);
        if (rasConfig.GetEntryProperties(rasEntryName.szEntryName, NULL,&size) == UTE_BUFFER_TOO_SHORT)
        {
            rasEntry = new RASENTRY[size];
            rasEntry->dwSize = size;
			
			rasConfig.GetEntryProperties(rasEntryName.szEntryName,rasEntry,&size);
			
			if(strcmp(rasEntry->szDeviceType,RASDT_Vpn)==0)
				m_l2tpCtrl.AddString(rasEntryName.szEntryName);

			delete rasEntry;
		}
			
	}
}
void CConfigDialog::fillRasCtrl()
{
	CUT_RAS      rasConfig;
	RASENTRYNAME rasEntryName;
	RASENTRY*    rasEntry;
	DWORD        size;

	m_rasCtrl.ResetContent();
	rasConfig.EnumEntries();
	for(int i=0;i<rasConfig.GetEntryCount();i++)
	{
		rasConfig.GetEntry(&rasEntryName,i);
		size=sizeof(RASENTRY);
        if (rasConfig.GetEntryProperties(rasEntryName.szEntryName, NULL,&size) == UTE_BUFFER_TOO_SHORT)
        {
            rasEntry = new RASENTRY[size];
            rasEntry->dwSize = size;
			
			rasConfig.GetEntryProperties(rasEntryName.szEntryName,rasEntry,&size);
			
			if((strcmp(rasEntry->szDeviceType,RASDT_Modem)==0)||
			   (strcmp(rasEntry->szDeviceType,RASDT_Isdn) ==0)||
			   (strcmp(rasEntry->szDeviceType,RASDT_PPPoE)==0))

				m_rasCtrl.AddString(rasEntryName.szEntryName);

			delete rasEntry;
		}
			
	}
}

void CConfigDialog::updateDialog()
{
	int i;
	BYTE ip1,ip2,ip3,ip4;

	/*
	 * Display connection
	 */
	if(m_vpnConfig->m_vpnSessions.GetSize()<=0)
		return;
	// Get active Connection
	i=m_connectionCtrl.GetCurSel();
	m_actConnection=i;

	m_vpnConfig->splitIp(m_vpnConfig->m_vpnSessions[i].m_gateway,ip1,ip2,ip3,ip4);
	m_gatewayCtrl.SetAddress(ip1,ip2,ip3,ip4);
	
	m_vpnConfig->splitIp(m_vpnConfig->m_vpnSessions[i].m_network,ip1,ip2,ip3,ip4);
	m_networkCtrl.SetAddress(ip1,ip2,ip3,ip4);

	m_vpnConfig->splitIp(m_vpnConfig->m_vpnSessions[i].m_netmask,ip1,ip2,ip3,ip4);
	m_netmaskCtrl.SetAddress(ip1,ip2,ip3,ip4);
	if(m_vpnConfig->m_vpnSessions[i].m_network=="0.0.0.0")
	{
		m_destinationAny=true;
		m_networkCtrl.EnableWindow(FALSE);
		m_netmaskCtrl.SetAddress(0,0,0,0);
		m_netmaskCtrl.EnableWindow(FALSE);
	}
	else
	{
		m_destinationAny=false;
		m_networkCtrl.EnableWindow(TRUE);
		m_netmaskCtrl.EnableWindow(TRUE);
	}

	m_authType=m_vpnConfig->m_vpnSessions[i].m_authType;
	m_authValue=m_vpnConfig->m_vpnSessions[i].m_authValue;
	m_authValue.Replace("\n","\r\n");

	m_ipsecMode=m_vpnConfig->m_vpnSessions[i].m_ipsecMode;
	m_ipsecEncryption=m_vpnConfig->m_vpnSessions[i].m_ipsecEncryption;
	m_ipsecAuth=m_vpnConfig->m_vpnSessions[i].m_ipsecAuth;
	m_ipsecPFS=m_vpnConfig->m_vpnSessions[i].m_ipsecPFS;
	m_ipsecRekeyData=m_vpnConfig->m_vpnSessions[i].m_ipsecRekeyData;
	m_ipsecRekeyTime=m_vpnConfig->m_vpnSessions[i].m_ipsecRekeyTime;


	if(m_vpnConfig->m_vpnSessions[i].m_ras!="")
	{
		m_useRAS=true;
		m_rasCtrl.SetCurSel(m_rasCtrl.FindString(0,m_vpnConfig->m_vpnSessions[i].m_ras));
	}
	else
	{
		m_useRAS=false;
	}
	m_rasCtrl.EnableWindow(m_useRAS);

	if(m_vpnConfig->m_vpnSessions[i].m_l2tp!="")
	{
		m_useL2TP=true;
		m_l2tpCtrl.SetCurSel(m_l2tpCtrl.FindString(0,m_vpnConfig->m_vpnSessions[i].m_l2tp));
	}
	else
	{
		m_useL2TP=false;
	}
	m_l2tpCtrl.EnableWindow(m_useL2TP);

	m_blockNonIPSec=m_vpnConfig->m_vpnSessions[i].m_blockNonIPSec;

	if(m_blockNonIPSec)
	{
		m_buttonAllowLocalTraffic.EnableWindow(TRUE);
		m_buttonAllowLocalTraffic.SetCheck(m_vpnConfig->m_vpnSessions[i].m_allowLocalTraffic);
	}
	else
	{
		m_buttonAllowLocalTraffic.EnableWindow(FALSE);
		m_buttonAllowLocalTraffic.SetCheck(FALSE);
	}

	UpdateData(FALSE);

}

void CConfigDialog::OnSelchangeComboConnection() 
{
	UpdateData();
	updateDialog();
}


void CConfigDialog::OnFloppyButton() 
{
	int i;
	BYTE ip1,ip2,ip3,ip4;
	CString temp;

	UpdateData();

	/*
	 * Store connection
	 */
	if(m_vpnConfig->m_vpnSessions.GetSize()<=0)
		return;
	// Get active Connection
	i=m_actConnection;

	m_gatewayCtrl.GetAddress(ip1,ip2,ip3,ip4);
	m_vpnConfig->joinIp(ip1,ip2,ip3,ip4,m_vpnConfig->m_vpnSessions[i].m_gateway);
	
	m_networkCtrl.GetAddress(ip1,ip2,ip3,ip4);
	m_vpnConfig->joinIp(ip1,ip2,ip3,ip4,m_vpnConfig->m_vpnSessions[i].m_network);

	m_netmaskCtrl.GetAddress(ip1,ip2,ip3,ip4);
	m_vpnConfig->joinIp(ip1,ip2,ip3,ip4,m_vpnConfig->m_vpnSessions[i].m_netmask);

	m_vpnConfig->m_vpnSessions[i].m_authType=m_authType;
	m_vpnConfig->m_vpnSessions[i].m_authValue=m_authValue;
	m_vpnConfig->m_vpnSessions[i].m_authValue.Replace("\r\n","\n");

	m_vpnConfig->m_vpnSessions[i].m_ipsecMode=m_ipsecMode;
	m_vpnConfig->m_vpnSessions[i].m_ipsecEncryption=m_ipsecEncryption;
	m_vpnConfig->m_vpnSessions[i].m_ipsecAuth=m_ipsecAuth;
	m_vpnConfig->m_vpnSessions[i].m_ipsecPFS=m_ipsecPFS;
	m_vpnConfig->m_vpnSessions[i].m_ipsecRekeyData=m_ipsecRekeyData;
	m_vpnConfig->m_vpnSessions[i].m_ipsecRekeyTime=m_ipsecRekeyTime;

	if(m_useRAS)
	{
		m_rasCtrl.GetWindowText(m_vpnConfig->m_vpnSessions[i].m_ras);
	}
	else
	{
		m_vpnConfig->m_vpnSessions[i].m_ras="";
	}

	if(m_useL2TP)
	{
		m_l2tpCtrl.GetWindowText(m_vpnConfig->m_vpnSessions[i].m_l2tp);
	}
	else
	{
		m_vpnConfig->m_vpnSessions[i].m_l2tp="";
	}

	m_vpnConfig->m_vpnSessions[i].m_blockNonIPSec=m_blockNonIPSec;
	m_vpnConfig->m_vpnSessions[i].m_allowLocalTraffic=m_buttonAllowLocalTraffic.GetCheck();


	// has to be the last action, so that OnSelchangeComboConnection() is called at last
	m_connectionCtrl.GetWindowText(temp);
	if(temp!=m_vpnConfig->m_vpnSessions[i].m_name)
	{
		m_vpnConfig->m_vpnSessions[i].m_name=temp;
		m_connectionCtrl.InsertString(i,m_vpnConfig->m_vpnSessions[i].m_name);
		m_connectionCtrl.DeleteString(i+1);
		m_connectionCtrl.SetCurSel(i);
	}
}

void CConfigDialog::OnDeleteButton() 
{
	int i=m_connectionCtrl.GetCurSel();

	m_connectionCtrl.DeleteString(i);
	m_vpnConfig->m_vpnSessions.RemoveAt(i);

	m_connectionCtrl.SetCurSel(0);
	updateDialog();
}

void CConfigDialog::OnNewButton() 
{
	CVPNSession newSession;
	CString tempName;
	int i=0;
	do
	{
		tempName.Format("New Session %i",i);
		i++;
	}
	while(m_connectionCtrl.FindStringExact(0,tempName)!=CB_ERR);

	m_connectionCtrl.AddString(tempName);
	newSession.m_name=tempName;
	m_connectionCtrl.SetCurSel(m_vpnConfig->m_vpnSessions.Add(newSession));

	updateDialog();
}


void CConfigDialog::OnDestinationAny() 
{
	int i;

	UpdateData();
	if(m_destinationAny)
	{
		m_networkCtrl.SetAddress(0,0,0,0);
		m_networkCtrl.EnableWindow(FALSE);
		m_netmaskCtrl.SetAddress(0,0,0,0);
		m_netmaskCtrl.EnableWindow(FALSE);
		i=m_connectionCtrl.GetCurSel();
		m_vpnConfig->m_vpnSessions[i].m_network="0.0.0.0";
		m_vpnConfig->m_vpnSessions[i].m_netmask="0.0.0.0";
	}
	else
	{
		m_networkCtrl.EnableWindow(TRUE);
		m_netmaskCtrl.EnableWindow(TRUE);
	}

	UpdateData(FALSE);
}

void CConfigDialog::OnCheckBlockNonIPSec() 
{
	UpdateData();
	if(m_blockNonIPSec)
	{
		m_buttonAllowLocalTraffic.EnableWindow(TRUE);
	}
	else
	{
		m_buttonAllowLocalTraffic.EnableWindow(FALSE);
		m_buttonAllowLocalTraffic.SetCheck(FALSE);
	}

	UpdateData(FALSE);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -