📄 vncserver.cpp
字号:
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] != '\0') {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - malformed AuthHosts string"));
machineMode = vh_ExpectDelimiter;
}
break;
// ExpectPattern - we expect to see a valid pattern
case vh_ExpectPattern:
// ExpectDelimiter - we're scanning for the next ':', skipping a pattern
case vh_ExpectDelimiter:
if ((m_auth_hosts[authHostsPos] == ':') ||
(m_auth_hosts[authHostsPos] == '\0')) {
if (machineMode == vh_ExpectPattern) {
if (patternStart == 0) {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - pattern processing failed!"));
} else {
// Process the match
if (MatchStringToTemplate(hostname, hostNameLen,
&(m_auth_hosts[patternStart]), authHostsPos-patternStart)) {
// The hostname matched - apply the include/exclude rule
verifiedHost = patternType;
}
}
}
// We now expect another + or -
machineMode = vh_ExpectIncludeExclude;
}
break;
}
// Have we hit the end of the pattern string?
if (m_auth_hosts[authHostsPos] == '\0')
break;
authHostsPos++;
}
}
// Based on the server's QuerySetting, adjust the verification result
switch (verifiedHost) {
case vncServer::aqrAccept:
if (QuerySetting() >= 3)
verifiedHost = vncServer::aqrQuery;
break;
case vncServer::aqrQuery:
if (QuerySetting() <= 1)
verifiedHost = vncServer::aqrAccept;
else if (QuerySetting() == 4)
verifiedHost = vncServer::aqrReject;
break;
case vncServer::aqrReject:
if (QuerySetting() == 0)
verifiedHost = vncServer::aqrQuery;
break;
};
return verifiedHost;
}
void
vncServer::AddAuthHostsBlacklist(const char *machine) {
//TR@2005: Don't blacklist local connects, no good with DynGate!
if (strcmp(machine, "127.0.0.1")==0)
return;
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
// Get the current time as a 64-bit value
SYSTEMTIME systime;
FILETIME ftime;
LARGE_INTEGER now;
GetSystemTime(&systime);
SystemTimeToFileTime(&systime, &ftime);
now.LowPart=ftime.dwLowDateTime;now.HighPart=ftime.dwHighDateTime;
now.QuadPart /= 10000000; // Convert it into seconds
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
// If the host is already blocked then ignore
if (current->_blocked)
return;
// Set the RefTime & failureCount
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_failureCount++;
if (current->_failureCount > 5)
current->_blocked = TRUE;
return;
}
current = current->_next;
}
// Didn't find the entry
current = new vncServer::BlacklistEntry;
current->_blocked = FALSE;
current->_failureCount = 0;
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_machineName = strdup(machine);
current->_next = m_blacklist;
m_blacklist = current;
}
void
vncServer::RemAuthHostsBlacklist(const char *machine) {
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
vncServer::BlacklistEntry *previous = 0;
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
if (previous)
previous->_next = current->_next;
else
m_blacklist = current->_next;
vncServer::BlacklistEntry *next = current->_next;
free (current->_machineName);
delete current;
current = next;
continue;
}
previous = current;
current = current->_next;
}
}
// Modif sf@2002
void vncServer::SetSingleWindowName(const char *szName)
{
strncpy(m_szWindowName, szName, MAX_SW_NAMELEN-1);
m_szWindowName[MAX_SW_NAMELEN-1] = '\0';
}
// Modef rdv@202
void
vncServer::SetNewSWSize(long w,long h,BOOL desktop)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
if (!GetClient(*i)->SetNewSWSize(w,h,desktop)) {
vnclog.Print(LL_INTINFO, VNCLOG("Unable to set new desktop size"));
KillClient(*i);
}
}
}
void
vncServer::SetSWOffset(int x,int y)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->SetSWOffset(x,y);
}
}
void
vncServer::SetScreenOffset(int x,int y,int type)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->SetScreenOffset(x,y,type);
}
}
// Modif sf@2002 - v1.1.0 - Default Scaling
UINT vncServer::GetDefaultScale()
{
return m_nDefaultScale;
}
BOOL vncServer::SetDefaultScale(int nScale)
{
m_nDefaultScale = nScale;
return TRUE;
}
int vncServer::FileTransferEnabled()
{
return m_fFileTransferEnabled;
}
BOOL vncServer::EnableFileTransfer(int fEnable)
{
m_fFileTransferEnabled = fEnable;
return TRUE;
}
int vncServer::AutostartSetting()
{
bool runAsService=vncService::InstalledAsService();
bool isInAutostart=vncService::IsInAutostart();
if(!runAsService && isInAutostart)
{
return 1;
}
else if(runAsService)
{
return 2;
}
else
//if(!runAsService && !isInAutostart)
{
return 0;
}
}
void vncServer::RemoveService()
{
if(vncService::InstalledAsService())
{
char path[MAX_PATH]="";
GetModuleFileName(NULL, path, MAX_PATH);
ShellExecute(NULL,"open",path,"-remove",0,SW_SHOW);
}
}
void vncServer::RemoveAutostart()
{
if(vncService::IsInAutostart())
{
vncService::RemoveAutostart();
}
}
bool vncServer::IsInstallAutostartAllowed()
{
return vncService::IsInstallAutostartAllowed();
}
bool vncServer::InstallAutostart()
{
if(!vncService::IsInAutostart())
{
return vncService::InstallAutostart();
}
return false;
}
void vncServer::InstallService()
{
if(!vncService::InstalledAsService())
{
vncService::InstallService(true);
}
}
BOOL vncServer::SetAutostartSetting(int autostartmode)
{
switch (autostartmode)
{
case 3:
case 0:
// don磘 autostart anymore
RemoveAutostart();
RemoveService();
break;
case 1:
// "regular" autostart, not as service
InstallAutostart();
RemoveService();
break;
case 2:
RemoveAutostart();
InstallService();
break;
}
//m_autostartsetting = autostartmode;
return true;
}
BOOL vncServer::MSLogonRequired()
{
return m_fMSLogonRequired;
}
BOOL vncServer::RequireMSLogon(BOOL fEnable)
{
m_fMSLogonRequired = fEnable;
return TRUE;
}
BOOL vncServer::GetNewMSLogon()
{
return m_fNewMSLogon;
}
BOOL vncServer::SetNewMSLogon(BOOL fEnable)
{
m_fNewMSLogon = fEnable;
return TRUE;
}
//
// sgf@2002 - for now, we disable cache rects when more than one client
//
void vncServer::DisableCacheForAllClients()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
GetClient(*i)->EnableCache(FALSE);
}
}
void
vncServer::Clear_Update_Tracker() {
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
GetClient(*i)->Clear_Update_Tracker();
}
}
void vncServer::Driver(BOOL enable)
{
sethook=true;
m_driver = enable;
}
void vncServer::Hook(BOOL enable)
{
sethook=true;
m_hook=enable;
}
void vncServer::SetHookings()
{
if (sethook && m_desktop)
{
m_desktop->SethookMechanism(Hook(),Driver());
}
sethook=false;
}
void vncServer::EnableXRichCursor(BOOL fEnable)
{
m_fXRichCursor = fEnable;
}
BOOL
vncServer::SetDisableTrayIcon(BOOL disableTrayIcon)
{
if (disableTrayIcon != m_disableTrayIcon)
{
m_disableTrayIcon = disableTrayIcon;
}
return TRUE;
}
BOOL
vncServer::GetDisableTrayIcon()
{
return m_disableTrayIcon;
}
BOOL
vncServer::SetAllowEditClients(BOOL AllowEditClients)
{
if (AllowEditClients != m_AllowEditClients)
{
m_AllowEditClients = AllowEditClients;
}
return TRUE;
}
BOOL
vncServer::GetAllowEditClients()
{
return m_AllowEditClients;
}
BOOL
vncServer::All_clients_initialalized() {
vncClientList::iterator i;
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (!GetClient(*i)->client_settings_passed) return false;
}
return true;
}
bool vncServer::IsClient(vncClient* pClient)
{
vncClientList::iterator i;
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
if (GetClient(*i) == pClient) return true;
return false;
}
void vncServer::SetServerMode(bool serverMode)
{
if(serverMode!=m_serverMode)
{
// CS: not a good solution
if(menu!=NULL)
{
menu->Show(serverMode);
}
m_serverMode=serverMode;
}
}
void vncServer::SetLogging(bool logging)
{
if(logging == m_logging) // not changed -> nothing to set
return;
vnclog.Print(1, VNCLOG("setlogging=%d"), logging);
if(logging)
{
//char path[MAX_PATH]="";
string path;
// when running as a service always log to application directory, else try to log to desktop
if(vncService::RunningAsService() || !GetSpecialFolderPath(CSIDL_DESKTOP,path,false))
{
GetApplicationDirectory(path);
}
//strcat(path,"\\TeamViewer_Logfile.log");
path += "\\TeamViewer_Logfile.log";
vnclog.SetFile(path.c_str(),true);
int mode = VNCLog::ToFile;
#ifdef _DEBUG
mode |= VNCLog::ToDebug;
#endif
vnclog.SetMode(mode);
vnclog.SetLevel(LL_ALL);
}
else
{
vnclog.SetLevel(LL_NONE);
}
m_logging=logging;
}
char* vncServer::Version()
{
return TEAMVIEWER_VERSION;
}
void vncServer::SetIdentity(char *newid)
{
if(newid != NULL)
{
strncpy(m_identity, newid, MAXIDENTITYLEN);
m_identity[MAXIDENTITYLEN] = '\0';
string info = string(newid);
TeamviewerInfo::setLocalInfo(tvIdentity, info);
}
}
void vncServer::SetUseDynGate(bool useDynGate)
{
m_useDynGate=useDynGate;
if(useDynGate)
TeamviewerInfo::setLocalInfo(tvID, CroGateway::Instance()->ClientID());
else
TeamviewerInfo::setLocalInfo(tvID, "");
}
void SetSW(HWND window);
void vncServer::SendTVCommandToClients(CARD16 msgid, string value)
{
vncClientList::iterator i;
for ( i = m_authClients.begin(); i != m_authClients.end(); i++)
{
TeamviewerInfo *info = GetClient(*i)->m_thread->m_tvinfo;
info->SendCommand(msgid, value);
info->FinishTeamviewerInfo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -