mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 10:37:42 -07:00
Refactoring stage II
This commit is contained in:
parent
83196f310b
commit
b998c72500
88 changed files with 422 additions and 896 deletions
170
func/domain.sh
170
func/domain.sh
|
@ -1,3 +1,39 @@
|
|||
# Web template check
|
||||
is_apache_template_valid() {
|
||||
c=$(echo "$templates" | grep -w "$template")
|
||||
t="$WEBTPL/apache_$template.tpl"
|
||||
d="$WEBTPL/apache_$template.descr"
|
||||
s="$WEBTPL/apache_$template.stpl"
|
||||
if [ -z "$c" ] || [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then
|
||||
echo "Error: $template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# Nginx template check
|
||||
is_nginx_template_valid() {
|
||||
t="$WEBTPL/ngingx_vhost_$template.tpl"
|
||||
d="$WEBTPL/ngingx_vhost_$template.descr"
|
||||
s="$WEBTPL/ngingx_vhost_$template.stpl"
|
||||
if [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then
|
||||
echo "Error: $template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# DNS template check
|
||||
is_dns_template_valid() {
|
||||
tpl="$DNSTPL/$template.tpl"
|
||||
descr="$DNSTPL/$template.descr"
|
||||
if [ ! -e $tpl ] || [ ! -e $descr ]; then
|
||||
echo "Error: template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# Checking domain existance
|
||||
is_domain_new() {
|
||||
config_type="$1"
|
||||
|
@ -20,38 +56,12 @@ is_domain_new() {
|
|||
fi
|
||||
}
|
||||
|
||||
is_domain_suspended() {
|
||||
config_type="$1"
|
||||
# Parsing domain values
|
||||
check_domain=$(grep "DOMAIN='$domain'" $USER_DATA/$config_type.conf|\
|
||||
grep "SUSPENDED='yes'")
|
||||
|
||||
# Checking result
|
||||
if [ ! -z "$check_domain" ]; then
|
||||
echo "Error: domain $domain is suspended"
|
||||
log_event 'debug' "$E_SUSPENDED $EVENT"
|
||||
exit $E_SUSPENDED
|
||||
fi
|
||||
}
|
||||
|
||||
is_domain_unsuspended() {
|
||||
config_type="$1"
|
||||
# Parsing domain values
|
||||
check_domain=$(grep "DOMAIN='$domain'" $USER_DATA/$config_type.conf|\
|
||||
grep "SUSPENDED='no'")
|
||||
|
||||
# Checking result
|
||||
if [ ! -z "$check_domain" ]; then
|
||||
echo "Error: domain unsuspended"
|
||||
log_event 'debug' "$E_UNSUSPENDED $EVENT"
|
||||
exit $E_UNSUSPENDED
|
||||
fi
|
||||
}
|
||||
|
||||
# Update domain zone
|
||||
update_domain_zone() {
|
||||
# Definigng variables
|
||||
conf="$HOMEDIR/$user/conf/dns/$domain.db"
|
||||
line=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
|
||||
fields='$RECORD\t$TTL\tIN\t$TYPE\t$VALUE'
|
||||
fields='$RECORD\t$TTL\tIN\t$TYPE\t$PRIORITY\t$VALUE'
|
||||
|
||||
# Checking serial
|
||||
if [ -e $conf ]; then
|
||||
|
@ -99,34 +109,21 @@ update_domain_zone() {
|
|||
|
||||
# Converting utf records to ascii
|
||||
RECORD=$(idn --quiet -a -t "$RECORD")
|
||||
#VALUE=$(idn --quiet -a -t "$VALUE")
|
||||
eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf
|
||||
done < $USER_DATA/dns/$domain
|
||||
done < $USER_DATA/dns/$domain.conf
|
||||
}
|
||||
|
||||
get_next_dns_record() {
|
||||
# Parsing config
|
||||
curr_str=$(grep "ID=" $USER_DATA/dns/$domain|cut -f 2 -d \'|\
|
||||
sort -n|tail -n1)
|
||||
|
||||
# Print result
|
||||
echo "$((curr_str +1))"
|
||||
}
|
||||
|
||||
is_dns_record_free() {
|
||||
# Checking record id
|
||||
check_id=$(grep "ID='$id'" $USER_DATA/dns/$domain)
|
||||
|
||||
if [ ! -z "$check_id" ]; then
|
||||
echo "Error: ID exist"
|
||||
log_event 'debug' "$E_EXISTS $EVENT"
|
||||
exit $E_EXISTS
|
||||
get_next_dnsrecord(){
|
||||
if [ -z "$id" ]; then
|
||||
curr_str=$(grep "ID=" $USER_DATA/dns/$domain.conf | cut -f 2 -d \' |\
|
||||
sort -n|tail -n1)
|
||||
id="$((curr_str +1))"
|
||||
fi
|
||||
}
|
||||
|
||||
sort_dns_records() {
|
||||
# Defining conf
|
||||
conf="$USER_DATA/dns/$domain"
|
||||
conf="$USER_DATA/dns/$domain.conf"
|
||||
cat $conf |sort -n -k 2 -t \' >$conf.tmp
|
||||
mv -f $conf.tmp $conf
|
||||
}
|
||||
|
@ -231,86 +228,13 @@ replace_web_config() {
|
|||
sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf
|
||||
}
|
||||
|
||||
get_domain_value() {
|
||||
conf_type="$1"
|
||||
key="$2"
|
||||
default_str="DOMAIN='$domain'"
|
||||
search_str="${3-DOMAIN=$search_str}"
|
||||
|
||||
# Parsing config
|
||||
string=$(grep "$search_str" $USER_DATA/$conf_type.conf )
|
||||
|
||||
# Parsing key=value
|
||||
eval $string
|
||||
|
||||
# Self reference
|
||||
eval value="$key"
|
||||
|
||||
# Print value
|
||||
echo "$value"
|
||||
}
|
||||
|
||||
# Get domain values
|
||||
get_domain_values() {
|
||||
# Defining domain parameters
|
||||
for line in $(grep "DOMAIN='$domain'" $USER_DATA/$1.conf); do
|
||||
# Assing key=value
|
||||
eval $line
|
||||
done
|
||||
}
|
||||
|
||||
update_domain_value() {
|
||||
conf_type="$1"
|
||||
key="$2"
|
||||
value="$3"
|
||||
default_str="DOMAIN='$domain'"
|
||||
search_str=${4-$default_str}
|
||||
|
||||
# Defining conf
|
||||
conf="$USER_DATA/$conf_type.conf"
|
||||
|
||||
# Parsing conf
|
||||
domain_str=$(grep -n "$search_str" $conf)
|
||||
str_number=$(echo $domain_str | cut -f 1 -d ':')
|
||||
str=$(echo $domain_str | cut -f 2 -d ':')
|
||||
|
||||
# Reading key=values
|
||||
eval $str
|
||||
|
||||
# Defining clean key
|
||||
c_key=$(echo "${key//$/}")
|
||||
|
||||
eval old="${key}"
|
||||
|
||||
# Escaping slashes
|
||||
old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
||||
new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
||||
|
||||
# Updating conf
|
||||
sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
|
||||
$conf
|
||||
}
|
||||
|
||||
is_domain_key_empty() {
|
||||
conf_type="$1"
|
||||
key="$2"
|
||||
|
||||
# Parsing domains
|
||||
string=$( grep "DOMAIN='$domain'" $USER_DATA/$conf_type.conf )
|
||||
|
||||
# Parsing key=value
|
||||
eval $string
|
||||
|
||||
# Self reference
|
||||
eval value="$key"
|
||||
|
||||
# Checkng key
|
||||
if [ ! -z "$value" ] && [ "$value" != 'no' ]; then
|
||||
echo "Error: ${key//$} is not empty = $value"
|
||||
log_event 'debug' "$E_EXISTS $EVENT"
|
||||
exit $E_EXISTS
|
||||
fi
|
||||
}
|
||||
|
||||
is_web_domain_cert_valid() {
|
||||
|
||||
# Checking file existance
|
||||
|
|
106
func/shared.sh
106
func/shared.sh
|
@ -51,7 +51,7 @@ log_history() {
|
|||
# Argument list checker
|
||||
check_args() {
|
||||
if [ "$1" -gt "$2" ]; then
|
||||
echo "Error: bad args"
|
||||
echo "Error: not enought arguments"
|
||||
echo "Usage: $SCRIPT $3"
|
||||
log_event "$E_ARGS" "$EVENT"
|
||||
exit $E_ARGS
|
||||
|
@ -75,14 +75,13 @@ is_package_full() {
|
|||
awk -F "ALIAS='" '{print $2}' | cut -f 1 -d \' | tr ',' '\n' |\
|
||||
wc -l );;
|
||||
DNS_DOMAINS) used=$(wc -l $USER_DATA/dns.conf |cut -f1 -d \ );;
|
||||
DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain |cut -f1 -d \ );;
|
||||
DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain.conf |cut -f1 -d \ );;
|
||||
MAIL_DOMAINS) used=$(wc -l $USER_DATA/mail.conf |cut -f1 -d \ );;
|
||||
MAIL_ACCOUNTS) used=$(wc -l $USER_DATA/mail/$domain |\
|
||||
MAIL_ACCOUNTS) used=$(wc -l $USER_DATA/mail/$domain.conf |\
|
||||
cut -f1 -d \ );;
|
||||
DATABASES) used=$(wc -l $USER_DATA/db.conf |cut -f1 -d \ );;
|
||||
CRON_JOBS) used=$(wc -l $USER_DATA/cron.conf |cut -f1 -d \ );;
|
||||
esac
|
||||
|
||||
limit=$(grep "^$1=" $USER_DATA/user.conf | cut -f 2 -d \' )
|
||||
if [ "$used" -ge "$limit" ]; then
|
||||
echo "Error: Upgrade package"
|
||||
|
@ -102,42 +101,6 @@ gen_password() {
|
|||
echo "$pass"
|
||||
}
|
||||
|
||||
# Web template check
|
||||
is_apache_template_valid() {
|
||||
c=$(echo "$templates" | grep -w "$template")
|
||||
t="$WEBTPL/apache_$template.tpl"
|
||||
d="$WEBTPL/apache_$template.descr"
|
||||
s="$WEBTPL/apache_$template.stpl"
|
||||
if [ -z "$c" ] || [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then
|
||||
echo "Error: $template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# Nginx template check
|
||||
is_nginx_template_valid() {
|
||||
t="$WEBTPL/ngingx_vhost_$template.tpl"
|
||||
d="$WEBTPL/ngingx_vhost_$template.descr"
|
||||
s="$WEBTPL/ngingx_vhost_$template.stpl"
|
||||
if [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then
|
||||
echo "Error: $template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# DNS template check
|
||||
is_dns_template_valid() {
|
||||
tpl="$DNSTPL/$template.tpl"
|
||||
descr="$DNSTPL/$template.descr"
|
||||
if [ ! -e $tpl ] || [ ! -e $descr ]; then
|
||||
echo "Error: template not found"
|
||||
log_event "$E_NOTEXIST" "$EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
# Package existance check
|
||||
is_package_valid() {
|
||||
if [ ! -e "$VESTA/data/packages/$package.pkg" ]; then
|
||||
|
@ -176,7 +139,7 @@ is_object_free() {
|
|||
object=$(grep "$2='$3'" $USER_DATA/$1.conf)
|
||||
fi
|
||||
if [ ! -z "$object" ]; then
|
||||
echo "Error: $3 exists"
|
||||
echo "Error: $2 with value $3 exists"
|
||||
log_event "$E_EXISTS" "$EVENT"
|
||||
exit $E_EXISTS
|
||||
fi
|
||||
|
@ -209,7 +172,7 @@ is_object_suspended() {
|
|||
else
|
||||
spnd=$(grep "$2='$3'" $USER_DATA/$1.conf|grep "SUSPENDED='yes'")
|
||||
fi
|
||||
if [ ! -z "$spnd" ]; then
|
||||
if [ -z "$spnd" ]; then
|
||||
echo "Error: $3 is suspended"
|
||||
log_event "$E_SUSPENDED" "$EVENT"
|
||||
exit $E_SUSPENDED
|
||||
|
@ -223,13 +186,21 @@ is_object_unsuspended() {
|
|||
else
|
||||
spnd=$(grep "$2='$3'" $USER_DATA/$1.conf|grep "SUSPENDED='yes'")
|
||||
fi
|
||||
if [ -z "$spnd" ]; then
|
||||
if [ ! -z "$spnd" ]; then
|
||||
echo "Error: $3 is not suspended"
|
||||
log_event "$E_UNSUSPENDED" "$EVENT"
|
||||
exit $E_UNSUSPENDED
|
||||
fi
|
||||
}
|
||||
|
||||
# Get object value
|
||||
get_object_value() {
|
||||
object=$(grep "$2='$3'" $USER_DATA/$1.conf)
|
||||
eval "$object"
|
||||
eval object_val="$4"
|
||||
echo "$object_val"
|
||||
}
|
||||
|
||||
# Update object value
|
||||
update_object_value() {
|
||||
row=$(grep -n "$2='$3'" $USER_DATA/$1.conf)
|
||||
|
@ -256,7 +227,7 @@ search_objects() {
|
|||
|
||||
# Get user value
|
||||
get_user_value() {
|
||||
grep "^$1=" $USER_DATA/user.conf| cut -f 2 -d \'
|
||||
grep "^${1//$/}=" $USER_DATA/user.conf| cut -f 2 -d \'
|
||||
}
|
||||
|
||||
# Update user value in user.conf
|
||||
|
@ -514,7 +485,7 @@ validate_format_email() {
|
|||
# Username
|
||||
validate_format_username() {
|
||||
if ! [[ "$1" =~ ^[0-Z]+(\.[0-Z]+)?$ ]] || [[ "${#1}" -gt 28 ]]; then
|
||||
echo "Error: usernmae $1 is not valid"
|
||||
echo "Error: $2 $1 is not valid"
|
||||
log_event "$E_INVALID" "$EVENT"
|
||||
exit $E_INVALID
|
||||
fi
|
||||
|
@ -593,10 +564,10 @@ validate_format_mhdmw() {
|
|||
}
|
||||
|
||||
# Nginx static extention or DNS record
|
||||
validate_format_extentions() {
|
||||
exclude="[!|@|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%| ]"
|
||||
validate_format_common() {
|
||||
exclude="[!|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%| ]"
|
||||
if [[ "$1" =~ $exclude ]] || [ 200 -le ${#1} ]; then
|
||||
echo "Error: extention $1 is not valid"
|
||||
echo "Error: $2 $1 is not valid"
|
||||
log_event "$E_INVALID" "$EVENT"
|
||||
exit $E_INVALID
|
||||
fi
|
||||
|
@ -616,6 +587,11 @@ validate_format_dvalue() {
|
|||
if [ "$rtype" = 'NS' ]; then
|
||||
validate_format_domain "$1"
|
||||
fi
|
||||
if [ "$rtype" = 'MX' ]; then
|
||||
validate_format_domain "$1"
|
||||
validate_format_int "$priority"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Date
|
||||
|
@ -630,13 +606,19 @@ validate_format_date() {
|
|||
# Format validation controller
|
||||
validate_format(){
|
||||
for arg_name in $*; do
|
||||
eval arg=\$$argument_name
|
||||
case $var in
|
||||
account) validate_format_username "$arg" ;;
|
||||
eval arg=\$$arg_name
|
||||
if [ -z "$arg" ]; then
|
||||
echo "Error: argument $arg_name is not valid (empty)"
|
||||
log_event "$E_INVALID" "$EVENT"
|
||||
exit $E_INVALID
|
||||
fi
|
||||
|
||||
case $arg_name in
|
||||
account) validate_format_username "$arg" "$arg_name" ;;
|
||||
antispam) validate_format_boolean "$arg" ;;
|
||||
antivirus) validate_format_boolean "$arg" ;;
|
||||
auth_pass) validate_format_password "$arg" ;;
|
||||
auth_user) validate_format_username "$arg" ;;
|
||||
auth_user) validate_format_username "$arg" "$arg_name" ;;
|
||||
backup) validate_format_date "$arg" ;;
|
||||
database) validate_format_database "$arg" ;;
|
||||
day) validate_format_mhdmw "$arg" $arg_name ;;
|
||||
|
@ -648,11 +630,11 @@ validate_format(){
|
|||
dom_alias) validate_format_domain "$arg" ;;
|
||||
dvalue) validate_format_dvalue "$arg";;
|
||||
email) validate_format_email "$arg" ;;
|
||||
encoding) validate_format_username "$arg" ;;
|
||||
encoding) validate_format_username "$arg" "$arg_name" ;;
|
||||
exp) validate_format_date "$arg" ;;
|
||||
extentions) validate_format_extentions "$arg" ;;
|
||||
fname) validate_format_username "$arg" ;;
|
||||
host) validate_format_username "$arg" ;;
|
||||
extentions) validate_format_common "$arg" 'extentions' ;;
|
||||
fname) validate_format_username "$arg" "$arg_name" ;;
|
||||
host) validate_format_username "$arg" "$arg_name" ;;
|
||||
hour) validate_format_mhdmw "$arg" $arg_name ;;
|
||||
id) validate_format_int "$arg" ;;
|
||||
interface) validate_format_interface "$arg" ;;
|
||||
|
@ -660,9 +642,9 @@ validate_format(){
|
|||
ip_name) validate_format_domain "$arg" ;;
|
||||
ip_status) validate_format_ip_status "$arg" ;;
|
||||
job) validate_format_int "$arg" ;;
|
||||
key) validate_format_username "$arg" ;;
|
||||
lname) validate_format_username "$arg" ;;
|
||||
malias) validate_format_username "$arg" ;;
|
||||
key) validate_format_username "$arg" "$arg_name" ;;
|
||||
lname) validate_format_username "$arg" "$arg_name" ;;
|
||||
malias) validate_format_username "$arg" "$arg_name" ;;
|
||||
mask) validate_format_ip "$arg" ;;
|
||||
max_db) validate_format_int "$arg" ;;
|
||||
min) validate_format_mhdmw "$arg" $arg_name ;;
|
||||
|
@ -675,16 +657,16 @@ validate_format(){
|
|||
ns6) validate_format_domain "$arg" ;;
|
||||
ns7) validate_format_domain "$arg" ;;
|
||||
ns8) validate_format_domain "$arg" ;;
|
||||
package) validate_format_username "$arg" ;;
|
||||
package) validate_format_username "$arg" "$arg_name" ;;
|
||||
password) validate_format_password "$arg" ;;
|
||||
port) validate_format_int "$arg" ;;
|
||||
quota) validate_format_int "$arg" ;;
|
||||
restart) validate_format_boolean "$arg" ;;
|
||||
record) validate_format_extentions "$arg" ;;
|
||||
record) validate_format_common "$arg" 'record';;
|
||||
rtype) validate_format_dns_type "$arg" ;;
|
||||
shell) validate_format_shell "$arg" ;;
|
||||
soa) validate_format_domain "$arg" ;;
|
||||
template) validate_format_username "$arg" ;;
|
||||
template) validate_format_username "$arg" "$arg_name" ;;
|
||||
ttl) validate_format_int "$arg" ;;
|
||||
url) validate_format_url "$arg" ;;
|
||||
user) validate_format_username "$arg" ;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue