@@ -104,9 +104,9 @@ regex[url]="^(http|https)://([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}|[0-9]{1,3}(\.[0-9]{1,3
104
104
function show_help {
105
105
echo " "
106
106
echo " Usage: reality-ezpz.sh [-t|--transport=tcp|http|grpc|ws|tuic|hysteria2] [-d|--domain=<domain>] [--server=<server>] [--regenerate] [--default]
107
- [-r|--restart] [--enable-safenet=true|false] [--port=<port>] [-c|--core=xray|sing-box]
108
- [--enable- warp=true|false] [--warp- license=<license>] [--security=reality|letsencrypt|selfsigned] [-m|--menu] [--show-server-config]
109
- [--add-user=<username>] [--lists-users] [-- show-user=<username>] [--delete-user=<username>] [--backup] [--restore=<url|file>] [-u|--uninstall]"
107
+ [-r|--restart] [--enable-safenet=true|false] [--port=<port>] [-c|--core=xray|sing-box] [--enable-warp=true|false]
108
+ [--warp- license=<license>] [--security=reality|letsencrypt|selfsigned] [-m|--menu] [--show-server-config] [--add-user=<username>] [--lists-users]
109
+ [--show-user=<username>] [--delete-user=<username>] [--backup] [--restore=<url|file>] [--backup-password=<password >] [-u|--uninstall]"
110
110
echo " "
111
111
echo " -t, --transport <tcp|http|grpc|ws|tuic|hysteria2> Transport protocol (tcp, http, grpc, ws, tuic, hysteria2, default: ${defaults[transport]} )"
112
112
echo " -d, --domain <domain> Domain to use as SNI (default: ${defaults[domain]} )"
@@ -130,15 +130,16 @@ function show_help {
130
130
echo " --list-users List all users"
131
131
echo " --show-user <username> Shows the config and QR code of the user"
132
132
echo " --delete-user <username> Delete the user"
133
- echo " --backup Backup users and configuration and upload it to keep .sh"
133
+ echo " --backup Backup users and configuration and upload it to temp .sh"
134
134
echo " --restore <url|file> Restore backup from URL or file"
135
+ echo " --backup-password <password> Create/Restore password protected backup file"
135
136
echo " -h, --help Display this help message"
136
137
return 1
137
138
}
138
139
139
140
function parse_args {
140
141
local opts
141
- opts=$( getopt -o t:d:ruc:mh --long transport:,domain:,server:,regenerate,default,restart,uninstall,enable-safenet:,port:,warp-license:,enable-warp:,core:,security:,menu,show-server-config,add-user:,list-users,show-user:,delete-user:,backup,restore:,enable-tgbot:,tgbot-token:,tgbot-admins:,help -- " $@ " )
142
+ opts=$( getopt -o t:d:ruc:mh --long transport:,domain:,server:,regenerate,default,restart,uninstall,enable-safenet:,port:,warp-license:,enable-warp:,core:,security:,menu,show-server-config,add-user:,list-users,show-user:,delete-user:,backup,restore:,backup-password:, enable-tgbot:,tgbot-token:,tgbot-admins:,help -- " $@ " )
142
143
if [[ $? -ne 0 ]]; then
143
144
return 1
144
145
fi
@@ -328,6 +329,10 @@ function parse_args {
328
329
fi
329
330
shift 2
330
331
;;
332
+ --backup-password)
333
+ args[backup_password]=" $2 "
334
+ shift 2
335
+ ;;
331
336
-h|--help)
332
337
return 1
333
338
;;
@@ -353,40 +358,83 @@ function parse_args {
353
358
354
359
function backup {
355
360
local backup_name
361
+ local backup_password=" $1 "
356
362
local backup_file_url
357
363
local exit_code
358
- backup_name=reality-ezpz-backup-$( date +%Y-%m-%d_%H-%M-%S) .tar.gz
359
- tar -czf " /tmp/${backup_name} " -C " ${config_path} " ./
360
- if ! backup_file_url=$( curl -fsS -m 30 --upload-file " /tmp/${backup_name} " https://free.keep.sh) ; then
364
+ backup_name=" reality-ezpz-backup-$( date +%Y-%m-%d_%H-%M-%S) .zip"
365
+ cd " ${config_path} "
366
+ if [ -z " ${backup_password} " ]; then
367
+ zip -r " /tmp/${backup_name} " . > /dev/null
368
+ else
369
+ zip -P " ${backup_password} " -r " /tmp/${backup_name} " . > /dev/null
370
+ fi
371
+ if ! backup_file_url=$( curl -fsS -m 30 -F " file=@/tmp/${backup_name} " " https://temp.sh/upload" ) ; then
361
372
rm -f " /tmp/${backup_name} "
362
373
echo " Error in uploading backup file" >&2
363
374
return 1
364
375
fi
365
376
rm -f " /tmp/${backup_name} "
366
377
echo " ${backup_file_url} "
367
- return
368
378
}
369
379
370
380
function restore {
371
- local backup_file=$1
381
+ local backup_file=" $1 "
382
+ local backup_password=" $2 "
372
383
local temp_file
384
+ local unzip_output
385
+ local unzip_exit_code
386
+ local current_state
373
387
if [[ ! -r ${backup_file} ]]; then
374
388
temp_file=$( mktemp -u)
375
- if ! curl -fSsL -m 30 " ${backup_file} " -o " ${temp_file} " ; then
376
- echo " Cannot download or find backup file" >&2
377
- return 1
389
+ if [[ " ${backup_file} " =~ ^https? ://temp\. sh/ ]]; then
390
+ if ! curl -fSsL -m 30 -X POST " ${backup_file} " -o " ${temp_file} " ; then
391
+ echo " Cannot download or find backup file" >&2
392
+ return 1
393
+ fi
394
+ else
395
+ if ! curl -fSsL -m 30 " ${backup_file} " -o " ${temp_file} " ; then
396
+ echo " Cannot download or find backup file" >&2
397
+ return 1
398
+ fi
378
399
fi
379
400
backup_file=" ${temp_file} "
380
401
fi
381
- if ! tar -tzf " ${backup_file} " | grep -q config; then
382
- echo " The provided file is not a reality-ezpz backup file." >&2
402
+ current_state=$( set +o)
403
+ set +e
404
+ if [[ -z " ${backup_password} " ]]; then
405
+ unzip_output=$( unzip -P " " -t " ${backup_file} " 2>&1 )
406
+ else
407
+ unzip_output=$( unzip -P " ${backup_password} " -t " ${backup_file} " 2>&1 )
408
+ fi
409
+ unzip_exit_code=$?
410
+ eval " $current_state "
411
+ if [[ ${unzip_exit_code} -eq 0 ]]; then
412
+ if ! echo " ${unzip_output} " | grep -q ' config' ; then
413
+ echo " The provided file is not a reality-ezpz backup file." >&2
414
+ rm -f " ${temp_file} "
415
+ return 1
416
+ fi
417
+ else
418
+ if echo " ${unzip_output} " | grep -q ' incorrect password' ; then
419
+ echo " The provided password for backup file is incorrect." >&2
420
+ else
421
+ echo " An error occurred during zip file verification: ${unzip_output} " >&2
422
+ fi
383
423
rm -f " ${temp_file} "
384
424
return 1
385
425
fi
386
426
rm -rf " ${config_path} "
387
427
mkdir -p " ${config_path} "
388
- if ! tar -xzf " ${backup_file} " -C " ${config_path} " ; then
389
- echo " Error in backup restore." >&2
428
+ set +e
429
+ if [[ -z " ${backup_password} " ]]; then
430
+ unzip_output=$( unzip -d " ${config_path} " " ${backup_file} " 2>&1 )
431
+ else
432
+ unzip_output=$( unzip -P " ${backup_password} " -d " ${config_path} " " ${backup_file} " 2>&1 )
433
+ fi
434
+ unzip_exit_code=$?
435
+ eval " $current_state "
436
+ if [[ ${unzip_exit_code} -ne 0 ]]; then
437
+ echo " Error in backup restore: ${unzip_output} " >&2
390
438
rm -f " ${temp_file} "
391
439
return 1
392
440
fi
@@ -636,16 +684,16 @@ function uninstall {
636
684
}
637
685
638
686
function install_packages {
639
- if ! which qrencode whiptail jq xxd > /dev/null 2>&1 ; then
687
+ if ! which qrencode whiptail jq xxd zip unzip > /dev/null 2>&1 ; then
640
688
if which apt > /dev/null 2>&1 ; then
641
689
apt update
642
- apt install qrencode whiptail jq xxd -y
690
+ DEBIAN_FRONTEND=noninteractive apt install qrencode whiptail jq xxd zip unzip -y
643
691
return 0
644
692
fi
645
693
if which yum > /dev/null 2>&1 ; then
646
694
yum makecache
647
695
yum install epel-release -y || true
648
- yum install qrencode newt jq vim-common -y
696
+ yum install qrencode newt jq vim-common zip unzip -y
649
697
return 0
650
698
fi
651
699
echo " OS is not supported!"
@@ -909,7 +957,7 @@ function generate_tgbot_dockerfile {
909
957
cat > " ${path[tgbot_dockerfile]} " << EOF
910
958
FROM ${image[python]}
911
959
WORKDIR ${config_path} /tgbot
912
- RUN apk add --no-cache docker-cli-compose curl bash newt libqrencode-tools sudo openssl jq
960
+ RUN apk add --no-cache docker-cli-compose curl bash newt libqrencode-tools sudo openssl jq zip unzip
913
961
RUN pip install --no-cache-dir python-telegram-bot==13.5
914
962
CMD [ "python", "./tgbot.py" ]
915
963
EOF
@@ -1609,6 +1657,7 @@ $([[ ${config[security]} == 'reality' ]] && echo "ShortId: ${config[short_id]}"
1609
1657
echo
1610
1658
echo " Press Enter to return ..."
1611
1659
read
1660
+ clear
1612
1661
fi
1613
1662
if [[ $# -gt 0 ]]; then
1614
1663
return 0
@@ -2107,33 +2156,38 @@ function config_tgbot_menu {
2107
2156
}
2108
2157
2109
2158
function backup_menu {
2159
+ local backup_password
2110
2160
local result
2111
- whiptail \
2161
+ backup_password= $( whiptail \
2112
2162
--clear \
2113
2163
--backtitle " $BACKTITLE " \
2114
2164
--title " Backup" \
2115
- --yesno " Do you want to create a backup from users and configuration? " \
2165
+ --inputbox " Choose a password for the backup file.\nLeave blank if you do not wish to set a password for the backup file. " \
2116
2166
$HEIGHT $WIDTH \
2117
- 3>&1 1>&2 2>&3
2167
+ 3>&1 1>&2 2>&3 )
2118
2168
if [[ $? -ne 0 ]]; then
2119
2169
return
2120
2170
fi
2121
- if result=$( backup 2>&1 ) ; then
2171
+ if result=$( backup " ${backup_password} " 2>&1 ) ; then
2172
+ clear
2122
2173
echo " Backup has been create and uploaded successfully."
2123
2174
echo " You can download the backup file from here:"
2175
+ echo " "
2124
2176
echo " ${result} "
2125
2177
echo " "
2126
- echo " The URL is valid for 24h ."
2178
+ echo " The URL is valid for 3 days ."
2127
2179
echo
2128
2180
echo " Press Enter to return ..."
2129
2181
read
2182
+ clear
2130
2183
else
2131
2184
message_box " Backup Failed" " ${result} "
2132
2185
fi
2133
2186
}
2134
2187
2135
2188
function restore_backup_menu {
2136
2189
local backup_file
2190
+ local backup_password
2137
2191
local result
2138
2192
while true ; do
2139
2193
backup_file=$( whiptail \
@@ -2150,13 +2204,24 @@ function restore_backup_menu {
2150
2204
message_box " Invalid Backup path of URL" " Backup file path or URL is not valid."
2151
2205
continue
2152
2206
fi
2153
- if result=$( restore ${backup_file} 2>&1 ) ; then
2207
+ backup_password=$( whiptail \
2208
+ --clear \
2209
+ --backtitle " $BACKTITLE " \
2210
+ --title " Restore Backup" \
2211
+ --inputbox " Enter backup file password.\nLeave blank if there is no password." \
2212
+ $HEIGHT $WIDTH \
2213
+ 3>&1 1>&2 2>&3 )
2214
+ if [[ $? -ne 0 ]]; then
2215
+ continue
2216
+ fi
2217
+ if result=$( restore " ${backup_file} " " ${backup_password} " 2>&1 ) ; then
2154
2218
parse_config_file
2155
2219
parse_users_file
2156
2220
build_config
2157
2221
update_config_file
2158
2222
update_users_file
2159
2223
message_box " Backup Restore Successful" " Backup has been restored successfully."
2224
+ args[restart]=true
2160
2225
break
2161
2226
else
2162
2227
message_box " Backup Restore Failed" " ${result} "
@@ -2429,17 +2494,31 @@ if [[ $EUID -ne 0 ]]; then
2429
2494
exit 1
2430
2495
fi
2431
2496
if [[ ${args[backup]} == true ]]; then
2432
- if backup_url=$( backup) ; then
2497
+ if [[ -n ${args[backup_password]} ]]; then
2498
+ backup_url=$( backup " ${args[backup_password]} " )
2499
+ else
2500
+ backup_url=$( backup)
2501
+ fi
2502
+ if [[ $? -eq 0 ]]; then
2433
2503
echo " Backup created successfully. You can download the backup file from this address:"
2434
2504
echo " ${backup_url} "
2435
- echo " The URL is valid for 24h."
2505
+ echo " The URL is valid for 3 days."
2506
+ exit 0
2436
2507
fi
2437
2508
fi
2438
2509
if [[ -n ${args[restore]} ]]; then
2439
- if restore ${args[restore]} ; then
2510
+ if [[ -n ${args[backup_password]} ]]; then
2511
+ restore " ${args[restore]} " " ${args[backup_password]} "
2512
+ else
2513
+ restore " ${args[restore]} "
2514
+ fi
2515
+ if [[ $? -eq 0 ]]; then
2440
2516
args[restart]=true
2441
2517
echo " Backup has been restored successfully."
2442
2518
fi
2519
+ echo " Press Enter to continue ..."
2520
+ read
2521
+ clear
2443
2522
fi
2444
2523
generate_file_list
2445
2524
install_packages
0 commit comments