vpndialer.cpp
来自「VPN拨号程序源码(from sourceforge.net)」· C++ 代码 · 共 268 行
CPP
268 行
// VPNDialer.cpp : Defines the class behaviors for the application.
//
/*******************************************************************************
* *
* 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 "VPNDialerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVPNDialerApp
BEGIN_MESSAGE_MAP(CVPNDialerApp, CWinApp)
//{{AFX_MSG_MAP(CVPNDialerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVPNDialerApp construction
CVPNDialerApp::CVPNDialerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CVPNDialerApp object
CVPNDialerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CVPNDialerApp initialization
BOOL CVPNDialerApp::InitInstance()
{
/* Test if we are already running, if so stop */
#ifdef WIN32
CreateMutex (NULL, FALSE, "VPNDIALER") ;
if (GetLastError () == ERROR_ALREADY_EXISTS)
return FALSE;
#endif
// First we see if there is a winsock ver 2.2 installed on the computer,
// we initizalize the sockets DLL for out app.
WSADATA data;
if (WSAStartup(MAKEWORD(2, 2), &data) != 0)
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED,MB_OK|MB_ICONERROR);
return(-1);
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
/*
* End if Prerequisits not met
*/
if(CheckPrerequisits()!=0)
{
AfxMessageBox("Prerequisits not met, exiting!",MB_OK|MB_ICONERROR);
// Clean Winsock
WSACleanup();
return FALSE;
}
#ifdef _DEBUG
AfxMessageBox("Prerequisits met!",MB_OK|MB_ICONINFORMATION);
#endif
CVPNDialerDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Clean Winsock
WSACleanup();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CVPNDialerApp::CheckPrerequisits()
{
HKEY hKey;
DWORD valueSize;
DWORD valueType;
LONG regRetVal;
int intValue;
int i=0;
CString temp,temp2;
temp=CVPNConfig::GetIPSecTool();
if(temp=="")
{
AfxMessageBox("Unsupported Windows-Version!",MB_OK|MB_ICONERROR);
return 1;
}
if(CVPNConfig::ExecuteCmd(temp,temp2)!=0)
{
temp+=" not found";
AfxMessageBox(temp,MB_OK|MB_ICONERROR);
return 1;
}
// check Registry-Settings
regRetVal=RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters",
0,
KEY_QUERY_VALUE,
&hKey);
if(regRetVal==ERROR_SUCCESS)
{
// ProhibitIpSec
valueType=REG_DWORD;
valueSize=sizeof(intValue);
if(RegQueryValueEx(hKey,
"ProhibitIpSec",
NULL,
&valueType,
(LPBYTE)&intValue,
&valueSize)==ERROR_SUCCESS)
{
if(intValue!=1)
{
temp="HKLM\\SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters\\ProhibitIpSec not set correctly.\r\n";
temp+="L2TP-Tunnels will not work.\r\n";
temp+="Should I try to fix it ?";
if(AfxMessageBox(temp,MB_YESNO|MB_ICONINFORMATION)==IDYES)
{
if(CreateProhibitIpSec()!=0)
{
AfxMessageBox("Unable to set Key",MB_OK|MB_ICONERROR);
return 2;
}
else
{
AfxMessageBox("You need to reboot your System",MB_OK|MB_ICONINFORMATION);
return 2;
}
}
return 0;
}
}
else
{
temp="HKLM\\SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters\\ProhibitIpSec does not exist\r\n";
temp+="L2TP-Tunnels will not work.";
temp+="Should I try to fix it ?";
if(AfxMessageBox(temp,MB_YESNO|MB_ICONINFORMATION)==IDYES)
{
if(CreateProhibitIpSec()!=0)
{
AfxMessageBox("Unable to create Key",MB_OK|MB_ICONERROR);
return 3;
}
else
{
AfxMessageBox("You need to reboot your System",MB_OK|MB_ICONINFORMATION);
return 2;
}
}
return 0;
}
// Close Session-Key
RegCloseKey(hKey);
}
else
{
AfxMessageBox("Unexpected Error: Unable to open HKLM\\SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters",MB_OK|MB_ICONERROR);
return 4;
}
return 0;
}
int CVPNDialerApp::CreateProhibitIpSec()
{
HKEY hKey;
DWORD valueSize;
DWORD valueType;
int intValue;
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters",
0,
"CLASS",
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey,
NULL)==ERROR_SUCCESS)
{
// ProhibitIpSec
valueType=REG_DWORD;
valueSize=sizeof(intValue);
intValue=1;
if(RegSetValueEx(hKey,
"ProhibitIpSec",
NULL,
valueType,
(LPBYTE)&intValue,
valueSize)!=ERROR_SUCCESS)
{
return 1;
}
RegCloseKey(hKey);
}
else
return 1;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?