3
3
# Configuration file path
4
4
CONFIG_FILE=" /pg/config/cf_tunnel.cfg"
5
5
6
- # ANSI color codes for green, red, and blue
7
- GREEN=" \033[0;32m"
6
+ # ANSI color codes for green, hot pink, and others
7
+ GREEN=" \033[1;32m" # Bold Green
8
+ HOT_PINK=" \033[1;35m" # Bold Hot Pink
8
9
RED=" \033[0;31m"
9
10
BLUE=" \033[0;34m"
10
11
NC=" \033[0m" # No color
12
+ CYAN=" \033[0;36m"
13
+ BOLD=" \033[1m"
11
14
12
15
# Clear the screen when the script starts
13
16
clear
@@ -39,14 +42,11 @@ container_exists() {
39
42
# Function to display the main menu
40
43
show_menu () {
41
44
clear
42
- echo " PG: CloudFlare Tunnel"
43
-
44
- # Display container deployment status
45
- echo -n " Container Deployed: "
45
+ echo -n -e " ${CYAN}${BOLD} PG: CloudFlare Tunnel${NC} "
46
46
if container_running; then
47
- echo -e " ${GREEN} Yes ${NC} "
47
+ echo -e " ${GREEN}${BOLD} [Deployed] ${NC} "
48
48
else
49
- echo -e " ${RED} No ${NC} "
49
+ echo -e " ${RED}${BOLD} [Not Deployed] ${NC} "
50
50
fi
51
51
52
52
echo
@@ -64,43 +64,19 @@ show_menu() {
64
64
65
65
# Function to prompt the user with a choice
66
66
prompt_choice () {
67
- read -p " Select an option: " choice
67
+ read -p " Select an Option > " choice
68
68
case ${choice,,} in # Convert input to lowercase for v/V, c/C, d/D, s/S, z/Z handling
69
69
v)
70
70
clear
71
71
view_token
72
72
;;
73
73
c)
74
74
clear
75
- local change_code=$( printf " %04d" $(( RANDOM % 10000 )) ) # Generate a 4-digit code
76
- while true ; do
77
- read -p " $( echo -e " To change the Cloudflare token, type [${RED}${change_code}${NC} ] to proceed or [${GREEN} no${NC} ] to cancel: " ) " input_code
78
- if [[ " $input_code " == " $change_code " ]]; then
79
- change_token
80
- break
81
- elif [[ " ${input_code,,} " == " no" ]]; then
82
- echo " Operation cancelled."
83
- break
84
- else
85
- echo -e " ${RED} Invalid response.${NC} Please type [${RED}${change_code}${NC} ] or [${GREEN} no${NC} ]."
86
- fi
87
- done
75
+ change_token
88
76
;;
89
77
d)
90
78
clear
91
- local deploy_code=$( printf " %04d" $(( RANDOM % 10000 )) ) # Generate a 4-digit code
92
- while true ; do
93
- read -p " $( echo -e " Deploy CF Tunnel? Type [${RED}${deploy_code}${NC} ] to proceed or [${GREEN} no${NC} ] to cancel: " ) " input_code
94
- if [[ " $input_code " == " $deploy_code " ]]; then
95
- deploy_container
96
- break
97
- elif [[ " ${input_code,,} " == " no" ]]; then
98
- echo " Operation cancelled."
99
- break
100
- else
101
- echo -e " ${RED} Invalid response.${NC} Please type [${RED}${deploy_code}${NC} ] or [${GREEN} no${NC} ]."
102
- fi
103
- done
79
+ deploy_container
104
80
;;
105
81
s)
106
82
clear
@@ -139,13 +115,52 @@ view_token() {
139
115
140
116
# Function to change the Cloudflare token
141
117
change_token () {
142
- clear
143
- read -p " Enter new Cloudflare token: " CLOUDFLARE_TOKEN
144
- save_token_to_config
145
- echo " Cloudflare token has been updated and saved to $CONFIG_FILE ."
146
- sleep 2
147
- show_menu
148
- prompt_choice
118
+ local proceed_pin cancel_pin
119
+ proceed_pin=$( printf " %04d" $(( RANDOM % 10000 )) ) # Generate a 4-digit proceed pin
120
+ cancel_pin=$( printf " %04d" $(( RANDOM % 10000 )) ) # Generate a 4-digit cancel pin
121
+
122
+ # Ask the user for the new token
123
+ echo -e " Enter new Cloudflare token:"
124
+ read -p " > " new_token # Get the new token from the user
125
+ echo # Echo a blank line for spacing
126
+
127
+ # Confirmation prompt with hot pink pin for proceed and green for cancel
128
+ while true ; do
129
+ echo -e " To proceed, enter this PIN [${HOT_PINK}${proceed_pin}${NC} ]"
130
+ echo -e " To cancel, enter this PIN [${GREEN}${cancel_pin}${NC} ]"
131
+ read -p " Enter PIN > " input_code
132
+
133
+ if [[ " $input_code " == " $proceed_pin " ]]; then
134
+ # Save the token and confirm
135
+ CLOUDFLARE_TOKEN=" $new_token "
136
+ save_token_to_config
137
+ echo -e " ${GREEN} Cloudflare token has been updated and saved to $CONFIG_FILE .${NC} "
138
+
139
+ # Check if the container is running, notify the user and stop/remove it
140
+ if container_running; then
141
+ echo -e " ${RED} Note:${NC} The CloudFlare Tunnel container is currently running."
142
+ echo " You must redeploy the container for the changes to take effect."
143
+
144
+ echo " Stopping and removing the running container..."
145
+ docker stop cf_tunnel
146
+ docker rm cf_tunnel
147
+ echo " Container stopped and removed."
148
+ fi
149
+
150
+ sleep 2
151
+ show_menu
152
+ prompt_choice
153
+ break
154
+ elif [[ " $input_code " == " $cancel_pin " ]]; then
155
+ echo -e " ${GREEN} Operation cancelled.${NC} "
156
+ sleep 2
157
+ show_menu
158
+ prompt_choice
159
+ break
160
+ else
161
+ echo -e " ${RED} Invalid response.${NC} Please enter [${HOT_PINK}${proceed_pin}${NC} ] to proceed or [${GREEN}${cancel_pin}${NC} ] to cancel."
162
+ fi
163
+ done
149
164
}
150
165
151
166
# Function to deploy or redeploy the container
0 commit comments