Skip to main content

dns

The DNS Hook

This hook will help to automate additional tasktasks with your dnsDNS sever.server. 

You can  integrate your Third Third-party DNS cluster into Eenos with the help of this hook  function.

Function name :name: dnsDNS

Base Directory :Directory:  /var/eenos/hooks/dns

Pre-Hooks  Location 

Please place all your DNS pre pre-hook  scrips in   /var/eenos/hooks/dns/pre/

Post Hooks Location 

Please put your post dns hooks scripts in   /var/eenos/hooks/dns/post/

All pre-hook and post-hook scripts need execute permission to perform the requested operations.

Supported Actions

 The dns hooks will support CREATE, UPDATEUPDATE, and DELETE actions .actions. These actions will be executed based on the hook operation.

CREATE

 This action will be given if a dns zone is created in the server.

UPDATE

This action will be given if ana dnsDNS zone file is updateupdated in the server

DELETE

This action will be given if the dns zone is  deleted infrom the server.

Hook Inputs

This hook will be provided with the following inputs:

  • data  :  A base64 encoded JSON data of the related actions ,actions,  This is compulsory.
  • action :  The action code  CREATE ,CREATE, UPDATE or DELETE  ,DELETE, This is a compulsory
  • panel : The control panel that performperforms the hooks ,hooks, wap. rapp or uapp ,uapp, This is a compulsory
  • domain : The domain name performing the hooks. It is optional
  • user :  The  Eenos user name associated with .with. It is optional
data

 The data will be given as  a base64 encoded Json data  string. This data containcontains all the  details of the Zone data which you can find in /var/eenos/userdata/USER/dns/domain.name  file

The DELETE Action will be provided with and an empty json data sting as there is no need to provide dns record details during the delete action

 

Example Pre/Post Hooks Scripts in Python

You can use the following sample python script to create a DNS Cluster update post of pre pre-action hook scritps.scripts.

#!/usr/bin/python3
'''
License  GPL V3
Feel free to customize 
'''
import os,sys
import argparse
from datetime import datetime
from pprint import pprint
import base64 

def options(default=False):    
    parser = argparse.ArgumentParser(description='Sync Domain to Dns cluster',usage='%(prog)s [options] ')
    optional=parser._action_groups.pop()      
    main_cmd = parser.add_argument_group("Command(s)")       
    main_cmd.add_argument('data',metavar="data",type=str,help='base64 encoded json  data')
    main_cmd.add_argument('action',metavar="action",type=str,help='The action  CREATE, UPDATE, DELETE')
    main_cmd.add_argument('panel',metavar="panel",type=str,help='The Control panel wap,rapp,uapp')
    main_cmd.add_argument('domain',metavar="domain",help='Domain name')    
    optional.add_argument('user',metavar="user",help='User name')
    parser._action_groups.append(optional)
    args=None
    if default:        
        now = datetime.now()
        print('Copyright(c) 2020-'+str(now.year)+', eenos.com')
        parser.print_help()
        sys.exit(1)
    else:
        try:
            args = parser.parse_args()
            return vars(args)
        except:           
            sys.exit(0)
if __name__ == "__main__":
    if not sys.argv[1:]:
        options(default=True)        
        sys.exit(0)
    else:
        cmd=options()
        # pprint(cmd)
        if bool(cmd) and bool(cmd['data']):
            try:
                domain=cmd['domain'].split('=')[-1]
                action=cmd['action'].split('=')[-1]
                base64_string=cmd['data'].split('=')[-1]
                base64_bytes = base64_string.encode("ascii") 
                data_string_bytes = base64.b64decode(base64_bytes) 
                # Decoded json string
                json_data_string=data_string_bytes.decode("ascii") 
                # print(json_data_string)

                if action == 'CREATE':
                    print("Creating Remote DNS Cluster Zone entry for domain : %s" %domain)
                    '''
                    Add your remote api code here for creating dns zone entry in dns cluster.
                    '''

                if action == 'UPDATE':
                    print("updating Remote DNS Cluster Zone entry for domain : %s" %domain)
                    '''
                    Add your remote api code here for updating dns zone entry in dns cluster.
                    '''
                    
                if action == 'DELETE':
                    print("Deleting Remote DNS Cluster Zone entry for domain : %s" %domain)
                    '''
                    Add your remote api code here for updating dns zone entry in dns cluster.
                    '''

            except Exception as e:
                print(str(e))
                pass

We recommend to useusing secure scripts to perform the actions.