📄 vncproperties.cpp
字号:
// Copyright (C) 2002-2003 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"const char WINVNC_REGISTRY_KEY [] = "Software\\ORL\\WinVNC3";const char NO_PASSWORD_WARN [] = "WARNING : Running WinVNC without setting a password is " "a dangerous security risk!\n" "Until you set a password, WinVNC will not accept incoming connections.";const char NO_OVERRIDE_ERR [] = "This machine has been preconfigured with WinVNC settings, " "which cannot be overridden by individual users. " "The preconfigured settings may be modified only by a System Administrator.";const char NO_PASSWD_NO_OVERRIDE_ERR [] = "No password has been set & this machine has been " "preconfigured to prevent users from setting their own.\n" "You must contact a System Administrator to configure WinVNC properly.";const char NO_PASSWD_NO_OVERRIDE_WARN [] = "WARNING : This machine has been preconfigured to allow un-authenticated\n" "connections to be accepted and to prevent users from enabling authentication.";const char NO_PASSWD_NO_LOGON_WARN [] = "WARNING : This machine has no default password set. WinVNC will present the " "Default Properties dialog now to allow one to be entered.";const char NO_CURRENT_USER_ERR [] = "The WinVNC settings for the current user are unavailable at present.";const char CANNOT_EDIT_DEFAULT_PREFS [] = "You do not have sufficient priviliges to edit the default local WinVNC settings.";// Constructor & DestructorvncProperties::vncProperties(){ m_alloweditclients = TRUE; m_allowproperties = TRUE; m_allowshutdown = TRUE; m_dlgvisible = FALSE; m_usersettings = TRUE;}vncProperties::~vncProperties(){}// InitialisationBOOLvncProperties::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) { if(m_server->AuthRequired()) { MessageBox(NULL, NO_PASSWD_NO_OVERRIDE_ERR, "WinVNC Error", MB_OK | MB_ICONSTOP); PostQuitMessage(0); } else { MessageBox(NULL, NO_PASSWD_NO_OVERRIDE_WARN, "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) { MessageBox(NULL, NO_PASSWD_NO_LOGON_WARN, "WinVNC Error", MB_OK | MB_ICONEXCLAMATION); Show(TRUE, FALSE); } else { Show(TRUE, TRUE); } } } } return TRUE;}// Dialog box handling functionsvoidvncProperties::Show(BOOL show, BOOL usersettings){ if (show) { if (!m_allowproperties) { // If the user isn't allowed to override the settings then tell them MessageBox(NULL, NO_OVERRIDE_ERR, "WinVNC Error", MB_OK | MB_ICONEXCLAMATION); return; } // 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, NO_CURRENT_USER_ERR, "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, CANNOT_EDIT_DEFAULT_PREFS, "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); for (;;) { m_returncode_valid = FALSE; // Do the dialog box int result = DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_PROPERTIES), 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, NO_PASSWORD_WARN, "WinVNC Warning", MB_OK | MB_ICONEXCLAMATION); omni_thread::sleep(4); } // Load in all the settings Load(TRUE); } }}BOOL CALLBACKvncProperties::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: { // 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->m_dlgvisible = TRUE; // Set the dialog box's title to indicate which Properties we're editting if (_this->m_usersettings) { SetWindowText(hwnd, "WinVNC: Current User Properties"); } else { SetWindowText(hwnd, "WinVNC: Default Local System Properties"); } // Initialise the properties controls HWND hConnectSock = GetDlgItem(hwnd, IDC_CONNECT_SOCK); SendMessage(hConnectSock, BM_SETCHECK, _this->m_server->SockConnected(), 0); HWND hConnectHTTP = GetDlgItem(hwnd, IDC_CONNECT_HTTP); SendMessage(hConnectHTTP, BM_SETCHECK, _this->m_server->HTTPConnectEnabled(), 0); HWND hConnectCorba = GetDlgItem(hwnd, IDC_CONNECT_CORBA); SendMessage(hConnectCorba, BM_SETCHECK, _this->m_server->CORBAConnected(), 0);#if(defined(_CORBA)) ShowWindow(hConnectCorba, SW_SHOW);#else ShowWindow(hConnectCorba, SW_HIDE);#endif HWND hAutoPortNo = GetDlgItem(hwnd, IDC_AUTO_DISPLAY_NO); SendMessage(hAutoPortNo, BM_SETCHECK, _this->m_server->AutoPortSelect(), 0); EnableWindow(hAutoPortNo, _this->m_server->SockConnected()); HWND hPortNo = GetDlgItem(hwnd, IDC_PORTNO); SetDlgItemInt(hwnd, IDC_PORTNO, PORT_TO_DISPLAY(_this->m_server->GetPort()), FALSE); EnableWindow(hPortNo, _this->m_server->SockConnected() && !_this->m_server->AutoPortSelect()); HWND hPassword = GetDlgItem(hwnd, IDC_PASSWORD); EnableWindow(hPassword, _this->m_server->SockConnected()); // Get the password { char plain[MAXPWLEN+1]; _this->m_server->GetPassword(plain); { vncPasswd::ToText plainpwd(plain); int length = strlen(plainpwd); for (int i=0; i<length; i++) { plain[i] = i+1; } plain[length]=0; } SetDlgItemText(hwnd, IDC_PASSWORD, (const char *) plain); } // 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -