Midgard Wide Logo In White

DNS Made Easy. PHP. And Laravel

Over the years we’ve been generating our own internal portal (https://www.mymidgard.co.uk) Its seen multiple upgrades, and changes.

One of the things we use it for, is a dashboard to pull in all our API’s into one place, allowing us to change 3rd party suppliers without major changes to our internal workflow.

DNS MADE EASY

One of our work flows is the creation, edits, and deletion of DNS records for our clients. We have domains hosted over different providers and registrars. (Domain Box, and DNS Made Easy Being the main two at the moment).

Both use completely different ways of interacting with their own API’s. Trying to find Packages, that allowed us to create nice restful hooks, we found one that was really good, but documentation was lacking (Had to deep dive into the code to see how to get stuff). We finally decided to just roll a stripped down version, using Laravels HTTP client and the actual API docs from DNS Made easy.

We cant show you all the code, and interfaces we use, and although we are tempted to publish it as a separate package, we would have to decouple quite a bit of our own internal logic.

So instead, we are going to post below a few snippits of the code, and host it on GitHub.
If there is a demand for this, we will release it as a full blown package.

GIT HUB LINK https://github.com/midgarditltd/DnsMadeEasyLaravel


        public function __construct()
        {
            $this->key    = config('dnsmadeeasy.apikey');
            $this->secret = config('dnsmadeeasy.secret');
            $this->urlApi = 'https://api.dnsmadeeasy.com/V2.0/';
        }


        /**
         * Adds auth headers to requests. These are generated based on the Api Key and the Secret Key.
         *
         * @return array
         * @throws \Exception
         */
        public function WithAuthHeaders(): array
        {
            $now       = new \DateTime('now', new \DateTimeZone('UTC'));
            $timestamp = $now->format('r');
            $hmac      = hash_hmac('sha1', $timestamp, $this->secret);
            $response  = [
                'Content-Type'        => 'application/json',
                'x-dnsme-hmac'        => $hmac,
                'x-dnsme-apiKey'      => $this->key,
                'x-dnsme-requestDate' => $timestamp,
            ];

            return $response;
        }

 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        /** 
        * This gets all the Domains linked to your account with DNS MAde Easy
         * @return array|mixed
         */
        public function domainsAll()
        {
            return Http::withHeaders(self::WithAuthHeaders())->get($this->urlApi . 'dns/managed/')->json();
        }



     /**
         * @param int $domainRemoteID
         * All the Domains DNS for a specific DNS Domain ID (See domainsAll to find a list of all the domains you may have.
         
         *
         */
        public function DnsFromRemoteDomainId(int $domainRemoteID): array
        {
            return Http::withHeaders(self::WithAuthHeaders())
                       ->get("{$this->urlApi}dns/managed/{$domainRemoteID}/records")
                       ->json();
        }
      
            /// CREATE REMOTE DNS DETAILS

        /**
         * @param int $domainRemoteID
         *
         *
         */
        public function CreateRemoteDnsFromRemoteDomainId(int $domainRemoteID, array $dnsDetails): array
        {
            $formattedDnsDetails = [
                'name'        => $dnsDetails['host'] ?? 'From MyMidgard',
                'type'        => strtoupper($dnsDetails['type']) ?? 'TXT',
                'source'      => $dnsDetails['source'] ?? 1,
                'value'       => $dnsDetails['record'],
                'gtdLocation' => $dnsDetails['gtdLocation'] ?? 'DEFAULT',
                "ttl"         => $dnsDetails['ttl'] ?? 86400,
            ];

            return Http::withHeaders(self::WithAuthHeaders())
                       ->post("{$this->urlApi}dns/managed/{$domainRemoteID}/records", $formattedDnsDetails)
                       ->json();
        }
Facebook
Twitter
LinkedIn

Table of Contents

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact

Midgard Short Logo In White

MyMidgard

Our Online Portal helps you keep ontop of your IT systems. Designed from the ground up by Midgard IT themselves.