/// <summary> /// Скалярное произведение двух действителььных функций на сетке /// </summary> /// <param name="f"></param> /// <param name="g"></param> /// <param name="c"></param> /// <returns></returns> public static double ScalarP(Func <double, double> f, Func <double, double> g, double[] c) { NetFunc a = new NetFunc(f, c); NetFunc b = new NetFunc(g, c); return(ScalarP(a, b)); }
/// <summary> /// Скалярное произведение сеточной и действительной функции /// </summary> /// <param name="a"></param> /// <param name="f"></param> /// <returns></returns> public static double ScalarP(NetFunc a, Func <double, double> f) { double[] c = a.Arguments; NetFunc b = new NetFunc(f, c); return(ScalarP(a, b)); }
public LogItem(Program.LogEntry entry, string name) { this.entry = entry; this.name = name != null ? name : "[unknown progream]"; this.IsLocal = NetFunc.IsLocalHost(entry.FwEvent.RemoteAddress); this.IsMulti = NetFunc.IsMultiCast(entry.FwEvent.RemoteAddress); this.IsLan = FirewallRule.MatchAddress(entry.FwEvent.RemoteAddress, FirewallRule.AddrKeywordLocalSubnet); }
public static bool MatchAddress(IPAddress Address, string strRanges, NetworkMonitor.AdapterInfo NicInfo = null) { int type = Address.GetAddressBytes().Length == 4 ? 4 : 6; BigInteger numIP = NetFunc.IpToInt(Address); foreach (string range in strRanges.Split(',')) { string[] strTemp = range.Split('-'); if (strTemp.Length == 1) { if (strTemp[0].Contains("/")) // ip/net { string[] strTemp2 = strTemp[0].Split('/'); int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp2[0], out temp); int pow = MiscFunc.parseInt(strTemp2[1]); BigInteger num2 = num1 + BigInteger.Pow(new BigInteger(2), pow); if (type == temp && num1 <= numIP && numIP <= num2) { return(true); } } else { string Addresses = GetSpecialNet(strTemp[0].Trim(), NicInfo); if (Addresses != null) { if (Addresses.Length > 0) { return(MatchAddress(Address, Addresses)); } } else { int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp[0], out temp); if (type == temp && num1 == numIP) { return(true); } } } } else if (strTemp.Length == 2) { int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp[0], out temp); BigInteger num2 = NetFunc.IpStrToInt(strTemp[1], out temp); if (type == temp && num1 <= numIP && numIP <= num2) { return(true); } } } return(false); }
public static FirewallRule MakeBlockInetRule(ProgramList.ID id, Firewall.Directions direction, long expiration = 0) { FirewallRule rule = new FirewallRule(id); rule.Name = MakeRuleName(BlockInet, expiration != 0); rule.Grouping = RuleGroup; rule.Action = Firewall.Actions.Block; rule.Direction = direction; rule.Enabled = true; rule.RemoteAddresses = NetFunc.GetNonLocalNet(); rule.Expiration = expiration; return(rule); }
public static bool MatchAddress(string strIP, string strRanges) { int type; BigInteger numIP = NetFunc.IpStrToInt(strIP, out type); foreach (string range in strRanges.Split(',')) { string[] strTemp = range.Split('-'); if (strTemp.Length == 1) { if (strTemp[0].Contains("/")) // ip/net { string[] strTemp2 = strTemp[0].Split('/'); int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp2[0], out temp); int pow = MiscFunc.parseInt(strTemp2[1]); BigInteger num2 = num1 + BigInteger.Pow(new BigInteger(2), pow); if (type == temp && num1 <= numIP && numIP <= num2) { return(true); } } else if (FirewallRule.SpecialAddresses.Contains(strTemp[0].Trim(), StringComparer.OrdinalIgnoreCase)) { return(MatchAddress(strIP, NetFunc.GetSpecialNet(strTemp[0].Trim()))); } else { int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp[0], out temp); if (type == temp && num1 == numIP) { return(true); } } } else if (strTemp.Length == 2) { int temp; BigInteger num1 = NetFunc.IpStrToInt(strTemp[0], out temp); BigInteger num2 = NetFunc.IpStrToInt(strTemp[1], out temp); if (type == temp && num1 <= numIP && numIP <= num2) { return(true); } } } return(false); }
/// <summary> /// Скалярное произведение сеточных функций /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static double ScalarP(NetFunc a, NetFunc b) { if (a.Knots.Count != b.Knots.Count) { throw new Exception("Сеточные функции имеют разную размерность!"); } double sum = 0; for (int i = 0; i < a.Knots.Count; i++) { sum += a[i] * b[i]; } sum /= a.Knots.Count; return(sum); }
/// <summary> /// Расстояние между сеточными функциями /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static double Distance(NetFunc a, NetFunc b) { if (a.Knots.Count != b.Knots.Count) { throw new Exception("Сеточные функции имеют разную размерность!"); } double sum = 0; for (int i = 0; i < a.Knots.Count; i++) { sum += (a[i] - b[i]) * (a[i] - b[i]); } sum /= a.Knots.Count; return(Math.Sqrt(sum)); }
public bool OnActivity(ProgramSet prog, Program program, Priv10Engine.FwEventArgs args) { ProgramControl item = null; if (!ProgramList.Items.TryGetValue(args.guid.ToString(), out item)) { if (FirewallPage.DoFilter(CurFilter, prog)) { return(false); } item = ProgramList.AddItem(prog); args.update = false; } //Note: windows firewall doesn't block localhost acces so we ignore it //if (args.entry.State == Program.LogEntry.States.RuleError // && args.entry.FwEvent.Action == FirewallRule.Actions.Allow // && !NetFunc.IsLocalHost(args.entry.FwEvent.RemoteAddress)) // item.SetError(true); if ((chkNoLocal.IsChecked != true || (!NetFunc.IsLocalHost(args.entry.FwEvent.RemoteAddress) && !NetFunc.IsMultiCast(args.entry.FwEvent.RemoteAddress))) && (chkNoLan.IsChecked != true || !FirewallRule.MatchAddress(args.entry.FwEvent.RemoteAddress, FirewallRule.AddrKeywordLocalSubnet)) && args.entry.FwEvent.ProcessId != ProcFunc.CurID) // Note: When DNS proxy is nabled we are always very active, so ignore it { switch (args.entry.FwEvent.Action) { case FirewallRule.Actions.Allow: item.Flash(Colors.LightGreen); break; case FirewallRule.Actions.Block: item.Flash(Colors.LightPink); break; } } item.DoUpdate(prog); return(SortBy == Sorts.LastActivity); }
public LogEntry(FirewallEvent Event, ProgramID progID) { guid = Guid.NewGuid(); FwEvent = Event; ProgID = progID; if (NetFunc.IsLocalHost(FwEvent.RemoteAddress)) { Realm = Realms.LocalHost; } else if (NetFunc.IsMultiCast(FwEvent.RemoteAddress)) { Realm = Realms.MultiCast; } else if (FirewallManager.MatchAddress(FwEvent.RemoteAddress, FirewallRule.AddrKeywordLocalSubnet)) { Realm = Realms.LocalArea; } else { Realm = Realms.Internet; } }
/// <summary> /// Кубический сплайн по сеточной функции с коэффициентами условий на границе /// </summary> /// <param name="f"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="is0outcut">Должна ли функция равняться 0 вне отрезка задания</param> /// <returns></returns> public static Func <double, double> ToSpline(this NetFunc f, double a = 0, double b = 0, bool is0outcut = true) => Polynom.CubeSpline(f.Points, a, b, is0outcut);
public void EvaluateRules(Program prog, bool apply) { String InetRanges = NetFunc.GetNonLocalNet(); prog.config.CurAccess = Program.Config.AccessLevels.Unconfigured; bool StrictTest = false; if (prog.Rules.Count > 0) { SortedDictionary <ProgramList.ID, RuleStat> RuleStats = new SortedDictionary <ProgramList.ID, RuleStat>(); int enabledCound = 0; foreach (FirewallRule rule in prog.Rules.Values.ToList()) { RuleStat Stat; if (!RuleStats.TryGetValue(rule.mID, out Stat)) { Stat = new RuleStat(); RuleStats.Add(rule.mID, Stat); } if (!rule.Enabled) { continue; } enabledCound++; if (!IsEmptyOrStar(rule.LocalAddresses)) { continue; } if (!IsEmptyOrStar(rule.LocalPorts) || !IsEmptyOrStar(rule.RemotePorts)) { continue; } if (!IsEmptyOrStar(rule.IcmpTypesAndCodes)) { continue; } bool AllProts = (rule.Protocol == (int)NetFunc.KnownProtocols.Any); bool InetProts = AllProts || (rule.Protocol == (int)FirewallRule.KnownProtocols.TCP) || (rule.Protocol == (int)FirewallRule.KnownProtocols.UDP); if (!InetProts) { continue; } if (rule.Profile != (int)Profiles.All && (rule.Profile != ((int)Profiles.Public | (int)Profiles.Private | (int)Profiles.Domain))) { continue; } if (rule.Interface != (int)Interfaces.All) { continue; } if (IsEmptyOrStar(rule.RemoteAddresses)) { if (rule.Action == Actions.Allow && InetProts) { Stat.AllowAll |= ((int)rule.Direction); } else if (rule.Action == Actions.Block && AllProts) { Stat.BlockAll |= ((int)rule.Direction); } } else if (rule.RemoteAddresses == InetRanges) { if (rule.Action == Actions.Block && AllProts) { Stat.BlockInet |= ((int)rule.Direction); } } else if (rule.RemoteAddresses == "LocalSubnet") { if (rule.Action == Actions.Allow && InetProts) { Stat.AllowLan |= ((int)rule.Direction); } } RuleStats[rule.mID] = Stat; } RuleStat MergedStat = RuleStats.Values.ElementAt(0); for (int i = 1; i < RuleStats.Count; i++) { RuleStat Stat = RuleStats.Values.ElementAt(i); MergedStat.AllowAll &= Stat.AllowAll; MergedStat.BlockAll &= Stat.BlockAll; MergedStat.AllowLan &= Stat.AllowLan; MergedStat.BlockInet &= Stat.BlockInet; } if ((MergedStat.BlockAll & (int)Directions.Outboun) != 0 && (!StrictTest || (MergedStat.BlockAll & (int)Directions.Inbound) != 0)) { prog.config.CurAccess = Program.Config.AccessLevels.BlockAccess; } else if ((MergedStat.AllowAll & (int)Directions.Outboun) != 0 && (!StrictTest || (MergedStat.AllowAll & (int)Directions.Inbound) != 0)) { prog.config.CurAccess = Program.Config.AccessLevels.FullAccess; } else if ((MergedStat.AllowLan & (int)Directions.Outboun) != 0 && (!StrictTest || ((MergedStat.AllowLan & (int)Directions.Inbound) != 0 && (MergedStat.AllowLan & (int)Directions.Inbound) != 0))) { prog.config.CurAccess = Program.Config.AccessLevels.LocalOnly; } else if (enabledCound > 0) { prog.config.CurAccess = Program.Config.AccessLevels.CustomConfig; } } if (!apply || prog.config.NetAccess == Program.Config.AccessLevels.Unconfigured || prog.config.NetAccess == Program.Config.AccessLevels.CustomConfig) { return; } if (prog.config.NetAccess == prog.config.CurAccess) { return; } if (prog.config.NetAccess != Program.Config.AccessLevels.CustomConfig) { DisableUserRules(prog); } ClearPrivRules(prog); foreach (ProgramList.ID id in prog.IDs) { for (int i = 1; i <= 2; i++) { Directions direction = (Directions)i; switch (prog.config.NetAccess) { case Program.Config.AccessLevels.FullAccess: // add and enable allow all rule UpdateRule(FirewallRule.MakeAllowRule(id, direction), true); break; case Program.Config.AccessLevels.LocalOnly: // create block rule only of we operate in blacklist mode //if (GetFilteringMode() == FilteringModes.BlackList) //{ //add and enable block rules for the internet UpdateRule(FirewallRule.MakeBlockInetRule(id, direction), true); //} //add and enable allow rules for the lan UpdateRule(FirewallRule.MakeAllowLanRule(id, direction), true); break; case Program.Config.AccessLevels.BlockAccess: // add and enable broad block rules UpdateRule(FirewallRule.MakeBlockRule(id, direction), true); break; } } } prog.config.CurAccess = prog.config.NetAccess; App.engine.NotifyChange(prog); }
/// <summary> /// Решение приведённого ОДУ первого порядка /// </summary> /// <param name="f">Свободная функция переменных u и x, где u - искомая функция</param> /// <param name="begin">Начальный аргумент по задаче Коши</param> /// <param name="end">Конечный аргумент</param> /// <param name="step">Шаг интегрирования</param> /// <param name="M">Метод поиска решения</param> /// <param name="begval">Значение функции при начальном аргументе</param> /// <param name="eps">Допустимый уровень расчётных погрешностей</param> /// <returns></returns> public static NetFunc ODUsearch(DRealFunc f, double begin = 0, double end = 10, double step = 0.01, Method M = Method.E1, double begval = 1, double eps = 0.0001, bool controllingstep = false) { double thisstep = step; NetFunc res = new NetFunc(); res.Add(new Point(begin, begval)); step *= Math.Sign(end - begin); Matrix A; switch (M) { case Method.E1: A = E1; break; case Method.E2: A = E2; break; case Method.H: A = H; break; case Method.RK3: A = RK3; break; case Method.RK4: A = Rk4; break; case Method.P38: A = P38; break; case Method.F: A = F; break; default: A = C; break; } int r = A.RowCount - 1; if (A.RowCount != A.ColCount) { r--; } while (begin < /*=*/ end) { double u = res.LastVal(); double t = res.LastArg(); double[] k = new double[r]; double tmp = 0, tmpp = 0; int stepchange = 0; //double[] h2 = new double[2]; //Get2Tmp(ref tmp, ref tmpp, step/2, A, k, f, u, t, r); //double uh1 = u + tmp * step/2; //Get2Tmp(ref tmp, ref tmpp, step / 2, A, k, f, uh1, t+step/2, r); //double uh2 = uh1 + tmp * step/2; Get2Tmp(ref tmp, ref tmpp, step, A, k, f, u, t, r); double val1 = u + step * tmp, val2 = u + step * tmpp; double R = 0.2 * Math.Abs(val1 - val2); if (controllingstep && stepchange <= MaxStepChange) { Get2Tmp(ref tmp, ref tmpp, step / 2, A, k, f, u, t, r); double uh1 = u + tmp * step / 2; Get2Tmp(ref tmp, ref tmpp, step / 2, A, k, f, uh1, t + step / 2, r); double uh2 = uh1 + tmp * step / 2; int p; switch (M) { case Method.E1: p = 1; break; case Method.E2: p = 2; break; case Method.H: p = 3; break; case Method.RK3: p = 3; break; case Method.RK4: p = 4; break; case Method.P38: p = 4; break; case Method.F: p = 3; break; default: p = 4; break; } double RR; if (A.RowCount != A.ColCount) { RR = Math.Abs((uh2 - val2) / (1 - 1.0 / Math.Pow(2, p))); } else { RR = Math.Abs((uh2 - val1) / (1 - 1.0 / Math.Pow(2, p))); } /*if (RR < eps / 64) { step *= 2; stepchange++; } * else */ if (RR > eps) { step /= 2; stepchange++; } else { begin += step; step = thisstep;//возврат к исходному шагу if (A.RowCount != A.ColCount) { res.Add(new Point(begin, val2)); } else { res.Add(new Point(begin, val1)); } } } else if (A.RowCount != A.ColCount && stepchange <= MaxStepChange) { if (R > eps) { step /= 2; stepchange++; } else if (R <= eps / 64) { begin += step; res.Add(new Point(begin, val2)); step *= 2; stepchange++; } else { begin += step; res.Add(new Point(begin, val2)); } } else { begin += step; res.Add(new Point(begin, val1)); } if (Math.Abs(end - begin) < step) { step = Math.Abs(end - begin); } } return(res); }
private bool SocksFilter(object obj) { var item = obj as SocketItem; if (socketFilter != FirewallPage.FilterPreset.Socket.Any) { switch (socketFilter) { case FirewallPage.FilterPreset.Socket.TCP: if ((item.sock.ProtocolType & (UInt32)IPHelper.AF_PROT.TCP) == 0) { return(false); } break; case FirewallPage.FilterPreset.Socket.Client: if ((item.sock.ProtocolType & (UInt32)IPHelper.AF_PROT.TCP) == 0 || item.sock.State == (int)IPHelper.MIB_TCP_STATE.LISTENING) { return(false); } break; case FirewallPage.FilterPreset.Socket.Server: if ((item.sock.ProtocolType & (UInt32)IPHelper.AF_PROT.TCP) == 0 || item.sock.State != (int)IPHelper.MIB_TCP_STATE.LISTENING) { return(false); } break; case FirewallPage.FilterPreset.Socket.UDP: if ((item.sock.ProtocolType & (UInt32)IPHelper.AF_PROT.UDP) == 0) { return(false); } break; case FirewallPage.FilterPreset.Socket.Web: if ((item.sock.ProtocolType & (UInt32)IPHelper.AF_PROT.TCP) == 0 || !(item.sock.RemotePort == 80 || item.sock.RemotePort == 443)) { return(false); } break; } } if (item.sock.RemoteAddress != null) { if (NetFunc.IsLocalHost(item.sock.RemoteAddress)) { if (chkNoLocal.IsChecked == true) { return(false); } } /*else if (NetFunc.IsMultiCast(item.sock.RemoteAddress)) * { * if (chkNoMulti.IsChecked == true) * return false; * }*/ else if (FirewallRule.MatchAddress(item.sock.RemoteAddress, FirewallRule.AddrKeywordLocalSubnet)) { if (chkNoLAN.IsChecked == true) { return(false); } } else if (chkNoINet.IsChecked == true) { return(false); } } if (FirewallPage.DoFilter(textFilter, item.name, new List <ProgramID>() { item.sock.ProgID })) { return(false); } return(true); }
/// <summary> /// Конструктор копирования /// </summary> /// <param name="f"></param> public NetFunc(NetFunc f) { this.Knots = new List <Point>(f.Knots); }
/// <summary> /// Расстояние между сеточной функцией и действительной функцией /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static double Distance(NetFunc a, Func <double, double> b) { NetFunc c = new NetFunc(b, a.Arguments); return(Distance(a, c)); }
/// <summary> /// Решение задачи Штурма-Лиувилля /// </summary> /// <param name="g">Функция внутри второй производной</param> /// <param name="h">Функция при первой производной</param> /// <param name="s">Функция при искомой функции</param> /// <param name="f">Свободная функция</param> /// <param name="a">Начало отрезка</param> /// <param name="b">Конец отрезка</param> /// <param name="N">Число шагов</param> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> /// <param name="A1"></param> /// <param name="B1"></param> /// <param name="C1"></param> /// <param name="D1"></param> /// <returns></returns> public static NetFunc SchLiuQu(Func <double, double> g, Func <double, double> h, Func <double, double> s, Func <double, double> f, out double nevaska, double a = 0, double b = 10, int N = 50, double A = 1, double B = 1, double D = 1, double A1 = 1, double B1 = 1, double D1 = 1, bool firstkind = true) { double[] hn = new double[N + 1], fn = new double[N + 1], sn = new double[N + 1], tn = new double[N + 1], an = new double[N + 1], bn = new double[N + 1], cn = new double[N + 1], dn = new double[N + 1]; double t = (b - a) / N; for (int i = 0; i < N + 1; i++) { double arg = a + i * t; tn[i] = arg; hn[i] = h(arg); fn[i] = f(arg); sn[i] = s(arg); an[i] = (g(arg - t / 2) / t - hn[i] / 2) / t; cn[i] = (g(arg + t / 2) / t + hn[i] / 2) / t; bn[i] = an[i] + cn[i] - sn[i]; //поставил sn вместо hn //bn[i] = (g(arg + t / 2) - g(arg - t / 2)) / t / t - sn[i]; dn[i] = fn[i]; } double k1 = 0, k2 = 0; if (firstkind) { bn[0] = A / t - B; cn[0] = A / t; dn[0] = D; an[N] = -A1 / t; bn[N] = -A1 / t - B1; dn[N] = D1; } else { bn[0] = 3 * A / 2 / t - B; cn[0] = 2 * A / t; k1 = -A / 2 / t; bn[N] = -3 * A1 / 2 / t - B1; an[N] = -2 * A1 / t; k2 = A1 / 2 / t; } dn[0] = D; dn[N] = D1; SLAU S = new SLAU(N + 1); S.A[0, 0] = -bn[0]; S.A[0, 1] = cn[0]; S.A[0, 2] = k1; S.A[N, N - 1] = an[N]; S.A[N, N - 2] = k2; S.A[N, N] = -bn[N]; S.b[0] = dn[0]; S.b[N] = dn[N]; for (int i = 1; i < N; i++) { S.A[i, 0 + i - 1] = an[i]; S.A[i, 1 + i - 1] = -bn[i]; S.A[i, 2 + i - 1] = cn[i]; S.b[i] = dn[i]; } S.Show(); "".Show(); double c1 = S.A[0, 2] / S.A[1, 2], c2 = S.A[N, N - 2] / S.A[N - 1, N - 2]; for (int i = 0; i < 3; i++) { S.A[0, i] -= S.A[1, i] * c1; S.A[N, N - i] -= S.A[N - 1, N - i] * c2; } S.b[0] -= S.b[1] * c1; S.b[N] -= S.b[N - 1] * c2; //S.Show(); "".Show(); S.ProRace(); S.Show(); nevaska = S.Nevaska; NetFunc res = new NetFunc(); for (int i = 0; i < N + 1; i++) { res.Add(new Point(tn[i], S.x[i])); } return(res); }
/// <summary> /// Норма сеточной функции /// </summary> /// <param name="a"></param> /// <returns></returns> public double Norm(NetFunc a) { return(Math.Sqrt(NetFunc.ScalarP(a, a))); }
/// <summary> /// Скалярное произведение сеточной и действительной функции /// </summary> /// <param name="f"></param> /// <param name="a"></param> /// <returns></returns> public static double ScalarP(Func <double, double> f, NetFunc a) { return(NetFunc.ScalarP(a, f)); }
public void GetHostName(int processId, IPAddress remoteAddress, object target, Action <object, string, NameSources> setter) { // sanity check if (remoteAddress.Equals(IPAddress.Any) || remoteAddress.Equals(IPAddress.IPv6Any)) { return; } if (remoteAddress.Equals(IPAddress.Loopback) || remoteAddress.Equals(IPAddress.IPv6Loopback)) { setter(target, "localhost", NameSources.ReverseDns); return; } if (NetFunc.IsMultiCast(remoteAddress)) { setter(target, "multicast.arpa", NameSources.ReverseDns); return; } NameSources Await = NameSources.None; if (queryWatcher.IsActive()) { string capturedName = FindMostRecentHost(queryWatcher.FindHostNames(processId, remoteAddress)); if (capturedName == null) { Await |= NameSources.CapturedQuery; } else { setter(target, capturedName, NameSources.CapturedQuery); } } if (Await != NameSources.None) { string cachedName = FindMostRecentHost(dnsCacheMonitor.FindHostNames(remoteAddress)); if (cachedName == null) { Await |= NameSources.CachedQuery; } else { setter(target, cachedName, NameSources.CachedQuery); } } int ReverseResolve = App.GetConfigInt("DnsInspector", "UseReverseDNS", 0); if (ReverseResolve == 2 || (ReverseResolve == 1 && (Await & NameSources.CachedQuery) != 0)) { string resolvedName = FindMostRecentHost(hostNameResolver.ResolveHostNames(remoteAddress)); if (resolvedName == null) { Await |= NameSources.ReverseDns; } else { setter(target, resolvedName, NameSources.ReverseDns); } } if (Await != NameSources.None) { HostObserveJob job = new HostObserveJob() { target = new WeakReference(target), setter = setter, processId = processId, remoteAddress = remoteAddress, Await = Await, timeOut = DateTime.Now.AddSeconds(30) }; ObserverJobs.Add(remoteAddress, job); } }
public static bool ValidateAddress(string Address, ref string reason) { string[] strTemp = Address.Split('-'); if (strTemp.Length == 1) { int temp; BigInteger num; if (strTemp[0].Contains("/")) // ip/net { string[] strTemp2 = strTemp[0].Split('/'); if (strTemp2.Length != 2) { reason = Translate.fmt("err_invalid_subnet"); return(false); } num = NetFunc.IpStrToInt(strTemp2[0], out temp); int pow = MiscFunc.parseInt(strTemp2[1]); BigInteger num2 = num + BigInteger.Pow(new BigInteger(2), pow); BigInteger numMax = NetFunc.MaxIPofType(temp); if (num2 > numMax) { reason = Translate.fmt("err_invalid_subnet"); return(false); } } else { num = NetFunc.IpStrToInt(strTemp[0], out temp); } if (temp != 4 && temp != 6) { reason = Translate.fmt("err_invalid_ip"); return(false); } } else if (strTemp.Length == 2) { int tempL; BigInteger numL = NetFunc.IpStrToInt(strTemp[0], out tempL); int tempR; BigInteger numR = NetFunc.IpStrToInt(strTemp[1], out tempR); if ((tempL != 4 && tempL != 6) || tempL != tempR) { reason = Translate.fmt("err_invalid_ip"); return(false); } if (!(numL < numR)) { reason = Translate.fmt("err_invalid_range"); return(false); } } else { reason = Translate.fmt("err_invalid_range"); return(false); } return(true); }
public RuleWindow(List <Program> progs, FirewallRule rule) { InitializeComponent(); this.Title = Translate.fmt("wnd_rule"); this.grpRule.Header = Translate.fmt("lbl_rule"); this.lblName.Text = Translate.fmt("lbl_name"); this.lblGroup.Text = Translate.fmt("lbl_group"); this.grpProgram.Header = Translate.fmt("lbl_program"); this.lblProgram.Text = Translate.fmt("lbl_program"); this.lblExecutable.Text = Translate.fmt("lbl_exe"); this.lblService.Text = Translate.fmt("lbl_svc"); this.lblApp.Text = Translate.fmt("lbl_app"); this.grpAction.Header = Translate.fmt("grp_action"); this.lblAction.Text = Translate.fmt("lbl_action"); this.radProfileAll.Content = Translate.fmt("lbl_prof_all"); this.radProfileCustom.Content = Translate.fmt("lbl_prof_sel"); this.chkPublic.Content = Translate.fmt("lbl_prof_pub"); this.chkDomain.Content = Translate.fmt("lbl_prof_dmn"); this.chkPrivate.Content = Translate.fmt("lbl_prof_priv"); this.radNicAll.Content = Translate.fmt("lbl_itf_all"); this.radNicCustom.Content = Translate.fmt("lbl_itf_select"); this.chkLAN.Content = Translate.fmt("lbl_itf_lan"); this.chkVPN.Content = Translate.fmt("lbl_itf_vpn"); this.chkWiFi.Content = Translate.fmt("lbl_itf_wifi"); this.grpNetwork.Header = Translate.fmt("grp_network"); this.lblDirection.Text = Translate.fmt("lbl_direction"); this.lblProtocol.Text = Translate.fmt("lbl_protocol"); this.lblLocalPorts.Text = Translate.fmt("lbl_local_port"); this.lblRemotePorts.Text = Translate.fmt("lbl_remote_port"); this.lblICMP.Text = Translate.fmt("lbl_icmp"); this.lblLocalIP.Text = Translate.fmt("lbl_local_ip"); this.lblRemoteIP.Text = Translate.fmt("lbl_remote_ip"); this.btnOK.Content = Translate.fmt("lbl_ok"); this.btnCancel.Content = Translate.fmt("lbl_cancel"); Rule = rule; bool bNew = Rule.guid == null; viewModel = new RuleWindowViewModel(); DataContext = viewModel; //txtName.Text = Rule.Name; viewModel.RuleName = Rule.Name; cmbGroup.ItemsSource = GroupModel.GetInstance().GetGroups(); if (!WpfFunc.CmbSelect(cmbGroup, Rule.Grouping)) { cmbGroup.Text = Rule.Grouping; } txtInfo.Text = Rule.Description; foreach (Program prog in progs) { ContentControl program = new ContentControl() { Content = prog.Description, Tag = prog.ID }; cmbProgram.Items.Add(program); if (Rule.ProgID != null && prog.ID.CompareTo(Rule.ProgID) == 0) { cmbProgram.SelectedItem = program; } } cmbAction.Items.Add(new ContentControl() { Content = Translate.fmt("str_allow"), Tag = FirewallRule.Actions.Allow }); cmbAction.Items.Add(new ContentControl() { Content = Translate.fmt("str_block"), Tag = FirewallRule.Actions.Block }); //WpfFunc.CmbSelect(cmbAction, Rule.Action.ToString()); viewModel.RuleAction = WpfFunc.CmbPick(cmbAction, Rule.Action.ToString()); if (Rule.Profile == (int)FirewallRule.Profiles.All) { radProfileAll.IsChecked = true; chkPrivate.IsChecked = true; chkDomain.IsChecked = true; chkPublic.IsChecked = true; } else { radProfileCustom.IsChecked = true; chkPrivate.IsChecked = ((Rule.Profile & (int)FirewallRule.Profiles.Private) != 0); chkDomain.IsChecked = ((Rule.Profile & (int)FirewallRule.Profiles.Domain) != 0); chkPublic.IsChecked = ((Rule.Profile & (int)FirewallRule.Profiles.Public) != 0); } if (Rule.Interface == (int)FirewallRule.Interfaces.All) { radNicAll.IsChecked = true; chkLAN.IsChecked = true; chkVPN.IsChecked = true; chkWiFi.IsChecked = true; } else { radNicCustom.IsChecked = true; chkLAN.IsChecked = ((Rule.Interface & (int)FirewallRule.Interfaces.Lan) != 0); chkVPN.IsChecked = ((Rule.Interface & (int)FirewallRule.Interfaces.RemoteAccess) != 0); chkWiFi.IsChecked = ((Rule.Interface & (int)FirewallRule.Interfaces.Wireless) != 0); } if (bNew) { cmbDirection.Items.Add(new ContentControl() { Content = Translate.fmt("str_inandout"), Tag = FirewallRule.Directions.Bidirectiona }); } cmbDirection.Items.Add(new ContentControl() { Content = Translate.fmt("str_outbound"), Tag = FirewallRule.Directions.Outboun }); cmbDirection.Items.Add(new ContentControl() { Content = Translate.fmt("str_inbound"), Tag = FirewallRule.Directions.Inbound }); WpfFunc.CmbSelect(cmbDirection, Rule.Direction.ToString()); cmbProtocol.Items.Add(new ContentControl() { Content = Translate.fmt("pro_any"), Tag = (int)NetFunc.KnownProtocols.Any }); for (int i = (int)NetFunc.KnownProtocols.Min; i <= (int)NetFunc.KnownProtocols.Max; i++) { string name = NetFunc.Protocol2Str((UInt32)i); if (name != null) { cmbProtocol.Items.Add(new ContentControl() { Content = i.ToString() + " - " + name, Tag = i }); } } //if (!WpfFunc.CmbSelect(cmbProtocol, Rule.Protocol.ToString())) // cmbProtocol.Text = Rule.Protocol.ToString(); viewModel.Protocol = WpfFunc.CmbPick(cmbProtocol, Rule.Protocol.ToString()); if (viewModel.Protocol == null) { viewModel.ProtocolTxt = Rule.Protocol.ToString(); } UpdatePorts(); addrDest.Address = Rule.RemoteAddresses; addrSrc.Address = Rule.LocalAddresses; WpfFunc.LoadWnd(this, "Rule"); }