vncproperties.cpp
来自「这是一个比较复杂的远程控制工具,分为服务器与客户斋,让你了解socket编程的知」· C++ 代码 · 共 1,652 行 · 第 1/4 页
CPP
1,652 行
// Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
// Copyright (C) 2000-2002 Const Kaplinsky. All Rights Reserved.
// Copyright (C) 2002 TightVNC. All Rights Reserved.
// Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of the VNC system.
//
// The VNC system 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
// vncProperties.cpp
// Implementation of the Properties dialog!
#include "stdhdrs.h"
#include "lmcons.h"
#include "vncService.h"
#include "WinVNC.h"
#include "vncProperties.h"
#include "vncServer.h"
#include "vncPasswd.h"
#include "vncOSVersion.h"
#include "localization.h" // ACT : Add localization on messages
//extern HINSTANCE g_hInst;
bool RunningAsAdministrator ();
const char WINVNC_REGISTRY_KEY [] = "Software\\ORL\\WinVNC3";
// Marscha@2004 - authSSP: Function pointer for dyn. linking
typedef void (*vncEditSecurityFn) (HWND hwnd, HINSTANCE hInstance);
vncEditSecurityFn vncEditSecurity = 0;
// Constructor & Destructor
vncProperties::vncProperties()
{
m_alloweditclients = TRUE;
m_allowproperties = TRUE;
m_allowshutdown = TRUE;
m_dlgvisible = FALSE;
m_usersettings = TRUE;
Lock_service_helper=true;
}
vncProperties::~vncProperties()
{
}
// Initialisation
BOOL
vncProperties::Init(vncServer *server)
{
// Save the server pointer
m_server = server;
// Load the settings from the registry
Load(TRUE);
// If the password is empty then always show a dialog
char passwd[MAXPWLEN];
m_server->GetPassword(passwd);
{
vncPasswd::ToText plain(passwd);
if (strlen(plain) == 0)
if (!m_allowproperties || !RunningAsAdministrator ()) {
if(m_server->AuthRequired()) {
MessageBox(NULL, sz_ID_NO_PASSWD_NO_OVERRIDE_ERR,
sz_ID_WINVNC_ERROR,
MB_OK | MB_ICONSTOP);
PostQuitMessage(0);
} else {
MessageBox(NULL, sz_ID_NO_PASSWD_NO_OVERRIDE_WARN,
sz_ID_WINVNC_ERROR,
MB_OK | MB_ICONEXCLAMATION);
}
} else {
// If null passwords are not allowed, ensure that one is entered!
if (m_server->AuthRequired()) {
char username[UNLEN+1];
if (!vncService::CurrentUser(username, sizeof(username)))
return FALSE;
if (strcmp(username, "") == 0) {
Lock_service_helper=true;
MessageBox(NULL, sz_ID_NO_PASSWD_NO_LOGON_WARN,
sz_ID_WINVNC_ERROR,
MB_OK | MB_ICONEXCLAMATION);
ShowAdmin(TRUE, FALSE);
Lock_service_helper=false;
} else {
ShowAdmin(TRUE, TRUE);
}
}
}
}
Lock_service_helper=false;
return TRUE;
}
// Dialog box handling functions
void
vncProperties::ShowAdmin(BOOL show, BOOL usersettings)
{
// if (Lock_service_helper) return;
if (!m_allowproperties) return;
if (!RunningAsAdministrator ()) return;
if (vncService::RunningAsService()) usersettings=false;
m_usersettings=usersettings;
if (show)
{
// Verify that we know who is logged on
if (usersettings) {
char username[UNLEN+1];
if (!vncService::CurrentUser(username, sizeof(username)))
return;
if (strcmp(username, "") == 0) {
MessageBox(NULL, sz_ID_NO_CURRENT_USER_ERR, sz_ID_WINVNC_ERROR, MB_OK | MB_ICONEXCLAMATION);
return;
}
} else {
// We're trying to edit the default local settings - verify that we can
HKEY hkLocal, hkDefault;
BOOL canEditDefaultPrefs = 1;
DWORD dw;
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
WINVNC_REGISTRY_KEY,
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS)
canEditDefaultPrefs = 0;
else if (RegCreateKeyEx(hkLocal,
"Default",
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ, NULL, &hkDefault, &dw) != ERROR_SUCCESS)
canEditDefaultPrefs = 0;
if (hkLocal) RegCloseKey(hkLocal);
if (hkDefault) RegCloseKey(hkDefault);
if (!canEditDefaultPrefs) {
MessageBox(NULL, sz_ID_CANNOT_EDIT_DEFAULT_PREFS, sz_ID_WINVNC_ERROR, MB_OK | MB_ICONEXCLAMATION);
return;
}
}
// Now, if the dialog is not already displayed, show it!
if (!m_dlgvisible)
{
if (usersettings)
vnclog.Print(LL_INTINFO, VNCLOG("show per-user Properties\n"));
else
vnclog.Print(LL_INTINFO, VNCLOG("show default system Properties\n"));
// Load in the settings relevant to the user or system
//Load(usersettings);
m_usersettings=usersettings;
for (;;)
{
m_returncode_valid = FALSE;
// Do the dialog box
int result = DialogBoxParam(hAppInstance,
MAKEINTRESOURCE(IDD_PROPERTIES1),
NULL,
(DLGPROC) DialogProc,
(LONG) this);
if (!m_returncode_valid)
result = IDCANCEL;
vnclog.Print(LL_INTINFO, VNCLOG("dialog result = %d\n"), result);
if (result == -1)
{
// Dialog box failed, so quit
PostQuitMessage(0);
return;
}
// We're allowed to exit if the password is not empty
char passwd[MAXPWLEN];
m_server->GetPassword(passwd);
{
vncPasswd::ToText plain(passwd);
if ((strlen(plain) != 0) || !m_server->AuthRequired())
break;
}
vnclog.Print(LL_INTERR, VNCLOG("warning - empty password\n"));
// The password is empty, so if OK was used then redisplay the box,
// otherwise, if CANCEL was used, close down WinVNC
if (result == IDCANCEL)
{
vnclog.Print(LL_INTERR, VNCLOG("no password - QUITTING\n"));
PostQuitMessage(0);
return;
}
// If we reached here then OK was used & there is no password!
int result2 = MessageBox(NULL, sz_ID_NO_PASSWORD_WARN,
sz_ID_WINVNC_WARNIN, MB_OK | MB_ICONEXCLAMATION);
omni_thread::sleep(4);
}
// Load in all the settings
Load(TRUE);
}
}
}
BOOL CALLBACK
vncProperties::DialogProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{
// We use the dialog-box's USERDATA to store a _this pointer
// This is set only once WM_INITDIALOG has been recieved, though!
vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
switch (uMsg)
{
case WM_INITDIALOG:
{
vnclog.Print(LL_INTINFO, VNCLOG("sINITDOALOG properties\n"));
// Retrieve the Dialog box parameter and use it as a pointer
// to the calling vncProperties object
SetWindowLong(hwnd, GWL_USERDATA, lParam);
_this = (vncProperties *) lParam;
_this->Load(_this->m_usersettings);
_this->m_dlgvisible = TRUE;
// Set the dialog box's title to indicate which Properties we're editting
if (_this->m_usersettings) {
SetWindowText(hwnd, sz_ID_CURRENT_USER_PROP);
} else {
SetWindowText(hwnd, sz_ID_DEFAULT_SYST_PROP);
}
// Initialise the properties controls
HWND hConnectSock = GetDlgItem(hwnd, IDC_CONNECT_SOCK);
// Tight 1.2.7 method
BOOL bConnectSock = _this->m_server->SockConnected();
SendMessage(hConnectSock, BM_SETCHECK, bConnectSock, 0);
// Set the content of the password field to a predefined string.
SetDlgItemText(hwnd, IDC_PASSWORD, "~~~~~~~~");
EnableWindow(GetDlgItem(hwnd, IDC_PASSWORD), bConnectSock);
// Set the initial keyboard focus
if (bConnectSock)
{
SetFocus(GetDlgItem(hwnd, IDC_PASSWORD));
SendDlgItemMessage(hwnd, IDC_PASSWORD, EM_SETSEL, 0, (LPARAM)-1);
}
else
SetFocus(hConnectSock);
// Set display/ports settings
_this->InitPortSettings(hwnd);
HWND hConnectHTTP = GetDlgItem(hwnd, IDC_CONNECT_HTTP);
SendMessage(hConnectHTTP,
BM_SETCHECK,
_this->m_server->HTTPConnectEnabled(),
0);
HWND hConnectXDMCP = GetDlgItem(hwnd, IDC_CONNECT_XDMCP);
SendMessage(hConnectXDMCP,
BM_SETCHECK,
_this->m_server->XDMCPConnectEnabled(),
0);
// Modif sf@2002
HWND hSingleWindow = GetDlgItem(hwnd, IDC_SINGLE_WINDOW);
SendMessage(hSingleWindow, BM_SETCHECK, _this->m_server->SingleWindow(), 0);
// handler to get window name
HWND hWindowName = GetDlgItem(hwnd, IDC_NAME_APPLI);
if ( _this->m_server->GetWindowName() != NULL)
{
SetDlgItemText(hwnd, IDC_NAME_APPLI,_this->m_server->GetWindowName());
}
EnableWindow(hWindowName, _this->m_server->SingleWindow());
// Modif sf@2002 - v1.1.0
HWND hFileTransfer = GetDlgItem(hwnd, IDC_FILETRANSFER);
SendMessage(hFileTransfer, BM_SETCHECK, _this->m_server->FileTransferEnabled(), 0);
HWND hFileTransferUserImp = GetDlgItem(hwnd, IDC_FTUSERIMPERSONATION_CHECK);
SendMessage(hFileTransferUserImp, BM_SETCHECK, _this->m_server->FTUserImpersonation(), 0);
HWND hBlank = GetDlgItem(hwnd, IDC_BLANK);
SendMessage(hBlank, BM_SETCHECK, _this->m_server->BlankMonitorEnabled(), 0);
HWND hAlpha = GetDlgItem(hwnd, IDC_ALPHA);
SendMessage(hAlpha, BM_SETCHECK, _this->m_server->CaptureAlphaBlending(), 0);
HWND hAlphab = GetDlgItem(hwnd, IDC_ALPHABLACK);
SendMessage(hAlphab, BM_SETCHECK, _this->m_server->BlackAlphaBlending(), 0);
HWND hLoopback = GetDlgItem(hwnd, IDC_ALLOWLOOPBACK);
BOOL fLoopback = _this->m_server->LoopbackOk();
SendMessage(hLoopback, BM_SETCHECK, fLoopback, 0);
HWND hLoopbackonly = GetDlgItem(hwnd, IDC_LOOPBACKONLY);
BOOL fLoopbackonly = _this->m_server->LoopbackOnly();
SendMessage(hLoopbackonly, BM_SETCHECK, fLoopbackonly, 0);
HWND hTrayicon = GetDlgItem(hwnd, IDC_DISABLETRAY);
BOOL fTrayicon = _this->m_server->GetDisableTrayIcon();
SendMessage(hTrayicon, BM_SETCHECK, fTrayicon, 0);
HWND hAllowshutdown = GetDlgItem(hwnd, IDC_ALLOWSHUTDOWN);
SendMessage(hAllowshutdown, BM_SETCHECK, !_this->m_allowshutdown , 0);
HWND hm_alloweditclients = GetDlgItem(hwnd, IDC_ALLOWEDITCLIENTS);
SendMessage(hm_alloweditclients, BM_SETCHECK, !_this->m_alloweditclients , 0);
_this->m_server->SetAllowEditClients(_this->m_alloweditclients);
if (vnclog.GetMode() >= 2)
CheckDlgButton(hwnd, IDC_LOG, BST_CHECKED);
else
CheckDlgButton(hwnd, IDC_LOG, BST_UNCHECKED);
// Marscha@2004 - authSSP: moved MS-Logon checkbox back to admin props page
// added New MS-Logon checkbox
// only enable New MS-Logon checkbox and Configure MS-Logon groups when MS-Logon
// is checked.
HWND hMSLogon = GetDlgItem(hwnd, IDC_MSLOGON_CHECKD);
SendMessage(hMSLogon, BM_SETCHECK, _this->m_server->MSLogonRequired(), 0);
HWND hNewMSLogon = GetDlgItem(hwnd, IDC_NEW_MSLOGON);
SendMessage(hNewMSLogon, BM_SETCHECK, _this->m_server->GetNewMSLogon(), 0);
EnableWindow(GetDlgItem(hwnd, IDC_NEW_MSLOGON), _this->m_server->MSLogonRequired());
EnableWindow(GetDlgItem(hwnd, IDC_MSLOGON), _this->m_server->MSLogonRequired());
// Marscha@2004 - authSSP: end of change
SetDlgItemInt(hwnd, IDC_SCALE, _this->m_server->GetDefaultScale(), false);
// Remote input settings
HWND hEnableRemoteInputs = GetDlgItem(hwnd, IDC_DISABLE_INPUTS);
SendMessage(hEnableRemoteInputs,
BM_SETCHECK,
!(_this->m_server->RemoteInputsEnabled()),
0);
// Local input settings
HWND hDisableLocalInputs = GetDlgItem(hwnd, IDC_DISABLE_LOCAL_INPUTS);
SendMessage(hDisableLocalInputs,
BM_SETCHECK,
_this->m_server->LocalInputsDisabled(),
0);
// Remove the wallpaper
HWND hRemoveWallpaper = GetDlgItem(hwnd, IDC_REMOVE_WALLPAPER);
SendMessage(hRemoveWallpaper,
BM_SETCHECK,
_this->m_server->RemoveWallpaperEnabled(),
0);
// Lock settings
HWND hLockSetting;
switch (_this->m_server->LockSettings()) {
case 1:
hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOCK);
break;
case 2:
hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOGOFF);
break;
default:
hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_NOTHING);
};
SendMessage(hLockSetting,
BM_SETCHECK,
TRUE,
0);
HWND hmvSetting;
switch (_this->m_server->ConnectPriority()) {
case 0:
hmvSetting = GetDlgItem(hwnd, IDC_MV1);
break;
case 1:
hmvSetting = GetDlgItem(hwnd, IDC_MV2);
break;
case 2:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?