public bool CreatePodfile(Podfile podfile, string podfilePath) { if (CancellationToken.IsCancellationRequested) { Log.LogError("Task was canceled."); return(false); } var podfileContents = $"{(podfile.UseFrameworks ? "use_frameworks!" : "")}\n" + $"platform :{podfile.PlatformName}, '{podfile.PlatformVersion}'\n" + $"target '{podfile.TargetName}' do\n"; foreach (var pod in podfile.Pods) { podfileContents += $" pod '{pod.Id}', '{pod.Version}'\n"; } podfileContents += $"end"; Ssh.CreateDirectory(CrossPath.GetDirectoryNameSsh(podfilePath)); using (var stream = Utilities.GetStreamFromText(podfileContents)) { Ssh.CreateFile(stream, podfilePath); } return(true); }
private void FormMain_Load(object sender, EventArgs e) { //Ssh connect if (Ssh.OpenSave()) { //Test database connect using (Database database = new Database()) { if (!database.OpenSave()) { FormSsh formSsh = new FormSsh(); formSsh.ShowDialog(); } } } else { FormSsh formSsh = new FormSsh(); formSsh.ShowDialog(); } //Rfid connect if (!Reader.Rfid.OpenLast()) { FormRfidConnect formRfidConnect = new FormRfidConnect(); formRfidConnect.ShowDialog(); } controlReg.StartLoad(); //test select using (Database database = new Database()) { database.OpenSave(); Reg reg = database.GetRegByNumcard("0005550141"); } }
public List <Category> GetAllCategories() { return(Ssh.executeQuery <List <Category> >(() => { List <Category> catList = new List <Category>(); DataTable table = new DataTable(); var query = "SELECT * FROM category;"; using (MySqlConnection conn = new MySqlConnection(ConnString)) { conn.Open(); using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn)) { adapter.Fill(table); foreach (DataRow row in table.Rows) { catList.Add(new Category() { Id = row.ItemArray[0].ToString(), Name = row.ItemArray[1].ToString() }); } } } return catList; })); }
public int SaveCategory(Category[] catArray) { return(Ssh.executeQuery <int>(() => { var insert = "INSERT INTO category (id, name) "; var values = "VALUES "; int rowsAffected = 0; foreach (var cat in catArray) { values += String.Format(" ( '{0}' , '{1}' ) ", KeyGen.CreateTableID("category"), cat.Name); if (cat != catArray.Last()) { values += ","; } } Debug.WriteLine(values); using (MySqlConnection conn = new MySqlConnection(ConnString)) { conn.Open(); using (MySqlCommand command = new MySqlCommand(insert + values + ";", conn)) { rowsAffected = command.ExecuteNonQuery(); } } return rowsAffected; })); }
public SshModule() : base("/ssh") { //Before += ctx => { // System.Console.WriteLine(Request.Headers.UserAgent); // return null; //}; Get["/authorizedkeys"] = x => { return(JsonConvert.SerializeObject(Application.CurrentConfiguration.Services.Ssh.AuthorizedKey)); }; Get["/publickey"] = x => { return(Response.AsText(Application.CurrentConfiguration.Services.Ssh.PublicKey)); }; Post["/save/authorizedkeys"] = x => { string data = Request.Form.Data; var objects = JsonConvert.DeserializeObject <AuthorizedKey[]>(data); Application.CurrentConfiguration.Services.Ssh.AuthorizedKey = objects; ConfigRepo.Save(); return(HttpStatusCode.OK); }; Post["/apply/authorizedkeys"] = x => { Ssh.SetAuthorizedKey(); return(HttpStatusCode.OK); }; }
public bool RunLipo(string output, IEnumerable <string> inputs) { if (CancellationToken.IsCancellationRequested) { Log.LogError("Task was canceled."); return(false); } inputs = inputs.Select(i => $@"""{i}""").ToArray(); var lipo = $@"lipo -create -output ""{output}"" {string.Join(" ", inputs)}"; var runLipo = Ssh.ExecuteCommand(lipo); if (!Ssh.WasSuccess(runLipo)) { Log.LogError("Error running lipo: " + runLipo.Result); return(false); } else { Log.LogVerbose($"lipo result: {runLipo.Result}"); } return(true); }
public bool RestorePodfile(string podfileRoot, bool?noRepoUpdate) { if (CancellationToken.IsCancellationRequested) { Log.LogError("Task was canceled."); return(false); } var restore = $@"""{PodToolPath}"" install" + $@" --no-integrate" + $@" --project-directory=""{podfileRoot}""" + $@" {(noRepoUpdate == true ? "--no-repo-update" : "")}"; var restorePods = Ssh.ExecuteCommandStream(restore, contents => { foreach (var line in Utilities.SplitLines(contents)) { if (line.Trim().StartsWith("[!]")) { Log.LogError(line); } } }); if (!Ssh.WasSuccess(restorePods)) { Log.LogError("Error installing the podfile."); return(false); } return(true); }
private void buttonSave_Click(object sender, EventArgs e) { if (Ssh.isOpen()) { Ssh.Close(); } if (!Ssh.Open( textBoxSshIp.Text, textBoxSshLogin.Text, textBoxSshPassword.Text, textBoxSshBoundHost.Text, (uint)numericUpDownSshBoundPort.Value, textBoxSshHost.Text, (uint)numericUpDownSshPort.Value)) { if (MessageBox.Show( "Ошибка подключения по SSH:\n'" + Ssh.lastErrorMeassage + "'\nВсё равно сохранить?", "Тестовое подключение по SSH", MessageBoxButtons.YesNo, MessageBoxIcon.Error) != DialogResult.Yes) { return; } } Properties.Settings.Default.SshIp = Encryption.EncryptString(textBoxSshIp.Text); Properties.Settings.Default.SshLogin = Encryption.EncryptString(textBoxSshLogin.Text); Properties.Settings.Default.SshPassword = Encryption.EncryptString(textBoxSshPassword.Text); Properties.Settings.Default.SshBoundHost = textBoxSshBoundHost.Text; Properties.Settings.Default.SshBoundPort = (uint)numericUpDownSshBoundPort.Value; Properties.Settings.Default.SshHost = textBoxSshHost.Text; Properties.Settings.Default.SshPort = (uint)numericUpDownSshPort.Value; Properties.Settings.Default.Save(); this.Close(); }
public void Dispose() { Ssh.Disconnect(); Ssh.Dispose(); Sftp.Disconnect(); Sftp.Dispose(); }
private void toolStripMenuItemSshChange_Click(object sender, EventArgs e) { Ssh.Close(); FormSsh formSsh = new FormSsh(); formSsh.ShowDialog(); }
public void Dispose() { forwardRemote.Stop(); forwardLocal.Stop(); Ssh.Disconnect(); Ssh.Dispose(); Sftp.Disconnect(); Sftp.Dispose(); }
public DeviceController( ClientConnectionsRepository clientConnections, AppSettings settings, Ssh ssh) { this.clientConnections = clientConnections; this.settings = settings; this.ssh = ssh; }
public void Connect() { if (IsConnected) { throw new Exception("Already connected!"); } Ssh.Connect(); Sftp.Connect(); IsConnected = true; }
private void buttonConnexion_Click(object sender, System.EventArgs e) { if (Ssh.IsConnected) { Ssh.Disconnect(); } else { Ssh.Connect(); } }
private void Command() { Ssh.SendCommand( "find " + _path + GenereTypeCommande(roundedCheckboxDossiers.State, roundedCheckboxFichiers.State) + " -exec du -S {} + | sort -rh | head -n " + _resultNumber, GereEspace, 1 ); }
public DeveloperController( Ssh ssh, ClientConnectionsRepository clientConnectionsRepository, DeveloperAuthorizationsRepository developerAuthorizationsRepository, DeviceRequestsRepository deviceRequestsRepository) { this.ssh = ssh; this.developerAuthorizationsRepository = developerAuthorizationsRepository; this.deviceRequestsRepository = deviceRequestsRepository; this.clientConnectionsRepository = clientConnectionsRepository; }
private bool ConnectSsh(string hostAddrs, string userName, string password, ref string reply, ref Ssh ssh) { ssh = new Ssh(); ssh.Subscribe(OnIncomingSsh); if (ssh.Connect(hostAddrs, userName, password, ref reply)) { ssh.CreateShellStream("terminal", 80, 24, 800, 600, 1024); //TODO: CHANGE THIS ACCORDING TO WINDOW SIZE, FOR LONG LINES PRINTING return(true); } return(false); }
private void pictureBoxSsh_MouseDown(object sender, MouseEventArgs e) { if (Ssh.isOpen()) { contextMenuStripSshOpen.Show(pictureBoxSsh, pictureBoxSsh.Location.X + 35, pictureBoxSsh.Location.Y - 58); } else { FormSsh formSsh = new FormSsh(); formSsh.ShowDialog(); } }
public Repartition() { InitializeComponent(); _nom = new List <string>(); Ssh.SendCommand("df", ListePartitions, 0); _path = "/volumeUSB1/usbshare/"; _resultNumber = 100; Command(); }
private void CheckActiveDeviceConnections() { List <string> deactivatedClients = new List <string>(); using (sshondemandContext dbContext = new sshondemandContext()) { ClientConnectionsRepository clientConnections = new ClientConnectionsRepository(dbContext); clientConnections.ResetOldConnections(15, out deactivatedClients); } Ssh ssh = new Ssh(settings); ssh.UnloadClientKeys(deactivatedClients); }
private void CheckActiveDeveloperRequests() { List <string> deactivatedClientNames = new List <string>(); using (sshondemandContext dbContext = new sshondemandContext()) { DeviceRequestsRepository deviceRequestsRepository = new DeviceRequestsRepository(dbContext); deviceRequestsRepository.DeactivateOldDeviceRequests(15, out deactivatedClientNames); } Ssh ssh = new Ssh(settings); ssh.UnloadClientKeys(deactivatedClientNames); }
protected override void RunOperations() { try { channel = Ssh.GetChannel(command); channel.setErrStream(new TextStream(stdErr)); channel.setOutputStream(new TextStream(stdOut)); channel.connect(); while (!channel.isEOF()) { Thread.Sleep(200); } channel.disconnect(); } finally { ExitCode = channel.getExitStatus(); } }
private static void ManageSsh() { if (RunningConfiguration.Services.Sshd.Active) { Sshd.Set(); } if (string.IsNullOrEmpty(RunningConfiguration.Services.Ssh.PublicKey)) { Ssh.CreateRootKeys(); } CurrentConfiguration.Services.Ssh.PublicKey = Ssh.GetRootPublicKey(); CurrentConfiguration.Services.Ssh.PrivateKey = Ssh.GetRootPrivateKey(); RunningConfiguration.Services.Ssh.PublicKey = Ssh.GetRootPublicKey(); RunningConfiguration.Services.Ssh.PrivateKey = Ssh.GetRootPrivateKey(); ConsoleLogger.Log("[ssh] ready"); }
public bool CreatePodfileXCodeProject(string podfileRoot, Podfile podfile, bool?noRepoUpdate = null) { if (CancellationToken.IsCancellationRequested) { Log.LogError("Task was canceled."); return(false); } var podfilePath = CrossPath.CombineSsh(podfileRoot, "Podfile"); var podfileLockPath = CrossPath.CombineSsh(podfileRoot, "Podfile.lock"); // see if we can avoid updating the master repo noRepoUpdate = noRepoUpdate == true || (noRepoUpdate == null && Ssh.FileExists(podfileLockPath)); // create and restore a Podfile return(CreatePodfile(podfile, podfilePath) && RestorePodfile(podfileRoot, noRepoUpdate)); }
public ReturnBox RunRemote(string cmd, int timeout_secs = 3600) { ReturnBox r = new ReturnBox(); if (Connected) { try { SshCommand command = Ssh.CreateCommand(cmd); command.CommandTimeout = TimeSpan.FromSeconds(timeout_secs); r.Output = command.Execute(); r.Error = command.Error; r.ExitCode = command.ExitStatus; } catch (Exception ex) { r.Error = ex.Message; } } r.Success = r.ExitCode == 0 && String.IsNullOrEmpty(r.Error); return(r); }
static void Main(string[] args) { General.ApplicationHeader(true); LoadArgs(args); if (!DataFiles.LoadConfig()) { return; } try { Ssh ssh = new Ssh(); Thread tt = new Thread(new ThreadStart(ssh.ProptForCommands)); tt.Start(); while (WaitHandle.WaitAny(Defs.EventMonitor) != (int)EVENT_MON.SHUTDOWN) { ; } DateTime startDate = DateTime.UtcNow; //give it 3 seconds, if still running. while (tt.IsAlive && tt.ThreadState == ThreadState.Running && DateTime.UtcNow.Subtract(startDate).TotalSeconds < 3) { Thread.Sleep(1000); } //kill the thread if still alive. if (tt.IsAlive && tt.ThreadState == ThreadState.Running) { tt.Abort(); } } finally { Log.Verbose("Thread Closed..", ConsoleColor.DarkYellow); } }
public void TC001_TestSSH() { //Arrange string fileContent = File.ReadAllText("settings.json"); Config.Setup(JsonConvert.DeserializeObject(fileContent), false); Ssh ssh = new Ssh(); string sshMessage = string.Format( @"[""setup"", {{ ""user"":""uSr12{0}"", ""public_key"": ""ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCr8DjwYoyfnhth18sfS8FBd+sjLZ8TShaHmWYTUKLqsVs/XR35ZKDrzwwEsDCva01drwQr3/ynkznVdycCnqi9cSRA+f1McOlKU9KGLEFx8tusRpQbOkF8bmFJqdG9BZBZnN6wEI+s1n8vU1xjWjM1vw/Wc1ad+VuKd3wCvgCC8waUCug47+OxDJtSH088Ex2WzZ59o6JVBl6v4PHWeKuaUYkndTgpQxmDZd3Z9q1TbGOxdmt6JVRvL43QUXSiOJfvvszKVxk0TU1dtYvNDd9JyST7988RezEPHxVeBdVbSJDeV/logaRGyZwGO6DpTP1hObXRD/gxoirTJ/k41n3L root@ubuntu"", ""password"":""Pa123!{1}"" }}]", Uhuru.Utilities.Credentials.GenerateCredential(), Uhuru.Utilities.Credentials.GenerateCredential()); //Act SshResult result = ssh.Process(JsonConvert.DeserializeObject(sshMessage)) as SshResult; //Assert Assert.AreEqual("success", result.Status.ToLower()); }
public void Connect() { lock (this) { if (IsConnected) { throw new Exception("Already connected!"); IsConnected = true; } } Ssh.Connect(); Sftp.Connect(); var forwardLocal = new ForwardedPortLocal("127.0.0.1", MonoEngine.MonoDebuggerPort, "127.0.0.1", MonoEngine.MonoDebuggerPort); var forwardRemote = new ForwardedPortRemote("127.0.0.1", MonoEngine.MonoDebuggerPort, "127.0.0.1", MonoEngine.MonoDebuggerPort); Ssh.AddForwardedPort(forwardLocal); Ssh.AddForwardedPort(forwardRemote); forwardLocal.Exception += (sender, e) => { throw e.Exception; }; forwardRemote.Exception += (sender, e) => { throw e.Exception; }; forwardLocal.Start(); forwardRemote.Start(); }
void testButtonClick(object sender, EventArgs e) { Ssh ssh = new Ssh(); SshSetForm startForm = new SshSetForm(); DialogResult result = startForm.ShowDialog(); if (result == DialogResult.OK) { ssh.HostName = startForm.SshHostName; ssh.Port = startForm.SshPort; ssh.UserName = startForm.SshUserName; ssh.Password = startForm.SshPassword; ssh.PrivateKey = startForm.SshPrivateKey; ssh.AuthPassOrKey = startForm.SshPassOrKey; } using (var sshClient = new SshClient(ssh.ConnectionInfo)){ System.Diagnostics.Debug.WriteLine(sshClient); sshClient.Connect(); if (sshClient.IsConnected) { using (var cmd = sshClient.CreateCommand("ls")) { Console.WriteLine(cmd.Execute()); Console.WriteLine(cmd.Error); Console.WriteLine(cmd.Result); Console.WriteLine(cmd.ExitStatus); } } else { Console.WriteLine("Connection Error"); return; } sshClient.Disconnect(); } }
public override Server creack(string ip, int port, string username, string password, int timeOut) { Ssh ssh = new Ssh(); Server server = new Server(); ssh.Timeout = timeOut * 1000; try { ssh.Connect(ip); if (ssh.IsConnected) { ssh.Login(username, password); if (ssh.IsAuthenticated) { server.isSuccess = true; server.banner = ssh.ServerKey.Comment; } } } catch (Exception e) { if (e.Message.IndexOf("incorrect") != -1) { return(server); } else { throw e; } } finally { ssh.Disconnect(); } return(server); }