public FirewallAccessRuleResponse DeleteAccessRule(string id) { string url = "https://api.cloudflare.com/client/v4/zones/{0}/firewall/access_rules/rules/{1}"; url = string.Format(url, zoneId, id); string json = JsonConvert.SerializeObject(new { cascade = "none" }); string content = HttpDelete(url, json, 90); FirewallAccessRuleResponse response = JsonConvert.DeserializeObject <FirewallAccessRuleResponse>(content); return(response); }
public FirewallAccessRuleResponse EditAccessRule(string id, FirewallAccessRuleRequest request) { string url = "https://api.cloudflare.com/client/v4/zones/{0}/firewall/access_rules/rules/{1}"; url = string.Format(url, zoneId, id); string json = JsonConvert.SerializeObject(request); string content = HttpPut(url, json, 90); FirewallAccessRuleResponse response = JsonConvert.DeserializeObject <FirewallAccessRuleResponse>(content); return(response); }
public void WhitelistIps(List <string> ips, string comment) { //List<FirewallAccessRule> firewallAccessRuleList = logsController.GetFirewallAccessRuleList(); List <FirewallAccessRule> firewallAccessRuleList = cloundFlareApiService.GetAccessRuleList("", "Add By Defense System"); firewallAccessRuleList = firewallAccessRuleList.Where(a => a.mode == EnumMode.whitelist).ToList(); foreach (string ip in ips) { if (!firewallAccessRuleList.Exists(a => a.configurationValue == ip)) { FirewallAccessRuleResponse firewallAccessRuleResponse = cloundFlareApiService.CreateAccessRule(new FirewallAccessRuleRequest { configuration = new Configuration { target = "ip", value = ip, }, mode = EnumMode.whitelist, notes = string.Format("{0}({1})", comment, "Add By Defense System"), }); if (firewallAccessRuleResponse.success) { logsController.InsertFirewallAccessRule(new List <FirewallAccessRule>() { new FirewallAccessRule { id = firewallAccessRuleResponse.result.id, notes = firewallAccessRuleResponse.result.notes, mode = firewallAccessRuleResponse.result.mode, configurationTarget = firewallAccessRuleResponse.result.configuration.target, configurationValue = firewallAccessRuleResponse.result.configuration.value, createTime = firewallAccessRuleResponse.result.created_on, modifiedTime = firewallAccessRuleResponse.result.modified_on, scopeId = firewallAccessRuleResponse.result.scope.id, scopeEmail = firewallAccessRuleResponse.result.scope.email, scopeType = firewallAccessRuleResponse.result.scope.type, } }); } } } }