forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-change-sys-port
More file actions
executable file
·96 lines (74 loc) · 2.91 KB
/
v-change-sys-port
File metadata and controls
executable file
·96 lines (74 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/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
# Nothing to do, exit
exit
else
# Replace port in config files.
sed -i "/listen/c\ listen $PORT ssl;" $HESTIA/nginx/conf/nginx.conf
if [ -d /etc/roundcube/ ]; then
sed -i "/password_hestia_port/c\$rcmail_config['password_hestia_port'] = '$PORT';" /etc/roundcube/plugins/password/config.inc.php
fi
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