mirror of
https://github.com/aclist/dztui.git
synced 2024-12-29 13:52:03 +01:00
Additional error handling for API keys
This commit is contained in:
parent
82ca4ccb7c
commit
a2b783478a
2 changed files with 34 additions and 17 deletions
|
@ -5,6 +5,10 @@
|
||||||
- Custom query API
|
- Custom query API
|
||||||
- Standardize dialogs
|
- Standardize dialogs
|
||||||
|
|
||||||
|
## [2.7.0-rc.23] 2022-10-03
|
||||||
|
### Fixed
|
||||||
|
- More robust error handling for API keys
|
||||||
|
|
||||||
## [2.7.0-rc.22] 2022-10-02
|
## [2.7.0-rc.22] 2022-10-02
|
||||||
### Fixed
|
### Fixed
|
||||||
- Merge stable branch hotfixes
|
- Merge stable branch hotfixes
|
||||||
|
|
47
dzgui.sh
47
dzgui.sh
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
version=2.7.0-rc.22
|
version=2.7.0-rc.23
|
||||||
|
|
||||||
aid=221100
|
aid=221100
|
||||||
game="dayz"
|
game="dayz"
|
||||||
|
@ -79,13 +79,13 @@ depcheck(){
|
||||||
init_items(){
|
init_items(){
|
||||||
#array order determines menu selector; this is destructive
|
#array order determines menu selector; this is destructive
|
||||||
items=(
|
items=(
|
||||||
|
"[NEW] Server browser"
|
||||||
"Launch server list"
|
"Launch server list"
|
||||||
"Quick connect to favorite server"
|
"Quick connect to favorite server"
|
||||||
"Connect by IP"
|
"Connect by IP"
|
||||||
"Add server by ID"
|
"Add server by ID"
|
||||||
"Add favorite server"
|
"Add favorite server"
|
||||||
"Delete server"
|
"Delete server"
|
||||||
"[NEW] Server browser"
|
|
||||||
"List installed mods"
|
"List installed mods"
|
||||||
"Toggle debug mode"
|
"Toggle debug mode"
|
||||||
"Report bug (opens in browser)"
|
"Report bug (opens in browser)"
|
||||||
|
@ -419,7 +419,7 @@ connect(){
|
||||||
ip=$(echo "$1" | awk -F"$separator" '{print $1}')
|
ip=$(echo "$1" | awk -F"$separator" '{print $1}')
|
||||||
bid=$(echo "$1" | awk -F"$separator" '{print $2}')
|
bid=$(echo "$1" | awk -F"$separator" '{print $2}')
|
||||||
if [[ $2 == "ip" ]]; then
|
if [[ $2 == "ip" ]]; then
|
||||||
fetch_mods_sa "$ip" > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
|
fetch_mods_sa "$ip" > >(zenity --pulsate --progress --auto-close --no-cancel --width=500 2>/dev/null)
|
||||||
else
|
else
|
||||||
fetch_mods "$bid"
|
fetch_mods "$bid"
|
||||||
fi
|
fi
|
||||||
|
@ -521,7 +521,13 @@ fetch_ip_metadata(){
|
||||||
#local_ip(){
|
#local_ip(){
|
||||||
#(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)
|
#(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)
|
||||||
#}
|
#}
|
||||||
|
test_steam_api(){
|
||||||
|
local code=$(curl -ILs "https://api.steampowered.com/IGameServersService/GetServerList/v1/?filter=\appid\221100&limit=10&key=$steam_api" \
|
||||||
|
| grep -E "^HTTP")
|
||||||
|
[[ $code =~ 403 ]] && { echo 403 >> logs; return 1; }
|
||||||
|
}
|
||||||
add_steam_api(){
|
add_steam_api(){
|
||||||
|
[[ ! $(test_steam_api) ]] && return 1
|
||||||
mv $config_file ${config_path}dztuirc.old
|
mv $config_file ${config_path}dztuirc.old
|
||||||
nr=$(awk '/steam_api=/ {print NR}' ${config_path}dztuirc.old)
|
nr=$(awk '/steam_api=/ {print NR}' ${config_path}dztuirc.old)
|
||||||
steam_api="steam_api=\"$steam_api\""
|
steam_api="steam_api=\"$steam_api\""
|
||||||
|
@ -535,9 +541,9 @@ check_steam_api(){
|
||||||
steam_api=$(zenity --entry --text="Key 'steam_api' not present in config file. Enter Steam API key:" --title="DZGUI" 2>/dev/null)
|
steam_api=$(zenity --entry --text="Key 'steam_api' not present in config file. Enter Steam API key:" --title="DZGUI" 2>/dev/null)
|
||||||
if [[ $? -eq 1 ]] ; then
|
if [[ $? -eq 1 ]] ; then
|
||||||
return
|
return
|
||||||
elif [[ $steam_api -lt 32 ]]; then
|
elif [[ ${#steam_api} -lt 32 ]] || [[ ! $(test_steam_api) ]]; then
|
||||||
zenity --warning --title="DZGUI" --text="Check API key and try again." 2>/dev/null
|
zenity --warning --title="DZGUI" --text="Check API key and try again." 2>/dev/null
|
||||||
return
|
return 1
|
||||||
else
|
else
|
||||||
add_steam_api
|
add_steam_api
|
||||||
fi
|
fi
|
||||||
|
@ -549,6 +555,7 @@ validate_ip(){
|
||||||
connect_by_ip(){
|
connect_by_ip(){
|
||||||
source $config_file
|
source $config_file
|
||||||
check_steam_api
|
check_steam_api
|
||||||
|
[[ $? -eq 1 ]] && return
|
||||||
while true; do
|
while true; do
|
||||||
if [[ $return_from_table -eq 1 ]]; then
|
if [[ $return_from_table -eq 1 ]]; then
|
||||||
return_from_table=0
|
return_from_table=0
|
||||||
|
@ -804,8 +811,12 @@ query_and_connect(){
|
||||||
query_api
|
query_api
|
||||||
parse_json
|
parse_json
|
||||||
#TODO: create logger function
|
#TODO: create logger function
|
||||||
echo "[DZGUI] Checking response time of servers"
|
if [[ ! $delete -eq 1 ]]; then
|
||||||
create_array | zenity --width 500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null
|
echo "[DZGUI] Checking response time of servers"
|
||||||
|
create_array | zenity --width 500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null
|
||||||
|
else
|
||||||
|
create_array
|
||||||
|
fi
|
||||||
rc=$?
|
rc=$?
|
||||||
if [[ $rc -eq 1 ]]; then
|
if [[ $rc -eq 1 ]]; then
|
||||||
:
|
:
|
||||||
|
@ -1038,6 +1049,8 @@ debug_servers(){
|
||||||
}
|
}
|
||||||
server_browser(){
|
server_browser(){
|
||||||
check_steam_api
|
check_steam_api
|
||||||
|
[[ $? -eq 1 ]] && return
|
||||||
|
|
||||||
unset ret
|
unset ret
|
||||||
file=$(mktemp)
|
file=$(mktemp)
|
||||||
local limit=20000
|
local limit=20000
|
||||||
|
@ -1086,7 +1099,7 @@ main_menu(){
|
||||||
items+=("Debug options")
|
items+=("Debug options")
|
||||||
fi
|
fi
|
||||||
if [[ -n $fav ]]; then
|
if [[ -n $fav ]]; then
|
||||||
items[4]="Change favorite server"
|
items[5]="Change favorite server"
|
||||||
fi
|
fi
|
||||||
while true; do
|
while true; do
|
||||||
set_header ${FUNCNAME[0]}
|
set_header ${FUNCNAME[0]}
|
||||||
|
@ -1095,20 +1108,20 @@ main_menu(){
|
||||||
if [[ -z $sel ]]; then
|
if [[ -z $sel ]]; then
|
||||||
warn "No item was selected."
|
warn "No item was selected."
|
||||||
elif [[ $sel == "${items[0]}" ]]; then
|
elif [[ $sel == "${items[0]}" ]]; then
|
||||||
query_and_connect
|
server_browser
|
||||||
elif [[ $sel == "${items[1]}" ]]; then
|
elif [[ $sel == "${items[1]}" ]]; then
|
||||||
connect_to_fav
|
query_and_connect
|
||||||
elif [[ $sel == "${items[2]}" ]]; then
|
elif [[ $sel == "${items[2]}" ]]; then
|
||||||
connect_by_ip
|
connect_to_fav
|
||||||
elif [[ $sel == "${items[3]}" ]]; then
|
elif [[ $sel == "${items[3]}" ]]; then
|
||||||
add_by_id
|
connect_by_ip
|
||||||
elif [[ $sel == "${items[4]}" ]]; then
|
elif [[ $sel == "${items[4]}" ]]; then
|
||||||
add_by_fav
|
add_by_id
|
||||||
elif [[ $sel == "${items[5]}" ]]; then
|
elif [[ $sel == "${items[5]}" ]]; then
|
||||||
|
add_by_fav
|
||||||
|
elif [[ $sel == "${items[6]}" ]]; then
|
||||||
delete=1
|
delete=1
|
||||||
query_and_connect
|
query_and_connect
|
||||||
elif [[ $sel == "${items[6]}" ]]; then
|
|
||||||
server_browser
|
|
||||||
elif [[ $sel == "${items[7]}" ]]; then
|
elif [[ $sel == "${items[7]}" ]]; then
|
||||||
list_mods | sed 's/\t/\n/g' | zenity --list --column="Mod" --column="Symlink" \
|
list_mods | sed 's/\t/\n/g' | zenity --list --column="Mod" --column="Symlink" \
|
||||||
--title="DZGUI" $sd_res --text="$(mods_disk_size)" \
|
--title="DZGUI" $sd_res --text="$(mods_disk_size)" \
|
||||||
|
@ -1344,7 +1357,7 @@ toggle_debug(){
|
||||||
setup(){
|
setup(){
|
||||||
if [[ -n $fav ]]; then
|
if [[ -n $fav ]]; then
|
||||||
set_fav
|
set_fav
|
||||||
items[4]="Change favorite server"
|
items[5]="Change favorite server"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
check_map_count(){
|
check_map_count(){
|
||||||
|
@ -1378,7 +1391,7 @@ while true; do
|
||||||
zenity --info --title="DZGUI" --text="Added "$fav_id" to:\n${config_path}dztuirc\nIf errors occurred, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
|
zenity --info --title="DZGUI" --text="Added "$fav_id" to:\n${config_path}dztuirc\nIf errors occurred, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
|
||||||
source $config_file
|
source $config_file
|
||||||
set_fav
|
set_fav
|
||||||
items[4]="Change favorite server"
|
items[5]="Change favorite server"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue