示例#1
0
        /// <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();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Method for launch PuTTy
        /// </summary>
        /// <param name="serverElement">Current selected server from Tree View<</param>
        private static void LaunchPuTTy(ServerElement serverElement)
        {
            string[] puttyExtractPath = ExtractFilePath(Settings.Default.puttypath);
            string   puttyPath        = Environment.ExpandEnvironmentVariables(puttyExtractPath[0]);
            string   puttyArgs        = puttyExtractPath[1];

            if (File.Exists(puttyPath))
            {
                string host = serverElement.Host;
                string port = serverElement.Port != "" ? serverElement.Port : "22";

                using (Process puttyProcess = new Process())
                {
                    puttyProcess.StartInfo.FileName   = Settings.Default.puttypath;
                    puttyProcess.StartInfo.Arguments  = "-ssh ";
                    puttyProcess.StartInfo.Arguments += serverElement.Username != "" ? serverElement.Username + "@" : "";

                    puttyProcess.StartInfo.Arguments += host != "" ? host : "";
                    puttyProcess.StartInfo.Arguments += port != "" ? " " + port : "";
                    puttyProcess.StartInfo.Arguments += serverElement.Username != "" && serverElement.Password != "" ? " -pw \"" + OtherHelper.ReplaceA(passs, passr, serverElement.Password) + "\"" : "";
                    puttyProcess.StartInfo.Arguments += Settings.Default.puttyexecute && Settings.Default.puttycommand != "" ? " -m \"" + Settings.Default.puttycommand + "\"" : "";
                    puttyProcess.StartInfo.Arguments += Settings.Default.puttykey && Settings.Default.puttykeyfile != "" ? " -i \"" + Settings.Default.puttykeyfile + "\"" : "";
                    puttyProcess.StartInfo.Arguments += Settings.Default.puttyforward ? " -X" : "";

                    puttyProcess.StartInfo.Arguments += puttyArgs != "" ? " " + puttyArgs + "@" : "";

                    puttyProcess.Start();
                }
            }
            else
            {
                if (MessageBox.Show(Resources.connectionHelper_LaunchVnc_M1 + puttyPath + Resources.connectionHelper_LaunchVnc_M2,
                                    Resources.connectionHelper_LaunchVnc_Error, MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    formMain.optionsForm.bPuTTYPath_Click();
                }
            }
        }
示例#3
0
        /// <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();
                }
            }
        }