Example #1
0
        public override void Run(KExplorerNode folder)
        {
            KExplorerNode parentNode = (KExplorerNode)folder.Parent;

            if (parentNode == null)
            {
                MessageBox.Show("Can't backup drives", "Error: Backup Folder", MessageBoxButtons.OK);
                return;
            }

            string backupFolderName = QuickDialog.DoQuickDialog("Backup Copy of Folder"
                                                                , "Enter name of new backup folder"
                                                                , folder.DirInfo.Name + ".bak");

            if (backupFolderName != null)
            {
                if (backupFolderName.Length == 0)
                {
                    MessageBox.Show("Name can't be empty.", "Error: Backup Folder", MessageBoxButtons.OK);
                }
                else
                {
                    DirectoryInfo backupFolder = parentNode.DirInfo.CreateSubdirectory(backupFolderName);


                    this.TransferFilesAndFolders(folder.DirInfo, backupFolder);


                    this.ScriptHelper.RefreshFolder(parentNode, true);
                }
            }
        }
Example #2
0
        public override void Run(KExplorerNode folder)
        {
            string newDir = QuickDialog.DoQuickDialog("Make Directory", "Sub-folder of: " + folder.DirInfo.Name
                                                      , "");

            if (newDir != null)
            {
                if (newDir.Length == 0)
                {
                    newDir = QuickDialog.DoQuickDialog("Make Directory"
                                                       , "Folder can't be empty. Use Cancel to abort"
                                                       , "");
                }
                if (newDir != null && newDir.Length > 0)
                {
                    // Go ahead and make the directory.

                    try
                    {
                        folder.DirInfo.CreateSubdirectory(newDir);
                    }
                    catch (Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show("Exception: " + e.Message
                                                             , "Make Direory error"
                                                             , MessageBoxButtons.OK);
                    }

                    this.ScriptHelper.RefreshFolder(folder, true);
                }
            }
        }
Example #3
0
        public override void Run(KExplorerNode folder)
        {
            string newName = QuickDialog.DoQuickDialog("Rename Folder", "New Name", folder.DirInfo.Name);

            if (newName != null && newName.Length > 0)
            {
                if (!newName.Equals(folder.DirInfo.Name))
                {
                    string x = folder.DirInfo.Parent.FullName + "\\" + newName;
                    folder.DirInfo.MoveTo(x);


                    this.ScriptHelper.RefreshFolder(folder, true);
                }
            }
        }
Example #4
0
        public override void Run(KExplorerNode folder, FileInfo[] files)
        {
            if (files == null || files.Length > 1)
            {
                return;
            }
            string newName = QuickDialog.DoQuickDialog("Rename Folder", "New Name", files[0].Name);

            if (newName != null && newName.Length > 0)
            {
                if (!newName.Equals(files[0].Name))
                {
                    string x = files[0].DirectoryName + "\\" + newName;
                    files[0].MoveTo(x);


                    this.ScriptHelper.RefreshFolder(folder, false);
                }
            }
        }
Example #5
0
        public override void Run(KExplorerNode folder)
        {
            string newZipName = QuickDialog.DoQuickDialog("Create Zip"
                                                          , "Zip Name"
                                                          , "..\\" + folder.Text);


            if (newZipName != null && newZipName.Length > 0)
            {
                if (!newZipName.ToLower().EndsWith(".zip"))
                {
                    newZipName = newZipName + ".zip";
                }


                this.ScriptHelper.RunProgram(@"7z.exe"
                                             , "a -tzip " + "\"" + newZipName + "\" -r \"" + folder.DirInfo.FullName + "\""
                                             , folder);
            }
        }
Example #6
0
        public override void Run(KExplorerNode folder, FileInfo[] files)
        {
            string newZipName = QuickDialog.DoQuickDialog("Create Zip"
                                                          , "Zip Name"
                                                          , "..\\" + folder.Text);


            if (newZipName != null && newZipName.Length > 0)
            {
                if (!newZipName.ToLower().EndsWith(".zip"))
                {
                    newZipName = newZipName + ".zip";
                }

                string listfile = Application.StartupPath + "\\zipfilelist.lst";

                this.BuildListFile(listfile, files);


                this.ScriptHelper.RunProgram(@"7z.exe"
                                             , "a -tzip " + "\"" + newZipName + "\" @\"" + listfile + "\""
                                             , folder);
            }
        }
Example #7
0
        public override void Run(KExplorerNode folder)
        {
            string searchString = QuickDialog.DoQuickDialog("WinGrep Search", "Search String");

            if (searchString == null)
            {
                return;
            }

            string       parFileName = Application.StartupPath + "\\wingrepinput.par";
            StreamWriter parFile     = File.CreateText(parFileName);


            parFile.Write("[General Search Parameters]\n");
            parFile.Write("Search String=" + searchString + "\n");

            parFile.Write("Skip Text Files=False\n");
            parFile.Write("Skip Binary Files=True\n");
            parFile.Write("Recurse Subdirectories=True\n");
            parFile.Write("Count Files First=False\n");


            parFile.Write("[Active File Specifications]\n");

            IList <String> extensions = this.ScriptHelper.GetValueList("//WinGrepExt");

            if (extensions != null && extensions.Count > 0)
            {
                int i = 0;

                foreach (String x in extensions)
                {
                    parFile.Write(i.ToString() + "=*." + x + "\n");
                    i++;
                }
            }
            else
            {
                parFile.Write("0=*.cs\n");
                parFile.Write("1=*.txt\n");
                parFile.Write("2=*.xml\n");
                parFile.Write("3=*.java\n");
                parFile.Write("4=*.csproj\n");
                parFile.Write("5=*.sln\n");
                parFile.Write("6=*.mak\n");
                parFile.Write("7=*.xslt\n");
                parFile.Write("8=*.php\n");
                parFile.Write("9=*.php5\n");
                parFile.Write("10=*.h\n");
                parFile.Write("11=*.cpp\n");
                parFile.Write("12=*.inc\n");
                parFile.Write("13=*.*66\n");
                parFile.Write("14=*.sql\n");
                parFile.Write("15=*.otl\n");
                parFile.Write("16=*.config\n");
                parFile.Write("17=*.aspx\n");
                parFile.Write("18=*.ascx\n");
                parFile.Write("19=*.properties\n");
            }


            parFile.Write("[Active Directory Specifications]\n");
            parFile.Write("0=" + folder.DirInfo.FullName + "\n");

            parFile.Flush();

            parFile.Close();



            this.ScriptHelper.RunProgram(@"grep32.exe"
                                         , "-F" + parFileName
                                         , folder);
        }
        public override void Run(KExplorerNode folder, FileInfo[] files)
        {
            while (true)
            {
                string[] checkName = QuickDialog2.DoQuickDialog(
                    "AccountRepo Check", "UserId", "", "Password (optional)", "");


                if (checkName == null)
                {
                    return;
                }


                string filePath;
                byte[] ciphertext = null;


                try
                {
                    filePath = files[0].FullName;

                    FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        ciphertext = reader.ReadBytes((int)fileStream.Length);
                    }

                    byte[] plaintext = null;

                    IOlympCryptography olympCryptography = new OlympCryptography();
                    plaintext = olympCryptography.Decrypt(ciphertext, new CompressStreamReaderDelegate(CompressStreamReader));


                    string reallyPlain = System.Text.UTF8Encoding.UTF8.GetString(plaintext);


                    XmlDocument doc = new XmlDocument();


                    // Seems sometimes in the encoding, we get a garbage character at the beginning.
                    if (reallyPlain.StartsWith("<"))
                    {
                        doc.LoadXml(reallyPlain);
                    }
                    else
                    {
                        doc.LoadXml(reallyPlain.Substring(1));
                    }



                    // If user enters nothing.  Give him a message box of all the user ids.
                    if (checkName[0].Trim().Length == 0)
                    {
                        StringBuilder names     = new StringBuilder();
                        XmlNodeList   nameNodes = doc.SelectNodes("//UserState[@StateKey='PasswordHash']");

                        foreach (XmlNode nameNode in nameNodes)
                        {
                            string  userId      = nameNode.Attributes["UserId"].Value;
                            XmlNode lockedState = doc.SelectSingleNode("//UserState[@StateKey='Locked' and @UserId='" + userId + "']");

                            bool locked = lockedState.Attributes["StateValue"].Value.Equals("True");


                            names.Append(userId + ((locked) ? " (locked);" : "; "));
                        }
                        if (MessageBox.Show(names.ToString(), "User ID's", MessageBoxButtons.OKCancel)
                            == DialogResult.Cancel)
                        {
                            return;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    // They entered a name and a password.  check it.  check it for locked.  If locked, prompt to unluck.
                    else
                    {
                        XmlNode nameNode =
                            doc.SelectSingleNode("//UserState[@StateKey='PasswordHash' and @UserId='" + checkName[0] + "']");

                        if (nameNode == null)
                        {
                            if (MessageBox.Show("User Not Found", "USer not found" + checkName[0], MessageBoxButtons.OKCancel)
                                == DialogResult.Cancel)
                            {
                                return;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        XmlNode userNode = doc.SelectSingleNode("//User[@UserId='" + checkName[0] + "']");

                        KeyedHashAlgorithm hashAlgorithm = KeyedHashAlgorithm.Create("HMACSHA1");

                        // we use the user ID as the "secret" key :-)
                        hashAlgorithm.Key = System.Text.Encoding.Default.GetBytes(checkName[0]);

                        string storedHash = nameNode.Attributes["StateValue"].Value;

                        if (checkName[1].Trim().Length > 0)
                        {
                            // compute the hash code
                            byte[] hash = hashAlgorithm.ComputeHash(System.Text.Encoding.Default.GetBytes(checkName[1]));

                            string passHash = Convert.ToBase64String(hash);


                            //EndOfValidity="2009-01-09T18:59:00.0000000"
                            if (userNode.Attributes["EndOfValidity"] != null)
                            {
                                string validityEnd = userNode.Attributes["EndOfValidity"].Value;

                                DateTime dt = Convert.ToDateTime(validityEnd);
                                if (dt < DateTime.Now)
                                {
                                    DialogResult dr = MessageBox.Show("Expired:" + validityEnd + ", Extend out one year?"
                                                                      , "AccountRepo Helper", MessageBoxButtons.YesNoCancel);
                                    if (dr == DialogResult.Cancel)
                                    {
                                        return;
                                    }
                                    else if (dr == DialogResult.Yes)
                                    {
                                        DateTime newDT       = DateTime.Now.AddYears(1);
                                        string   newValidity = newDT.ToString("yyyy-MM-dd");



                                        userNode.Attributes["EndOfValidity"].Value = newValidity;


                                        MemoryStream ms = new MemoryStream();

                                        doc.Save(ms);

                                        ciphertext = olympCryptography.Encrypt(ms.GetBuffer()
                                                                               , new CompressStreamWriterDelegate(CompressStreamWriter));


                                        fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                                        using (BinaryWriter writer = new BinaryWriter(fileStream))
                                        {
                                            writer.Write(ciphertext, 0, ciphertext.Length);
                                            writer.Flush();
                                        }
                                    }
                                }
                            }

                            // User entered correct password.  Let's go the extra mile and see if the user is locked
                            // expired.. If so, let's force unlock the user.
                            XmlNode lockedState = doc.SelectSingleNode("//UserState[@StateKey='Locked' and @UserId='" + checkName[0] + "']");

                            bool locked = lockedState.Attributes["StateValue"].Value.Equals("True");

                            if (!passHash.Equals(storedHash))
                            {
                                string newPass = QuickDialog.DoQuickDialog("Force new password", "New Password (blank=no change)", "");

                                if (newPass == null)
                                {
                                    return;
                                }
                                else if (newPass.Trim().Length > 0)
                                {
                                    hash = hashAlgorithm.ComputeHash(System.Text.Encoding.Default.GetBytes(checkName[1]));

                                    passHash = Convert.ToBase64String(hash);

                                    nameNode.Attributes["StateValue"].Value = passHash;

                                    MemoryStream ms = new MemoryStream();

                                    doc.Save(ms);

                                    ciphertext = olympCryptography.Encrypt(ms.GetBuffer()
                                                                           , new CompressStreamWriterDelegate(CompressStreamWriter));


                                    fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                                    {
                                        writer.Write(ciphertext, 0, ciphertext.Length);
                                        writer.Flush();
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (!locked)
                            {
                                if (MessageBox.Show("PW IS GOOD for " + checkName[0] + " and locked=" + locked.ToString(),
                                                    "AccountRepo help", MessageBoxButtons.OKCancel)
                                    == DialogResult.Cancel)
                                {
                                    return;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                DialogResult dr = MessageBox.Show("User is locked.  unlock?", "AccountRepo Help", MessageBoxButtons.YesNoCancel);

                                if (dr == DialogResult.Cancel)
                                {
                                    return;
                                }
                                else if (dr == DialogResult.No)
                                {
                                    continue;
                                }
                                else                                   // Yes
                                {
                                    lockedState.Attributes["StateValue"].Value = "False";

                                    MemoryStream ms = new MemoryStream();

                                    doc.Save(ms);

                                    ciphertext = olympCryptography.Encrypt(ms.GetBuffer()
                                                                           , new CompressStreamWriterDelegate(CompressStreamWriter));


                                    fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                                    {
                                        writer.Write(ciphertext, 0, ciphertext.Length);
                                        writer.Flush();
                                    }
                                }
                            }
                        }
                        else
                        {
                            string[] abc123 = new string[] { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")" };

                            bool found = false;
                            foreach (string pCharTest in abc123)
                            {
                                // compute the hash code
                                byte[] hash = hashAlgorithm.ComputeHash(System.Text.Encoding.Default.GetBytes(
                                                                            "ABCD123" + pCharTest));

                                string passHash = Convert.ToBase64String(hash);



                                if (passHash.Equals(storedHash))
                                {
                                    found = true;

                                    string  userId      = nameNode.Attributes["UserId"].Value;
                                    XmlNode lockedState = doc.SelectSingleNode("//UserState[@StateKey='Locked' and @UserId='" + userId + "']");

                                    bool locked = lockedState.Attributes["StateValue"].Value.Equals("True");


                                    if (MessageBox.Show(pCharTest + ((locked) ? " (locked)" : ""), "Hint Hint", MessageBoxButtons.OKCancel)
                                        == DialogResult.Cancel)
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!found)
                            {
                                if (MessageBox.Show("None found", "Hint Hint", MessageBoxButtons.OK) == DialogResult.Cancel)
                                {
                                    return;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // Exceptions are secret.
                    //Console.WriteLine( e.StackTrace );
                    //Console.WriteLine( e.Message );
                }
            }
        }