Skip to content

Commit 69b9a65

Browse files
authored
Merge pull request aleskxyz#160 from aleskxyz/remove-keep-sh
Use temp.sh for backup storage
2 parents 07c6c82 + 0c1b218 commit 69b9a65

File tree

2 files changed

+128
-42
lines changed

2 files changed

+128
-42
lines changed

README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ You can also enable Telegram bot with `--enable-tgbot` option and manage users f
7575

7676
Help message of the script:
7777
```
78-
Usage: reality-ezpz.sh [-t|--transport=tcp|http|grpc|ws|tuic|hysteria2] [-d|--domain=<domain>] [--server=<server>] [--regenerate] [--default]
79-
[-r|--restart] [--enable-safenet=true|false] [--port=<port>] [-c|--core=xray|sing-box]
80-
[--enable-warp=true|false] [--warp-license=<license>] [--security=reality|letsencrypt|selfsigned] [-m|--menu] [--show-server-config]
81-
[--add-user=<username>] [--lists-users] [--show-user=<username>] [--delete-user=<username>] [--backup] [--restore=<url|file>] [-u|--uninstall]
78+
79+
Usage: reality-ezpz.sh [-t|--transport=tcp|http|grpc|ws|tuic|hysteria2] [-d|--domain=<domain>] [--server=<server>]
80+
[--regenerate] [--default] [-r|--restart] [--enable-safenet=true|false] [--port=<port>] [-c|--core=xray|sing-box]
81+
[--enable-warp=true|false] [--warp-license=<license>] [--security=reality|letsencrypt|selfsigned] [-m|--menu]
82+
[--show-server-config] [--add-user=<username>] [--lists-users] [--show-user=<username>] [--delete-user=<username>]
83+
[--backup] [--restore=<url|file>] [--backup-password=<password>] [-u|--uninstall]
8284
8385
-t, --transport <tcp|http|grpc|ws|tuic|hysteria2> Transport protocol (tcp, http, grpc, ws, tuic, hysteria2, default: tcp)
8486
-d, --domain <domain> Domain to use as SNI (default: www.google.com)
85-
--server <server> IP address or domain name of server (Must be a valid domain if using ws)
87+
--server <server> IP address or domain name of server (Must be a valid domain if using letsencrypt security)
8688
--regenerate Regenerate public and private keys
8789
--default Restore default configuration
8890
-r --restart Restart services
@@ -102,8 +104,9 @@ Usage: reality-ezpz.sh [-t|--transport=tcp|http|grpc|ws|tuic|hysteria2] [-d|--do
102104
--list-users List all users
103105
--show-user <username> Shows the config and QR code of the user
104106
--delete-user <username> Delete the user
105-
--backup Backup users and configuration and upload it to keep.sh
107+
--backup Backup users and configuration and upload it to temp.sh
106108
--restore <url|file> Restore backup from URL or file
109+
--backup-password <password> Create/Restore password protected backup file
107110
-h, --help Display this help message
108111
```
109112

@@ -285,22 +288,26 @@ bash <(curl -sL https://bit.ly/realityez) -c xray
285288
Valid options are `xray` and `sing-box`.
286289

287290
### Create backup
288-
You can create a backup from users and configuration and upload it to free.keep.sh by using `--backup` option:
291+
You can create a backup from users and configuration and upload it to https://temp.sh/ by using `--backup` option.
292+
293+
The `--backup-password` option allows you to protect the backup zip file with the specified password. (Optional)
289294
```
290-
bash <(curl -sL https://bit.ly/realityez) --backup
295+
bash <(curl -sL https://bit.ly/realityez) --backup --backup-password "P@ssw0rd"
291296
```
292-
This command will give you a URL to download you backup file. The URL is only valid for 24h.
297+
This command will give you a URL to download you backup file. The URL is only valid for 3 days.
293298

294299
### Restore backup
295300
You can restore a previously created backup file with `--restore` option.
296301

297-
You need to give the path or URL of the backup file to restore:
302+
You need to give the path or URL of the backup file to restore.
303+
304+
The `--backup-password` option allows you to restore the password protected backup zip file.
298305
```
299-
bash <(curl -sL https://bit.ly/realityez) --restore /path/to/backup.tar.gz
306+
bash <(curl -sL https://bit.ly/realityez) --restore /path/to/backup.zip --backup-password "P@ssw0rd"
300307
```
301308
or
302309
```
303-
bash <(curl -sL https://bit.ly/realityez) --restore "https://www.example.com/backup.tar.gz"
310+
bash <(curl -sL https://bit.ly/realityez) --restore "https://www.example.com/backup.zip" --backup-password "P@ssw0rd"
304311
```
305312

306313
You can migrate users and configuration from one server to another by:

reality-ezpz.sh

+109-30
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ regex[url]="^(http|https)://([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}|[0-9]{1,3}(\.[0-9]{1,3
104104
function show_help {
105105
echo ""
106106
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]"
110110
echo ""
111111
echo " -t, --transport <tcp|http|grpc|ws|tuic|hysteria2> Transport protocol (tcp, http, grpc, ws, tuic, hysteria2, default: ${defaults[transport]})"
112112
echo " -d, --domain <domain> Domain to use as SNI (default: ${defaults[domain]})"
@@ -130,15 +130,16 @@ function show_help {
130130
echo " --list-users List all users"
131131
echo " --show-user <username> Shows the config and QR code of the user"
132132
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"
134134
echo " --restore <url|file> Restore backup from URL or file"
135+
echo " --backup-password <password> Create/Restore password protected backup file"
135136
echo " -h, --help Display this help message"
136137
return 1
137138
}
138139

139140
function parse_args {
140141
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 -- "$@")
142143
if [[ $? -ne 0 ]]; then
143144
return 1
144145
fi
@@ -328,6 +329,10 @@ function parse_args {
328329
fi
329330
shift 2
330331
;;
332+
--backup-password)
333+
args[backup_password]="$2"
334+
shift 2
335+
;;
331336
-h|--help)
332337
return 1
333338
;;
@@ -353,40 +358,83 @@ function parse_args {
353358

354359
function backup {
355360
local backup_name
361+
local backup_password="$1"
356362
local backup_file_url
357363
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
361372
rm -f "/tmp/${backup_name}"
362373
echo "Error in uploading backup file" >&2
363374
return 1
364375
fi
365376
rm -f "/tmp/${backup_name}"
366377
echo "${backup_file_url}"
367-
return
368378
}
369379

370380
function restore {
371-
local backup_file=$1
381+
local backup_file="$1"
382+
local backup_password="$2"
372383
local temp_file
384+
local unzip_output
385+
local unzip_exit_code
386+
local current_state
373387
if [[ ! -r ${backup_file} ]]; then
374388
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
378399
fi
379400
backup_file="${temp_file}"
380401
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
383423
rm -f "${temp_file}"
384424
return 1
385425
fi
386426
rm -rf "${config_path}"
387427
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
390438
rm -f "${temp_file}"
391439
return 1
392440
fi
@@ -636,16 +684,16 @@ function uninstall {
636684
}
637685

638686
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
640688
if which apt >/dev/null 2>&1; then
641689
apt update
642-
apt install qrencode whiptail jq xxd -y
690+
DEBIAN_FRONTEND=noninteractive apt install qrencode whiptail jq xxd zip unzip -y
643691
return 0
644692
fi
645693
if which yum >/dev/null 2>&1; then
646694
yum makecache
647695
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
649697
return 0
650698
fi
651699
echo "OS is not supported!"
@@ -909,7 +957,7 @@ function generate_tgbot_dockerfile {
909957
cat >"${path[tgbot_dockerfile]}" << EOF
910958
FROM ${image[python]}
911959
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
913961
RUN pip install --no-cache-dir python-telegram-bot==13.5
914962
CMD [ "python", "./tgbot.py" ]
915963
EOF
@@ -1609,6 +1657,7 @@ $([[ ${config[security]} == 'reality' ]] && echo "ShortId: ${config[short_id]}"
16091657
echo
16101658
echo "Press Enter to return ..."
16111659
read
1660+
clear
16121661
fi
16131662
if [[ $# -gt 0 ]]; then
16141663
return 0
@@ -2107,33 +2156,38 @@ function config_tgbot_menu {
21072156
}
21082157

21092158
function backup_menu {
2159+
local backup_password
21102160
local result
2111-
whiptail \
2161+
backup_password=$(whiptail \
21122162
--clear \
21132163
--backtitle "$BACKTITLE" \
21142164
--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." \
21162166
$HEIGHT $WIDTH \
2117-
3>&1 1>&2 2>&3
2167+
3>&1 1>&2 2>&3)
21182168
if [[ $? -ne 0 ]]; then
21192169
return
21202170
fi
2121-
if result=$(backup 2>&1); then
2171+
if result=$(backup "${backup_password}" 2>&1); then
2172+
clear
21222173
echo "Backup has been create and uploaded successfully."
21232174
echo "You can download the backup file from here:"
2175+
echo ""
21242176
echo "${result}"
21252177
echo ""
2126-
echo "The URL is valid for 24h."
2178+
echo "The URL is valid for 3 days."
21272179
echo
21282180
echo "Press Enter to return ..."
21292181
read
2182+
clear
21302183
else
21312184
message_box "Backup Failed" "${result}"
21322185
fi
21332186
}
21342187

21352188
function restore_backup_menu {
21362189
local backup_file
2190+
local backup_password
21372191
local result
21382192
while true; do
21392193
backup_file=$(whiptail \
@@ -2150,13 +2204,24 @@ function restore_backup_menu {
21502204
message_box "Invalid Backup path of URL" "Backup file path or URL is not valid."
21512205
continue
21522206
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
21542218
parse_config_file
21552219
parse_users_file
21562220
build_config
21572221
update_config_file
21582222
update_users_file
21592223
message_box "Backup Restore Successful" "Backup has been restored successfully."
2224+
args[restart]=true
21602225
break
21612226
else
21622227
message_box "Backup Restore Failed" "${result}"
@@ -2429,17 +2494,31 @@ if [[ $EUID -ne 0 ]]; then
24292494
exit 1
24302495
fi
24312496
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
24332503
echo "Backup created successfully. You can download the backup file from this address:"
24342504
echo "${backup_url}"
2435-
echo "The URL is valid for 24h."
2505+
echo "The URL is valid for 3 days."
2506+
exit 0
24362507
fi
24372508
fi
24382509
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
24402516
args[restart]=true
24412517
echo "Backup has been restored successfully."
24422518
fi
2519+
echo "Press Enter to continue ..."
2520+
read
2521+
clear
24432522
fi
24442523
generate_file_list
24452524
install_packages

0 commit comments

Comments
 (0)