Last active
December 9, 2023 18:15
-
-
Save bouroo/fb9ea6a0e49847b50800e7a4ff48142f to your computer and use it in GitHub Desktop.
Bulk Add Domains To DirectAdmin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Require curl & jq | |
hash curl 2>/dev/null || { echo >&2 "I require 'curl' but it's not installed. Aborting."; exit 1; } | |
hash jq 2>/dev/null || { echo >&2 "I require 'jq' but it's not installed. Aborting."; exit 1; } | |
# Get user infos | |
read -e -i 'http://domain.com:2222' -p 'DA URL: ' DA_URL | |
read -p 'DA User: ' DA_USER | |
read -sp 'DA Password: ' DA_PASS | |
echo | |
read -e -i 'domains.csv' -p 'Domain list file: ' DOMAIN_FILE | |
read -e -i 'y' -p 'SSL support [Y/n]: ' DA_SSL | |
if [[ ${DA_SSL} =~ ^([yY][eE][sS]|[yY])+$ ]] | |
then | |
DA_SSL="ON" | |
else | |
DA_SSL="OFF" | |
fi | |
read -e -i 'y' -p 'CGI support [Y/n]: ' DA_CGI | |
if [[ ${DA_CGI} =~ ^([yY][eE][sS]|[yY])+$ ]] | |
then | |
DA_CGI="ON" | |
else | |
DA_CGI="OFF" | |
fi | |
read -e -i 'y' -p 'PHP support [Y/n]: ' DA_PHP | |
if [[ ${DA_PHP} =~ ^([yY][eE][sS]|[yY])+$ ]] | |
then | |
DA_PHP="ON" | |
else | |
DA_PHP="OFF" | |
fi | |
# Loop through domains list file | |
while IFS=',' read -r DOMAIN_ITEM HOST_IP || [ -n "${HOST_IP}" ]; do | |
# Ignore header | |
if [[ ${DOMAIN_ITEM} != *"."* ]] | |
then | |
continue | |
fi | |
# Create Domain | |
echo "Create Domain: " ${DOMAIN_ITEM} | |
RESP=$(curl -s -X POST "${DA_URL}/CMD_API_DOMAIN" \ | |
--user "${DA_USER}:${DA_PASS}" \ | |
-F "action=create" \ | |
-F "domain=${DOMAIN_ITEM}" \ | |
-F "ubandwidth=unlimited" \ | |
-F "uquota=unlimited" \ | |
-F "ssl=${DA_SSL}" \ | |
-F "cgi=${DA_CGI}" \ | |
-F "php=${DA_PHP}") | |
echo ${RESP} | |
sleep 5 | |
done < ${DOMAIN_FILE} | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Require curl & jq | |
hash curl 2>/dev/null || { echo >&2 "I require 'curl' but it's not installed. Aborting."; exit 1; } | |
hash jq 2>/dev/null || { echo >&2 "I require 'jq' but it's not installed. Aborting."; exit 1; } | |
# Get user infos | |
read -e -i 'http://domain.com:2222' -p 'DA URL: ' DA_URL | |
read -p 'DA User: ' DA_USER | |
read -sp 'DA Password: ' DA_PASS | |
echo | |
read -e -i 'domains.csv' -p 'Domain list file: ' DOMAIN_FILE | |
read -e -i 'n' -p 'Delete Domains [y/N]: ' DEL_DOMAIN | |
if [[ ${DEL_DOMAIN} =~ ^([nN][oO]|[nN])+$ ]] | |
then | |
exit 0 | |
fi | |
# Loop through domains list file | |
while IFS=',' read -r DOMAIN_ITEM HOST_IP || [ -n "${HOST_IP}" ]; do | |
# Ignore header | |
if [[ ${DOMAIN_ITEM} != *"."* ]] | |
then | |
continue | |
fi | |
# Create Domain | |
echo "Delete Domain: " ${DOMAIN_ITEM} | |
RESP=$(curl -s -X POST "${DA_URL}/CMD_API_DNS_ADMIN" \ | |
--user "${DA_USER}:${DA_PASS}" \ | |
-F "action=delete" \ | |
-F "delete=Delete" \ | |
-F "select0=${DOMAIN_ITEM}") | |
echo ${RESP} | |
sleep 5 | |
done < ${DOMAIN_FILE} | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domain1.com | IP1 | |
---|---|---|
domain2.net | IP2 | |
domain3.io | IP3 | |
domainX.xxx | IP4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment