Пример #1
0
        private RaSofOperation StopRemoteDesktop(RaSofOperation operation)
        {
            Logger.Info("Stopping remote desktop.");

            try
            {
                operation.Api = RaUrn.RdResults + "|||" + HttpMethods.Post;
                //operation.RequestMethod = HttpMethods.Post;

                bool   tunnelStopped = Tunnel.StopReverseTunnel();
                bool   rdStopped     = RemoteDesktop.StopService();
                string error         = String.Empty;

                if (!tunnelStopped)
                {
                    error = "Unable to stop tunnel. ";
                }

                if (!rdStopped)
                {
                    error += "Unable to stop remote desktop service. ";
                }

                if (error != String.Empty)
                {
                    error += "Please see agent log for details.";
                }

                operation.Success = tunnelStopped && rdStopped;
                operation.Error   = error;
            }
            catch (Exception e)
            {
                string msg = "Unable to stop remote desktop password.";
                operation.Success = false;
                operation.Error   = String.Format("{0}. {1}", msg, e.ToString());

                Logger.Error(msg);
                Logger.Exception(e);
            }

            operation.RawResult = RaFormatter.StopRemoteResult(operation);

            Logger.Info("Done.");
            return(operation);
        }
Пример #2
0
        private RaSofOperation StartRemoteDesktop(RaSofOperation operation)
        {
            Logger.Info("Starting remote desktop.");

            try
            {
                operation.Api = RaUrn.RdResults + "|||" + HttpMethods.Post;
                //operation.RequestMethod = HttpMethods.Post;

                bool tightRunning = false;

                string localPort = Tunnel.GetAvailablePort();

                if (localPort != String.Empty)
                {
                    RemoteDesktop.StopService();
                    tightRunning = RemoteDesktop.StartService(localPort.ToString());
                }
                else
                {
                    operation.Success = false;
                    operation.Error   = "No local port available. How did this happen?!";
                }

                if (tightRunning)
                {
                    if (operation.TunnelNeeded)
                    {
                        tunnelCreated = Tunnel.CreateReverseTunnel(
                            localPort,
                            operation.HostPort,
                            Settings.GetServerAddress,
                            operation.SSHPort
                            );

                        if (!tunnelCreated)
                        {
                            operation.Success = false;
                            operation.Error   = "Could not create tunnel. Please see agent log for more details.";
                            RemoteDesktop.StopService();
                        }
                    }
                }
                else
                {
                    operation.Success = false;
                    operation.Error   = "Could not start VNC server. Please see agent log for more details.";
                }

                operation.Success = tightRunning && tunnelCreated;
            }
            catch (Exception e)
            {
                string msg = "Unable to start remote desktop.";
                operation.Success = false;
                operation.Error   = String.Format("{0}. {1}", msg, e.ToString());

                Logger.Error(msg);
                Logger.Exception(e);
            }

            operation.RawResult = RaFormatter.StartRemoteResult(operation);

            Logger.Info("Done.");
            return(operation);
        }