Exemplo n.º 1
0
        void CreateUserButton_Click(object sender, EventArgs e)
        {
            try
            {
                Directory.CreateDirectory(CacheDir.Path + Path.DirectorySeparatorChar + UserFile);

                if (File.Exists(UserPath))
                {
                    StatusLabel.Text = "User already created";
                    return;
                }

                StatusLabel.Text = "Creating user...";

                OpUser.CreateNew(UserPath, OpName, Username, Password, AccessType.Secret, null, true);

                StatusLabel.Text = "User created";
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Create error: " + ex.Message;
            }
        }
Exemplo n.º 2
0
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            // check input data
            try
            {
                ValidateFields();


                // check if file exists
                string filename = OpName + " - " + TextName.Text;

                string path = BrowseLink.Text + Path.DirectorySeparatorChar +
                              filename + Path.DirectorySeparatorChar +
                              filename + ".dop";

                Directory.CreateDirectory(BrowseLink.Text + Path.DirectorySeparatorChar + filename);

                if (File.Exists(path))
                {
                    // A profile for test - swax already exists, overwrite? Yes / No / Cancel
                    DialogResult result = MessageBox.Show("A profile for " + filename + " already exists. Overwrite?", "Overwrite?", MessageBoxButtons.YesNoCancel);

                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (result == DialogResult.No)
                    {
                        Close();
                        return;
                    }

                    // All data for test - swax will be lost OK/Cancel
                    result = MessageBox.Show("Are you sure? All previous data will be lost for " + filename, "Overwrite?", MessageBoxButtons.YesNo);

                    if (result == DialogResult.No)
                    {
                        return;
                    }

                    Directory.Delete(Path.GetDirectoryName(path), true);
                }

                byte[] opKey = null;

                if (Invite != null)
                {
                    opKey = Invite.Info.OpID;
                }

                OpUser.CreateNew(path, OpName, TextName.Text, TextPassword.Text, OpAccess, opKey, GlobalIM);

                var ui = App.LoadCore(path, TextPassword.Text);

                if (Invite != null)
                {
                    ui.Core.ProcessInvite(Invite);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
Exemplo n.º 3
0
        private bool DoGenerate()
        {
            // load last / male / female names
            List <string> LastNames  = ReadNames(NamesFolderLink.Text + Path.DirectorySeparatorChar + "names_last.txt");
            List <string> FirstNames = ReadNames(NamesFolderLink.Text + Path.DirectorySeparatorChar + "\\names_first.txt");
            List <string> OpNames    = ReadNames(NamesFolderLink.Text + Path.DirectorySeparatorChar + "\\names_ops.txt");

            if (UsersNumeric.Value > LastNames.Count || UsersNumeric.Value > FirstNames.Count)
            {
                MessageBox.Show("Only " + FirstNames.Count.ToString() + " first and " + LastNames.Count.ToString() + " last names loaded");
                return(false);
            }

            if (OrgNumeric.Value > OpNames.Count)
            {
                MessageBox.Show("Only " + OpNames.Count.ToString() + " orgs loaded");
                return(false);
            }

            int users = (int)UsersNumeric.Value;
            int orgs  = (int)OrgNumeric.Value;

            List <byte[]> OpKeys = new List <byte[]>();

            for (int i = 0; i < orgs; i++)
            {
                RNGCryptoServiceProvider rnd = new RNGCryptoServiceProvider();
                OpKeys.Add(Utilities.GenerateKey(rnd, 256));
            }

            Directory.CreateDirectory(OutputFolderLink.Text);

            // choose random name combos to create profiles for
            string name = "";

            GenProgress.Value   = 0;
            GenProgress.Maximum = users;

            for (int i = 0; i < users; i++)
            {
                name = FirstNames[Rnd.Next(FirstNames.Count)] + " " + LastNames[Rnd.Next(LastNames.Count)];

                // create profile
                int index = Rnd.Next(0, orgs);

                string filename = OpNames[index] + " - " + name;
                string path     = OutputFolderLink.Text + Path.DirectorySeparatorChar + filename + Path.DirectorySeparatorChar + filename + ".dop";
                Directory.CreateDirectory(OutputFolderLink.Text + Path.DirectorySeparatorChar + filename);
                string password = name.Split(' ')[0].ToLower(); // lower case first name is password

                var access = SecretNetworkCheckBox.Checked ? AccessType.Secret : AccessType.Private;

                OpUser.CreateNew(path, OpNames[index], name, password, access, OpKeys[index], false);

                if (CreateGlobal.Checked)
                {
                    filename = "Global IM - " + name;
                    path     = OutputFolderLink.Text + Path.DirectorySeparatorChar + filename + Path.DirectorySeparatorChar + filename + ".dop";
                    Directory.CreateDirectory(OutputFolderLink.Text + Path.DirectorySeparatorChar + filename);
                    OpUser.CreateNew(path, "Global IM", name, password, AccessType.Secret, null, true);
                }

                GenProgress.Value++;
            }

            return(true);
        }