Пример #1
0
        public DnsEntry GetDnsEntry(string HostName, IPAddress Address)
        {
            if (HostName == null && (Address == null || Address.Equals(IPAddress.Any) || Address.Equals(IPAddress.IPv6Any)))
            {
                return(null);
            }

            bool Unresolved = HostName == null;

            if (Unresolved)
            {
                HostName = Address.ToString();
            }

            if (HostName.Length == 0)
            {
                return(null);
            }

            DnsEntry Entry;

            if (!DnsLog.TryGetValue(HostName, out Entry))
            {
                Entry            = new DnsEntry(ID);
                Entry.Unresolved = Unresolved;
                Entry.HostName   = HostName;
                Entry.LastSeen   = DateTime.Now;
                Entry.SeenCounter++;
                DnsLog.Add(HostName, Entry);
            }
            return(Entry);
        }
Пример #2
0
        private void OnHostChanged(object sender, WithHost.ChangeEventArgs e)
        {
            var socket = sender as NetworkSocket;

            // if we get a better host name re asign and if needed remove old entry
            if (e != null)
            {
                string   OldName = e.oldName ?? socket.RemoteAddress?.ToString();
                DnsEntry OldEntry;
                if (OldName != null && DnsLog.TryGetValue(OldName, out OldEntry))
                {
                    OldEntry.ConCounter--;
                    if (OldEntry.ConCounter <= 0)
                    {
                        DnsLog.Remove(socket.RemoteAddress.ToString());
                    }
                }
            }

            DnsEntry Entry = GetDnsEntry(socket.RemoteHostName, socket.RemoteAddress);

            if (Entry != null)
            {
                Entry.ConCounter++;
            }
        }
            public async Task AddRecordAsync(string zoneId, DnsEntry entry)
            {
                var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"dns/managed/{zoneId}/records")
                {
                    Content = new StringContent(JsonConvert.SerializeObject(entry), Encoding.UTF8, "application/json")
                });

                response.EnsureSuccessStatusCode();
            }
Пример #4
0
 public bool Load(XmlNode entryNode)
 {
     foreach (XmlNode node in entryNode.ChildNodes)
     {
         if (node.Name == "ID")
         {
             ProgramID id = new ProgramID();
             if (id.Load(node))
             {
                 ID = id;
             }
         }
         else if (node.Name == "Description")
         {
             Description = node.InnerText;
         }
         else if (node.Name == "FwRules")
         {
             foreach (XmlNode childNode in node.ChildNodes)
             {
                 FirewallRuleEx rule = new FirewallRuleEx();
                 rule.ProgID = ID;
                 if (rule.Load(childNode) && !Rules.ContainsKey(rule.guid))
                 {
                     Rules.Add(rule.guid, rule);
                 }
                 else
                 {
                     App.LogError("Failed to load Firewall RuleEx {0} in {1}", rule.Name != null ? rule.Name : "[un named]", this.Description);
                 }
             }
         }
         else if (node.Name == "DnsLog")
         {
             foreach (XmlNode childNode in node.ChildNodes)
             {
                 DnsEntry Entry = new DnsEntry(ID);
                 if (Entry.Load(childNode) && !DnsLog.ContainsKey(Entry.HostName))
                 {
                     DnsLog.Add(Entry.HostName, Entry);
                 }
                 else
                 {
                     App.LogError("Failed to load DnsLog Entry in {0}", this.Description);
                 }
             }
         }
         else
         {
             AppLog.Debug("Unknown Program Value, '{0}':{1}", node.Name, node.InnerText);
         }
     }
     return(ID != null);
 }
Пример #5
0
            public async Task AddRecordAsync(string zoneName, DnsEntry entry)
            {
                await EnsureLoggedInAsync();

                var request = new DnsEntryRequest
                {
                    DnsEntry = entry
                };

                var response = await _httpClient.PostAsync($"domains/{zoneName}/dns", request);

                response.EnsureSuccessStatusCode();
            }
Пример #6
0
        public bool Update()
        {
            UInt64 uploadRate   = 0;
            UInt64 downloadRate = 0;

            UInt64 totalUpload   = OldUpload;
            UInt64 totalDownload = OldDownload;

            foreach (DnsEntry Entry in DnsLog.Values)
            {
                Entry.ConCounter    = Entry.OldConCounter;
                Entry.TotalUpload   = Entry.OldUpload;
                Entry.TotalDownload = Entry.OldDownload;
            }

            foreach (NetworkSocket Socket in Sockets.Values)
            {
                uploadRate   += Socket.Stats.UploadRate.ByteRate;
                downloadRate += Socket.Stats.DownloadRate.ByteRate;

                totalUpload   += Socket.Stats.SentBytes;
                totalDownload += Socket.Stats.ReceivedBytes;

                DnsEntry Entry = GetDnsEntry(Socket.RemoteHostName, Socket.RemoteAddress);
                if (Entry != null)
                {
                    Entry.ConCounter++;
                    Entry.TotalUpload   += Socket.Stats.SentBytes;
                    Entry.TotalDownload += Socket.Stats.ReceivedBytes;
                }
            }

            if (UploadRate != uploadRate || DownloadRate != downloadRate ||
                TotalUpload != totalUpload || TotalDownload != totalDownload ||
                SocketCount != Sockets.Count || ActivityChanged)
            {
                SocketCount = Sockets.Count;

                UploadRate   = uploadRate;
                DownloadRate = downloadRate;

                TotalUpload   = totalUpload;
                TotalDownload = totalDownload;

                ActivityChanged = false;

                return(true);
            }
            return(false);
        }
Пример #7
0
        public async Task <ActionResult> SetOrUpdate([FromBody] DnsEntry entry)
        {
            var result = await _manager.SetOrUpdate(entry);

            if (result.Success)
            {
                _logger.LogInformation($"DnsEntry added for {entry.Id}");
            }
            else
            {
                _logger.LogError(result.Error);
            }

            return(result.Success ? Ok() : BadRequest(result.Error) as ActionResult);
        }
Пример #8
0
            public async Task AddRecordAsync(string zoneName, DnsEntry entry)
            {
                await EnsureLoggedInAsync();

                var request = new DnsEntryRequest
                {
                    DnsEntry = entry
                };

                var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"domains/{zoneName}/dns")
                {
                    Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")
                });

                response.EnsureSuccessStatusCode();
            }
Пример #9
0
        public void RemoveSocket(NetworkSocket socket)
        {
            OldUpload   += socket.Stats.SentBytes;
            OldDownload += socket.Stats.ReceivedBytes;

            Sockets.Remove(socket.guid);

            DnsEntry Entry = GetDnsEntry(socket.RemoteHostName, socket.RemoteAddress);

            if (Entry != null)
            {
                Entry.OldUpload   += socket.Stats.SentBytes;
                Entry.OldDownload += socket.Stats.ReceivedBytes;
                Entry.OldConCounter++;
            }
        }
Пример #10
0
        public void LogDomain(string HostName)
        {
            DnsEntry Entry = null;

            if (!DnsLog.TryGetValue(HostName, out Entry))
            {
                Entry          = new DnsEntry(ID);
                Entry.HostName = HostName;
                DnsLog.Add(HostName, Entry);
            }
            else
            {
                Entry.LastSeen = DateTime.Now;
            }
            //Entry.LastSeenIP = IP;
            Entry.SeenCounter++;
        }
Пример #11
0
        public void LogDomain(string HostName, DateTime TimeStamp)
        {
            DnsEntry Entry = null;

            if (!DnsLog.TryGetValue(HostName, out Entry))
            {
                Entry          = new DnsEntry(ID);
                Entry.HostName = HostName;
                DnsLog.Add(HostName, Entry);
            }
            else if (Entry.LastSeen == TimeStamp)
            {
                return; // dont count duplicates
            }
            Entry.LastSeen = TimeStamp;
            //Entry.LastSeenIP = IP;
            Entry.SeenCounter++;
        }
Пример #12
0
        public IActionResult Process(Transaction transaction)
        {
            try
            {
                var dns = DnsEntry.Parse(transaction.Data);
                if (!dns.VerifyForUId())
                {
                    _logger.LogInformation("Invalid client's signature for {0}", transaction.Index);
                    return(new BadRequestObjectResult("Client's signature is invalid"));
                }

                //TODO: Add ork signature verification
                if (false)
                {
                    _logger.LogInformation("Invalid ORK's signature for {0}", transaction.Index);
                    return(new BadRequestObjectResult("One of the ORK signatures is invalid"));
                }

                //TODO: Verify if this works
                var sourceTran = _blockchain.Read(transaction.Location, transaction.Index);
                if (sourceTran != null)
                {
                    _logger.LogInformation("Dns entry is already created for {0}", transaction.Index);
                    return(new BadRequestObjectResult("The account already exists"));
                }

                lock (_lockObj)
                {
                    var result = _blockchain.Write(transaction);
                    _logger.LogInformation("Dns entry created for {0}", transaction.Index);
                    return(result.success ? new OkResult() as IActionResult
                        : new BadRequestObjectResult(result.error));
                }
            }
            catch (System.Exception e)
            {
                _logger.LogError(0, e, "Error processing dns contract: {0}", transaction.Data);
                return(new ObjectResult(e.Message)
                {
                    StatusCode = 500
                });
            }
        }
        public static string AsMailEntry(this DnsEntry entry, IPAddress currentIp, AutonsType type)
        {
            var value = entry.Value == Consts.CURRENT_IP ? currentIp.ToString() : entry.Value;

            switch (type)
            {
            case AutonsType.A:
                return($"{Environment.NewLine}9b. autons-a...................: {entry.Prefix} {value}");

            case AutonsType.Cname:
                return($"{Environment.NewLine}9d. autons-cname...............: {entry.Prefix} {value}");

            case AutonsType.Txt:
                return($"{Environment.NewLine}9f. autons-txt.................: {entry.Prefix} {value}");

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Пример #14
0
        public unsafe Task <DnsEntry[]> TryResolve()
        {
            var records = new List <DnsEntry>();

            byte[] dataBuffer = new byte[1024];
            int    dataLen    = LinuxLib.res_query(Query, C_IN, (int)Type, dataBuffer, dataBuffer.Length);

            if (dataLen > 0)
            {
                GCHandle handle = GCHandle.Alloc(dataBuffer, GCHandleType.Pinned);

                try
                {
                    fixed(byte *pBuffer = dataBuffer)
                    {
                        var reader = new LDnsReader
                        {
                            Buffer  = pBuffer,
                            Current = pBuffer,
                            End     = pBuffer + dataLen
                        };

                        // Response Header
                        int queryId = reader.UInt16();  // Query Identifier (Read & Ignore)

                        byte[] hBits = reader.Bytes(2); // Header Bits & Flags (Read & Ignore)

                        int qdCount = reader.UInt16();  // Question Count (Use Below)
                        int anCount = reader.UInt16();  // Answer Count (Use Below)

                        int nsCount = reader.UInt16();  // NameServer Count (Read & Ignore)
                        int arCount = reader.UInt16();  // Resource Count (Read & Ignore)

                        // Question Section (read and ignore)
                        for (int q = 0; q < qdCount && reader.OK(); q++)
                        {
                            string qName  = reader.Name();
                            ushort qType  = reader.UInt16();
                            ushort qClass = reader.UInt16();
                        }

                        // Answers (the good stuff)
                        for (int a = 0; a < anCount && reader.OK(); a++)
                        {
                            var      ansHead  = new LDnsHeader(reader);
                            DnsEntry dnsEntry = DnsEntry.Create(ansHead, reader);

                            records.Add(dnsEntry);
                        }
                    }
                }
                finally
                {
                    handle.Free();
                }
            }

            _allRecords  = records.ToArray();
            _typeRecords = records.Where(r => r.Type == Type).ToArray();

            if (Type == DnsRecordType.SRV || Type == DnsRecordType.MX)    // sort
            {
                _typeRecords = _typeRecords.OrderBy(r => ((IOrderedDnsEntry)r).SortOrder).ToArray();
            }

            return(Task.FromResult(_typeRecords));
        }
Пример #15
0
        private void QueryComplete(IntPtr contextPtr, IntPtr resultPtr)
        {
            lock (_syncLock)
            {
                if (_completed)
                {
                    return;
                }
                _completed = true;

                // stop timer
                if (_timer != null)
                {
                    _timer.Dispose();
                    _timer = null;
                }
            }

            try
            {
                // check if timed out
                if (_timedOut)
                {
                    _taskCompletion.SetException(new DnsTimeoutException(Query));
                    return;
                }

                // process results
                var records = new List <DnsEntry>();
                if (resultPtr != IntPtr.Zero)
                {
                    var queryResult = Marshal.PtrToStructure <Win32.DNS_QUERY_RESULT>(resultPtr);
                    if (queryResult.QueryStatus == 0)   // SUCCESS
                    {
                        IntPtr ptr = queryResult.QueryRecords;
                        while (ptr != IntPtr.Zero)
                        {
                            var record = Marshal.PtrToStructure <Win32.DNS_RECORD>(ptr);
                            records.Add(DnsEntry.Create(record, ptr));

                            ptr = record.Next;  // Next Record
                        }

                        if (queryResult.QueryRecords != IntPtr.Zero)
                        {
                            Win32.DnsRecordListFree(queryResult.QueryRecords, (int)Win32.DNS_FREE_TYPE.DnsFreeRecordList);
                        }
                    }
                }

                _allRecords  = records.ToArray();
                _typeRecords = records.Where(r => r.Type == Type).ToArray();

                if (Type == DnsRecordType.SRV || Type == DnsRecordType.MX)    // sort
                {
                    _typeRecords = _typeRecords.OrderBy(r => ((IOrderedDnsEntry)r).SortOrder).ToArray();
                }

                _taskCompletion.SetResult(_typeRecords);
            }
            catch (Exception ex)
            {
                _taskCompletion.SetException(ex);
            }
            finally
            {
                if (resultPtr != _resultPtr)
                {
                    Win32.FreeHGlobal(ref resultPtr);
                }

                Win32.FreeHGlobal(ref _resultPtr);
                Win32.FreeHGlobal(ref _requestPtr);

                _runningWait.Set();
                GC.SuppressFinalize(this);
            }
        }
Пример #16
0
        /// <summary>
        /// Implements the <b>set</b> command.
        /// </summary>
        /// <param name="commandLine">The command line.</param>
        private void SetEntry(CommandLine commandLine)
        {
            DnsEntry dnsEntry;

            var wait = commandLine.HasOption("--wait");

            if (commandLine.Arguments.Length >= 3)
            {
                // Handle: neon dns set [--check] HOST ADDRESSES

                var host  = commandLine.Arguments.ElementAtOrDefault(1);
                var check = commandLine.HasOption("--check");

                dnsEntry = new DnsEntry()
                {
                    Hostname = host
                };

                foreach (var address in commandLine.Arguments.Skip(2))
                {
                    dnsEntry.Endpoints.Add(
                        new DnsEndpoint()
                    {
                        Target = address,
                        Check  = check
                    });
                }
            }
            else
            {
                // Handle: neon dns set PATH
                //     or: neon dns set -

                string path = commandLine.Arguments.ElementAtOrDefault(1);
                string data;

                if (path == null)
                {
                    Console.Error.WriteLine("*** ERROR: [PATH] or [-] argument expected.");
                    Program.Exit(1);
                }

                if (path == "-")
                {
                    data = NeonHelper.ReadStandardInputText();
                }
                else
                {
                    data = File.ReadAllText(path);
                }

                dnsEntry = NeonHelper.JsonOrYamlDeserialize <DnsEntry>(data, strict: true);
            }

            // Check for errors.

            var errors = dnsEntry.Validate(hive.Definition, hive.Definition.GetHostGroups(excludeAllGroup: true));

            if (errors.Count > 0)
            {
                foreach (var error in errors)
                {
                    Console.Error.WriteLine($"*** ERROR: {error}");
                }

                Program.Exit(1);
            }

            // Persist the entry.

            hive.Dns.Set(dnsEntry, waitUntilPropagated: wait);

            Console.WriteLine();
            Console.WriteLine($"Saved [{dnsEntry.Hostname}] DNS host entry.");
        }
            public async Task DeleteRecordAsync(string zoneId, DnsEntry entry)
            {
                var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Delete, $"dns/managed/{zoneId}/records/{entry.Id}"));

                response.EnsureSuccessStatusCode();
            }
Пример #18
0
        /// <inheritdoc/>
        public void Run(ModuleContext context)
        {
            var hive   = HiveHelper.Hive;
            var consul = HiveHelper.Consul;

            if (!context.ValidateArguments(context.Arguments, validModuleArgs))
            {
                context.Failed = true;
                return;
            }

            // Obtain common arguments.

            context.WriteLine(AnsibleVerbosity.Trace, $"Parsing [hostname]");

            if (!context.Arguments.TryGetValue <string>("hostname", out var hostname))
            {
                throw new ArgumentException($"[hostname] module argument is required.");
            }

            if (!HiveDefinition.DnsHostRegex.IsMatch(hostname))
            {
                throw new ArgumentException($"[hostname={hostname}] is not a valid DNS hostname.");
            }

            context.WriteLine(AnsibleVerbosity.Trace, $"Parsing [system]");

            var system = context.ParseBool("system") ?? false;

            context.WriteLine(AnsibleVerbosity.Trace, $"Parsing [state]");

            if (!context.Arguments.TryGetValue <string>("state", out var state))
            {
                state = "present";
            }

            state = state.ToLowerInvariant();

            context.WriteLine(AnsibleVerbosity.Trace, $"Parsing [endpoints]");

            if (!context.Arguments.TryGetValue <JToken>("endpoints", out var endpointsToken) && state == "present")
            {
                throw new ArgumentException($"[endpoints] module argument is required when [state={state}].");
            }

            context.WriteLine(AnsibleVerbosity.Trace, $"Parsing [wait]");

            var wait = context.ParseBool("wait");

            wait = wait ?? false;

            if (context.HasErrors)
            {
                return;
            }

            // We have the required arguments, so perform the operation.

            switch (state)
            {
            case "absent":

                context.WriteLine(AnsibleVerbosity.Trace, $"Check if DNS entry [{hostname}] exists.");

                if (hive.Dns.Get(hostname) != null)
                {
                    context.WriteLine(AnsibleVerbosity.Trace, $"DNS entry [{hostname}] does exist.");
                    context.WriteLine(AnsibleVerbosity.Info, $"Deleting DNS entry [{hostname}].");

                    if (context.CheckMode)
                    {
                        context.WriteLine(AnsibleVerbosity.Info, $"DNS entry [{hostname}] will be deleted when CHECK-MODE is disabled.");
                    }
                    else
                    {
                        hive.Dns.Remove(hostname, waitUntilPropagated: wait.Value);
                        context.WriteLine(AnsibleVerbosity.Trace, $"DNS entry [{hostname}] deleted.");
                    }

                    context.Changed = !context.CheckMode;
                }
                else
                {
                    context.WriteLine(AnsibleVerbosity.Trace, $"DNS entry [{hostname}] does not exist.");
                }
                break;

            case "present":

                var endpointsArray = endpointsToken as JArray;

                if (endpointsArray == null)
                {
                    throw new ArgumentException($"[endpoints] module argument must be an array.");
                }

                var endpoints = new List <DnsEndpoint>();

                foreach (var item in endpointsArray)
                {
                    var endpointJObject = item as JObject;

                    if (endpointJObject == null)
                    {
                        context.WriteErrorLine("One or more [endpoints] are invalid.");
                        context.Failed = true;
                        return;
                    }

                    if (!context.ValidateArguments(endpointJObject, endpointArgs, "endpoints"))
                    {
                        context.Failed = true;
                        return;
                    }

                    endpoints.Add(item.ToObject <DnsEndpoint>());
                }

                context.WriteLine(AnsibleVerbosity.Trace, $"[{endpoints.Count}] endpoints parsed.");

                // Construct the new entry.

                var newEntry = new DnsEntry()
                {
                    Hostname  = hostname,
                    IsSystem  = system,
                    Endpoints = endpoints
                };

                // Validate the new DNS entry.

                context.WriteLine(AnsibleVerbosity.Trace, "Validating DNS entry.");

                var errors = newEntry.Validate(hive.Definition, hive.Definition.GetHostGroups(excludeAllGroup: true));

                if (errors.Count > 0)
                {
                    context.WriteLine(AnsibleVerbosity.Trace, $"[{errors.Count}] DNS entry validation errors.");

                    foreach (var error in errors)
                    {
                        context.WriteLine(AnsibleVerbosity.Important, error);
                        context.WriteErrorLine(error);
                    }

                    context.Failed = true;
                    return;
                }

                context.WriteLine(AnsibleVerbosity.Trace, "DNS entry is valid.");

                // Try reading an existing entry with this name and then determine
                // whether the two versions of the entry are actually different.

                context.WriteLine(AnsibleVerbosity.Trace, $"Look up existing DNS entry for [{hostname}].");

                var existingEntry = hive.Dns.Get(hostname);
                var changed       = false;

                if (existingEntry != null)
                {
                    context.WriteLine(AnsibleVerbosity.Trace, $"DNS entry exists: checking for differences.");

                    changed = !NeonHelper.JsonEquals(newEntry, existingEntry);

                    if (changed)
                    {
                        context.WriteLine(AnsibleVerbosity.Trace, $"DNS entries are different.");
                    }
                    else
                    {
                        context.WriteLine(AnsibleVerbosity.Info, $"DNS entries are the same.  No need to update.");
                    }
                }
                else
                {
                    changed = true;
                    context.WriteLine(AnsibleVerbosity.Trace, $"DNS entry for [hostname={hostname}] does not exist.");
                }

                if (changed)
                {
                    if (context.CheckMode)
                    {
                        context.WriteLine(AnsibleVerbosity.Info, $"DNS entry [{hostname}] will be updated when CHECK-MODE is disabled.");
                    }
                    else
                    {
                        context.WriteLine(AnsibleVerbosity.Trace, $"Updating DNS entry.");
                        hive.Dns.Set(newEntry, waitUntilPropagated: wait.Value);
                        context.WriteLine(AnsibleVerbosity.Info, $"DNS entry updated.");
                    }

                    context.Changed = !context.CheckMode;
                }

                break;

            default:

                throw new ArgumentException($"[state={state}] is not one of the valid choices: [present] or [absent].");
            }
        }
Пример #19
0
            public async Task DeleteRecordAsync(string zoneId, DnsEntry entry)
            {
                var response = await _httpClient.DeleteAsync($"v1/domains/{zoneId}/records/{entry.Type}/{entry.Name}");

                response.EnsureSuccessStatusCode();
            }
Пример #20
0
        public bool Load(XmlNode entryNode)
        {
            foreach (XmlNode node in entryNode.ChildNodes)
            {
                if (node.Name == "ID")
                {
                    ProgramID id = new ProgramID();
                    if (id.Load(node))
                    {
                        // COMPAT: remove service tag
                        ID = FirewallRuleEx.AdjustProgID(id);
                    }
                }
                else if (node.Name == "Description")
                {
                    Description = node.InnerText;
                }
                else if (node.Name == "ReceivedBytes")
                {
                    UInt64.TryParse(node.InnerText, out OldDownload);
                }
                else if (node.Name == "SentBytes")
                {
                    UInt64.TryParse(node.InnerText, out OldUpload);
                }
                else if (node.Name == "FwRules")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        FirewallRuleEx rule = new FirewallRuleEx();
                        rule.ProgID = ID; // todo: remove later, load loads this amyways
                        if (rule.Load(childNode) && !Rules.ContainsKey(rule.guid))
                        {
                            // COMPAT: update entry, old version did not save these data separatly
                            //if (ID.Type != ProgramID.Types.Global && (rule.BinaryPath == null && rule.ServiceTag == null && rule.AppSID == null))
                            //    rule.SetProgID(ID);

                            Rules.Add(rule.guid, rule);
                        }
                        else
                        {
                            Priv10Logger.LogError("Failed to load Firewall RuleEx {0} in {1}", rule.Name != null ? rule.Name : "[un named]", this.Description);
                        }
                    }
                }
                else if (node.Name == "DnsLog")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        DnsEntry Entry = new DnsEntry(ID);
                        if (Entry.Load(childNode) && !DnsLog.ContainsKey(Entry.HostName))
                        {
                            DnsLog.Add(Entry.HostName, Entry);
                        }
                        else
                        {
                            Priv10Logger.LogError("Failed to load DnsLog Entry in {0}", this.Description);
                        }
                    }
                }
                else
                {
                    AppLog.Debug("Unknown Program Value, '{0}':{1}", node.Name, node.InnerText);
                }
            }

            if (Description == null || Description.Substring(0, 2) == "@{")
            {
                Description = GetDescription();
            }

            return(ID != null);
        }
Пример #21
0
 public async Task DeleteDnsEntry(string domainName, DnsEntry entry) =>
 _ = await Delete($"domains/{domainName}/dns", new DnsEntryWrapper()
 {
     DnsEntry = entry
 });
Пример #22
0
            public async Task DeleteRecordAsync(string zoneId, DnsEntry entry)
            {
                var response = await _httpClient.DeleteAsync($"dns/managed/{zoneId}/records/{entry.Id}");

                response.EnsureSuccessStatusCode();
            }
Пример #23
0
        public bool Update()
        {
            UInt64 uploadRate   = 0;
            UInt64 downloadRate = 0;

            UInt64 totalUpload   = OldUpload;
            UInt64 totalDownload = OldDownload;

            foreach (DnsEntry Entry in DnsLog.Values)
            {
                Entry.ConCounter    = Entry.OldConCounter;
                Entry.TotalUpload   = Entry.OldUpload;
                Entry.TotalDownload = Entry.OldDownload;
            }

            SocketsWeb = 0;
            SocketsTcp = 0;
            SocketsUdp = 0;
            SocketsSrv = 0;
            foreach (NetworkSocket Socket in Sockets.Values)
            {
                uploadRate   += Socket.Stats.UploadRate.ByteRate;
                downloadRate += Socket.Stats.DownloadRate.ByteRate;

                totalUpload   += Socket.Stats.SentBytes;
                totalDownload += Socket.Stats.ReceivedBytes;

                DnsEntry Entry = GetDnsEntry(Socket.RemoteHostName, Socket.RemoteAddress);
                if (Entry != null)
                {
                    Entry.ConCounter++;
                    Entry.TotalUpload   += Socket.Stats.SentBytes;
                    Entry.TotalDownload += Socket.Stats.ReceivedBytes;
                }

                if ((Socket.ProtocolType & 0xFF) == (UInt32)IPHelper.AF_PROT.UDP)
                {
                    SocketsUdp++;
                }
                else if ((Socket.ProtocolType & 0xFF) == (UInt32)IPHelper.AF_PROT.TCP)
                {
                    SocketsTcp++;
                    if (Socket.RemotePort == 80 || Socket.RemotePort == 443)
                    {
                        SocketsWeb++;
                    }
                    if (Socket.State == (int)IPHelper.MIB_TCP_STATE.LISTENING)
                    {
                        SocketsSrv++;
                    }
                }
            }

            RuleCount     = 0;
            EnabledRules  = 0;
            DisabledRules = 0;
            ChgedRules    = 0;
            foreach (FirewallRuleEx rule in Rules.Values)
            {
                RuleCount++;
                if (rule.Enabled)
                {
                    EnabledRules++;
                }
                else
                {
                    DisabledRules++;
                }
                if (rule.State != FirewallRuleEx.States.Approved)
                {
                    ChgedRules++;
                }
            }

            if (UploadRate != uploadRate || DownloadRate != downloadRate ||
                TotalUpload != totalUpload || TotalDownload != totalDownload ||
                SocketCount != Sockets.Count //|| ActivityChanged
                )
            {
                SocketCount = Sockets.Count;

                UploadRate   = uploadRate;
                DownloadRate = downloadRate;

                TotalUpload   = totalUpload;
                TotalDownload = totalDownload;

                //ActivityChanged = false;

                return(true);
            }
            return(false);
        }
Пример #24
0
            public async Task AddRecordAsync(string zoneId, DnsEntry entry)
            {
                var response = await _httpClient.PostAsync($"dns/managed/{zoneId}/records", entry);

                response.EnsureSuccessStatusCode();
            }