Ejemplo n.º 1
0
        public bool DeleteAccessRule(string zoneId, string authEmail, string authKey, string ip)
        {
            var list = _cloudFlareApiService.GetAccessRuleList(zoneId, authEmail, authKey, ip, "");
            var rule = list.FirstOrDefault();
            FirewallAccessRuleResponse response = new FirewallAccessRuleResponse
            {
                success = true
            };

            if (rule != null)
            {
                //var zoneList = ZoneBusiness.GetZoneList();
                //var zone = zoneList.FirstOrDefault(a => a.ZoneId == zoneId);

                response = _cloudFlareApiService.DeleteAccessRule(zoneId, authEmail, authKey, rule.id);
                if (response.success)
                {
                    string key = string.Format("GetBlackListModelList:{0}-{1}-{2}", zoneId, authEmail, authKey);
                    Utils.RemoveMemoryCache(key);
                }

                return(response.success);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public bool CreateAccessRule(string zoneId, string authEmail, string authKey, string ip, string comment)
        {
            //var zoneList = ZoneBusiness.GetZoneList();
            //var zone = zoneList.FirstOrDefault(a => a.ZoneId == zoneId);
            FirewallAccessRuleResponse response = new FirewallAccessRuleResponse
            {
                success = true
            };

            //Code review by michael, 这里面是可能有异常的.
            response = _cloudFlareApiService.CreateAccessRule(zoneId, authEmail, authKey, new FirewallAccessRuleRequest
            {
                configuration = new Configuration
                {
                    target = "ip",
                    value  = ip,
                },
                mode  = EnumMode.challenge,
                notes = comment,
            });

            if (response.success)
            {
                string key = string.Format("GetBlackListModelList:{0}-{1}-{2}", zoneId, authEmail, authKey);
                Utils.RemoveMemoryCache(key);
            }

            return(response.success);
        }
        public FirewallAccessRuleResponse DeleteAccessRule(string zoneId, string authEmail, string authKey, 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" });
            //解密
            var    authKeyDecrypt = Utils.AesDecrypt(authKey);
            string content        = HttpDelete(authEmail, authKeyDecrypt, url, json, 90);
            FirewallAccessRuleResponse response = JsonConvert.DeserializeObject <FirewallAccessRuleResponse>(content);

            return(response);
        }