-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOPENSSH.sh
58 lines (46 loc) · 1.58 KB
/
OPENSSH.sh
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
#!/bin/bash
# Define colors for prompt
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to check if input is a digit
is_digit() {
if [[ $1 =~ ^[0-9]+$ ]]; then
return 0 # Input is a digit
else
return 1 # Input is not a digit
fi
}
# Prompt for a new port (loop until a digit is entered)
while true; do
echo -e "${BLUE}Enter the new SSH port:${NC} "
read -p "" new_port
if is_digit "$new_port"; then
break # Exit the loop when a digit is entered
else
echo -e "${RED}Invalid input. Please enter a numeric value.${NC}"
fi
done
# Construct the sed command to replace the DEFAULT_HOST port in wsproxy.py
sed_command_wsproxy="s/DEFAULT_HOST = \"127.0.0.1:[0-9]*\"/DEFAULT_HOST = \"127.0.0.1:$new_port\"/"
# Use sed to modify the wsproxy.py script
sudo sed -i "$sed_command_wsproxy" /etc/VPSManager/wsproxy.py
# Construct the sed command to replace the DEFAULT_HOST port in proxy.py
sed_command_proxy="s/DEFAULT_HOST = '0.0.0.0:[0-9]*'/DEFAULT_HOST = '0.0.0.0:$new_port'/"
# Use sed to modify the proxy.py script
sudo sed -i "$sed_command_proxy" /etc/VPSManager/proxy.py
# Display a colorful message
echo -e "${GREEN}OPENSSH PORT updated to: $new_port${NC}"
# Schedule a system reboot after a 10-second delay
countdown=10
echo -e "${BLUE}Rebooting the system in $countdown seconds...${NC}"
# Countdown loop
while [ $countdown -gt 0 ]; do
echo -e "${BLUE}Time remaining: $countdown seconds...${NC}"
sleep 1
countdown=$((countdown - 1))
done
# Reboot the system
echo -e "${GREEN}Rebooting the system now...${NC}"
sudo shutdown -r now