Ejemplo n.º 1
0
 public static void SaveDescriptor(AgentDescriptor descriptor, string file)
 {
     if (string.IsNullOrEmpty(file))
     {
         file = Path.Combine(Directory.GetCurrentDirectory(), "savedDescriptor.json");
     }
     File.WriteAllText(file, JsonConvert.SerializeObject(descriptor));
 }
Ejemplo n.º 2
0
 public int GetNextFreeLocalPort(AgentDescriptor descriptor, int sshServicePort)
 {
     MiscUtils.CheckServiceRunning(sshServicePort);
     using (var client = new ExtendedWebClient(timeout))
     {
         try
         {
             return(int.Parse(client.UploadString(string.Format("http://localhost:{0}/?cmd=getnextlocalport",
                                                                sshServicePort.ToString()), JsonConvert.SerializeObject(descriptor))));
         }
         catch (WebException ex)
         {
             Log.Error("PortUtils.GetNextFreeLocalPort WebException: {0}", ex.Message);
         }
         return(0);
     }
 }
Ejemplo n.º 3
0
 public void CopyTo(AgentDescriptor target)
 {
     if (target != null)
     {
         target.ClientName     = ClientName;
         target.MachineName    = MachineName;
         target.LocalIp        = LocalIp;
         target.PublicIp       = PublicIp;
         target.AgentName      = AgentName;
         target.Id             = Id;
         target.SshServer      = SshServer;
         target.RemotePort     = RemotePort;
         target.LocalPort      = LocalPort;
         target.AgentRole      = AgentRole;
         target.DateCreated    = DateCreated;
         target.ExpirationDate = ExpirationDate;
         target.IdSSHServer    = IdSSHServer;
     }
 }
Ejemplo n.º 4
0
        public AgentDescriptor ReOpenTunnel(int sshServicePort, AgentDescriptor descriptor)
        {
            MiscUtils.CheckServiceRunning(sshServicePort);

            using (var client = new WebClient())
            {
                try
                {
                    return(JsonConvert.DeserializeObject <AgentDescriptor>(
                               client.UploadString(string.Format("http://localhost:{0}?cmd=reopentunnel",
                                                                 sshServicePort.ToString()), "POST", JsonConvert.SerializeObject(descriptor))));
                }
                catch (WebException ex)
                {
                    Log.Error(ex);
                }
                return(null);
            }
        }
Ejemplo n.º 5
0
        public AgentDescriptor RegisterTunnel(int sshServicePort, AgentDescriptor descriptor)
        {
            MiscUtils.CheckServiceRunning(sshServicePort);

            using (var client = new WebClient())
            {
                try
                {
                    Log.Info("Calling SSHService to register tunnel");
                    return(JsonConvert.DeserializeObject <AgentDescriptor>(
                               client.UploadString(string.Format("http://localhost:{0}?cmd=registeragent",
                                                                 sshServicePort.ToString()), "POST", JsonConvert.SerializeObject(descriptor))));
                }
                catch (WebException ex)
                {
                    Log.Error("SshTunnelUtils - RegisterTunnel WebException error: {0}", ex);
                }
                catch (Exception ex)
                {
                    Log.Error("SshTunnelUtils - RegisterTunnel general error: {0}", ex);
                }
                return(null);
            }
        }