Skip to content

Commit e3513fb

Browse files
committed
Add v-change-sys-port and integrate it to install scripts.
1 parent 4cdf6d5 commit e3513fb

File tree

3 files changed

+109
-4
lines changed

3 files changed

+109
-4
lines changed

bin/v-change-sys-port

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
# info: change system backend port
3+
# options: PORT
4+
#
5+
# The function for changing the system backend port in NGINX configuration.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
PORT=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
# Define not usable ports
20+
BUSY_PORTS=('80' '443' '8080' '8443')
21+
22+
is_port_valid() {
23+
24+
# Check if PORT is numeric
25+
if [[ ! $PORT =~ ^[0-9]+$ ]]; then
26+
echo 'Port should contains a numeric value only!'
27+
log_event $E_NOTEXIST "$ARGUMENTS"
28+
exit $E_NOTEXIST
29+
fi
30+
31+
# Check if PORT is already used
32+
for BUSY_PORT in ${BUSY_PORTS[@]}; do
33+
if [ "$BUSY_PORT" = "$PORT" ]; then
34+
echo 'Port is already used by Hestia, please set anotherone!'
35+
log_event $E_NOTEXIST "$ARGUMENTS"
36+
exit $E_NOTEXIST
37+
fi
38+
done
39+
}
40+
41+
42+
#----------------------------------------------------------#
43+
# Verifications #
44+
#----------------------------------------------------------#
45+
46+
check_args '1' "$#" 'PORT'
47+
is_port_valid
48+
49+
50+
#----------------------------------------------------------#
51+
# Action #
52+
#----------------------------------------------------------#
53+
54+
# Get original port
55+
ORIGINAL_PORT=$(cat $HESTIA/nginx/conf/nginx.conf | grep "listen" | sed 's/[^0-9]*//g')
56+
57+
# Check if system variable is set
58+
if [ ! -n "$BACKEND_PORT" ]; then
59+
echo "BACKEND_PORT='$port'" >> $HESTIA/conf/hestia.conf
60+
source $HESTIA/conf/hestia.conf
61+
fi
62+
63+
# Check if port is different to hestia.conf
64+
if [ ! "$BACKEND_PORT" = "$PORT" ]; then
65+
sed -i s/BACKEND_PORT=\'$BACKEND_PORT\'/BACKEND_PORT=\'$PORT\'/g $HESTIA/conf/hestia.conf
66+
fi
67+
68+
# Check if port is different to nginx.conf
69+
if [ "$ORIGINAL_PORT" = "$PORT" ]; then
70+
echo "nothing to do"
71+
# Nothing to do, exit
72+
exit
73+
else
74+
# Replace port in config files.
75+
sed -i "/listen/c\ listen $PORT ssl;" $HESTIA/nginx/conf/nginx.conf
76+
sed -i "/password_hestia_port/c\$rcmail_config['password_hestia_port'] = '$PORT';" /etc/roundcube/plugins/password/config.inc.php
77+
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
78+
79+
# Restart services
80+
$HESTIA/bin/v-restart-service iptables
81+
82+
# Check if Hestia is running
83+
if [[ $(ps -eaf | grep -i hestia |sed '/^$/d' | wc -l) > 1 ]]; then
84+
$HESTIA/bin/v-restart-service hestia
85+
fi
86+
fi
87+
88+
#----------------------------------------------------------#
89+
# Hestia #
90+
#----------------------------------------------------------#
91+
92+
# Logging
93+
#log_event "$OK" "$ARGUMENTS"
94+
95+
exit

install/hst-install-debian.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ help() {
7878
-b, --fail2ban Install Fail2ban [yes|no] default: yes
7979
-q, --quota Filesystem Quota [yes|no] default: no
8080
-d, --api Activate API [yes|no] default: yes
81+
-r, --port Change Backend Port default: 8083
8182
-l, --lang Default language default: en
8283
-y, --interactive Interactive install [yes|no] default: yes
8384
-s, --hostname Set hostname
@@ -162,9 +163,9 @@ for arg; do
162163
--spamassassin) args="${args}-t " ;;
163164
--iptables) args="${args}-i " ;;
164165
--fail2ban) args="${args}-b " ;;
165-
--remi) args="${args}-r " ;;
166166
--multiphp) args="${args}-o " ;;
167167
--quota) args="${args}-q " ;;
168+
--port) args="${args}-r " ;;
168169
--lang) args="${args}-l " ;;
169170
--interactive) args="${args}-y " ;;
170171
--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
197198
t) spamd=$OPTARG ;; # SpamAssassin
198199
i) iptables=$OPTARG ;; # Iptables
199200
b) fail2ban=$OPTARG ;; # Fail2ban
200-
r) remi=$OPTARG ;; # Remi repo
201201
q) quota=$OPTARG ;; # FS Quota
202+
r) port=$OPTARG ;; # Backend Port
202203
l) lang=$OPTARG ;; # Language
203204
d) api=$OPTARG ;; # Activate API
204205
y) interactive=$OPTARG ;; # Interactive install
@@ -235,6 +236,7 @@ set_default_value 'fail2ban' 'yes'
235236
set_default_value 'quota' 'no'
236237
set_default_value 'api' 'yes'
237238
set_default_value 'interactive' 'yes'
239+
set_default_port '8083'
238240
set_default_lang 'en'
239241

240242
# Checking software conflicts
@@ -1424,6 +1426,9 @@ if [ "$quota" = 'yes' ]; then
14241426
$HESTIA/bin/v-add-sys-quota
14251427
fi
14261428

1429+
# Set backend port
1430+
$HESTIA/bin/v-change-sys-port $port
1431+
14271432
# Starting hestia service
14281433
update-rc.d hestia defaults
14291434
service hestia start

install/hst-install-ubuntu.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ help() {
5757
-b, --fail2ban Install Fail2ban [yes|no] default: yes
5858
-q, --quota Filesystem Quota [yes|no] default: no
5959
-d, --api Activate API [yes|no] default: yes
60+
-r, --port Change Backend Port default: 8083
6061
-l, --lang Default language default: en
6162
-y, --interactive Interactive install [yes|no] default: yes
6263
-s, --hostname Set hostname
@@ -141,9 +142,9 @@ for arg; do
141142
--spamassassin) args="${args}-t " ;;
142143
--iptables) args="${args}-i " ;;
143144
--fail2ban) args="${args}-b " ;;
144-
--remi) args="${args}-r " ;;
145145
--multiphp) args="${args}-o " ;;
146146
--quota) args="${args}-q " ;;
147+
--port) args="${args}-r " ;;
147148
--lang) args="${args}-l " ;;
148149
--interactive) args="${args}-y " ;;
149150
--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
176177
t) spamd=$OPTARG ;; # SpamAssassin
177178
i) iptables=$OPTARG ;; # Iptables
178179
b) fail2ban=$OPTARG ;; # Fail2ban
179-
r) remi=$OPTARG ;; # Remi repo
180180
q) quota=$OPTARG ;; # FS Quota
181+
r) port=$OPTARG ;; # Backend Port
181182
l) lang=$OPTARG ;; # Language
182183
d) api=$OPTARG ;; # Activate API
183184
y) interactive=$OPTARG ;; # Interactive install
@@ -214,6 +215,7 @@ set_default_value 'fail2ban' 'yes'
214215
set_default_value 'quota' 'no'
215216
set_default_value 'interactive' 'yes'
216217
set_default_value 'api' 'yes'
218+
set_default_port '8083'
217219
set_default_lang 'en'
218220

219221
# Checking software conflicts
@@ -1363,6 +1365,9 @@ if [ "$quota" = 'yes' ]; then
13631365
$HESTIA/bin/v-add-sys-quota
13641366
fi
13651367

1368+
# Set backend port
1369+
$HESTIA/bin/v-change-sys-port $port
1370+
13661371
# Starting Hestia service
13671372
update-rc.d hestia defaults
13681373
service hestia start

0 commit comments

Comments
 (0)