mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 18:49:21 -07:00
8k alias fix + new tpl convention
This commit is contained in:
parent
9ca747f89e
commit
7ce7cf1797
41 changed files with 721 additions and 908 deletions
|
@ -14,14 +14,14 @@ is_cert_valid() {
|
|||
path="$1"
|
||||
|
||||
# Checking file existance
|
||||
if [ ! -e "$path/$cert.crt" ] || [ ! -e "$path/$cert.key" ]; then
|
||||
if [ ! -e "$path/$ssl.crt" ] || [ ! -e "$path/$ssl.key" ]; then
|
||||
echo "Error: certificate not exist"
|
||||
log_event 'debug' "$E_CERT_NOTEXIST $V_EVENT"
|
||||
exit $E_CERT_NOTEXIST
|
||||
fi
|
||||
|
||||
# Checking crt file
|
||||
crt=$(openssl verify "$path/$cert.crt" 2>/dev/null|tail -n 1|grep -w 'OK')
|
||||
crt=$(openssl verify "$path/$ssl.crt" 2>/dev/null|tail -n 1|grep -w 'OK')
|
||||
if [ -z "$crt" ]; then
|
||||
echo "Error: certificate invalid"
|
||||
log_event 'debug' "$E_CERT_INVALID $V_EVENT"
|
||||
|
@ -29,7 +29,7 @@ is_cert_valid() {
|
|||
fi
|
||||
|
||||
# Checking key file
|
||||
key=$(openssl rsa -in "$path/$cert.key" -check 2>/dev/null|\
|
||||
key=$(openssl rsa -in "$path/$ssl.key" -check 2>/dev/null|\
|
||||
head -n1|grep -w 'ok')
|
||||
if [ -z "$key" ]; then
|
||||
echo "Error: key invalid"
|
||||
|
@ -39,7 +39,7 @@ is_cert_valid() {
|
|||
|
||||
# FIXME we should run server on free port
|
||||
# Checking server
|
||||
cmd="openssl s_server -quiet -cert $path/$cert.crt -key $path/$cert.key"
|
||||
cmd="openssl s_server -quiet -cert $path/$ssl.crt -key $path/$ssl.key"
|
||||
$cmd &
|
||||
|
||||
# Defining pid
|
||||
|
@ -65,7 +65,7 @@ is_cert_valid() {
|
|||
|
||||
is_cert_used() {
|
||||
# Parsing config
|
||||
check_cert=$(grep "SSL_CERT='$cert'" $V_USERS/$user/web.conf)
|
||||
check_cert=$(grep "SSL_CERT='$ssl'" $V_USERS/$user/web.conf)
|
||||
|
||||
# Checking result
|
||||
if [ ! -z "$check_cert" ]; then
|
||||
|
|
141
func/domain.func
141
func/domain.func
|
@ -223,23 +223,28 @@ add_web_config() {
|
|||
# Adding template to config
|
||||
cat $tpl_file | \
|
||||
sed -e "s/%ip%/$ip/g" \
|
||||
-e "s/%web_port%/$web_port/g" \
|
||||
-e "s/%web_ssl_port%/$web_ssl_port/g" \
|
||||
-e "s/%proxy_port%/$proxy_port/g" \
|
||||
-e "s/%proxy_ssl_port%/$proxy_ssl_port/g" \
|
||||
-e "s/%web_port%/$WEB_PORT/g" \
|
||||
-e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
|
||||
-e "s/%proxy_string%/${proxy_string////\/}/g" \
|
||||
-e "s/%proxy_port%/$PROXY_PORT/g" \
|
||||
-e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
|
||||
-e "s/%domain_idn%/$domain_idn/g" \
|
||||
-e "s/%domain%/$domain/g" \
|
||||
-e "s/%user%/$user/g" \
|
||||
-e "s/%group%/$group/g" \
|
||||
-e "s/%home%/${V_HOME////\/}/g" \
|
||||
-e "s/%docroot%/${docroot////\/}/g" \
|
||||
-e "s/%docroot_string%/${docroot_string////\/}/g" \
|
||||
-e "s/%email%/$email/g" \
|
||||
-e "s/%alias_string%/$alias_string/g" \
|
||||
-e "s/%alias_idn%/${aliases_idn//,/ }/g" \
|
||||
-e "s/%alias%/${aliases//,/ }/g" \
|
||||
-e "s/%ssl_cert%/${ssl_cert////\/}/g" \
|
||||
-e "s/%ssl_key%/${ssl_key////\/}/g" \
|
||||
-e "s/%extentions%/${extentions//,/|}/g" \
|
||||
-e "s/%nginx_extentions%/${NGINX_EXT//,/|}/g" \
|
||||
-e "s/%elog%/$elog/g" \
|
||||
-e "s/%cgi%/$cgi/g" \
|
||||
-e "s/%cgi_option%/$cgi_option/g" \
|
||||
>> $conf
|
||||
}
|
||||
|
||||
|
@ -260,6 +265,13 @@ get_web_config_brds() {
|
|||
str=$(grep -ni "Name $domain_idn" $conf | cut -f 1 -d :)
|
||||
top_line=$((str - serv_line + 1))
|
||||
bottom_line=$((top_line + last_line -1))
|
||||
|
||||
# Check for multialias (8k alias issue)
|
||||
multi=$(sed -n "$top_line,$bottom_line p" $conf |grep ServerAlias |wc -l)
|
||||
if [ "$multi" -ge 2 ]; then
|
||||
bottom_line=$((bottom_line + multi -1))
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
change_web_config() {
|
||||
|
@ -286,6 +298,25 @@ change_web_config() {
|
|||
fi
|
||||
}
|
||||
|
||||
replace_web_config() {
|
||||
# Get config borders
|
||||
get_web_config_brds || exit $?
|
||||
|
||||
# Escaping chars
|
||||
clean_new=$(echo "$new" | sed \
|
||||
-e 's/\\/\\\\/g' \
|
||||
-e 's/&/\\&/g' \
|
||||
-e 's/\//\\\//g')
|
||||
|
||||
clean_old=$(echo "$old" | sed \
|
||||
-e 's/\\/\\\\/g' \
|
||||
-e 's/&/\\&/g' \
|
||||
-e 's/\//\\\//g')
|
||||
|
||||
# Replacing string in config
|
||||
sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf
|
||||
}
|
||||
|
||||
get_web_domain_value() {
|
||||
key="$1"
|
||||
|
||||
|
@ -304,6 +335,16 @@ get_web_domain_value() {
|
|||
echo "$value"
|
||||
}
|
||||
|
||||
get_web_domain_values() {
|
||||
# Defining domain parameters
|
||||
for line in $(grep "DOMAIN='$domain'" $V_USERS/$user/web.conf); do
|
||||
# Assing key=value
|
||||
for key in $line; do
|
||||
eval ${key%%=*}=${key#*=}
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
get_dns_domain_value() {
|
||||
key="$1"
|
||||
|
||||
|
@ -406,6 +447,17 @@ is_web_domain_key_empty() {
|
|||
fi
|
||||
}
|
||||
|
||||
is_web_domain_cert_valid() {
|
||||
# Checking file existance
|
||||
path="$V_USERS/$user/cert"
|
||||
if [ ! -e "$path/$ssl.crt" ] || [ ! -e "$path/$ssl.key" ]; then
|
||||
echo "Error: certificate not exist"
|
||||
log_event 'debug' "$E_CERT_NOTEXIST $V_EVENT"
|
||||
exit $E_CERT_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
is_dns_record_valid() {
|
||||
# Checking record id
|
||||
check_id=$(grep "^ID='$id'" $V_USERS/$user/zones/$domain)
|
||||
|
@ -610,3 +662,82 @@ namehost_ip_disable() {
|
|||
web_restart='yes'
|
||||
fi
|
||||
}
|
||||
|
||||
upd_web_domain_values() {
|
||||
ip=$IP
|
||||
group="$user"
|
||||
email="$user@$domain"
|
||||
docroot="$V_HOME/$user/web/$domain/public_html"
|
||||
docroot_string="DocumentRoot $docroot"
|
||||
proxy_string="proxy_pass http://$ip:$WEB_PORT;"
|
||||
|
||||
# Parsing domain aliases
|
||||
i=1
|
||||
j=1
|
||||
OLD_IFS="$IFS"
|
||||
IFS=','
|
||||
server_alias=''
|
||||
alias_string=''
|
||||
for dalias in $ALIAS; do
|
||||
dalias=$(idn -t --quiet -a $dalias)
|
||||
# Spliting ServerAlias lines
|
||||
check_8k="$server_alias $dalias"
|
||||
if [ "${#check_8k}" -ge '8100' ]; then
|
||||
if [ "$j" -eq 1 ]; then
|
||||
alias_string="ServerAlias $server_alias"
|
||||
else
|
||||
alias_string="$alias_string\n ServerAlias $server_alias"
|
||||
fi
|
||||
(( ++j))
|
||||
server_alias=''
|
||||
fi
|
||||
if [ "$i" -eq 1 ]; then
|
||||
aliases_idn="$dalias"
|
||||
server_alias="$dalias"
|
||||
alias_string="ServerAlias $server_alias"
|
||||
else
|
||||
aliases_idn="$aliases_idn,$dalias"
|
||||
server_alias="$server_alias $dalias"
|
||||
fi
|
||||
(( ++i))
|
||||
done
|
||||
|
||||
if [ "$j" -gt 1 ]; then
|
||||
alias_string="$alias_string\n ServerAlias $server_alias"
|
||||
else
|
||||
alias_string="ServerAlias $server_alias"
|
||||
fi
|
||||
|
||||
IFS=$OLD_IFS
|
||||
|
||||
# Checking error log status
|
||||
if [ "$ELOG" = 'no' ]; then
|
||||
elog='#'
|
||||
else
|
||||
elog=''
|
||||
fi
|
||||
|
||||
# Checking cgi
|
||||
if [ "$CGI" != 'yes' ]; then
|
||||
cgi='#'
|
||||
cgi_option='-ExecCGI'
|
||||
else
|
||||
cgi=''
|
||||
cgi_option='+ExecCGI'
|
||||
fi
|
||||
|
||||
# Checking suspend
|
||||
if [ "$SUSPEND" = 'yes' ]; then
|
||||
docroot_string="Redirect / http://$url"
|
||||
proxy_string="rewrite ^(.*)\$ http://$url;"
|
||||
fi
|
||||
|
||||
# Defining SSL vars
|
||||
ssl_cert="$V_HOME/$user/conf/$SSL_CERT.crt"
|
||||
ssl_key="$V_HOME/$user/conf/$SSL_CERT.key"
|
||||
case $SSL_HOME in
|
||||
single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
|
||||
same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
40
func/ip.func
40
func/ip.func
|
@ -117,6 +117,7 @@ is_ip_avalable() {
|
|||
|
||||
is_sys_ip_owner() {
|
||||
# Parsing ip
|
||||
ip="$IP"
|
||||
ip_owner=$(grep 'OWNER=' $V_IPS/$ip|cut -f 2 -d \')
|
||||
if [ "$ip_owner" != "$user" ]; then
|
||||
echo "Error: IP not owned"
|
||||
|
@ -131,13 +132,14 @@ get_ip_name() {
|
|||
}
|
||||
|
||||
increase_ip_value() {
|
||||
sip=${1-ip}
|
||||
USER=$user
|
||||
web_key='U_WEB_DOMAINS'
|
||||
usr_key='U_SYS_USERS'
|
||||
|
||||
# Parsing values
|
||||
current_web=$(grep "$web_key=" $V_IPS/$ip |cut -f 2 -d \')
|
||||
current_usr=$(grep "$usr_key=" $V_IPS/$ip |cut -f 2 -d \')
|
||||
current_web=$(grep "$web_key=" $V_IPS/$sip |cut -f 2 -d \')
|
||||
current_usr=$(grep "$usr_key=" $V_IPS/$sip |cut -f 2 -d \')
|
||||
|
||||
# Checking result
|
||||
if [ -z "$current_web" ]; then
|
||||
|
@ -221,40 +223,6 @@ get_sys_ip_value() {
|
|||
echo "$value"
|
||||
}
|
||||
|
||||
change_domain_ip() {
|
||||
# Defining vars
|
||||
conf="$1"
|
||||
domain="$2"
|
||||
ip="$3"
|
||||
old_ip="$4"
|
||||
tpl_file="$5"
|
||||
|
||||
# Get ServerName line
|
||||
serv_line=$(grep -n 'ServerName %domain_idn%' "$tpl_file" |cut -f 1 -d :)
|
||||
|
||||
# Get tpl_file last line
|
||||
last_line=$(wc -l $tpl_file|cut -f 1 -d ' ')
|
||||
|
||||
# Get before line
|
||||
bfr_line=$((serv_line - 1))
|
||||
|
||||
# Parsing httpd.conf
|
||||
str=$(grep -B $bfr_line -n "ServerName $domain" $conf|grep '<VirtualHost')
|
||||
|
||||
# Checking integrity
|
||||
if [ -z "$str" ] || [ -z "$serv_line" ] || [ -z "$bfr_line" ]; then
|
||||
echo "Error: httpd parsing error"
|
||||
log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
|
||||
exit $E_PARSE_ERROR
|
||||
fi
|
||||
|
||||
# String number
|
||||
str_number=$(echo $str | sed -e "s/-/+/" | cut -f 1 -d '+')
|
||||
|
||||
# Changing elog in config
|
||||
sed -i "$str_number s/$old_ip/$ip/g" $conf
|
||||
}
|
||||
|
||||
get_current_interface() {
|
||||
# Parsing ifconfig
|
||||
i=$(/sbin/ifconfig |grep -B1 "addr:$ip "|head -n 1 |cut -f 1 -d ' ')
|
||||
|
|
|
@ -5,17 +5,13 @@ log_event() {
|
|||
event="$2"
|
||||
|
||||
# Checking logging system
|
||||
log_system=$(grep 'LOG_SYSTEM=' $V_CONF/vesta.conf | cut -f 2 -d \' )
|
||||
|
||||
if [ "$log_system" = 'yes' ]; then
|
||||
if [ "$LOG_SYSTEM" = 'yes' ]; then
|
||||
# Checking logging level
|
||||
log=$(grep 'LOG_LEVEL=' $V_CONF/vesta.conf|\
|
||||
cut -f 2 -d \'|grep -w "$level" )
|
||||
log=$(echo "$LOG_LEVEL" | cut -f 2 -d \' | grep -w "$level" )
|
||||
if [ ! -z "$log" ]; then
|
||||
echo "$event" >> $V_LOG/$level.log
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Log user history
|
||||
|
@ -24,8 +20,7 @@ log_history() {
|
|||
undo="$2"
|
||||
|
||||
# Checking logging system
|
||||
log_history=$(grep 'LOG_HISTORY=' $V_CONF/vesta.conf | cut -f 2 -d \' )
|
||||
if [ "$log_history" = 'yes' ]; then
|
||||
if [ "$LOG_HISTORY" = 'yes' ]; then
|
||||
echo "$event [$undo]" >> $V_USERS/$user/history.log
|
||||
fi
|
||||
}
|
||||
|
@ -328,7 +323,7 @@ format_validation() {
|
|||
dom_alias) format_dom "$v" ;;
|
||||
auth_pass) format_pwd "$v" ;;
|
||||
auth_user) format_usr "$v" ;;
|
||||
certificate) format_usr "$v" ;;
|
||||
ssl) format_usr "$v" ;;
|
||||
domain) format_dom "$v" ;;
|
||||
database) format_db "$v" ;;
|
||||
db_user) format_dbu "$v" ;;
|
||||
|
@ -376,11 +371,7 @@ is_system_enabled() {
|
|||
stype="$1"
|
||||
|
||||
web_function() {
|
||||
# Parsing config
|
||||
web_system=$(grep "WEB_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ -z "$web_system" ] || [ "$web_system" = "no" ]; then
|
||||
if [ -z "$WEB_SYSTEM" ] || [ "$WEB_SYSTEM" = "no" ]; then
|
||||
echo "Error: web hosting support disabled"
|
||||
log_event 'debug' "$E_WEB_DISABLED $V_EVENT"
|
||||
exit $E_WEB_DISABLED
|
||||
|
@ -388,11 +379,7 @@ is_system_enabled() {
|
|||
}
|
||||
|
||||
proxy_function() {
|
||||
# Parsing config
|
||||
proxy_system=$(grep "PROXY_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ "$proxy_system" != 'nginx' ]; then # only nginx
|
||||
if [ "$PROXY_SYSTEM" != 'nginx' ]; then # only nginx
|
||||
echo "Error: proxy hosting support disabled" # support for
|
||||
log_event 'debug' "$E_PROXY_DISABLED $V_EVENT" # now
|
||||
exit $E_PROXY_DISABLED
|
||||
|
@ -400,11 +387,7 @@ is_system_enabled() {
|
|||
}
|
||||
|
||||
dns_function() {
|
||||
# Parsing config
|
||||
dns_system=$(grep "DNS_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ -z "$dns_system" ] || [ "$cron_system" = "no" ]; then
|
||||
if [ -z "$DNS_SYSTEM" ] || [ "$DNS_SYSTEM" = "no" ]; then
|
||||
echo "Error: dns support disabled"
|
||||
log_event 'debug' "$E_DNS_DISABLED $V_EVENT"
|
||||
exit $E_DNS_DISABLED
|
||||
|
@ -412,11 +395,7 @@ is_system_enabled() {
|
|||
}
|
||||
|
||||
cron_function() {
|
||||
# Parsing config
|
||||
cron_system=$(grep "CRON_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ -z "$cron_system" ] || [ "$cron_system" = "no" ]; then
|
||||
if [ -z "$CRON_SYSTEM" ] || [ "$CRON_SYSTEM" = "no" ]; then
|
||||
echo "Error: crond support disabled"
|
||||
log_event 'debug' "$E_CRON_DISABLED $V_EVENT"
|
||||
exit $E_CRON_DISABLED
|
||||
|
@ -424,11 +403,7 @@ is_system_enabled() {
|
|||
}
|
||||
|
||||
db_function() {
|
||||
# Parsing config
|
||||
db_system=$(grep "DB_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ -z "$db_system" ] || [ "$db_system" = "no" ]; then
|
||||
if [ -z "$DB_SYSTEM" ] || [ "$DB_SYSTEM" = "no" ]; then
|
||||
echo "Error: db support disabled"
|
||||
log_event 'debug' "$E_DB_DISABLED $V_EVENT"
|
||||
exit $E_DB_DISABLED
|
||||
|
@ -436,11 +411,7 @@ is_system_enabled() {
|
|||
}
|
||||
|
||||
backup_function() {
|
||||
# Parsing config
|
||||
bck_system=$(grep "BACKUP_SYSTEM=" $V_CONF/vesta.conf|cut -f 2 -d \' )
|
||||
|
||||
# Checking result
|
||||
if [ -z "$bck_system" ] || [ "$bck_system" = "no" ]; then
|
||||
if [ -z "$BACKUP_SYSTEM" ] || [ "$BACKUP_SYSTEM" = "no" ]; then
|
||||
echo "Error: backup support disabled"
|
||||
log_event 'debug' "$E_BACKUP_DISABLED $V_EVENT"
|
||||
exit $E_BACKUP_DISABLED
|
||||
|
@ -803,16 +774,6 @@ increase_user_value() {
|
|||
sed -i "s/$key='$current_value'/$key='$new_value'/g" $conf
|
||||
}
|
||||
|
||||
is_web_domain_cert_valid() {
|
||||
# Checking file existance
|
||||
path="$V_USERS/$user/cert"
|
||||
if [ ! -e "$path/$cert.crt" ] || [ ! -e "$path/$cert.key" ]; then
|
||||
echo "Error: certificate not exist"
|
||||
log_event 'debug' "$E_CERT_NOTEXIST $V_EVENT"
|
||||
exit $E_CERT_NOTEXIST
|
||||
fi
|
||||
}
|
||||
|
||||
is_type_valid() {
|
||||
# Argument defenition
|
||||
sys="$1"
|
||||
|
@ -965,9 +926,9 @@ json_list() {
|
|||
# Printing child
|
||||
if [ $i -lt $fileds_count ]; then
|
||||
(( ++i))
|
||||
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
|
||||
echo -e "\t\t\"${field//$/}\": \"$value\","
|
||||
else
|
||||
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
|
||||
echo -e "\t\t\"${field//$/}\": \"$value\""
|
||||
data=1
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue