public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false) { Name = name; IpPrefix = ipPrefix; CcmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); if (instantiateSshClient) { string sshHost = "TBD"; int sshPort = -1; string sshUser = "******"; string sshPassword = "******"; _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword); _sshClient.Connect(); _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_sshShellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) { break; } } } }
private void RestartController(object mSender, EventArgs e) { Task.Run(() => { string IP = ""; string Building = ""; string Room = ""; string Tag = ""; Task.Run(() => { Button sender = (Button)mSender; IP = RoomIPs[sender.Id]; Building = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Building; Room = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Room; Tag = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Tag; }); using (Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(IP, "Username", "Password")) { sshClient.HostKeyReceived += (_sender, _e) => { _e.CanTrust = true; }; sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30); try { sshClient.Connect(); } catch { return; } var amxStream = sshClient.CreateShellStream("amxStream", 0, 0, 0, 0, 256); bool streamLockToken = true; var streamTTL = DateTime.Now.Add(TimeSpan.FromSeconds(30)); while (streamLockToken) { if (amxStream.DataAvailable) { streamLockToken = false; } else if (DateTime.Now >= streamTTL) { sshClient.Disconnect(); return; } else { System.Threading.Thread.Sleep(0); } } amxStream.WriteLine("reboot"); sshClient.Disconnect(); } }); }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(_ssh_host, _ssh_port, _ssh_username, _ssh_password); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) { break; } } }
public void Login(string host) { if (isLoggedIn) { return; } client = new Renci.SshNet.SshClient(host, port, username, password); client.Connect(); stream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); reader = new StreamReader(stream); writer = new StreamWriter(stream); writer.AutoFlush = true; isLoggedIn = true; }
private CCMBridge() { _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); _ssh_client = new Renci.SshNet.SshClient(_ssh_host, _ssh_port, _ssh_username, _ssh_password); _ssh_client.Connect(); _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_ssh_shellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) { break; } } }
public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false) { Name = name; IpPrefix = ipPrefix; CcmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); if (instantiateSshClient) { string sshHost = "TBD"; int sshPort = -1; string sshUser = "******"; string sshPassword = "******"; _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword); _sshClient.Connect(); _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000); var outp = new StringBuilder(); while (true) { outp.Append(_sshShellStream.Read()); if (outp.ToString().Trim().EndsWith("$")) break; } } }
private void RestartController(object mSender, RoutedEventArgs mE) { Task.Run(() => { string IP = ""; string Building = ""; string Room = ""; string Tag = ""; (mSender as Button).Dispatcher.Invoke(() => { IP = (mSender as Button).Tag.ToString(); Building = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Building; Room = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Room; Tag = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Tag; }); using (Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(IP, "username", "password")) { sshClient.HostKeyReceived += (_sender, _e) => { _e.CanTrust = true; }; Log("Attempting to connect to " + Building + " " + Room + " " + Tag + " controller"); sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30); try { sshClient.Connect(); } catch { Log("Controller " + Building + " " + Room + " " + Tag + " connection timed out"); return; } Log("Connected to " + Building + " " + Room + " " + Tag + " controller"); Log("Attempting to reboot " + Building + " " + Room + " " + Tag + " controller"); var amxStream = sshClient.CreateShellStream("amxStream", 0, 0, 0, 0, 256); bool streamLockToken = true; var streamTTL = DateTime.Now.Add(TimeSpan.FromSeconds(30)); while (streamLockToken) { if (amxStream.DataAvailable) { streamLockToken = false; } else if (DateTime.Now >= streamTTL) { Log("Controller " + Building + " " + Room + " " + Tag + " connection nonresponsive"); sshClient.Disconnect(); return; } else { System.Threading.Thread.Sleep(0); } } amxStream.WriteLine("reboot"); Log("Reboot " + Building + " " + Room + " " + Tag + " command sent"); sshClient.Disconnect(); } }); }