public OptionsWindow(RemoteControlService remoteControlService, PluginManager pluginManager, IconManager iconManager, WebServer webServer, Action shutdownCallback) { RemoteControlService = remoteControlService; PluginManager = pluginManager; _IconManager = iconManager; WebServer = webServer; IPWhitelist = new IPWhitelist(); Interfaces = new ObservableCollection <InterfaceModel>(); ToggleErrorDetails = new DelegateCommand(() => ErrorDetailsVisible = !ErrorDetailsVisible); AddButtonCommand = new DelegateCommand(AddButton); AddToggleButtonCommand = new DelegateCommand(AddToggleButton); AddBoundToggleButtonCommand = new DelegateCommand(AddBoundToggleButton); AddSliderCommand = new DelegateCommand(AddSlider); AddBooleanLabelCommand = new DelegateCommand(AddBooleanLabel); AddFloatLabelCommand = new DelegateCommand(AddFloatLabel); AddStringLabelCommand = new DelegateCommand(AddStringLabel); AddStaticLabelCommand = new DelegateCommand(AddStaticLabel); AddTouchPadCommand = new DelegateCommand(AddTouchPad); OpenPropertiesCommand = new DelegateCommand <RemoteElement>(ShowButtonProperties); RemoveButtonCommand = new DelegateCommand <RemoteElement>(RemoveElement); ShutdownCommand = new DelegateCommand(shutdownCallback); OpenUriCommand = new DelegateCommand <Uri>(OpenUri); OpenPluginsDirectoryCommand = new DelegateCommand(OpenPluginsDirectory); TogglePluginsFlyoutCommand = new DelegateCommand(() => PluginsOpen = !PluginsOpen); ToggleSettingsFlyoutCommand = new DelegateCommand(() => SettingsOpen = !SettingsOpen); ToggleConnectionsFlyoutCommand = new DelegateCommand(() => ConnectionsOpen = !ConnectionsOpen); InitializeComponent(); HashSet <IPAddress> addressSet = new HashSet <IPAddress>(); if (Settings.Default.ListenAddressesCustom != null) { for (int i = Settings.Default.ListenAddressesCustom.Count - 1; i >= 0; i--) { IPAddress addr; if (!IPAddress.TryParse(Settings.Default.ListenAddressesCustom[i], out addr) || !addressSet.Add(addr)) { Settings.Default.ListenAddressesCustom.RemoveAt(i); } } } foreach (var iface in NetworkInterface.GetAllNetworkInterfaces()) { string name = iface.Name; foreach (var ifaceAddressProp in iface.GetIPProperties().UnicastAddresses) { Interfaces.Add(new InterfaceModel(name, ifaceAddressProp.Address, addressSet.Contains(ifaceAddressProp.Address), false, UpdateListenAddresses)); addressSet.Remove(ifaceAddressProp.Address); } } foreach (IPAddress addr in addressSet) { Interfaces.Add(new InterfaceModel(R.UnknownInterface, addr, true, true, UpdateListenAddresses)); } SetValue(PasswordRequiredProperty, !string.IsNullOrEmpty(Settings.Default.RequiredPassword)); }
private void Application_BeginRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpRequest request = application.Context.Request; HttpResponse response = application.Context.Response; if (DomainsBlacklist == null || !DomainsBlacklist.Any() || (request.Url.HostNameType == UriHostNameType.Dns && DomainsBlacklist.Contains(request.Url.Host))) { if (IPWhitelist != null && IPWhitelist.Contains(request.UserHostAddress)) { // IP found, do nothing response.Headers.Add("X-TestUser", "Access by IP"); return; } if (UserWhitelist != null) { string authHeader = request.Headers["Authorization"]; if (authHeader != null) { var authHeaderVal = AuthenticationHeaderValue.Parse(authHeader); // RFC 2617 sec 1.2, "scheme" name is case-insensitive if (authHeaderVal.Scheme.Equals("basic", StringComparison.OrdinalIgnoreCase) && authHeaderVal.Parameter != null) { if (DoesUserExist(authHeaderVal.Parameter)) { // User is valid, do nothing response.Headers.Add("X-TestUser", "Access by credentials"); return; } } } else { // No authenticationheader found, request a username and password response.Clear(); response.StatusCode = 401; response.Headers.Add("WWW-Authenticate", string.Format("Basic realm=\"{0}\"", Realm)); response.End(); } } // No whitelisted IP or user found, block access response.Clear(); response.StatusCode = 403; response.StatusDescription = "Forbidden"; response.End(); } }
public IPExclusion(params string[] ranges) { Whitelist = new IPWhitelist(ranges); }