using System; using System.Text; using System.Collections.Specialized; using Gtk; using Glade; using Novell.CASA; using Novell.SecretStore.NSSSWrapper; namespace GladeSharp2 { /// /// Summary description for Driver. /// class Driver { #region Glade Widgets [Widget] Gtk.Window window1; [Widget] Gtk.TreeView treeview1; [Widget] Gtk.Window addSecretWindow; [Widget] Gtk.Window displaySecretWindow; [Widget] Gtk.Entry entrySecretID; [Widget] Gtk.Entry entryUsername; [Widget] Gtk.Entry entryPassword; [Widget] Gtk.Entry entryNDAP; [Widget] Gtk.Entry entryLDAP; [Widget] Gtk.Entry entryEMAIL; [Widget] Gtk.Entry entryLoginUser; [Widget] Gtk.Entry entryLoginPassword; [Widget] Gtk.Entry entryLoginServer; [Widget] Gtk.Label label11; [Widget] Gtk.Label label22; [Widget] Gtk.Label labelCreated; [Widget] Gtk.Label labelAccessed; [Widget] Gtk.Label labelModified; [Widget] Gtk.TreeView listActivity; [Widget] Gtk.TreeView tvKeyValue; [Widget] Gtk.Statusbar statusbar1; [Widget] Gtk.Image image1; [Widget] Gtk.Entry entryHost; [Widget] Gtk.Entry entryHostPort; [Widget] Gtk.Entry entryServerPort; [Widget] Gtk.Label labelServerStatus; #endregion Novell.CASA.SecretStore ss = Novell.CASA.SecretStore.getInstance(); private RemoteStore m_rs = null; private bool b_isAuthenticated = false; //private RemoteServer m_remoteServer = null; TreeStore tsActivityStore; TreeIter tIter = new TreeIter(); // used for secret list TreeStore store; TreeIter secretIter = new TreeIter(); private static string SHS_PASSWORD = "Password"; private static string SHS_USERNAME = "Username"; private static string SHS_OTHER = "Other"; private static string SHS_BINARY = "Binary"; private static string SHS_CN = "CN"; private static string SHS_DN_LDAP = "DN_LDAP"; private static string SHS_DN_NDAP = "DN_NDAP"; private static string SHS_EMAIL = "EMAIL"; private DateTime date1970 = new DateTime(1970, 1, 1); /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { new Driver(args); } public Driver(string[] args) { Application.Init(); Glade.XML gxml = new Glade.XML (null, "gladesharp1.glade", "window1", null); gxml.Autoconnect (this); treeview1.AppendColumn ("Secrets", new CellRendererText (), "text", 0); store = new TreeStore (typeof (string)); store.SetSortColumnId(0, Gtk.SortType.Ascending); treeview1.Model = store; listActivity.AppendColumn("Demo", new CellRendererText (), "text", 0); tsActivityStore = new TreeStore (typeof (string)); listActivity.Model = tsActivityStore; logActivity("SecretStore Started"); //image1.Pixbuf = new Gdk.Pixbuf (null, "./Bitmap.bmp"); //image1.Pixbuf = "c:/Bitmap.bmp"; showSecrets(); // set Network login id entryLoginUser.Text = "cn="+getNetworkUserID()+",o=novell"; // get config //System.Configuration.ConfigurationSettings.AppSettings.Set("Jim", "Jim Value"); Application.Run(); } private void logActivity(string message) { tsActivityStore.Append (out tIter); tsActivityStore.SetValue (tIter, 0, "[" + DateTime.Now.ToShortTimeString() + "] "+ message); } // Connect the Signals defined in Glade public void on_window1_delete_event (object o, DeleteEventArgs args) { Application.Quit(); args.RetVal = true; } #region Button Click Event handlers protected void on_toolbutton1_clicked(object o, EventArgs args) { return; } protected void on_toolbutton2_clicked(object o, EventArgs args) { FileSelection fDlg = new FileSelection("Choose a File"); fDlg.Modal = true; int nRc = fDlg.Run(); fDlg.Hide(); if(nRc == (int)ResponseType.Ok) { } return; } protected void on_toolbutton3_clicked(object o, EventArgs args) { Application.Quit(); return; } #endregion #region Menu item handlers protected void on_quit1_activate(object o, EventArgs args) { Application.Quit(); return; } protected void on_create_sample_credential1_activate(object o, EventArgs args) { Secret secret = ss.getSecret(0, "SampleCredential", Secret.SS_CREDSET, ""); secret.setKeyValuePair(SHS_CN,"userCN"); secret.setKeyValuePair(SHS_DN_LDAP, "cn=admin,o=novell"); secret.setKeyValuePair(SHS_DN_NDAP, "admin.novell"); secret.setKeyValuePair(SHS_EMAIL, "admin@novell.com"); secret.setKeyValuePair(SHS_PASSWORD, "userPassword"); ss.setSecret(0, secret, Secret.SS_CREDSET); showSecrets(); } protected void on_cut1_activate(object o, EventArgs args) { return; } protected void on_copy1_activate(object o, EventArgs args) { return; } protected void on_delete1_activate(object o, EventArgs args) { return; } protected void on_paste1_activate(object o, EventArgs args) { return; } protected void on_about1_activate(object o, EventArgs args) { System.Text.StringBuilder AuthorStringBuild = new System.Text.StringBuilder (); AuthorStringBuild.Append ("SecretStore Client Version 4.0\n\n"); AuthorStringBuild.Append ("Sample GUI Application.\n"); AuthorStringBuild.Append ("Copyright (c) 2004\n\n"); Gtk.MessageDialog md = new Gtk.MessageDialog ( this.window1, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, AuthorStringBuild.ToString () ); int result = md.Run (); md.Hide(); return; } #endregion // Common functions use by buttons and menu items public void on_button8_clicked(object o, EventArgs args) { Console.WriteLine("Sync Called"); } private void showSecrets() { store.Clear(); StringCollection sc = ss.enumerateSecretIDs(); if (sc != null) { StringEnumerator se = sc.GetEnumerator(); se.Reset(); while (se.MoveNext()) { //listBox2.Items.Add(se.Current); store.Append(out secretIter); store.SetValue(secretIter, 0, se.Current); } } } public void on_button10_clicked (object o, EventArgs args) { showSecrets(); /* for (int i=0; i<10; i++) { store.AppendValues("[ " + System.DateTime.Now.ToString() + " ]"); treeview1.ShowAll(); treeview1.Show(); System.Threading.Thread.Sleep(100); } */ } public void on_btnDeleteSecret_clicked(object o, EventArgs args) { Console.WriteLine("on_btnDeleteSecret_clicked"); TreeModel model; TreeIter iter; string selected = "no selection"; // you get the iter and the model if something is selected if (treeview1.Selection.GetSelected (out model, out iter)) selected = (string) model.GetValue (iter, 0); Console.WriteLine (selected); ss.removeSecret(selected.Substring(11), 2); showSecrets(); } public void on_btnAddSecret_clicked(object o, EventArgs args) { Glade.XML gxml = new Glade.XML (null, "gladesharp1.glade", "addSecretWindow", null); gxml.Autoconnect (this); addSecretWindow.Show(); } public void on_btnOKAddSecret_clicked(object o, EventArgs args) { // add this secret string sSecretID = entrySecretID.Text; if (sSecretID != null && sSecretID.Length > 0) { string sUsername = entryUsername.Text; string sPassword = entryPassword.Text; if ((sUsername != null) && (sPassword != null)) { Secret secret = ss.getSecret(0, sSecretID, Secret.SS_CREDSET, ""); secret.setKeyValuePair(SHS_CN, sUsername); secret.setKeyValuePair(SHS_PASSWORD, sPassword); // get the rest if (entryNDAP.Text != null && entryNDAP.Text.Length > 0) secret.setKeyValuePair(SHS_DN_NDAP, entryNDAP.Text); if (entryLDAP.Text != null && entryLDAP.Text.Length > 0) secret.setKeyValuePair(SHS_DN_LDAP, entryLDAP.Text); if (entryEMAIL.Text != null && entryEMAIL.Text.Length > 0) secret.setKeyValuePair(SHS_EMAIL, entryEMAIL.Text); ss.setSecret(0, secret, Secret.SS_CREDSET); showSecrets(); addSecretWindow.HideAll(); } } else { System.Text.StringBuilder AuthorStringBuild = new System.Text.StringBuilder (); AuthorStringBuild.Append ("You must enter a SecretID\n\n"); Gtk.MessageDialog md = new Gtk.MessageDialog ( this.window1, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.Ok, AuthorStringBuild.ToString () ); int result = md.Run (); md.Hide(); } } public void on_btnCancelAddSecret_clicked(object o, EventArgs args) { addSecretWindow.HideAll(); } public void on_btnEditSecret_clicked(object o, EventArgs args) { // edit the selected secret TreeModel model; TreeIter iter; string selected = null; //"no selection"; // you get the iter and the model if something is selected if (treeview1.Selection.GetSelected (out model, out iter)) selected = (string) model.GetValue (iter, 0); if (selected != null && selected.Length > 0) { selected = selected.Substring(11); Secret secret = ss.getSecret(0, selected, Secret.SS_CREDSET, ""); Glade.XML gxml = new Glade.XML (null, "gladesharp1.glade", "displaySecretWindow", null); gxml.Autoconnect (this); TreeStore storeKeyValue = new TreeStore(typeof (string), typeof (string)); storeKeyValue.SetSortColumnId(0, Gtk.SortType.Ascending); TreeIter iterKV = new TreeIter(); NameValueCollection nvc = secret.getKeyValueCollection(); for (int i=0; i 0) { selected = selected.Substring(11); Secret secret = ss.getSecret(0, selected, Secret.SS_CREDSET, ""); Glade.XML gxml = new Glade.XML (null, "gladesharp1.glade", "addSecretWindow", null); gxml.Autoconnect (this); entrySecretID.Text = selected; entrySecretID.Editable = false; if (secret.getKeyValue("CN") !=null) entryUsername.Text = secret.getKeyValue("CN"); if (secret.getKeyValue("password") !=null) entryPassword.Text = secret.getKeyValue("password"); addSecretWindow.Title = "Edit Secret"; addSecretWindow.Show(); } } public void on_btnRemoveAll_clicked(object o, EventArgs args) { System.Text.StringBuilder AuthorStringBuild = new System.Text.StringBuilder (); AuthorStringBuild.Append ("Remove All\n\n Are you sure?"); Gtk.MessageDialog md = new Gtk.MessageDialog ( this.window1, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo, AuthorStringBuild.ToString () ); int result = md.Run (); md.Hide(); if (result == -8) { //enum the secrets and remove StringCollection sc = ss.enumerateSecretIDs(); if (sc != null) { StringEnumerator se = sc.GetEnumerator(); se.Reset(); while (se.MoveNext()) { ss.removeSecret(se.Current.Substring(11),2); } } showSecrets(); } } private void getRemoteSecrets() { if (b_isAuthenticated) { logActivity("Getting remote secrets"); string[] saSecrets = m_rs.enumerateSecrets(); // add these secrets to our local cache if (saSecrets != null) { if (ss == null) ss = new SecretStore(); for (int i=0; i