void ClientConnection::Save_Latest_Connection()
{
	vnclog.Print(2, _T("Saving connection info\n"));	
	char fname[_MAX_PATH];
//	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();
	int disp = PORT_TO_DISPLAY(m_port);
	char optionfile[MAX_PATH];
	char *tempvar=NULL;
	tempvar = getenv( "TEMP" );
	if (tempvar) strcpy(optionfile,tempvar);
	else strcpy(optionfile,"");
	strcat(optionfile,"\\options.vnc");

	sprintf(fname, optionfile);
	vnclog.Print(1, "Saving to %s\n", fname);	

	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);

	ret = WritePrivateProfileString("connection", "proxyhost", m_proxyhost, fname);
	sprintf(buf, "%d", m_proxyport);
	WritePrivateProfileString("connection", "proxyport", buf, fname);
	buf[0] = '\0';

	WritePrivateProfileString("connection", "password", buf, fname);
	m_opts.Save(fname);
	m_opts.Register();
}
Ejemplo n.º 2
0
void ClientConnection::SaveConnection()
{
	//vnclog.Print(2, _T("Saving connection info\n"));	
	char fname[_MAX_PATH];
	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();
	int disp = PORT_TO_DISPLAY(m_port);
	sprintf(fname, "%.10s-%d.vnc", m_host, (disp > 0 && disp < 100) ? disp : m_port);
	ofn.hwndOwner = m_hwnd;
	ofn.lpstrFile = fname;
	ofn.lpstrFileTitle = tname;
	ofn.Flags = OFN_HIDEREADONLY;
	if (!GetSaveFileName(&ofn)) 
	{
		DWORD err = CommDlgExtendedError();
		char msg[1024]; 
		switch(err) 
		{
		case 0:	// user cancelled
			break;
		case FNERR_INVALIDFILENAME:
			{
				strcpy(msg, sz_K1);
				MessageBox(m_hwnd, msg, sz_K2, MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
			}
			break;
		default:
			{
				//vnclog.Print(0, "Error %d from GetSaveFileName\n", err);
				Log.Add(_ERROR_, "Error %d from GetSaveFileName", err);
			}
			break;
		}
		return;
	}
	//vnclog.Print(1, "Saving to %s\n", fname);	

	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);

	ret = WritePrivateProfileString("connection", "proxyhost", m_proxyhost, fname);
	sprintf(buf, "%d", m_proxyport);
	WritePrivateProfileString("connection", "proxyport", buf, fname);

	if (MessageBox(m_hwnd,
		sz_K3,  
		sz_K4, 
		MB_YESNO | MB_ICONWARNING) == IDYES) 
	{
		for (int i = 0; i < MAXPWLEN; i++) {
			sprintf(buf+i*2, "%02x", (unsigned int) m_encPasswd[i]);
		}
	} else
		buf[0] = '\0';
	WritePrivateProfileString("connection", "password", buf, fname);
	m_opts.Save(fname);
	m_opts.Register();
}
void ClientConnection::Save_Latest_Connection()
{
	vnclog.Print(2, _T("Saving connection info\n"));
	// don't save in case of .vnc file
	if (config_specified) return;
	char fname[_MAX_PATH];
//	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();
	int disp = PORT_TO_DISPLAY(m_port);
	char optionfile[MAX_PATH];
    VNCOptions::GetDefaultOptionsFileName(optionfile);

	sprintf(fname, optionfile);
	vnclog.Print(1, "Saving to %s\n", fname);	

	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);

	ret = WritePrivateProfileString("connection", "proxyhost", m_proxyhost, fname);
	sprintf(buf, "%d", m_proxyport);
	WritePrivateProfileString("connection", "proxyport", buf, fname);
	buf[0] = '\0';

	WritePrivateProfileString("connection", "password", buf, fname);
	m_opts.Save(fname);
	m_opts.Register();
}
void ClientConnection::Save_auto_Connection()
{
		
	char fname[_MAX_PATH];
//	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();
	int disp = PORT_TO_DISPLAY(m_port);
	char optionfile[MAX_PATH];

	char szFileName[MAX_PATH];
	if (GetModuleFileName(NULL, szFileName, MAX_PATH))
				{
				char* p = strrchr(szFileName, '\\');
					if (p == NULL) return;
					*p = '\0';
				strcat (szFileName,"\\viewers\\");
			}
	CreateDirectory(szFileName,NULL);
	strcpy(optionfile,"");
	strcat(optionfile,szFileName);
	sprintf(szFileName, "%.14s-%d.vnc", m_host, (disp > 0 && disp < 100) ? disp : m_port);
	strcat(optionfile,szFileName);
	sprintf(fname, optionfile);
	vnclog.Print(1, "Saving to %s\n", fname);	

	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);

	ret = WritePrivateProfileString("connection", "proxyhost", m_proxyhost, fname);
	sprintf(buf, "%d", m_proxyport);
	WritePrivateProfileString("connection", "proxyport", buf, fname);
	if (MessageBox(m_hwnd,
		sz_K3,  
		sz_K4, 
		MB_YESNO | MB_ICONWARNING) == IDYES) 
	{
		for (int i = 0; i < MAXPWLEN; i++) {
			sprintf(buf+i*2, "%02x", (unsigned int) m_encPasswd[i]);
		}
	} else
		buf[0] = '\0';

	WritePrivateProfileString("connection", "password", buf, fname);
	m_opts.Save(fname);
	m_opts.Register();
}
void ClientConnection::Save_auto_Connection_all()
{
	char fname[_MAX_PATH];
//	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();
	int disp = PORT_TO_DISPLAY(m_port);
	char optionfile[MAX_PATH];
	char temp[MAX_PATH];

	char szFileName[MAX_PATH];
	if (GetModuleFileName(NULL, szFileName, MAX_PATH))
				{
				char* p = strrchr(szFileName, '\\');
					if (p == NULL) return;
					*p = '\0';
				strcat (szFileName,"\\temp\\");
			}
	CreateDirectory(szFileName,NULL);
	strcpy(optionfile,"");
	strcpy(temp,"");
	strcat(optionfile,szFileName);
	strcat(optionfile,_itoa(GetTickCount(),temp,10));
	sprintf(szFileName, "%.14s-%d.vnc", m_host, (disp > 0 && disp < 100) ? disp : rand());
	strcat(optionfile,szFileName);
	sprintf(fname, optionfile);
	vnclog.Print(1, "Saving to %s\n", fname);	

	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);

	ret = WritePrivateProfileString("connection", "proxyhost", m_proxyhost, fname);
	sprintf(buf, "%d", m_proxyport);
	if (!m_ms_logon)
	{
	WritePrivateProfileString("connection", "proxyport", buf, fname);
	for (int i = 0; i < MAXPWLEN; i++) {
			sprintf(buf+i*2, "%02x", (unsigned int) m_encPasswd[i]);
	}

	WritePrivateProfileString("connection", "password", buf, fname);
	}
	m_opts.Save(fname);
	vnclog.Print(0, _T("%s\n"), fname);
	m_opts.Register();
}
Ejemplo n.º 6
0
// returns zero if successful
int ClientConnection::LoadConnection(char *fname, bool sess)
{
  if (sess) {
    char tname[_MAX_FNAME + _MAX_EXT];

    ofnInit();

    ofn.hwndOwner = m_hSess;
    ofn.lpstrFile = fname;
    ofn.lpstrFileTitle = tname;
    ofn.Flags = OFN_HIDEREADONLY;

    if (GetOpenFileName(&ofn) == 0)
      return -1;
  }
  if (GetPrivateProfileString("connection", "host", "", m_host,
                              MAX_HOST_NAME_LEN, fname) == 0) {
    MessageBox(m_hwnd, "Error reading host name from file",
               "Config file error", MB_ICONERROR | MB_OK);
    return -1;
  }
  if ((m_port = GetPrivateProfileInt("connection", "port", 0, fname)) == 0) {
    MessageBox(m_hwnd, "Error reading port number from file",
               "Config file error", MB_ICONERROR | MB_OK);
    return -1;
  }
  FormatDisplay(m_port, m_opts.m_display, _countof(m_opts.m_display), m_host);

  char buf[1026];
  m_passwdSet = false;
  if (GetPrivateProfileString("connection", "password", "", buf, 32,
                              fname) > 0) {
    for (int i = 0; i < MAXPWLEN; i++)  {
      int x = 0;
      sscanf_s(buf + i * 2, "%2x", &x);
      m_encPasswd[i] = (unsigned char) x;
    }
    m_passwdSet = true;
  }
  if (sess) {
    m_opts.Load(fname);
    m_opts.Register();
  }
  return 0;
}
void ClientConnection::RealiseFullScreenMode()
{
	LONG style = GetWindowLong(m_hwndMain, GWL_STYLE);
	if (m_opts.m_FullScreen) {

		// A bit crude here - we can skip the prompt on a registry setting.
		// We'll do this properly later.
		DWORD skipprompt = 0;

		{
			char fname[_MAX_PATH];
			ofnInit();
			char optionfile[MAX_PATH];
			VNCOptions::GetDefaultOptionsFileName(optionfile);
			sprintf(fname, optionfile);
			vnclog.Print(1, "Saving to %s\n", fname);
			skipprompt = 0;
			skipprompt = GetPrivateProfileInt("connection", "SkipFullScreenPrompt", skipprompt, fname);
		}


		/*if ( RegCreateKey(HKEY_CURRENT_USER, SETTINGS_KEY_NAME, &hRegKey)  != ERROR_SUCCESS ) {
	        hRegKey = NULL;
		} else {
			DWORD skippromptsize = sizeof(skipprompt);
			DWORD valtype;	
			if ( RegQueryValueEx( hRegKey,  "SkipFullScreenPrompt", NULL, &valtype, 
				(LPBYTE) &skipprompt, &skippromptsize) != ERROR_SUCCESS) {
				skipprompt = 0;
			}
			RegCloseKey(hRegKey);
		}*/
		
		skipprompt = 1; //sf@2004 - This prompt isn't needed any more now that we have
						// the fullscreen title bar :) Thanks Lars !
		if (!skipprompt && !skipprompt2)
			MessageBox(m_hwndMain, 
				sz_J1,
				sz_J2,
				MB_OK | MB_ICONINFORMATION | MB_TOPMOST | MB_SETFOREGROUND);

		/* Does not work yet
		// Used by VNCon - Copyright (C) 2001-2003 - Alastair Burr
		//ShowWindow(m_hwnd, SW_HIDE);
		*/
		ShowWindow(m_hwndMain, SW_MAXIMIZE);

		style = GetWindowLong(m_hwndMain, GWL_STYLE);
		style &= ~(WS_DLGFRAME | WS_THICKFRAME);
		SetWindowLong(m_hwndMain, GWL_STYLE, style);
		/* Does not work yet
		// Used by VNCon - Copyright (C) 2001-2003 - Alastair Burr
		// int cx = this->m_hScrollMax;
		// int cy = this->m_vScrollMax;
		*/

        // 7 May 2008 jdp
        HMONITOR hMonitor = ::MonitorFromWindow(m_hwndMain, MONITOR_DEFAULTTOPRIMARY);
        MONITORINFO mi;
        mi.cbSize = sizeof (MONITORINFO);

        GetMonitorInfo(hMonitor, &mi);
        int x = mi.rcMonitor.left; 
        int y = mi.rcMonitor.top;
		int cx = mi.rcMonitor.right - x; 
		int cy = mi.rcMonitor.bottom - y;
		SetWindowPos(m_hwndMain, HWND_TOPMOST, x, y, cx+3, cy+3, SWP_FRAMECHANGED);
        TitleBar.MoveToMonitor(hMonitor);
		// adzm - 2010-07 - Extended clipboard
		CheckMenuItem(m_hPopupMenuDisplay, ID_FULLSCREEN, MF_BYCOMMAND|MF_CHECKED);
		if (m_opts.m_ShowToolbar)
		SetWindowPos(m_hwndcn, m_hwndTBwin,0,m_TBr.bottom,m_winwidth, m_winheight, SWP_SHOWWINDOW);
		else 
		{
			SetWindowPos(m_hwndcn, m_hwndTBwin,0,0,cx+3, cy+3, SWP_SHOWWINDOW);
			SetWindowPos(m_hwndTBwin, NULL ,0,0,0, 0, SWP_HIDEWINDOW);
		}

		TitleBar.DisplayWindow(TRUE, TRUE); //Added by: Lars Werner (http://lars.werner.no)
		TCHAR title[_MAX_PATH];
		if (strlen(m_opts.m_title) > 0) {
			strcpy(title, m_desktopNameFull);
			strcat(title, " ");	
			if (m_opts.m_ViewOnly) {
				strcat(title, "-º¸±âÀü¿ë");
			}
			TitleBar.SetText(title);
		}
		else {
			strcpy(title, m_desktopNameFull);
			if (m_opts.m_ViewOnly)TitleBar.SetText(m_desktopName_viewonly);
			else TitleBar.SetText(m_desktopNameFull); //Added by: Lars Werner (http://lars.werner.no)
		}					
		OutputDebugString("------------full screen title-------------------");
		OutputDebugString(title);


	} else {
		ShowWindow(m_hwndMain, SW_NORMAL);
		style = GetWindowLong(m_hwndMain, GWL_STYLE);
		style |= WS_DLGFRAME | WS_THICKFRAME;
		SetWindowLong(m_hwndMain, GWL_STYLE, style);
		SetWindowPos(m_hwndMain, HWND_NOTOPMOST, 0,0,100,100, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); //Modified by: Lars Werner (http://lars.werner.no) - Reason: Bugfix, The framework got invisible after moving, so a NCCALCSIZE needed to be called!
		// adzm - 2010-07 - Extended clipboard
		CheckMenuItem(m_hPopupMenuDisplay, ID_FULLSCREEN, MF_BYCOMMAND|MF_UNCHECKED);

		TitleBar.DisplayWindow(FALSE, TRUE); //Added by: Lars Werner (http://lars.werner.no)

		if (m_hwndStatus)::RedrawWindow(m_hwndStatus, NULL,NULL,TRUE); //Added by: Lars Werner (http://lars.werner.no) - Reason: The status window is not getting redrawn after a resize.
	}
}
// returns zero if successful
int ClientConnection::LoadConnection(char *fname, bool fFromDialog,bool default_file)
{
	// The Connection Profile ".vnc" has been required from Connection Session Dialog Box
	if (fFromDialog)
	{
		char tname[_MAX_FNAME + _MAX_EXT];
		ofnInit();
		ofn.hwndOwner = m_hSessionDialog;
		ofn.lpstrFile = fname;
		ofn.lpstrFileTitle = tname;
		ofn.Flags = OFN_HIDEREADONLY;

		// Open the FileSelection Dialog boxq
		if (GetOpenFileName(&ofn) == 0)
			return -1;
	}

	if (GetPrivateProfileString("connection", "host", "", m_host, MAX_HOST_NAME_LEN, fname) == 0) {
		//AaronP
//		MessageBox(m_hwnd, sz_K5, sz_K6, MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
//		return -1;
		//EndAaronP
	}
	if ( (m_port = GetPrivateProfileInt("connection", "port", 0, fname)) == 0)
	{
		//
		//MessageBox(m_hwnd, sz_K7, sz_K6, MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
		// in case options.vnc does not exist return to normal menu
		return -1;
	}

	GetPrivateProfileString("connection", "proxyhost", "", m_proxyhost, MAX_HOST_NAME_LEN, fname);
	m_proxyport = GetPrivateProfileInt("connection", "proxyport", 0, fname);
	m_fUseProxy = GetPrivateProfileInt("options", "UseProxy", 0, fname);

	char buf[32];
	m_encPasswd[0] = '\0';
	if (GetPrivateProfileString("connection", "password", "", buf, 32, fname) > 0) {
		for (int i = 0; i < MAXPWLEN; i++)	{
			int x = 0;
			sscanf(buf+i*2, "%2x", &x);
			m_encPasswd[i] = (unsigned char) x;
		}
	}

	// The Connection Profile ".vnc" has been required from Connection Session Dialog Box
	// Load the rest of params
	char optionfile[MAX_PATH];
	char *tempvar=NULL;
	tempvar = getenv( "TEMP" );
	if (tempvar) strcpy(optionfile,tempvar);
	else strcpy(optionfile,"");
	strcat(optionfile,"\\options.vnc");
	
//	if (fFromDialog)
	{
		m_opts.Load(fname);
		m_opts.Register();
	}
	//AaronP
	//else 
		if (strcmp(m_host, "") == 0 || 
			  strcmp(fname,optionfile)==0)
	{
		// Load the rest of params 
		strcpy(m_opts.m_proxyhost,m_proxyhost);
		m_opts.m_proxyport=m_proxyport;
		m_opts.m_fUseProxy=m_fUseProxy;
		m_opts.Load(fname);
		m_opts.Register();
		// Then display the session dialog to get missing params again
		SessionDialog sessdlg(&m_opts, this, m_pDSMPlugin); //sf@2002
		if (!sessdlg.DoDialog())
		{
			throw QuietException("");
		}
		_tcsncpy(m_host, sessdlg.m_host_dialog, MAX_HOST_NAME_LEN);
		m_port = sessdlg.m_port;
	
		_tcsncpy(m_proxyhost, sessdlg.m_proxyhost, MAX_HOST_NAME_LEN);
		m_proxyport = sessdlg.m_proxyport;
		m_fUseProxy = sessdlg.m_fUseProxy;

	};	
	//EndAaronP
	return 0;
}
Ejemplo n.º 9
0
void ClientConnection::SaveConnection()
{
	vnclog.Print(2, _T("Saving connection info\n"));	
	char tname[_MAX_FNAME + _MAX_EXT];
	ofnInit();

	// Let's choose a reasonable file name based on hostname and port
	char fname[_MAX_PATH];

	// If the first character of the hostname is a letter, try to use
	// only the part of the hostname before the first dot
	char *ptr = NULL;
	if (isalpha(m_host[0])) {
		ptr = strchr(m_host, '.');
		if (ptr - m_host > 24)
			ptr = NULL;
	}
	if (ptr) {
		memcpy(fname, m_host, ptr - m_host);
		fname[ptr - m_host] = '\0';
	} else {
		sprintf(fname, "%.24s", m_host);
	}
	// Append the port number if it's not the default port
	if (PORT_TO_DISPLAY(m_port) != 0) {
		sprintf(&fname[strlen(fname)], "-%d", m_port);
	}
	// Finally, append the .vnc suffix (note there will be no buffer overrun)
	strcat(fname, ".vnc");

	ofn.hwndOwner = m_hwnd;
	ofn.lpstrFile = fname;
	ofn.lpstrFileTitle = tname; 
	ofn.Flags = OFN_HIDEREADONLY;
	if (!GetSaveFileName(&ofn)) {
		DWORD err = CommDlgExtendedError();
		char msg[1024]; 
		switch(err) {
		case 0:	// user cancelled
			break;
		case FNERR_INVALIDFILENAME:
			strcpy(msg, "Invalid filename");
			MessageBox(m_hwnd, msg, "Error saving file", MB_ICONERROR | MB_OK);
			break;
		default:
			vnclog.Print(0, "Error %d from GetSaveFileName\n", err);
			break;
		}
		return;
	}
	vnclog.Print(1, "Saving to %s\n", fname);	
	int ret = WritePrivateProfileString("connection", "host", m_host, fname);
	char buf[32];
	sprintf(buf, "%d", m_port);
	WritePrivateProfileString("connection", "port", buf, fname);
	buf[0] = '\0';
	if (m_authScheme == rfbAuthVNC) {
		if (MessageBox(m_hwnd,
			"Do you want to save the password in this file?\n\r"
			"If you say Yes, anyone with access to this file could access your session\n\r"
			"and (potentially) discover your VNC password.",  
			"Security warning", 
			MB_YESNO | MB_ICONWARNING) == IDYES) 
		{
			for (int i = 0; i < MAXPWLEN; i++) {
				sprintf(buf+i*2, "%02x", (unsigned int) m_encPasswd[i]);
			}
			WritePrivateProfileString("connection", "password", buf, fname);
		}
	}
	m_opts.Save(fname);
	m_opts.Register();
}