Skip to main content

dns

The DNS Hook

This hook will help to automate additional task with your dns sever. 

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

Function name : dns

Base Directory :  /var/eenos/hooks/dns

Pre-Hooks  Location 

Please place all your DNS 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, UPDATE and DELETE 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 an dns zone file is update in the server

DELETE

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

Hook Inputs

This hook will be provided with the following inputs:

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

 The data will be given as  a base64 encoded Json data  string. This data contain 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  empty json data sting as there is no need to provide dns record details during 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 action hook scritps.

#!/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 use secure scripts to perform the actions.