// // OpenVPN Administrator // // Author(s): Everaldo Canuto // // (C) 2006 Everaldo Canuto // (C) 2006 The Gang // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // using System; using Mono.Unix; using Gtk; using Glade; using System.IO; namespace OpenVPN.Admin { public class CertForm : BaseDialog { #region Fields [Widget] Image imageLogo; [Widget] Button buttonCreate; //[Widget] Button buttonClose; [Widget] Notebook notebookArea; [Widget] Entry entryName; [Widget] Entry entryKeySize; [Widget] Entry entryEMail; [Widget] Entry entryCountry; [Widget] Entry entryState; [Widget] Entry entryCity; [Widget] Entry entryOrganization; [Widget] Entry entryUnit; [Widget] Entry entryPassPhrase; [Widget] Entry entryPassAgain; [Widget] Entry entryFolder; // Page 2 [Widget] Label labelKey; [Widget] Label labelReq; [Widget] TextView textRequest; #endregion #region Constructors and destructors public CertForm() { InitializeComponent("certForm"); Window.Icon = Gdk.Pixbuf.LoadFromResource("certificate.png"); imageLogo.Pixbuf = Gdk.Pixbuf.LoadFromResource("certificate.png"); // notebookArea notebookArea.CurrentPage = 0; notebookArea.ShowTabs = false; // Event handler. entryName.Changed += new EventHandler(on_entry_changed); entryKeySize.Changed += new EventHandler(on_entry_changed); entryEMail.Changed += new EventHandler(on_entry_changed); entryCountry.Changed += new EventHandler(on_entry_changed); entryState.Changed += new EventHandler(on_entry_changed); entryCity.Changed += new EventHandler(on_entry_changed); entryOrganization.Changed += new EventHandler(on_entry_changed); entryUnit.Changed += new EventHandler(on_entry_changed); entryPassPhrase.Changed += new EventHandler(on_entry_changed); entryPassAgain.Changed += new EventHandler(on_entry_changed); entryFolder.Changed += new EventHandler(on_entry_changed); } #endregion #region Private methods private void on_entry_changed(object o, EventArgs args) { // Disable Create button if fields is empty. buttonCreate.Sensitive = ((entryName.Text.Trim().Length > 0) && (entryEMail.Text.Trim().Length > 0) && (entryCountry.Text.Trim().Length > 0) && (entryState.Text.Trim().Length > 0) && (entryCity.Text.Trim().Length > 0) && //(entryOrganization.Text.Trim().Length > 0) && //(entryUnit.Text.Trim().Length > 0) && //(entryPassPhrase.Text.Trim().Length > 0) && //(entryPassAgain.Text.Trim().Length > 0) && (entryFolder.Text.Trim().Length > 0)); } public void on_create_clicked(object o, EventArgs args) { try { if (entryPassPhrase.Text != entryPassAgain.Text) throw new Exception(Catalog.GetString("Passphrase and Passphrase (Again) need to be the same.")); if (entryCountry.Text.Length < 2) throw new Exception(Catalog.GetString("Country need to have 2 chars.")); string fileprefix = entryName.Text.Trim().Replace(" ", "_"); Certificate cert = new Certificate(); cert.Name = entryName.Text; cert.KeySize = entryKeySize.Text; cert.EMail = entryEMail.Text; cert.Country = entryCountry.Text; cert.State = entryState.Text; cert.City = entryCity.Text; cert.Organization = entryOrganization.Text; cert.Unit = entryUnit.Text; cert.Passphrase = entryPassPhrase.Text; cert.Path = entryFolder.Text; cert.FilePrefix = fileprefix; cert.Make(); labelKey.Text = System.IO.Path.GetFileName(cert.KeyFile); labelReq.Text = System.IO.Path.GetFileName(cert.RequestFile); textRequest.Buffer.Text = File.OpenText(cert.RequestFile).ReadToEnd();; notebookArea.CurrentPage = 1; buttonCreate.Hide(); } catch (Exception e) { ErrorBox(e.Message); } } #endregion } }