Просмотр исходного кода

Add v-change-sys-port and integrate it to install scripts.

Raphael Schneeberger 7 лет назад
Родитель
Сommit
e3513fb909
3 измененных файлов с 109 добавлено и 4 удалено
  1. 95 0
      bin/v-change-sys-port
  2. 7 2
      install/hst-install-debian.sh
  3. 7 2
      install/hst-install-ubuntu.sh

+ 95 - 0
bin/v-change-sys-port

@@ -0,0 +1,95 @@
+#!/bin/bash
+# info: change system backend port
+# options: PORT
+#
+# The function for changing the system backend port in NGINX configuration.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+PORT=$1
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+# Define not usable ports
+BUSY_PORTS=('80' '443' '8080' '8443')
+
+is_port_valid() {
+
+    # Check if PORT is numeric
+    if [[ ! $PORT =~ ^[0-9]+$ ]]; then
+        echo 'Port should contains a numeric value only!'
+        log_event $E_NOTEXIST "$ARGUMENTS"
+        exit $E_NOTEXIST
+    fi
+
+    # Check if PORT is already used
+    for BUSY_PORT in ${BUSY_PORTS[@]}; do
+        if [ "$BUSY_PORT" = "$PORT" ]; then
+            echo 'Port is already used by Hestia, please set anotherone!'
+            log_event $E_NOTEXIST "$ARGUMENTS"
+            exit $E_NOTEXIST
+        fi
+    done
+}
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'PORT'
+is_port_valid
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Get original port
+ORIGINAL_PORT=$(cat $HESTIA/nginx/conf/nginx.conf | grep "listen" | sed 's/[^0-9]*//g')
+
+# Check if system variable is set
+if [ ! -n "$BACKEND_PORT" ]; then
+    echo "BACKEND_PORT='$port'" >> $HESTIA/conf/hestia.conf
+    source $HESTIA/conf/hestia.conf
+fi
+
+# Check if port is different to hestia.conf
+if [ ! "$BACKEND_PORT" = "$PORT" ]; then
+    sed -i s/BACKEND_PORT=\'$BACKEND_PORT\'/BACKEND_PORT=\'$PORT\'/g $HESTIA/conf/hestia.conf
+fi
+
+# Check if port is different to nginx.conf
+if [ "$ORIGINAL_PORT" = "$PORT" ]; then
+    echo "nothing to do"
+    # Nothing to do, exit
+    exit
+else
+    # Replace port in config files.
+    sed -i "/listen/c\        listen          $PORT ssl;" $HESTIA/nginx/conf/nginx.conf
+    sed -i "/password_hestia_port/c\$rcmail_config['password_hestia_port'] = '$PORT';" /etc/roundcube/plugins/password/config.inc.php
+    sed -i "/COMMENT='HESTIA'/c\RULE='2' ACTION='ACCEPT' PROTOCOL='TCP' PORT='$PORT' IP='0.0.0.0/0' COMMENT='HESTIA' SUSPENDED='no' TIME='07:40:16' DATE='2014-05-25'" $HESTIA/data/firewall/rules.conf
+    
+    # Restart services
+    $HESTIA/bin/v-restart-service iptables
+
+    # Check if Hestia is running
+    if [[ $(ps -eaf | grep -i hestia |sed '/^$/d' | wc -l) > 1 ]]; then
+        $HESTIA/bin/v-restart-service hestia
+    fi  
+fi
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+#log_event "$OK" "$ARGUMENTS"
+
+exit

+ 7 - 2
install/hst-install-debian.sh

@@ -78,6 +78,7 @@ help() {
   -b, --fail2ban          Install Fail2ban      [yes|no]  default: yes
   -q, --quota             Filesystem Quota      [yes|no]  default: no
   -d, --api               Activate API          [yes|no]  default: yes
+  -r, --port              Change Backend Port             default: 8083
   -l, --lang              Default language                default: en
   -y, --interactive       Interactive install   [yes|no]  default: yes
   -s, --hostname          Set hostname
@@ -162,9 +163,9 @@ for arg; do
         --spamassassin)         args="${args}-t " ;;
         --iptables)             args="${args}-i " ;;
         --fail2ban)             args="${args}-b " ;;
-        --remi)                 args="${args}-r " ;;
         --multiphp)             args="${args}-o " ;;
         --quota)                args="${args}-q " ;;
+        --port)                 args="${args}-r " ;;
         --lang)                 args="${args}-l " ;;
         --interactive)          args="${args}-y " ;;
         --api)                  args="${args}-d " ;;
@@ -197,8 +198,8 @@ while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:o:q:l:y:s:e:p:fh" Option; do
         t) spamd=$OPTARG ;;             # SpamAssassin
         i) iptables=$OPTARG ;;          # Iptables
         b) fail2ban=$OPTARG ;;          # Fail2ban
-        r) remi=$OPTARG ;;              # Remi repo
         q) quota=$OPTARG ;;             # FS Quota
+        r) port=$OPTARG ;;              # Backend Port
         l) lang=$OPTARG ;;              # Language
         d) api=$OPTARG ;;               # Activate API
         y) interactive=$OPTARG ;;       # Interactive install
@@ -235,6 +236,7 @@ set_default_value 'fail2ban' 'yes'
 set_default_value 'quota' 'no'
 set_default_value 'api' 'yes'
 set_default_value 'interactive' 'yes'
+set_default_port '8083'
 set_default_lang 'en'
 
 # Checking software conflicts
@@ -1424,6 +1426,9 @@ if [ "$quota" = 'yes' ]; then
     $HESTIA/bin/v-add-sys-quota
 fi
 
+# Set backend port
+$HESTIA/bin/v-change-sys-port $port
+
 # Starting hestia service
 update-rc.d hestia defaults
 service hestia start

+ 7 - 2
install/hst-install-ubuntu.sh

@@ -57,6 +57,7 @@ help() {
   -b, --fail2ban          Install Fail2ban      [yes|no]  default: yes
   -q, --quota             Filesystem Quota      [yes|no]  default: no
   -d, --api               Activate API          [yes|no]  default: yes
+  -r, --port              Change Backend Port             default: 8083
   -l, --lang              Default language                default: en
   -y, --interactive       Interactive install   [yes|no]  default: yes
   -s, --hostname          Set hostname
@@ -141,9 +142,9 @@ for arg; do
         --spamassassin)         args="${args}-t " ;;
         --iptables)             args="${args}-i " ;;
         --fail2ban)             args="${args}-b " ;;
-        --remi)                 args="${args}-r " ;;
         --multiphp)             args="${args}-o " ;;
         --quota)                args="${args}-q " ;;
+        --port)                 args="${args}-r " ;;
         --lang)                 args="${args}-l " ;;
         --interactive)          args="${args}-y " ;;
         --api)                  args="${args}-d " ;;
@@ -176,8 +177,8 @@ while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:o:q:l:y:s:e:p:fh" Option; do
         t) spamd=$OPTARG ;;             # SpamAssassin
         i) iptables=$OPTARG ;;          # Iptables
         b) fail2ban=$OPTARG ;;          # Fail2ban
-        r) remi=$OPTARG ;;              # Remi repo
         q) quota=$OPTARG ;;             # FS Quota
+        r) port=$OPTARG ;;              # Backend Port
         l) lang=$OPTARG ;;              # Language
         d) api=$OPTARG ;;               # Activate API
         y) interactive=$OPTARG ;;       # Interactive install
@@ -214,6 +215,7 @@ set_default_value 'fail2ban' 'yes'
 set_default_value 'quota' 'no'
 set_default_value 'interactive' 'yes'
 set_default_value 'api' 'yes'
+set_default_port '8083'
 set_default_lang 'en'
 
 # Checking software conflicts
@@ -1363,6 +1365,9 @@ if [ "$quota" = 'yes' ]; then
     $HESTIA/bin/v-add-sys-quota
 fi
 
+# Set backend port
+$HESTIA/bin/v-change-sys-port $port
+
 # Starting Hestia service
 update-rc.d hestia defaults
 service hestia start