Beispiel #1
0
        public async Task <IActionResult> PutWhitelist(int id, Whitelist whitelist)
        {
            if (id != whitelist.Id)
            {
                return(BadRequest());
            }

            _context.Entry(whitelist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WhitelistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        private async Task LookupIps(AddEntry message, Whitelist entry)
        {
            var lookup = new LookupClient();
            var result = await lookup.QueryAsync(message.DomainName, QueryType.ANY);

            foreach (var record in result.AllRecords)
            {
                switch (record)
                {
                case ARecord ipRecord:
                    await _uow.InsertAsync(new WhitelistedDomainIp
                    {
                        DomainId    = entry.Id,
                        IpAddress   = ipRecord.Address,
                        IpType      = IpType.Lookup,
                        StoredAtUtc = DateTime.UtcNow
                    });

                    break;

                case AaaaRecord ip6Record:
                    await _uow.InsertAsync(new WhitelistedDomainIp
                    {
                        DomainId    = entry.Id,
                        IpAddress   = ip6Record.Address,
                        IpType      = IpType.Lookup,
                        StoredAtUtc = DateTime.UtcNow
                    });

                    break;
                }
            }
        }
Beispiel #3
0
        private void ExportWhiteListToCsv()
        {
            var list         = Whitelist.Cast <object>().ToList();
            var exportAction = new CsvImportAndExport();

            exportAction.CsvExport <WhitelistMap>(list, "Whitelist.csv");
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Whitelist whitelist = new Whitelist();

            if (divWhitelist.Visible != true)
            {
                whitelist.add(txtReason.Text, Convert.ToDateTime(from.Text), Convert.ToDateTime(to.Text), 0, Convert.ToInt32(ddlWorkstation.SelectedValue));
                lblText.Text = "<br />Record inserted successfully<br />";

                divForm.Visible = false;
                txtReason.Text  = "";
                from.Text       = "";
                to.Text         = "";
            }
            else
            {
                whitelist.edit(Convert.ToInt32(lbl.Text), txtReason.Text, Convert.ToDateTime(from.Text), Convert.ToDateTime(to.Text), 0, Convert.ToInt32(ddlWorkstation.SelectedValue));
                lblText.Text           = "<br />Record modified successfully<br />";
                divForm.Visible        = false;
                divWhitelist.Visible   = false;
                lbl.Text               = "";
                gvWhitelists.EditIndex = -1;
            }

            // Bind the GridView control to the courseInfo collection.
            gvWhitelists.DataSource = whitelist.load();
            gvWhitelists.DataBind();
            btnInsert.Visible = true;
        }
Beispiel #5
0
        private void ImportWhiteListFromCsv()
        {
            var importAction = new CsvImportAndExport();
            var filePath     = importAction.ImportCsv();

            if (filePath is null)
            {
                return;
            }

            try
            {
                var importData = new List <Whitelist>(importAction.GetCsvRecords <Whitelist>(importAction.LoadCsv <WhitelistMap>(filePath)));
                foreach (var data in importData)
                {
                    Whitelist.Add(data);
                }

                MessageBox.Show(Properties.Resources.SuccessfulImport, Properties.Resources.AppName, MessageBoxButton.OK);
            }
            catch (Exception)
            {
                MessageBox.Show(Properties.Resources.ImportFailed, Properties.Resources.AppName, MessageBoxButton.OK);
            }
        }
Beispiel #6
0
        public async Task <ActionResult <Whitelist> > PostWhitelist(Whitelist whitelist)
        {
            _context.Whitelist.Add(whitelist);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetWhitelist", new { id = whitelist.Id }, whitelist));
        }
        public void RequestedResourceIsWhitelisted_ReturnsFalse_IfRequestResourceIsNotWhitelisted()
        {
            using (var context = _apacheLogContextFactory.NewTestContext())
            {
                // Arrange
                context.WhitelistedResources.Add(new WhitelistedResource()
                {
                    BasePath = "media"
                });
                context.SaveChanges();

                // Arrange
                var whitelistedResources = new List <string>()
                {
                    @"media"
                }.AsQueryable();;
                var whitelist     = new Whitelist(context);
                var accessRequest = new AccessRequest()
                {
                    Resource = @"/admin/mysql2/index.php"
                };

                // Act
                var result = whitelist.RequestedResourceIsWhitelisted(accessRequest);

                // Assert
                Assert.False(result);
            }
        }
Beispiel #8
0
 public CQHub(Crypt crypt, Whitelist whitelist, RSA rsa, Action <string> onStatusChange)
 {
     _crypt          = crypt;
     _whitelist      = whitelist;
     _rsa            = rsa;
     _onStatusChange = onStatusChange;
 }
 public WhitelistPresentationStub(Whitelist dbItem)
 {
     this.Id           = dbItem.id;
     this.Barcode      = dbItem.barcode;
     this.TanggalAwal  = dbItem.tanggal_awal;
     this.TanggalAkhir = dbItem.tanggal_akhir;
 }
        public ActionResult Add(Whitelist whitelist)
        {
            ViewBag.Domain = whitelist.Domain;
            Whitelist w = Data.whitelists.Find(x => x.Domain.Equals(whitelist.Domain));
            Blacklist b = Data.blacklists.Find(x => x.Domain.Equals(whitelist.Domain));

            if (b != null)
            {
                ViewBag.AjoutReussi = "blackcontient";
            }
            else if (w != null)
            {
                ViewBag.AjoutReussi = "contient";
            }
            else
            {
                try
                {
                    // Vérifie si le site web existe
                    Dns.GetHostEntry(whitelist.Domain);
                    if (Data.addWhitelist(whitelist.Domain))
                    {
                        ViewBag.AjoutReussi = "reussi";
                    }
                    else
                    {
                        ViewBag.AjoutReussi = "echouer";
                    }
                }
                catch (Exception e)
                {
                    if (!string.IsNullOrEmpty(whitelist.Domain))
                    {
                        //Vérification domain et sous domaine est un .* ou pas
                        if (whitelist.Domain.Equals(".") || Data.TLD.Contains(whitelist.Domain.ToUpper()))
                        {
                            if (Data.addWhitelist(whitelist.Domain))
                            {
                                ViewBag.AjoutReussi = "reussi";
                            }
                            else
                            {
                                ViewBag.AjoutReussi = "echouer";
                            }
                        }
                        else
                        {
                            ViewBag.AjoutReussi = "echouer";
                        }
                    }
                    else
                    {
                        ViewBag.AjoutReussi = "echouer";
                    }
                }
            }

            ViewBag.Whitelist = Data.whitelists;
            return(View("Index"));
        }
Beispiel #11
0
        public void TestScriptTagInWhiteList()
        {
            Whitelist whitelist = Whitelist.Relaxed;

            whitelist.AddTags("script");
            Assert.IsTrue(Dcsoup.IsValid("Hello<script>alert('Doh')</script>World !", whitelist));
        }
Beispiel #12
0
    // Options to be presented once a user has been selected //
    public void PrintUserOptions(User user)
    {
        Console.WriteLine($"Account Age: {user.age}");
        Console.Write($"Game List: ");
        foreach (string game in user.gameList)
        {
            Console.WriteLine($"{game}, ");
        }
        Console.WriteLine($"Reports: {user.reports}");
        Console.WriteLine($"Friend Requests/Friends: {user.requests}/{user.friends}");
        Console.WriteLine();
        Console.WriteLine("1. Blacklist this user.");
        Console.WriteLine("2. Whitelist this user.");
        Console.WriteLine("3. Back");
        Console.Write("Choose an option: ");

        int userOption = Convert.ToInt32(Console.ReadLine());

        if (userOption == 1)
        {
            _users.Remove(user);
            Blacklist newUser = new Blacklist(user.id, user.gameList, user.age, user.reports, user.playtime, user.messages, user.requests, user.friends);
            _users.Add(newUser);
        }
        if (userOption == 2)
        {
            _users.Remove(user);
            Whitelist newUser = new Whitelist(user.id, user.gameList, user.age, user.reports, user.playtime, user.messages, user.requests, user.friends);
            _users.Add(newUser);
        }
        else if (userOption == 3)
        {
            return;
        }
    }
Beispiel #13
0
    // Assigns all users to either blacklist or whitelist //
    public void ScanUsers()
    {
        int whitelisted = 0;
        int blacklisted = 0;

        Console.WriteLine("--#################--");
        Console.WriteLine(_users.Count);
        foreach (User user in _users.ToArray())
        {
            double danger = user.HealthAnalysis();
            if (danger <= 50)
            {
                _users.Remove(user);
                Whitelist newUser = new Whitelist(user.id, user.gameList, user.age, user.reports, user.playtime, user.messages, user.requests, user.friends);
                _users.Add(newUser);
                whitelisted++;
            }
            else if (danger > 50)
            {
                _users.Remove(user);
                Blacklist newUser = new Blacklist(user.id, user.gameList, user.age, user.reports, user.playtime, user.messages, user.requests, user.friends);
                _users.Add(newUser);
                blacklisted++;
            }
        }
        Console.WriteLine("--#################--");
        Console.WriteLine($"Total Whitelisted: {whitelisted}");
        Console.WriteLine($"Total Blacklisted: {blacklisted}");
        Console.WriteLine("--#################--");
    }
Beispiel #14
0
        public void LoadRunningScriptsFromWorld()
        {
            Log.Info("Loading running scripts from world...");
            if (MyAPIGateway.Utilities.FileExistsInWorldStorage(runningScriptsFileName, typeof(ScriptManagerConfig)))
            {
                //Dictionary<long, long> runningScripts;

                Dictionary <long, long> runningScripts = null;
                try
                {
                    using (var reader = MyAPIGateway.Utilities.ReadBinaryFileInWorldStorage(runningScriptsFileName, typeof(ScriptManagerConfig)))
                        runningScripts = MyAPIGateway.Utilities.SerializeFromBinary <Dictionary <long, long> >(reader.ReadBytes((int)reader.BaseStream.Length));

                    //runningScripts = MyAPIGateway.Utilities.SerializeFromXML<Dictionary<long, long>>(serialized);
                }
                catch (Exception e)
                {
                    Log.Warn($"Parsing running scripts failed: {e.Message}");
                    return;
                }

                foreach (var kvp in runningScripts)
                {
                    var script = Whitelist.First(item => item.Id == kvp.Value);
                    AddRunningScript(kvp.Key, script);
                }
            }
        }
Beispiel #15
0
        public void ClientAdminRead(IReadMessage incMsg)
        {
            int count = incMsg.ReadUInt16();

            for (int i = 0; i < count; i++)
            {
                UInt32 key = incMsg.ReadUInt32();
                if (netProperties.ContainsKey(key))
                {
                    bool changedLocally = netProperties[key].ChangedLocally;
                    netProperties[key].Read(incMsg);
                    netProperties[key].TempValue = netProperties[key].Value;

                    if (netProperties[key].GUIComponent != null)
                    {
                        if (!changedLocally)
                        {
                            netProperties[key].GUIComponentValue = netProperties[key].Value;
                        }
                    }
                }
                else
                {
                    UInt32 size = incMsg.ReadVariableUInt32();
                    incMsg.BitPosition += (int)(8 * size);
                }
            }

            ReadMonsterEnabled(incMsg);
            BanList.ClientAdminRead(incMsg);
            Whitelist.ClientAdminRead(incMsg);
        }
Beispiel #16
0
        /// <summary>
        /// Interpreters a series of access tags for a series of vehicle types.
        /// </summary>
        public static bool InterpretAccessValues(IAttributeCollection attributes, Whitelist whiteList, IEnumerable <string> keys, params string[] rootKeys)
        {
            bool?value   = null;
            var  usedKey = string.Empty;

            for (var i = 0; i < rootKeys.Length; i++)
            {
                var currentAccess = Vehicle.InterpretAccessValue(attributes, rootKeys[i]);
                if (currentAccess != null)
                {
                    value   = currentAccess;
                    usedKey = rootKeys[i];
                }
            }
            foreach (var key in keys)
            {
                var currentAccess = Vehicle.InterpretAccessValue(attributes, key);
                if (currentAccess != null)
                {
                    value   = currentAccess;
                    usedKey = key;
                }
            }
            if (!string.IsNullOrWhiteSpace(usedKey))
            {
                whiteList.Add(usedKey);
            }

            return(!value.HasValue || value.Value);
        }
Beispiel #17
0
        public async Task <IActionResult> Edit(int CohortId, string UserId, [Bind("CohortId,UserId,IsMentor")] Whitelist whitelist)
        {
            if (CohortId != whitelist.CohortId || UserId != whitelist.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(whitelist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WhitelistExists(whitelist.CohortId, whitelist.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = whitelist.CohortId }));
            }
            ViewData["CohortId"] = new SelectList(_context.Cohort, "CohortId", "CohortName", whitelist.CohortId);
            return(View(whitelist));
        }
Beispiel #18
0
        public async Task <IActionResult> Create([Bind("CohortId,UserId,IsMentor")] Whitelist whitelist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(whitelist);
                await _context.SaveChangesAsync();

                /* Update user privileges.*/
                var user = await _context.Users.FirstOrDefaultAsync(u => u.Email.ToLower() == whitelist.UserId.ToLower());

                if (user != null)
                {
                    if (whitelist.IsMentor)
                    {
                        await _userManager.AddToRoleAsync(user, Constants.MentorRole);
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, Constants.StudentRole);
                    }
                }

                return(RedirectToAction(nameof(Index), new { id = whitelist.CohortId }));
            }
            ViewData["CohortId"] = new SelectList(_context.Cohort, "CohortId", "CohortName", whitelist.CohortId);
            return(View(whitelist));
        }
Beispiel #19
0
        /// <summary>
        /// Test if the input HTML has only tags and attributes allowed by the Whitelist. Useful for form validation. The input HTML should
        /// still be run through the cleaner to set up enforced attributes, and to tidy the output.
        /// </summary>
        /// <param name="bodyHtml">HTML to test</param>
        /// <param name="whitelist">whitelist to test against</param>
        /// <returns>true if no tags or attributes were removed; false otherwise</returns>
        /// <seealso cref="Clean(string, NSoup.Safety.Whitelist)"/>
        public static bool IsValid(string bodyHtml, Whitelist whitelist)
        {
            Document dirty   = ParseBodyFragment(bodyHtml, string.Empty);
            Cleaner  cleaner = new Cleaner(whitelist);

            return(cleaner.IsValid(dirty));
        }
Beispiel #20
0
        public LanguageIndexer(LanguageSettings languageSettings)
        {
            LanguageSettings = languageSettings;
            Exclusions       = (from item in LanguageSettings.Tokens.Where(y => y.Type == TokenTypeOption.Stop) select item.Content).ToList();

            HashSet <char> hs = new HashSet <char>();

            if (LanguageSettings.Tokens.Any(y => y.Type.Equals(TokenTypeOption.Whitelist)))
            {
                foreach (var item in LanguageSettings.Tokens.Where(x => x.Type.Equals(TokenTypeOption.Whitelist)))
                {
                    foreach (var c in item.Content.ToCharArray())
                    {
                        if (hs.Add(c))
                        {
                            Whitelist.Add(c);
                        }
                    }
                }
            }
            else
            {
                Whitelist.AddRange(Span(65, 90));
                Whitelist.AddRange(Span(97, 122));
            }
        }
        private async Task FetchIps(Whitelist entry)
        {
            using (var cmd = _uow.CreateDbCommand())
            {
                cmd.CommandText =
                    $"SELECT * FROM  WhitelistedDomainIps WHERE DomainId = @domainId";
                cmd.AddParameter("domainId", entry.Id);
                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    var addresses = new List <WhitelistedDomainIp>();
                    while (await reader.ReadAsync())
                    {
                        addresses.Add(new WhitelistedDomainIp()
                        {
                            DomainId    = entry.Id,
                            IpAddress   = IPAddress.Parse((string)reader["IpAddress"]),
                            IpType      = (IpType)(int)reader["IpType"],
                            StoredAtUtc = (DateTime)reader["StoredAtUtc"]
                        });
                    }

                    entry.IpAddresses = addresses.ToArray();
                }
            }
        }
        private async Task UpdateApplications(EditEntry message, Whitelist entry)
        {
            var dbApps = await _uow.ToListAsync <WhitelistedDomainApplication>("DomainId = @id", new { id = message.Id });

            //find new
            var newApps = message.ApplicationIds.Except(dbApps.Select(x => x.ApplicationId));

            foreach (var newApp in newApps)
            {
                var entity = new WhitelistedDomainApplication {
                    DomainId = entry.Id, ApplicationId = newApp
                };
                await _uow.InsertAsync(entity);
            }

            //find removed
            var removedApps = dbApps.Select(x => x.ApplicationId)
                              .Except(message.ApplicationIds)
                              .Select(x => dbApps.First(y => x == y.ApplicationId));

            foreach (var app in removedApps)
            {
                await _uow.DeleteAsync(app);
            }
        }
Beispiel #23
0
        public override async Task ConfigureAsync(string configFile)
        {
            await base.ConfigureAsync(configFile);

            ZoneParser = new ZoneParser(Resources);

            Whitelist = new Whitelist(Resources);

            await Whitelist.LoadDefaultWhitelist();

            GameMessageReceived += HandleGameMessageAsync;
            ServerStopped       += () =>
            {
                foreach (var zone in Zones)
                {
                    Object.Destroy(zone);
                }
            };

            RakNetServer.ClientDisconnected += HandleDisconnect;

            var _ = Task.Run(async() =>
            {
                await ZoneParser.LoadZoneDataAsync((int)ServerSpecification.ZoneId);

                await LoadZone(ServerSpecification);
            });

            Logger.Information($"Setting up world server: {ServerSpecification.Id}");
        }
Beispiel #24
0
        public async Task HandleAsync(IMessageContext context, AddEntry message)
        {
            var entry = new Whitelist {
                DomainName = message.DomainName
            };
            await _uow.InsertAsync(entry);

            foreach (var dto in message.ApplicationIds)
            {
                var entity = new WhitelistedDomainApplication {
                    DomainId = entry.Id, ApplicationId = dto
                };
                await _uow.InsertAsync(entity);
            }

            if (message.IpAddresses?.Length > 0)
            {
                foreach (var ip in message.IpAddresses)
                {
                    var entity = new WhitelistedDomainIp
                    {
                        DomainId    = entry.Id,
                        IpType      = IpType.Manual,
                        IpAddress   = IPAddress.Parse(ip),
                        StoredAtUtc = DateTime.UtcNow
                    };

                    await _uow.InsertAsync(entity);
                }
            }
            else
            {
                await LookupIps(message, entry);
            }
        }
 public WhitelistFormStub(Whitelist dbItem)
     : this()
 {
     this.Id           = dbItem.id;
     this.Barcode      = dbItem.barcode;
     this.TanggalAwal  = dbItem.tanggal_awal;
     this.TanggalAkhir = dbItem.tanggal_akhir;
 }
Beispiel #26
0
        /// <summary>
        /// Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted
        /// tags and attributes.
        /// </summary>
        /// <param name="bodyHtml">Input untrusted HTML (body fragment)</param>
        /// <param name="baseUri">URL to resolve relative URLs against</param>
        /// <param name="whitelist">White-list of permitted HTML elements</param>
        /// <returns>Safe HTML (body fragment)</returns>
        /// <seealso cref="Cleaner.Clean(Document)"/>
        public static string Clean(string bodyHtml, string baseUri, Whitelist whitelist)
        {
            Document dirty   = ParseBodyFragment(bodyHtml, baseUri);
            Cleaner  cleaner = new Cleaner(whitelist);
            Document clean   = cleaner.Clean(dirty);

            return(clean.Body.Html());
        }
 public Whitelist GetDbObject(Whitelist dbItem)
 {
     dbItem.id            = this.Id;
     dbItem.barcode       = this.Barcode;
     dbItem.tanggal_awal  = this.TanggalAwal;
     dbItem.tanggal_akhir = this.TanggalAkhir;
     return(dbItem);
 }
        public void Parse_SingleIPv6()
        {
            string input = "::1";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("::1")));
        }
        public void Parse_Empty()
        {
            string input = "";

            var whitelist = Whitelist.Parse(input);

            Assert.IsFalse(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
Beispiel #30
0
 private void WhitelistLinqAndCollections()
 {
     Whitelist
     .Namespace("System.Linq", Permission.Allowed)
     .Namespace("System.Collections", Permission.Allowed)
     .Namespace("System.Collections.Generic", Permission.Allowed)
     ;
 }