Beispiel #1
0
        public void TestBranch()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                SQLOperations.InsertIntoBranchTable(db, "firstRepo", "imaNewBranch");
                SQLOperations.InsertIntoBranchTable(db, "firstRepo", "imanotherBranch");
                SQLOperations.InsertIntoRepoTable(db, "helloRepo", "imanotherUser");

                db.SaveChanges();

                SQLOperations.InsertIntoBranchTable(db, "helloRepo", "helloBranch");

                db.SaveChanges();

                List <BranchLookup> branchesActual   = SQLOperations.QueryBranches(db, "firstRepo");
                List <BranchLookup> branchesExpected = new List <BranchLookup>
                {
                    new BranchLookup {
                        BranchName = "imaNewBranch", Locked = false
                    },
                    new BranchLookup {
                        BranchName = "imanotherBranch", Locked = false
                    }
                };

                SameListContents(branchesActual, branchesExpected);
            }
        }
Beispiel #2
0
        private void TestPermissionInsertion(ReVersion_DatabaseContext db, List <string> users, List <string> repos)
        {
            SQLOperations.InsertIntoRepoPermissionsTable(db, "firstRepo", "imaUser");
            SQLOperations.InsertIntoRepoPermissionsTable(db, "yetAnotherRepo", "imaUser");
            SQLOperations.InsertIntoRepoPermissionsTable(db, "yetAnotherRepo", "imanotherUser");

            db.SaveChanges();

            foreach (var item in repos.Zip(users, (r, u) => new { RepositoryName = r, Username = u }))
            {
                if (item.Username.Equals("imanotherUser") && item.RepositoryName.Equals("firstRepo"))
                {
                    Assert.IsFalse(SQLOperations.UserCanAccessRepository(db, item.Username, item.RepositoryName));
                }
                else
                {
                    Assert.IsTrue(SQLOperations.UserCanAccessRepository(db, item.Username, item.RepositoryName));
                }
            }

            List <string> permsActual   = SQLOperations.QueryPermissions(db, "imaUser");
            List <string> permsExpected = new List <string> {
                "firstRepo", "yetAnotherRepo"
            };

            SameListContents(permsActual, permsExpected);
        }
Beispiel #3
0
        public void TestVersions()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                FileHierarchyData hierData = new FileHierarchyData(hierarchy);
                hierData.AddNode("/A/B/alpha/beTa");
                hierData.DeleteNode("F/");

                VersionData data = new VersionData
                {
                    RepositoryName   = "yetAnotherRepo",
                    BranchName       = "yetAnotherBranch",
                    ParentBranchName = "yetAnotherOtherBranch",
                    NewBranch        = true,
                    DeltaContent     = "here's Delta!",
                    //FileHierarchy = hierData.GetHierarchyList(),
                    EventId = 5
                };

                SQLOperations.InsertIntoVersionsTable(db, data);
                db.SaveChanges();

                List <int> versionsActual   = SQLOperations.QueryVersions(db, "yetAnotherRepo", "yetAnotherBranch");
                List <int> versionsExpected = new List <int> {
                    1
                };
                SameListContents(versionsActual, versionsExpected);
            }
        }
Beispiel #4
0
 public void TestBranchIdQuery()
 {
     using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
     {
         int actualId = SQLOperations.QueryBranchId(db, "helloRepo", "helloBranch");
         Assert.AreEqual(actualId, 3);
     }
 }
Beispiel #5
0
 public void TestVersionDelete()
 {
     using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
     {
         SQLOperations.DeleteAllFromVersionsTable(db, "yetAnotherRepo");
         db.SaveChanges();
     }
 }
Beispiel #6
0
        private static void ProcessDelChar(Session MySession, List <byte> myPacket)
        {
            //Passes in packet with ServerID on it, will grab, transform and return ServerID while also removing packet bytes
            int clientServID = (int)Utility_Funcs.Untechnique(myPacket);

            //Call SQL delete method to actually process the delete.
            SQLOperations.DeleteCharacter(clientServID, MySession);
        }
 public void TestCaseSetup()
 {
     using (var db = new SQLOperations(() => new SqlConnection(TestConnectionString), transactional: false))
     {
         db.ExecuteNonQuery(@"DELETE FROM [kunden]");
         db.ExecuteNonQuery(@"DELETE FROM [produkte]");
         db.ExecuteNonQuery(@"DELETE FROM [lagerposten]");
         db.ExecuteNonQuery(@"DELETE FROM [produkteex]");
     }
 }
Beispiel #8
0
 public override Action GetCT()
 {
     return(() => {
         SQLOperations.NonQuery($"Erro ao criar profissao: {TableName}",
                                $"create table if not exists {TableName} (" +
                                $"  cpf varchar(15)," +
                                $"  primary key (cpf)," +
                                $"  foreign key (cpf) references funcionarios(cpf) ON DELETE CASCADE ON UPDATE CASCADE" +
                                $");");
     });
 }
 public static void Produkt(SQLOperations sql, Guid id, string bezeichnung)
 {
     sql.ExecuteNonQuery(
         @"INSERT INTO [produkteex] ([id],[bezeichnung],[bestand],[verfuegbar]) VALUES (@id,@bezeichnung,0,0)",
         set_parameter =>
         {
             set_parameter("id", id);
             set_parameter("bezeichnung", bezeichnung);
         }
         );
 }
Beispiel #10
0
        public void TestEmptyPermissionRequests()
        {
            using (var db = new ReVersion_DatabaseContext())
            {
                List <PermissionLookup> actual = SQLOperations.QueryPermissionRequests(db, "adam");

                List <PermissionLookup> expected = new List <PermissionLookup>();

                Assert.AreEqual(actual.Count, expected.Count);
            }
        }
Beispiel #11
0
        private void TestPermissionDeletion(ReVersion_DatabaseContext db, List <string> users, List <string> repos)
        {
            SQLOperations.DeleteAllFromPermissionsTable(db, "yetAnotherRepo");

            db.SaveChanges();

            foreach (var item in repos.Zip(users, (r, u) => new { RepositoryName = r, Username = u }))
            {
                if (item.RepositoryName.Equals("firstRepo") && item.Username.Equals("imaUser"))
                {
                    Assert.IsTrue(SQLOperations.UserCanAccessRepository(db, item.Username, item.RepositoryName));
                }
                else
                {
                    Assert.IsFalse(SQLOperations.UserCanAccessRepository(db, item.Username, item.RepositoryName));
                }
            }
        }
        public static void Update(SQLOperations sql, Guid produkt)
        {
            var posten = new LagerbestandRepository(sql).RetrieveAlleStandorte(produkt);
            var bestand = posten.Bestand.Sum(_ => _.LagerBestand);
            var zulauf = posten.Bestand.Sum(_ => _.MengeImZulauf);

            var verfuegbar = bestand + zulauf;

            sql.ExecuteNonQuery(
                @"UPDATE [produkteex] SET [bestand]=@bestand,[verfuegbar]=@verfuegbar WHERE [id]=@produkt",
                set_parameter =>
                {
                    set_parameter("produkt", produkt);
                    set_parameter("bestand", bestand);
                    set_parameter("verfuegbar", verfuegbar);
                }
                );
        }
Beispiel #13
0
        public void TestPermissions()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                List <string> users = new List <string> {
                    "imaUser", "imanotherUser"
                };
                List <string> repos = new List <string> {
                    "firstRepo", "yetAnotherRepo"
                };

                foreach (var item in repos.Zip(users, (r, u) => new { RepositoryName = r, Username = u }))
                {
                    Assert.IsFalse(SQLOperations.UserCanAccessRepository(db, item.Username, item.RepositoryName));
                }

                TestPermissionInsertion(db, users, repos);
                //TestPermissionDeletion(db, users, repos);
            }
        }
Beispiel #14
0
        public void TestBranchLocks()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                bool lockedActual = SQLOperations.BranchIsLocked(db, "helloRepo", "helloBranch");
                Assert.AreEqual(lockedActual, false, $"Lock Query: {lockedActual}");

                SQLOperations.LockState actualLockState =
                    SQLOperations.AcquireLock(db, "helloRepo", "helloBranch");
                db.SaveChanges();

                Assert.AreEqual(actualLockState, SQLOperations.LockState.SuccessfulLockOperation,
                                $"Initial Lock: {actualLockState}");
                actualLockState = SQLOperations.AcquireLock(db, "helloRepo", "helloBranch");
                db.SaveChanges();

                Assert.AreEqual(actualLockState, SQLOperations.LockState.AlreadyLockedConflict,
                                $"Second Lock: {actualLockState}");

                lockedActual = SQLOperations.BranchIsLocked(db, "helloRepo", "helloBranch");
                Assert.AreEqual(lockedActual, true, $"Second lock query: {lockedActual}");

                actualLockState = SQLOperations.ReleaseLock(db, "helloRepo", "helloBranch");
                db.SaveChanges();

                Assert.AreEqual(actualLockState, SQLOperations.LockState.SuccessfulLockOperation,
                                $"Release Lock: {actualLockState}");

                actualLockState = SQLOperations.ReleaseLock(db, "helloRepo", "helloBranch");
                db.SaveChanges();

                Assert.AreEqual(actualLockState, SQLOperations.LockState.AlreadyUnlockedConflict,
                                $"Second release lock: {actualLockState}");

                lockedActual = SQLOperations.BranchIsLocked(db, "helloRepo", "helloBranch");

                Assert.AreEqual(lockedActual, false, $"last lock query: {lockedActual}");
            }
        }
Beispiel #15
0
        public void TestMethod1()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                /*
                 * SQLOperations.InsertIntoUsersTable(db, "imaUser");
                 * SQLOperations.InsertIntoUsersTable(db, "imanotherUser");
                 * db.SaveChanges();
                 *
                 * SQLOperations.InsertIntoRepoTable(db, "firstRepo", "imaUser");
                 * SQLOperations.InsertIntoRepoTable(db, "repo2", "imanotherUser");
                 * SQLOperations.InsertIntoRepoTable(db, "yetAnotherRepo", "imaUser");
                 * db.SaveChanges();
                 */
                List <RepositoryLookup> repos = SQLOperations.QueryRepositories(db);

                List <RepositoryLookup> expected = new List <RepositoryLookup>
                {
                    new RepositoryLookup {
                        Name = "firstRepo", Owner = "imaUser"
                    },
                    new RepositoryLookup {
                        Name = "helloRepo", Owner = "imanotherUser"
                    },
                    new RepositoryLookup {
                        Name = "yetAnotherRepo", Owner = "imaUser"
                    }
                };

                SameListContents(repos, expected);

                //SQLOperations.DeleteFromRepositoryTable(db, "repo2");
                //db.SaveChanges();
                //expected.Remove("repo2");
                //repos = SQLOperations.QueryRepositories(db);

                //SameListContents(repos, expected);
            }
        }
Beispiel #16
0
        public void TestBranchDelete()
        {
            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                SQLOperations.DeleteAllFromBranchesTable(db, "firstRepo");
                db.SaveChanges();

                List <BranchLookup> branchesActual   = SQLOperations.QueryBranches(db, "firstRepo");
                List <BranchLookup> branchesExpected = new List <BranchLookup>();

                SameListContents(branchesActual, branchesExpected);

                branchesActual   = SQLOperations.QueryBranches(db, "helloRepo");
                branchesExpected = new List <BranchLookup>
                {
                    new BranchLookup {
                        BranchName = "helloBranch", Locked = false
                    }
                };

                SameListContents(branchesActual, branchesExpected);
            }
        }
        public void Setup()
        {
            try
            {
                using (var db = new SQLOperations(() => new SqlConnection(MasterConnectionString), transactional: false)
                    )
                {
                    db.ExecuteNonQuery(string.Format(@"CREATE DATABASE [{0}];", TestDatabase));
                }

                using (var db = new SQLOperations(() => new SqlConnection(TestConnectionString), transactional: false))
                {
                    db.ExecuteNonQuery(@"CREATE TABLE [kunden] ( id uniqueidentifier NOT NULL, name nvarchar(100) NOT NULL, anschrift nvarchar(200) NOT NULL)");
                    db.ExecuteNonQuery(@"CREATE TABLE [produkte] ( id uniqueidentifier NOT NULL, bezeichnung nvarchar(100) NOT NULL)");
                    db.ExecuteNonQuery(@"CREATE TABLE [lagerposten] ( lager uniqueidentifier NOT NULL, produkt uniqueidentifier NOT NULL, bestand int NOT NULL, zulauf int NOT NULL, nachbestellen_ab int NOT NULL, nachbestellen_menge int NOT NULL)");

                    db.ExecuteNonQuery(@"CREATE TABLE [produkteex] ( id uniqueidentifier NOT NULL, bezeichnung nvarchar(100) NOT NULL, bestand int NOT NULL, verfuegbar int NOT NULL)");
                }
            }
            catch
            {
                // Jaja, ist eine Demo ;)
            }
        }
        static void Main(string[] args)
        {
            string        _websiteName        = null;
            bool          _https              = false;
            string        _port               = null;
            string        _DBconnectionString = null;
            string        _application        = null;
            string        _driveName          = null;
            string        node                 = null;
            string        _sourcePath          = null;
            string        _targetPath          = null;
            string        _fileName            = null;
            XmlNodeList   copyFiles            = null;
            XmlNodeList   regOperation         = null;
            XmlNodeList   sqlOperations        = null;
            XmlNodeList   grouppolicyOperation = null;
            RegisitryCRUD registrycrud         = null;


            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AppSecurity.xml") && System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\data.xml"))
            {
                _appConfig = new XmlDocument();
                _appConfig.Load(AppDomain.CurrentDomain.BaseDirectory + "\\AppSecurity.xml");
                _websiteName        = _appConfig.SelectSingleNode("settings/websiteName").InnerText;
                _application        = _appConfig.SelectSingleNode("settings/application").InnerText;
                _driveName          = _appConfig.SelectSingleNode("settings/DriveLetter").InnerText;
                _https              = Convert.ToBoolean(_appConfig.SelectSingleNode("settings/https").InnerText);
                _port               = _appConfig.SelectSingleNode("settings/port").InnerText;
                _DBconnectionString = _appConfig.SelectSingleNode("settings/DBconnectionString").InnerText;

                _appConfig = null;
                _appConfig = new XmlDocument();
                _appConfig.Load(AppDomain.CurrentDomain.BaseDirectory + "\\data.xml");

                regOperation         = _appConfig.SelectNodes("settings/RegistryOperations/Registry");
                sqlOperations        = _appConfig.SelectNodes("settings/SqlOperations/Sql");
                grouppolicyOperation = _appConfig.SelectNodes("settings/GroupPolicy/policy");

                RegisitryCRUD _registryCrud     = new RegisitryCRUD();
                string        _installationPath = null;
                _installationPath       = _registryCrud.getInstallationFolderPath(_application);
                Console.ForegroundColor = ConsoleColor.DarkYellow;

                try
                {
                    if (_installationPath.Equals(null))
                    {
                    }
                }
                catch (Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("" + _application.ToUpper() + " IS NOT INSTALLED ON SERVER. Exiting from Utility");
                    Logger.WriteMessage("" + _application.ToUpper() + " IS NOT INSTALLED ON SERVER. Exiting from Utility");
                    System.Environment.Exit(0);
                }


                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("                 -----------------------------------------------");
                Console.WriteLine("                     APPLICATION SECURITY VERSION :" + Assembly.GetExecutingAssembly().GetName().Version);
                Logger.WriteMessage("                   APPLICATION SECURITY VERSION :" + Assembly.GetExecutingAssembly().GetName().Version);
                Console.WriteLine("                 -----------------------------------------------");

                Console.ForegroundColor = ConsoleColor.Cyan;

                /**
                 * -------------------------------------------------------------------------
                 * Web-content is on a non-system partition
                 * ----------------------------------------------------------------------
                 */

                string _wwwrootPath        = null;
                string _binDirectory       = null;
                string _binDirUnderSetting = null;

                _wwwrootPath        = _driveName + @":\wwwroot";
                _binDirectory       = _wwwrootPath + "\\bin";
                _binDirUnderSetting = _installationPath + "\\Settings\\bin";

                if (_application.ToUpper().Equals("IRC"))
                {
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(" Start - Web-content is on a non-system partition");
                    Console.WriteLine(" Start - Web-content is on a non-system partition");
                    Console.WriteLine(" ----------------------------------------------------------------------");

                    if (!System.IO.Directory.Exists(_wwwrootPath))
                    {
                        try
                        {
                            System.IO.Directory.CreateDirectory(_wwwrootPath);
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteError("Error while creating driectory on " + _wwwrootPath);
                            Logger.WriteMessage(ex.Message);
                        }
                    }
                    try
                    {
                        //Now Create all of the directories
                        foreach (string dirPath in Directory.GetDirectories("C:\\inetpub\\wwwroot", "*", SearchOption.AllDirectories))
                        {
                            Directory.CreateDirectory(dirPath.Replace("C:\\inetpub\\wwwroot", _wwwrootPath));
                        }
                        System.Threading.Thread.Sleep(10000);
                        //Copy all the files & Replaces any files with the same name
                        foreach (string newPath in Directory.GetFiles("C:\\inetpub\\wwwroot", "*.*", SearchOption.AllDirectories))
                        {
                            File.Copy(newPath, newPath.Replace("C:\\inetpub\\wwwroot", _wwwrootPath), true);
                        }
                        System.Threading.Thread.Sleep(10000);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteError("Error while coping files in D drive");
                        Logger.WriteMessage(ex.Message);;
                    }

                    Logger.WriteMessage("End - Web-content is on a non-system partition");
                    Console.WriteLine(" END - Web-content is on a non-system partition");
                    Console.WriteLine(" ----------------------------------------------------------------------");

                    try
                    {
                        System.IO.Directory.CreateDirectory(_binDirectory);
                        System.Threading.Thread.Sleep(2000);
                        Logger.WriteMessage("" + _binDirectory + " directory is created");
                        Console.WriteLine("" + _binDirectory + " directory is created");
                        Console.WriteLine(" ----------------------------------------------------------------------");
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteError("Error while creating folder at " + _binDirectory);
                        Logger.WriteMessage(ex.Message);
                    }

                    try
                    {
                        System.IO.Directory.CreateDirectory(_binDirUnderSetting);
                        System.Threading.Thread.Sleep(2000);
                        Logger.WriteMessage("" + _binDirUnderSetting + " directory is created");
                        Console.WriteLine("" + _binDirUnderSetting + " directory is created");
                        Console.WriteLine(" ----------------------------------------------------------------------");
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteError("Error while creating folder at " + _binDirUnderSetting);
                        Logger.WriteMessage(ex.Message);
                    }
                }

                switch (_application.ToUpper())
                {
                case "IRC":
                    _sourcePath = _installationPath + @"\BizRightsPresentation\bin";
                    break;

                case "CM":
                    _sourcePath = _installationPath + @"\presentation\bin";
                    break;

                default:
                    throw new Exception("Applicaton type is in incorrect format");
                }
                _fileName = "Approva.Presentation.Framework.HttpModule.dll";
                try
                {
                    CopyDLL._CopyFromLocation(_sourcePath, _binDirectory, _fileName);
                    System.Threading.Thread.Sleep(3000);
                }
                catch (Exception ex)
                {
                    Logger.WriteError("Error while copying " + _fileName);
                    Logger.WriteMessage(ex.Message);;
                }
                _sourcePath = null;
                _fileName   = null;


                //----------------------------------------------------------------------

                /**
                 * -------------------------------------------------------------------------
                 * Copy the Approva.Presentation.Framework.HttpModule.dll from the [IRC InstallPath]\BizRightsPresentation\bin to 3 locations:
                 * [IRC Install path]\Core\bin
                 * [IRC Install path]\Adapters\TMonitor\bin
                 * [IRC Install path]\BRPublisher\bin
                 * ----------------------------------------------------------------------
                 */
                switch (_application.ToUpper())
                {
                case "IRC":
                    copyFiles = _appConfig.SelectNodes("settings/IRCcopyFiles");
                    break;

                case "CM":
                    copyFiles = _appConfig.SelectNodes("settings/CMcopyFiles");
                    break;

                default:
                    throw new Exception("Applicaton type is in incorrect format");
                }

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Copying the Approva.Presentation.Framework.HttpModule.dll from the [IRC InstallPath]\BizRightsPresentation\bin to 4 locations:");
                Console.WriteLine(@" Copying the Approva.Presentation.Framework.HttpModule.dll from the[IRC InstallPath]\\BizRightsPresentation\bin to 4 locations:");


                foreach (XmlNode itemCopyFiles in copyFiles)
                {
                    // foreach (XmlNode filepath in copyFiles)
                    //{
                    Console.WriteLine("------------------------------------------------");
                    _sourcePath = itemCopyFiles.SelectSingleNode("SourceFile").Attributes["path"].Value;
                    _fileName   = itemCopyFiles.SelectSingleNode("SourceFile").Attributes["fileName"].Value;
                    _sourcePath = _installationPath + _sourcePath;
                    XmlNodeList _locationlist = itemCopyFiles.SelectNodes("SourceFile/location");
                    foreach (XmlNode item in _locationlist)
                    {
                        _targetPath = item.InnerText;
                        _targetPath = _installationPath + _targetPath;
                        CopyDLL._CopyFromLocation(_sourcePath, _targetPath, _fileName);
                        Logger.WriteMessage(@"Copied to:" + _targetPath);
                        Console.WriteLine(@"Copied to:" + _targetPath);
                        System.Threading.Thread.Sleep(500);
                        _targetPath = null;
                    }
                    _sourcePath = null;
                    //}
                }

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"WhiteHat - Fixing the information leakage vulnerability");
                Console.WriteLine(@" WhiteHat - Fixing the information leakage vulnerability");
                bool iswebConfigPresent = System.IO.File.Exists(_wwwrootPath + "\\web.config");

                if (_application.ToUpper().Equals("IRC"))
                {
                    if (iswebConfigPresent)
                    {
                        Console.WriteLine("Web.config is already present & backedup with 'OldWeb.config' at " + _wwwrootPath);
                        try
                        {
                            File.Copy(_wwwrootPath + "\\web.config", _wwwrootPath + "\\OldWeb.config", true);
                            File.Delete(_wwwrootPath + "\\web.config");
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Error while renaming Web.config");
                            Logger.WriteMessage("Error while renaming Web.config");
                            throw;
                        }
                    }

                    // string webConfigFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\web.config";
                    try
                    {
                        CopyDLL._CopyFromLocation(AppDomain.CurrentDomain.BaseDirectory, _wwwrootPath, "web.config");
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteMessage("Problem while copying web.config file ");
                        Console.WriteLine("Problem while copying web.config file");
                        Logger.WriteMessage(ex.Message);
                    }
                }


                // Remove or comment out the following node from these paths to unregister"AntiHttpCrossSiteForgeryRequestModule" managed HTTP module.               *
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Remove/comment out the following node from these paths to unregister AntiHttpCrossSiteForgeryRequestModule managed HTTP module from Bizrightspresentation/bin");
                Console.WriteLine(@" Remove/comment out the following node from these paths to unregister AntiHttpCrossSiteForgeryRequestModule managed HTTP module from Bizrightspresentation/bin");
                _fileName = "web.config";
                switch (_application.ToUpper())
                {
                case "IRC":
                    _sourcePath = _installationPath + "\\BizrightsPresentation";
                    File.Copy(_sourcePath + "\\web.config", _wwwrootPath + "\\Old_IRC_Web.config", true);
                    break;

                case "CM":
                    _sourcePath = _installationPath + "\\presentation";
                    File.Copy(_sourcePath + "\\web.config", _wwwrootPath + "\\Old_CM_Web.config", true);
                    break;

                default:
                    throw new Exception("Application type not correct");
                }
                string _node    = @"add[@name='AntiHttpCrossSiteForgeryRequestModule']";
                string _refNode = @"/configuration/system.webServer/modules/";
                XMLCRUD._commentInWebConfigXML(_sourcePath, _fileName, _refNode, _node, true);

                _node    = null;
                _refNode = null;


                /*
                 * --------------------------------------------------------------------------------------
                 * Cookie security: cookie not sent over SSL
                 * ------------------------------------------------------------------------------------
                 */
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Cookie security: cookie not sent over SSL");
                Console.WriteLine(@" Cookie security: cookie not sent over SSL");
                string _attribute      = null;
                string _attributeValue = null;

                if (_application.ToUpper().Equals("IRC") && _https)
                {
                    _attribute      = "cookieRequireSSL";
                    _attributeValue = "true";
                    _refNode        = "roleManager";
                    XMLCRUD.addAttributeToExistingNode(_sourcePath, _fileName, _attribute, _attributeValue, _refNode);

                    _attribute      = "null";
                    _attributeValue = "null";
                    _refNode        = "null";

                    _attribute      = "requireSSL";
                    _refNode        = "forms";
                    _attributeValue = "true";
                    XMLCRUD.addAttributeToExistingNode(_sourcePath, _fileName, _attribute, _attributeValue, _refNode);

                    _attribute      = "null";
                    _attributeValue = "null";
                    _refNode        = "null";

                    _attribute      = "requireSSL";
                    _refNode        = "httpCookies";
                    _attributeValue = "true";
                    XMLCRUD.addAttributeToExistingNode(_sourcePath, _fileName, _attribute, _attributeValue, _refNode);

                    _attribute      = "null";
                    _attributeValue = "null";
                    _refNode        = "null";
                }


                /*
                 * -------------------------------------------------------------------------
                 * CIS - CAT hardening - ASP.Net configuration recommendations
                 * //C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config
                 * ----------------------------------------------------------------------
                 */
                if (_application.ToUpper().Equals("IRC"))
                {
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"CIS - CAT hardening - ASP.Net configuration recommendations");
                    Console.WriteLine(@" CIS - CAT hardening - ASP.Net configuration recommendations");
                    node = "deployment";
                    CopyDLL._backupFiles("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\Config", "machine.config");
                    XMLCRUD._modifyXML("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\Config", "machine.config", node, "configuration/system.web", false);
                    node = null;

                    /*
                     * -------------------------------------------------------------------------
                     *   Ensure Handler is not granted Write and Script/Execute
                     * ----------------------------------------------------------------------
                     */

                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"Ensure Handler is not granted Write and Script/Execute");
                    Console.WriteLine(@" Ensure Handler is not granted Write and Script/Execute");
                    CopyDLL._backupFiles("C:\\Windows\\system32\\inetsrv\\config", "applicationHost.config");
                    XmlDocument _appHostConfig = new XmlDocument();
                    try
                    {
                        try
                        {
                            _appHostConfig.Load("C:\\Windows\\system32\\inetsrv\\config\\applicationHost.config");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error while Loading Config file: " + e.Message);
                        }

                        XmlAttribute handlers = (XmlAttribute)_appHostConfig.SelectSingleNode("configuration//location//system.webServer//handlers/@accessPolicy");
                        String       _policy  = handlers.InnerText;
                        // Console.WriteLine("Present Handler Values: " + _policy);
                        Logger.WriteMessage("Present Handler Values: " + _policy);
                        if (_policy.ToUpper().Contains("Write"))
                        {
                            handlers.Value = "Read, Script";
                            _appHostConfig.Save("C:\\Windows\\system32\\inetsrv\\config\\applicationHost.config");
                            //   Console.WriteLine("applicationHost.config file has been modified successfully");
                            Logger.WriteMessage("applicationHost.config file has been modified successfully");
                        }
                        else
                        {
                            //  Console.WriteLine("Required Handler Values are present");
                            Logger.WriteMessage("Required Handler Values are present");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error while modifing/reading Handler in ApplicationHost.config file");
                        Logger.WriteMessage("Error while modifing/reading Handler in ApplicationHost.config file" + e.Message);
                    }
                }

                // Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Change IIS Website Physical path");
                //Console.WriteLine(@"Change IIS Website Physical path");
                node = null;
                node = "Change IIS Physical path";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                //Console.WriteLine("change physical path to " + _wwwrootPath);
                System.Threading.Thread.Sleep(3000);

                //  Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Change IIS log path");
                // Console.WriteLine(@"Change IIS log path");
                node = null;
                node = "Change IIS log path";
                string _logPath = _driveName + @":\LogFiles";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _driveName);
                // Console.WriteLine("change IIS log");
                System.Threading.Thread.Sleep(3000);


                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"IIS Hardening -Configuring host headers on all sites");
                Console.WriteLine(@" IIS Hardening -Configuring host headers on all sites ");
                // IIS Hardening -Configuring host headers on all sites
                node = "Host Header";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);

                node = null;

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"IIS - Setting the default application pool identity to least privilege principal");
                Console.WriteLine(@" IIS - Setting the default application pool identity to least privilege principal");
                // IIS - Setting the default application pool identity to least privilege principal
                node = "Default application pool identity";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;


                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"IIS - Configuring the anonymous user identity to use the Application Pool identity");
                Console.WriteLine(@" IIS - Configuring the anonymous user identity to use the Application Pool identity");
                //IIS - Configuring the anonymous user identity to use the Application Pool identity
                node = "Anonymous user identity to use the Application Pool identity";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;


                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"IIS - Configuring the Require SSL option in the Forms authentication");
                Console.WriteLine(@" IIS - Configuring the Require SSL option in the Forms authentication");
                // IIS - Configuring the Require SSL option in the Forms authentication
                if (_https)
                {
                    //string[] subsites = new string[] { "BizRightsCoreSettings", "BRPublisher", "CertificationManager", "Core", "IRC", "PDSService", "TMAdapter" };
                    node = "Required SSL in form authentication";
                    CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                    //foreach (string s in subsites)
                    //{
                    //    string temp = _websiteName + "/" + s;
                    //    CMDOperations.cmdRun(node, temp, _https, _port, _wwwrootPath);
                    //    temp = null;
                    //}
                    node = null;
                }

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"IIS - Turning the Debug Off in the IIS  ");
                Console.WriteLine(@" IIS - Turning the Debug Off in the IIS ");
                //IIS - Turning the Debug Off in the IIS
                node = "Debug off in the IIS";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Adding X-Content - Type - Options ");
                Console.WriteLine(@" Adding X-Content - Type - Options ");

                //Adding X-Content - Type - Options
                if (_application.ToUpper().Equals("IRC"))
                {
                    node = "X-Content-Type-Options";
                    CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                    node = null;
                }

                //Disabling directory browsing feature of Certification Manager Site using IIS

                if (_application.ToUpper().Equals("CM"))
                {
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"Disabling directory browsing feature of Certification Manager Site");
                    node = "Directory Browsing";
                    CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                    node = null;
                }


                //Enabling Advanced IIS logging

                //Setting cookies with the HttpOnly attribute
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Setting cookies with the HttpOnly attribute is incorporated in pre shipped web config");


                // Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Setting 'forms authentication' to use cookies");
                Console.WriteLine(@" Setting 'forms authentication' to use cookies");
                //Setting 'forms authentication' to use cookies
                node = "forms Authentication to use cookies";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;

                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Ensure non-ASCII Characters in URLs are not allowed");
                Console.WriteLine(@" Ensure non-ASCII Characters in URLs are not allowed");
                //Ensure non-ASCII Characters in URLs are not allowed
                node = "Request Filter";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;

                //To configure general request-filter-Configure Double escaping (allowdoubleescaping)
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Ensure Double-Encoded requests will be rejected");
                Console.WriteLine(@"Ensure Double-Encoded requests will be rejected");
                //Ensure non-ASCII Characters in URLs are not allowed
                node = "Double Escaping";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;


                //To configure configure IIS to deny HTTP TRACE requests (Ensure 'HTTP Trace Method' is disabled)
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Ensure 'HTTP Trace Method' is disabled");
                Console.WriteLine(@"Ensure 'HTTP Trace Method' is disabled");
                //Ensure non-ASCII Characters in URLs are not allowed
                node = "HTTP TRACE";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;

                //Edit ISAPI and CGI Restrictions Settings
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Ensure 'notListedIsapisAllowed/notListedCgisAllowed' is set to false");
                Console.WriteLine(@"Ensure 'notListedIsapisAllowed/notListedCgisAllowed' is set to false");
                //Ensure non-ASCII Characters in URLs are not allowed
                node = "ISAPI_CGI Restrictions";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;

                //Machine Key Settings
                Console.WriteLine(" ----------------------------------------------------------------------");
                Logger.WriteMessage(@"Ensure 'MachineKey validation method - .Net 4.5' is configured");
                Console.WriteLine(@"Ensure 'MachineKey validation method - .Net 4.5' is configured");
                //Ensure non-ASCII Characters in URLs are not allowed
                node = "Machine Key 4.5 Validation";
                CMDOperations.cmdRun(node, _websiteName, _https, _port, _wwwrootPath);
                node = null;

                /**
                 * -------------------------------------------------------------------------
                 * Disabling the RC4 Cipher suites,
                 * Ensure TLS 1.2 is enabled
                 * Ensure NULL Cipher Suites is disabled
                 * Ensure DES Cipher Suites is disabled,Ensure RC2 Cipher Suites is disabled
                 * Ensure AES 256/256 Cipher Suite is enabled
                 * ----------------------------------------------------------------------
                 */
                string _regHive      = null;
                string _regPath      = null;
                string _regKey       = null;
                int    _regvalue     = 0;
                string _sregvalue    = null;
                string _regvalueType = null;
                string _regvalueKind = null;
                if (_application.ToUpper().Equals("IRC"))
                {
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"Disabling the RC4 Cipher suites, Ensure TLS 1.2 is enabled ");
                    Console.WriteLine(@"Disabling the RC4 Cipher suites");
                    registrycrud = null;
                    foreach (XmlNode itemReg in regOperation)
                    {
                        registrycrud  = new RegisitryCRUD();
                        _regHive      = itemReg.Attributes["regHive"].Value.ToString();
                        _regPath      = itemReg.Attributes["regPath"].Value.ToString();
                        _regKey       = itemReg.Attributes["regKey"].Value.ToString();
                        _regvalueType = itemReg.Attributes["regValueType"].Value.ToString();
                        _regvalueKind = itemReg.Attributes["regValueKind"].Value.ToString().Equals(" ") ? null : itemReg.Attributes["regValueKind"].Value.ToString();
                        if (_regvalueType.Equals("int"))
                        {
                            _regvalue = Convert.ToInt32(itemReg.Attributes["regvalue"].Value);
                            registrycrud.createRegistryKey(_regHive, _regPath, _regKey, _regvalue, _regvalueKind);
                        }
                        else
                        {
                            _sregvalue = itemReg.Attributes["regvalue"].Value.ToString();
                            registrycrud.createRegistryKey(_regHive, _regPath, _regKey, _sregvalue, _regvalueKind);
                        }
                        registrycrud = null;
                    }


                    /**
                     * -------------------------------------------------------------------------
                     * Group Policy Operations
                     * ----------------------------------------------------------------------
                     */
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"Group Policy Operations");
                    Console.WriteLine(@"Group Policy Operations");

                    foreach (XmlNode policy in grouppolicyOperation)
                    {
                        string _policyName  = policy.Attributes["name"].Value.ToString();
                        string _policyValue = policy.Attributes["value"].Value.ToString();
                        _regHive  = "HKEY_LOCAL_MACHINE";
                        _regPath  = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
                        _regKey   = null;
                        _regvalue = 0;

                        switch (_policyName)
                        {
                        case "User Account Control: Behavior of the elevation prompt for administrators inAdmin Approval Mode":
                            _regKey   = "ConsentPromptBehaviorAdmin";
                            _regvalue = 5;
                            break;

                        case "User Account Control: Switch to the secure desktop when prompting forelevation":
                            _regKey   = "PromptOnSecureDesktop";
                            _regvalue = 1;
                            break;

                        default:
                            throw new System.InvalidOperationException("parameter  in the App Security xml");
                        }
                        registrycrud = new RegisitryCRUD();
                        registrycrud.createRegistryKey(_regHive, _regPath, _regKey, _regvalue, "");
                        Logger.WriteMessage(_policyName + " value changed to '" + _policyValue + "'");
                        registrycrud = null;
                    }

                    /*
                     * -------------------------------------------------------------------------
                     * SQL Operations
                     * ----------------------------------------------------------------------
                     */
                    Console.WriteLine(" ----------------------------------------------------------------------");
                    Logger.WriteMessage(@"SQL Operations");
                    Console.WriteLine(@"SQL Operations");
                    String dbName = _DBconnectionString.Split(';')[3].Split('=')[1].ToString();
                    if (!sqlOperations.Equals(""))
                    {
                        foreach (XmlNode sqlQuery in sqlOperations)
                        {
                            string _sql = sqlQuery.InnerText.ToString();
                            if (_sql.Contains("Revoke"))
                            {
                                SQLOperations._revokeGuestUserfromDB(dbName, _sql, _DBconnectionString);
                            }
                            else
                            {
                                SQLOperations._executeSQLQueries(_sql, _DBconnectionString);
                            }
                        }
                    }
                }
            }
        }
Beispiel #19
0
 public ProduktRepository(UnitOfWork uow)
 {
     _sql = uow.Db;
 }
Beispiel #20
0
 public KundenRepository(SQLOperations sql)
 {
     _sql = sql;
 }
Beispiel #21
0
 public KundenRepository(UnitOfWork uow)
 {
     _sql = uow.Db;
 }
 public LagerbestandRepository(SQLOperations sql)
 {
     _sql = sql;
 }
 public LagerbestandRepository(UnitOfWork uow)
 {
     _sql = uow.Db;
 }
Beispiel #24
0
 public UnitOfWork(Func<SqlConnection> connectionFactory)
 {
     Db = new SQLOperations(connectionFactory, transactional: true);
 }
Beispiel #25
0
        private static void ProcessRdpReport(Session MySession, List <byte> MyPacket, bool UnreliableReport)
        {
            //Eventually incorporate UnreliableReport to cycle through unreliables and update accordingly

            //Read client bundle here. Accept client bundle as is because packets could be lost or dropped, client bundle# should not be "tracked"
            //considerations could be to track it for possible drop/lost rates
            MySession.clientBundleNumber = (ushort)(MyPacket[1] << 8 | MyPacket[0]);
            ushort LastRecvBundleNumber  = (ushort)(MyPacket[3] << 8 | MyPacket[2]);
            ushort LastRecvMessageNumber = (ushort)(MyPacket[5] << 8 | MyPacket[4]);

            //Check our list  of reliable messages to remove
            for (int i = 0; i < MySession.MyMessageList.Count(); i++)
            {
                //If our message stored is less then client ack, need to remove it!
                if (MySession.MyMessageList[i - i].ThisMessagenumber <= LastRecvMessageNumber)
                {
                    MySession.MyMessageList.RemoveAt(0);
                }

                //Need to keep remaining messages, move on
                else
                {
                    break;
                }
            }


            MyPacket.RemoveRange(0, 6);
            ///Only one that really matters, should tie into our packet resender stuff
            if (MySession.serverMessageNumber >= LastRecvMessageNumber)
            {
                ///This should be removing messages from resend mechanics.
                ///Update our last known message ack'd by client
                MySession.clientRecvMessageNumber = LastRecvMessageNumber;
            }

            ///Triggers creating master session
            if (((MySession.clientEndpoint + 1) == (MySession.sessionIDBase & 0x0000FFFF)) && MySession.SessionAck && MySession.serverSelect == false)
            {
                ///Key point here for character select is (MySession.clientEndpoint + 1 == MySession.sessionIDBase)
                ///SessionIDBase is 1 more then clientEndPoint
                ///Assume it's Create Master session?
                Session NewMasterSession = new Session(MySession.clientEndpoint, MySession.MyIPEndPoint, MySession.AccountID);

                SessionManager.AddMasterSession(NewMasterSession);
            }

            ///Trigger Server Select with this?
            else if ((MySession.clientEndpoint == (MySession.sessionIDBase & 0x0000FFFF)) && MySession.SessionAck && MySession.serverSelect == false)
            {
                MySession.serverSelect = true;
            }

            ///Triggers Character select
            else if (MySession.CharacterSelect && (MySession.clientEndpoint != MySession.sessionIDBase))
            {
                MySession.CharacterSelect = false;
                List <Character> MyCharacterList = new List <Character>();
                Logger.Info("Generating Character Select");
                MyCharacterList = SQLOperations.AccountCharacters(MySession);

                //Assign to our session
                MySession.CharacterData = MyCharacterList;

                ProcessOpcode.CreateCharacterList(MyCharacterList, MySession);
            }

            else if (MySession.Dumpstarted)
            {
                //Let client know more data is coming
                if (MySession.MyDumpData.Count() > 500)
                {
                    List <byte> ThisChunk = MySession.MyDumpData.GetRange(0, 500);
                    MySession.MyDumpData.RemoveRange(0, 500);

                    ///Handles packing message into outgoing packet
                    RdpCommOut.PackMessage(MySession, ThisChunk, MessageOpcodeTypes.MultiShortReliableMessage);
                }

                //End of dump
                else
                {
                    List <byte> ThisChunk = MySession.MyDumpData.GetRange(0, MySession.MyDumpData.Count());
                    MySession.MyDumpData.Clear();
                    ///Handles packing message into outgoing packet
                    RdpCommOut.PackMessage(MySession, ThisChunk, MessageOpcodeTypes.ShortReliableMessage);
                    //turn dump off
                    MySession.Dumpstarted = false;

                    //Gather remaining data to send in dump
                    //ignore list
                    ProcessOpcode.IgnoreList(MySession);
                    //Randommessage
                    //RandomFriend
                    //characterSpeed
                    ProcessOpcode.ActorSpeed(MySession);
                    //Some opcode
                }
            }

            else
            {
                Logger.Err($"Client received server message {LastRecvMessageNumber}, expected {MySession.serverMessageNumber}");
            }
        }
Beispiel #26
0
 public ProduktRepository(SQLOperations sql)
 {
     _sql = sql;
 }
Beispiel #27
0
        public static void ProcessMemoryDump(Session MySession)
        {
            //Let's get remaining character data before preparing it for transport
            //Hotkeys
            SQLOperations.GetPlayerHotkeys(MySession);

            //Quests, skip for now
            //Weaponhotbars
            SQLOperations.GetPlayerWeaponHotbar(MySession);

            //Auctions go here, skip for now
            //Spells
            SQLOperations.GetPlayerSpells(MySession);

            MySession.MyDumpData.AddRange(MySession.MyCharacter.PullCharacter());
            MySession.MyDumpData.Add((byte)(MySession.MyCharacter.MyHotkeys.Count() * 2));

            //cycle over all our hotkeys and append them
            foreach (Hotkey MyHotkey in MySession.MyCharacter.MyHotkeys)
            {
                MySession.MyDumpData.AddRange(MyHotkey.PullHotkey());
            }
            //Unknown at this time 4 byte null
            MySession.MyDumpData.AddRange(BitConverter.GetBytes(0));

            //Unknown at this time 4 byte null
            MySession.MyDumpData.AddRange(BitConverter.GetBytes(0));

            //Quest Count
            MySession.MyDumpData.AddRange(BitConverter.GetBytes(MySession.MyCharacter.MyQuests.Count()));

            //Iterate over quest data and append (Should be 0 for now...)
            foreach (Quest MyQuest in MySession.MyCharacter.MyQuests)
            {
                MySession.MyDumpData.AddRange(MyQuest.PullQuest());
            }

            //Get Inventory Item count
            MySession.MyDumpData.Add((byte)(MySession.MyCharacter.InventoryItems.Count() * 2));
            MySession.MyDumpData.AddRange(BitConverter.GetBytes(MySession.MyCharacter.InventoryItems.Count()));
            foreach (Item MyItem in MySession.MyCharacter.InventoryItems)
            {
                MySession.MyDumpData.AddRange(MyItem.PullItem());
            }

            foreach (WeaponHotbar MyWeaponHotbar in MySession.MyCharacter.WeaponHotbars)
            {
                MySession.MyDumpData.AddRange(MyWeaponHotbar.PullWeaponHotbar());
            }

            //Get Bank Item count
            MySession.MyDumpData.Add((byte)(MySession.MyCharacter.BankItems.Count() * 2));
            MySession.MyDumpData.AddRange(BitConverter.GetBytes(MySession.MyCharacter.BankItems.Count()));
            foreach (Item MyItem in MySession.MyCharacter.BankItems)
            {
                MySession.MyDumpData.AddRange(MyItem.PullItem());
            }

            // end of bank? or could be something else for memory dump
            MySession.MyDumpData.Add((byte)0);

            //Buying auctions
            MySession.MyDumpData.Add((byte)(MySession.MyCharacter.MyBuyingAuctions.Count()));
            foreach (Auction MyAuction in MySession.MyCharacter.MyBuyingAuctions)
            {
                MySession.MyDumpData.AddRange(MyAuction.PullAuction());
            }

            //Selling auctions
            MySession.MyDumpData.Add((byte)(MySession.MyCharacter.MySellingAuctions.Count()));
            foreach (Auction MyAuction in MySession.MyCharacter.MySellingAuctions)
            {
                MySession.MyDumpData.AddRange(MyAuction.PullAuction());
            }

            //Spell count and Spells
            MySession.MyDumpData.AddRange(Utility_Funcs.Technique(MySession.MyCharacter.MySpells.Count()));
            foreach (Spell MySpell in MySession.MyCharacter.MySpells)
            {
                MySession.MyDumpData.AddRange(MySpell.PullSpell());
                //Indicates end of spell?
                MySession.MyDumpData.Add((byte)0);
            }

            MySession.MyDumpData.AddRange(new byte[] { 0x55, 0x55, 0x0d, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
                                                       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
                                                       0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00,
                                                       0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                       0x00, 0x00, 0x00, 0x00, 0xa0, 0x0f, 0xae, 0x98, 0x4c, 0x00, 0x55, 0x55, 0x0d, 0x41, 0xe6,
                                                       0x01, 0x96, 0x01, 0x78, 0x96, 0x01, 0x00, 0x00, 0x00, 0xde, 0x02, 0xde, 0x02, 0x00, 0xfa,
                                                       0x01, 0x00, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x5a, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x4f, 0x00,
                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x02, 0xde, 0x02, 0x00, 0xfa, 0x01, 0x00, 0x00, 0x00 });

            MySession.Dumpstarted = true;

            //Get our timestamp opcode in queue
            RdpCommOut.PackMessage(MySession, DNP3Creation.CreateDNP3TimeStamp(), MessageOpcodeTypes.ShortReliableMessage, GameOpcode.Time);

            List <byte> ThisChunk;

            //Gather our dump data
            if (MySession.MyDumpData.Count() > 500)
            {
                ThisChunk = MySession.MyDumpData.GetRange(0, 500);
                MySession.MyDumpData.RemoveRange(0, 500);

                //Set this to true to send packet to client
                MySession.ClientFirstConnect = true;

                ///Handles packing message into outgoing packet
                RdpCommOut.PackMessage(MySession, ThisChunk, MessageOpcodeTypes.MultiShortReliableMessage, GameOpcode.MemoryDump);
            }

            //Dump data is smaller then 500 bytes
            else
            {
                ThisChunk = MySession.MyDumpData.GetRange(0, MySession.MyDumpData.Count());
                MySession.MyDumpData.Clear();

                //Set this to true to send packet to client
                MySession.ClientFirstConnect = true;

                //Appears dump is short, end it here
                MySession.Dumpstarted = false;

                ///Handles packing message into outgoing packet
                RdpCommOut.PackMessage(MySession, ThisChunk, MessageOpcodeTypes.ShortReliableMessage, GameOpcode.MemoryDump);
            }
        }
Beispiel #28
0
        public void TestPermissionRequests()
        {
            // List<PermissionLookup> QueryPermissionRequests(db, username)
            //              PermissionLookup { string Message, string RequestingUser, string RepositoryName, int RequestId, DateTime LogTimestamp }
            // int QueryRepositoryIdFromRequest(db, requestId)
            // int QueryMainTrunkFromRequest(db, requestId)
            // int QueryUserFromRequest(db, requestId)
            //
            // void DeleteAllFromPermissionRequestsTable(db, repoName)
            // void InsertIntoPermissionRequestTable(db, repoName, eventId)
            // void DeleteFromPermissionRequestTable(db, requestId)

            using (ReVersion_DatabaseContext db = new ReVersion_DatabaseContext())
            {
                /*
                 * SQLOperations.InsertIntoPermissionRequestTable(db, "helloRepo", 7);
                 * SQLOperations.InsertIntoPermissionRequestTable(db, "helloRepo", 8);
                 * SQLOperations.InsertIntoPermissionRequestTable(db, "firstRepo", 9);
                 * SQLOperations.InsertIntoPermissionRequestTable(db, "yetAnotherRepo", 10);
                 * SQLOperations.InsertIntoPermissionRequestTable(db, "firstRepo", 11);
                 * db.SaveChanges();
                 */
                /*
                 * SQLOperations.DeleteAllFromPermissionRequestsTable(db, "helloRepo");
                 * SQLOperations.DeleteFromPermissionRequestTable(db, 3);
                 * SQLOperations.DeleteFromPermissionRequestTable(db, 4);
                 * SQLOperations.DeleteFromPermissionRequestTable(db, 5);
                 * db.SaveChanges();
                 */

                int actual = SQLOperations.QueryUserFromRequest(db, 4);
                Assert.AreEqual(actual, 2);
                actual = SQLOperations.QueryUserFromRequest(db, 3);
                Assert.AreEqual(actual, 4);

                actual = SQLOperations.QueryMainTrunkFromRequest(db, 5);
                Assert.AreEqual(actual, 6);
                actual = SQLOperations.QueryMainTrunkFromRequest(db, 1);
                Assert.AreEqual(actual, 8);

                /*
                 * actual = SQLOperations.QueryRepositoryIdFromRequest(db, 2);
                 * Assert.AreEqual(actual, 9);
                 * actual = SQLOperations.QueryRepositoryIdFromRequest(db, 3);
                 * Assert.AreEqual(actual, 1);
                 */

                List <PermissionLookup> actualPerms   = SQLOperations.QueryPermissionRequests(db, "imanotherUser");
                List <PermissionLookup> expectedPerms = new List <PermissionLookup>
                {
                    new PermissionLookup {
                        RequestId = 1, RepositoryName = "helloRepo", Message = "permit", RequestingUser = "******"
                    },
                    new PermissionLookup {
                        RequestId = 2, RepositoryName = "helloRepo", Message = "permit", RequestingUser = "******"
                    }
                };

                SameListContents(actualPerms, expectedPerms);
            }
        }
Beispiel #29
0
        //Method to create new character when new character opcode is received
        private static void ProcessCreateChar(Session MySession, List <byte> myPacket)
        {
            //Create NewCharacter object
            Character charCreation = new Character();

            //Log that a new character creation packet was received
            Logger.Info("Received Character Creation Packet");

            //Get length of characters name expected in packet
            int nameLength = myPacket[3] << 24 | myPacket[2] << 16 | myPacket[1] << 8 | myPacket[0];

            //Remove nameLength from packet
            myPacket.RemoveRange(0, 4);

            //var for actual character name
            byte[] characterNameArray = new byte[nameLength];

            //Copy the actual character name to above variable
            myPacket.CopyTo(0, characterNameArray, 0, nameLength);

            //Remove charactername from packet
            myPacket.RemoveRange(0, nameLength);

            //Make charactername readable
            charCreation.CharName = Encoding.Default.GetString(characterNameArray);

            //Before processing a full character creation check if the characters name already exists in the DB.
            //Later this will need to include a character/world combination if additional servers are spun up.
            if (charCreation.CharName == SQLOperations.CheckName(charCreation.CharName))
            {
                myPacket.Clear();
                //List and assignment to hold game op code in bytes to send out
                List <byte> NameTaken = new List <byte>();
                NameTaken.AddRange(BitConverter.GetBytes(GameOpcode.NameTaken));

                //Log character name taken and send out RDP message to pop up that name is taken.
                Console.WriteLine("Character Name Already Taken");
                RdpCommOut.PackMessage(MySession, MessageOpcodeTypes.ShortReliableMessage, GameOpcode.NameTaken);
            }
            //If name not found continue to actually create character
            else
            {
                //Get starting level
                charCreation.Level = Utility_Funcs.Untechnique(myPacket);

                //Divide startLevel by 2 because client doubles it
                //Get single byte attributes
                charCreation.Race          = Utility_Funcs.Untechnique(myPacket);
                charCreation.StartingClass = Utility_Funcs.Untechnique(myPacket);
                charCreation.Gender        = Utility_Funcs.Untechnique(myPacket);
                charCreation.HairColor     = Utility_Funcs.Untechnique(myPacket);
                charCreation.HairLength    = Utility_Funcs.Untechnique(myPacket);
                charCreation.HairStyle     = Utility_Funcs.Untechnique(myPacket);
                charCreation.FaceOption    = Utility_Funcs.Untechnique(myPacket);
                charCreation.HumTypeNum    = Utility_Funcs.Untechnique(myPacket);

                //Get player attributes from packet and remove bytes after reading into variable
                charCreation.AddStrength     = myPacket[3] << 24 | myPacket[2] << 16 | myPacket[1] << 8 | myPacket[0];
                charCreation.AddStamina      = myPacket[7] << 24 | myPacket[6] << 16 | myPacket[5] << 8 | myPacket[4];
                charCreation.AddAgility      = myPacket[11] << 24 | myPacket[10] << 16 | myPacket[9] << 8 | myPacket[8];
                charCreation.AddDexterity    = myPacket[15] << 24 | myPacket[14] << 16 | myPacket[13] << 8 | myPacket[12];
                charCreation.AddWisdom       = myPacket[19] << 24 | myPacket[18] << 16 | myPacket[17] << 8 | myPacket[16];
                charCreation.AddIntelligence = myPacket[23] << 24 | myPacket[22] << 16 | myPacket[21] << 8 | myPacket[20];
                charCreation.AddCharisma     = myPacket[27] << 24 | myPacket[26] << 16 | myPacket[25] << 8 | myPacket[24];

                myPacket.RemoveRange(0, 28);

                //Call SQL method for character creation
                SQLOperations.CreateCharacter(MySession, charCreation);
            }
        }