public override bool Equals(object obj) { if (obj == null) { return(false); } IpAddressRange two = obj as IpAddressRange; if (two == null) { return(false); } return(Value == two.Value); }
public void AddToIpsList(List<IpAddressRange> result, IpAddressRange ip, bool warning) { if (ip.Valid == false) { if(warning == true) Engine.Instance.Logs.Log(LogType.Error, MessagesFormatter.Format(Messages.NetworkLockAllowedIpInvalid, ip.ToString())); return; } if (result.Contains(ip)) { if (warning == true) Engine.Instance.Logs.Log(LogType.Warning, MessagesFormatter.Format(Messages.NetworkLockAllowedIpDuplicated, ip.ToString())); return; } result.Add(ip); }
public void AddToIpsList(List <IpAddressRange> result, IpAddressRange ip, bool warning) { if (ip.Valid == false) { if (warning == true) { Engine.Instance.Logs.Log(LogType.Error, Messages.Format(Messages.NetworkLockAllowedIpInvalid, ip.ToString())); } return; } if (result.Contains(ip)) { if (warning == true) { Engine.Instance.Logs.Log(LogType.Warning, Messages.Format(Messages.NetworkLockAllowedIpDuplicated, ip.ToString())); } return; } result.Add(ip); }
public static XmlElement CreateItemAllowAddress(string title, IpAddressRange range) { string address = range.GetAddress().ToString(); string mask = range.GetMask(); XmlDocument xmlDocRule = new XmlDocument(); XmlElement xmlRule = xmlDocRule.CreateElement("rule"); xmlRule.SetAttribute("name", title); if(range.IsV4) xmlRule.SetAttribute("layer", "ipv4"); else if(range.IsV6) xmlRule.SetAttribute("layer", "ipv6"); xmlRule.SetAttribute("action", "permit"); XmlElement XmlIf1 = xmlDocRule.CreateElement("if"); xmlRule.AppendChild(XmlIf1); XmlIf1.SetAttribute("field", "ip_remote_address"); XmlIf1.SetAttribute("match", "equal"); XmlIf1.SetAttribute("address", address); XmlIf1.SetAttribute("mask", mask); return xmlRule; }
public void BuildOVPN() { ServerInfo CurrentServer = Engine.Instance.CurrentServer; Storage s = Engine.Instance.Storage; OvpnBuilder ovpn = new OvpnBuilder(); if (s.GetBool("openvpn.skip_defaults") == false) { ovpn.AppendDirectives(Engine.Instance.Storage.Get("openvpn.directives"), "Client level"); CurrentServer.Provider.OnBuildOvpnDefaults(ovpn); ovpn.AppendDirectives(CurrentServer.OvpnDirectives, "Server level"); } if (s.Get("openvpn.dev_node") != "") ovpn.AppendDirective("dev-node", s.Get("openvpn.dev_node"), ""); int rcvbuf = s.GetInt("openvpn.rcvbuf"); if ((rcvbuf == -2) && (Platform.IsWindows())) rcvbuf = (256 * 1024); if (rcvbuf == -2) rcvbuf = -1; if (rcvbuf != -1) ovpn.AppendDirective("rcvbuf", rcvbuf.ToString(), ""); int sndbuf = s.GetInt("openvpn.sndbuf"); if ((sndbuf == -2) && (Platform.IsWindows())) sndbuf = (256 * 1024); if (sndbuf == -2) sndbuf = -1; if (sndbuf != -1) ovpn.AppendDirective("sndbuf", sndbuf.ToString(), ""); string proxyDirectiveName = ""; string proxyDirectiveArgs = ""; string proxyMode = s.GetLower("proxy.mode"); if (proxyMode == "tor") { proxyDirectiveName = "socks-proxy"; } else if (proxyMode == "http") { proxyDirectiveName = "http-proxy"; } else if (proxyMode == "socks") { proxyDirectiveName = "socks-proxy"; } if (proxyDirectiveName != "") { proxyDirectiveArgs += s.Get("proxy.host") + " " + s.Get("proxy.port"); if ((s.GetLower("proxy.mode") != "none") && (s.GetLower("proxy.mode") != "tor")) { if (s.Get("proxy.auth") != "None") { m_fileProxyAuth = new TemporaryFile("ppw"); string fileNameAuthOvpn = m_fileProxyAuth.Path.Replace("\\", "\\\\"); // 2.6, Escaping for Windows string fileNameData = s.Get("proxy.login") + "\n" + s.Get("proxy.password") + "\n"; Platform.Instance.FileContentsWriteText(m_fileProxyAuth.Path, fileNameData); proxyDirectiveArgs += " \"" + fileNameAuthOvpn + "\" " + s.Get("proxy.auth").ToLowerInvariant(); // 2.6 Auth Fix } } ovpn.AppendDirective(proxyDirectiveName, proxyDirectiveArgs, ""); } string routesDefault = s.Get("routes.default"); if (routesDefault == "out") { ovpn.AppendDirective("route-nopull", "", "For Routes Out"); // For Checking if(CurrentServer.IpExit != "") ovpn.AppendDirective("route", CurrentServer.IpExit + " 255.255.255.255 vpn_gateway", "For Checking Route"); // For DNS // < 2.9. route directive useless, and DNS are forced manually in every supported platform. // TOCLEAN /* ovpn += "dhcp-option DNS " + Constants.DnsVpn + "\n"; // Manually because route-nopull skip it ovpn += "route 10.4.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.5.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.6.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.7.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.8.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.9.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.30.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; ovpn += "route 10.50.0.1 255.255.255.255 vpn_gateway # AirDNS\n"; */ // 2.9, Can be removed when resolv-conf method it's not binded anymore in up/down ovpn directive // TOFIX ovpn.AppendDirective("dhcp-option", "DNS " + Constants.DnsVpn, ""); } string routes = s.Get("routes.custom"); string[] routes2 = routes.Split(';'); foreach (string route in routes2) { string[] routeEntries = route.Split(','); if (routeEntries.Length != 3) continue; IpAddressRange ipCustomRoute = new IpAddressRange(routeEntries[0]); if (ipCustomRoute.Valid == false) Engine.Instance.Logs.Log(LogType.Warning, MessagesFormatter.Format(Messages.CustomRouteInvalid, ipCustomRoute.ToString())); else { string action = routeEntries[1]; string notes = routeEntries[2]; if ((routesDefault == "out") && (action == "in")) ovpn.AppendDirective("route", ipCustomRoute.ToOpenVPN() + " vpn_gateway", Utils.SafeString(notes)); if ((routesDefault == "in") && (action == "out")) ovpn.AppendDirective("route", ipCustomRoute.ToOpenVPN() + " net_gateway", Utils.SafeString(notes)); } } if (routesDefault == "in") { if (proxyMode == "tor") { List<string> torNodeIps = TorControl.GetGuardIps(); foreach (string torNodeIp in torNodeIps) { ovpn.AppendDirective("route", torNodeIp + " 255.255.255.255 net_gateway", "Tor Circuit"); } } } ovpn.AppendDirective("management", "127.0.0.1 " + Engine.Instance.Storage.Get("openvpn.management_port"), ""); ovpn.AppendDirectives(Engine.Instance.Storage.Get("openvpn.custom"), "Custom level"); // Experimental - Allow identification as Public Network in Windows. Advanced Option? // ovpn.Append("route-metric 512"); // ovpn.Append("route 0.0.0.0 0.0.0.0"); // Used by OpenVPN provider if (ovpn.ExistsDirective("auth-user-pass")) { m_filePasswordAuth = new TemporaryFile("ppw"); string fileNameAuthOvpn = m_filePasswordAuth.Path.Replace("\\", "\\\\"); string login = CurrentServer.Provider.GetLogin(); string password = CurrentServer.Provider.GetPassword(); string fileNameData = login + "\n" + password + "\n"; Platform.Instance.FileContentsWriteText(m_filePasswordAuth.Path, fileNameData); proxyDirectiveArgs += " \"" + fileNameAuthOvpn + "\" " + s.Get("proxy.auth").ToLowerInvariant(); ovpn.AppendDirective("auth-user-pass", "\"" + fileNameAuthOvpn + "\"", "Auth"); } CurrentServer.Provider.OnBuildOvpn(ovpn); CurrentServer.Provider.OnBuildOvpnAuth(ovpn); Platform.Instance.OnBuildOvpn(ovpn); ovpn.Normalize(); string ovpnText = ovpn.Get(); CurrentServer.Provider.OnBuildOvpnPost(ref ovpnText); Engine.Instance.ConnectedOVPN = ovpnText; m_ovpn = ovpn; }