@@ -243,24 +243,33 @@ add_web_config() {
243243 >> $conf
244244}
245245
246- change_web_config () {
246+ get_web_config_brds () {
247247 # Defining template borders
248248 serv_line=$( grep -ni ' Name %domain_idn%' " $tpl_file " | cut -f 1 -d :)
249- last_line=$( wc -l $tpl_file | cut -f 1 -d ' ' )
249+ if [ -z " $serv_line " ]; then
250+ log_event ' debug' " $E_PARSE_ERROR $V_EVENT "
251+ return $E_PARSE_ERROR
252+ fi
253+
254+ # Template lines
255+ last_line=$( wc -l $tpl_file | cut -f 1 -d ' ' )
250256 bfr_line=$(( serv_line - 1 ))
251257 aftr_line=$(( last_line - serv_line - 1 ))
252258
259+ # Config lines
260+ str=$( grep -ni " Name $domain_idn " $conf | cut -f 1 -d :)
261+ top_line=$(( str - serv_line + 1 ))
262+ bottom_line=$(( top_line + last_line - 1 ))
263+ }
264+
265+ change_web_config () {
266+ # Get config borders
267+ get_web_config_brds || exit $?
268+
253269 # Parsing config
254270 vhost=$( grep -A $aftr_line -B $bfr_line -ni " Name $domain_idn " $conf )
255271 str=$( echo " $vhost " | grep -F " $search_phrase " | head -n 1)
256272
257- # Checking parsing result
258- if [ -z " $str " ] || [ -z " $serv_line " ] || [ -z " $aftr_line " ]; then
259- echo " Error: config parsing error"
260- log_event ' debug' " $E_PARSE_ERROR $V_EVENT "
261- exit $E_PARSE_ERROR
262- fi
263-
264273 # Parsing string position and content
265274 str_numb=$( echo " $str " | sed -e " s/-/=/" | cut -f 1 -d ' =' )
266275 str_cont=$( echo " $str " | sed -e " s/-/=/" | cut -f 2 -d ' =' )
@@ -452,25 +461,10 @@ is_dns_domain_value_exist() {
452461
453462
454463del_web_config () {
455- # Get servername line in template
456- serv_line=$( grep -ni ' Name %domain_idn%' " $tpl_file " | cut -f 1 -d :)
457-
458- # Get last template line
459- last_line=$( wc -l $tpl_file | cut -f 1 -d ' ' )
460-
461- # Parsing config
462- str=$( grep -ni " Name $domain_idn " $conf | cut -f 1 -d :)
463-
464- # Checking result
465- if [ -z " $str " ] || [ -z " $serv_line " ]; then
466- echo " Error: httpd parsing error"
467- log_event ' debug' " $E_PARSE_ERROR $V_EVENT "
468- exit $E_PARSE_ERROR
469- fi
464+ # Get config borders
465+ get_web_config_brds || exit $?
470466
471467 # Deleting lines from config
472- top_line=$(( str - serv_line + 1 ))
473- bottom_line=$(( top_line + last_line - 1 ))
474468 sed -i " $top_line ,$bottom_line d" $conf
475469}
476470
0 commit comments