Hooks

The Eenos hooks integrate your custom action scripts and codes into Eenos operations.

About Eenos Hooks

Understand how Hooks works in the Eenos control panel. Create your own Hooks

About Eenos Hooks

Introduction

Getting started with hooks in Eenos

The  Eenos control panel supports hooks, which will help you to integrate any custom scripts or code blocks in the middle of Eenos operations. 

Eenos supports two types of hooks  Pre Hooks and Post Hooks.

Pre Hooks

The pre-hooks will be executed before the operation of a specific function. You should place the hook script in the following folder.

Location :   /var/eenos/hooks/FUNCTION_NAME/pre/   ,   where FUNCTION_NAME is the action function

Example :

 Example for a DNS creation pre-hook: /var/eenos/hooks/dns/pre/01-dns_sync.py

Post Hooks

The post hooks will be executed after the operation of a specific function. You should place the hook script in the following folder.

Location : /var/eenos/hooks/FUNCTION_NAME/post/  , where FUNCTION_NAME is the action function

Example :

 Example for a dns creation post hook:  /var/eenos/hooks/dns/post/01-dns_sync.py

All hook scripts must need execute permission to run the program.

Hook Inputs

The Eenos system calls will send the following  command line inputs to the hook scripts.

An example hook action will be look like as follows :

/var/eenos/hooks/dns/pre/01-test.py \
  data=eyJ0ZXN0IjoidGVzdCIsImhpIjoiaGVsbG8ifQ== \
  action=CREATE \
  panel=wap \
  domain=fun.com \
  user=foo

You may decode the data and process it. 

Hook Programming Languages

The  Eenos hook supports any programming language or binary. The only requirement is that you need to provide execute permission for the hook scripts. We recommend using Python scripts for creating hooks.

Hooks Script Ordering

The  Eenos will sort the hook scripts based on the name. So if you like to execute multiple hooks, please make sure the hook script names are in a sorted order.  ( eg : 00-pre.py , 01-pre.py, 02-pre.py )

Available Hooks

All the action hooks are available in Eenos. Keep watching this page, more hooks will come in the future as we are getting the feature request for action hooks.

Available Hooks

dns

The DNS Hook

This hook will help to automate additional tasks with your DNS server. 

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 a DNS zone file is updated in the server

DELETE

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

Hook Inputs

This hook will be provided with the following inputs:

data

 The data will be given as a base64 encoded Json data string. This data contains 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 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-action hook 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 using secure scripts to perform the actions.

Available Hooks

createacct

The account creation hooks

These hooks will be executed when a user account creation happens.

Function name: createacct

Base Directory:  /var/eenos/hooks/createacct

Pre-Hooks  Location 

Please place all your create  account pre-hook scrips in   /var/eenos/hooks/createacct/pre/

Post Hooks Location 

Please put your post create account  hooks scripts in   /var/eenos/hooks/createacct/post/

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

Supported Actions

 This hook will support CREATE  action only.

Hook Inputs

This hook will be provided with the following inputs:

data

The data will be a base64 encoded json string that contains the userdata file contents.

Available Hooks

removeacct

The account termination hooks

These hooks will be executed when a user account is being terminated.

Function name: removeacct

Base Directory:  /var/eenos/hooks/removeacct

Pre-Hooks  Location 

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

Post Hooks Location 

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

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

Supported Actions

 This hook will support DELETE  action only.

Hook Inputs

This hook will be provided with the following inputs:

data

The data will be a base64 encoded json string that contains the userdata file contents.

Available Hooks

suspendacct

The account suspend hooks

These hooks will be executed when a user account is being suspended.

Function name: suspendacct

Base Directory :  /var/eenos/hooks/suspendacct

Pre-Hooks  Location 

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

Post Hooks Location 

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

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

Supported Actions

 This hook will support UPDATE  action only.

Hook Inputs

This hook will be provided with the following inputs:

data

The data will be a base64 encoded json string that contains the userdata file contents.

Available Hooks

unsuspendacct

The account unsuspend hooks

These hooks will be executed when a user account is being unsuspended.

Function name: unsuspendacct

Base Directory:  /var/eenos/hooks/unsuspendacct

Pre-Hooks  Location 

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

Post Hooks Location 

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

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

Supported Actions

 This hook will support UPDATE  action only.

Hook Inputs

This hook will be provided with the following inputs:

data

The data will be a base64 encoded json string that contains the the userdata file contents.