public void Page_Load(object sender, EventArgs e) { if (!Main.Context.AdminApi.IsPluginAuthorized) { HttpContext.Current.Response.Write("<h1>未授权访问</h1>"); HttpContext.Current.Response.End(); return; } _config = Main.GetConfig(); if (IsPostBack) { return; } RblIpRestrictionType.Items.Add(new ListItem { Text = ERestrictionTypeUtils.GetText(ERestrictionType.None), Value = ERestrictionTypeUtils.GetValue(ERestrictionType.None), Selected = ERestrictionTypeUtils.Equals(ERestrictionType.None, _config.IpRestrictionType) }); RblIpRestrictionType.Items.Add(new ListItem { Text = ERestrictionTypeUtils.GetText(ERestrictionType.BlackList), Value = ERestrictionTypeUtils.GetValue(ERestrictionType.BlackList), Selected = ERestrictionTypeUtils.Equals(ERestrictionType.BlackList, _config.IpRestrictionType) }); RblIpRestrictionType.Items.Add(new ListItem { Text = ERestrictionTypeUtils.GetText(ERestrictionType.WhiteList), Value = ERestrictionTypeUtils.GetValue(ERestrictionType.WhiteList), Selected = ERestrictionTypeUtils.Equals(ERestrictionType.WhiteList, _config.IpRestrictionType) }); DdlIsHostRestriction.Items.Add(new ListItem { Text = "不设置", Value = false.ToString(), Selected = !_config.IsHostRestriction }); DdlIsHostRestriction.Items.Add(new ListItem { Text = "设置", Value = true.ToString(), Selected = _config.IsHostRestriction }); PhHost.Visible = _config.IsHostRestriction; TbHost.Text = _config.Host; }
public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } if (!IsPostBack) { BreadCrumbSettings(AppManager.Settings.LeftMenu.Restriction, "访问限制选项", AppManager.Settings.Permission.SettingsRestriction); ERestrictionTypeUtils.AddListItems(RestrictionType); ControlUtils.SelectListItemsIgnoreCase(RestrictionType, ERestrictionTypeUtils.GetValue(ConfigManager.SystemConfigInfo.RestrictionType)); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (Page.IsPostBack && Page.IsValid) { ConfigManager.SystemConfigInfo.RestrictionType = ERestrictionTypeUtils.GetEnumType(RestrictionType.SelectedValue); try { BaiRongDataProvider.ConfigDao.Update(ConfigManager.Instance); Body.AddAdminLog("设置访问限制选项"); SuccessMessage("访问限制选项修改成功!"); } catch (Exception ex) { FailMessage(ex, "访问限制选项修改失败!"); } } }
public void Startup(IContext context, IService service) { Context = context; _config = Context.ConfigApi.GetConfig <Config>(0) ?? new Config { IpRestrictionType = ERestrictionTypeUtils.GetValue(ERestrictionType.None), IpBlackList = string.Empty, IpWhiteList = string.Empty }; if (_config.IpBlackList == null) { _config.IpBlackList = string.Empty; } if (_config.IpWhiteList == null) { _config.IpWhiteList = string.Empty; } service.AddPluginMenu(PluginMenu); }
public override void Startup(IService service) { _config = ConfigApi.GetConfig <Config>(0) ?? new Config { IpRestrictionType = ERestrictionTypeUtils.GetValue(ERestrictionType.None), IpBlackList = string.Empty, IpWhiteList = string.Empty }; if (_config.IpBlackList == null) { _config.IpBlackList = string.Empty; } if (_config.IpWhiteList == null) { _config.IpWhiteList = string.Empty; } service.AddPluginMenu(PluginMenu); Instance = this; }
public static bool IsVisitAllowed(Config config) { var restrictionType = ERestrictionTypeUtils.GetEnumType(config.IpRestrictionType); var restrictionList = new List <string>(); if (restrictionType == ERestrictionType.BlackList) { restrictionList = new List <string>(config.IpBlackList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)); } else if (restrictionType == ERestrictionType.WhiteList) { restrictionList = new List <string>(config.IpWhiteList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)); } var isAllowed = true; if (restrictionType != ERestrictionType.None) { var userIp = GetIpAddress(); if (restrictionType == ERestrictionType.BlackList) { var list = new IpList(); foreach (var restriction in restrictionList) { AddRestrictionToIpList(list, restriction); } if (list.CheckNumber(userIp)) { isAllowed = false; } } else if (restrictionType == ERestrictionType.WhiteList) { if (restrictionList.Count > 0) { isAllowed = false; var list = new IpList(); foreach (var restriction in restrictionList) { AddRestrictionToIpList(list, restriction); } if (list.CheckNumber(userIp)) { isAllowed = true; } } } } if (isAllowed) { if (config.IsHostRestriction && !string.IsNullOrEmpty(config.Host)) { var currentHost = RemoveProtocolFromUrl(GetHost()); if (!StartsWithIgnoreCase(currentHost, RemoveProtocolFromUrl(config.Host))) { isAllowed = false; } } } return(isAllowed); }