コード例 #1
0
ファイル: DnsHandler.cs プロジェクト: lulzzz/handlers.Dns.net
    public bool ValidateActionParameters(DnsActionDetail request)
    {
        bool areValid = true;

        if (string.IsNullOrWhiteSpace(request.Action) || request.Action.ToLower() != "add" && request.Action.ToLower() != "delete")
        {
            OnLogMessage("Execute", "Allowed action type is 'add' or 'delete' only.", LogLevel.Error);
            areValid = false;
        }
        else if (string.IsNullOrWhiteSpace(request.RecordType) || request.RecordType.ToLower() != "atype" && request.RecordType.ToLower() != "ptrtype")
        {
            OnLogMessage("Execute", "Allowed record types are 'AType' or 'PTRType' only.", LogLevel.Error);
            areValid = false;
        }
        else if (string.IsNullOrWhiteSpace(request.RequestOwner))
        {
            OnLogMessage("Execute", "Request owner must be specified.", LogLevel.Error);
            areValid = false;
        }
        else if (string.IsNullOrWhiteSpace(request.Note))
        {
            OnLogMessage("Execute", "Request note must be specified.", LogLevel.Error);
            areValid = false;
        }
        else if (string.IsNullOrWhiteSpace(request.Hostname) || string.IsNullOrWhiteSpace(request.IpAddress))
        {
            OnLogMessage("Execute", "Both hostname and ip address must be specified.", LogLevel.Error);
            areValid = false;
        }

        return(areValid);
    }
コード例 #2
0
ファイル: DnsHandler.cs プロジェクト: lulzzz/handlers.Dns.net
    public bool ExecuteDnsActions(DnsActionDetail request, DnsHandlerConfig config, bool isDryRun = false)
    {
        if (request == null || config == null)
        {
            return(false);
        }

        string domainSuffix = GetDomainSuffix(request.Hostname);

        if (string.IsNullOrWhiteSpace(domainSuffix))
        {
            throw new Exception($"Domain suffix {domainSuffix} is not valid.");
        }

        string dnsServer = GetDnsServer(config, domainSuffix);

        if (string.IsNullOrWhiteSpace(dnsServer))
        {
            throw new Exception($"Unable to find a matching DNS server for domain suffix {domainSuffix}.");
        }

        bool isSuccess = false;

        if (request.Action.ToLower() == "add" && request.RecordType.ToLower() == "atype")
        {
            OnLogMessage("Execute", "Adding type A DNS record...");
            DnsServices.CreateARecord(request.Hostname, request.IpAddress, "", dnsServer, isDryRun);
            OnLogMessage("Execute", "Operation is successful.");
            isSuccess = true;
        }

        if (request.Action.ToLower() == "delete" && request.RecordType.ToLower() == "atype")
        {
            OnLogMessage("Execute", "Deleting type A DNS record and its associated PTR record...");
            DnsServices.DeleteARecord(request.Hostname, request.IpAddress, dnsServer, isDryRun);
            OnLogMessage("Execute", "Operation is successful.");
            isSuccess = true;
        }

        if (request.Action.ToLower() == "add" && request.RecordType.ToLower() == "ptrtype")
        {
            OnLogMessage("Execute", "Adding type PTR DNS record...");
            DnsServices.CreatePtrRecord(request.Hostname, request.IpAddress, request.DnsZone, dnsServer, isDryRun);
            OnLogMessage("Execute", "Operation is successful.");
            isSuccess = true;
        }

        if (request.Action.ToLower() == "delete" && request.RecordType.ToLower() == "ptrtype")
        {
            OnLogMessage("Execute", "Deleting type PTR DNS record...");
            DnsServices.DeletePtrRecord(request.Hostname, request.IpAddress, dnsServer, isDryRun);
            OnLogMessage("Execute", "Operation is successful.");
            isSuccess = true;
        }

        return(isSuccess);
    }