Domain Management Hooks

domain_change_(pre|post).sh

This pre/post script is called before/after changing a domain name.

Environment variables

  • domain: current domain name
  • newdomain: new domain name
  • username: owner of domain
  • bandwidth(number in MB or unlimited) : bandwidth limit set for this domain
  • cgi(ON or OFF): is CGI (Common Gateway Interface) is enabled
  • defaultdomain(yes or no): whether the created domain is the user default
  • ip: the ip set for this domain
  • php(ON or OFF): is PHP is enabled
  • safemode(ON or OFF): whether safe mode is enabled for the domain
  • ssl(ON or OFF): whether ssl is enabled for the domain
  • suspended(yes or no): whether the domain is suspended

domain_create_(pre|post).sh

This script is called before/after a new domain has been created.

Environment variables

  • Info about domain:
    • domain: created domain name
    • username: owner of domain
    • creator: If domain was created by reseller, logged in as owner, resellers username would be set here
    • defaultdomain (yes/no): whether the created domain is the user default
  • Quotas
    • bandwidth (number in MB or unlimited) : bandwidth limit set for this domain
    • quota (number in MB or unlimited) : disk quota set for this domain
  • Web-server configuration:
    • cgi (ON or OFF): whether CGI (Common Gateway Interface) is enabled
    • php (ON or OFF): whether PHP is enabled
    • ssl (ON or OFF): whether SSL is enabled for the domain
    • open_basedir (ON or OFF): whether open_basedir is set for the domain
  • Creation process:
    • skip_template (0 or 1): specifies if the index.html is to be omitted from the domain creation. This is set to 1 if the domain already existed or the domain's directory is to be restored.
    • user_creation (0 or 1): specifies if the domain creation is happening at the same time that this User is being created.
    • created_by: Specifies the method by which the domain is created. possible options:
      • 0: domain is created with the User, by the Admin or Reseller creator (see creator variable to see who)
      • 1: domain is created by the User via the additional domains section
      • 2: domain is created by the User, via a User Level restore
      • 3: domain is created by Reseller Level restore
      • 4: domain is created by an Admin Level restore

domain_destroy_(pre|post).sh

This script is called before/after a domain has been destroyed.

Environment variables

  • delete_data (0 or 1): whether domain data from directory gets deleted
  • Info about domain:
    • domain: created domain name
    • username: owner of domain
    • defaultdomain (yes/no): whether the created domain is the User default domain
  • Quotas:
    • bandwidth (number in MB or unlimited) : bandwidth limit set for this domain
    • quota (number in MB or unlimited) : disk quota set for this domain
  • Web-server configuration:
    • cgi (ON/OFF): whether CGI (Common Gateway Interface) is enabled
    • php (ON/OFF): whether PHP is enabled
    • ssl (ON/OFF): whether SSL is enabled for the domain
    • open_basedir (ON/OFF): whether open_basedir is set for the domain
    • suspended (yes/no): whether the domain is suspended

domain_modify_(pre|post).sh

This script is called when a User modifies a domain (changes SSL, bandwidth, settings, etc.)

This is not for the change of a domain name, that's domain_change_pre.sh and domain_change_post.sh.

Environment variables

  • Info about domain
    • domain: name of modified domains
    • username: owner of domain
    • defaultdomain(yes/no): whether this domain is the user default domain
    • active(yes/no): whether the domain is active
    • suspended(yes/no): whether the domain is suspended
    • ip: ip assigned to domain
    • UseCanonicalName: NOTE: obsolete as of https://www.directadmin.com/features.php?id=423open in new window
  • Quotas
    • bandwidth=unlimited
    • quota=unlimited
  • Web-server configuration:
    • cgi (ON/OFF): whether CGI (Common Gateway Interface) is enabled
    • php (ON/OFF): whether PHP is enabled
    • ssl (ON/OFF): whether SSL is enabled for the domain
    • open_basedir (ON/OFF): whether open_basedir is set for domain
    • safemode(ON/OFF): whether php safe mode is on
    • force_redirect(non-www/www): (unset when no redirect is selected) force redirection to domain.tld or www.domain.tld
  • SSL configuration:
    • force_ssl(yes/no): force only SSL connections
    • SSLCACertificateFile: full path to certificate authority chain file
    • SSLCertificateFile: full path to domain certificate file
    • SSLCertificateKeyFile: full path to domain certificate key file
  • DA php selector
    • php1_select(1|2|3|4): main PHP version for a domain... number denotes which PHP version is used as set in CustomBuild

domain_pointer_create_(pre|post).sh

This hook is called before/after a domain pointer is created.

Environment variables

  • username: DA user/owner of domain
  • domain: domain for which pointer is created
  • from: domain which points to domain
  • ip: ip for the pointer
  • ns(1|2): nameservers for the domain pointer
  • alias: set to "yes" if this domain pointer needs to be created as pointer

domain_pointer_destroy_(pre|post).sh

This script is called before/after a domain pointer is destroyed.

Environment variables

  • username: DA user. owner of domain
  • domain: domain for which pointer is created
  • from: domain which points to domain

subdomain_create_(pre|post).sh

This hook script is called before/after a subdomain is created.

Environment variables

  • username: owner of domain
  • domain: domain for which this subdomain is created
  • subdomain: sub part of created subdomain
  • ip: user ip to be used for subdomain vhost
  • skip_template(0|1): do not use subdomain template (true when restoring user)
  • create_path(0|1): whether the new path for the subdomain is created (false when restoring the user)

subdomain_destroy_(pre|post).sh

The hook script called before/after a subdomain is destroyed.

Environment variables

  • username: owner of domain
  • domain: domain for which this subdomain is created
  • subdomain: sub part of created subdomain
  • ip: user ip to be used for subdomain vhost
  • contents(0|1): 1 - remove contents of subdomain (0 - leave subdomain contents intact)

Examples

Using domain_create_pre.sh to limit the number of domains allowed on a server

If you want to cap the number of domains created on the server, you can use the domain_create_pre.sh to do so.

In this example, we'll see a maximum number of 10 domains, but you can change this number as desired.

  1. Create the following file:
/usr/local/directadmin/scripts/custom/domain_create_pre.sh

In that script, add the code:

#!/bin/sh
MAX_DOMAINS=10

#obtains the exact number of domains on the system right now.  The tally is delayed, and cannot be used.
CURRENT=`ls -la /etc/virtual/ | grep drwx | grep -v majordomo | grep -v usage | grep -c drwx`

if [ "$CURRENT" -ge "$MAX_DOMAINS" ]; then
       echo "Maximum number of domains ($MAX_DOMAINS) has already been created.  Cannot create any more."
       exit 1;
fi
exit 0;
  1. chmod the script to 700 and the ownership to diradmin:
chmod 755 /usr/local/directadmin/scripts/custom/domain_create_pre.sh
chown diradmin. /usr/local/directadmin/scripts/custom/domain_create_pre.sh
  1. You may want to run this script before user creation as well (domain_create_pre.sh is ran after the user is already created), so just create a link to it:
cd /usr/local/directadmin/scripts/custom
ln -s domain_create_pre.sh user_create_pre.sh
Last Updated: