Added default domain
This commit is contained in:
105
bin/v-default-domain
Executable file
105
bin/v-default-domain
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# info: add web/dns/mail domain
|
||||||
|
# options: USER DOMAIN COMMAND
|
||||||
|
#
|
||||||
|
# example: v-default-domain admin example.com set
|
||||||
|
# v-default-domain admin example.com delete
|
||||||
|
# v-default-domain admin example.com check
|
||||||
|
# v-default-domain admin example.com check-default
|
||||||
|
#
|
||||||
|
# This function set user's domain as default or reset it or get default domain or check is domain default.
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Variables & Functions #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Argument definition
|
||||||
|
user=$1
|
||||||
|
domain=$2
|
||||||
|
command=$3
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
# shellcheck source=/etc/hestiacp/hestia.conf
|
||||||
|
source /etc/hestiacp/hestia.conf
|
||||||
|
# shellcheck source=/usr/local/hestia/func/main.sh
|
||||||
|
source $HESTIA/func/main.sh
|
||||||
|
# load config file
|
||||||
|
source_conf "$HESTIA/conf/hestia.conf"
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Verifications #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
check_args '3' "$#" 'USER DOMAIN COMMAND'
|
||||||
|
is_format_valid 'user' 'domain'
|
||||||
|
if [ -n "$ip" ]; then
|
||||||
|
is_format_valid 'ip'
|
||||||
|
fi
|
||||||
|
is_object_valid 'user' 'USER' "$user"
|
||||||
|
is_object_unsuspended 'user' 'USER' "$user"
|
||||||
|
|
||||||
|
# Perform verification if read-only mode is enabled
|
||||||
|
check_hestia_demo_mode
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Action #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
confd="conf.h.d"
|
||||||
|
|
||||||
|
if [[ $command == check* ]]; then
|
||||||
|
default_conf="/etc/httpd/$confd/domains/00000000000000000_default.conf"
|
||||||
|
if [ -e "$default_conf" ]; then
|
||||||
|
file_name=$(readlink -f "$default_conf")
|
||||||
|
s_username=$(echo "$file_name" | cut -d"/" -f3 )
|
||||||
|
s_domain=$(echo "$file_name" | rev | cut -d"/" -f2 | rev )
|
||||||
|
if [ "$command" == "check-default" ]; then
|
||||||
|
echo "$s_username:$s_domain"
|
||||||
|
else
|
||||||
|
if [ "$user" == "$s_username" ] && [ "$domain" == "$s_domain" ]; then
|
||||||
|
echo "true"
|
||||||
|
else
|
||||||
|
echo "false"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "no default domain"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Working on web domain
|
||||||
|
if [ -n "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" == "httpd" ]; then
|
||||||
|
domain_path="/etc/httpd/$confd/domains/$domain.conf"
|
||||||
|
domain_ssl_path="/etc/httpd/$confd/domains/$domain.ssl.conf"
|
||||||
|
if [ -e "$domain_ssl_path" ] || [ -e "$domain_path" ]; then
|
||||||
|
path_name="$domain_path"
|
||||||
|
if [ -e "$domain_ssl_path" ]; then
|
||||||
|
path_name="$domain_ssl_path"
|
||||||
|
fi
|
||||||
|
if [ "$command" == "delete" ]; then
|
||||||
|
if [ -e "/etc/httpd/$confd/domains/00000000000000000_default.conf" ]; then
|
||||||
|
mv -f "/etc/httpd/$confd/domains/00000000000000000_default.conf" "/etc/httpd/$confd/domains/00000000000000000_default.conf.trash"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
ln -sf "${path_name}" "/etc/httpd/$confd/domains/00000000000000000_default.conf"
|
||||||
|
fi
|
||||||
|
echo "true"
|
||||||
|
else
|
||||||
|
echo "false"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restarting services
|
||||||
|
$BIN/v-restart-web "yes"
|
||||||
|
check_result $? "can't restart web" > /dev/null
|
||||||
|
|
||||||
|
$BIN/v-restart-proxy "yes"
|
||||||
|
check_result $? "can't restart proxy" > /dev/null
|
||||||
|
|
||||||
|
$BIN/v-restart-dns "yes"
|
||||||
|
check_result $? "can't restart dns" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Hestia #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
exit
|
||||||
@@ -130,6 +130,16 @@ if (!in_array($v_redirect, ["www." . $v_domain, $v_domain])) {
|
|||||||
$v_redirect_custom = $v_redirect;
|
$v_redirect_custom = $v_redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Is default domain
|
||||||
|
$v_is_default = false;
|
||||||
|
exec(HESTIA_CMD . "v-default-domain " . $user . " " . quoteshellarg($v_domain). " check", $output, $return_var);
|
||||||
|
if ($return_var == 0) {
|
||||||
|
if (strpos(implode("", $output), 'true') !== false) {
|
||||||
|
$v_is_default = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($output);
|
||||||
|
|
||||||
$v_ftp_user = $data[$v_domain]["FTP_USER"];
|
$v_ftp_user = $data[$v_domain]["FTP_USER"];
|
||||||
$v_ftp_path = $data[$v_domain]["FTP_PATH"];
|
$v_ftp_path = $data[$v_domain]["FTP_PATH"];
|
||||||
if (!empty($v_ftp_user)) {
|
if (!empty($v_ftp_user)) {
|
||||||
@@ -1593,6 +1603,40 @@ if (!empty($_POST["save"])) {
|
|||||||
unset($v_custom_doc_root);
|
unset($v_custom_doc_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST["v-default-domain"])) {
|
||||||
|
if ($v_is_default == false) {
|
||||||
|
exec(
|
||||||
|
HESTIA_CMD .
|
||||||
|
"v-default-domain " .
|
||||||
|
$user .
|
||||||
|
" " .
|
||||||
|
quoteshellarg($v_domain) .
|
||||||
|
" set",
|
||||||
|
$output,
|
||||||
|
$return_var,
|
||||||
|
);
|
||||||
|
check_return_code($return_var, $output);
|
||||||
|
unset($output);
|
||||||
|
$v_is_default = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($v_is_default == true) {
|
||||||
|
exec(
|
||||||
|
HESTIA_CMD .
|
||||||
|
"v-default-domain " .
|
||||||
|
$user .
|
||||||
|
" " .
|
||||||
|
quoteshellarg($v_domain) .
|
||||||
|
" delete",
|
||||||
|
$output,
|
||||||
|
$return_var,
|
||||||
|
);
|
||||||
|
check_return_code($return_var, $output);
|
||||||
|
unset($output);
|
||||||
|
$v_is_default = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($v_redirect) && empty($_POST["v-redirect-checkbox"])) {
|
if (!empty($v_redirect) && empty($_POST["v-redirect-checkbox"])) {
|
||||||
exec(
|
exec(
|
||||||
HESTIA_CMD . "v-delete-web-domain-redirect " . $user . " " . quoteshellarg($v_domain),
|
HESTIA_CMD . "v-delete-web-domain-redirect " . $user . " " . quoteshellarg($v_domain),
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -127,6 +127,12 @@ if ($passenger_state == "enabled") {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-check u-mb10">
|
||||||
|
<input class="form-check-input" type="checkbox" name="v-default-domain" id="v-default-domain" <?php if ($v_is_default == true) echo 'checked'; ?>>
|
||||||
|
<label for="v-default-domain">
|
||||||
|
<?= _("Set this domain as default for server") ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="form-check u-mb10">
|
<div class="form-check u-mb10">
|
||||||
<input x-model="redirectEnabled" class="form-check-input" type="checkbox" name="v-redirect-checkbox" id="v-redirect-checkbox">
|
<input x-model="redirectEnabled" class="form-check-input" type="checkbox" name="v-redirect-checkbox" id="v-redirect-checkbox">
|
||||||
<label for="v-redirect-checkbox">
|
<label for="v-redirect-checkbox">
|
||||||
|
|||||||
Reference in New Issue
Block a user