protected override void OnInitialized() { _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new ArgumentNullException()).Result; _newRule = new Infrastructure.Schema.Whitelist(); if (_clientRole != UserRole.Roles.Privileged && _clientRole != UserRole.Roles.Administrator) { throw new Exception(); } Log?fromLog = LogActionService.GetAndUnset(); if (fromLog != null) { Console.WriteLine("From log: " + fromLog.Question); string pattern = @"(?:^|.+\.)" + fromLog.Question.Replace(".", @"\.") + "$"; Rule().Pattern = pattern; } InitValidators(); InitInputs(); // _whitelistTable = new FlareTable <Infrastructure.Schema.Whitelist>( () => _clientRole == UserRole.Roles.Privileged ? WhitelistModel.List(ClientIP !) : WhitelistModel.List(), sessionStorage: SessionStorageService, identifier: "Rules.WhitelistTable", monospace: true); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.ID)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Pattern)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Expires)); _whitelistTable.RegisterColumn("_Edit", sortable: false, filterable: false, displayName: "", width: "56px"); _whitelistTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); _whitelistTable.OnRowClick += whitelist => { }; BuildHeaders(); }
protected override void OnInitialized() { _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new ArgumentNullException()).Result; _newRule = new Infrastructure.Schema.Blacklist(); Log?fromLog = LogActionService.GetAndUnset(); if (fromLog != null) { Console.WriteLine("From log: " + fromLog.Question); string pattern = @"(?:^|.+\.)" + fromLog.Question.Replace(".", @"\.") + "$"; _newRule.Pattern = pattern; } _validator = new Validator <ValidationResult>(); _validator.Register("Pattern", () => { if (_clientRole != UserRole.Roles.Administrator) { return new[] { new Validation <ValidationResult>(ValidationResult.Warning, "You are not permitted to create blacklist rules") } } ; if (string.IsNullOrEmpty(Rule().Pattern)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Required") } } ; if (!Utility.ValidateRegex(Rule().Pattern)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Invalid regular expression") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "Valid") }); }); _patternChangeDebouncer = new Debouncer <string>(pattern => { _validator !.Validate(); _onInputValidation.Trigger(); InvokeAsync(StateHasChanged); }, "", 200); _validator.Validate(); Task.Run(() => { try { BuildBlacklistTable(); } catch (Exception e) { Console.WriteLine(e); } }); // BuildHeaders(); }