Compare commits

..

No commits in common. "master" and "0.9.8-12" have entirely different histories.

4553 changed files with 29817 additions and 286556 deletions

9
.gitignore vendored
View file

@ -1,9 +0,0 @@
*.tar
*.zip
*.gzip
*.gz
.vscode
.DS_Store
src/react/node_modules
src/react/build
/.idea

View file

@ -1,23 +0,0 @@
### Operating System (OS/VERSION):
Type here, e.g. CentOS 6
### VestaCP Version:
Type here, e.g. 3.14159
### Installed Software (what you got with the installer):
Type here, e.g. php-fpm, apache, nginx, mysql
### Steps to Reproduce:
Type here, e.g. install vesta and type rm -rf / --no-preserve-root
### Related Issues/Forum Threads:
Found anything that might be related to this? It might help us find the cause.
### Other Notes:
Anything else?

View file

@ -1,44 +1,29 @@
[Vesta Control Panel](http://vestacp.com/)
==================================================
Vesta is back under active development as of 25 February 2024. We are commited to open source, and will engage with the community to identify the new roadmap for Vesta. Stay tuned!
[![Join the chat at https://gitter.im/vesta-cp/Lobby](https://badges.gitter.im/vesta-cp/Lobby.svg)](https://gitter.im/vesta-cp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
* Vesta is an open source hosting control panel.
* Vesta has a clean and focused interface without the clutter.
* Vesta has the latest of very innovative technologies.
How to install (2 step)
How to install
----------------------------
Connect to your server as root via SSH
```bash
ssh root@your.server
```
Download the installation script, and run it:
Download the installation script
```bash
curl https://vestacp.com/pub/vst-install.sh | bash
curl -O http://vestacp.com/pub/vst-install.sh
```
How to install (3 step)
----------------------------
If the above example does not work, try this 3 step method:
Connect to your server as root via SSH
```bash
ssh root@your.server
```
Download the installation script:
```bash
curl -O https://vestacp.com/pub/vst-install.sh
```
Then run it:
Run it
```bash
bash vst-install.sh
```
License
----------------------------
Vesta is licensed under [GPL v3 ](https://github.com/outroll/vesta/blob/master/LICENSE) license
Vesta is licensed under [GPL v3 ](https://github.com/serghey-rodin/vesta/blob/master/LICENSE.txt) license

View file

@ -1,5 +0,0 @@
# Security Policy
## Reporting a Vulnerability
Please report security issues to dev@vestacp.com

View file

@ -1,66 +0,0 @@
#!/bin/bash
# info: update user notification
# options: USER NOTIFICATION
#
# The function updates user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
nid=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER NOTIFICATION'
is_format_valid '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" "$ARGUMENTS"
exit

View file

@ -1,67 +0,0 @@
#!/bin/bash
# info: activate vesta license
# options: MODULE LICENSE
#
# The function activates and registers the vesta license
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
module=$(echo $1 | tr '[:lower:]' '[:upper:]')
license=$2
# Importing system environment
source /etc/profile
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'MODULE LICENSE'
is_user_format_valid "$license" "license"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Activating license
v_host='https://vestacp.com/checkout'
answer=$(curl -s "$v_host/activate.php?licence_key=$license&module=$module")
check_result $? "cant' connect to vestacp.com " $E_CONNECT
# Checking server answer
if [[ "$answer" != '0' ]]; then
echo "Error: $module license $license is invalid"
exit $E_INVALID
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating vesta.conf
if [ -z "$(grep "${module}_KEY" $VESTA/conf/vesta.conf)" ]; then
echo "${module}_KEY='$license'" >> $VESTA/conf/vesta.conf
else
sed -i "s/${module}_KEY=.*/${module}_KEY='$license'/g" $VESTA/conf/vesta.conf
fi
# Activating sftpjail
if [ "$module" = 'SFTPJAIL' ]; then
setsid $BIN/v-add-sys-sftp-jail 2>/dev/null
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit

101
bin/v-add-backup-ftp-host Executable file
View file

@ -0,0 +1,101 @@
#!/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

View file

@ -1,200 +0,0 @@
#!/bin/bash
# info: add backup host
# options: TYPE HOST USERNAME PASSWORD [PATH] [PORT]
#
# This function adds a backup host
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
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]"
is_format_valid 'user' 'host' 'path' 'port'
is_password_valid
if [ "$type" = 'sftp' ]; then
which expect >/dev/null 2>&1
check_result $? "expect command not found" $E_NOTEXIST
fi
host "$host" >/dev/null 2>&1
check_result $? "host connection failed" "$E_CONNECT"
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" "$ARGUMENTS"
exit $E_CONNECT
fi
# Checking write permissions
if [ -z $path ]; then
ftmpdir="vst.bK76A9SUkt"
else
ftpc "mkdir $path" > /dev/null 2>&1
ftmpdir="$path/vst.bK76A9SUkt"
fi
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" "$ARGUMENTS"
exit $E_FTP
fi
fi
if [ "$type" = 'sftp' ]; then
if [ -z $port ]; then
port=22
fi
if [ -z $path ]; then
sftmpdir="vst.bK76A9SUkt"
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
else
if sftpc "mkdir $path" > /dev/null 2>&1 ; then
sftmpdir="$path/vst.bK76A9SUkt"
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
else
sftmpdir="$path/vst.bK76A9SUkt"
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
fi
fi
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" "$ARGUMENTS"
exit "$rc"
fi
fi
# Adding backup host
if [ $type != 'local' ]; then
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
str="HOST='$host'\nUSERNAME='$user'\nPASSWORD='$password'"
str="$str\nBPATH='$path'\nPORT='$port'\nTIME='$time'\nDATE='$date'"
echo -e "$str" > $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" "$ARGUMENTS"
exit

View file

@ -10,14 +10,14 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
min=$2
hour=$3
day=$4
month=$5
wday=$6
command=$(echo $7 |sed "s/'/%quote%/g")
command=$(echo $7 | sed "s/'/%quote%/g")
job=$8
restart=$9
@ -25,7 +25,8 @@ restart=$9
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
HIDE=7
# Assing new value
A7="$command"
#----------------------------------------------------------#
@ -33,13 +34,13 @@ HIDE=7
#----------------------------------------------------------#
check_args '7' "$#" 'USER MIN HOUR DAY MONTH WDAY COMMAND [JOB] [RESTART]'
is_format_valid 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_package_full 'CRON_JOBS'
get_next_cronjob
is_format_valid 'job'
validate_format 'job'
is_object_new 'cron' 'JOB' "$job"
@ -47,14 +48,9 @@ is_object_new 'cron' 'JOB' "$job"
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatenating cron string
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
# Adding to crontab
echo "$str" >> $VESTA/data/users/$user/cron.conf
@ -76,12 +72,14 @@ sync_cron_jobs
# Increasing cron value
increase_user_value $user '$U_CRON_JOBS'
# Restarting crond
# Restart crond
$BIN/v-restart-cron
check_result $? "Cron restart failed" >/dev/null
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Logging
log_history "added cron job $job"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,43 +0,0 @@
#!/bin/bash
# info: add letsencrypt cronjob
# options: NONE
#
# The script for enabling letsencrypt cronjob
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Add cron job
cmd="sudo /usr/local/vesta/bin/v-update-sys-queue letsencrypt"
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
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add cron reports
# options: user
# opions: user
#
# The script for enabling reports on cron tasks and administrative
# notifications.
@ -10,7 +10,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
# Includes
@ -23,7 +23,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
is_format_valid 'user'
validate_format 'user'
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -46,10 +46,12 @@ sync_cron_jobs
# Restart crond
$BIN/v-restart-cron
check_result $? "Cron restart failed" >/dev/null
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Logging
log_history "enabled cron reporting"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add cron reports
# options: NONE
# opions: NONE
#
# The script for enabling restart cron tasks
@ -38,6 +38,6 @@ fi
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=admin
# Includes
@ -34,14 +34,9 @@ fi
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Define time somewhere at night
min=$(generate_password '012345' '2')
hour=$(generate_password '1234567' '1')
# Define time somewhere at nigth
min=$(gen_password '012345' '2')
hour=$(gen_password '1234567' '1')
day='*'
month='*'
wday='*'
@ -49,7 +44,7 @@ command='sudo /usr/local/vesta/bin/v-update-sys-vesta-all'
# Concatenating cron string
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
# Adding to crontab
echo "$str" >> $VESTA/data/users/$user/cron.conf
@ -71,12 +66,14 @@ sync_cron_jobs
# Increasing cron value
increase_user_value $user '$U_CRON_JOBS'
# Restarting crond
# Restart crond
$BIN/v-restart-cron
check_result $? "Cron restart failed" >/dev/null
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Logging
log_history "added cron job $job"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -15,11 +15,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
database="$user"_"$2"
dbuser="$user"_"$3"
password=$4; HIDE=4
dbpass=$4
type=${5-mysql}
host=$6
charset=${7-UTF8}
@ -30,25 +30,27 @@ 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]'
is_format_valid 'user' 'database' 'dbuser' 'charset'
validate_format 'user' 'database' 'dbuser' 'dbpass' 'charset'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_type_valid "$DB_SYSTEM" "$type"
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_new 'db' 'DB' "$database"
get_next_dbhost
is_object_valid "../../../conf/$type" 'HOST' "$host"
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"
#----------------------------------------------------------#
@ -66,15 +68,14 @@ esac
# Vesta #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Update time and date
DATE=$(date +%F)
TIME=$(date +%T)
# Adding db to db conf
str="DB='$database' DBUSER='$dbuser' MD5='$md5' HOST='$host' TYPE='$type'"
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$time'"
str="$str DATE='$date'"
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
str="$str DATE='$DATE'"
echo "$str" >> $USER_DATA/db.conf
chmod 660 $USER_DATA/db.conf
@ -84,6 +85,6 @@ increase_user_value "$user" '$U_DATABASES'
# Logging
log_history "added $type database $database"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -13,11 +13,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
type=$1
host=$2
dbuser=$3
password=$4; HIDE=4
dbpass=$4
max_db=${6-500}
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
template=${8-template1}
@ -27,31 +27,8 @@ source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf
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" "$ARGUMENTS"
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" "$ARGUMENTS"
exit $E_CONNECT
fi
}
# Hiding password
A4='******'
#----------------------------------------------------------#
@ -60,12 +37,10 @@ is_pgsql_host_alive() {
args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
check_args '4' "$#" "$args_usage"
is_format_valid 'host' 'dbuser' 'max_db' 'charsets' 'template'
#is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
#is_type_valid "$DB_SYSTEM" "$type"
validate_format 'host' 'dbuser' 'dbpass' '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 ;;
@ -76,44 +51,27 @@ esac
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatenating db host string
# Concatentating db host string
case $type in
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date'";;
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
str="$str TIME='$time' DATE='$date'";;
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" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add dns domain
# options: USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]
# options: USER DOMAIN IP [NS1] [NS2] [NS3] [NS4] [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.
@ -13,75 +13,56 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
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
ns1=$4
ns2=$5
ns3=$6
ns4=$7
ns5=$8
ns6=$9
ns7=${10}
ns8=${11}
restart=${12}
restart=$8
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]'
is_format_valid 'user' 'domain' 'ip'
check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [NS4]'
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' "$domain"
is_domain_new 'dns'
is_package_full 'DNS_DOMAINS'
template=$(get_user_value '$DNS_TEMPLATE')
is_dns_template_valid $template
is_dns_template_valid
if [ ! -z "$ns1" ]; then
ns1=$(echo $4 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns1'
ns1=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns1'
fi
if [ ! -z "$ns2" ]; then
ns2=$(echo $5 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns2'
ns2=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns2'
fi
if [ ! -z "$ns3" ]; then
ns3=$(echo $6 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns3'
ns3=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns3'
fi
if [ ! -z "$ns4" ]; then
ns4=$(echo $7 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns4'
fi
if [ ! -z "$ns5" ]; then
ns5=$(echo $8 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns5'
fi
if [ ! -z "$ns6" ]; then
ns6=$(echo $9 |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns6'
fi
if [ ! -z "$ns7" ]; then
ns7=$(echo ${10} |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns7'
fi
if [ ! -z "$ns8" ]; then
ns8=$(echo ${11} |sed -e 's/\.*$//g' -e 's/^\.*//g')
is_format_valid 'ns8'
ns4=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
validate_format 'ns4'
fi
@ -100,7 +81,6 @@ if [ -z $ns2 ]; then
fi
soa="$ns1"
exp=$(date +%F -d "+ 1 year")
serial=$(date +'%Y%m%d01')
ttl=14400
# Reading template
@ -108,30 +88,13 @@ 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%)
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%)
template_data=$(echo "$template_data" | grep -v %ns4%)
fi
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding dns zone to the user config
# Add dns zone to the user config
echo "$template_data" |\
sed -e "s/%ip%/$ip/g" \
-e "s/%domain_idn%/$domain_idn/g" \
@ -140,25 +103,21 @@ 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
-e "s/%time%/$TIME/g" \
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
chmod 660 $USER_DATA/dns/$domain.conf
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' SERIAL='$serial' SRC='' RECORDS='$records'"
dns_rec="$dns_rec SUSPENDED='no' TIME='$time' DATE='$date'"
dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' TIME='$TIME'"
dns_rec="$dns_rec DATE='$DATE'"
echo "$dns_rec" >> $USER_DATA/dns.conf
chmod 660 $USER_DATA/dns.conf
# Creating system configs
# Create system configs
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
if [ -e '/etc/named.conf' ]; then
dns_conf='/etc/named.conf'
@ -176,14 +135,14 @@ if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
# Updating domain dns zone
update_domain_zone
# Changing permissions
chmod 640 $HOMEDIR/$user/conf/dns/$domain.db
chown root:$dns_group $HOMEDIR/$user/conf/dns/$domain.db
# Set permissions
chmod 640 $conf
chown root:$dns_group $conf
fi
# Updating dns-cluster queue
if [ ! -z "$DNS_CLUSTER" ]; then
cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
cmd="$BIN/v-add-remote-dns-domain $user $domain no"
echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
fi
@ -197,11 +156,15 @@ increase_user_value "$user" '$U_DNS_DOMAINS'
increase_user_value "$user" '$U_DNS_RECORDS' "$records"
# Restart named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed"
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "added dns domain $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add dns domain or dns record after web domain alias
# options: USER ALIAS IP [RESTART]
# info: add dns domain or dns record based on web domain alias restart
# options: USER DOMAIN
#
# The function adds dns domain or dns record based on web domain alias.
@ -9,11 +9,15 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
alias=$2
ip=$3
restart=$4
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"
# Includes
source $VESTA/func/main.sh
@ -25,54 +29,58 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER ALIAS IP [RESTART]'
is_format_valid 'user' 'alias' 'ip'
check_args '3' "$#" 'USER DOMAIN ALIAS'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ -e "$USER_DATA/dns/$alias.conf" ]; then
exit
fi
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
# Parsing domain values
get_domain_values 'web'
# 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 top-level 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)
# 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
else
check_record=$(grep -w "RECORD='$sub_domain'" $USER_DATA/dns/$top_domain.conf)
fi
# Check subdomain
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
# Adding subdomain record
if [ -z "$check_record" ]; then
$BIN/v-add-dns-record \
$user $top_domain "$sub_domain" A $ip '' '' $restart >> /dev/null
# 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
fi
@ -80,6 +88,6 @@ fi
# Vesta #
#----------------------------------------------------------#
# No logging
# No Logging
exit

View file

@ -12,10 +12,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
record=$(idn -t --quiet -u "$3" )
record=$(echo "$record" | tr '[:upper:]' '[:lower:]')
rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
@ -40,31 +41,18 @@ fi
# Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
trailing_dot=$(echo $dvalue | grep "\.$")
if [ -z "$trailing_dot" ]; then
if [ -z $trailing_dot ]; then
dvalue="$dvalue."
fi
fi
if [ $rtype != "CAA" ]; then
dvalue=${dvalue//\"/}
if [[ "$dvalue" =~ [\;[:space:]] ]]; then
dvalue='"'"$dvalue"'"'
fi
fi
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '5' "$#" 'USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART]'
is_format_valid 'user' 'domain' 'record' 'rtype' 'dvalue'
validate_format 'user' 'domain' 'record' 'rtype' 'dvalue'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -72,7 +60,7 @@ is_object_valid 'dns' 'DOMAIN' "$domain"
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
is_package_full 'DNS_RECORDS'
get_next_dnsrecord
is_format_valid 'id'
validate_format 'id'
is_object_new "dns/$domain" 'ID' "$id"
is_dns_fqnd "$rtype" "$dvalue"
is_dns_nameserver_valid "$domain" "$rtype" "$dvalue"
@ -82,15 +70,10 @@ is_dns_nameserver_valid "$domain" "$rtype" "$dvalue"
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding record
zone="$USER_DATA/dns/$domain.conf"
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
echo "$dns_rec" >> $zone
chmod 660 $zone
@ -99,7 +82,6 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -118,17 +100,21 @@ fi
# Vesta #
#----------------------------------------------------------#
# Update counters
# Upddate counters
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
increase_user_value "$user" '$U_DNS_RECORDS'
# Restart named
$BIN/v-restart-dns $restart
check_result $? $E_RESTART 'dns failed to restart'
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "added $rtype dns record $record for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -25,9 +25,9 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [IP] [RESTART]'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
if [ ! -z "$ip" ] ; then
is_format_valid 'ip'
validate_format 'ip'
fi
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -39,43 +39,50 @@ is_object_unsuspended 'user' 'USER' "$user"
# Get ip if it wasn't defined
if [ -z "$ip" ]; then
get_user_ip
ip=$(get_user_ip $user)
if [ -z "$ip" ]; then
check_result $E_NOTEXIST "no avaiable IP address"
echo "Error: no avaiable IP address"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
fi
# Working on web domain
# Web domain
if [ ! -z "$WEB_SYSTEM" ]; then
$BIN/v-add-web-domain $user $domain $ip 'no'
check_result $? "can't add web domain" >/dev/null
return_code=$?
fi
# 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
# 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'
fi
# Working on mail domain
if [ ! -z "$MAIL_SYSTEM" ]; then
# 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
$BIN/v-add-mail-domain $user $domain
check_result $? "can't add mail domain" >/dev/null
return_code=$?
fi
# Restarting services
$BIN/v-restart-web $restart
check_result $? "can't restart web" > /dev/null
$BIN/v-restart-proxy $restart
check_result $? "can't restart proxy" > /dev/null
$BIN/v-restart-dns $restart
check_result $? "can't restart dns" > /dev/null
# Restart services
if [ "$restart" != 'no' ] && [ "$return_code" -eq 0 ]; then
$BIN/v-restart-web
$BIN/v-restart-proxy
$BIN/v-restart-dns
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit
exit $return_code

View file

@ -12,7 +12,7 @@
# Importing system variables
source /etc/profile
# Argument definition
# Argument defenition
ip=$1
chain=$(echo $2|tr '[:lower:]' '[:upper:]')
@ -29,7 +29,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'IP CHAIN'
is_format_valid 'ip' 'chain'
validate_format 'ip' 'chain'
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
@ -59,13 +59,8 @@ fi
# Adding chain
$BIN/v-add-firewall-chain $chain
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding ip to banlist
echo "IP='$ip' CHAIN='$chain' TIME='$time' DATE='$date'" >> $conf
echo "IP='$ip' CHAIN='$chain' TIME='$TIME' DATE='$DATE'" >> $conf
$iptables -I fail2ban-$chain 1 -s $ip \
-j REJECT --reject-with icmp-port-unreachable 2>/dev/null
@ -78,6 +73,6 @@ chmod 660 $conf
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -12,7 +12,7 @@
# Importing system variables
source /etc/profile
# Argument definition
# Argument defenition
chain=$(echo $1 | tr '[:lower:]' '[:upper:]')
port=$2
protocol=${4-TCP}
@ -21,12 +21,6 @@ protocol=$(echo $protocol|tr '[:lower:]' '[:upper:]')
# Defining absolute path to iptables
iptables="/sbin/iptables"
# Get vesta port by reading nginx.conf
vestaport=$(grep 'listen' $VESTA/nginx/conf/nginx.conf | awk '{print $2}' | sed "s|;||")
if [ -z "$vestaport" ]; then
vestaport=8083
fi
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
@ -37,7 +31,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '1' "$#" 'CHAIN [PORT] [PROTOCOL]'
is_format_valid 'chain'
validate_format 'chain'
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
@ -47,19 +41,13 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
# Checking known chains
case $chain in
SSH) # Get ssh port by reading ssh config file.
sshport=$(grep '^Port ' /etc/ssh/sshd_config | head -1 | cut -d ' ' -f 2)
if [ -z "$sshport" ]; then
sshport=22
fi
port=$sshport;
protocol=TCP ;;
SSH) port=22; protocol=TCP ;;
FTP) port=21; protocol=TCP ;;
MAIL) port='25,465,587,2525,110,995,143,993'; protocol=TCP ;;
DNS) port=53; protocol=UDP ;;
WEB) port='80,443'; protocol=TCP ;;
DB) port='3306,5432'; protocol=TCP ;;
VESTA) port=$vestaport; protocol=TCP ;;
VESTA) port=8083; protocol=TCP ;;
*) check_args '2' "$#" 'CHAIN PORT' ;;
esac
@ -93,6 +81,6 @@ chmod 660 $chains
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -12,7 +12,7 @@
# Importing system variables
source /etc/profile
# Argument definition
# Argument defenition
action=$(echo $1|tr '[:lower:]' '[:upper:]')
ip=$2
port_ext=$3
@ -47,13 +47,13 @@ sort_fw_rules() {
#----------------------------------------------------------#
check_args '3' "$#" 'ACTION IP PORT [PROTOCOL] [COMMENT] [RULE]'
is_format_valid 'action' 'protocol' 'port_ext' 'ip'
validate_format 'action' 'protocol' 'port_ext' 'ip'
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
get_next_fw_rule
is_format_valid 'rule'
validate_format 'rule'
is_object_new '../../data/firewall/rules' 'RULE' "$rule"
if [ ! -z "$comment" ]; then
is_format_valid 'comment'
if [ ! -z "$comment"]; then
validate_format 'comment'
fi
@ -61,15 +61,10 @@ fi
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatenating rule
str="RULE='$rule' ACTION='$action' PROTOCOL='$protocol' PORT='$port_ext'"
str="$str IP='$ip' COMMENT='$comment' SUSPENDED='no'"
str="$str TIME='$time' DATE='$date'"
str="$str TIME='$TIME' DATE='$DATE'"
# Adding to config
echo "$str" >> $VESTA/data/firewall/rules.conf
@ -89,6 +84,6 @@ $BIN/v-update-firewall
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,76 +0,0 @@
#!/bin/bash
# info: archive directory
# options: USER ARCHIVE SOURCE
#
# The function creates tar archive
user=$1
archive=$2
src0=$3
# Checking arguments
if [ -z "$src0" ]; then
echo "Usage: USER ARCHIVE FILE [FILE_2] [FILE_3] [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 archive
if [ -e "$archive" ]; then
echo "Error: archive already exist $archive"
exit 1
fi
# Checking source path
IFS=$'\n'
i=1
for src in $*; do
if [ "$i" -gt 2 ]; then
rpath=$(readlink -f "$src")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
echo "Error: invalid source path $src"
exit 1
fi
fi
((i++))
done
i=1
for src in $*; do
if [ "$i" -gt 2 ]; then
# Deleting leading home path
src=$(echo "$src"| sed -e "s|/home/$user/||")
# Creating tar.gz archive
sudo -u $user tar -rf "${archive/.gz/}" -C /home/$user $src >\
/dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo "Error: archive $archive was not created"
exit 3
fi
fi
((i++))
done
# Checking gzip
if [[ "$archive" =~ \.gz$ ]]; then
sudo -u $user gzip "${archive/.gz/}" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo "Error: archive $archive was not gziped"
exit 3
fi
fi
exit

View file

@ -1,44 +0,0 @@
#!/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

View file

@ -1,44 +0,0 @@
#!/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

@ -1,399 +0,0 @@
#!/bin/bash
# info: check letsencrypt domain
# options: USER DOMAIN [ALIASES]
#
# The function check and validates domain with Let's Encript
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
aliases=$3
# LE API
API='https://acme-v02.api.letsencrypt.org'
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_identifier_idn() {
identifier_idn=$identifier
if [[ "$identifier_idn" = *[![:ascii:]]* ]]; then
identifier_idn=$(idn -t --quiet -a $identifier_idn)
fi
}
# encode base64
encode_base64() {
cat |base64 |tr '+/' '-_' |tr -d '\r\n='
}
# Let's Encrypt v2 curl function
query_le_v2() {
protected='{"nonce": "'$3'",'
protected=''$protected' "url": "'$1'",'
protected=''$protected' "alg": "RS256", "kid": "'$KID'"}'
content="Content-Type: application/jose+json"
payload_=$(echo -n "$2" |encode_base64)
protected_=$(echo -n "$protected" |encode_base64)
signature_=$(printf "%s" "$protected_.$payload_" |\
openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key |\
encode_base64)
post_data='{"protected":"'"$protected_"'",'
post_data=$post_data'"payload":"'"$payload_"'",'
post_data=$post_data'"signature":"'"$signature_"'"}'
# Save http response to file passed as "$4" arg or print to stdout if not provided
# http response headers are always sent to stdout
local save_to_file=${4:-"/dev/stdout"}
curl --silent --dump-header /dev/stdout --data "$post_data" "$1" --header "$content" --output "$save_to_file"
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [ALIASES]'
is_format_valid 'user' 'domain' 'aliases'
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"
get_domain_values 'web'
echo "-----------------------------------------------------------------------------------" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : v-add-letsencrypt-domain $domain [$aliases]" >> /usr/local/vesta/log/letsencrypt.log
# check if alias is the letsencrypt wildcard domain, if not, make the normal checks
if [[ "$aliases" != "*.$domain" ]]; then
for alias in $(echo "$aliases" |tr ',' '\n' |sort -u); do
check_alias="$(echo $ALIAS |tr ',' '\n' |grep ^$alias$)"
if [ -z "$check_alias" ]; then
echo "[$(date)] : EXIT=domain alias $alias doesn't exist" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_NOTEXIST "domain alias $alias doesn't exist"
fi
done
fi;
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Registering LetsEncrypt user account
echo "[$(date)] : v-add-letsencrypt-user $user" >> /usr/local/vesta/log/letsencrypt.log
$BIN/v-add-letsencrypt-user $user
echo "[$(date)] : result: $?" >> /usr/local/vesta/log/letsencrypt.log
if [ "$?" -ne 0 ]; then
touch $VESTA/data/queue/letsencrypt.pipe
sed -i "/ $domain /d" $VESTA/data/queue/letsencrypt.pipe
send_notice "LETSENCRYPT" "Account registration failed"
echo "[$(date)] : EXIT=LE account registration" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "LE account registration" >/dev/null
fi
# Parsing LetsEncrypt account data
source $USER_DATA/ssl/le.conf
# Checking wildcard alias
if [ "$aliases" = "*.$domain" ]; then
echo "[$(date)] : Checking wildcard alias" >> /usr/local/vesta/log/letsencrypt.log
wildcard='yes'
proto="dns-01"
if [ ! -e "$VESTA/data/users/$user/dns/$domain.conf" ]; then
echo "[$(date)] : EXIT=DNS domain $domain doesn't exist" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_NOTEXIST "DNS domain $domain doesn't exist"
fi
else
proto="http-01"
fi
# Requesting nonce / STEP 1
echo "[$(date)] : --- Requesting nonce / STEP 1 ---" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : curl -s -I \"$API/directory\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(curl -s -I "$API/directory")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
echo "[$(date)] : nonce=$nonce" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 200 ]]; then
echo "[$(date)] : EXIT=Let's Encrypt nonce request status $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt nonce request status $status"
fi
# Placing new order / STEP 2
echo "[$(date)] : --- Placing new order / STEP 2 ---" >> /usr/local/vesta/log/letsencrypt.log
url="$API/acme/new-order"
payload='{"identifiers":['
for identifier in $(echo $domain,$aliases |tr ',' '\n' |sort -u); do
format_identifier_idn
payload=$payload'{"type":"dns","value":"'$identifier_idn'"},'
done
payload=$(echo "$payload"|sed "s/,$//")
payload=$payload']}'
echo "[$(date)] : payload=$payload" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : query_le_v2 \"$url\" \"$payload\" \"$nonce\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(query_le_v2 "$url" "$payload" "$nonce")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
echo "[$(date)] : nonce=$nonce" >> /usr/local/vesta/log/letsencrypt.log
authz=$(echo "$answer" |grep "acme/authz" |cut -f2 -d '"')
echo "[$(date)] : authz=$authz" >> /usr/local/vesta/log/letsencrypt.log
finalize=$(echo "$answer" |grep 'finalize":' |cut -f4 -d '"')
echo "[$(date)] : finalize=$finalize" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer" |grep HTTP/ |tail -n1 |cut -f2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 201 ]]; then
echo "[$(date)] : EXIT=Let's Encrypt new auth status $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt new auth status $status"
fi
# Requesting authorization token / STEP 3
echo "[$(date)] : --- Requesting authorization token / STEP 3 ---" >> /usr/local/vesta/log/letsencrypt.log
for auth in $authz; do
payload=''
echo "[$(date)] : for auth=$auth" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : query_le_v2 \"$auth\" \"$payload\" \"$nonce\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(query_le_v2 "$auth" "$payload" "$nonce")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
url=$(echo "$answer" |grep -A3 $proto |grep '"url"' |cut -f 4 -d \")
echo "[$(date)] : url=$url" >> /usr/local/vesta/log/letsencrypt.log
token=$(echo "$answer" |grep -A3 $proto |grep token |cut -f 4 -d \")
echo "[$(date)] : token=$token" >> /usr/local/vesta/log/letsencrypt.log
nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
echo "[$(date)] : nonce=$nonce" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 200 ]]; then
echo "[$(date)] : EXIT=Let's Encrypt acme/authz bad status $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt acme/authz bad status $status"
fi
# Configuring challenge / STEP 4
echo "[$(date)] : --- Configuring challenge / STEP 4 ---" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : wildcard=$wildcard" >> /usr/local/vesta/log/letsencrypt.log
if [ "$wildcard" = 'yes' ]; then
record=$(printf "%s" "$token.$THUMB" |\
openssl dgst -sha256 -binary |encode_base64)
old_records=$($BIN/v-list-dns-records $user $domain plain|grep 'TXT')
old_records=$(echo "$old_records" |grep _acme-challenge |cut -f 1)
for old_record in $old_records; do
$BIN/v-delete-dns-record "$user" "$domain" "$old_record"
done
$BIN/v-add-dns-record "$user" "$domain" "_acme-challenge" "TXT" "$record"
exitstatus=$?
echo "[$(date)] : v-add-dns-record \"$user\" \"$domain\" \"_acme-challenge\" \"TXT\" \"$record\"" >> /usr/local/vesta/log/letsencrypt.log
if [ "$exitstatus" -ne 0 ]; then
echo "[$(date)] : EXIT=DNS _acme-challenge record wasn't created" >> /usr/local/vesta/log/letsencrypt.log
fi
check_result $exitstatus "DNS _acme-challenge record wasn't created"
else
if [ "$WEB_SYSTEM" = 'nginx' ] || [ ! -z "$PROXY_SYSTEM" ]; then
if [ -f "/usr/local/vesta/web/inc/nginx_proxy" ]; then
# if vesta is behind main nginx
well_known="$HOMEDIR/$user/web/$domain/public_html/.well-known"
acme_challenge="$well_known/acme-challenge"
mkdir -p $acme_challenge
echo "$token.$THUMB" > $acme_challenge/$token
echo "[$(date)] : in $acme_challenge/$token we put: $token.$THUMB" >> /usr/local/vesta/log/letsencrypt.log
chown -R $user:$user $well_known
else
# default nginx method
conf="$HOMEDIR/$user/conf/web/nginx.$domain.conf_letsencrypt"
sconf="$HOMEDIR/$user/conf/web/snginx.$domain.conf_letsencrypt"
# if [ ! -e "$conf" ]; then
echo 'location ~ "^/\.well-known/acme-challenge/(.*)$" {' \
> $conf
echo ' default_type text/plain;' >> $conf
echo ' return 200 "$1.'$THUMB'";' >> $conf
echo '}' >> $conf
# fi
echo "[$(date)] : in $conf we put: $THUMB" >> /usr/local/vesta/log/letsencrypt.log
if [ ! -e "$sconf" ]; then
ln -s "$conf" "$sconf"
fi
echo "[$(date)] : v-restart-proxy" >> /usr/local/vesta/log/letsencrypt.log
$BIN/v-restart-proxy
if [ -z "$PROXY_SYSTEM" ]; then
# apache-less variant
echo "[$(date)] : v-restart-web" >> /usr/local/vesta/log/letsencrypt.log
$BIN/v-restart-web
fi
exitstatus=$?
if [ "$exitstatus" -ne 0 ]; then
echo "[$(date)] : EXIT=Proxy restart failed = $exitstatus" >> /usr/local/vesta/log/letsencrypt.log
fi
check_result $exitstatus "Proxy restart failed" >/dev/null
fi
else
well_known="$HOMEDIR/$user/web/$domain/public_html/.well-known"
acme_challenge="$well_known/acme-challenge"
mkdir -p $acme_challenge
echo "$token.$THUMB" > $acme_challenge/$token
chown -R $user:$user $well_known
echo "[$(date)] : in $acme_challenge/$token we put: $token.$THUMB" >> /usr/local/vesta/log/letsencrypt.log
# $BIN/v-restart-web
# check_result $? "Web restart failed" >/dev/null
fi
fi
# Requesting ACME validation / STEP 5
echo "[$(date)] : --- Requesting ACME validation / STEP 5 ---" >> /usr/local/vesta/log/letsencrypt.log
validation_check=$(echo "$answer" |grep '"valid"')
echo "[$(date)] : validation_check=$validation_check" >> /usr/local/vesta/log/letsencrypt.log
if [[ ! -z "$validation_check" ]]; then
validation='valid'
else
validation='pending'
fi
# Doing pol check on status
i=1
while [ "$validation" = 'pending' ]; do
echo "[$(date)] : - Doing pol check on status" >> /usr/local/vesta/log/letsencrypt.log
payload='{}'
echo "[$(date)] : query_le_v2 \"$url\" \"$payload\" \"$nonce\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(query_le_v2 "$url" "$payload" "$nonce")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
validation=$(echo "$answer"|grep -A1 $proto |tail -n1|cut -f4 -d \")
echo "[$(date)] : validation=$validation" >> /usr/local/vesta/log/letsencrypt.log
nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
echo "[$(date)] : nonce=$nonce" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 200 ]]; then
echo "[$(date)] : EXIT=Let's Encrypt validation status $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt validation status $status"
fi
i=$((i + 1))
if [ "$i" -gt 10 ]; then
echo "[$(date)] : EXIT=Let's Encrypt domain validation timeout" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt domain validation timeout"
fi
sleeping=$((i*2))
echo "[$(date)] : sleep $sleeping (i=$i)" >> /usr/local/vesta/log/letsencrypt.log
sleep $sleeping
done
if [ "$validation" = 'invalid' ]; then
echo "[$(date)] : EXIT=Let's Encrypt domain verification failed" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt domain verification failed"
fi
done
# Generating new ssl certificate
ssl_dir=$($BIN/v-generate-ssl-cert "$domain" "info@$domain" "US" "California"\
"San Francisco" "Vesta" "IT" "$aliases" |tail -n1 |awk '{print $2}')
# Sending CSR to finalize order / STEP 6
echo "[$(date)] : --- Sending CSR to finalize order / STEP 6 ---" >> /usr/local/vesta/log/letsencrypt.log
csr=$(openssl req -in $ssl_dir/$domain.csr -outform DER |encode_base64)
payload='{"csr":"'$csr'"}'
echo "[$(date)] : query_le_v2 \"$finalize\" \"$payload\" \"$nonce\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(query_le_v2 "$finalize" "$payload" "$nonce")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
echo "[$(date)] : nonce=$nonce" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
certificate=$(echo "$answer"|grep 'certificate":' |cut -f4 -d '"')
echo "[$(date)] : certificate=$certificate" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 200 ]]; then
echo "[$(date)] : EXIT=Let's Encrypt finalize bad status $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_CONNECT "Let's Encrypt finalize bad status $status"
fi
# Downloading signed certificate / STEP 7
echo "[$(date)] : --- Downloading signed certificate / STEP 7 ---" >> /usr/local/vesta/log/letsencrypt.log
echo "[$(date)] : query_le_v2 \"$certificate\" \"\" \"$nonce\"" >> /usr/local/vesta/log/letsencrypt.log
answer=$(query_le_v2 "$certificate" "" "$nonce" "$ssl_dir/$domain.pem")
echo "[$(date)] : answer=$answer" >> /usr/local/vesta/log/letsencrypt.log
status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
echo "[$(date)] : status=$status" >> /usr/local/vesta/log/letsencrypt.log
if [[ "$status" -ne 200 ]]; then
[ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
echo "[$(date)] : EXIT=Let's Encrypt downloading signed cert failed status: $status" >> /usr/local/vesta/log/letsencrypt.log
check_result $E_NOTEXIST "Let's Encrypt downloading signed cert failed status: $status"
fi
# Splitting up downloaded pem
# echo "[$(date)] : - Splitting up downloaded pem" >> /usr/local/vesta/log/letsencrypt.log
crt_end=$(grep -n 'END CERTIFICATE' $ssl_dir/$domain.pem |head -n1 |cut -f1 -d:)
# echo "[$(date)] : crt_end=$crt_end" >> /usr/local/vesta/log/letsencrypt.log
head -n $crt_end $ssl_dir/$domain.pem > $ssl_dir/$domain.crt
pem_lines=$(wc -l $ssl_dir/$domain.pem |cut -f 1 -d ' ')
# echo "[$(date)] : pem_lines=$pem_lines" >> /usr/local/vesta/log/letsencrypt.log
ca_end=$(grep -n 'BEGIN CERTIFICATE' $ssl_dir/$domain.pem |tail -n1 |cut -f 1 -d :)
# echo "[$(date)] : ca_end=$ca_end" >> /usr/local/vesta/log/letsencrypt.log
ca_end=$(( pem_lines - crt_end + 1 ))
# echo "[$(date)] : ca_end=$ca_end" >> /usr/local/vesta/log/letsencrypt.log
tail -n $ca_end $ssl_dir/$domain.pem > $ssl_dir/$domain.ca
# Temporary fix for double "END CERTIFICATE"
if [[ $(head -n 1 $ssl_dir/$domain.ca) = "-----END CERTIFICATE-----" ]]; then
sed -i '1,2d' $ssl_dir/$domain.ca
fi
# Adding SSL
ssl_home=$(search_objects 'web' 'LETSENCRYPT' 'yes' 'SSL_HOME')
$BIN/v-delete-web-domain-ssl $user $domain >/dev/null 2>&1
echo "[$(date)] : v-add-web-domain-ssl $user $domain $ssl_dir $ssl_home" >> /usr/local/vesta/log/letsencrypt.log
$BIN/v-add-web-domain-ssl $user $domain $ssl_dir $ssl_home
exitstatus=$?
echo "[$(date)] : v-add-web-domain-ssl status: $exitstatus" >> /usr/local/vesta/log/letsencrypt.log
if [ "$exitstatus" -ne '0' ]; then
touch $VESTA/data/queue/letsencrypt.pipe
sed -i "/ $domain /d" $VESTA/data/queue/letsencrypt.pipe
echo "[$(date)] : EXIT=$domain certificate installation failed" >> /usr/local/vesta/log/letsencrypt.log
send_notice 'LETSENCRYPT' "$domain certificate installation failed"
check_result $exitstatus "SSL install" >/dev/null
fi
# Adding LE autorenew cronjob
if [ -z "$(grep v-update-lets $VESTA/data/users/admin/cron.conf)" ]; then
min=$(generate_password '012345' '2')
hour=$(generate_password '1234567' '1')
cmd="sudo $BIN/v-update-letsencrypt-ssl"
$BIN/v-add-cron-job admin "$min" "$hour" '*' '*' '*' "$cmd" > /dev/null
fi
# Updating letsencrypt key
if [ -z "$LETSENCRYPT" ]; then
add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT' 'FTP_USER'
fi
update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT' 'yes'
reset_web_counter "$user" "$domain" 'LETSENCRYPT_FAIL_COUNT'
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Deleteing task from queue
touch $VESTA/data/queue/letsencrypt.pipe
sed -i "/ $domain /d" $VESTA/data/queue/letsencrypt.pipe
# Notifying user
send_notice 'LETSENCRYPT' "$domain SSL has been installed successfully"
echo "[$(date)] : EXIT=***** $domain SSL has been installed successfully *****" >> /usr/local/vesta/log/letsencrypt.log
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,141 +0,0 @@
#!/bin/bash
# info: register letsencrypt user account
# options: USER
#
# The function creates and register LetsEncript account
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
# LE API
API='https://acme-v02.api.letsencrypt.org'
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# encode base64
encode_base64() {
cat |base64 |tr '+/' '-_' |tr -d '\r\n='
}
# Let's Encrypt v2 curl function
query_le_v2() {
protected='{"nonce": "'$3'",'
protected=''$protected' "url": "'$1'",'
protected=''$protected' "alg": "RS256", "jwk": '$jwk'}'
content="Content-Type: application/jose+json"
payload_=$(echo -n "$2" |encode_base64)
protected_=$(echo -n "$protected" |encode_base64)
signature_=$(printf "%s" "$protected_.$payload_" |\
openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key |\
encode_base64)
post_data='{"protected":"'"$protected_"'",'
post_data=$post_data'"payload":"'"$payload_"'",'
post_data=$post_data'"signature":"'"$signature_"'"}'
curl -s -i -d "$post_data" "$1" -H "$content"
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"
if [ -e "$USER_DATA/ssl/le.conf" ]; then
source "$USER_DATA/ssl/le.conf"
fi
if [ ! -z "$KID" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining user email
if [[ -z "$EMAIL" ]]; then
EMAIL=$(get_user_value '$CONTACT')
fi
# Defining user agreement
agreement=''
# Generating user key
KEY="$USER_DATA/ssl/user.key"
if [ ! -e "$KEY" ]; then
openssl genrsa -out $KEY 4096 >/dev/null 2>&1
chmod 600 $KEY
fi
# Defining key exponent
if [ -z "$EXPONENT" ]; then
EXPONENT=$(openssl pkey -inform pem -in "$KEY" -noout -text_pub |\
grep Exponent: |cut -f 2 -d '(' |cut -f 1 -d ')' |sed -e 's/x//' |\
xxd -r -p |encode_base64)
fi
# Defining key modulus
if [ -z "$MODULUS" ]; then
MODULUS=$(openssl rsa -in "$KEY" -modulus -noout |\
sed -e 's/^Modulus=//' |xxd -r -p |encode_base64)
fi
# Defining JWK
jwk='{"e":"'$EXPONENT'","kty":"RSA","n":"'"$MODULUS"'"}'
# Defining key thumbnail
if [ -z "$THUMB" ]; then
THUMB="$(echo -n "$jwk" |openssl dgst -sha256 -binary |encode_base64)"
fi
# Requesting ACME nonce
nonce=$(curl -s -I "$API/directory" |grep -i nonce |cut -f2 -d\ |tr -d '\r\n')
# Creating ACME account
url="$API/acme/new-acct"
payload='{"termsOfServiceAgreed": true}'
answer=$(query_le_v2 "$url" "$payload" "$nonce")
kid=$(echo "$answer" |grep -i location: |cut -f2 -d ' '|tr -d '\r')
# Checking answer status
status=$(echo "$answer" |grep HTTP/ |tail -n1 |cut -f2 -d ' ')
if [[ "${status:0:2}" -ne "20" ]]; then
check_result $E_CONNECT "Let's Encrypt acc registration failed $status"
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding le.conf
if [ ! -e "$USER_DATA/ssl/le.conf" ]; then
echo "EXPONENT='$EXPONENT'" > $USER_DATA/ssl/le.conf
echo "MODULUS='$MODULUS'" >> $USER_DATA/ssl/le.conf
echo "THUMB='$THUMB'" >> $USER_DATA/ssl/le.conf
echo "EMAIL='$EMAIL'" >> $USER_DATA/ssl/le.conf
echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
chmod 660 $USER_DATA/ssl/le.conf
else
sed -i '/^KID=/d' $USER_DATA/ssl/le.conf
echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -9,22 +9,23 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
account=$3
password=$4; HIDE=4
quota=${5-unlimited}
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}
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
if [[ "$account" =~ [[:upper:]] ]]; then
account=$(echo "$account" |tr '[:upper:]' '[:lower:]')
fi
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
@ -32,10 +33,7 @@ fi
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD [QUOTA]'
is_format_valid 'user' 'domain' 'account'
if [ "$quota" != 'unlimited' ]; then
is_format_valid 'quota'
fi
validate_format 'user' 'domain' 'account' 'password' 'quota'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -43,22 +41,19 @@ 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 #
#----------------------------------------------------------#
# Generating hashed password
salt=$(generate_password "$PW_MATRIX" "8")
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
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
# 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
@ -68,18 +63,9 @@ fi
# Vesta #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
if [[ "$quota" -eq '0' ]]; then
quota='unlimited'
fi
str="ACCOUNT='$account' ALIAS='' AUTOREPLY='no' FWD='' FWD_ONLY=''"
str="$str MD5='$md5' QUOTA='$quota' U_DISK='0' SUSPENDED='no'"
str="$str TIME='$time' DATE='$date'"
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'"
echo "$str" >> $USER_DATA/mail/$domain.conf
chmod 660 $USER_DATA/mail/$domain.conf
@ -90,6 +76,6 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
# Logging
log_history "added mail account $account@$domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
malias=$4
@ -21,18 +22,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT ALIAS'
is_format_valid 'user' 'domain' 'account' 'malias'
validate_format 'user' 'domain' 'account' 'malias'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -49,7 +45,7 @@ is_mail_new "$malias"
# Adding exim alias
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
str="$malias@$domain_idn:$account@$domain_idn"
str="$malias@$domain:$account@$domain"
echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
fi
@ -69,6 +65,6 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
# Logging
log_history "added alias $malias to $account@$domain "
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
autoreply=$4
@ -28,18 +29,13 @@ else
MAIL_USER=exim
fi
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT MESSAGE'
is_format_valid 'user' 'domain' 'account' 'autoreply'
validate_format 'user' 'domain' 'account' 'autoreply'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -74,6 +70,6 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY' 'yes'
# Logging
log_history "added autoreply message on $account@$domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
forward=$4
@ -21,17 +22,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT FORWARD'
is_format_valid 'user' 'domain' 'account' 'forward'
validate_format 'user' 'domain' 'account' 'forward'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -42,7 +39,7 @@ is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
if [ ! -z "$(echo $fwd | grep -w $forward)" ]; then
echo "Error: forward $forward exists"
log_event "$E_EXISTS $ARGUMENTS"
log_event "$E_EXISTS $EVENT"
exit $E_EXISTS
fi
@ -60,8 +57,8 @@ fi
# Adding forward to exim
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "$account@$domain_idn:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
sed -i "/^$account@$domain:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "$account@$domain:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
fi
@ -74,6 +71,6 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
# Logging
log_history "added forwarding from $account@$domain to $forward"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
# Includes
@ -27,18 +28,13 @@ else
MAIL_USER=exim
fi
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN ACCOUNT'
is_format_valid 'user' 'domain' 'account'
validate_format 'user' 'domain' 'account'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -49,7 +45,7 @@ is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
if [ -z "$fwd" ]; then
echo "Error: forward doesn't exist"
log_event "$E_NOTEXIST $ARGUMENTS"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
@ -60,7 +56,7 @@ fi
# Adding account to fwd_only
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
echo "$account" >> $HOMEDIR/$user/conf/mail/$domain/fwd_only
echo "$account" > $HOMEDIR/$user/conf/mail/$domain/fwd_only
chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/fwd_only
fi
@ -75,6 +71,6 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' "yes"
# Logging
log_history "added fwd_only flag for $account@$domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,9 +9,12 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
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")
antispam=${3-yes}
antivirus=${4-yes}
dkim=${5-yes}
@ -29,38 +32,28 @@ else
MAIL_USER=exim
fi
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [ANTISPAM] [ANTIVIRUS] [DKIM] [DKIM_SIZE]'
is_format_valid 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
validate_format 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_domain_new 'mail' "$domain"
is_domain_new 'mail'
is_package_full 'MAIL_DOMAINS'
is_dir_symlink $HOMEDIR/$user/mail
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding domain to mail.conf
s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
s="$s CATCHALL='' ACCOUNTS='0' U_DISK='0' SUSPENDED='no' TIME='$time'"
s="$s DATE='$date'"
s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' TIME='$TIME'"
s="$s DATE='$DATE'"
echo $s >> $USER_DATA/mail.conf
touch $USER_DATA/mail/$domain.conf
@ -120,10 +113,10 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$dkim" = 'yes' ]; then
p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
record='_domainkey'
policy="\"t=y; o=~;\""
$BIN/v-add-dns-record $user $domain $record TXT "$policy" '' '' 'no'
$BIN/v-add-dns-record $user $domain $record TXT "$policy"
record='mail._domainkey'
selector="\"v=DKIM1\; k=rsa\; p=$p\""
selector="\"k=rsa\; p=$p\""
$BIN/v-add-dns-record $user $domain $record TXT "$selector"
fi
fi
@ -141,6 +134,6 @@ fi
# Logging
log_history "added mail domain $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -2,35 +2,31 @@
# info: add mail domain antispam support
# options: USER DOMAIN
#
# The function enables spamassasin for incoming emails.
# The function enables spamassasin for incomming emails.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -58,6 +54,6 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$ANTISPAM' 'yes'
# Logging
log_history "enabled antispam on $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -2,35 +2,31 @@
# info: add mail domain antivirus support
# options: USER DOMAIN
#
# The function enables clamav scan for incoming emails.
# The function enables clamav scan for incomming emails.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -58,6 +54,6 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$ANTIVIRUS' 'yes'
# Logging
log_history "enabled antivirus on $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -2,17 +2,18 @@
# info: add mail domain catchall account
# options: USER DOMAIN EMAIL
#
# The function enables catchall account for incoming emails.
# The function enables catchall account for incomming emails.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
email="$3"
# Includes
@ -20,17 +21,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN EMAIL'
is_format_valid 'user' 'domain' 'email'
validate_format 'user' 'domain' 'email'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -45,8 +42,8 @@ is_object_value_empty 'mail' 'DOMAIN' "$domain" '$CATCHALL'
# Adding catchall alias
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
sed -i "/*@$domain_idn:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "*@$domain_idn:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
sed -i "/*@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "*@$domain:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
fi
@ -59,6 +56,6 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$CATCHALL' "$email"
# Logging
log_history "added $email as catchall email for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
dkim_size=${3-1024}
# Includes
@ -27,18 +28,13 @@ else
MAIL_USER=exim
fi
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [DKIM_SIZE]'
is_format_valid 'user' 'domain' 'dkim_size'
validate_format 'user' 'domain' 'dkim_size'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -67,12 +63,12 @@ fi
# Adding dns records
if [ ! -z "$DNS_SYSTEM" ] && [ -e "$USER_DATA/dns/$domain.conf" ]; then
p=$(cat $USER_DATA/mail/$domain.pub |grep -v ' KEY---' |tr -d '\n')
record="_domainkey"
record='_domainkey'
policy="\"t=y; o=~;\""
$BIN/v-add-dns-record $user $domain $record TXT "$policy" '' '' 'no'
$BIN/v-add-dns-record $user $domain $record TXT "$policy"
record="mail._domainkey"
selector="\"v=DKIM1\; k=rsa\; p=$p\""
record='mail._domainkey'
selector="\"k=rsa\; p=$p\""
$BIN/v-add-dns-record $user $domain $record TXT "$selector"
fi
@ -83,10 +79,10 @@ fi
# Adding dkim in config
update_object_value 'mail' 'DOMAIN' "$domain" '$DKIM' 'yes'
increase_user_value "$user" '$U_MAIL_DKIM'
increase_user_value "$user" '$U_MAIL_DKMI'
# Logging
log_history "enabled DKIM support for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,12 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
flush=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/remote.sh
@ -26,61 +25,103 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [FLUSH]'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_procces_running
remote_dns_health_check
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain record
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
if [ -z "$str" ]; then
# Check domain existance
check_local_domain=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
if [ -z "$check_local_domain" ]; then
pipe="$VESTA/data/queue/dns-cluster.pipe"
queue_str=$(grep -n "$SCRIPT $1 $2 " $pipe |cut -f1 -d: |head -n1)
if [ ! -z "$queue_str" ]; then
sed -i "$queue_str d" $pipe
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit
fi
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Parsing remote dns host parameters
eval $cluster
# Check remote dns nodes
remote_dns_health_check
# Parsing domain parameters
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)
eval $str
# Syncing domain data
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
check_result $? "$HOST connection failed" $E_CONNECT
$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 records
tmp_file="/tmp/vst-sync.$DOMAIN"
cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
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
# 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
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
# Update pipe
rm -f $tmpfile
pipe="$VESTA/data/queue/dns-cluster.pipe"
str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
@ -88,4 +129,8 @@ if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -9,17 +9,12 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
host=$1
HOST=$host
port=$2
PORT=$port
user=$3
USER=$user
password=$4; HIDE=4
PASSWORD=$password
password=$4
type=${5-api}
TYPE="$type"
dns_user=${6-dns-cluster}
DNS_USER=$dns_user
@ -28,6 +23,9 @@ source $VESTA/func/main.sh
source $VESTA/func/remote.sh
source $VESTA/conf/vesta.conf
# Hiding passwords
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -35,9 +33,8 @@ source $VESTA/conf/vesta.conf
args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]'
check_args '4' "$#" "$args_usage"
is_format_valid 'host' 'port' 'user' 'type' 'dns_user'
validate_format 'host' 'port' 'user' 'password' 'type' 'dns_user'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_password_valid
is_dnshost_new
is_dnshost_alive
@ -46,15 +43,10 @@ is_dnshost_alive
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatentating dns host string
str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
str="$str TIME='$time' DATE='$date'"
str="$str TIME='$TIME' DATE='$DATE'"
# Adding host to dns-cluster.conf
echo "$str" >> $VESTA/conf/dns-cluster.conf
@ -67,27 +59,37 @@ else
sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
fi
# Enabling remote dns-cluster queue
cluster_cmd v-add-cron-restart-job
check_result $? "$HOST connection failed" $E_CONNECT
# 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
# Syncing all domains
# Sync current zones
$BIN/v-sync-dns-cluster $host
check_result $? "$HOST sync failed" $E_CONNECT
return_code=$?
if [ "$return_code" -ne 0 ]; then
exit $return_code
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding local dns-cluster cron job
# 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
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
id=$3
@ -25,61 +25,87 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN ID'
is_format_valid 'user' 'domain' 'id'
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_procces_running
remote_dns_health_check
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
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# 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
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Parsing remote host parameters
eval $cluster
# Check remote dns nodes
remote_dns_health_check
# 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
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Get host values
eval $cluster_str
# 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
# Check connection type
if [ -z "TYPE" ]; then
TYPE='api'
fi
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $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
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
# 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 #
#----------------------------------------------------------#
exit

View file

@ -1,11 +1,11 @@
#!/bin/bash
# info: add system ip address
# options: IP NETMASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
#
# The function adds ip address into a system. It also creates rc scripts. You
# can specify ip name which will be used as root domain for temporary aliases.
# For example, if you set a1.myhosting.com as name, each new domain created on
# this ip will automatically receive alias $domain.a1.myhosting.com. Of course
# this ip will automaticaly receive alias $domain.a1.myhosting.com. Of course
# you must have wildcard record *.a1.myhosting.com pointed to ip. This feature
# is very handy when customer wants to test domain before dns migration.
@ -14,9 +14,9 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
ip=${1// /}
netmask=$2
mask=$2
interface="${3-eth0}"
user="${4-admin}"
ip_status="${5-shared}"
@ -34,40 +34,36 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NATED_IP]'
is_format_valid 'ip' 'netmask' 'interface' 'user' 'ip_status'
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]'
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
is_ip_free
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ ! -z "$ip_name" ] ; then
is_format_valid 'ip_name'
validate_format 'ip_name'
fi
if [ ! -z "$nat_ip" ] ; then
is_format_valid 'nat_ip'
validate_format 'nat_ip'
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
iface=$(get_ip_iface)
cidr=$(convert_netmask $netmask)
broadcast=$(get_broadcast $ip $netmask)
sys_ip_check=$(/sbin/ip addr | grep "$ip")
get_ip_iface
sys_ip_check=$(/sbin/ifconfig | grep "addr:$ip ")
if [ -z "$sys_ip_check" ]; then
# Adding sys ip
/sbin/ip addr add $ip/$cidr dev $interface \
broadcast $broadcast label $iface
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
# Adding RHEL/CentOS/Fedora/Amazon startup script
if [ -d "/etc/sysconfig" ]; then
# Adding RHEL/CentOS/Fedora startup script
if [ -e "/etc/redhat-release" ]; then
sys_ip="# Added by vesta"
sys_ip="$sys_ip\nDEVICE=$iface"
sys_ip="$sys_ip\nBOOTPROTO=static"
sys_ip="$sys_ip\nONBOOT=yes"
sys_ip="$sys_ip\nIPADDR=$ip"
sys_ip="$sys_ip\nNETMASK=$netmask"
sys_ip="$sys_ip\nNETMASK=$mask"
echo -e $sys_ip > /etc/sysconfig/network-scripts/ifcfg-$iface
fi
@ -77,16 +73,11 @@ if [ -z "$sys_ip_check" ]; then
sys_ip="$sys_ip\nauto $iface"
sys_ip="$sys_ip\niface $iface inet static"
sys_ip="$sys_ip\naddress $ip"
sys_ip="$sys_ip\nnetmask $netmask"
sys_ip="$sys_ip\nnetmask $mask"
echo -e $sys_ip >> /etc/network/interfaces
fi
fi
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding vesta ip
echo "OWNER='$user'
STATUS='$ip_status'
@ -94,28 +85,23 @@ NAME='$ip_name'
U_SYS_USERS=''
U_WEB_DOMAINS='0'
INTERFACE='$interface'
NETMASK='$netmask'
NETMASK='$mask'
NAT='$nat_ip'
TIME='$time'
DATE='$date'" > $VESTA/data/ips/$ip
TIME='$TIME'
DATE='$DATE'" > $VESTA/data/ips/$ip
chmod 660 $VESTA/data/ips/$ip
# WEB support
if [ ! -z "$WEB_SYSTEM" ]; then
web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf"
rm -f $web_conf
if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf
fi
echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf
echo "Listen $ip:$WEB_PORT" >> $web_conf
fi
if [ "$WEB_SSL" = 'mod_ssl' ]; then
if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
echo "NameVirtualHost $ip:$WEB_SSL_PORT" >> $web_conf
fi
echo "NameVirtualHost $ip:$WEB_SSL_PORT" >> $web_conf
echo "Listen $ip:$WEB_SSL_PORT" >> $web_conf
fi
fi
@ -142,14 +128,6 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
rpaf_str="$rpaf_str $ip"
sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
fi
#mod_remoteip
remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
if [ -e "$remoteip_conf" ]; then
if [ $( grep -ic "$ip" $remoteip_conf ) -eq 0 ]; then
sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ip\n<\/IfModule>/g" $remoteip_conf
fi
fi
fi
@ -172,23 +150,18 @@ else
increase_user_value 'admin' '$IP_AVAIL'
fi
# Restarting web server
# Restart web server
$BIN/v-restart-web
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
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Restarting firewall
if [ ! -z "$FIREWALL_SYSTEM" ]; then
$BIN/v-update-firewall
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Logging
log_history "added system ip address $ip" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,106 +0,0 @@
#!/bin/bash
# info: copy mail ssl certificate
# options: USER DOMAIN [RESTART]
#
# The function copies user domain SSL to mail SSL directory
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
restart=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [RESTART]'
is_format_valid 'user' 'domain'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining certificate location
dom_crt="/home/$user/conf/web/ssl.$domain.pem"
dom_key="/home/$user/conf/web/ssl.$domain.key"
vst_crt="$VESTA/ssl/mail.crt"
vst_key="$VESTA/ssl/mail.key"
# Checking certificate
if [ ! -e "$dom_crt" ] || [ ! -e "$dom_key" ]; then
check_result $E_NOTEXIST "$domain certificate doesn't exist"
fi
# Checking difference
diff $dom_crt $vst_crt >/dev/null 2>&1
if [ $? -ne 0 ]; then
rm -f $vst_crt.old $vst_key.old
mv $vst_crt $vst_crt.old >/dev/null 2>&1
mv $vst_key $vst_key.old >/dev/null 2>&1
cp $dom_crt $vst_crt 2>/dev/null
cp $dom_key $vst_key 2>/dev/null
chown root:mail $vst_crt $vst_key
else
restart=no
fi
# Updating mail certificate
case $MAIL_SYSTEM in
exim) conf='/etc/exim/exim.conf';;
exim4) conf='/etc/exim4/exim4.conf.template';;
esac
if [ -e "$conf" ]; then
sed -e "s|^tls_certificate.*|tls_certificate = $vst_crt|" \
-e "s|^tls_privatekey.*|tls_privatekey = $vst_key|" -i $conf
fi
# Updating imap certificate
conf="/etc/dovecot/conf.d/10-ssl.conf"
if [ ! -z "$IMAP_SYSTEM" ] && [ -e "$conf" ]; then
sed -e "s|ssl_cert.*|ssl_cert = <$vst_crt|" \
-e "s|ssl_key.*|ssl_key = <$vst_key|" -i $conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restarting services
if [ "$restart" != 'no' ]; then
if [ ! -z "$MAIL_SYSTEM" ]; then
$BIN/v-restart-service $MAIL_SYSTEM
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
$BIN/v-restart-service $IMAP_SYSTEM
fi
fi
# Updating vesta.conf
if [ -z "$(grep MAIL_CERTIFICATE $VESTA/conf/vesta.conf)" ]; then
echo "MAIL_CERTIFICATE='$user:$domain'" >> $VESTA/conf/vesta.conf
else
sed -i "s/MAIL_CERTIFICATE.*/MAIL_CERTIFICATE='$user:$domain'/g" \
$VESTA/conf/vesta.conf
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,12 +1,12 @@
#!/bin/bash
# info: add system quota
# options: NONE
# opions: NONE
#
# The script enables filesystem quota on /home partition
# The script enables filesystem quota on /home patition
#----------------------------------------------------------#
# Variable & Function #
# Variable&Function #
#----------------------------------------------------------#
# Includes
@ -19,15 +19,21 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Checking quota package
quota=$(which --skip-alias --skip-functions quota 2>/dev/null)
if [ $? -ne 0 ]; then
if [ -d "/etc/sysconfig" ]; then
if [ ! -e "/usr/sbin/setquota" ]; then
if [ -e "/etc/redhat-release" ]; then
yum -y install quota >/dev/null 2>&1
check_result $? "quota package installation failed" $E_UPDATE
result=$?
else
export DEBIAN_FRONTEND=noninteractive
apt-get -y install quota >/dev/null 2>&1
check_result $? "quota package installation failed" $E_UPDATE
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
fi
fi
@ -36,38 +42,38 @@ fi
# Action #
#----------------------------------------------------------#
# Adding group and user quota on /home partition
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
# Adding usrquota option on /home partition
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
if [ -z "$(echo $options |grep usrquota)" ]; then
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab
mount -o remount $mnt
fi
# Adding v2 group and user quota index
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
quotacheck -avcugm >/dev/null 2>&1
# Adding aquota.user file
if [ ! -e "$mnt/aquota.user" ]; then
quotacheck -cu $mnt >/dev/null 2>&1
fi
# Adding quotacheck on reboot
touch /forcequotacheck
# Building fs quota index
quotacheck -um $mnt
# Adding cron job
echo '#!/bin/bash' > /etc/cron.daily/quotacheck
echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck
# Adding weekly cron job
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck
chmod a+x /etc/cron.daily/quotacheck
# Enabling group and user quota
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
quotaon -v $mnt
check_result $? "quota can't be enabled in $mnt" $E_DISK
# 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
fi
# Updating vesta.conf value
# Updating DISK_QUOTA value
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
else
@ -85,6 +91,6 @@ done
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,106 +0,0 @@
#!/bin/bash
# info: add system sftp jail
# options: NONE
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Importing system environment as we run this script
# mostly by cron which 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 " " >> $config
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 \')
/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" |$SENDMAIL -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" "$ARGUMENTS"
exit

View file

@ -1,97 +0,0 @@
#!/bin/bash
# info: add vesta ssl certificate
# options: USER DOMAIN [RESTART]
#
# The function copies user domain SSL to vesta SSL directory
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
restart=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [RESTART]'
is_format_valid 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining certificate location
dom_crt="/home/$user/conf/web/ssl.$domain.pem"
dom_key="/home/$user/conf/web/ssl.$domain.key"
vst_crt="$VESTA/ssl/certificate.crt"
vst_key="$VESTA/ssl/certificate.key"
# Checking certificate
if [ ! -e "$dom_crt" ] || [ ! -e "$dom_key" ]; then
check_result $E_NOTEXIST "$domain certificate doesn't exist"
fi
# Checking difference
diff $dom_crt $vst_crt >/dev/null 2>&1
if [ $? -ne 0 ]; then
rm -f $vst_crt.old $vst_key.old
mv $vst_crt $vst_crt.old
mv $vst_key $vst_key.old
cp $dom_crt $vst_crt 2>/dev/null
cp $dom_key $vst_key 2>/dev/null
chown root:mail $vst_crt $vst_key
else
restart=no
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restarting services
if [ "$restart" != 'no' ]; then
if [ ! -z "$MAIL_SYSTEM" ] && [ -z "$MAIL_CERTIFICATE" ]; then
$BIN/v-restart-service $MAIL_SYSTEM
fi
if [ ! -z "$IMAP_SYSTEM" ] && [ -z "$MAIL_CERTIFICATE" ]; then
$BIN/v-restart-service $IMAP_SYSTEM
fi
if [ ! -z "$FTP_SYSTEM" ]; then
$BIN/v-restart-service "$FTP_SYSTEM"
fi
if [ -e "/var/run/vesta-nginx.pid" ]; then
kill -HUP $(cat /var/run/vesta-nginx.pid)
else
service vesta restart
fi
fi
# Updating vesta.conf
if [ -z "$(grep VESTA_CERTIFICATE $VESTA/conf/vesta.conf)" ]; then
echo "VESTA_CERTIFICATE='$user:$domain'" >> $VESTA/conf/vesta.conf
else
sed -i "s/VESTA_CERTIFICATE.*/VESTA_CERTIFICATE='$user:$domain'/g" \
$VESTA/conf/vesta.conf
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -9,9 +9,9 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
password=$2; HIDE=2
password=$2
email=$3
package=${4-default}
fname=$5
@ -21,10 +21,16 @@ 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 "^$user$" )
check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
check_result $E_EXISTS "user $user exists"
echo "Error: user $user exists"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
}
@ -34,12 +40,12 @@ is_user_free() {
#----------------------------------------------------------#
check_args '3' "$#" 'USER PASSWORD EMAIL [PACKAGE] [FNAME] [LNAME]'
is_format_valid 'user' 'email' 'package'
validate_format 'user' 'password' 'email' 'package'
if [ ! -z "$fname" ]; then
is_format_valid 'fname' 'lname'
validate_format 'fname' 'lname'
fi
is_user_free "$user"
is_password_valid
is_package_valid
@ -48,7 +54,7 @@ is_package_valid
#----------------------------------------------------------#
# Parsing package data
pkg_data=$(cat $VESTA/data/packages/$package.pkg |egrep -v "TIME|DATE")
pkg_data=$(cat $VESTA/data/packages/$package.pkg |grep -v TIME |grep -v DATE)
# Checking shell
shell_conf=$(echo "$pkg_data" | grep 'SHELL' | cut -f 2 -d \')
@ -56,7 +62,11 @@ shell=$(grep -w "$shell_conf" /etc/shells |head -n1)
# Adding user
/usr/sbin/useradd "$user" -s "$shell" -c "$email" -m -d "$HOMEDIR/$user"
check_result $? "user creation failed" $E_INVALID
if [ $? -ne 0 ]; then
echo "Error: user creation failed"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
# Adding password
echo "$user:$password" | /usr/sbin/chpasswd
@ -65,16 +75,21 @@ echo "$user:$password" | /usr/sbin/chpasswd
mkdir $HOMEDIR/$user/conf
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir $HOMEDIR/$user/conf/web $HOMEDIR/$user/web $HOMEDIR/$user/tmp
chmod 751 $HOMEDIR/$user/conf/web
chmod 700 $HOMEDIR/$user/tmp
chown $user:$user $HOMEDIR/$user/web $HOMEDIR/$user/tmp
mkdir $HOMEDIR/$user/conf/web
mkdir $HOMEDIR/$user/web
mkdir $HOMEDIR/$user/tmp
chmod 751 $HOMEDIR/$user/conf/web
chmod 751 $HOMEDIR/$user/web
chmod 771 $HOMEDIR/$user/tmp
chown $user:$user $HOMEDIR/$user/web
chown $user:$user $HOMEDIR/$user/tmp
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir $HOMEDIR/$user/conf/mail $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/mail
chmod 755 $HOMEDIR/$user/conf/mail
mkdir $HOMEDIR/$user/conf/mail
mkdir $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/mail
chmod 751 $HOMEDIR/$user/conf/mail
fi
if [ ! -z "$DNS_SYSTEM" ]; then
@ -92,51 +107,54 @@ chattr +i $HOMEDIR/$user/conf
#----------------------------------------------------------#
# Adding user dir
mkdir -p $USER_DATA/ssl $USER_DATA/dns $USER_DATA/mail
mkdir $USER_DATA
chmod 770 $USER_DATA
# Creating configuration files and pipes
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
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
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
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
if [ ! -z "$CRON_SYSTEM" ]; then
touch $USER_DATA/cron.conf
chmod 660 $USER_DATA/cron.conf
fi
# Filling user config
if [ "$user" != 'admin' ]; then
@ -154,7 +172,7 @@ $pkg_data
CONTACT='$email'
CRON_REPORTS='yes'
MD5='$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)'
RKEY='$(generate_password)'
RKEY='$(gen_password)'
SUSPENDED='no'
SUSPENDED_USERS='0'
SUSPENDED_WEB='0'
@ -183,9 +201,8 @@ U_DATABASES='0'
U_CRON_JOBS='0'
U_BACKUPS='0'
LANGUAGE=''
NOTIFICATIONS='no'
TIME='$time'
DATE='$date'" > $USER_DATA/user.conf
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
chmod 660 $USER_DATA/user.conf
# Updating quota
@ -203,13 +220,8 @@ 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" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,125 +0,0 @@
#!/bin/bash
# info: adding user favourites
# options: USER SYSTEM OBJECT
#
# The function adds object to users favourites
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
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'
is_format_valid 'user' 'system'
case $system in
MAIL_ACC) is_format_valid 'email' ;;
CRON) is_format_valid 'id' ;;
DNS_REC) is_format_valid 'id' ;;
*) is_format_valid '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" "$ARGUMENTS"
exit

View file

@ -1,76 +0,0 @@
#!/bin/bash
# info: add user notification
# options: USER TOPIC NOTICE [TYPE]
#
# The function adds user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
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]'
is_format_valid '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
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# 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

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
pkg_dir=$1
package=$2
rewrite=$3
@ -22,47 +22,24 @@ source $VESTA/conf/vesta.conf
is_package_new() {
if [ -e "$VESTA/data/packages/$package.pkg" ]; then
echo "Error: package $package already exists."
log_event "$E_EXISTS" "$ARGUMENTS"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
}
is_package_consistent() {
source $pkg_dir/$package.pkg
if [ "$WEB_DOMAINS" != 'unlimited' ]; then
is_int_format_valid $WEB_DOMAINS 'WEB_DOMAINS'
fi
if [ "$WEB_ALIASES" != 'unlimited' ]; then
is_int_format_valid $WEB_ALIASES 'WEB_ALIASES'
fi
if [ "$DNS_DOMAINS" != 'unlimited' ]; then
is_int_format_valid $DNS_DOMAINS 'DNS_DOMAINS'
fi
if [ "$DNS_RECORDS" != 'unlimited' ]; then
is_int_format_valid $DNS_RECORDS 'DNS_RECORDS'
fi
if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
is_int_format_valid $MAIL_DOMAINS 'MAIL_DOMAINS'
fi
if [ "$MAIL_ACCOUNTS" != 'unlimited' ]; then
is_int_format_valid $MAIL_ACCOUNTS 'MAIL_ACCOUNTS'
fi
if [ "$DATABASES" != 'unlimited' ]; then
is_int_format_valid $DATABASES 'DATABASES'
fi
if [ "$CRON_JOBS" != 'unlimited' ]; then
is_int_format_valid $CRON_JOBS 'CRON_JOBS'
fi
if [ "$DISK_QUOTA" != 'unlimited' ]; then
is_int_format_valid $DISK_QUOTA 'DISK_QUOTA'
fi
if [ "$BANDWIDTH" != 'unlimited' ]; then
is_int_format_valid $BANDWIDTH 'BANDWIDTH'
fi
if [ "$BACKUPS" != 'unlimited' ]; then
is_int_format_valid $BACKUPS 'BACKUPS'
fi
is_format_valid_shell $SHELL
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'
validate_format_shell $SHELL
}
@ -71,7 +48,7 @@ is_package_consistent() {
#----------------------------------------------------------#
check_args '2' "$#" 'PKG_DIR PACKAGE' 'rewrite'
is_format_valid 'pkg_dir' 'package'
validate_format 'pkg_dir' 'package'
if [ "$rewrite" != 'yes' ]; then
is_package_new
fi
@ -97,6 +74,6 @@ if [ "$rewrite" != 'yes' ]; then
else
log_history "updated user package $package" '' 'admin'
fi
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,66 +0,0 @@
#!/bin/bash
# info: add user sftp jail
# options: USER
#
# The script enables sftp jailed environment
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
is_format_valid '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 /chroot/$user/$home)" ]; then
mount -o bind $home /chroot/$user/$home/
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,133 +0,0 @@
#!/bin/bash
# info: add vesta softaculous
# options: [TYPE]
#
# The script enables softaculous plugin
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
TYPE=$1
# Includes
source /etc/profile
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ "$TYPE" = 'WEB' ]; then
if [ ! -e "$VESTA/softaculous" ] && [ ! -e "$VESTA/ioncube" ]; then
$BIN/v-schedule-vesta-softaculous
exit
fi
else
cmd="v-add-vesta-softaculous"
check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
if [ ! -z "$check_cron" ]; then
eval $check_cron
$BIN/v-delete-cron-job admin $JOB
fi
fi
if [ "$SOFTACULOUS" = 'yes' ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Cleaning yum cache
if [ -d "/etc/sysconfig" ]; then
yum -q clean all
yum="yum -q -y --noplugins --disablerepo=* --enablerepo=vesta"
else
export DEBIAN_FRONTEND=noninteractive
apt-get update -o Dir::Etc::sourcelist="sources.list.d/vesta.list" \
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" -qq
fi
# Updating php pacakge
if [ -z "$($VESTA/php/bin/php -v|grep 'PHP 5.6')" ]; then
if [ -d "/etc/sysconfig" ]; then
$yum -y update vesta-php
check_result $? "vesta-php package upgrade failed" $E_UPDATE
else
apt-get -y install vesta-php
check_result $? "vesta-php package upgrade failed" $E_UPDATE
fi
fi
# Adding vesta-ioncube package
if [ -d "/etc/sysconfig" ]; then
rpm -q vesta-ioncube >/dev/null 2>&1
if [ $? -ne 0 ]; then
$yum -y install vesta-ioncube >/dev/null 2>&1
check_result $? "vesta-ioncube package installation failed" $E_UPDATE
fi
else
dpkg -l vesta-ioncube |grep ^ii >/dev/null 2>&1
if [ $? -ne 0 ]; then
apt-get -y install vesta-ioncube >/dev/null 2>&1
check_result $? "vesta-ioncube package installation failed" $E_UPDATE
fi
fi
# Adding vesta-softaculous package
if [ -d "/etc/sysconfig" ]; then
rpm -q vesta-softaculous >/dev/null 2>&1
if [ $? -ne 0 ]; then
$yum -y install vesta-softaculous >/dev/null 2>&1
check_result $? "vesta-softaculous package installation failed" $E_UPDATE
fi
else
dpkg -l vesta-softaculous |grep ^ii >/dev/null 2>&1
if [ $? -ne 0 ]; then
apt-get -y install vesta-softaculous >/dev/null 2>&1
check_result $? "vesta-softaculous package installation failed" $E_UPDATE
fi
fi
# Installing softaculous
if [ ! -e "$VESTA/softaculous/vst_installed" ]; then
mkdir -p /var/softaculous
chown -R admin:admin /var/softaculous
cd $VESTA/softaculous
wget -q http://c.vestacp.com/3rdparty/softaculous_install.inc
$VESTA/php/bin/php softaculous_install.inc
check_result $? "vesta-softaculous package installation failed" $E_UPDATE
touch $VESTA/softaculous/vst_installed
fi
# Enabling symlink
if [ -e "$VESTA/disabled_plugins/softaculous" ]; then
if [ ! -e "$VESTA/web/softaculous" ]; then
mv $VESTA/disabled_plugins/softaculous $VESTA/web/softaculous
fi
fi
# Updating SOFTACULOUS value
if [ -z "$(grep SOFTACULOUS $VESTA/conf/vesta.conf)" ]; then
echo "SOFTACULOUS='yes'" >> $VESTA/conf/vesta.conf
else
sed -i "s/SOFTACULOUS.*/SOFTACULOUS='yes'/g" \
$VESTA/conf/vesta.conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,28 +1,27 @@
#!/bin/bash
# info: add web domain
# options: USER DOMAIN [IP] [ALIASES] [PROXY_EXTENSIONS] [RESTART]
# options: USER DOMAIN IP [RESTART]
#
# The function adds virtual host to a server. In cases when ip is
# undefined in the script, "default" template will be used. The alias of
# www.domain.tld type will be automatically assigned to the domain unless
# "none" is transmited as argument. If ip have associated dns name, this
# domain will also get the alias domain-tpl.$ipname. An alias with the ip
# name is useful during the site testing while dns isn't moved to server yet.
# 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
# www.domain.tld type will be automatically assigned to the domain. If ip have
# assocated dns name, this domain will also get the alias domain-tpl.$ipname.
# An alias with the ip name is useful during the site testing while dns isn't
# moved to a server yet.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
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
restart=$4 # will be moved to the end soon
aliases=$5
proxy_ext=$6
restart=$4
# Includes
source $VESTA/func/main.sh
@ -30,42 +29,62 @@ source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
format_aliases
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
validate_format 'user' 'domain' 'ip'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
check_args '2' "$#" 'USER DOMAIN [IP] [RESTART] [ALIASES] [PROXY_EXTENSIONS]'
is_format_valid 'user' 'domain' 'aliases' 'ip' 'proxy_ext'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_package_full 'WEB_DOMAINS' 'WEB_ALIASES'
is_domain_new 'web' "$domain,$aliases"
is_dir_symlink $HOMEDIR/$user/web
if_dir_exists $HOMEDIR/$user/web/$domain
is_dir_symlink $HOMEDIR/$user/web/$domain
if [ ! -z "$ip" ]; then
is_ip_valid "$ip" "$user"
else
get_user_ip
fi
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
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Reading user values
source $USER_DATA/user.conf
# Define real ip in case of NAT
IP=$ip
ip=$(get_real_ip $ip)
# Creating domain directories
sudo -u $user mkdir -p $HOMEDIR/$user/web/$domain \
# 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"
fi
# Defining vars for add_config function
group="$user"
email="info@$domain"
docroot="$HOMEDIR/$user/web/$domain/public_html"
tpl_file="$WEBTPL/$WEB_SYSTEM/$template.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
# Adding web config
add_web_config
# Building directory tree
mkdir -p $HOMEDIR/$user/web/$domain \
$HOMEDIR/$user/web/$domain/public_html \
$HOMEDIR/$user/web/$domain/public_shtml \
$HOMEDIR/$user/web/$domain/document_errors \
@ -74,74 +93,63 @@ sudo -u $user mkdir -p $HOMEDIR/$user/web/$domain \
$HOMEDIR/$user/web/$domain/stats \
$HOMEDIR/$user/web/$domain/logs
# Creating domain logs
# Adding domain logs
touch /var/log/$WEB_SYSTEM/domains/$domain.bytes \
/var/log/$WEB_SYSTEM/domains/$domain.log \
/var/log/$WEB_SYSTEM/domains/$domain.error.log
# Adding symlink for logs
ln -f -s /var/log/$WEB_SYSTEM/domains/$domain.*log \
$HOMEDIR/$user/web/$domain/logs/
# Adding domain skeleton
sudo -u $user cp -r $WEBTPL/skel/* $HOMEDIR/$user/web/$domain/ >/dev/null 2>&1
if [ -e "$WEBTPL/skel/public_html/" ]; then
cp -r $WEBTPL/skel/public_html/ $HOMEDIR/$user/web/$domain/
fi
if [ -e "$WEBTPL/skel/public_shtml/" ]; then
cp -r $WEBTPL/skel/public_shtml/ $HOMEDIR/$user/web/$domain/
fi
if [ -e "$WEBTPL/skel/document_errors/" ]; then
cp -r $WEBTPL/skel/document_errors/ $HOMEDIR/$user/web/$domain/
fi
if [ -e "$WEBTPL/skel/cgi-bin/" ]; then
cp -r $WEBTPL/skel/cgi-bin/ $HOMEDIR/$user/web/$domain/
fi
# Changing tpl values
for file in $(find "$HOMEDIR/$user/web/$domain/" -type f); do
sed -i "s/%domain%/$domain/g" $file
done
# Changing file owner & permission
# Changing file owner
chown -R $user:$user $HOMEDIR/$user/web/$domain
chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.* $conf
chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.*
chown root:$user $conf
# Changing file permissions
chmod 640 $conf
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.*
sudo -u $user chmod 751 $HOMEDIR/$user/web/$domain $HOMEDIR/$user/web/$domain/*
sudo -u $user chmod 551 $HOMEDIR/$user/web/$domain/stats $HOMEDIR/$user/web/$domain/logs
sudo -u $user chmod 644 $HOMEDIR/$user/web/$domain/public_*html/*.*
# Addding PHP-FPM backend
if [ ! -z "$WEB_BACKEND" ]; then
if [ -z "$BACKEND_TEMPLATE" ]; then
BACKEND_TEMPLATE='default'
if [ -z "$(grep BACKEND_TEMPLATE $USER_DATA/user.conf)" ]; then
sed -i "s/^DNS_TEMPL/BACKEND_TEMPLATE='default'\nDNS_TEMPL/g" \
$USER_DATA/user.conf
else
update_user_value "$user" '$BACKEND_TEMPLATE' "default"
fi
fi
$BIN/v-add-web-domain-backend "$user" "$domain" $BACKEND_TEMPLATE
check_result $? "Backend error" >/dev/null
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
fi
# Preparing domain aliases
if [ "$aliases" = 'none' ]; then
ALIAS=''
else
ALIAS="www.$domain"
if [ -z "$aliases" ]; then
ALIAS="www.$domain"
else
ALIAS="$aliases"
fi
ip_alias=$(get_ip_alias $domain)
if [ ! -z "$ip_alias" ]; then
ALIAS="$ALIAS,$ip_alias"
fi
fi
# Preparing domain variables
prepare_web_domain_values
# Adding web server config
add_web_config "$WEB_SYSTEM" "$WEB_TEMPLATE.tpl"
# Adding proxy config
if [ ! -z "$PROXY_SYSTEM" ]; then
PROXY_EXT="$proxy_ext"
if [ -z "$proxy_ext" ]; then
PROXY_EXT="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls"
PROXY_EXT="$PROXY_EXT,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp"
PROXY_EXT="$PROXY_EXT,rtf,js,mp3,avi,mpeg,flv,html,htm"
fi
add_web_config "$PROXY_SYSTEM" "$PROXY_TEMPLATE.tpl"
# Checking web config
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep $conf $web_conf)" ]; then
echo "Include $conf" >> $web_conf
fi
@ -150,32 +158,31 @@ fi
#----------------------------------------------------------#
# Increasing counters
increase_ip_value "$local_ip"
increase_ip_value "$ip"
increase_user_value "$user" '$U_WEB_DOMAINS'
increase_user_value "$user" '$U_WEB_ALIASES' "$alias_number"
increase_user_value "$user" '$U_WEB_ALIASES'
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# 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 STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
str="$str TIME='$TIME' DATE='$DATE'"
# Adding domain in web.conf
echo "DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$ALIAS' TPL='$WEB_TEMPLATE'\
SSL='no' SSL_HOME='same' LETSENCRYPT='no' FTP_USER='' FTP_MD5=''\
BACKEND='$BACKEND_TEMPLATE' PROXY='$PROXY_TEMPLATE' PROXY_EXT='$PROXY_EXT'\
STATS='' STATS_USER='' STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0'\
SUSPENDED='no' TIME='$time' DATE='$date'" >> $USER_DATA/web.conf
# Registering domain
echo "$str" >> $USER_DATA/web.conf
chmod 660 $USER_DATA/web.conf
# Restarting web server
$BIN/v-restart-web $restart
check_result $? "Web restart failed" >/dev/null
# Restarting proxy server
$BIN/v-restart-proxy $restart
check_result $? "Proxy restart failed" >/dev/null
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "added web domain $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add web domain alias
# options: USER DOMAIN ALIASES [RESTART]
# options: USER DOMAIN ALIAS [RESTART]
#
# The call is intended for adding aliases to a domain (it is also called
# "domain parking"). The function supports wildcards *.domain.tpl.
@ -10,11 +10,15 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
aliases=$3
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
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"
# Includes
@ -23,25 +27,19 @@ source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
format_aliases
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN ALIASES [RESTART]'
is_format_valid 'user' 'domain' 'dom_alias'
check_args '3' "$#" 'USER DOMAIN DOM_ALIAS [RESTART]'
validate_format 'user' 'domain' 'dom_alias'
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_domain_new 'web' "$aliases"
is_domain_new 'web' "$dom_alias"
is_package_full 'WEB_ALIASES'
@ -51,31 +49,43 @@ is_package_full 'WEB_ALIASES'
# Parsing domain values
get_domain_values 'web'
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
ip=$(get_real_ip $IP)
# Parsing domain aliases
if [ -z "$ALIAS" ]; then
ALIAS="$dom_alias"
else
ALIAS="$ALIAS,$dom_alias"
fi
# Preparing domain values for the template substitution
local_ip=$(get_real_ip $IP)
if [ -z "$ALIAS" ]; then
ALIAS="$aliases"
else
ALIAS="$ALIAS,$aliases"
fi
prepare_web_domain_values
upd_web_domain_values
# Recreating vhost
del_web_config
add_web_config
# Rebuilding vhost
del_web_config "$WEB_SYSTEM" "$TPL.tpl"
add_web_config "$WEB_SYSTEM" "$TPL.tpl"
if [ "$SSL" = 'yes' ]; then
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
add_web_config
fi
# Rebuilding proxy configuration
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
# Checking proxy
if [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
del_web_config
add_web_config
if [ "$SSL" = 'yes' ]; then
del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
del_web_config
add_web_config
fi
fi
@ -86,18 +96,24 @@ fi
# Adding new alias
update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
# Update counters
increase_user_value "$user" '$U_WEB_ALIASES'
# Restarting web server
$BIN/v-restart-web $restart
check_result $? "Web restart failed" >/dev/null
# Adding task to the vesta pipe
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Restarting proxy server
$BIN/v-restart-proxy $restart
check_result $? "Proxy restart failed" >/dev/null
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
log_history "added $aliases for $domain"
log_event "$OK" "$ARGUMENTS"
log_history "added $dom_alias as alias for $domain"
log_event "$OK" "$EVENT"
exit

View file

@ -1,77 +0,0 @@
#!/bin/bash
# info: add web domain backend
# options: USER DOMAIN [TEMPLATE] [RESTART]
#
# The call is used for adding web backend configuration.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
template=${3-default}
restart=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [RESTART]'
is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_backend_template_valid "$template"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining pool directory
prepare_web_backend
# Checking backend configuration
if [ -e "$pool/$backend_type.conf" ]; then
exit
fi
# Allocating backend port
backend_port=9000
ports=$(grep listen $pool/* 2>/dev/null |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|g"\
-e "s|%domain%|$domain|g"\
-e "s|%backend%|$backend_type|g" > $pool/$backend_type.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restart backend server
$BIN/v-restart-web-backend $restart
check_result $? "Web backend restart failed" >/dev/null
# Logging
log_history "added $WEB_BACKEND backend configuration for $domain"
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -9,12 +9,12 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ftp_user=${1}_${3}
password=$4; HIDE=4
ftp_password=$4
ftp_path=$5
# Includes
@ -22,10 +22,9 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
@ -33,7 +32,7 @@ format_domain_idn
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN FTP_USER FTP_PASSWORD [FTP_PATH]'
is_format_valid 'user' 'domain' 'ftp_user'
validate_format 'user' 'domain' 'ftp_user' 'ftp_password'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -42,10 +41,9 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
check_ftp_user=$(grep "^$ftp_user:" /etc/passwd)
if [ ! -z "$check_ftp_user" ] && [ "$FTP_USER" != "$ftp_user" ]; then
echo "Error: ftp user $ftp_user already exists"
log_event "$E_EXISTS" "$ARGUMENTS"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
is_password_valid
#----------------------------------------------------------#
@ -56,8 +54,12 @@ is_password_valid
get_domain_values 'web'
# Defining ftp user shell
shell=$(which nologin)
if [ ! -z "$FTP_SHELL" ]; then
if [ -z "$FTP_SHELL" ]; then
shell='/sbin/nologin'
if [ -e "/usr/bin/rssh" ]; then
shell='/usr/bin/rssh'
fi
else
shell=$FTP_SHELL
fi
@ -69,7 +71,7 @@ else
ftp_path_a=$(readlink -f "$HOMEDIR/$user/web/$domain/$ftp_path")
if [ -z "$(echo $ftp_path_a |grep $HOMEDIR/$user/web/$domain)" ]; then
echo "Error: absolute path $ftp_path_a is invalid"
log_event "$E_INVALID" "$ARGUMENTS"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
# Creating ftp user home directory
@ -84,18 +86,13 @@ fi
/usr/sbin/useradd $ftp_user \
-s $shell \
-o -u $(id -u $user) \
-g $(id -g $user) \
-g $(id -u $user) \
-M -d "$ftp_path_a" > /dev/null 2>&1
# Set ftp user password
echo "$ftp_user:$password" | /usr/sbin/chpasswd
echo "$ftp_user:$ftp_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 #
@ -121,6 +118,6 @@ update_object_value 'web' 'DOMAIN' "$domain" '$FTP_PATH' "$ftp_path"
# Logging
log_history "added ftp account ${1}_${3}@$domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,115 +0,0 @@
#!/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 definition
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
# Defining htpasswd file
htaccess="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf_htaccess"
htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
shtaccess="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.$domain.conf_htaccess"
shtpasswd="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.$domain.htpasswd"
docroot="$HOMEDIR/$user/web/$domain/public_html"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN AUTH_USER AUTH_PASSWORD [RESTART]'
is_format_valid '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" "$ARGUMENTS"
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
chgrp $user $htpasswd $htaccess
sed -i "/^$auth_user:/d" $htpasswd
echo "$auth_user:$auth_hash" >> $htpasswd
# Symbolic link for secure web templates
if [ ! -L $shtpasswd ]; then
ln -s $htpasswd $shtpasswd
fi
if [ ! -L $shtaccess ]; then
ln -s $htaccess $shtaccess
fi
# 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" "$ARGUMENTS"
exit

View file

@ -10,9 +10,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
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"
@ -31,7 +32,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]'
is_format_valid 'user' 'domain' 'extentions'
validate_format 'user' 'domain' 'extentions'
is_system_enabled "$PROXY_SYSTEM" 'PROXY_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -41,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 $template
is_proxy_template_valid
#----------------------------------------------------------#
@ -50,16 +51,44 @@ is_proxy_template_valid $template
# Defining domain parameters
get_domain_values 'web'
prepare_web_domain_values
local_ip=$(get_real_ip $IP)
PROXY="$template"
PROXY_EXT="$extentions"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
PROXY_EXT="$extentions"
add_web_config "$PROXY_SYSTEM" "$template.tpl"
upd_web_domain_values
add_web_config
# Adding proxy for ssl
# Set permission and ownership
chown root:$user $conf
chmod 640 $conf
# Checking proxy config
proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep "$conf" $proxy_conf)" ]; then
echo "include $conf;" >> $proxy_conf
fi
# Checking ssl
if [ "$SSL" = 'yes' ]; then
add_web_config "$PROXY_SYSTEM" "$template.stpl"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/s$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
fi
# Running template trigger
if [ -x $WEBTPL/$PROXY_SYSTEM/$template.sh ]; then
$WEBTPL/$PROXY_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
fi
@ -68,14 +97,18 @@ fi
#----------------------------------------------------------#
# Update config
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template"
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
# Restarting web server
$BIN/v-restart-proxy $restart
check_result $? "Proxy restart failed" >/dev/null
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
log_history "enabled proxy support for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -14,44 +14,27 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ssl_dir=$3
ssl_home=${4-same}
restart="$5"
# Additional argument formatting
if [[ "$domain" =~ [[:upper:]] ]]; then
domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]')
fi
if [[ "$domain" =~ ^www\..* ]]; then
domain=$(echo "$domain" |sed -e "s/^www.//")
fi
if [[ "$domain" =~ .*\.$ ]]; then
domain=$(echo "$domain" |sed -e "s/\.$//")
fi
domain=$(idn -t --quiet -u "$domain" )
domain_idn=$(idn -t --quiet -a "$domain")
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN SSL_DIR [SSL_HOME] [RESTART]'
is_format_valid 'user' 'domain' 'ssl_dir'
validate_format 'user' 'domain' 'ssl_dir'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
is_object_valid 'user' 'USER' "$user"
@ -77,6 +60,22 @@ if [ -e "$ssl_dir/$domain.ca" ]; then
fi
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"
SSL_HOME="$ssl_home"
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values
# Adding domain to the web config
add_web_config
chown root:$user $conf
chmod 640 $conf
# Adding certificate to user dir
cp -f $USER_DATA/ssl/$domain.crt $HOMEDIR/$user/conf/web/ssl.$domain.crt
cp -f $USER_DATA/ssl/$domain.key $HOMEDIR/$user/conf/web/ssl.$domain.key
@ -85,20 +84,31 @@ if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/ssl.$domain.ca
fi
# Parsing domain values
get_domain_values 'web'
local_ip=$(get_real_ip $IP)
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $sdocroot
fi
# Preparing domain values for the template substitution
SSL_HOME="$ssl_home"
prepare_web_domain_values
# Checking web config
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep "$conf" $web_conf)" ]; then
echo "Include $conf" >> $web_conf
fi
# Adding domain to the web config
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
# Checking proxy
if [ ! -z "$PROXY" ]; then
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
add_web_config
# Checking proxy config
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
chown root:$user $conf
chmod 640 $conf
# Checking proxy config
proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
if [ -z "$(grep "$conf" $proxy_conf )" ]; then
echo "include $conf;" >> $proxy_conf
fi
fi
@ -113,44 +123,21 @@ 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"
# Restarting web server
$BIN/v-restart-web $restart
check_result $? "Web restart failed" >/dev/null
$BIN/v-restart-proxy $restart
check_result $? "Proxy restart failed" >/dev/null
# Updating system ssl dependencies
if [ ! -z "$VESTA_CERTIFICATE" ]; then
crt_user=$(echo "$VESTA_CERTIFICATE" |cut -f 1 -d :)
crt_domain=$(echo "$VESTA_CERTIFICATE" |cut -f 2 -d :)
if [ "$user" = "$crt_user" ] && [ "$domain" = "$crt_domain" ]; then
$BIN/v-add-sys-vesta-ssl $user $domain >/dev/null 2>&1
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
if [ ! -z "$MAIL_CERTIFICATE" ]; then
crt_user=$(echo "$MAIL_CERTIFICATE" |cut -f 1 -d :)
crt_domain=$(echo "$MAIL_CERTIFICATE" |cut -f 2 -d :)
if [ "$user" = "$crt_user" ] && [ "$domain" = "$crt_domain" ]; then
$BIN/v-add-sys-mail-ssl $user $domain >/dev/null 2>&1
fi
fi
if [ ! -z "$UPDATE_HOSTNAME_SSL" ] && [ "$UPDATE_HOSTNAME_SSL" = "yes" ]; then
hostname=$(hostname)
if [ "$hostname" = "$domain" ]; then
$BIN/v-update-host-certificate $user $domain
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
UPDATE_SSL_SCRIPT=''
source $VESTA/conf/vesta.conf
if [ ! -z "$UPDATE_SSL_SCRIPT" ]; then
eval "$UPDATE_SSL_SCRIPT $user $domain"
fi
# Logging
log_history "enabled ssl support for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -13,10 +13,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
type=$3
# Includes
@ -24,17 +24,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN TYPE'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_type_valid "$STATS_SYSTEM" "$type"
is_object_valid 'user' 'USER' "$user" "$user"
@ -51,8 +47,10 @@ is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS'
# Parse aliases
get_domain_values 'web'
# Preparing domain values for the template substitution
upd_web_domain_values
# Adding statistic config
prepare_web_domain_values
cat $WEBTPL/$type/$type.tpl |\
sed -e "s|%ip%|$ip|g" \
-e "s|%web_port%|$WEB_PORT|g" \
@ -92,7 +90,7 @@ update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
# Logging
log_history "enabled web log analyzer for $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
# Build stats
exec $BIN/v-update-web-domain-stat $user $domain

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add password protection to web domain statistics
# options: USER DOMAIN STATS_USER STATS_PASSWORD [RESTART]
# options: USER DOMAIN STATS_USER STATS_PASSWORD
#
# The call is used for securing the web statistics page.
@ -9,57 +9,52 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain=$(idn -t --quiet -u "$2" )
stats_user=$3
password=$4; HIDE=4
restart=$5
stats_pass=$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 [RESTART]'
is_format_valid 'user' 'domain' 'stats_user'
check_args '4' "$#" 'USER DOMAIN STATS_USER STATS_PASS'
validate_format 'user' 'domain' 'stats_user' 'stats_pass'
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
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining statistic dir
# Definining statistic dir
stats_dir="$HOMEDIR/$user/web/$domain/stats"
conf_dir="$HOMEDIR/$user/conf/web"
# Adding htaccess file
if [ "$WEB_SYSTEM" = 'nginx' ]; then
echo "auth_basic \"Web Statistics\";" > $conf_dir/$domain.auth
echo "auth_basic_user_file $stats_dir/.htpasswd;" >> $conf_dir/$domain.auth
else
echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
echo "AuthType Basic" >> $stats_dir/.htaccess
echo "Require valid-user" >> $stats_dir/.htaccess
fi
echo "AuthUserFile $stats_dir/.htpasswd
AuthName \"Web Statistics\"
AuthType Basic
Require valid-user" > $stats_dir/.htaccess
# Generating htaccess user and password
salt=$(generate_password "$PW_MATRIX" "8")
stats_pass=$($BIN/v-generate-password-hash md5 $salt $password)
echo "$stats_user:$stats_pass" > $stats_dir/.htpasswd
rm -f $stats_dir/.htpasswd
htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
#----------------------------------------------------------#
# Vesta #
@ -67,16 +62,10 @@ echo "$stats_user:$stats_pass" > $stats_dir/.htpasswd
# Adding stats user in config
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_pass"
# Restarting web server
if [ "$WEB_SYSTEM" = 'nginx' ]; then
$BIN/v-restart-web $restart
check_result $? "Web restart failed" >/dev/null
fi
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
# Logging
log_history "added password protection for web stats on $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

File diff suppressed because it is too large Load diff

View file

@ -9,8 +9,8 @@
# Variable&Function #
#----------------------------------------------------------#
# Importing system environment as we run this script
# mostly by cron which not read it by itself
# Importing system enviroment as we run this script
# mostly by cron wich not read it by itself
source /etc/profile
# Includes
@ -22,15 +22,7 @@ source $VESTA/conf/vesta.conf
# Action #
#----------------------------------------------------------#
$BIN/v-check-vesta-license >/dev/null
if [ -z "$BACKUP_SYSTEM" ]; then
exit
fi
for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
if [ ! -f "$VESTA/data/users/$user/user.conf" ]; then
continue;
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
if [ ! -z "$check_suspend" ]; then
@ -47,6 +39,6 @@ done
#----------------------------------------------------------#
# No Logging
#log_event "$OK" "$ARGUMENTS"
#log_event "$OK" "$EVENT"
exit

View file

@ -10,7 +10,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
job=$2
min=$3
@ -30,27 +30,21 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '7' "$#" 'USER JOB MIN HOUR DAY MONTH WDAY COMMAND'
is_format_valid 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command'
validate_format 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command'
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'cron' 'JOB' "$job"
is_object_unsuspended 'cron' 'JOB' "$job"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatenating cron string
command=$(echo $command | sed -e "s/'/%quote%/g")
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
# Deleting old job
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
@ -69,12 +63,14 @@ sync_cron_jobs
# Vesta #
#----------------------------------------------------------#
# Restarting crond
# Restart crond
$BIN/v-restart-cron
check_result $? "Cron restart failed" >/dev/null
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
# Logging
log_history "changed cron job $job"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,68 +0,0 @@
#!/bin/bash
# info: change database server password
# options: TYPE HOST USER PASSWORD
#
# The function changes database server password.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
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"
is_format_valid '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" ;
if [ "$dbuser" == "root" ]; then
echo -e "[client]\npassword='$dbpass'\n" > /root/.my.cnf
chmod 600 /root/.my.cnf
fi;;
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" "$ARGUMENTS"
exit

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: change database owner
# info: change database password
# options: DATABASE USER
#
# The function for changing database owner.
@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
database=$1
user=$2
@ -25,7 +25,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'DATABASE USER'
is_format_valid 'database' 'user'
validate_format 'database' 'user'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -34,7 +34,7 @@ is_object_unsuspended 'user' 'USER' "$user"
owner=$(echo $database | cut -f 1 -d '_')
if [ ! -e "$VESTA/data/users/$owner" ]; then
echo "Error: database owner doesn't exist"
log_event "$E_NOTEXIST" "$ARGUMENTS"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
@ -47,7 +47,7 @@ fi
db_data=$(grep "DB='$database'" $VESTA/data/users/$owner/db.conf)
if [ -z "$db_data" ]; then
echo "Error: database $database doesn't exist"
log_event "$E_NOTEXIST" "$ARGUMENTS"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
@ -56,7 +56,7 @@ new_db=$(echo $database | sed "s/^${owner}_/${user}_/")
check_db=$(grep "DB='$new_db'" $VESTA/data/users/$user/db.conf)
if [ ! -z "$check_db" ]; then
echo "Error: $new_db database exists"
log_event "$E_EXISTS" "$ARGUMENTS"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
@ -69,7 +69,7 @@ fi
tmpdir=$(mktemp -p $BACKUP -d)
if [ "$?" -ne 0 ]; then
echo "Error: can't create $tmpdir"
log_event "$E_NOTEXIST" "$ARGUMENTS"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
@ -80,6 +80,7 @@ $BIN/v-suspend-database $owner $database > /dev/null 2>&1
eval $db_data
dump="$tmpdir/$database.$TYPE.sql"
grants="$tmpdir/$database.$TYPE.$DBUSER"
send_mail='/bin/true'
case $TYPE in
mysql) dump_mysql_database ;;
pgsql) dump_pgsql_database ;;
@ -119,6 +120,6 @@ $BIN/v-update-user-counters $user
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -10,30 +10,33 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
database=$2
password=$3; HIDE=3
dbpass=$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'
is_format_valid 'user' 'database'
validate_format 'user' 'database' 'dbpass'
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 #
@ -56,6 +59,6 @@ update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
# Logging
log_history "changed $database database password"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,11 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
database=$2
dbuser="$user"_"$3"
password=$4; HIDE=4
dbpass=$4
# Includes
source $VESTA/func/main.sh
@ -21,25 +21,25 @@ 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 #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DATABASE DBUSER [DBPASS]'
is_format_valid 'user' 'database' 'dbuser'
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,6 +47,11 @@ if [ "$old_dbuser" = "$dbuser" ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Set new dbuser
update_object_value 'db' 'DB' "$database" '$DBUSER' "$dbuser"
@ -86,6 +91,6 @@ fi
# Logging
log_history "changed $database database user to $dbuser"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: change dns domain expiration date
# info: change dns domain expiriation date
# options: USER DOMAIN EXP
#
# The function of changing the term of expiration domain's registration. The
@ -10,28 +10,23 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
exp=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN EXP'
is_format_valid 'user' 'domain' 'exp'
validate_format 'user' 'domain' 'exp'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -62,7 +57,7 @@ fi
#----------------------------------------------------------#
# Logging
log_history "changed whois expiration date for $domain"
log_event "$OK" "$ARGUMENTS"
log_history "changed whois expiriation date for $domain"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ip=$3
restart=$4
@ -21,18 +21,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN IP'
is_format_valid 'user' 'domain' 'ip'
validate_format 'user' 'domain' 'ip'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -56,7 +51,6 @@ 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
@ -65,7 +59,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 yes"
cmd="$BIN/v-add-remote-dns-domain $user $domain domain"
echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
fi
fi
@ -75,12 +69,16 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed dns ip for $domain to $ip"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -10,10 +10,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
soa=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g')
restart=$4
@ -22,18 +22,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN SOA'
is_format_valid 'user' 'domain' 'soa'
validate_format 'user' 'domain' 'soa'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -50,7 +45,6 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$SOA' "$soa"
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -69,12 +63,16 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed soa record for $domain to $soa"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -11,10 +11,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
restart=$4
@ -23,23 +23,19 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
is_format_valid 'user' 'domain' 'template'
validate_format 'user' 'domain' 'template'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
is_dns_template_valid "$template"
is_dns_template_valid
#----------------------------------------------------------#
@ -47,7 +43,8 @@ is_dns_template_valid "$template"
#----------------------------------------------------------#
# Defining variables
get_domain_values 'dns'
ip=$(get_object_value 'dns' 'DOMAIN' "$domain" '$IP')
i=1
ns=$(get_user_value '$NS')
for nameserver in ${ns//,/ };do
@ -55,49 +52,21 @@ for nameserver in ${ns//,/ };do
(( ++i))
done
# Reading template
template_data=$(cat $DNSTPL/$template.tpl)
# Deleting unused nameservers
if [ -z "$ns3" ]; then
template_data=$(echo "$template_data" |grep -v %ns3%)
fi
if [ -z "$ns4" ]; then
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
# Changing tpl
echo "$template_data" |\
sed -e "s/%ip%/$IP/g" \
cat $DNSTPL/$template.tpl |\
sed -e "s/%ip%/$ip/g" \
-e "s/%domain_idn%/$domain_idn/g" \
-e "s/%domain%/$domain/g" \
-e "s/%ns1%/$ns1/g" \
-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
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
@ -120,12 +89,16 @@ fi
update_object_value 'dns' 'DOMAIN' "$domain" '$TPL' "$template"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed dns template for $domain to $template" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -2,17 +2,17 @@
# info: change dns domain ttl
# options: USER DOMAIN TTL
#
# The function for changing the time to live TTL parameter for all records.
# The function for chaning the time to live TTL parameter for all records.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ttl=$3
restart=$4
@ -21,18 +21,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN TTL'
is_format_valid 'user' 'domain' 'ttl'
validate_format 'user' 'domain' 'ttl'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -49,7 +44,6 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$TTL' "$ttl"
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -68,12 +62,16 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed TTL for $domain to $ttl"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
id=$3
dvalue=$(idn -t --quiet -u "$4" )
priority=$5
@ -23,18 +24,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ID VALUE [PRIORITY] [RESTART]'
is_format_valid 'user' 'domain' 'id' 'dvalue'
validate_format 'user' 'domain' 'id' 'dvalue'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -71,14 +67,9 @@ is_dns_nameserver_valid "$domain" "$TYPE" "$dvalue"
# Deleting old record
sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Adding record
dns_rec="ID='$id' RECORD='$RECORD' TYPE='$TYPE' PRIORITY='$priority'"
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
# Sorting records
@ -86,7 +77,6 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -105,12 +95,16 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed dns record on $domain to $dvalue"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
id=$3
newid=$4
restart=$5
@ -22,18 +23,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ID NEWID [RESTART]'
is_format_valid 'user' 'domain' 'id' 'newid'
validate_format 'user' 'domain' 'id' 'newid'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -55,7 +51,6 @@ sort_dns_records
# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
update_domain_serial
update_domain_zone
fi
@ -74,12 +69,16 @@ fi
# Vesta #
#----------------------------------------------------------#
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "DNS restart failed" >/dev/null
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed dns record id on $domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: change domain owner
# options: DOMAIN USER
# info: change ip owner
# options: DOMAIN USER [IP]
#
# The function of changing domain ownership.
@ -9,9 +9,10 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
domain=$1
user=$2
ip=$3
# Includes
source $VESTA/func/ip.sh
@ -23,13 +24,20 @@ source $VESTA/conf/vesta.conf
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'DOMAIN USER'
is_format_valid 'domain' 'user'
check_args '2' "$#" 'DOMAIN USER [IP]'
validate_format 'domain' 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
owner=$($BIN/v-search-domain-owner $domain)
if [ ! -z "$ip" ]; then
is_ip_valid
is_ip_avalable
fi
owner=$(v-search-domain-owner $domain)
if [ -z "$owner" ]; then
check_result $E_NOTEXIST "domain $domain doesn't exist"
echo "Error: domain $domain doesn't exist"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
if [ "$owner" = "$user" ]; then
exit
@ -148,18 +156,6 @@ if [ ! -z "$mail_data" ]; then
$BIN/v-unsuspend-mail-domain $user $domain no >> /dev/null 2>&1
$BIN/v-rebuild-mail-domains $owner no
$BIN/v-rebuild-mail-domains $user
# Checking exim username for later chowning
exim_user="exim";
check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
if [ "$check_exim_username" -eq 1 ]; then
exim_user="Debian-exim"
fi
# Chowning mail conf files to exim user
if [ -d "$HOMEDIR/$user/conf/mail/$domain" ]; then
find $HOMEDIR/$user/conf/mail/$domain -user root \
-exec chown $exim_user {} \;
fi
fi
# Update counters
@ -172,6 +168,6 @@ $BIN/v-update-user-counters $user
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -13,7 +13,7 @@
# Importing system variables
source /etc/profile
# Argument definition
# Argument defenition
rule=$1
action=$(echo $2|tr '[:lower:]' '[:upper:]')
ip=$3
@ -40,9 +40,9 @@ sort_fw_rules() {
#----------------------------------------------------------#
check_args '5' "$#" 'RULE ACTION IP PORT [PROTOCOL] [COMMENT]'
is_format_valid 'rule' 'action' 'protocol' 'port_ext' 'ip'
validate_format 'rule' 'action' 'protocol' 'port_ext' 'ip'
if [ ! -z "$comment" ]; then
is_format_valid 'comment'
validate_format 'comment'
fi
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
@ -52,15 +52,10 @@ is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
# Concatenating firewall rule
str="RULE='$rule' ACTION='$action' PROTOCOL='$protocol' PORT='$port_ext'"
str="$str IP='$ip' COMMENT='$comment' SUSPENDED='no'"
str="$str TIME='$time' DATE='$date'"
str="$str TIME='$TIME' DATE='$DATE'"
# Deleting old rule
sed -i "/RULE='$rule' /d" $VESTA/data/firewall/rules.conf
@ -80,6 +75,6 @@ $BIN/v-update-firewall
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,51 +0,0 @@
#!/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 [ ! -fe "$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 -R $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

@ -9,22 +9,22 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
password=$4; HIDE=4
password=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
# Hiding password
A4='******'
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
@ -32,7 +32,7 @@ format_domain_idn
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD'
is_format_valid 'user' 'domain' 'account'
validate_format 'user' 'domain' 'account' 'password'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -40,23 +40,21 @@ 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 #
#----------------------------------------------------------#
# Generating hashed password
salt=$(generate_password "$PW_MATRIX" "8")
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
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
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
quota=$(grep $account $VESTA/data/users/${user}/mail/${domain}.conf)
quota=$(echo $quota | awk '{ print $7 }' | sed -e "s/'//g" )
quota=$(echo $quota | cut -d "=" -f 2 | sed -e "s/unlimited/0/g")
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}M"
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
fi
@ -70,6 +68,6 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5' "$md5"
# Logging
log_history "changed password for $account@$domain"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,10 +9,11 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
account=$3
quota=$4
@ -21,21 +22,13 @@ source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN ACCOUNT QUOTA'
is_format_valid 'user' 'domain' 'account'
if [ "$quota" != 'unlimited' ]; then
is_format_valid 'quota'
fi
validate_format 'user' 'domain' 'account' 'quota'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -51,9 +44,6 @@ 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
@ -64,15 +54,11 @@ fi
# Vesta #
#----------------------------------------------------------#
if [[ "$quota" -eq 0 ]]; then
quota='unlimited'
fi
# Update quota
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA' "$quota"
# Logging
log_history "changed mail quota for $account@$domain to $quota"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -2,35 +2,32 @@
# info: change mail domain catchall email
# options: USER DOMAIN EMAIL
#
# The function changes mail domain catchall.
# The function changes mail domain cathcall.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
domain_idn=$2
email=$3
domain=$(idn -t --quiet -u "$2" )
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
domain_idn=$(idn -t --quiet -a "$domain")
email="$3"
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN EMAIL'
is_format_valid 'user' 'domain' 'email'
validate_format 'user' 'domain' 'email'
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -44,8 +41,8 @@ is_object_unsuspended 'mail' 'DOMAIN' "$domain"
# Change cathcall alias
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
sed -i "/*@$domain_idn:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "*@$domain_idn:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
sed -i "/*@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
echo "*@$domain:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
fi
@ -56,8 +53,9 @@ fi
# Change catchall in config
update_object_value 'mail' 'DOMAIN' "$domain" '$CATCHALL' "$email"
# Logging
log_history "changed catchall email for $domain to $email"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: change remote dns domain expiration date
# info: change remote dns domain expiriation date
# options: USER DOMAIN
#
# The function synchronize dns domain with the remote server.
@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
@ -24,41 +24,83 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_procces_running
remote_dns_health_check
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Parsing remote host parameters
eval $cluster
# Check remote dns nodes
remote_dns_health_check
# Syncing domain
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
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
check_result $? "$HOST connection failed (exp insert)" $E_CONNECT
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
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
# 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 #
#----------------------------------------------------------#
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
@ -24,45 +24,86 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_procces_running
remote_dns_health_check
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Parsing remote host parameters
eval $cluster
# Check remote dns nodes
remote_dns_health_check
# Syncing SOA
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
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 (sync)" $E_CONNECT
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $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
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
# 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 #
#----------------------------------------------------------#
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
domain=$2
@ -24,45 +24,100 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
validate_format 'user' 'domain'
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_procces_running
remote_dns_health_check
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
echo "Error: dns-cluster.conf doesn't exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
# Parsing remote host parameters
eval $cluster
# Check remote dns nodes
remote_dns_health_check
# Syncing TTL
# 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
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 (sync)" $E_CONNECT
eval $str
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed (rebuild)" $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
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating pipe
# 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 #
#----------------------------------------------------------#
exit

View file

@ -10,7 +10,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
value=$2
@ -18,34 +18,27 @@ value=$2
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'KEY VALUE'
is_format_valid 'key'
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
format_no_quotes "$value" 'value'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating 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
sed -i "s/$key=.*/$key='$value'/g" $VESTA/conf/vesta.conf
#----------------------------------------------------------#
@ -53,6 +46,6 @@ fi
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
domain=$1
# Includes
@ -22,7 +22,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '1' "$#" 'HOSTNAME'
is_format_valid 'domain'
validate_format 'domain'
#----------------------------------------------------------#
@ -31,16 +31,18 @@ is_format_valid 'domain'
hostname $domain
if [ -d "/etc/sysconfig" ]; then
# RHEL/CentOS/Amazon
# RHEL/CentOS
if [ -e "/etc/redhat-release" ]; then
touch /etc/sysconfig/network
if [ -z "$(grep HOSTNAME /etc/sysconfig/network)" ]; then
echo "HOSTNAME='$domain'" >> /etc/sysconfig/network
else
sed -i "s/HOSTNAME=.*/HOSTNAME='$domain'/" /etc/sysconfig/network
fi
else
# Debian/Ubuntu
fi
# Debian/Ubuntu
if [ ! -e "/etc/redhat-release" ]; then
echo "$domain" > /etc/hostname
fi
@ -50,6 +52,6 @@ fi
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
ip=$1
ip_name=$2
@ -24,9 +24,11 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'IP IP_NAME'
is_format_valid 'ip'
is_format_valid 'ip_name'
is_ip_valid "$ip"
validate_format 'ip'
if [ ! -z "$ip_name" ]; then
validate_format 'ip_name'
fi
is_ip_valid
#----------------------------------------------------------#
@ -42,7 +44,7 @@ update_ip_value '$NAME' "$ip_name"
#----------------------------------------------------------#
# Logging
log_history "changed associated dns on $ip to $ip_name" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_history "changed associated dns on $ip to $domain" '' 'admin'
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
ip=$1
nat_ip=$2
restart=$3
@ -25,83 +25,65 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'IP NAT_IP [RESTART]'
is_format_valid 'ip'
is_format_valid 'nat_ip'
is_ip_valid "$ip"
validate_format 'ip'
if [ ! -z "$nat_ip" ]; then
validate_format 'nat_ip'
fi
is_ip_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating IP
# Changing nat ip
if [ -z "$(grep NAT= $VESTA/data/ips/$ip)" ]; then
sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $VESTA/data/ips/$ip
old=''
new=$nat_ip
else
old=$(get_ip_value '$NAT')
new=$nat_ip
sed -i "s/NAT=.*/NAT='$new'/" $VESTA/data/ips/$ip
if [ -z "$nat_ip" ]; then
new=$ip
update_ip_value '$NAT' "$nat_ip"
fi
# Check ftp system
if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
# Find configuration
if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
conf='/etc/vsftpd/vsftpd.conf'
fi
fi
# Updating WEB configs
if [ ! -z "$old" ] && [ ! -z "$WEB_SYSTEM" ]; then
sed -i "s/$old/$new/" $VESTA/data/users/*/web.conf
for user in $(ls $VESTA/data/users/); do
$BIN/v-rebuild-web-domains $user no
done
$BIN/v-restart-dns $restart
fi
if [ -e '/etc/vsftpd.conf' ]; then
conf='/etc/vsftpd.conf'
fi
# Updating DNS configs
if [ ! -z "$old" ] && [ ! -z "$DNS_SYSTEM" ]; then
sed -i "s/$old/$new/" $VESTA/data/users/*/dns.conf
sed -i "s/$old/$new/" $VESTA/data/users/*/dns/*.conf
for user in $(ls $VESTA/data/users/); do
$BIN/v-rebuild-dns-domains $user no
done
$BIN/v-restart-dns $restart
fi
# Updating FTP
if [ ! -z "$old" ] && [ ! -z "$FTP_SYSTEM" ]; then
conf=$(find /etc -name $FTP_SYSTEM.conf)
if [ -e "$conf" ]; then
sed -i "s/$old/$new/g" $conf
if [ "$FTP_SYSTEM" = 'vsftpd' ]; then
check_pasv=$(grep pasv_address $conf)
if [ -z "$check_pasv" ] && [ ! -z "$nat_ip" ]; then
echo "pasv_address=$nat_ip" >> $conf
fi
if [ ! -z "$check_pasv" ] && [ -z "$nat_ip" ]; then
sed -i "/pasv_address/d" $conf
fi
if [ ! -z "$check_pasv" ] && [ ! -z "$nat_ip" ]; then
sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
fi
# Update config
if [ -z "$(grep pasv_address $conf)" ]; then
if [ ! -z "$nat_ip" ]; then
echo "pasv_address=$nat_ip" >> $conf
fi
else
if [ ! -z "$nat_ip" ]; then
sed -i "s/pasv_address=.*/pasv_address='$nat_ip'/g" $conf
else
sed -i "/pasv_address/d" $conf
fi
fi
$BIN/v-restart-ftp $restart
fi
# Updating firewall
if [ ! -z "$old" ] && [ ! -z "$FIREWALL_SYSTEM" ]; then
sed -i "s/$old/$new/g" $VESTA/data/firewall/*.conf
$BIN/v-update-firewall
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restart ftp server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-ftp
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
ip=$1
user=$2
@ -24,13 +24,14 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'IP USER'
is_format_valid 'ip' 'user'
validate_format 'ip' 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_ip_valid "$ip"
is_ip_valid
is_ip_key_empty '$U_WEB_DOMAINS'
is_ip_key_empty '$U_SYS_USERS'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
@ -76,6 +77,6 @@ fi
# Logging
log_history "changed owner of $ip to $user" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
ip=$1
ip_status=$2
@ -24,16 +24,21 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'IP IP_STATUS'
is_format_valid 'ip' 'ip_status'
is_ip_valid "$ip"
validate_format 'ip' 'ip_status'
is_ip_valid
if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
check_result "$E_EXISTS" "status $ip_status is already set"
echo "Error: status $ip_status is already set"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
web_domains=$(get_ip_value '$U_WEB_DOMAINS')
sys_user=$(get_ip_value '$U_SYS_USERS')
ip_owner=$(get_ip_value '$OWNER')
if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
check_result "$E_INUSE" "ip $ip is used"
echo "Error: ip $ip is used"
log_event "$E_INUSE" "$EVENT"
exit $E_INUSE
fi
@ -51,6 +56,6 @@ update_ip_value '$STATUS' "$ip_status"
# Logging
log_history "changed $ip status to $ip_status" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
language=$1
# Includes
@ -20,7 +20,7 @@ source $VESTA/conf/vesta.conf
is_language_valid() {
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
echo "Error: language file $language doesn't exist"
log_event "$E_NOTEXIST $ARGUMENTS"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
}
@ -31,7 +31,7 @@ is_language_valid() {
#----------------------------------------------------------#
check_args '1' "$#" 'LANGUAGE'
is_format_valid 'language'
validate_format 'language'
is_language_valid $language
@ -52,6 +52,6 @@ fi
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -1,131 +0,0 @@
#!/bin/bash
# info: change service config
# options: CONFIG SERVICE [RESTART]
#
# The function for changing service confguration.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
src=$1
service=$2
restart=$3
echo "$0 $*" >/tmp/t.log
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'CONFIG SERVICE [RESTART]'
if [ ! -e "$src" ]; then
check_result "$E_NOTEXIST" "$src config doesn't exist"
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining dst config path
case $service in
nginx) dst='/etc/nginx/nginx.conf';;
httpd) dst='/etc/httpd/conf/httpd.conf';;
apache2) dst='/etc/apache2/apache2.conf';;
exim) dst='/etc/exim/exim.conf';;
exim4) dst='/etc/exim4/exim4.conf.template';;
vsftpd) dst=$(find /etc/vsftpd* -name 'vsftpd.conf');;
proftpd) dst=$(find /etc/proftpd* -name 'proftpd.conf');;
php) dst=$(find /etc/php* -name php.ini);;
mysql) dst=$(find /etc/my* -name my.cnf);;
mysqld) dst=$(find /etc/my* -name my.cnf);;
mariadb) dst=$(find /etc/my* -name my.cnf);;
postgresql) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 1);;
postgresql-hba) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 2);;
dovecot) dst=$(find /etc/dovecot* -name dovecot.conf);;
dovecot-1) dst='/etc/dovecot/conf.d/10-auth.conf';;
dovecot-2) dst='/etc/dovecot/conf.d/10-logging.conf';;
dovecot-3) dst='/etc/dovecot/conf.d/10-mail.conf';;
dovecot-4) dst='/etc/dovecot/conf.d/10-master.conf';;
dovecot-5) dst='/etc/dovecot/conf.d/10-ssl.conf';;
dovecot-6) dst='/etc/dovecot/conf.d/20-imap.conf';;
dovecot-7) dst='/etc/dovecot/conf.d/20-pop3.conf';;
dovecot-8) dst='/etc/dovecot/conf.d/auth-passwdfile.conf.ext';;
named) dst='/etc/named.conf';;
bind9) dst='/etc/bind/named.conf';;
bind9-opt) dst='/etc/bind/named.conf.options';;
spamd) dst=$($BIN/v-list-sys-spamd-config plain);;
spamassassin) dst=$($BIN/v-list-sys-spamd-config plain);;
clamd) dst=$($BIN/v-list-sys-clamd-config plain);;
clamd.scan) dst=$($BIN/v-list-sys-clamd-config plain);;
cron) dst='/etc/crontab';;
crond) dst='/etc/crontab';;
fail2ban) dst='/etc/fail2ban/jail.local';;
*) check_result $E_NOTEXIST "service $service doesn't exist"
esac
# Checking config path
for config in $dst; do
if [ ! -e "$config" ]; then
check_result $E_NOTEXIST "$service config doesn't exist"
fi
done
# Checking diff between src and dst configs
for config in $dst; do
diff -q $src $config >/dev/null
if [ $? -ne 0 ]; then
cp $config $config.vst.back
cp $src $config
update="yes"
fi
done
# Restarting service
if [ "$update" = 'yes' ] && [ "$restart" != 'no' ]; then
if [[ "$service" =~ - ]]; then
service=$(echo ${service%-*})
fi
if [ "$service" = 'php' ]; then
if [ "$WEB_SYSTEM" = "nginx" ]; then
if [ $(ps --no-headers -o comm 1) == systemd ]; then
service=$(systemctl | grep -o -E "php.*fpm.*\.service")
service=${service//.service/}
else
service=$(ls /etc/init.d/php*fpm* |cut -f 4 -d /)
fi
else
service=$WEB_SYSTEM
fi
fi
for single_service in $service; do
service $single_service restart >/dev/null 2>&1
done <<< "$service"
if [ $? -ne 0 ]; then
for config in $dst; do
cat $config.vst.back > $config
rm -f $config.vst.back
done
check_result $E_RESTART "$service failed to start with new config"
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -1,72 +0,0 @@
#!/bin/bash
# info: change system timezone
# options: TIMEZONE
#
# The function for changing system timezone.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
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 "$ARGUMENTS"
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" "$ARGUMENTS"
exit

View file

@ -1,77 +0,0 @@
#!/bin/bash
# info: change vesta ssl certificate
# options: SSL_DIR [RESTART]
#
# The function changes vesta SSL certificate and the key.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
domain='certificate'
ssl_dir=$1
restart=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'SSL_DIR [RESTART]'
is_format_valid 'ssl_dir'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking new certificate
certificate=$(cat $ssl_dir/$domain.crt |grep -n END)
certificate_count=$(echo "$certificate" |wc -l)
if [ "$certificate_count" -gt 1 ]; then
crt_end=$(echo "$certificate" |head -n1 |cut -f 1 -d :)
crt_lines=$(wc -l $ssl_dir/$domain.crt |cut -f1 -d ' ')
pem_begin=$((crt_lines - crt_end))
mv $ssl_dir/$domain.crt $ssl_dir/$domain.crt_full
head -n $crt_end $ssl_dir/$domain.crt_full > $ssl_dir/$domain.crt
tail -n $pem_begin $ssl_dir/$domain.crt_full > $ssl_dir/$domain.ca
is_web_domain_cert_valid
mv -f $ssl_dir/$domain.crt_full $ssl_dir/$domain.crt
rm -f $ssl_dir/$domain.ca
else
is_web_domain_cert_valid
fi
# Moving old certificate
mv $VESTA/ssl/certificate.crt $VESTA/ssl/certificate.crt.back
mv $VESTA/ssl/certificate.key $VESTA/ssl/certificate.key.back
# Adding new certificate
cp -f $ssl_dir/certificate.crt $VESTA/ssl/certificate.crt
cp -f $ssl_dir/certificate.key $VESTA/ssl/certificate.key
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restarting web server
if [ "$restart" != 'no' ]; then
kill -HUP $(cat /var/run/vesta-nginx.pid)
$BIN/v-restart-mail
if [ ! -z "$IMAP_SYSTEM" ]; then
v-restart-service "$IMAP_SYSTEM"
fi
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
email=$2
@ -23,7 +23,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER EMAIL'
is_format_valid 'user' 'email'
validate_format 'user' 'email'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -49,6 +49,6 @@ $BIN/v-rebuild-cron-jobs $user > /dev/null 2>&1
# Logging
log_history "changed contact email to $email"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
language=$2
@ -19,14 +19,9 @@ source $VESTA/conf/vesta.conf
is_language_valid() {
if ! [[ "$1" =~ ^[[:alnum:]_-]+$ ]]; then
echo "Error: language $1 is not valid"
log_event "$E_INVALID" "$ARGUMENTS"
exit $E_INVALID
fi
if [ ! -e "$VESTA/web/inc/i18n/$1.php" ]; then
echo "Error: language $1 doesn't exist"
log_event "$E_NOTEXIST" "$ARGUMENTS"
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
echo "Error: language $language not exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
}
@ -37,7 +32,7 @@ is_language_valid() {
#----------------------------------------------------------#
check_args '2' "$#" 'USER LANGUAGE'
is_format_valid 'user' 'language'
validate_format 'user' 'language'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_language_valid $language
@ -61,6 +56,6 @@ fi
# Logging
log_history "changed language to $language"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,7 +9,7 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
fname=$2
lname=$3
@ -24,7 +24,7 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
check_args '3' "$#" 'USER FNAME LNAME'
is_format_valid 'user' 'fname' 'lname'
validate_format 'user' 'fname' 'lname'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
@ -48,6 +48,6 @@ update_user_value "$user" '$LNAME' "$lname"
# Logging
log_history "changed user name to $fname $lname"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

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

View file

@ -9,19 +9,23 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
package=$2
force=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.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
eval ${key%%=*}=${key#*=}
done
source $USER_DATA/user.conf
WEB_DOMAINS='0'
DATABASES='0'
MAIL_DOMAINS='0'
@ -29,66 +33,32 @@ is_package_avalable() {
DISK_QUOTA='0'
BANDWIDTH='0'
pkg_data=$(cat $VESTA/data/packages/$package.pkg| egrep -v "TIME|DATE")
IFS=$'\n'
for str in $pkg_data; do
key=$(echo $str |cut -f 1 -d =)
value=$(echo $str |cut -f 2 -d \')
eval $key="$value"
done
pkg_data=$(cat $VESTA/data/packages/$package.pkg |grep -v TIME |\
grep -v DATE)
eval $pkg_data
# Checking usage agains package limits
if [ "$WEB_DOMAINS" != 'unlimited' ]; then
if [ "$WEB_DOMAINS" -lt "$U_WEB_DOMAINS" ]; then
check_result $E_LIMIT "Package doesn't cover WEB_DOMAIN usage"
fi
# 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
fi
if [ "$DNS_DOMAINS" != 'unlimited' ]; then
if [ "$DNS_DOMAINS" -lt "$U_DNS_DOMAINS" ]; then
check_result $E_LIMIT "Package doesn't cover DNS_DOMAIN usage"
fi
fi
if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
if [ "$MAIL_DOMAINS" -lt "$U_MAIL_DOMAINS" ]; then
check_result $E_LIMIT "Package doesn't cover MAIL_DOMAIN usage"
fi
fi
if [ "$DATABASES" != 'unlimited' ]; then
if [ "$DATABASES" -lt "$U_DATABASES" ]; then
check_result $E_LIMIT "Package doesn't cover DATABASE usage"
fi
fi
if [ "$CRON_JOBS" != 'unlimited' ]; then
if [ "$CRON_JOBS" -lt "$U_CRON_JOBS" ]; then
check_result $E_LIMIT "Package doesn't cover CRON usage"
fi
fi
if [ "$DISK_QUOTA" != 'unlimited' ]; then
if [ "$DISK_QUOTA" -lt "$U_DISK" ]; then
check_result $E_LIMIT "Package doesn't cover DISK usage"
fi
fi
if [ "$BANDWIDTH" != 'unlimited' ]; then
if [ "$BANDWIDTH" -lt "$U_BANDWIDTH" ]; then
check_result $E_LIMIT "Package doesn't cover BANDWIDTH usage"
fi
fi
# Checking templates
is_web_template_valid $WEB_TEMPLATE
is_dns_template_valid $DNS_TEMPLATE
is_proxy_template_valid $PROXY_TEMPLATE
}
change_user_package() {
source $USER_DATA/user.conf
pkg_data=$(cat $VESTA/data/packages/$package.pkg| egrep -v "TIME|DATE")
IFS=$'\n'
for str in $pkg_data; do
key=$(echo $str |cut -f 1 -d =)
value=$(echo $str |cut -f 2 -d \')
eval $key="$value"
done
usr_data=$(cat $USER_DATA/user.conf)
eval $usr_data
pkg_data=$(cat $VESTA/data/packages/$package.pkg |grep -v TIME |\
grep -v DATE)
eval $pkg_data
echo "FNAME='$FNAME'
LNAME='$LNAME'
PACKAGE='$package'
@ -140,7 +110,6 @@ 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
}
@ -151,7 +120,7 @@ DATE='$DATE'" > $USER_DATA/user.conf
#----------------------------------------------------------#
check_args '2' "$#" 'USER PACKAGE [FORCE]'
is_format_valid 'user' 'package'
validate_format 'user' 'package'
is_object_valid 'user' 'USER' "$user"
is_package_valid
if [ "$force" != 'yes' ];then
@ -167,7 +136,7 @@ fi
change_user_package
# Update user shell
shell_conf=$(echo "$pkg_data" |grep 'SHELL' |cut -f 2 -d \')
shell_conf=$(echo "$pkg_data" | grep 'SHELL' | cut -f 2 -d \')
shell=$(grep -w "$shell_conf" /etc/shells |head -n1)
/usr/bin/chsh -s "$shell" "$user" &>/dev/null
@ -176,12 +145,6 @@ 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 #
@ -189,6 +152,6 @@ fi
# Logging
log_history "changed $user package to $package" '' 'admin'
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

View file

@ -9,31 +9,27 @@
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
# Argument defenition
user=$1
password=$2; HIDE=2
# Importing system enviroment as we run this script
# mostly by cron wich not read it by itself
source /etc/profile
password=$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 #
#----------------------------------------------------------#
if [ "$user" = "root" ]; then
check_result $E_FORBIDEN "Changing root password is forbiden"
fi
check_args '2' "$#" 'USER PASSWORD'
is_format_valid 'user'
validate_format 'user' 'password'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_password_valid
#----------------------------------------------------------#
@ -44,21 +40,17 @@ is_password_valid
echo "$user:$password" | /usr/sbin/chpasswd
md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
if [ "$user" = 'admin' ] && [ -e "$VESTA/web/reset.admin" ]; then
rm -f $VESTA/web/reset.admin
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing RKEY value
update_user_value "$user" '$RKEY' "$(generate_password)"
update_user_value "$user" '$RKEY' "$(gen_password)"
update_user_value "$user" '$MD5' "$md5"
# Logging
log_history "changed password"
log_event "$OK" "$ARGUMENTS"
log_event "$OK" "$EVENT"
exit

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