dynamic rule set creation and execution with php |
I didn't know which category to put this topic under. I apologize if I'm in the wrong category.
Hello, I have a form exactly like when adding waf rules in cloudflare. Here the user chooses what and how to evaluate and saves it. I understood the form structure and saved it in my database. but I can't figure out how to dynamically write this rule set on the php side. How can I develop the algorithm that checks the conditions behind this form and executes the result. I need to check the rule set that I read from the database or share in json with php and if there is a matching situation, I need to execute the process in the rule set. Thank you in advance for your help and ideas. I apologize for the bad translation. I set up a database schema like this. PHP Code: {
Do you want to create WAF functionality?
Create a controller filter. See https://codeigniter4.github.io/CodeIgnit...lters.html Throttler code may help you. https://codeigniter4.github.io/CodeIgnit...ttler.html
(04-10-2024, 07:24 PM)kenjis Wrote: Do you want to create WAF functionality? No, I think I was completely misunderstood. I'm setting up a payment fraud algorithm. The administrator creates a rule set in their dashboard and saves it to the database. With php, I am trying to run the rule set saved in the database with a dynamic condition structure that checks every payment.
I assume you just want to implement a class or classes that does the following:
1. retrieve rules from the database 2. perform checks based on the rules Then just run that check before every payment. No controller filter is needed.
(04-12-2024, 12:38 AM)kenjis Wrote: I assume you just want to implement a class or classes that does the following: Yes, that's right, I have a form like below and there are too many rule sets for the administrator to choose from. How can I write the php code of the condition structure of the rule set to be created as a result of all these alternatives in the most performant way? The administrator can create many sets of rules for a member or for any situation. Each time a payment request is received and each time a payment is completed, these fraud control rules should be checked by php in the payment codes. If any rule set is stuck, the operation of that rule set should not be executed. (Add to BlackList, Block Transaction Initiation, Take Payment to Security Review.) Form Image 1 Form Image 2 Form Image 3 the "ve" value in the pictures is and. this can be selected as and or and the rule continues to be added. Here's how I plan it. 1. Create a class called ruleControl. 2. Load all the data to be used for the relevant rule into the class. 3. Loop all conditions of the related rule and compare the related dynamic data. 4. If there is a matching condition, the class returns a condition type and the corresponding operation is executed. However, here is the scenario I cannot set up. 1. How performant would this be? 2. The rule set can be combined with and or. it can even contain complex or statements in parentheses. I can't write this structure in code. How can a rule like if(ip == '192.168.1.1' and last1HourPaymentCount > 2 and (username == 'sdfsfwer' or email == '[email protected]')) be dynamically constructed?
It will be:
PHP Code: ($condition1 and $condition2 and $condition3) and $condition3 will be PHP Code: ($subCondition1 or $subCondition2) |
Welcome Guest, Not a member yet? Register Sign In |