2 using System.Collections.Generic;
9 public partial class MainWindow: Gtk.Window
11 private const string new_text = "new ...";
12 private IMCloudAwk MCA;
14 public MainWindow (): base (Gtk.WindowType.Toplevel)
17 this.MCA = new MCloudMgr ();
18 TConnection[] Conns = MCA.GetConnections ();
19 foreach (var Conn in Conns) {
20 this.ConnectionSelection.AppendText (Conn.Name);
22 this.ConnectionSelection.AppendText (new_text);
23 this.ConnectionSelection.Active = 0;
26 protected void OnDeleteEvent (object sender, DeleteEventArgs a)
33 protected void TestButtonPressed (object sender, EventArgs e)
35 // extract connection name
36 string connection_name = this.ConnectionSelection.ActiveText;
38 // TODO: implement ssh connection test
39 int r = this.MCA.TestConnection (connection_name);
41 if (r == MCloudMgr.SSH_NO_PW || r == MCloudMgr.SSH_WITH_PW) {
44 GtkUtil.MessageBox.Show("Keine ssh-Verbindung möglich");
48 // if connection is new, add it to configuration
49 if (connection_name == new_text) {
51 // build connection object
52 connection_name = this.UserField.Text + "@" + this.ServerField.Text;
53 TConnection C = new TConnection {
54 Name = connection_name,
55 User = this.UserField.Text,
56 Server = this.ServerField.Text,
57 Password = this.PasswordField.Text
59 this.MCA.AddConnection (C);
62 // TODO: check login w/o password
63 bool login_without_password_possible = false;
65 if (!login_without_password_possible) {
67 // check existence of public key file
68 if (!System.IO.File.Exists ("/home/monodev/.ssh/id_dsa.pub")) {
70 // TODO: create public key file
71 using (System.IO.StreamWriter File = new System.IO.StreamWriter ("/home/monodev/.ssh/id_dsa.pub", false)) {
72 File.WriteLine ("Hallo");
75 // TODO: scp file to target
76 // TODO: append it to .ssh/authorized_keys
77 // TODO: test login w/o password again
79 // TODO: next configution step
82 DirectorySelectionWin DirWin = new DirectorySelectionWin ();
87 protected void ConnectionSelectionChanged (object sender, EventArgs e)
89 if (((Gtk.ComboBox)sender).ActiveText.IndexOf ('@') > 0) {
91 this.ServerField.Sensitive = false;
92 this.PasswordField.Sensitive = false;
93 this.UserField.Sensitive = false;
95 // activate delete button
96 this.DeleteConnectionBtn.Sensitive = true;
98 // activate input fields
99 this.ServerField.Sensitive = true;
100 this.PasswordField.Sensitive = true;
101 this.UserField.Sensitive = true;
103 // deactivate delete button
104 this.DeleteConnectionBtn.Sensitive = false;
108 protected void DeleteConnectionPressed (object sender, EventArgs e)
110 string connection = this.ConnectionSelection.ActiveText;
111 if (this.ConnectionSelection.ActiveText.IndexOf ('@') == -1)
112 throw new Exception ("Cannot remove default entry");
113 int connPos = this.ConnectionSelection.Active;
114 this.ConnectionSelection.Active = connPos+1;
115 this.ConnectionSelection.RemoveText (connPos);
116 this.MCA.DeleteConnection (connection);