| Server IP : 172.67.149.12 / Your IP : 162.159.114.31 Web Server : Apache System : Linux vm3310.eosdns.net 4.18.0-553.132.1.el8_10.x86_64 #1 SMP Thu Jun 11 14:27:43 UTC 2026 x86_64 User : carnalmedia ( 1000) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mojo/ |
Upload File : |
#!/bin/bash
#
# Script: mjact_newdom
#
# Usage: mjact_newdom <IP> <FQDN> <user>
#
# Description: A tool for adding domains
#
# Author: Nikita Shchetinin
#
# Changelog:
# * 05.10.2022: Nikita Shchetinin
# - Replaced hard coded root path with a variable
# * 12.07.2021: Nikita Shchetinin
# - Removed creating SQL files with DNS zones
# * 25.02.2021: Nikita Shchetinin
# - Initial write
if [ "$(whoami)" != 'root' ]
then
echo "You must execute this script as the root user!"
exit 1
fi
mojoroot="/home/httpd/html"
ip=$1
domain=$2
user=$3
primaryip=$(hostname -i)
serial=$(date +%Y%m%d"01")
ADD () {
echo $'Preflight check...\n'
if ipcalc -cs $ip
then
echo "The IP is valid"
else
echo "The IP is invalid!"
exit 1
fi
if [ $(grep -c -P '(?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9\-]){0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$)' <<< $domain) == 1 ]
then
echo "The domain is valid"
else
echo "The domain is invalid!"
exit 1
fi
if id -u $user > /dev/null 2>&1
then
echo "The user exists"
else
echo "The user does not exist!"
exit 1
fi
echo $'\nAdding the domain...\n'
if [ ! -d $mojoroot/$domain/public_html ]
then
mkdir -p $mojoroot/$domain/public_html
chown -R $user:$user $mojoroot/$domain
echo $'The domain\'s root directory has been created'
else
echo $'The domain\'s root directory already exists!'
fi
if [ ! -f $mojoroot/$domain/public_html/index.php ]
then
echo "<?php echo '<h1>$domain</h1>'; ?>" > $mojoroot/$domain/public_html/index.php
chown $user:$user $mojoroot/$domain/public_html/index.php
echo "The index.php file has been created"
else
echo "The index.php file already exists!"
fi
if [ ! -f /etc/httpd/sites-available/$domain.conf ]
then
echo "<VirtualHost $ip:80>
ServerName $domain
ServerAlias www.$domain
DocumentRoot $mojoroot/$domain/public_html
CustomLog /var/log/httpd/domlog/${domain}_access_log combined
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteCond %{REQUEST_URI} !/.well-known
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
#<VirtualHost $ip:443>
#ServerName $domain
#ServerAlias www.$domain
#DocumentRoot $mojoroot/$domain/public_html
#CustomLog /var/log/httpd/domlog/${domain}_access_log combined
#SSLEngine on
#SSLCertificateFile /etc/letsencrypt/live/$domain/cert.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/$domain/privkey.pem
#SSLCertificateChainFile /etc/letsencrypt/live/$domain/chain.pem
#</VirtualHost>" > /etc/httpd/sites-available/$domain.conf
echo "The configuration file for $domain has been created"
else
echo "The configuration file for $domain already exists!"
fi
if [ ! -f /etc/httpd/sites-enabled/$domain.conf ]
then
ln -s /etc/httpd/sites-available/$domain.conf /etc/httpd/sites-enabled/$domain.conf
echo "The configuration file for $domain has been enabled"
else
echo "The configuration file for $domain is already enabled!"
fi
echo "$domain is added to the server"
}
HELP () {
echo "A tool for adding domains"
echo "usage: mjact_newdom <IP> <FQDN> <user>"
}
if [ -z "$3" ]
then
HELP
else
ADD
fi