Merge remote-tracking branch 'refs/remotes/serghey-rodin/master'

This commit is contained in:
nguyenngocphuongnb 2015-11-08 00:40:22 +07:00
commit e3149992e8
2192 changed files with 101406 additions and 14417 deletions

View file

@ -13,12 +13,18 @@ Connect to your server as root via SSH
ssh root@your.server
```
Download the installation script
Download the installation script, and run it:
```bash
curl http://vestacp.com/pub/vst-install.sh | bash
```
If the above example does not work, try this 2 step method:
Download the installation script:
```bash
curl -O http://vestacp.com/pub/vst-install.sh
```
Run it
Then run it:
```bash
bash vst-install.sh
```

View file

@ -0,0 +1,66 @@
#!/bin/bash
# info: update user notification
# options: USER NOTIFICATION
#
# The function updates user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
nid=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER NOTIFICATION'
validate_format 'user' 'nid'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating notification
update_object_value 'notifications' 'NID' "$nid" '$ACK' 'yes' 2>/dev/null
# Checking last notification
if [ -e "$USER_DATA/notifications.conf" ]; then
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
else
notice='no'
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ "$notice" = 'no' ]; then
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "no"
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -1,101 +0,0 @@
#!/bin/bash
# info: add backup ftp host
# options: HOST USERNAME PASSWORD [PATH] [PORT]
#
# The function adds ftp host for system backups
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
host=$1
ftp_user=$2
ftp_password=$3
ftp_path=${4-/backup}
ftp_port=${5-21}
A3='******'
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Defining ftp command function
ftpc() {
ftp -p -n $host $ftp_port <<EOF
quote USER $ftp_user
quote PASS $ftp_password
binary
$1
$2
$3
quit
EOF
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" "HOST USERNAME PASSWORD [PATH] [PORT]"
validate_format 'host' 'ftp_user' 'ftp_password'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking network connection
fconn=$(ftpc)
ferror=$(echo $fconn |grep -i -e failed -e error -e "Can't" -e "not conn")
if [ ! -z "$ferror" ]; then
echo "Error: can't login to ftp"
log_event "$E_CONNECT" "$EVENT"
exit $E_CONNECT
fi
# Checking write permissions
ftpc "mkdir $ftp_path" > /dev/null 2>&1
ftmpdir="$ftp_path/vst.bK76A9SUkt"
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir"|grep -v Trying)
if [ ! -z "$ftp_result" ] ; then
echo "$ftp_result"
rm -rf $tmpdir
echo "Error: can't create temp folder on the ftp"
log_event "$E_FTP" "$EVENT"
exit $E_FTP
fi
# Adding backup host
echo "HOST='$host'
USERNAME='$ftp_user'
PASSWORD='$ftp_password'
BPATH='$ftp_path'
PORT='$ftp_port'
TIME='$TIME'
DATE='$DATE'" > $VESTA/conf/ftp.backup.conf
chmod 660 $VESTA/conf/ftp.backup.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Update vesta.conf
if [ -z "$(grep LANGUAGE $VESTA/conf/vesta.conf)" ]; then
echo "BACKUP_SYSTEM='ftp'" >> $VESTA/conf/vesta.conf
else
bckp=$(echo "$BACKUP_SYSTEM,ftp" |\
sed "s/,/\n/g"|\
sort -r -u |\
sed "/^$/d"|\
sed ':a;N;$!ba;s/\n/,/g')
sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $VESTA/conf/vesta.conf
fi
# Logging
log_event "$OK" "$EVENT"
exit

186
bin/v-add-backup-host Executable file
View file

@ -0,0 +1,186 @@
#!/bin/bash
# info: add backup host
# options: TYPE HOST USERNAME PASSWORD [PATH] [PORT]
#
# The function adds backup host
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
host=$2
user=$3
password=$4; HIDE=4
path=${5-/backup}
port=$6
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Defining ftp command function
ftpc() {
ftp -p -n $host $port <<EOF
quote USER $user
quote PASS $password
binary
$1
$2
$3
quit
EOF
}
# Defining sftp command function
sftpc() {
expect -f "-" <<EOF "$@"
set count 0
spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o \
Port=$port $user@$host
expect {
"password:" {
send "$password\r"
exp_continue
}
-re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
set count \$argc
set output "Disconnected."
set rc $E_FTP
exp_continue
}
-re ".*denied.*(publickey|password)." {
set output "Permission denied, wrong publickey or password."
set rc $E_CONNECT
}
"sftp>" {
if {\$count < \$argc} {
set arg [lindex \$argv \$count]
send "\$arg\r"
incr count
} else {
send "exit\r"
set output "Disconnected."
if {[info exists rc] != 1} {
set rc $OK
}
}
exp_continue
}
timeout {
set output "Connection timeout."
set rc $E_CONNECT
}
}
if {[info exists output] == 1} {
puts "\$output"
}
exit \$rc
EOF
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ "$type" != 'local' ];then
check_args '4' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
validate_format 'host'
is_password_valid
if [ "$type" = 'sftp' ]; then
which expect >/dev/null 2>&1
check_result $? "expect command not found" $E_NOTEXIST
fi
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking network connection
if [ "$type" = 'ftp' ]; then
if [ -z $port ]; then
port=21
fi
fconn=$(ftpc 2>&1)
ferror=$(echo $fconn |\
grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
if [ ! -z "$ferror" ]; then
echo "Error: can't login to ftp $user@$host"
log_event "$E_CONNECT" "$EVENT"
exit $E_CONNECT
fi
# Checking write permissions
ftpc "mkdir $path" > /dev/null 2>&1
ftmpdir="$path/vst.bK76A9SUkt"
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir"|grep -v Trying)
if [ ! -z "$ftp_result" ] ; then
echo "$ftp_result"
rm -rf $tmpdir
echo "Error: can't create $ftmpdir folder on the ftp"
log_event "$E_FTP" "$EVENT"
exit $E_FTP
fi
fi
if [ "$type" = 'sftp' ]; then
if [ -z $port ]; then
port=22
fi
sftmpdir="$path/vst.bK76A9SUkt"
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
rc=$?
if [[ "$rc" != 0 ]]; then
case $rc in
$E_CONNECT) echo "Error: can't login to sftp $user@$host";;
$E_FTP) echo "Error: can't create temp folder on the sftp host";;
esac
log_event "$rc" "$EVENT"
exit "$rc"
fi
fi
# Adding backup host
if [ $type != 'local' ]; then
echo "HOST='$host'
USERNAME='$user'
PASSWORD='$password'
BPATH='$path'
PORT='$port'
TIME='$TIME'
DATE='$DATE'" > $VESTA/conf/$type.backup.conf
chmod 660 $VESTA/conf/$type.backup.conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Update vesta.conf
if [ -z "$(grep BACKUP_SYSTEM $VESTA/conf/vesta.conf)" ]; then
echo "BACKUP_SYSTEM='$type'" >> $VESTA/conf/vesta.conf
else
bckp=$(echo "$BACKUP_SYSTEM,$type" |\
sed "s/,/\n/g"|\
sort -r -u |\
sed "/^$/d"|\
sed ':a;N;$!ba;s/\n/,/g')
sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $VESTA/conf/vesta.conf
fi
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -72,11 +72,9 @@ sync_cron_jobs
# Increasing cron value
increase_user_value $user '$U_CRON_JOBS'
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_history "added cron job $job"

View file

@ -46,9 +46,7 @@ sync_cron_jobs
# Restart crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_history "enabled cron reporting"

View file

@ -66,11 +66,9 @@ sync_cron_jobs
# Increasing cron value
increase_user_value $user '$U_CRON_JOBS'
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_history "added cron job $job"

View file

@ -19,7 +19,7 @@
user=$1
database="$user"_"$2"
dbuser="$user"_"$3"
dbpass=$4
password=$4; HIDE=4
type=${5-mysql}
host=$6
charset=${7-UTF8}
@ -30,17 +30,13 @@ source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DATABASE DBUSER DBPASS [TYPE] [HOST] [CHARSET]'
validate_format 'user' 'database' 'dbuser' 'dbpass' 'charset'
validate_format 'user' 'database' 'dbuser' 'charset'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_type_valid "$DB_SYSTEM" "$type"
is_object_valid 'user' 'USER' "$user"
@ -51,6 +47,8 @@ is_object_valid "../../../conf/$type" 'DBHOST' "$host"
is_object_unsuspended "../../../conf/$type" 'DBHOST' "$host"
#is_charset_valid
is_package_full 'DATABASES'
is_password_valid
dbpass="$password"
#----------------------------------------------------------#

View file

@ -17,7 +17,7 @@
type=$1
host=$2
dbuser=$3
dbpass=$4
password=$4; HIDE=4
max_db=${6-500}
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
template=${8-template1}
@ -27,8 +27,31 @@ source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
is_mysql_host_alive() {
mycnf=$(mktemp)
echo "[client]">$mycnf
echo "host='$HOST'" >> $mycnf
echo "user='$USER'" >> $mycnf
echo "password='$PASSWORD'" >> $mycnf
chmod 600 $mycnf
mysql --defaults-file=$mycnf -e 'SELECT VERSION()' >/dev/null 2>&1
rm $mycnf
if [ '0' -ne "$?" ]; then
echo "Error: MySQL connection to $host failed"
log_event "$E_CONNECT" "$EVENT"
exit $E_CONNECT
fi
}
is_pgsql_host_alive() {
export PGPASSWORD="$dbpass"
psql -h $host -U $dbuser -c "SELECT VERSION()" > /dev/null 2>&1
if [ '0' -ne "$?" ]; then
echo "Error: PostgreSQL connection to $host failed"
log_event "$E_CONNECT" "$EVENT"
exit $E_CONNECT
fi
}
#----------------------------------------------------------#
@ -37,10 +60,12 @@ A4='******'
args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
check_args '4' "$#" "$args_usage"
validate_format 'host' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_type_valid "$DB_SYSTEM" "$type"
validate_format 'host' 'dbuser' 'max_db' 'charsets' 'template'
#is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
#is_type_valid "$DB_SYSTEM" "$type"
is_dbhost_new
is_password_valid
dbpass="$password"
case $type in
mysql) is_mysql_host_alive ;;
pgsql) is_pgsql_host_alive ;;
@ -62,15 +87,28 @@ case $type in
str="$str TIME='$TIME' DATE='$DATE'";;
esac
# Adding host to conf
echo "$str" >> $VESTA/conf/$type.conf
chmod 660 $VESTA/conf/$type.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding host to conf
echo "$str" >> $VESTA/conf/$type.conf
chmod 660 $VESTA/conf/$type.conf
# Updating vesta.conf
if [ -z "$(grep DB_SYSTEM $VESTA/conf/vesta.conf)" ]; then
echo "DB_SYSTEM='$type'" >> $VESTA/conf/vesta.conf
else
db=$(echo "$DB_SYSTEM,$type" |\
sed "s/,/\n/g"|\
sort -r -u |\
sed "/^$/d"|\
sed ':a;N;$!ba;s/\n/,/g')
sed -i "s/DB_SYSTEM=.*/DB_SYSTEM='$db'/g" $VESTA/conf/vesta.conf
fi
# Logging
log_event "$OK" "$EVENT"

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add dns domain
# options: USER DOMAIN IP [NS1] [NS2] [NS3] [NS4] [RESTART]
# options: USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]
#
# The function adds DNS zone with records defined in the template. If the exp
# argument isn't stated, the expiration date value will be set to next year.
@ -24,7 +24,11 @@ ns1=$4
ns2=$5
ns3=$6
ns4=$7
restart=$8
ns5=$8
ns6=$9
ns7=${10}
ns8=${11}
restart=${12}
# Includes
source $VESTA/func/main.sh
@ -36,14 +40,13 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [NS4]'
check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]'
validate_format 'user' 'domain' 'ip'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_domain_new 'dns'
is_package_full 'DNS_DOMAINS'
template=$(get_user_value '$DNS_TEMPLATE')
is_dns_template_valid
@ -64,6 +67,23 @@ if [ ! -z "$ns4" ]; then
ns4=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns4'
fi
if [ ! -z "$ns5" ]; then
ns5=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns5'
fi
if [ ! -z "$ns6" ]; then
ns6=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns6'
fi
if [ ! -z "$ns7" ]; then
ns7=$(echo ${10} | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns7'
fi
if [ ! -z "$ns8" ]; then
ns8=$(echo ${11} | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns8'
fi
#----------------------------------------------------------#
@ -81,6 +101,7 @@ if [ -z $ns2 ]; then
fi
soa="$ns1"
exp=$(date +%F -d "+ 1 year")
serial=$(date +'%Y%m%d01')
ttl=14400
# Reading template
@ -88,13 +109,25 @@ template_data=$(cat $DNSTPL/$template.tpl)
# Deleting unused nameservers
if [ -z "$ns3" ]; then
template_data=$(echo "$template_data" | grep -v %ns3%)
template_data=$(echo "$template_data" |grep -v %ns3%)
fi
if [ -z "$ns4" ]; then
template_data=$(echo "$template_data" | grep -v %ns4%)
template_data=$(echo "$template_data" |grep -v %ns4%)
fi
if [ -z "$ns5" ]; then
template_data=$(echo "$template_data" |grep -v %ns5%)
fi
if [ -z "$ns6" ]; then
template_data=$(echo "$template_data" |grep -v %ns6%)
fi
if [ -z "$ns7" ]; then
template_data=$(echo "$template_data" |grep -v %ns7%)
fi
if [ -z "$ns8" ]; then
template_data=$(echo "$template_data" |grep -v %ns8%)
fi
# Add dns zone to the user config
# Adding dns zone to the user config
echo "$template_data" |\
sed -e "s/%ip%/$ip/g" \
-e "s/%domain_idn%/$domain_idn/g" \
@ -103,6 +136,10 @@ echo "$template_data" |\
-e "s/%ns2%/$ns2/g" \
-e "s/%ns3%/$ns3/g" \
-e "s/%ns4%/$ns4/g" \
-e "s/%ns5%/$ns5/g" \
-e "s/%ns6%/$ns6/g" \
-e "s/%ns7%/$ns7/g" \
-e "s/%ns8%/$ns8/g" \
-e "s/%time%/$TIME/g" \
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
@ -111,13 +148,13 @@ records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
# Adding dns.conf record
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' TIME='$TIME'"
dns_rec="$dns_rec DATE='$DATE'"
dns_rec="$dns_rec SOA='$soa' SERIAL='$serial' SRC='' RECORDS='$records'"
dns_rec="$dns_rec SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
echo "$dns_rec" >> $USER_DATA/dns.conf
chmod 660 $USER_DATA/dns.conf
# Create system configs
# Creating system configs
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
if [ -e '/etc/named.conf' ]; then
dns_conf='/etc/named.conf'
@ -135,14 +172,14 @@ if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
# Updating domain dns zone
update_domain_zone
# Set permissions
chmod 640 $conf
chown root:$dns_group $conf
# Changing permissions
chmod 640 $HOMEDIR/$user/conf/dns/$domain.db
chown root:$dns_group $HOMEDIR/$user/conf/dns/$domain.db
fi
# Updating dns-cluster queue
if [ ! -z "$DNS_CLUSTER" ]; then
cmd="$BIN/v-add-remote-dns-domain $user $domain no"
cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
fi
@ -158,9 +195,7 @@ increase_user_value "$user" '$U_DNS_RECORDS' "$records"
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed"
fi
# Logging

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add dns domain or dns record based on web domain alias restart
# options: USER DOMAIN
# info: add dns domain or dns record after web domain alias
# options: USER ALIAS IP [RESTART]
#
# The function adds dns domain or dns record based on web domain alias.
@ -11,13 +11,9 @@
# Argument defenition
user=$1
domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
domain_idn=$(idn -t --quiet -a "$domain")
dom_alias=$(idn -t --quiet -u "$3" )
dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
restart="$4"
alias=$2
ip=$3
restart=$4
# Includes
source $VESTA/func/main.sh
@ -29,58 +25,54 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN ALIAS'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
check_args '3' "$#" 'USER ALIAS IP [RESTART]'
validate_format 'user' 'alias' 'ip'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
if [ -e "$USER_DATA/dns/$alias.conf" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain values
get_domain_values 'web'
# Logging
log_event "$OK" "$EVENT"
# Check if it a simple domain
if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
if [ ! -e "$USER_DATA/dns/$dom_alias.conf" ]; then
$BIN/v-add-dns-domain \
$user $dom_alias $IP '' '' '' '' '' $restart > /dev/null
fi
# Define additional vars
sub_domain=$(echo "$alias" |awk -F '.' '{print $1}')
top_domain=$(echo "$alias" |sed -e "s/^$sub_domain.//")
domain_lvl=$(echo "$alias" |grep -o "\." |wc -l)
# Adding second level domain
if [ "$domain_lvl" -eq 1 ] || [ "${#top_domain}" -le '6' ]; then
$BIN/v-add-dns-domain \
$user $alias $ip '' '' '' '' '' $restart >> /dev/null
exit
fi
# Adding toplevel domain and then its sub
$BIN/v-add-dns-domain $user $top_domain $ip '' '' '' '' $restart >> /dev/null
# Checking top-level domain
if [ ! -e "$USER_DATA/dns/$top_domain.conf" ]; then
exit
fi
# Checking subdomain record
if [ "$sub_domain" == '*' ]; then
check_record=$(grep -w "RECORD='\*'" $USER_DATA/dns/$top_domain.conf)
else
# Check subdomain
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
check_record=$(grep -w "RECORD='$sub_domain'" $USER_DATA/dns/$top_domain.conf)
fi
# Ignore short domains like co.uk, com.au and so on
if [ "${#dom}" -le '6' ]; then
exit
fi
if [ ! -e "$USER_DATA/dns/$dom.conf" ]; then
$BIN/v-add-dns-domain \
$user $dom $IP '' '' '' '' $restart > /dev/null
if [ $? -eq 0 ]; then
$BIN/v-add-dns-record \
$user $dom "$sub" A $IP '' '' $restart
fi
else
if [ "$sub" == '*' ]; then
rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$dom.conf)
else
rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$dom.conf)
fi
if [ -z "$rec" ]; then
$BIN/v-add-dns-record \
$user $dom "$sub" A $IP '' '' $restart > /dev/null
fi
fi
# Adding subdomain record
if [ -z "$check_record" ]; then
$BIN/v-add-dns-record \
$user $top_domain "$sub_domain" A $ip '' '' $restart >> /dev/null
fi
@ -88,6 +80,6 @@ fi
# Vesta #
#----------------------------------------------------------#
# No Logging
# No logging
exit

View file

@ -82,6 +82,7 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -108,9 +109,7 @@ increase_user_value "$user" '$U_DNS_RECORDS'
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? $E_RESTART 'dns failed to restart'
fi
# Logging

View file

@ -47,37 +47,34 @@ if [ -z "$ip" ]; then
fi
fi
# Web domain
# Working on web domain
if [ ! -z "$WEB_SYSTEM" ]; then
$BIN/v-add-web-domain $user $domain $ip 'no'
return_code=$?
check_result $? "can't add web domain" >/dev/null
fi
# Proxy support
if [ ! -z "$PROXY_SYSTEM" ] && [ "$return_code" -eq 0 ]; then
extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls"
extentions="$extentions,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav"
extentions="$extentions,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
$BIN/v-add-web-domain-proxy $user $domain 'default' "$extentions" 'no'
# Working on DNS domain
if [ ! -z "$DNS_SYSTEM" ]; then
$BIN/v-add-dns-domain $user $domain $ip "" "" "" "" "" 'no'
check_result $? "can't add dns domain" >/dev/null
fi
# DNS domain
if [ ! -z "$DNS_SYSTEM" ] && [ "$return_code" -eq 0 ]; then
$BIN/v-add-dns-domain $user $domain $ip 'no'
return_code=$?
fi
# Mail domain
if [ ! -z "$MAIL_SYSTEM" ] && [ "$return_code" -eq 0 ]; then
# Working on mail domain
if [ ! -z "$MAIL_SYSTEM" ]; then
$BIN/v-add-mail-domain $user $domain
return_code=$?
check_result $? "can't add mail domain" >/dev/null
fi
# Restart services
if [ "$restart" != 'no' ] && [ "$return_code" -eq 0 ]; then
# Restarting services
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
$BIN/v-restart-proxy
check_result $? "can't restart web" > /dev/null
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "can't restart proxy" > /dev/null
fi
$BIN/v-restart-dns
check_result $? "can't restart dns" > /dev/null
fi
@ -85,4 +82,4 @@ fi
# Vesta #
#----------------------------------------------------------#
exit $return_code
exit

View file

@ -52,7 +52,7 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
get_next_fw_rule
validate_format 'rule'
is_object_new '../../data/firewall/rules' 'RULE' "$rule"
if [ ! -z "$comment"]; then
if [ ! -z "$comment" ]; then
validate_format 'comment'
fi

59
bin/v-add-fs-archive Executable file
View file

@ -0,0 +1,59 @@
#!/bin/bash
# info: archive directory
# options: USER ARCHIVE DIRECTORY [DIRECTORY_N]
#
# The function creates tar archive
user=$1
archive=$2
src1=$3
src2=$4
src3=$5
src4=$6
src5=$7
src6=$8
src7=$9
# Checking arguments
if [ -z "$src1" ]; then
echo "Usage: USER ARCHIVE DIRECTORY [DIRECTORY_N]"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking archive
if [ -e "$archive.tar.gz" ]; then
echo "Error: archive already exist $archive.tar.gz"
exit 1
fi
# Checking source path
for src_path in $src1 $src2 $src3 $src4 $src5 $src6 $src7; do
rpath=$(readlink -f "$src_path")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src_path"
exit 1
fi
done
# Creating tar.gz archive
sudo -u $user tar -czf "$archive.tar.gz" \
$src1 $src2 $src3 $src4 $src5 $src6 $src7 > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
# echo "Error: archive $archive.tar.gz was not created"
exit 3
fi
exit

44
bin/v-add-fs-directory Executable file
View file

@ -0,0 +1,44 @@
#!/bin/bash
# info: add directory
# options: USER DIRECTORY
#
# The function creates new directory on the file system
user=$1
dst_dir=$2
# Checking arguments
if [ -z "$dst_dir" ]; then
echo "Usage: USER DIRECTORY"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking destination path
rpath=$(readlink -f "$dst_dir")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid destination path $dst_dir"
exit 2
fi
# Adding directory
sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: directory $dst_dir was not created"
exit 3
fi
# Extiging
exit

44
bin/v-add-fs-file Executable file
View file

@ -0,0 +1,44 @@
#!/bin/bash
# info: add file
# options: USER FILE
#
# The function creates new files on file system
user=$1
dst_file=$2
# Checking arguments
if [ -z "$dst_file" ]; then
echo "Usage: USER FILE"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking destination path
rpath=$(readlink -f "$dst_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid destination path $dst_dir"
exit 2
fi
# Creating file
sudo -u $user touch "$dst_file" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: file $dst_file was not created"
exit 3
fi
# Exiting
exit

View file

@ -15,25 +15,24 @@ domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$(echo $3 | tr '[:upper:]' '[:lower:]')
password=$4
quota=${5-0}
password=$4; HIDE=4
quota=${5-unlimited}
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD [QUOTA]'
validate_format 'user' 'domain' 'account' 'password' 'quota'
validate_format 'user' 'domain' 'account'
if [ "$quota" != 'unlimited' ]; then
validate_format 'quota'
fi
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -41,19 +40,22 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
is_package_full 'MAIL_ACCOUNTS'
is_mail_new "$account"
is_password_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -x '/usr/bin/doveadm' ]; then
md5=$(/usr/bin/doveadm pw -s md5 -p "$password")
else
md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
fi
# Generating hashed password
salt=$(gen_password "$PW_MATRIX" "8")
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
# Adding account info into password file
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
if [ "$quota" = 'unlimited' ]; then
quota='0'
fi
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
fi
@ -63,6 +65,10 @@ fi
# Vesta #
#----------------------------------------------------------#
if [[ "$quota" -eq '0' ]]; then
quota='unlimited'
fi
str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
str="$str FWD_ONLY='' MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
str="$str DATE='$DATE'"

View file

@ -27,101 +27,64 @@ source $VESTA/conf/vesta.conf
check_args '2' "$#" 'USER DOMAIN [FLUSH]'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Check domain existance
check_local_domain=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
if [ -z "$check_local_domain" ]; then
# Parsing domain record
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
if [ -z "$str" ]; then
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
queue_str=$(grep -n "$SCRIPT $1 $2 no$" $pipe |cut -f1 -d: |head -n1)
if [ ! -z "$queue_str" ]; then
sed -i "$queue_str d" $pipe
fi
exit
fi
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Check remote dns nodes
remote_dns_health_check
# Parsing remote dns host parameters
eval $cluster
search_str=$(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf)
for cluster_str in $search_str; do
# Get host values
eval $cluster_str
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Check flush parameters
# Sync domain
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
# Parsing domain parameters
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME "$flush" 'no'
if [ $? -eq 0 ]; then
# Sync records
if [ "$TYPE" = 'ssh' ]; then
tmp=$(mktemp -u)
scp_cmd $USER_DATA/dns/$DOMAIN.conf $tmp
$send_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp 'no'
else
for str in $(cat $USER_DATA/dns/$DOMAIN.conf); do
str=$(echo "$str" | sed 's/"/\\"/g')
$send_cmd v-insert-dns-record $DNS_USER $DOMAIN "$str"
done
fi
# Syncing domain data
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
check_result $? "$HOST connection failed" $E_CONNECT
# Rebuild dns zone
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
fi
# Syncing domain records
tmp_file="/tmp/vst-sync.$DOMAIN"
cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
check_result $? "$HOST connection failed" $E_CONNECT
# Inserting synced records
cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
check_result $? "$HOST connection failed" $E_CONNECT
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed" $E_CONNECT
done
# Update pipe
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
rm -f $tmpfile
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
@ -129,8 +92,4 @@ if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -11,10 +11,15 @@
# Argument defenition
host=$1
HOST=$host
port=$2
PORT=$port
user=$3
password=$4
USER=$user
password=$4; HIDE=4
PASSWORD=$password
type=${5-api}
TYPE="$type"
dns_user=${6-dns-cluster}
DNS_USER=$dns_user
@ -23,9 +28,6 @@ source $VESTA/func/main.sh
source $VESTA/func/remote.sh
source $VESTA/conf/vesta.conf
# Hiding passwords
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -33,8 +35,9 @@ A4='******'
args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]'
check_args '4' "$#" "$args_usage"
validate_format 'host' 'port' 'user' 'password' 'type' 'dns_user'
validate_format 'host' 'port' 'user' 'type' 'dns_user'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_password_valid
is_dnshost_new
is_dnshost_alive
@ -59,36 +62,26 @@ else
sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
fi
# Enabling restart queue
HOST=$host
PORT=$port
USER=$user
PASSWORD=$password
case $type in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
$send_cmd v-add-cron-restart-job
# Enabling remote dns-cluster queue
cluster_cmd v-add-cron-restart-job
check_result $? "$HOST connection failed" $E_CONNECT
# Sync current zones
# Syncing all domains
$BIN/v-sync-dns-cluster $host
return_code=$?
if [ "$return_code" -ne 0 ]; then
exit $return_code
fi
# Add dns-cluster cron job
cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster"
check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
$BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
fi
check_result $? "$HOST sync failed" $E_CONNECT
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding local dns-cluster cron job
cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster"
check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
$BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
fi
# Logging
log_event "$OK" "$EVENT"

View file

@ -29,83 +29,62 @@ validate_format 'user' 'domain' 'id'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_object_valid "dns/$domain" 'ID' "$id"
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
# Parsing record
str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
if [ -z "$str" ]; then
pipe="$VESTA/data/queue/dns-cluster.pipe"
queue_str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$queue_str" ]; then
sed -i "$queue_str d" $pipe
fi
exit
fi
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Check remote dns nodes
remote_dns_health_check
# Parsing remote host parameters
eval $cluster
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Syncing serial
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
check_result $? "$HOST connection failed (soa sync)" $E_CONNECT
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Syncing record
str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf | sed 's/"/\\"/g')
cluster_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no'
check_result $? "$HOST connection failed (record sync)" $E_CONNECT
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Sync record
str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
str=$(echo "$str" | sed 's/"/\\"/g')
$send_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no'
if [ $? -eq 0 ]; then
# Rebuild dns zone
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (rebuild)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
fi
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
done
# Update pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -159,14 +159,19 @@ else
increase_user_value 'admin' '$IP_AVAIL'
fi
# Restart web server
# Restarting web server
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
check_result $? "Web restart failed" >/dev/null
# Restarting proxy server
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
# Restarting firewall
if [ ! -z "$FIREWALL_SYSTEM" ]; then
$BIN/v-update-firewall
fi
# Logging

View file

@ -22,18 +22,11 @@ source $VESTA/conf/vesta.conf
if [ ! -e "/usr/sbin/setquota" ]; then
if [ -e "/etc/redhat-release" ]; then
yum -y install quota >/dev/null 2>&1
result=$?
check_result $? "quota package installation failed" $E_UPDATE
else
export DEBIAN_FRONTEND=noninteractive
apt-get -y install quota >/dev/null 2>&1
result=$?
fi
# Checking installation status
if [ "$result" -ne 0 ]; then
echo "Error: quota package wasn't successfully installed"
log_event "$E_UPDATE" "$EVENT"
exit $E_UPDATE
check_result $? "quota package installation failed" $E_UPDATE
fi
fi
@ -66,11 +59,7 @@ chmod a+x /etc/cron.daily/quotacheck
# Enabling fs quota
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
quotaon $mnt
if [ $? -ne 0 ]; then
echo "Error: quota can't be enabled on $mnt partition"
log_event "$E_DISK" "$EVENT"
exit $E_DISK
fi
check_result $? "quota can't be enabled in $mtn" $E_DISK
fi
# Updating DISK_QUOTA value

106
bin/v-add-sys-sftp-jail Executable file
View file

@ -0,0 +1,106 @@
#!/bin/bash
# info: add system sftp jail
# opions: NONE
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Importing system enviroment as we run this script
# mostly by cron wich do not read it by itself
source /etc/profile
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ -z "$SFTPJAIL_KEY" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking sshd directives
config='/etc/ssh/sshd_config'
sftp_n=$(grep -n "Subsystem.*sftp" $config |grep -v internal |grep -v ":#")
sftp_i=$(grep -n "Subsystem.*sftp" $config |grep internal |grep -v ":#")
# Disabling normal sftp
if [ ! -z "$sftp_n" ]; then
fline=$(echo $sftp_n |cut -f 1 -d :)
sed -i "${fline}s/Subsystem.*sftp/#Subsystem sftp/" $config
restart='yes'
fi
# Enabling jailed sftp
if [ -z "$sftp_i" ]; then
echo "Subsystem sftp internal-sftp" >> $config
echo "Match Group sftp-only" >> $config
echo "ChrootDirectory /chroot/%u" >> $config
echo " AllowTCPForwarding no" >> $config
echo " X11Forwarding no" >> $config
echo " ForceCommand internal-sftp" >> $config
restart='yes'
fi
# Validating opensshd config
if [ "$restart" = 'yes' ]; then
subj="OpenSSH restart failed"
email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \')
send_mail="$VESTA/web/inc/mail-wrapper.php"
/usr/sbin/sshd -t >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
mail_text="OpenSSH can not be restarted. Please check config:
\n\n$(/usr/sbin/sshd -t)"
echo -e "$mail_text" | $send_mail -s "$subj" $email
else
service ssh restart >/dev/null 2>&1
service sshd restart >/dev/null 2>&1
fi
fi
# Adding sftp group
groupadd sftp-only 2>/dev/null
# Checking users
shells="rssh|nologin"
for user in $(grep "$HOMEDIR" /etc/passwd |egrep "$shells" |cut -f 1 -d:); do
$BIN/v-add-user-sftp-jail $user
done
# Adding v-add-sys-sftp-jail to startup
if [ -e "/etc/rc.local" ]; then
check_sftp=$(grep $0 /etc/rc.local)
check_exit=$(grep ^exit /etc/rc.local)
if [ -z "$check_sftp" ]; then
if [ -z "$check_exit" ]; then
echo "$BIN/v-add-sys-sftp-jail" >> /etc/rc.local
else
sed -i "s|^exit|$BIN/v-add-sys-sftp-jail\nexit|" /etc/rc.local
fi
fi
chmod +x /etc/rc.local
else
echo "$BIN/v-add-sys-sftp-jail" > /etc/rc.local
chmod +x /etc/rc.local
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -11,7 +11,7 @@
# Argument defenition
user=$1
password=$2
password=$2; HIDE=2
email=$3
package=${4-default}
fname=$5
@ -21,10 +21,6 @@ lname=$6
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Hiding password
A2='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
is_user_free() {
check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
@ -40,12 +36,12 @@ is_user_free() {
#----------------------------------------------------------#
check_args '3' "$#" 'USER PASSWORD EMAIL [PACKAGE] [FNAME] [LNAME]'
validate_format 'user' 'password' 'email' 'package'
validate_format 'user' 'email' 'package'
if [ ! -z "$fname" ]; then
validate_format 'fname' 'lname'
fi
is_user_free "$user"
is_password_valid
is_package_valid
@ -62,11 +58,7 @@ shell=$(grep -w "$shell_conf" /etc/shells |head -n1)
# Adding user
/usr/sbin/useradd "$user" -s "$shell" -c "$email" -m -d "$HOMEDIR/$user"
if [ $? -ne 0 ]; then
echo "Error: user creation failed"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
check_result $? "user creation failed" $E_INVALID
# Adding password
echo "$user:$password" | /usr/sbin/chpasswd
@ -75,21 +67,15 @@ echo "$user:$password" | /usr/sbin/chpasswd
mkdir $HOMEDIR/$user/conf
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir $HOMEDIR/$user/conf/web
mkdir $HOMEDIR/$user/web
mkdir $HOMEDIR/$user/tmp
chmod 751 $HOMEDIR/$user/conf/web
chmod 751 $HOMEDIR/$user/web
mkdir $HOMEDIR/$user/conf/web $HOMEDIR/$user/web $HOMEDIR/$user/tmp
chmod 751 $HOMEDIR/$user/conf/web $HOMEDIR/$user/web
chmod 771 $HOMEDIR/$user/tmp
chown $user:$user $HOMEDIR/$user/web
chown $user:$user $HOMEDIR/$user/tmp
chown $user:$user $HOMEDIR/$user/web $HOMEDIR/$user/tmp
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir $HOMEDIR/$user/conf/mail
mkdir $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/conf/mail
mkdir $HOMEDIR/$user/conf/mail $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/mail $HOMEDIR/$user/conf/mail
fi
if [ ! -z "$DNS_SYSTEM" ]; then
@ -107,54 +93,47 @@ chattr +i $HOMEDIR/$user/conf
#----------------------------------------------------------#
# Adding user dir
mkdir $USER_DATA
chmod 770 $USER_DATA
mkdir -p $USER_DATA/ssl $USER_DATA/dns $USER_DATA/mail
# Creating configuration files and pipes
touch $USER_DATA/backup.conf
chmod 660 $USER_DATA/backup.conf
touch $USER_DATA/history.log
chmod 660 $USER_DATA/history.log
touch $USER_DATA/stats.log
chmod 660 $USER_DATA/stats.log
touch $USER_DATA/backup.conf \
$USER_DATA/history.log \
$USER_DATA/stats.log \
$USER_DATA/web.conf \
$USER_DATA/dns.conf \
$USER_DATA/mail.conf \
$USER_DATA/db.conf \
$USER_DATA/cron.conf
chmod 770 $USER_DATA \
$USER_DATA/ssl \
$USER_DATA/dns \
$USER_DATA/mail
chmod 660 $USER_DATA/backup.conf \
$USER_DATA/history.log \
$USER_DATA/stats.log \
$USER_DATA/web.conf \
$USER_DATA/dns.conf \
$USER_DATA/mail.conf \
$USER_DATA/db.conf \
$USER_DATA/cron.conf
# Updating queue pipes
echo "$BIN/v-update-user-disk $user" >> $VESTA/data/queue/disk.pipe
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir $USER_DATA/ssl
chmod 770 $USER_DATA/ssl
touch $USER_DATA/web.conf
chmod 660 $USER_DATA/web.conf
echo "$BIN/v-update-web-domains-traff $user" \
>> $VESTA/data/queue/traffic.pipe
echo "$BIN/v-update-web-domains-disk $user" >> $VESTA/data/queue/disk.pipe
fi
if [ ! -z "$DNS_SYSTEM" ]; then
mkdir $USER_DATA/dns
chmod 770 $USER_DATA/dns
touch $USER_DATA/dns.conf
chmod 660 $USER_DATA/dns.conf
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir $USER_DATA/mail
chmod 770 $USER_DATA/mail
touch $USER_DATA/mail.conf
chmod 660 $USER_DATA/mail.conf
echo "$BIN/v-update-mail-domains-disk $user" >> $VESTA/data/queue/disk.pipe
fi
if [ ! -z "$DB_SYSTEM" ]; then
touch $USER_DATA/db.conf
chmod 660 $USER_DATA/db.conf
echo "$BIN/v-update-databases-disk $user" >> $VESTA/data/queue/disk.pipe
fi
if [ ! -z "$CRON_SYSTEM" ]; then
touch $USER_DATA/cron.conf
chmod 660 $USER_DATA/cron.conf
fi
# Filling user config
if [ "$user" != 'admin' ]; then
@ -201,6 +180,7 @@ U_DATABASES='0'
U_CRON_JOBS='0'
U_BACKUPS='0'
LANGUAGE=''
NOTIFICATIONS='no'
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
chmod 660 $USER_DATA/user.conf
@ -220,6 +200,11 @@ if [ -x "$VESTA/data/packages/$package.sh" ]; then
$VESTA/data/packages/$package.sh "$user" "$email" "$fname" "$lname"
fi
# Adding jailed sftp env
if [ ! -z "$SFTPJAIL_KEY" ]; then
$BIN/v-add-user-sftp-jail $user
fi
# Logging
log_history "added system user $user" '' 'admin'
log_event "$OK" "$EVENT"

125
bin/v-add-user-favourites Executable file
View file

@ -0,0 +1,125 @@
#!/bin/bash
# info: adding user favourites
# options: USER SYSTEM OBJECT
#
# The function adds object to users favourites
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
system=$(echo "$2" |tr '[:lower:]' '[:upper:]')
object=$3
email=$3
id=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER SYSTEM OBJECT'
validate_format 'user' 'system'
case $system in
MAIL_ACC) validate_format 'email' ;;
CRON) validate_format 'id' ;;
DNS_REC) validate_format 'id' ;;
*) validate_format 'object'
esac
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
# Checking system
case $system in
USER) check='ok' ;;
WEB) check='ok' ;;
DNS) check='ok' ;;
DNS_REC) check='ok' ;;
MAIL) check='ok' ;;
MAIL_ACC) check='ok' ;;
DB) check='ok' ;;
CRON) check='ok' ;;
BACKUP) check='ok' ;;
IP) check='ok' ;;
PACKAGE) check='ok' ;;
FIREWALL) check='ok' ;;
*) check_args '2' '0' 'USER SYSTEM OBJECT'
esac
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Flushing vars
USER=''
WEB=''
DNS=''
DNS_REC=''
MAIL=''
MAIL_ACC=''
DB=''
CRON=''
BACKUP=''
IP=''
PACKAGE=''
FIREWALL=''
# Creating config just in case
touch $USER_DATA/favourites.conf
# Reading current values
source $USER_DATA/favourites.conf
# Assigning current system value
eval value=\$$system
# Checking if object is new
check_fav=$(echo "$value" |tr ',' '\n'| grep "^$object$")
if [ ! -z "$check_fav" ]; then
exit 0
fi
# Adding object to favorites
if [ -z "$value" ]; then
value="$object"
else
value="$value,$object"
fi
# Updating sytem
eval $system=$value
# Updating user favorites
echo "USER='$USER'
WEB='$WEB'
DNS='$DNS'
DNS_REC='$DNS_REC'
MAIL='$MAIL'
MAIL_ACC='$MAIL_ACC'
DB='$DB'
CRON='$CRON'
BACKUP='$BACKUP'
IP='$IP'
PACKAGE='$PACKAGE'
FIREWALL='$FIREWALL'" > $USER_DATA/favourites.conf
# Changing file permission
chmod 640 $USER_DATA/favourites.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "added starred $object in $system listing"
log_event "$OK" "$EVENT"
exit

71
bin/v-add-user-notification Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
# info: add user notification
# options: USER TOPIC NOTICE [TYPE]
#
# The function adds user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
topic=$(echo $2 |sed "s/'/%quote%/g")
notice=$(echo $3 |sed "s/'/%quote%/g")
type=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER TOPIC NOTICE [TYPE]'
validate_format 'user' 'topic' 'notice'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining notification id
if [ -e "$USER_DATA/notifications.conf" ]; then
nid=$(grep "NID=" $USER_DATA/notifications.conf |cut -f 2 -d \')
nid=$(echo "$nid" |sort -n |tail -n1)
if [ ! -z "$nid" ]; then
nid="$((nid +1))"
else
nid=1
fi
else
nid=1
fi
# Concatenating string
str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
str="$str ACK='no' TIME='$TIME' DATE='$DATE'"
# Adding to config
echo "$str" >> $USER_DATA/notifications.conf
# Changing permissions
chmod 660 $USER_DATA/notifications.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "yes"
fi
exit

View file

@ -29,16 +29,39 @@ is_package_new() {
is_package_consistent() {
source $pkg_dir/$package.pkg
validate_format_int $WEB_DOMAINS 'WEB_DOMAINS'
validate_format_int $WEB_ALIASES 'WEB_ALIASES'
validate_format_int $DNS_DOMAINS 'DNS_DOMAINS'
validate_format_int $DNS_RECORDS 'DNS_RECORDS'
validate_format_int $MAIL_DOMAINS 'MAIL_DOMAINS'
validate_format_int $MAIL_ACCOUNTS 'MAIL_ACCOUNTS'
validate_format_int $DATABASES 'DATABASES'
validate_format_int $CRON_JOBS 'CRON_JOBS'
validate_format_int $DISK_QUOTA 'DISK_QUOTA'
validate_format_int $BACKUPS 'BACKUPS'
if [ "$WEB_DOMAINS" != 'unlimited' ]; then
validate_format_int $WEB_DOMAINS 'WEB_DOMAINS'
fi
if [ "$WEB_ALIASES" != 'unlimited' ]; then
validate_format_int $WEB_ALIASES 'WEB_ALIASES'
fi
if [ "$DNS_DOMAINS" != 'unlimited' ]; then
validate_format_int $DNS_DOMAINS 'DNS_DOMAINS'
fi
if [ "$DNS_RECORDS" != 'unlimited' ]; then
validate_format_int $DNS_RECORDS 'DNS_RECORDS'
fi
if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
validate_format_int $MAIL_DOMAINS 'MAIL_DOMAINS'
fi
if [ "$MAIL_ACCOUNTS" != 'unlimited' ]; then
validate_format_int $MAIL_ACCOUNTS 'MAIL_ACCOUNTS'
fi
if [ "$DATABASES" != 'unlimited' ]; then
validate_format_int $DATABASES 'DATABASES'
fi
if [ "$CRON_JOBS" != 'unlimited' ]; then
validate_format_int $CRON_JOBS 'CRON_JOBS'
fi
if [ "$DISK_QUOTA" != 'unlimited' ]; then
validate_format_int $DISK_QUOTA 'DISK_QUOTA'
fi
if [ "$BANDWIDTH" != 'unlimited' ]; then
validate_format_int $BANDWIDTH 'BANDWIDTH'
fi
if [ "$BACKUPS" != 'unlimited' ]; then
validate_format_int $BACKUPS 'BACKUPS'
fi
validate_format_shell $SHELL
}

66
bin/v-add-user-sftp-jail Executable file
View file

@ -0,0 +1,66 @@
#!/bin/bash
# info: add user sftp jail
# opions: USER
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
validate_format 'user'
if [ -z "$SFTPJAIL_KEY" ]; then
exit
fi
user_str=$(grep "^$user:" /etc/passwd |egrep "rssh|nologin")
if [ -z "$user_str" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining user homedir
home="$(echo $user_str |cut -f 6 -d :)"
# Adding chroot directory
if [ ! -d "/chroot/$user/$home" ]; then
mkdir -p /chroot/$user/$home
chmod 750 /chroot/$user
chmod 775 /chroot/$user/$home
chown root:sftp-only /chroot/$user
chown $user:sftp-only /chroot/$user/$home
fi
# Adding user to sftp group
usermod -a -G sftp-only $user
# Mouting home directory
if [ -z "$(mount |grep $home)" ]; then
mount -o bind $home /chroot/$user/$home/
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
#log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add web domain
# options: USER DOMAIN IP [RESTART]
# options: USER DOMAIN IP [RESTART] [ALIASES] [PROXY_EXTENTIONS]
#
# The function adds virtual host to a server. In cases when a template is
# undefined in the script, the template "default" will be used. The alias of
@ -20,8 +20,12 @@ domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g')
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
ip=$3
ip=$3; IP=$3
restart=$4
aliases=$5
default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
extentions=${6-$default_extentions}
# Includes
source $VESTA/func/main.sh
@ -34,7 +38,7 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
check_args '3' "$#" 'USER DOMAIN IP [RESTART] [ALIASES] [PROXY_EXTENTIONS]'
validate_format 'user' 'domain' 'ip'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
@ -43,43 +47,60 @@ is_domain_new 'web'
is_ip_valid
is_ip_avalable
is_package_full 'WEB_DOMAINS'
template=$(get_user_value '$WEB_TEMPLATE')
is_web_template_valid
if [ ! -z "$aliases" ]; then
for domain_alias in $(echo "${aliases//,/ }"); do
is_domain_new 'web' "$domain_alias" 'alias'
done
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
validate_format 'extentions'
proxy=$(get_user_value '$PROXY_TEMPLATE')
is_proxy_template_valid $proxy
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Define real ip in case of NAT
IP=$ip
ip=$(get_real_ip $ip)
# Defining domain aliases
ip_name=$(get_ip_name)
ip_name_idn=$(idn -t --quiet -a "$ip_name")
domain_alias="www.$domain"
domain_alias_idn="www.$domain_idn"
if [ ! -z "$ip_name" ]; then
domain_alias_dash="${domain//./-}.$ip_name"
domain_alias_dash_idn="${domain_idn//./-}.$ip_name_idn"
aliases="$domain_alias,$domain_alias_dash"
aliases_idn="$domain_alias_idn,$domain_alias_dash_idn"
alias_string="ServerAlias $domain_alias_idn $domain_alias_dash_idn"
else
aliases="$domain_alias"
aliases_idn="$domain_alias_idn"
alias_string="ServerAlias $domain_alias_idn"
# Checking domain backend in case PHP-FPM is configured
if [ ! -z "$WEB_BACKEND" ]; then
is_web_backend_pool_valid
$BIN/v-add-web-domain-backend $user $domain
rc=$?
if [ $rc -ne 0 ]; then
exit $rc
fi
get_domain_backend_values
backend=$(get_user_value '$BACKEND_TEMPLATE')
fi
# Defining vars for add_config function
# Defining variables for add_config function
ip=$(get_real_ip $ip)
group="$user"
email="info@$domain"
docroot="$HOMEDIR/$user/web/$domain/public_html"
tpl_file="$WEBTPL/$WEB_SYSTEM/$template.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
# Defining domain aliases
ip_name=$(get_ip_name)
if [ -z "$aliases" ]; then
if [ -z "$ip_name" ]; then
aliases="www.$domain"
else
aliases="www.$domain,${domain//./-}.$ip_name"
fi
else
if [ ! -z "$ip_name" ]; then
aliases="$aliases,${domain//./-}.$ip_name"
fi
fi
aliases_idn=$(idn -t --quiet -a $aliases)
alias_string="ServerAlias ${aliases_idn//,/ }"
# Adding web config
add_web_config
@ -123,34 +144,54 @@ done
# Changing file owner
chown -R $user:$user $HOMEDIR/$user/web/$domain
chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.*
chown root:$user $conf
chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.* $conf
# Changing file permissions
chmod 640 $conf
chmod 640 $conf /var/log/$WEB_SYSTEM/domains/$domain.*
chmod 551 $HOMEDIR/$user/web/$domain
chmod 751 $HOMEDIR/$user/web/$domain/private
chmod 751 $HOMEDIR/$user/web/$domain/cgi-bin
chmod 751 $HOMEDIR/$user/web/$domain/public_html
chmod 751 $HOMEDIR/$user/web/$domain/public_shtml
chmod 751 $HOMEDIR/$user/web/$domain/document_errors
chmod -f -R 665 $HOMEDIR/$user/web/$domain/cgi-bin/*
chmod -f -R 665 $HOMEDIR/$user/web/$domain/public_html/*
chmod -f -R 665 $HOMEDIR/$user/web/$domain/document_errors/*
chmod 551 $HOMEDIR/$user/web/$domain/stats
chmod 551 $HOMEDIR/$user/web/$domain/logs
chmod 640 /var/log/$WEB_SYSTEM/domains/$domain.*
chmod 751 $HOMEDIR/$user/web/$domain/private \
$HOMEDIR/$user/web/$domain/cgi-bin \
$HOMEDIR/$user/web/$domain/public_html \
$HOMEDIR/$user/web/$domain/public_shtml \
$HOMEDIR/$user/web/$domain/document_errors
chmod -f -R 665 $HOMEDIR/$user/web/$domain/cgi-bin/* \
$HOMEDIR/$user/web/$domain/public_html/* \
$HOMEDIR/$user/web/$domain/document_errors/* \
chmod 551 $HOMEDIR/$user/web/$domain/stats \
$HOMEDIR/$user/web/$domain/logs
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
$user $domain $ip $HOMEDIR $docroot
fi
# Checking web config
# Checking web config include
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep $conf $web_conf)" ]; then
web_include=$(grep "$conf" $web_conf )
if [ -z "$web_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then
echo "Include $conf" >> $web_conf
fi
if [ -z "$web_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then
echo "include $conf;" >> $web_conf
fi
# Checking proxy system
if [ ! -z "$PROXY_SYSTEM" ]; then
PROXY_EXT="$extentions"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$proxy.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
add_web_config
chown root:$user $conf
chmod 640 $conf
proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep "$conf" $proxy_conf)" ]; then
echo "include $conf;" >> $proxy_conf
fi
if [ -x $WEBTPL/$PROXY_SYSTEM/$proxy.sh ]; then
$WEBTPL/$PROXY_SYSTEM/$proxy.sh $user $domain $ip $HOMEDIR $docroot
fi
fi
#----------------------------------------------------------#
@ -164,20 +205,22 @@ increase_user_value "$user" '$U_WEB_ALIASES'
# Defining domain variables
str="DOMAIN='$domain' IP='$IP' IP6='' ALIAS='$aliases' TPL='$template'"
str="$str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5=''"
str="$str PROXY='' PROXY_EXT='' STATS='' STATS_USER=''"
str="$str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5='' BACKEND='$backend'"
str="$str PROXY='$proxy' PROXY_EXT='$extentions' STATS='' STATS_USER=''"
str="$str STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
str="$str TIME='$TIME' DATE='$DATE'"
# Registering domain
echo "$str" >> $USER_DATA/web.conf
chmod 660 $USER_DATA/web.conf
# Restart web server
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
check_result $? "Web restart failed" >/dev/null
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

View file

@ -39,7 +39,7 @@ is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_domain_new 'web' "$dom_alias"
is_domain_new 'web' "$dom_alias" 'alias'
is_package_full 'WEB_ALIASES'
@ -49,7 +49,7 @@ is_package_full 'WEB_ALIASES'
# Parsing domain values
get_domain_values 'web'
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
ip=$(get_real_ip $IP)
@ -68,14 +68,14 @@ del_web_config
add_web_config
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
add_web_config
fi
# Checking proxy
if [ ! -z "$PROXY" ]; then
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
del_web_config
@ -100,16 +100,14 @@ update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
# Update counters
increase_user_value "$user" '$U_WEB_ALIASES'
# Adding task to the vesta pipe
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

77
bin/v-add-web-domain-backend Executable file
View file

@ -0,0 +1,77 @@
#!/bin/bash
# info: add web domain backend
# options: USER DOMAIN [TEMPLATE] [RESTART]
#
# The call is used for adding web backend configuration for user
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$2
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [RESTART]'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
is_object_unsuspended 'user' 'USER' "$user"
is_web_backend_template_valid $template
is_web_backend_pool_valid
if [ -e "$pool/$backend.conf" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Allocating backend port
backend_port=9000
ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
ports=$(echo "$ports" |sed "s/://" |sort -n)
for port in $ports; do
if [ "$backend_port" -eq "$port" ]; then
backend_port=$((backend_port + 1))
fi
done
# Adding backend config
cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
sed -e "s|%backend_port%|$backend_port|" \
-e "s|%user%|$user|"\
-e "s|%domain%|$domain|"\
-e "s|%domain_idn%|$domain_idn|"\
-e "s|%backend%|$backend|g" > $pool/$backend.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restart backend server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web-backend
check_result $? "Web backend restart failed" >/dev/null
fi
# Logging
log_history "added $WEB_BACKEND backend configuration for $domain"
log_event "$OK" "$EVENT"
exit

View file

@ -14,7 +14,7 @@ user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ftp_user=${1}_${3}
ftp_password=$4
password=$4; HIDE=4
ftp_path=$5
# Includes
@ -22,17 +22,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN FTP_USER FTP_PASSWORD [FTP_PATH]'
validate_format 'user' 'domain' 'ftp_user' 'ftp_password'
validate_format 'user' 'domain' 'ftp_user'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -44,6 +40,7 @@ if [ ! -z "$check_ftp_user" ] && [ "$FTP_USER" != "$ftp_user" ]; then
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
is_password_valid
#----------------------------------------------------------#
@ -90,9 +87,14 @@ fi
-M -d "$ftp_path_a" > /dev/null 2>&1
# Set ftp user password
echo "$ftp_user:$ftp_password" | /usr/sbin/chpasswd
echo "$ftp_user:$password" | /usr/sbin/chpasswd
ftp_md5=$(awk -v user=$ftp_user -F : 'user == $1 {print $2}' /etc/shadow)
# Adding jailed sftp env
if [ ! -z "$SFTPJAIL_KEY" ]; then
$BIN/v-add-user-sftp-jail $ftp_user
fi
#----------------------------------------------------------#
# Vesta #

105
bin/v-add-web-domain-httpauth Executable file
View file

@ -0,0 +1,105 @@
#!/bin/bash
# info: add password protection for web domain
# options: USER DOMAIN AUTH_USER AUTH_PASSWORD [RESTART]
#
# The call is used for securing web domain with http auth
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$2
auth_user=$3
password=$4; HIDE=4
restart=${5-yes}
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Definining htpasswd file
htaccess="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf_htaccess"
htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
docroot="$HOMEDIR/$user/web/$domain/public_html"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN AUTH_USER AUTH_PASSWORD [RESTART]'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_password_valid
get_domain_values 'web'
if [ ! -z "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
echo "Error: auth user $auth_user already exists"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Adding htaccess password protection
if [ ! -e "$htaccess" ]; then
if [ "$WEB_SYSTEM" != 'nginx' ]; then
echo "<Directory $docroot>" > $htaccess
echo " AuthUserFile $htpasswd" >> $htaccess
echo " AuthName \"$domain access\"" >> $htaccess
echo " AuthType Basic" >> $htaccess
echo " Require valid-user" >> $htaccess
echo "</Directory>" >> $htaccess
else
echo "auth_basic \"$domain password access\";" > $htaccess
echo "auth_basic_user_file $htpasswd;" >> $htaccess
fi
restart_required='yes'
fi
# Adding httpasswd user
auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
touch $htpasswd
chmod 640 $htpasswd $htaccess
sed -i "/^$auth_user:/d" $htpasswd
echo "$auth_user:$auth_hash" >> $htpasswd
# Restarting web server
if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
$BIN/v-restart-web
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Preparing web.conf keys
if [ ! -z "$AUTH_USER" ]; then
auth_user="$AUTH_USER:$auth_user"
auth_hash="$AUTH_HASH:$auth_hash"
else
# Adding new key into web.conf
add_object_key "web" 'DOMAIN' "$domain" 'AUTH_USER' 'U_DISK'
add_object_key "web" 'DOMAIN' "$domain" 'AUTH_HASH' 'U_DISK'
fi
# Updating config
update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_USER' "$auth_user"
update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_HASH' "$auth_hash"
# Logging
log_history "added http auth user $httpauth_user on $domain"
log_event "$OK" "$EVENT"
exit

View file

@ -42,7 +42,7 @@ is_object_value_empty 'web' 'DOMAIN' "$domain" '$PROXY'
if [ -z $template ]; then
template=$(get_user_value '$PROXY_TEMPLATE')
fi
is_proxy_template_valid
is_proxy_template_valid $template
#----------------------------------------------------------#
@ -100,12 +100,10 @@ fi
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
# Restart web server
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Proxy restart failed" >/dev/null
fi
log_history "enabled proxy support for $domain"

View file

@ -63,7 +63,7 @@ chmod 660 $USER_DATA/ssl/$domain.*
# Parsing domain values
get_domain_values 'web'
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
SSL_HOME="$ssl_home"
ip=$(get_real_ip $IP)
@ -85,8 +85,9 @@ if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
fi
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $sdocroot
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
$user $domain $ip $HOMEDIR $sdocroot
fi
# Checking web config
@ -96,7 +97,7 @@ if [ -z "$(grep "$conf" $web_conf)" ]; then
fi
# Checking proxy
if [ ! -z "$PROXY" ]; then
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
add_web_config
@ -123,16 +124,14 @@ increase_user_value "$user" '$U_WEB_SSL'
update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME"
update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes"
# Restart web server
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

View file

@ -13,29 +13,26 @@
user=$1
domain=$(idn -t --quiet -u "$2" )
stats_user=$3
stats_pass=$4
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN STATS_USER STATS_PASS'
validate_format 'user' 'domain' 'stats_user' 'stats_pass'
validate_format 'user' 'domain' 'stats_user'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_password_valid
#----------------------------------------------------------#
@ -53,7 +50,7 @@ Require valid-user" > $stats_dir/.htaccess
# Generating htaccess user and password
rm -f $stats_dir/.htpasswd
htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$password" &>/dev/null
stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
#----------------------------------------------------------#

View file

@ -54,12 +54,11 @@ if [ "$notify" != 'no' ]; then
email=$(get_user_value '$CONTACT')
else
subj="$user → backup failed"
email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \')
fi
send_mail="$VESTA/web/inc/mail-wrapper.php"
# Check load average
la=$(cat /proc/loadavg | cut -f 1 -d ' ' | cut -f 1 -d '.')
la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.')
i=0
while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do
echo "$(date "+%F %T") LoadAverage $la is above threshold. Sleeping..."
@ -67,20 +66,20 @@ while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do
if [ "$i" -ge "5" ]; then
mail_top=$(top -b| head -n 30)
mail_text="LoadAverage $i is above threshold\n\n$mail_top\n"
echo -e "$mail_text" | $send_mail -s "$subj" $email
echo -e "$mail_text" |$send_mail -s "$subj" $email
echo "Error: LA is too high"
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
log_event "$E_LA" "$EVENT"
exit $E_LA
fi
la=$(cat /proc/loadavg | cut -f 1 -d ' ' | cut -f 1 -d '.')
la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.')
(( ++i))
done
# Creating temporary directory
tmpdir=$(mktemp -p $BACKUP -d)
if [ "$?" -ne 0 ]; then
echo "Can't create tmp dir $tmpdir" | $send_mail -s "$subj" $email
echo "Can't create tmp dir $tmpdir" |$send_mail -s "$subj" $email
echo "Error: can't create tmp dir"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
@ -137,15 +136,15 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then
# Parsing domain exclusions
conf="$USER_DATA/web.conf"
for domain in $(search_objects 'web' 'SUSPENDED' "*" 'DOMAIN'); do
check_exl=$(echo -e "${WEB//,/\n}" |grep "^$domain$")
if [ -z "$check_exl" ]; then
exclusion=$(echo -e "$WEB" |tr ',' '\n' |grep "^$domain$")
if [ -z "$exclusion" ]; then
web_list="$web_list $domain"
else
echo "$(date "+%F %T") excluding $domain"
msg="$msg\n$(date "+%F %T") excluding $domain"
fi
done
web_list=$(echo "$web_list" | sed -e "s/ */\ /g" -e "s/^ //")
web_list=$(echo "$web_list" |sed -e "s/ */\ /g" -e "s/^ //")
i=0
@ -166,14 +165,14 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then
grep "DOMAIN='$domain'" $conf > vesta/web.conf
# Backup vhost config
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/$WEB_SYSTEM.conf
# Backup ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/s$WEB_SYSTEM.conf
@ -207,36 +206,26 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then
fi
# Define exclude arguments
exlusion=$(echo -e "$WEB" |tr ',' '\n' |grep "^$domain:")
set -f
fargs=()
fargs+=(-not)
fargs+=(-path)
fargs+=("./logs*")
check_exlusion=$(echo -e "${WEB//,/\n}" | grep "^$domain:")
if [ ! -z "$check_exlusion" ]; then
xdirs="$(echo -e "${check_exlusion//:/\n}" |grep -v $domain)"
fargs+=(--exclude='logs/*')
if [ ! -z "$exlusion" ]; then
xdirs="$(echo -e "$exlusion" |tr ':' '\n' |grep -v $domain)"
for xpath in $xdirs; do
xpath="$(echo $xpath | sed -e 's/\/*$//' -e 's/^\/*//')"
fargs+=(-not)
fargs+=(-path)
fargs+=("./$xpath/*")
fargs+=(--exclude=$xpath/*)
echo "$(date "+%F %T") excluding directory $xpath"
msg="$msg\n$(date "+%F %T") excluding directory $xpath"
done
fi
set +f
# Backup files
cd $HOMEDIR/$user/web/$domain
find . ${fargs[@]} -type f -print0 |\
tar -cpf $tmpdir/web/$domain/domain_data.tar --null -T -
# Backup empty folders
find . ${fargs[@]} -type d -empty -print0 |\
tar -rpf $tmpdir/web/$domain/domain_data.tar --null -T -
tar -cpf $tmpdir/web/$domain/domain_data.tar * ${fargs[@]}
# Compress archive
gzip -$BACKUP_GZIP $tmpdir/web/$domain/domain_data.tar
set +f
done
# Print total
@ -259,15 +248,15 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then
# Parsing domain exclusions
for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
check_exl=$(echo -e "${DNS//,/\n}" |grep "^$domain$")
if [ -z "$check_exl" ]; then
exclusion=$(echo "$DNS" |tr ',' '\n' |grep "^$domain$")
if [ -z "$exclusion" ]; then
dns_list="$dns_list $domain"
else
echo "$(date "+%F %T") excluding $domain"
msg="$msg\n$(date "+%F %T") excluding $domain"
fi
done
dns_list=$(echo "$dns_list" | sed -e "s/ */\ /g" -e "s/^ //")
dns_list=$(echo "$dns_list" |sed -e "s/ */\ /g" -e "s/^ //")
i=0
for domain in $dns_list; do
@ -312,7 +301,7 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then
# Parsing domain exclusions
conf="$USER_DATA/mail.conf"
for domain in $(search_objects 'mail' 'SUSPENDED' "*" 'DOMAIN'); do
check_exl=$(echo -e "${MAIL//,/\n}" |grep "^$domain$")
check_exl=$(echo "$MAIL" |tr ',' '\n' |grep "^$domain$")
if [ -z "$check_exl" ]; then
mail_list="$mail_list $domain"
else
@ -320,7 +309,7 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then
msg="$msg\n$(date "+%F %T") excluding $domain"
fi
done
mail_list=$(echo "$mail_list" | sed -e "s/ */\ /g" -e "s/^ //")
mail_list=$(echo "$mail_list" |sed -e "s/ */\ /g" -e "s/^ //")
i=0
for domain in $mail_list; do
@ -348,8 +337,8 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then
# Backup emails
cd $HOMEDIR/$user/mail/$domain_idn
for account in $(ls); do
exclusion=$(echo -e "${MAIL//,/\n}" |grep "$domain:")
exclusion=$(echo -e "${exclusion//:/\n}" |grep "^$account$")
exclusion=$(echo "$MAIL" |tr ',' '\n' |grep "$domain:")
exclusion=$(echo "$exclusion" |tr ':' '\n' |grep "^$account$")
# Checking exlusions
if [ -z "$exclusion" ] && [[ "$MAIL_SYSTEM" =~ exim ]]; then
@ -390,8 +379,8 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then
# Parsing database exclusions
for database in $(search_objects 'db' 'SUSPENDED' "*" 'DB'); do
check_exl=$(echo -e "${DB//,/\n}" |grep "^$database$")
if [ -z "$check_exl" ]; then
exclusion=$(echo "$DB" |tr ',' '\n' |grep "^$database$")
if [ -z "$exclusion" ]; then
db_list="$db_list $database"
else
echo "$(date "+%F %T") excluding $database"
@ -401,7 +390,7 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then
i=0
conf="$USER_DATA/db.conf"
db_list=$(echo "$db_list" | sed -e "s/ */\ /g" -e "s/^ //")
db_list=$(echo "$db_list" |sed -e "s/ */\ /g" -e "s/^ //")
for database in $db_list; do
((i ++))
get_database_values
@ -477,9 +466,8 @@ if [ "$USER" != '*' ]; then
if [ -e "$USER_DATA/backup-excludes.conf" ]; then
source $USER_DATA/backup-excludes.conf
fi
exlusion_list=$(echo -e "${USER//,/\n}")
fargs=()
for xpath in $exlusion_list; do
for xpath in $(echo "$USER" |tr ',' '\n'); do
fargs+=(-not)
fargs+=(-path)
fargs+=("./$xpath*")
@ -490,28 +478,24 @@ if [ "$USER" != '*' ]; then
IFS=$'\n'
set -f
i=0
for udir in $(ls |egrep -v "conf|web|dns|mail"); do
check_exl=$(echo -e "${USER//,/\n}" |grep "^$udir$")
if [ -z "$check_exl" ]; then
for udir in $(ls -a |egrep -v "conf|web|dns|mail|^\.\.$|^\.$"); do
exclusion=$(echo "$USER" |tr ',' '\n' |grep "^$udir$")
if [ -z "$exclusion" ]; then
((i ++))
udir_list="$udir_list $udir"
echo -e "$(date "+%F %T") adding directory $udir"
msg="$msg\n$(date "+%F %T") adding directory $udir"
echo -e "$(date "+%F %T") adding $udir"
msg="$msg\n$(date "+%F %T") adding $udir"
# Backup files
find ./$udir ${fargs[@]} -type f -print0 |\
tar -cpf $tmpdir/user_dir/$udir.tar --null -T -
# Backup empty folders
find ./$udir ${fargs[@]} -type d -empty -print0 |\
tar -rpf $tmpdir/user_dir/$udir.tar --null -T -
# Backup files and dirs
tar -cpf $tmpdir/user_dir/$udir.tar $udir
# Compress arhive
gzip -$BACKUP_GZIP $tmpdir/user_dir/$udir.tar
fi
done
set +f
udir_list=$(echo "$udir_list" | sed -e "s/ */\ /g" -e "s/^ //")
udir_list=$(echo "$udir_list" |sed -e "s/ */\ /g" -e "s/^ //")
# Print total
if [ "$i" -eq 1 ]; then
@ -526,7 +510,7 @@ if [ "$USER" != '*' ]; then
fi
# Get backup size
size="$(du -shm $tmpdir | cut -f 1)"
size="$(du -shm $tmpdir |cut -f 1)"
# Get current time
end_time=$(date '+%s')
@ -536,23 +520,19 @@ TIME=$(date +%T)
# Defining local storage function
local_backup(){
# Removing dublicate for this day
if [ -e "$BACKUP/$user.$DATE.tar" ]; then
deprecated="$DATE"
rm -f $BACKUP/$user.$DATE.tar
fi
rm -f $BACKUP/$user.$DATE.tar
# Checking retention
backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' |grep "^$user\.")
backups_count=$(echo "$backup_list" | wc -l)
backup_list=$(ls -lrt $BACKUP/ |awk '{print $9}' |grep "^$user\.")
backups_count=$(echo "$backup_list" |wc -l)
if [ "$BACKUPS" -le "$backups_count" ]; then
backups_rm_number=$((backups_count - BACKUPS))
(( ++backups_rm_number))
for backup in $(echo "$backup_list" | head -n $backups_rm_number); do
# Removing old backup
backup_date=$(echo $backup | sed -e "s/$user.//" -e "s/.tar$//")
deprecated="$deprecated $backup_date"
# Removing old backup
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//")
echo -e "$(date "+%F %T") Roated: $backup_date"
msg="$msg\n$(date "+%F %T") Rotated: $backup_date"
rm -f $BACKUP/$backup
@ -580,7 +560,7 @@ local_backup(){
localbackup='yes'
echo -e "$(date "+%F %T") Local: $BACKUP/$user.$DATE.tar"
msg="$msg\n$(date "+%F %T") Local: $BACKUP/$user.$DATE.tar"
U_BACKUPS=$(ls $BACKUP/ | grep "^$user." | wc -l)
U_BACKUPS=$(ls $BACKUP/ |grep "^$user." |wc -l)
update_user_value "$user" '$U_BACKUPS' "$U_BACKUPS"
}
@ -603,7 +583,7 @@ ftp_backup() {
# Checking config
if [ ! -e "$VESTA/conf/ftp.backup.conf" ]; then
ftp_conf_error="Can't open $VESTA/conf/ftp.backup.conf"
echo "$ftp_conf_error" | $send_mail -s "$subj" $email
echo "$ftp_conf_error" |$send_mail -s "$subj" $email
echo "Error: $VESTA/conf/ftp.backup.conf doesn't exist"
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
log_event "$E_NOTEXIST" "$EVENT"
@ -667,12 +647,11 @@ ftp_backup() {
# Checking retention
backup_list=$(ftpc "cd $BPATH" "ls" |awk '{print $9}' |grep "^$user\.")
backups_count=$(echo "$backup_list" | wc -l)
backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS + 1))
for backup in $(echo "$backup_list" | head -n $backups_rm_number); do
backup_date=$(echo $backup | sed -e "s/$user.//" -e "s/.tar$//")
deprecated="$deprecated $backup"
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//")
echo -e "$(date "+%F %T") Roated ftp backup: $backup_date"
msg="$msg\n$(date "+%F %T") Roated ftp backup: $backup_date"
ftpc "cd $BPATH" "delete $backup"
@ -692,6 +671,147 @@ ftp_backup() {
fi
}
# sftp command function
sftpc() {
expect -f "-" <<EOF "$@"
set timeout 60
set count 0
spawn /usr/bin/sftp -o StrictHostKeyChecking=no \
-o Port=$PORT $USERNAME@$HOST
expect {
"password:" {
send "$PASSWORD\r"
exp_continue
}
-re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
set count \$argc
set output "Disconnected."
set rc $E_FTP
exp_continue
}
-re ".*denied.*(publickey|password)." {
set output "Permission denied, wrong publickey or password."
set rc $E_CONNECT
}
-re "\[0-9]*%" {
exp_continue
}
"sftp>" {
if {\$count < \$argc} {
set arg [lindex \$argv \$count]
send "\$arg\r"
incr count
} else {
send "exit\r"
set output "Disconnected."
if {[info exists rc] != 1} {
set rc $OK
}
}
exp_continue
}
timeout {
set output "Connection timeout."
set rc $E_CONNECT
}
}
if {[info exists output] == 1} {
puts "\$output"
}
exit \$rc
EOF
}
sftp_backup() {
# Checking config
if [ ! -e "$VESTA/conf/sftp.backup.conf" ]; then
sftp_conf_error="Can't open $VESTA/conf/sftp.backup.conf"
echo "$sftp_conf_error" |$send_mail -s "$subj" $email
echo "Error: $VESTA/conf/sftp.backup.conf doesn't exist"
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
# Parse config
source $VESTA/conf/sftp.backup.conf
# Set current data
DATE=$(date +%F)
TIME=$(date +%T)
# Set default port
if [ -z "$(grep 'PORT=' $VESTA/conf/sftp.backup.conf)" ]; then
PORT='22'
fi
# Checking variables
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
rm -rf $tmpdir
echo "Can't parse sftp backup configuration" |\
$send_mail -s "$subj" $email
echo "Error: Parsing error"
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
log_event "$E_PARSING" "$EVENT"
exit $E_PARSING
fi
# Debug info
echo -e "$(date "+%F %T") Remote: sftp://$HOST/$BPATH/$user.$DATE.tar"
# Checking network connection and write permissions
sftmpdir="$BPATH/vst.bK76A9SUkt"
sftpc "mkdir $BPATH" > /dev/null 2>&1
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
rc=$?
if [[ "$rc" != 0 ]]; then
rm -rf $tmpdir
case $rc in
$E_CONNECT) echo "Error: can't login to sftp host $HOST" |\
$send_mail -s "$subj" $email;;
$E_FTP) echo "Error: can't create temp folder on sftp $HOST" |\
$send_mail -s "$subj" $email;;
esac
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
log_event "$rc" "$EVENT"
exit "$rc"
fi
# Checking retention
backup_list=$(sftpc "cd $BPATH" "ls -l" |awk '{print $9}' |grep "^$user\.")
backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS + 1))
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar.*$//")
echo -e "$(date "+%F %T") Roated sftp backup: $backup_date"
msg="$msg\n$(date "+%F %T") Roated sftp backup: $backup_date"
sftpc "cd $BPATH" "rm $backup" > /dev/null 2>&1
done
fi
# Uploading backup archive
echo -e "$(date "+%F %T") Uploading $user.$DATE.tar ..."
if [ "$localbackup" = 'yes' ]; then
cd $BACKUP
sftpc "cd $BPATH" "put $user.$DATE.tar" > /dev/null 2>&1
else
cd $tmpdir
tar -cf $BACKUP/$user.$DATE.tar .
cd $BACKUP/
sftpc "cd $BPATH" "put $user.$DATE.tar" > /dev/null 2>&1
rm -f $user.$DATE.tar
fi
}
echo "-- SUMMARY --"
msg="$msg\n-- SUMMARY --"
@ -700,11 +820,11 @@ for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
case $backup_type in
local) local_backup ;;
ftp) ftp_backup ;;
sftp) sftp_backup ;;
esac
done
# Removing tmpdir
cd /
rm -rf $tmpdir
# Calculation run time
@ -729,14 +849,11 @@ msg="$msg\n$(date "+%F %T") Runtime: $run_time $min"
# Vesta #
#----------------------------------------------------------#
# Deleting old backup records
for backup_record in $deprecated; do
if [ -e "$USER_DATA/backup.conf" ]; then
sed -i "/DATE='$backup_record/d" $USER_DATA/backup.conf
fi
done
# Removing duplicate
touch $USER_DATA/backup.conf
sed -i "/$user.$DATE.tar/d" $USER_DATA/backup.conf
# Concatenating string
# Regestering new backup
backup_str="BACKUP='$user.$DATE.tar'"
backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
backup_str="$backup_str WEB='${web_list// /,}'"
@ -747,16 +864,20 @@ backup_str="$backup_str CRON='$cron_list'"
backup_str="$backup_str UDIR='${udir_list// /,}'"
backup_str="$backup_str RUNTIME='$run_time' TIME='$TIME' DATE='$DATE'"
echo "$backup_str" >> $USER_DATA/backup.conf
# Removing old backups
tail -n $BACKUPS $USER_DATA/backup.conf > $USER_DATA/backup.conf_
mv -f $USER_DATA/backup.conf_ $USER_DATA/backup.conf
chmod 660 $USER_DATA/backup.conf
# Clean backup queue
# Deleting task from queue
sed -i "/v-backup-user $user /d" $VESTA/data/queue/backup.pipe
# Send notification
if [ "$notify" != 'no' ]; then
subj="$user → backup has been completed"
email=$(get_user_value '$CONTACT')
echo -e "$msg" | $send_mail -s "$subj" $email
echo -e "$msg" |$send_mail -s "$subj" $email
fi
# Logging

View file

@ -22,6 +22,9 @@ source $VESTA/conf/vesta.conf
# Action #
#----------------------------------------------------------#
if [ -z "$BACKUP_SYSTEM" ]; then
exit
fi
for user in $(ls $VESTA/data/users); do
check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
log=$VESTA/log/backup.log

View file

@ -64,11 +64,9 @@ sync_cron_jobs
# Vesta #
#----------------------------------------------------------#
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_history "changed cron job $job"

View file

@ -0,0 +1,64 @@
#!/bin/bash
# info: change database server password
# options: TYPE HOST USER PASSWORD
#
# The function changes database server password.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
host=$2
dbuser=$3
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
args_usage='TYPE HOST DBUSER DBPASS'
check_args '4' "$#" "$args_usage"
validate_format 'host' 'dbuser'
is_object_valid "../../conf/$type" 'HOST' "$host"
dbpass="$password"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Define email
email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f2 -d \')
subj="v-change-database-host-password $*"
case $type in
mysql) mysql_connect $host;
query="USE mysql; UPDATE user SET"
query="$query password=PASSWORD('$dbpass')"
query="$query WHERE User='$dbuser';"
query="$query FLUSH PRIVILEGES;"
mysql_query "$query" ;;
pgsql) echo "TBD" >/dev/null;;
esac
update_object_value "../../conf/$type" 'HOST' "$host" '$USER' "$dbuser"
update_object_value "../../conf/$type" 'HOST' "$host" '$PASSWORD' "$dbpass"
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: change database password
# info: change database owner
# options: DATABASE USER
#
# The function for changing database owner.

View file

@ -13,30 +13,27 @@
# Argument defenition
user=$1
database=$2
dbpass=$3
password=$3; HIDE=3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf
# Hiding password
A3='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DATABASE DBPASS'
validate_format 'user' 'database' 'dbpass'
validate_format 'user' 'database'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
is_password_valid
dbpass="$password"
#----------------------------------------------------------#
# Action #

View file

@ -13,7 +13,7 @@
user=$1
database=$2
dbuser="$user"_"$3"
dbpass=$4
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
@ -21,10 +21,6 @@ source $VESTA/func/db.sh
source $VESTA/func/rebuild.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
@ -32,14 +28,18 @@ EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
check_args '3' "$#" 'USER DATABASE DBUSER [DBPASS]'
validate_format 'user' 'database' 'dbuser'
if [ ! -z "$dbpass" ]; then
validate_format 'dbpass'
fi
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
is_password_valid
dbpass="$password"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Compare old and new user
old_dbuser=$(get_object_value 'db' 'DB' "$database" '$DBUSER')
@ -47,11 +47,6 @@ if [ "$old_dbuser" = "$dbuser" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Set new dbuser
update_object_value 'db' 'DB' "$database" '$DBUSER' "$dbuser"

View file

@ -51,6 +51,7 @@ sed -i "s/$old/$ip/g" $USER_DATA/dns/$domain.conf
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -59,7 +60,7 @@ if [ ! -z "$DNS_CLUSTER" ]; then
# Check for first sync
dlock=$(grep "domain $user $domain" $VESTA/data/queue/dns-cluster.pipe)
if [ -z "$dlock" ]; then
cmd="$BIN/v-add-remote-dns-domain $user $domain domain"
cmd="$BIN/v-add-remote-dns-domain $user $domain domain yes"
echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
fi
fi
@ -69,12 +70,10 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

View file

@ -45,6 +45,7 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$SOA' "$soa"
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -63,12 +64,10 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

View file

@ -67,6 +67,7 @@ records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -89,12 +90,10 @@ fi
update_object_value 'dns' 'DOMAIN' "$domain" '$TPL' "$template"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

View file

@ -44,6 +44,7 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$TTL' "$ttl"
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -62,12 +63,10 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

View file

@ -77,6 +77,7 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -95,12 +96,10 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

View file

@ -51,6 +51,7 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -69,12 +70,10 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "DNS restart failed" >/dev/null
fi
# Logging

51
bin/v-change-fs-file-permission Executable file
View file

@ -0,0 +1,51 @@
#!/bin/bash
# info: change file permission
# options: USER FILE PERMISSIONS
#
# The function changes file access permissions on the file system
user=$1
src_file=$2
permissions=$3
# Checking arguments
if [ -z "$permissions" ]; then
echo "Usage: USER FILE PERMISSIONS"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking source file
if [ ! -f "$src_file" ]; then
echo "Error: source file doesn't exist $src_file"
exit 3
fi
# Checking source path
rpath=$(readlink -f "$src_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src_file"
exit 2
fi
# Changing file permissions
sudo -u $user chmod $permissions "$src_file" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: access permission on $src_file was not changed"
exit 3
fi
# Exiting
exit

View file

@ -15,24 +15,20 @@ domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
password=$4
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD'
validate_format 'user' 'domain' 'account' 'password'
validate_format 'user' 'domain' 'account'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -40,17 +36,16 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
is_password_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -x '/usr/bin/doveadm' ]; then
md5=$(/usr/bin/doveadm pw -s md5 -p "$password")
else
md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
fi
# Generating hashed password
salt=$(gen_password "$PW_MATRIX" "8")
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd

View file

@ -28,7 +28,10 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT QUOTA'
validate_format 'user' 'domain' 'account' 'quota'
validate_format 'user' 'domain' 'account'
if [ "$quota" != 'unlimited' ]; then
validate_format 'quota'
fi
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -44,6 +47,9 @@ is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
if [ "$quota" = 'unlimited' ]; then
quota=0
fi
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
@ -54,6 +60,10 @@ fi
# Vesta #
#----------------------------------------------------------#
if [[ "$quota" -eq 0 ]]; then
quota='unlimited'
fi
# Update quota
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA' "$quota"

View file

@ -28,79 +28,42 @@ validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Check remote dns nodes
remote_dns_health_check
# Parsing remote host parameters
eval $cluster
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Sync domain
# Syncing domain
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
check_result $? "$HOST connection failed (exp insert)" $E_CONNECT
done
# Update pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -28,82 +28,46 @@ validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result 1 $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $VESTA/bin/$SCRIPT |wc -l)" -gt 2 ]; then
check_result 1 $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Check remote dns nodes
remote_dns_health_check
# Parsing remote host parameters
eval $cluster
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Sync domain
# Syncing SOA
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
check_result $? "$HOST connection failed (sync)" $E_CONNECT
# Rebuild dns zone
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (rebuild)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
done
# Update pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -28,96 +28,46 @@ validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Check remote dns nodes
remote_dns_health_check
# Parsing remote host parameters
eval $cluster
# Starting cluster loop
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check host connection
$send_cmd v-list-sys-config
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
$send_cmd v-list-user $DNS_USER
if [ $? -ne 0 ]; then
echo "Error: dns user $DNS_USER doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Sync domain
# Syncing TTL
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
check_result $? "$HOST connection failed (sync)" $E_CONNECT
# Rebuild dns zone
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (rebuild)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
done
# Update pipe
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -25,12 +25,6 @@ source $VESTA/conf/vesta.conf
check_args '2' "$#" 'KEY VALUE'
validate_format 'key'
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
if [ -z "$check_ckey" ]; then
echo "Error: key $key not found"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
#----------------------------------------------------------#
@ -38,7 +32,17 @@ fi
#----------------------------------------------------------#
# Updating conf
sed -i "s/$key=.*/$key='$value'/g" $VESTA/conf/vesta.conf
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
if [ -z "$check_ckey" ]; then
echo "$key='$value'" >> $VESTA/conf/vesta.conf
else
sed -i "s|$key=.*|$key='$value'|g" $VESTA/conf/vesta.conf
fi
if [ "$key" = "BACKUP" ] && [ "$value" != '/backup' ]; then
rm /backup
ln -s $value /backup
fi
#----------------------------------------------------------#

View file

@ -77,9 +77,7 @@ fi
# Restart ftp server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-ftp
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "FTP restart failed" >/dev/null
fi
# Logging

72
bin/v-change-sys-timezone Executable file
View file

@ -0,0 +1,72 @@
#!/bin/bash
# info: change system timezone
# options: TIMEZONE
#
# The function for changing system timezone.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
timezone=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
is_timezone_valid() {
if [ ! -e "/usr/share/zoneinfo/$timezone" ]; then
echo "Error: tz file $timezone doesn't exist"
log_event $E_NOTEXIST "$EVENT"
exit $E_NOTEXIST
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'TIMEZONE'
is_timezone_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Changing system timezone
which timedatectls >/dev/null 2>&1
if [ "$?" -eq 0 ]; then
timedatectl set-timezone $timezone
else
if [ -e "/etc/sysconfig/clock" ]; then
sed -i "s/ZONE.*//" /etc/sysconfig/clock
echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
fi
if [ -e "/etc/timezone" ]; then
echo "$timezone" > /etc/timezone
fi
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
fi
# Chaning php timezone
if [ ! -z "$WEB_SYSTEM" ]; then
for conf in $(find /etc/php* -name php.ini); do
sed -i "s|;date.timezone =|date.timezone =|" $conf
sed -i "s|date.timezone =.*|date.timezone = $timezone|" $conf
done
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: change user nameservers
# options: USER NS1 NS2 [NS3] [NS4]
# options: USER NS1 NS2 [NS3] [NS4] [NS5] [NS6] [NS7] [NS8]
#
# The function for changing default nameservers for speciefic user.
@ -13,8 +13,12 @@
user=$1
ns1=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns2=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns3=$4
ns4=$5
ns3=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns4=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns5=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns6=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns7=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns8=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
# Includes
source $VESTA/func/main.sh
@ -26,10 +30,10 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Checking args
check_args '3' "$#" 'USER NS1 NS2 [NS3] [NS4]'
check_args '3' "$#" 'USER NS1 NS2 [NS3] [NS4] [NS5] [NS6] [NS7] [NS8]'
# Checking argument format
validate_format 'user' 'ns1' 'ns2'
validate_format 'user' 'ns1' 'ns2'
if [ ! -z "$ns3" ]; then
ns3=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns3'
@ -38,7 +42,22 @@ if [ ! -z "$ns4" ]; then
ns4=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns4'
fi
if [ ! -z "$ns5" ]; then
ns5=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns5'
fi
if [ ! -z "$ns6" ]; then
ns6=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns6'
fi
if [ ! -z "$ns7" ]; then
ns7=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns7'
fi
if [ ! -z "$ns8" ]; then
ns8=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns8'
fi
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -48,7 +67,7 @@ is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Merging values
ns="$ns1,$ns2,$ns3,$ns4"
ns="$ns1,$ns2,$ns3,$ns4,$ns5,$ns6,$ns7,$ns8"
ns=$(echo "$ns" | sed -e "s/,,//g" -e "s/,$//")
# Changing ns values
@ -60,7 +79,7 @@ update_user_value "$user" '$NS' "$ns"
#----------------------------------------------------------#
# Logging
log_history "changed user nameservers to $ns1, $ns2"
log_history "updated nameservers $ns1 $ns2 $ns3 $ns4 $ns5 $ns6 $ns7 $ns8"
log_event "$OK" "$EVENT"
exit

View file

@ -19,7 +19,7 @@ source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
is_package_avalable() {
# Parsing user data
usr_data=$(cat $USER_DATA/user.conf)
IFS=$'\n'
for key in $usr_data; do
@ -37,17 +37,55 @@ is_package_avalable() {
grep -v DATE)
eval $pkg_data
# Comparing user data with package
if [[ "$WEB_DOMAINS" -lt "$U_WEB_DOMAINS" ]] ||\
[[ "$DNS_DOMAINS" -lt "$U_DNS_DOMAINS" ]] ||\
[[ "$MAIL_DOMAINS" -lt "$U_MAIL_DOMAINS" ]] ||\
[[ "$DATABASES" -lt "$U_DATABASES" ]] ||\
[[ "$CRON_JOBS" -lt "$U_CRON_JOBS" ]] ||\
[[ "$DISK_QUOTA" -lt "$U_DISK" ]] ||\
[[ "$BANDWIDTH" -lt "$U_BANDWIDTH" ]]; then
echo "Error: Package not cover current usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
# Checking usage agains package limits
if [ "$WEB_DOMAINS" != 'unlimited' ]; then
if [ "$WEB_DOMAINS" -lt "$U_WEB_DOMAINS" ]; then
echo "Error: Package doesn't cover WEB_DOMAIN usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$DNS_DOMAINS" ! = 'unlimited' ]; then
if [ "$DNS_DOMAINS" -lt "$U_DNS_DOMAINS" ]; then
echo "Error: Package doesn't cover DNS_DOMAIN usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
if [ "$MAIL_DOMAINS" -lt "$U_MAIL_DOMAINS" ]; then
echo "Error: Package doesn't cover MAIL_DOMAIN usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$DATABASES" != 'unlimited' ]; then
if [ "$DATABASES" -lt "$U_DATABASES" ]; then
echo "Error: Package doesn't cover DATABASE usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$CRON_JOBS" != 'unlimited' ]; then
if [ "$CRON_JOBS" -lt "$U_CRON_JOBS" ]; then
echo "Error: Package doesn't cover CRON usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$DISK_QUOTA" != 'unlimited' ]; then
if [ "$DISK_QUOTA" -lt "$U_DISK" ]; then
echo "Error: Package doesn't cover DISK usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
if [ "$BANDWIDTH" != 'unlimited' ]; then
if [ "$BANDWIDTH" -lt "$U_BANDWIDTH" ]; then
echo "Error: Package doesn't cover BANDWIDTH usage"
log_event "$E_LIMIT" "$EVENT"
exit $E_LIMIT
fi
fi
}
@ -110,6 +148,7 @@ U_DATABASES='$U_DATABASES'
U_CRON_JOBS='$U_CRON_JOBS'
U_BACKUPS='$U_BACKUPS'
LANGUAGE='$LANGUAGE'
NOTIFICATIONS='$NOTIFICATIONS'
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
}
@ -145,6 +184,12 @@ if [ -x "$VESTA/data/packages/$package.sh" ]; then
$VESTA/data/packages/$package.sh "$user" "$CONTACT" "$FNAME" "$LNAME"
fi
# Update disk quota
source $VESTA/conf/vesta.conf
if [ "$DISK_QUOTA" = 'yes' ]; then
$BIN/v-update-user-quota $user
fi
#----------------------------------------------------------#
# Vesta #

View file

@ -11,25 +11,22 @@
# Argument defenition
user=$1
password=$2
password=$2; HIDE=2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Hiding password
A2="******"
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER PASSWORD'
validate_format 'user' 'password'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_password_valid
#----------------------------------------------------------#

View file

@ -36,9 +36,18 @@ is_object_unsuspended 'user' 'USER' "$user"
shell_path=$(grep -w "$shell" /etc/shells | head -n1)
# Changing passwd file
/usr/bin/chsh -s "$shell_path" "$user" &>/dev/null
/usr/bin/chsh -s "$shell_path" "$user" >/dev/null 2>&1
shell=$(basename $shell_path)
# Adding jailed sftp env
if [ ! -z "$SFTPJAIL_KEY" ]; then
if [[ "$shell" =~ nologin ]] || [[ "$shell" =~ rssh ]]; then
$BIN/v-add-user-sftp-jail $user >/dev/null 2>&1
else
$BIN/v-delete-user-sftp-jail $user >/dev/null 2>&1
fi
fi
#----------------------------------------------------------#
# Vesta #

View file

@ -37,7 +37,7 @@ is_object_unsuspended 'user' 'USER' "$user"
case $type in
WEB) is_web_template_valid;
update_user_value "$user" '$WEB_TEMPLATE' "$template";;
PROXY) is_proxy_template_valid;
PROXY) is_proxy_template_valid $template;
update_user_value "$user" '$PROXY_TEMPLATE' "$template";;
DNS) is_dns_template_valid;
update_user_value "$user" '$DNS_TEMPLATE' "$template";;

View file

@ -0,0 +1,171 @@
#!/bin/bash
# info: change web domain backend template
# options: USER DOMAIN TEMPLATE [RESTART]
#
# The function changes backend template
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
restart="$4"
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
validate_format 'user' 'domain' 'template'
is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_web_backend_template_valid $template
is_web_backend_pool_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting backend
rm -f $pool/$backend.conf
# Allocating backend port
backend_port=9000
ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
ports=$(echo "$ports" |sed "s/://" |sort -n)
for port in $ports; do
if [ "$backend_port" -eq "$port" ]; then
backend_port=$((backend_port + 1))
fi
done
# Changing backend config
cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
sed -e "s|%backend_port%|$backend_port|" \
-e "s|%user%|$user|"\
-e "s|%domain%|$domain|"\
-e "s|%domain_idn%|$domain_idn|"\
-e "s|%backend%|$backend|g" > $pool/$backend.conf
# Checking backend pool configuration
if [ "$backend" = "$user" ]; then
conf=$USER_DATA/web.conf
fields='$DOMAIN'
nohead=1
for domain in $(shell_list); do
# Parsing domain values
get_domain_values 'web'
ip=$(get_real_ip $IP)
# Deleting old vhost
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
del_web_config
# Deleting old ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
fi
# Adding new vhost
upd_web_domain_values
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
add_web_config
# Adding new ssl vhost
if [ "$SSL" = 'yes' ]; then
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
add_web_config
fi
# Update config
add_object_key "web" 'DOMAIN' "$domain" 'BACKEND' 'PROXY'
update_object_value 'web' 'DOMAIN' "$domain" '$BACKEND' "$template"
done
# Chaning template in user config
old_template=$(grep BACKEND_TEMPLATE $USER_DATA/user.conf)
if [ -z "$old_template" ]; then
sed -i "s/^WEB_DOMAINS/BACKEND_TEMPLATE='$template'\nWEB_DOMAINS/g" \
$USER_DATA/user.conf
else
update_user_value "$user" '$BACKEND_TEMPLATE' "$template"
fi
else
# Parsing domain values
get_domain_values 'web'
ip=$(get_real_ip $IP)
# Deleting old vhost
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
del_web_config
# Deleting old ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
fi
# Adding new vhost
upd_web_domain_values
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
add_web_config
# Adding new ssl vhost
if [ "$SSL" = 'yes' ]; then
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
add_web_config
fi
# Update config
add_object_key "web" 'DOMAIN' "$domain" 'BACKEND' 'PROXY'
update_object_value 'web' 'DOMAIN' "$domain" '$BACKEND' "$template"
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restarting web
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-web-backend
check_result $? "Web backend restart failed" >/dev/null
fi
# Logging
log_history "changed backend template for $domain to $template"
log_event "$OK" "$EVENT"
exit

View file

@ -14,7 +14,7 @@ user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ftp_user=$3
ftp_password=$4
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
@ -27,12 +27,13 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN FTP_USER FTP_PASSWORD'
validate_format 'user' 'domain' 'ftp_user' 'ftp_password'
validate_format 'user' 'domain' 'ftp_user'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_password_valid
get_domain_values 'web'
if [ -z "$(echo $FTP_USER | tr ':' '\n' | grep ^$ftp_user$)" ]; then
echo "Error: account $ftp_user doesn't exist"
@ -46,7 +47,7 @@ fi
#----------------------------------------------------------#
# Changing ftp user password
echo "$ftp_user:$ftp_password" | /usr/sbin/chpasswd
echo "$ftp_user:$password" | /usr/sbin/chpasswd
ftp_md5=$(awk -v user=$ftp_user -F : 'user == $1 {print $2}' /etc/shadow)

View file

@ -0,0 +1,76 @@
#!/bin/bash
# info: change password for http auth user
# options: USER DOMAIN AUTH_USER AUTH_PASSWORD
#
# The call is used for chaning http auth user password
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$2
auth_user=$3
password=$4; HIDE=4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Definining htpasswd file
htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN AUTH_USER AUTH_PASSWORD [RESTART]'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_password_valid
get_domain_values 'web'
if [ -z "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
echo "Error: auth user $auth_user doesn't exist"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Adding httpasswd user
auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
touch $htpasswd
sed -i "/^$auth_user:/d" $htpasswd
echo "$auth_user:$auth_hash" >> $htpasswd
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Rebuilding AUTH_HASH variable
position=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep ":$auth_user$" |\
cut -f 1 -d:)
auth_hash=$(echo $AUTH_HASH |tr ':' '\n' |grep -n '' |\
sed -e "s%^$position:.*%$position:$auth_hash%" |\
cut -f 2 -d :| sed -e "/^$/d"| sed -e ':a;N;$!ba;s/\n/:/g')
# Updating config
update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_HASH' "$auth_hash"
# Logging
log_history "changed auth user $httpauth_user password on $domain"
log_event "$OK" "$EVENT"
exit

View file

@ -45,7 +45,7 @@ is_ip_avalable
# Define variable for replace
get_domain_values 'web'
ip=$(get_real_ip $ip)
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
old=$(get_real_ip $IP)
new=$ip
@ -53,23 +53,23 @@ replace_web_config
# Checking SSL
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
replace_web_config
fi
# Checking proxy
if [ ! -z "$PROXY" ]; then
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
replace_web_config
fi
# Checking SSL proxy
if [ "$SSL" = 'yes' ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
replace_web_config
# Checking SSL proxy
if [ "$SSL" = 'yes' ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
replace_web_config
fi
fi
@ -87,13 +87,11 @@ update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "WEB restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

View file

@ -39,7 +39,7 @@ is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_object_value_exist 'web' 'DOMAIN' "$domain" '$PROXY'
is_proxy_template_valid
is_proxy_template_valid $template
#----------------------------------------------------------#
@ -87,16 +87,14 @@ fi
# Vesta #
#----------------------------------------------------------#
# Update config
# Updating config
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
# Restart web
# Restarting proxy
if [ "$restart" != 'no' ]; then
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Proxy restart failed" >/dev/null
fi
# Logging

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: change domain ssl certificate
# options: USER DOMAIN SSL_DIR
# options: USER DOMAIN SSL_DIR [RESTART]
#
# The function changes SSL domain certificate and the key. If ca file present
# it will be replaced as well.
@ -15,6 +15,7 @@ user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ssl_dir=$3
restart=$4
# Includes
source $VESTA/func/main.sh
@ -26,7 +27,7 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN SSL_DIR'
check_args '3' "$#" 'USER DOMAIN SSL_DIR [RESTART]'
validate_format 'user' 'domain' 'ssl_dir'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
@ -69,15 +70,15 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restart web server
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi
# Logging

View file

@ -10,6 +10,7 @@ user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ssl_home=$3
restart=$4
# Includes
source $VESTA/func/main.sh
@ -21,7 +22,7 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN SSL_HOME'
check_args '3' "$#" 'USER DOMAIN SSL_HOME [RESTART]'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
@ -39,7 +40,7 @@ is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL'
get_domain_values 'web'
old_ssl_home=$SSL_HOME
SSL_HOME=$ssl_home
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
# Parsing tpl_option
@ -55,7 +56,7 @@ esac
replace_web_config
# Checking proxy config
if [ ! -z "$PROXY" ]; then
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
replace_web_config
@ -69,15 +70,15 @@ fi
# Update config
update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME"
# Restart web server
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi
# Logging

View file

@ -47,40 +47,40 @@ get_domain_values 'web'
ip=$(get_real_ip $IP)
# Deleting domain
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
old_tpl=$TPL
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
del_web_config
# Deleting ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
fi
# Defining variables for new vhost config
upd_web_domain_values
tpl_file="$WEBTPL/$WEB_SYSTEM/$template.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.tpl"
# Adding domain to the web conf
add_web_config
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
$user $domain $ip $HOMEDIR $docroot
fi
# Checking SSL
if [ "$SSL" = 'yes' ]; then
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$template.stpl"
del_web_config
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.stpl"
add_web_config
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh \
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
"$user" "$domain" "$ip" "$HOMEDIR" "$sdocroot"
fi
fi
@ -93,12 +93,10 @@ fi
# Changing tpl in config
update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
# Restart web
# Restarting web
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Web restart failed" >/dev/null
fi
# Logging

54
bin/v-check-fs-permission Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# info: open file
# options: USER FILE
#
# The function opens/reads files on the file system
user=$1
src_file=$2
# Checking arguments
if [ -z "$src_file" ]; then
echo "Usage: USER FILE"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking path
if [ ! -z "$src_file" ]; then
rpath=$(readlink -f "$src_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src_file"
exit 2
fi
fi
# Reading file
#sudo -u $user cat "$src_file" 2>/dev/null
#if [ $? -ne 0 ]; then
# echo "Error: file $src_file was not opened"
# exit 3
#fi
# Checking if file has readable permission
if [[ ! -r $src_file ]]
then
# echo "File is readable"
#else
echo "Cannot read file"
fi
# Exiting
exit

91
bin/v-check-user-password Executable file
View file

@ -0,0 +1,91 @@
#!/bin/bash
# info: check user password
# options: USER PASSWORD [IP]
#
# The function verifies user password from file
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
password=$2; HIDE=2
ip=${3-127.0.0.1}
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER PASSWORD'
validate_format 'user'
# Checking user
if [ ! -d "$VESTA/data/users/$user" ] && [ "$user" != 'root' ]; then
echo "Error: password missmatch"
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
exit 9
fi
# Checking user password
is_password_valid
# Checking empty password
if [[ -z "$password" ]]; then
echo "Error: password missmatch"
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
exit 9
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing user's salt
shadow=$(grep "^$user:" /etc/shadow)
salt=$(echo "$shadow" |cut -f 3 -d \$)
method=$(echo "$shadow" |cut -f 2 -d \$)
if [ "$method" -eq '1' ]; then
method='md5'
else
method='sha-512'
fi
if [ -z "$salt" ]; then
echo "Error: password missmatch"
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
exit 9
fi
# Generating SHA-512
hash=$($BIN/v-generate-password-hash $method $salt <<< $password)
if [[ -z "$hash" ]]; then
echo "Error: password missmatch"
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
exit 9
fi
# Checking hash
result=$(grep "^$user:$hash:" /etc/shadow 2>/dev/null)
if [[ -z "$result" ]]; then
echo "Error: password missmatch"
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
exit 9
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
echo "$DATE $TIME $user $ip successfully logged in" >> $VESTA/log/auth.log
exit

58
bin/v-copy-fs-directory Executable file
View file

@ -0,0 +1,58 @@
#!/bin/bash
# info: copy directory
# options: USER SRC_DIRECTORY DST_DIRECTORY
#
# The function copies directory on the file system
user=$1
src_dir=$2
dst_dir=$3
# Checking arguments
if [ -z "$dst_dir" ]; then
echo "Usage: USER SRC_DIRECTORY DST_DIRECTORY"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking source dir
if [ ! -e "$src_dir" ]; then
echo "Error: source directory $src_dir doesn't exist"
exit 3
fi
# Checking source path
rpath=$(readlink -f "$src_dir")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src_dir"
exit 2
fi
# Checking destination path
rpath=$(readlink -f "$dst_dir")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid destination path $dst_dir"
exit 2
fi
# Copying directory
sudo -u $user cp -r "$src_dir" "$dst_dir" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: directory $src_dir was not copied"
exit 3
fi
# Exiting
exit

View file

@ -1,58 +1,58 @@
#!/bin/bash
# File copier
# info: copy file
# options: USER SRC_FILE DST_FLE
#
# The function copies file on the file system
user=$1
file_src=$2
file_dst=$3
src_file=$2
dst_file=$3
# Checking arguments
if [ -z "$file_dst" ]; then
if [ -z "$dst_file" ]; then
echo "Usage: USER SRC_FILE DST_FILE"
exit 1
fi
# Checking users
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
exit 1
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking homedir
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
exit 1
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking source file
if [ ! -e "$file_src" ]; then
exit 1
if [ ! -f "$src_file" ]; then
echo "Error: $src_file doesn't exist"
exit 3
fi
# Checking source path
rpath=$(readlink -f "$file_src")
if [ -z "$(echo $rpath |grep ^/tmp)" ]; then
exit 1
rpath=$(readlink -f "$src_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src_file"
exit 2
fi
# Checking destination path
rpath=$(readlink -f "$file_dst")
if [ -z "$(echo $rpath |grep ^$homedir)" ]; then
exit 1
fi
# Checking dst file permission
if [ -e "$file_dst" ]; then
perms=$(stat --format '%a' $file_dst)
rpath=$(readlink -f "$dst_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: ivalid destination path $dst_file"
exit 2
fi
# Copying file
cp $file_src $file_dst
# Changing ownership
chown $user:$user $file_dst
# Changin permissions
if [ ! -z "$perms" ]; then
chmod $perms $file_dst
sudo -u $user cp "$src_file" "$dst_file" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: file $src_file was not copied"
exit 3
fi
# Exiting
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: delete backup ftp server
# options: NONE
# options: TYPE
#
# The function deletes ftp backup host
@ -9,6 +9,9 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
@ -18,23 +21,31 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'TYPE [HOST]'
types=$(echo "$BACKUP_SYSTEM" |sed "s/,/\n/g" |grep "^$type$")
if [ -z "$types" ]; then
echo "Error: invalid backup type"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking network connection
rm -f $VESTA/conf/ftp.backup.conf
# Deleting host config
rm -f $VESTA/conf/$type.backup.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Update vesta.conf
# Updating vesta.conf
bckp=$(echo "$BACKUP_SYSTEM" |\
sed "s/,/\n/g"|\
sed "s/ftp//" |\
sed "s/^$type$//" |\
sed "/^$/d"|\
sed ':a;N;$!ba;s/\n/,/g')
sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $VESTA/conf/vesta.conf

View file

@ -52,11 +52,9 @@ sync_cron_jobs
# Decreasing cron value
decrease_user_value "$user" '$U_CRON_JOBS'
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Restart restart failed" >/dev/null
# Logging
log_history "deleted cron job $job"

View file

@ -44,11 +44,9 @@ sync_cron_jobs
# Vesta #
#----------------------------------------------------------#
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_history "disabled cron reporting"

View file

@ -51,11 +51,9 @@ sync_cron_jobs
# Decreasing cron value
decrease_user_value "$user" '$U_CRON_JOBS'
# Restart crond
# Restarting crond
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Cron restart failed" >/dev/null
# Logging
log_event "$OK" "$EVENT"

View file

@ -71,12 +71,10 @@ rm -f $USER_DATA/dns/$domain.conf
decrease_user_value "$user" '$U_DNS_DOMAINS'
decrease_user_value "$user" '$U_DNS_RECORDS' "$records"
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns $restart
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Bind restart failed" >/dev/null
fi
# Logging

View file

@ -11,6 +11,7 @@
# Argument defenition
user=$1
restart=$2
# Includes
source $VESTA/func/main.sh
@ -41,10 +42,10 @@ done
# Vesta #
#----------------------------------------------------------#
# Restart named
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
check_result $? "Bind restart failed" >/dev/null
fi
# Logging

View file

@ -46,9 +46,7 @@ done
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Bind restart failed" >/dev/null
fi
# Logging

View file

@ -45,6 +45,7 @@ sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -68,12 +69,10 @@ records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
decrease_user_value "$user" '$U_DNS_RECORDS'
# Restart named
# Restarting named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Bind restart failed" >/dev/null
fi
# Logging

View file

@ -16,7 +16,6 @@ restart="${3-yes}"
# Includes
source $VESTA/func/main.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
@ -34,51 +33,53 @@ is_object_unsuspended 'user' 'USER' "$user"
# Action #
#----------------------------------------------------------#
# Web domain
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
check_web=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
if [ ! -z "$check_web" ]; then
# Working on Web domain
if [ ! -z "$WEB_SYSTEM" ]; then
str=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf |grep "SUSPENDED='no")
if [ ! -z "$str" ]; then
domain_found='yes'
$BIN/v-delete-web-domain $user $domain 'no'
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "can't suspend web" > /dev/null
fi
fi
# DNS domain
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
check_dns=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
if [ ! -z "$check_dns" ]; then
# Working on DNS domain
if [ ! -z "$DNS_SYSTEM" ]; then
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf |grep "SUSPENDED='no")
if [ ! -z "$str" ]; then
domain_found='yes'
$BIN/v-delete-dns-domain $user $domain 'no'
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "can't suspend dns" > /dev/null
fi
fi
# Mail domain
if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
check_mail=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf)
if [ ! -z "$check_mail" ]; then
# Working on Mail domain
if [ ! -z "$MAIL_SYSTEM" ]; then
str=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf |grep "SUSPENDED='no")
if [ ! -z "$str" ]; then
domain_found='yes'
$BIN/v-delete-mail-domain $user $domain
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "can't suspend mail" > /dev/null
fi
fi
# Check domain status
if [ -z "$check_web" ] && [ -z "$check_dns" ] && [ -z "$check_mail" ]; then
# Checking domain search result
if [ -z "$domain_found" ]; then
echo "Error: domain $domain doesn't exist"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
# Restart services
# Restarting services
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
$BIN/v-restart-proxy
check_result $? "can't restart web" > /dev/null
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "can't restart proxy" > /dev/null
fi
$BIN/v-restart-dns
check_result $? "can't restart dns" > /dev/null
fi

View file

@ -46,8 +46,8 @@ fi
# Deleting ip from banlist
sed -i "/IP='$ip' CHAIN='$chain'/d" $conf
$iptables -D fail2ban-$chain -s $ip \
-j REJECT --reject-with icmp-port-unreachable 2>/dev/null
b=$($iptables -L fail2ban-$chain --line-number -n|grep $ip|awk '{print $1}')
$iptables -D fail2ban-$chain $b 2>/dev/null
# Changing permissions
chmod 660 $conf

45
bin/v-delete-fs-directory Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# info: delete directory
# options: USER DIRECTORY
#
# The function deletes directory on the file system
user=$1
dst_dir=$2
# Checking arguments
if [ -z "$dst_dir" ]; then
echo "Usage: USER DIRECTORY"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking destination path
rpath=$(readlink -f "$dst_dir")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid destination path $dst_dir"
exit 1
fi
# Deleting directory
sudo -u $user rm -rf "$dst_dir" # >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: directory $dst_dir was not deleted"
exit 3
fi
# Exiting
exit

45
bin/v-delete-fs-file Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# info: delete file
# options: USER FILE
#
# The function deletes file on the file system
user=$1
dst_file=$2
# Checking arguments
if [ -z "$dst_file" ]; then
echo "Usage: USER FILE"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
echo "Error: vesta user $user doesn't exist"
exit 3
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
echo "Error: user home directory doesn't exist"
exit 12
fi
# Checking destination path
rpath=$(readlink -f "$dst_file")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid destination path $dst_file"
exit 2
fi
# Deleting file
sudo -u $user rm -f "$dst_file" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: file $dst_file was not deleted"
exit 3
fi
# Exiting
exit

View file

@ -26,84 +26,45 @@ source $VESTA/conf/vesta.conf
check_args '2' "$#" 'USER DOMAIN'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
# Starting cluster loop
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Parsing remote host parameters
eval $cluster
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
# Syncing domain
cluster_cmd v-delete-dns-domain $DNS_USER $domain 'yes'
rc=$?
if [ "$rc" -ne 0 ] && [ $rc -ne 3 ]; then
check_result $rc "$HOST connection failed (sync)" $E_CONNECT
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check host connection
$send_cmd v-list-sys-config
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
$send_cmd v-list-user $DNS_USER
if [ $? -ne 0 ]; then
echo "Error: dns user $DNS_USER doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
# Check dns exceptions
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
DNS_CLUSTER_IGNORE='dns-cluster'
fi
# Sync domain
$send_cmd v-delete-dns-domain $DNS_USER $domain 'scheduled'
done
# Update pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -22,26 +22,19 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
if [ -z $host ]; then
@ -51,65 +44,18 @@ else
fi
# Starting cluster loop
for cluster_str in $hosts; do
for cluster in $hosts; do
# Get host values
eval $cluster_str
# Parsing remote host parameters
eval $cluster
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Deleting source records
cluster_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME 'no'
check_result $? "$HOST connection failed (cleanup)" $E_CONNECT
# Print hostname
if [ ! -z "$verbose" ]; then
echo "HOSTNAME: $HOSTNAME"
echo "TYPE: $TYPE"
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check host connection
$send_cmd v-list-sys-config
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
if [ ! -z "$verbose" ]; then
echo "DNS_USER: $DNS_USER"
fi
$send_cmd v-list-user $DNS_USER
if [ $? -ne 0 ]; then
echo "Error: dns user $DNS_USER doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
# Clean source records
$send_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME 'no'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (cleanup)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Rebuild dns zones
$send_cmd v-rebuild-dns-domains $DNS_USER 'scheduled'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (rebuild)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Rebuilding dns zones
$send_cmd v-rebuild-dns-domains $DNS_USER 'yes'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
done
@ -118,4 +64,11 @@ done
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -32,25 +32,13 @@ is_object_valid "../../conf/dns-cluster" 'HOST' "$host"
# Action #
#----------------------------------------------------------#
eval $(grep $host $VESTA/conf/dns-cluster.conf)
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check host connection
$send_cmd v-list-sys-config
if [ $? -eq 0 ]; then
# Deleting domains
$BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1
$send_cmd v-add-cron-restart-job
fi
# Deleting remote domains
$BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1
# Deleting server
sed -i "/HOST='$host' /d" $VESTA/conf/dns-cluster.conf
# Delete DNS_CLUSTER key
# Deleting DNS_CLUSTER key
check_cluster=$(grep HOST $VESTA/conf/dns-cluster.conf |wc -l)
if [ "$check_cluster" -eq '0' ]; then
rm -f $VESTA/conf/dns-cluster.conf

View file

@ -27,79 +27,53 @@ source $VESTA/conf/vesta.conf
check_args '3' "$#" 'USER DOMAIN ID'
validate_format 'user' 'domain' 'id'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
fi
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
if [ "$number_of_proc" -gt 2 ]; then
echo "Error: another sync process already exists"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
check_result $E_EXISTS "another sync process already running"
fi
remote_dns_health_check
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
# Starting cluster loop
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
IFS=$'\n'
for cluster in $(cat $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# Parsing remote host parameters
eval $cluster
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Switch on connection type
case $TYPE in
ssh) send_cmd="send_ssh_cmd" ;;
*) send_cmd="send_api_cmd" ;;
esac
# Check host connection
$send_cmd v-list-sys-config
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
# Check recipient dns user
if [ -z "$DNS_USER" ]; then
DNS_USER='dns-cluster'
fi
$send_cmd v-list-user $DNS_USER
if [ $? -ne 0 ]; then
echo "Error: dns user $DNS_USER doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
# Syncing serial
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
check_result $? "$HOST connection failed (soa sync)" $E_CONNECT
# Sync domain
$send_cmd v-delete-dns-record $DNS_USER $domain $id 'scheduled'
cluster_cmd v-delete-dns-record $DNS_USER $domain $id 'no'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
done
# Update pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit

View file

@ -121,15 +121,19 @@ else
decrease_user_value "$OWNER" '$IP_AVAIL'
fi
# Adding task to the vesta pipe
# Restarting web server
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
check_result $? "Web restart failed" >/dev/null
# Restarting proxy server
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
# Restarting firewall
if [ ! -z "$FIREWALL_SYSTEM" ]; then
$BIN/v-update-firewall
fi
# Logging

89
bin/v-delete-sys-sftp-jail Executable file
View file

@ -0,0 +1,89 @@
#!/bin/bash
# info: delete system sftp jail
# opions: NONE
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Importing system enviroment as we run this script
# mostly by cron wich do not read it by itself
source /etc/profile
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ -z "$SFTPJAIL_KEY" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking users
for user in $(grep "$HOMEDIR" /etc/passwd |cut -f 1 -d:); do
$BIN/v-delete-user-sftp-jail $user
done
# Checking sshd directives
config='/etc/ssh/sshd_config'
sftp_n=$(grep -n "Subsystem.*sftp" $config |grep -v internal |grep ":#")
sftp_i=$(grep -n "Subsystem.*sftp" $config |grep internal |grep -v ":#")
# Backing up config
cp $config $config.bak-$(date +%s)
# Enabling normal sftp
if [ ! -z "$sftp_n" ]; then
fline=$(echo $sftp_n |cut -f 1 -d :)
sed -i "${fline}s/#Subsystem/Subsystem sftp/" $config
restart='yes'
fi
# Disabling jailed sftp
if [ ! -z "$sftp_i" ]; then
fline=$(echo $sftp_i |cut -f 1 -d :)
lline=$((fline + 5))
sed -i "${fline},${lline}d" $config
restart='yes'
fi
# Validating opensshd config
if [ "$restart" = 'yes' ]; then
subj="OpenSSH restart failed"
email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \')
send_mail="$VESTA/web/inc/mail-wrapper.php"
/usr/sbin/sshd -t >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
mail_text="OpenSSH can not be restarted. Please check config:
\n\n$(/usr/sbin/sshd -t)"
echo -e "$mail_text" | $send_mail -s "$subj" $email
else
service ssh restart >/dev/null 2>&1
service sshd restart >/dev/null 2>&1
fi
fi
# Deleting v-add-sys-sftp-jail from startup
sed -i "/v-add-sys-sftp-jail/d" /etc/rc.local 2>/dev/null
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -91,11 +91,17 @@ sed -i "/ $user$/d" $VESTA/data/queue/traffic.pipe
# Deleting system user
/usr/sbin/userdel -f $user >> /dev/null 2>&1
if [ "$?" != 0 ]; then
sed -i "/^$user:/d" /etc/passwd
sed -i "/^$user:/d" /etc/shadow
fi
/usr/sbin/groupdel $user >> /dev/null 2>&1
if [ "$?" != 0 ]; then
sed -i "/^$user:/d" /etc/group
fi
# Deleting user directories
chattr -i $HOMEDIR/$user/conf
rm -rf $HOMEDIR/$user

124
bin/v-delete-user-favourites Executable file
View file

@ -0,0 +1,124 @@
#!/bin/bash
# info: deleting user favourites
# options: USER SYSTEM OBJECT
#
# The function deletes object from users favourites
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
system=$(echo "$2" |tr '[:lower:]' '[:upper:]')
object=$3
email=$3
id=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER SYSTEM OBJECT'
case $system in
MAIL_ACC) validate_format 'email' ;;
CRON) validate_format 'id' ;;
DNS_REC) validate_format 'id' ;;
*) validate_format 'object'
esac
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
# Checking system
case $system in
USER) check='ok' ;;
WEB) check='ok' ;;
DNS) check='ok' ;;
DNS_REC) check='ok' ;;
MAIL) check='ok' ;;
MAIL_ACC) check='ok' ;;
DB) check='ok' ;;
CRON) check='ok' ;;
BACKUP) check='ok' ;;
IP) check='ok' ;;
PACKAGE) check='ok' ;;
FIREWALL) check='ok' ;;
*) check_args '2' '0' 'USER SYSTEM OBJECT'
esac
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Flushing vars
USER=''
WEB=''
DNS=''
DNS_REC=''
MAIL=''
MAIL_ACC=''
DB=''
CRON=''
BACKUP=''
IP=''
PACKAGE=''
FIREWALL=''
# Creating config just in case
touch $USER_DATA/favourites.conf
# Reading current values
source $USER_DATA/favourites.conf
# Assigning current system value
eval value=\$$system
# Checking if object is new
check_fav=$(echo "$value" |tr ',' '\n'| grep "^$object$")
if [ -z "$check_fav" ]; then
exit 0
fi
# Deleting object from favorites
value=$(echo "$value" |\
sed -e "s/,/\n/g"|\
sed -e "s/^$object$//g"|\
sed -e "/^$/d"|\
sed -e ':a;N;$!ba;s/\n/,/g')
# Updating sytem
eval $system=$value
# Updating user favorites
echo "USER='$USER'
WEB='$WEB'
DNS='$DNS'
DNS_REC='$DNS_REC'
MAIL='$MAIL'
MAIL_ACC='$MAIL_ACC'
DB='$DB'
CRON='$CRON'
BACKUP='$BACKUP'
IP='$IP'
PACKAGE='$PACKAGE'
FIREWALL='$FIREWALL'" > $USER_DATA/favourites.conf
# Changing file permission
chmod 640 $USER_DATA/favourites.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "deleted starred $object from $system listing"
log_event "$OK" "$EVENT"
exit

66
bin/v-delete-user-notification Executable file
View file

@ -0,0 +1,66 @@
#!/bin/bash
# info: delete user notification
# options: USER NOTIFICATION
#
# The function deletes user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
nid=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER NOTIFICATION'
validate_format 'user' 'nid'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting notification
sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
# Checking last notification
if [ -e "$USER_DATA/notifications.conf" ]; then
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
else
notice='no'
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ "$notice" = 'no' ]; then
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "no"
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit

63
bin/v-delete-user-sftp-jail Executable file
View file

@ -0,0 +1,63 @@
#!/bin/bash
# info: delete user sftp jail
# opions: USER
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
validate_format 'user'
user_str=$(grep "^$user:" /etc/passwd)
if [ -z "$user_str" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining user homedir
home="$(echo $user_str |cut -f 6 -d :)"
# Unmounting home directory
mount_dir=$(mount |grep /chroot/$user/ |awk '{print $3}')
if [ ! -z "$mount_dir" ]; then
umount -f $mount_dir 2>/dev/null
if [ $? -ne 0 ]; then
gpasswd -d $user sftp-only >/dev/null 2>&1
exit 1
fi
fi
# Deleting chroot dir
rmdir $mount_dir 2>/dev/null
rm -rf /chroot/$user
# Deleting user from sftp group
gpasswd -d $user sftp-only >/dev/null 2>&1
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
#log_event "$OK" "$EVENT"
exit

View file

@ -44,7 +44,7 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
# Get template name
get_domain_values 'web'
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
ip=$(get_real_ip $IP)
@ -60,7 +60,7 @@ fi
# Checking SSL
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
@ -69,6 +69,11 @@ if [ "$SSL" = 'yes' ]; then
rm -f $USER_DATA/ssl/$domain.*
fi
# Checking backend
if [ ! -z "$WEB_BACKEND" ]; then
$BIN/v-delete-web-domain-backend $user $domain $restart
fi
# Checking proxy
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
@ -80,6 +85,12 @@ if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
del_web_config
fi
# Deleting domain from proxy cache pool
pool="/etc/$PROXY_SYSTEM/conf.d/01_caching_pool.conf"
if [ -e "$pool" ]; then
sed -i "/=$domain:/d" $pool
fi
fi
# Checking stats
@ -157,16 +168,14 @@ if [ "$SSL" = 'yes' ]; then
decrease_user_value "$user" '$U_WEB_SSL'
fi
# Restart web server
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

View file

@ -55,7 +55,7 @@ ALIAS=$(echo "$ALIAS" |\
sed -e "s/^$dom_alias$//g"|\
sed -e "/^$/d"|\
sed -e ':a;N;$!ba;s/\n/,/g')
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
# Preparing domain values for the template substitution
@ -66,14 +66,14 @@ del_web_config
add_web_config
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
add_web_config
fi
# Checking proxy
if [ ! -z "$PROXY" ]; then
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
del_web_config
@ -98,16 +98,14 @@ update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
# Update counters
decrease_user_value "$user" '$U_WEB_ALIASES'
# Restart web server
# Restarting web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
if [ ! -z "$PROXY_SYSTEM" ]; then
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" >/dev/null
fi
fi

Some files were not shown because too many files have changed in this diff Show more