فهرست منبع

addopted httpd_change_config for nginx and renamed it

Serghey Rodin 14 سال پیش
والد
کامیت
c5a7bdc8d5

+ 4 - 12
bin/v_add_web_domain_alias

@@ -62,14 +62,10 @@ is_package_full 'web_alias'
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Get template name
+# Defining params for change function
 tpl_name=$(get_web_domain_value '$TPL')
 tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
-
-# Defining config
 conf="$V_HOME/$user/conf/httpd.conf"
-
-# Defining search phrase
 search_phrase='ServerAlias'
 
 # Defining new alias string
@@ -86,20 +82,16 @@ fi
 str_repl="    ServerAlias ${new_alias_idn//,/ }"
 
 # Adding alias
-httpd_change_config
+change_web_config
 
 # Checking ssl domain
 cert=$(get_web_domain_value '$SSL_CERT')
 if [ ! -z "$cert" ]; then
 
-    # Defining ssl template
+    # Defining params for change function
     tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
-
-    # Defining ssl config
     conf="$V_HOME/$user/conf/shttpd.conf"
-
-    # Adding alias
-    httpd_change_config
+    change_web_config
 fi
 
 

+ 9 - 32
bin/v_add_web_domain_cgi

@@ -1,5 +1,5 @@
 #!/bin/bash
-# info: adding cgi for domain
+# info: adding cgi support for domain
 
 #----------------------------------------------------------#
 #                    Variable&Function                     #
@@ -53,55 +53,32 @@ is_web_domain_key_empty '$CGI'
 tpl_name=$(get_web_domain_value '$TPL')
 tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
 
-# Defining config
+# Defining params for ScriptAlias
 conf="$V_HOME/$user/conf/httpd.conf"
-
-# Defining search phrase
 search_phrase='ScriptAlias '
-
-# Defining replace string
 str_repl="    ScriptAlias /cgi-bin/ $V_HOME/$user/domains/$domain/cgi-bin/"
+change_web_config
 
-# Adding cgi-bin support
-httpd_change_config
-
-# Defining search phrase
+# Defining params for Options
 search_phrase='Options '
-
-# Defining replace string
 str_repl='        Options +Includes -Indexes +ExecCGI'
-
-# Adding execscgi support
-httpd_change_config
+change_web_config
 
 # Checking ssl
 cert=$(get_web_domain_value '$SSL_CERT')
 if [ ! -z "$cert" ]; then
 
-    # Get ssl template name
+    # Defining params for ScriptAlias
     tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
-
-    # Defining ssl config
     conf="$V_HOME/$user/conf/shttpd.conf"
-
-    # Defining search phrase
     search_phrase='ScriptAlias '
-
-    # Defining replace string
     str_repl="    ScriptAlias /cgi-bin/ $V_HOME/$user/domains/$domain/cgi-bin/"
+    change_web_config
 
-    # Adding cgi-bin support
-    httpd_change_config
-
-    # Defining search phrase
+    # Defining params for Options
     search_phrase='Options '
-
-    # Defining replace string
     str_repl='        Options +Includes -Indexes +ExecCGI'
-
-    # Adding execscgi support
-    httpd_change_config
-
+    change_web_config
 fi
 
 

+ 2 - 2
bin/v_add_web_domain_elog

@@ -63,7 +63,7 @@ search_phrase='ErrorLog '
 str_repl="    ErrorLog /var/log/httpd/domains/$domain.error.log"
 
 # Adding errolog support
-httpd_change_config
+change_web_config
 
 # Checking ssl
 cert=$(get_web_domain_value '$SSL_CERT')
@@ -76,7 +76,7 @@ if [ ! -z "$cert" ]; then
     conf="$V_HOME/$user/conf/shttpd.conf"
 
     # Adding errolog support
-    httpd_change_config
+    change_web_config
 
 fi
 

+ 2 - 2
bin/v_change_web_domain_sslcert

@@ -71,7 +71,7 @@ search_phrase='SSLCertificateFile'
 str_repl="    SSLCertificateFile $ssl_cert"
 
 # Changing sslhome
-httpd_change_config
+change_web_config
 
 # Defining search phrase
 search_phrase='SSLCertificateKeyFile'
@@ -80,7 +80,7 @@ search_phrase='SSLCertificateKeyFile'
 str_repl="    SSLCertificateKeyFile $ssl_key"
 
 # Changing sslhome
-httpd_change_config
+change_web_config
 
 # Adding certificate to user dir
 if [ ! -e "$ssl_cert" ]; then

+ 2 - 2
bin/v_change_web_domain_sslhome

@@ -71,7 +71,7 @@ esac
 str_repl="    DocumentRoot $docroot"
 
 # Changing sslhome
-httpd_change_config
+change_web_config
 
 # Get old sslhome value
 ssl_home=$(get_web_domain_value '$SSL_HOME')
@@ -90,7 +90,7 @@ search_phrase="<Directory $dirroot>"
 str_repl="    <Directory $docroot>"
 
 # Changing sslhome directory tag
-httpd_change_config
+change_web_config
 
 
 #----------------------------------------------------------#

+ 12 - 23
bin/v_del_web_domain_alias

@@ -58,45 +58,34 @@ fi
 
 # Defining new alias string
 new_alias=$(echo "$cur_alias" |\
-        sed -e "s/,/\n/g"|\
-        sed -e "s/^$dom_alias$//g"|\
-        sed -e "/^$/d"|\
-        sed -e ':a;N;$!ba;s/\n/,/g')
+    sed -e "s/,/\n/g"|\
+    sed -e "s/^$dom_alias$//g"|\
+    sed -e "/^$/d"|\
+    sed -e ':a;N;$!ba;s/\n/,/g')
 
 new_alias_idn=$(idn -t --quiet -a "$cur_alias" |\
-        sed -e "s/,/\n/g"|\
-        sed -e "s/^$dom_alias$//g"|\
-        sed -e "/^$/d"|\
-        sed -e ':a;N;$!ba;s/\n/,/g')
+    sed -e "s/,/\n/g"|\
+    sed -e "s/^$dom_alias$//g"|\
+    sed -e "/^$/d"|\
+    sed -e ':a;N;$!ba;s/\n/,/g')
 
-# Get template name
 tpl_name=$(get_web_domain_value '$TPL')
 tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
-
-# Defining config
 conf="$V_HOME/$user/conf/httpd.conf"
-
-# Defining search phrase
 search_phrase='ServerAlias'
-
-# Defining replace string
 str_repl="    ServerAlias ${new_alias_idn//,/ }"
 
 # Deleting alias
-httpd_change_config
+change_web_config
 
-# Checking ssl domain
+# Checking ssl
 cert=$(get_web_domain_value '$SSL_CERT')
 if [ ! -z "$cert" ]; then
 
-    # Defining ssl template
+    # Defining ssl options
     tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
-
-    # Defining ssl config
     conf="$V_HOME/$user/conf/shttpd.conf"
-
-    # Deleting ssl alias
-    httpd_change_config
+    change_web_config
 fi
 
 

+ 8 - 31
bin/v_del_web_domain_cgi

@@ -53,55 +53,32 @@ is_web_domain_value_exist '$CGI'
 tpl_name=$(get_web_domain_value '$TPL')
 tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
 
-# Defining config
+# Defining params for ScriptAlias
 conf="$V_HOME/$user/conf/httpd.conf"
-
-# Defining search phrase
 search_phrase='ScriptAlias '
-
-# Defining replace string
 str_repl="    #ScriptAlias /cgi-bin/ $V_HOME/$user/domains/$domain/cgi-bin"
+change_web_config
 
-# Deleting cgi-bin support
-httpd_change_config
-
-# Defining search phrase
+# Defining params for Options
 search_phrase='Options '
-
-# Defining replace string
 str_repl='        Options +Includes -Indexes -ExecCGI'
-
-# Deleting execscgi support
-httpd_change_config
+change_web_config
 
 # Checking ssl
 cert=$(get_web_domain_value '$SSL_CERT')
 if [ ! -z "$cert" ]; then
 
-    # Get ssl template name
+    # Defining params for ScriptAlias
     tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
-
-    # Defining ssl config
     conf="$V_HOME/$user/conf/shttpd.conf"
-
-    # Defining search phrase
     search_phrase='ScriptAlias '
-
-    # Defining replace string
     str_repl="    #ScriptAlias /cgi-bin/ $V_HOME/$user/domains/$domain/cgi-bin"
+    change_web_config
 
-    # Deleting cgi-bin support
-    httpd_change_config
-
-    # Defining search phrase
+    # Defining params for Options
     search_phrase='Options '
-
-    # Defining replace string
     str_repl='        Options +Includes -Indexes -ExecCGI'
-
-    # Deleting execscgi support
-    httpd_change_config
-
+    change_web_config
 fi
 
 

+ 2 - 2
bin/v_del_web_domain_elog

@@ -63,7 +63,7 @@ search_phrase='ErrorLog '
 str_repl="    #ErrorLog /var/log/httpd/domains/$domain.error.log"
 
 # Deleting errolog support
-httpd_change_config
+change_web_config
 
 # Checking ssl
 cert=$(get_web_domain_value '$SSL_CERT')
@@ -76,7 +76,7 @@ if [ ! -z "$cert" ]; then
     conf="$V_HOME/$user/conf/shttpd.conf"
 
     # Deleting errolog support
-    httpd_change_config
+    change_web_config
 
 fi
 

+ 2 - 2
bin/v_suspend_web_domain

@@ -60,7 +60,7 @@ search_phrase='DocumentRoot '
 str_repl="    Redirect / http://$url/"
 
 # Suspending vhost
-httpd_change_config
+change_web_config
 
 # Check ssl vhost
 cert=$(get_web_domain_value '$SSL_CERT')
@@ -75,7 +75,7 @@ if [ ! -z "$cert" ]; then
     str_repl="    Redirect / http://$url/"
 
     # Suspending vhost
-    httpd_change_config
+    change_web_config
 fi
 
 

+ 2 - 2
bin/v_suspend_web_domains

@@ -67,7 +67,7 @@ for domain in $domains; do
     str_repl="    Redirect / http://$url/"
 
     # Suspending vhost
-    httpd_change_config
+    change_web_config
 
     # Check ssl vhost
     cert=$(get_web_domain_value '$SSL_CERT')
@@ -82,7 +82,7 @@ for domain in $domains; do
         str_repl="    Redirect / http://$url/"
 
         # Suspending vhost
-        httpd_change_config
+        change_web_config
     fi
 
     # Adding suspend in config

+ 2 - 2
bin/v_unsuspend_web_domain

@@ -57,7 +57,7 @@ search_phrase='Redirect / '
 str_repl="    DocumentRoot $V_HOME/$user/domains/$domain/public_html"
 
 # Unsuspending vhost
-httpd_change_config
+change_web_config
 
 # Check ssl vhost
 cert=$(get_web_domain_value '$SSL_CERT')
@@ -79,7 +79,7 @@ if [ ! -z "$cert" ]; then
     str_repl="    DocumentRoot $docroot"
 
     # Unsuspending vhost
-    httpd_change_config
+    change_web_config
 fi
 
 

+ 2 - 2
bin/v_unsuspend_web_domains

@@ -64,7 +64,7 @@ for domain in $domains; do
     str_repl="    DocumentRoot $V_HOME/$user/domains/$domain/public_html"
 
     # Unsuspending vhost
-    httpd_change_config
+    change_web_config
 
     # Check ssl vhost
     cert=$(get_web_domain_value '$SSL_CERT')
@@ -86,7 +86,7 @@ for domain in $domains; do
         str_repl="    DocumentRoot $docroot"
 
         # Unsuspending vhost
-        httpd_change_config
+        change_web_config
     fi
 
     # Adding unsuspend in config

+ 6 - 14
func/domain_func.sh

@@ -243,28 +243,20 @@ add_web_config() {
     >> $conf
 }
 
-httpd_change_config() {
-    # Get ServerName line
-    serv_line=$(grep -n 'ServerName %domain_idn%' "$tpl_file" | cut -f 1 -d :)
-
-    # Get tpl_file last line
+change_web_config() {
+    # Defining template borders
+    serv_line=$(grep -ni 'Name %domain_idn%' "$tpl_file" |cut -f 1 -d :)
     last_line=$(wc -l $tpl_file | cut -f 1 -d ' ')
-
-    # Get before line
     bfr_line=$((serv_line - 1))
-
-    # Get after line
     aftr_line=$((last_line - serv_line - 1))
 
-    # Parsing httpd.conf
-    vhost=$(grep -A $aftr_line -B $bfr_line -n "ServerName $domain_idn" $conf)
-
-    # Searching prhase
+    # Parsing config
+    vhost=$(grep -A $aftr_line -B $bfr_line -ni "Name $domain_idn" $conf)
     str=$(echo "$vhost" | grep -F "$search_phrase" | head -n 1)
 
     # Checking parsing result
     if [ -z "$str" ] || [ -z "$serv_line" ] || [ -z "$aftr_line" ]; then
-        echo "Error: httpd parsing error"
+        echo "Error: config parsing error"
         log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
         exit $E_PARSE_ERROR
     fi