/// <summary> /// Method for launch WinSCP: SCP, FTP, SFTP Protocols /// </summary> /// <param name="protocol"> "scp://" or "ftp://" or "sftp://"</param> /// <param name="serverElement">Current selected server from Tree View</param> private static void LaunchWinScp(string protocol, ServerElement serverElement) { string[] winScpExtractPath = ExtractFilePath(Settings.Default.winscppath); string winScpPath = Environment.ExpandEnvironmentVariables(winScpExtractPath[0]); string winScpArgs = winScpExtractPath[1]; if (File.Exists(winScpPath)) { string host = serverElement.Host; string port = serverElement.Port != "" ? serverElement.Port : ""; using (Process winScpProcess = new Process()) { winScpProcess.StartInfo.FileName = Settings.Default.winscppath; winScpProcess.StartInfo.Arguments = protocol; if (serverElement.Username != "") { string[] s = { "%", " ", "+", "/", "@", "\"", ":", ";" }; serverElement.Username = OtherHelper.ReplaceU(s, serverElement.Username); serverElement.Password = OtherHelper.ReplaceU(s, serverElement.Password); winScpProcess.StartInfo.Arguments += serverElement.Username; winScpProcess.StartInfo.Arguments += serverElement.Password != "" ? ":" + serverElement.Password : ""; winScpProcess.StartInfo.Arguments += "@"; } winScpProcess.StartInfo.Arguments += (host != "" ? HttpUtility.UrlEncode(host) : "") ?? throw new InvalidOperationException(); winScpProcess.StartInfo.Arguments += port != "" ? ":" + port : ""; winScpProcess.StartInfo.Arguments += protocol == "ftp://" ? " /passive=" + (Settings.Default.winscppassive ? "on" : "off") : ""; winScpProcess.StartInfo.Arguments += Settings.Default.winscpkey && Settings.Default.winscpkeyfile != "" ? " /privatekey=\"" + Settings.Default.winscpkeyfile + "\"" : ""; winScpProcess.StartInfo.Arguments += winScpArgs != "" ? " " + winScpArgs : ""; winScpProcess.Start(); } } else { if (MessageBox.Show(Resources.connectionHelper_LaunchVnc_M1 + winScpPath + Resources.connectionHelper_LaunchVnc_M2, Resources.connectionHelper_LaunchVnc_Error, MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { formMain.optionsForm.bWSCPPath_Click(); } } }
/// <summary> /// Method for launch user VNC client like a TinyVNC, UltraVNC or ReadlVNC /// </summary> /// <param name="serverElement">Current selected server from Tree View</param> private static void LaunchVnc(ServerElement serverElement) { string[] vncExtractPath = ExtractFilePath(Settings.Default.vncpath); string vncPath = Environment.ExpandEnvironmentVariables(vncExtractPath[0]); string vncArgs = vncExtractPath[1]; if (File.Exists(vncPath)) { string host = serverElement.Host; string port = serverElement.Port != "" ? serverElement.Port : "5900"; _vncOutPath = ""; if (Settings.Default.vncfilespath != "" && OtherHelper.ReplaceA(ps, pr, Settings.Default.vncfilespath) != "\\") { _vncOutPath = OtherHelper.ReplaceA(ps, pr, Settings.Default.vncfilespath + "\\"); if (!Directory.Exists(_vncOutPath)) { Directory.CreateDirectory(_vncOutPath); } } TextWriter vncFile = new StreamWriter(_vncOutPath + OtherHelper.ReplaceU(f, serverElement.Name) + ".vnc"); vncFile.WriteLine("[Connection]"); vncFile.WriteLine(host != "" ? "host=" + host : ""); vncFile.WriteLine(port != "" ? "port=" + port : ""); vncFile.WriteLine(serverElement.Username != "" ? "username="******""); vncFile.WriteLine(serverElement.Password != "" ? "password="******""); vncFile.WriteLine("[Options]"); vncFile.WriteLine(Settings.Default.vncfullscreen ? "fullscreen=1" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "viewonly=1" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "sendptrevents=0" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "sendkeyevents=0" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "sendcuttext=0" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "acceptcuttext=0" : ""); vncFile.WriteLine(Settings.Default.vncviewonly ? "sharefiles=0" : ""); vncFile.WriteLine(serverElement.Password != "" && serverElement.Password.Length > 8 ? "protocol3.3=1" : ""); // f****n vnc 4.0 auth vncFile.Close(); Process myProc = new Process { StartInfo = { FileName = Settings.Default.vncpath, Arguments = "-config \"" + _vncOutPath + OtherHelper.ReplaceU(f, serverElement.Name) + ".vnc\"" + (vncArgs != "" ? " " + vncArgs : "") } }; myProc.Start(); } else { if (MessageBox.Show(Resources.connectionHelper_LaunchVnc_M1 + vncPath + Resources.connectionHelper_LaunchVnc_M2, Resources.connectionHelper_LaunchVnc_Error, MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { formMain.optionsForm.bVNCPath_Click(); } } }
/// <summary> /// Method for launch default RDP client (mstcs.exe) /// </summary> /// <param name="serverElement">Server data for launching</param> private static void LaunchRdp(ServerElement serverElement, XmlHelper xmlHelper) { string[] rdpExtractFilePath = ExtractFilePath(Settings.Default.rdpath); string rdpPath = Environment.ExpandEnvironmentVariables(rdpExtractFilePath[0]); string rdpLaunchArgs = rdpExtractFilePath[1]; if (File.Exists(rdpPath)) { var size = xmlHelper.configGet(serverElement.Id + "_rdsize"); if (string.IsNullOrEmpty(size)) { size = Settings.Default.rdsize; } string[] sizes = size.Split('x'); _rdpOutPath = ""; if (Settings.Default.rdfilespath != "" && OtherHelper.ReplaceA(ps, pr, Settings.Default.rdfilespath) != "\\") { _rdpOutPath = OtherHelper.ReplaceA(ps, pr, Settings.Default.rdfilespath + "\\"); //TODO: add try for exception if (!Directory.Exists(_rdpOutPath)) { Directory.CreateDirectory(_rdpOutPath); } } var rddrives = Settings.Default.rddrives; bool.TryParse(xmlHelper.configGet(serverElement.Id + "_rddrives"), out rddrives); var rdadmin = Settings.Default.rdadmin; bool.TryParse(xmlHelper.configGet(serverElement.Id + "_rdadmin"), out rdadmin); var rdspan = Settings.Default.rdspan; bool.TryParse(xmlHelper.configGet(serverElement.Id + "_rdspan"), out rdspan); TextWriter rdpFileWriter = new StreamWriter(path: _rdpOutPath + OtherHelper.ReplaceU(f, serverElement.Name) + ".rdp"); //TODO: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated rdpFileWriter.WriteLine(size == "Full screen" ? "screen mode id:i:2" : "screen mode id:i:1"); rdpFileWriter.WriteLine(sizes.Length == 2 ? "desktopwidth:i:" + sizes[0] : ""); rdpFileWriter.WriteLine(sizes.Length == 2 ? "desktopheight:i:" + sizes[1] : ""); rdpFileWriter.WriteLine(serverElement.HostWithPort != "" ? "full address:s:" + serverElement.HostWithPort : ""); rdpFileWriter.WriteLine(serverElement.Username != "" ? "username:s:" + serverElement.Username : ""); rdpFileWriter.WriteLine(serverElement.Username != "" && serverElement.Password != "" ? "password 51:b:" + CryptHelper.encryptpw(serverElement.Password) : ""); rdpFileWriter.WriteLine(rddrives ? "redirectdrives:i:1" : ""); rdpFileWriter.WriteLine(rdadmin ? "administrative session:i:1" : ""); rdpFileWriter.WriteLine(rdspan ? "use multimon:i:1" : ""); rdpFileWriter.Close(); Process myProc = new Process { StartInfo = { FileName = rdpPath, Arguments = "\"" + _rdpOutPath + OtherHelper.ReplaceU(f,serverElement.Name) + ".rdp\"" + (rdpLaunchArgs != null ? " " + rdpLaunchArgs : ""), } }; myProc.Start(); } else { if (MessageBox.Show(Resources.connectionHelper_LaunchVnc_M1 + rdpPath + Resources.connectionHelper_LaunchVnc_M2, Resources.connectionHelper_LaunchVnc_Error, MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { formMain.optionsForm.bRDPath_Click(); } } }