From 16d4e1399343087aab9cf27d120e88665a435cd9 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 1 Sep 2020 17:56:28 +0100 Subject: [PATCH] created queryip --- lgsm/functions/check_ip.sh | 93 ++++++------------------- lgsm/functions/command_dev_query_raw.sh | 12 ++-- lgsm/functions/command_monitor.sh | 26 +++---- lgsm/functions/core_getopt.sh | 4 +- lgsm/functions/query_gamedig.sh | 8 +-- 5 files changed, 45 insertions(+), 98 deletions(-) diff --git a/lgsm/functions/check_ip.sh b/lgsm/functions/check_ip.sh index d8c4f3ed5..7d4b4a613 100644 --- a/lgsm/functions/check_ip.sh +++ b/lgsm/functions/check_ip.sh @@ -7,78 +7,25 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -if [ "${travistest}" != "1" ]; then - if [ ! -f "/bin/ip" ]; then - ipcommand="/sbin/ip" - else - ipcommand="ip" - fi - getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -v 127.0.0) - getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -vc 127.0.0) - info_config.sh - info_parms.sh +if [ ! -f "/bin/ip" ]; then + ipcommand="/sbin/ip" +else + ipcommand="ip" +fi +getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -v 127.0.0) +getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -vc 127.0.0) +# Check if server has m ultiple IP addresses - # IP is not set to specific IP. - if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then - fn_print_dots "Check IP" - # Multiple interfaces. - if [ "${getipwc}" -ge "2" ]; then - if [ "${commandname}" == "details" ]; then - fn_print_warn "Check IP: Multiple IP addresses found." - else - fn_print_fail "Check IP: Multiple IP addresses found." - fi - echo -en "\n" - # IP is set within game config. - if [ "${ipsetinconfig}" == "1" ]; then - fn_print_information "Specify the IP you want to bind within ${servercfg}.\n" - echo -en " * location: ${servercfgfullpath}\n" - echo -en "\n" - echo -en "Set ${ipinconfigvar} to one of the following:\n" - fn_script_log_fatal "Multiple IP addresses found." - fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}." - # IP is set within LinuxGSM config. - else - fn_print_information_nl "Specify the IP you want to bind within a LinuxGSM config file.\n" - echo -en " * location: ${configdirserver}\n" - echo -en "\n" - echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" - fn_script_log_fatal "Multiple IP addresses found." - fn_script_log_fatal "Specify the IP you want to bind within: ${configdirserver}." - fi - echo -en "${getip}\n" - echo -en "\n" - echo -en "https://linuxgsm.com/network-interfaces\n" - echo -en "" - # Do not exit for details and postdetails commands. - if [ "${commandname}" != "DETAILS" ]||[ "${commandname}" != "POST-DETAILS" ]; then - fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n" - core_exit.sh - else - ip="NOT SET" - fi - # Single interface. - elif [ "${ipsetinconfig}" == "1" ]; then - fn_print_fail "Check IP: IP address not set in game config." - echo -en "\n" - fn_print_information "Specify the IP you want to bind within ${servercfg}.\n" - echo -en " * location: ${servercfgfullpath}\n" - echo -en "\n" - echo -en "Set ${ipinconfigvar} to the following:\n" - echo -en "${getip}\n" - echo -en "\n" - echo -en "https://linuxgsm.com/network-interfaces\n" - echo -en "" - fn_script_log_fatal "IP address not set in game config." - fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}." - fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n" - if [ "${commandname}" != "DETAILS" ]; then - core_exit.sh - fi - else - fn_print_info_nl "Check IP: ${getip}" - fn_script_log_info "IP automatically set as: ${getip}" - ip="${getip}" - fi - fi +# If the ip variable is set by user +if [ "${ip}" != "0.0.0.0" ]||[ "${ip}" != "" ]; then + queryip=( "${ip}" ) +# If ip is not set by user +else + queryip=( "${getip}" ) fi + +echo "###### DEV IP CHECK ######" +echo "IP: ${IP}" +echo "EXTIP: ${extip}" +echo "DISPLAYIP: ${displayip}" +echo "QUERYIP: ${queryip}" diff --git a/lgsm/functions/command_dev_query_raw.sh b/lgsm/functions/command_dev_query_raw.sh index 84efe0da9..3da1be8ea 100644 --- a/lgsm/functions/command_dev_query_raw.sh +++ b/lgsm/functions/command_dev_query_raw.sh @@ -42,20 +42,20 @@ echo -e "" echo -e "gsquery Raw Output" echo -e "=================================" echo -e "" -echo -e "./query_gsquery.py -a \"${ip}\" -p \"${queryport}\" -e \"${querytype}\"" +echo -e "./query_gsquery.py -a \"${queryip}\" -p \"${queryport}\" -e \"${querytype}\"" echo -e "" if [ ! -f "${functionsdir}/query_gsquery.py" ]; then fn_fetch_file_github "lgsm/functions" "query_gsquery.py" "${functionsdir}" "chmodx" "norun" "noforce" "nomd5" fi -"${functionsdir}"/query_gsquery.py -a "${ip}" -p "${queryport}" -e "${querytype}" +"${functionsdir}"/query_gsquery.py -a "${queryip}" -p "${queryport}" -e "${querytype}" echo -e "" echo -e "TCP Raw Output" echo -e "=================================" echo -e "" -echo -e "bash -c 'exec 3<> /dev/tcp/'${ip}'/'${queryport}''" +echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}''" echo -e "" -bash -c 'exec 3<> /dev/tcp/'${ip}'/'${queryport}'' +bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}'' querystatus="$?" echo -e "" if [ "${querystatus}" == "0" ]; then @@ -71,9 +71,9 @@ echo -e "" echo -e "TCP Raw Output" echo -e "=================================" echo -e "" -echo -e "bash -c 'exec 3<> /dev/tcp/'${ip}'/'${port}''" +echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}''" echo -e "" -bash -c 'exec 3<> /dev/tcp/'${ip}'/'${port}'' +bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}'' querystatus="$?" echo -e "" if [ "${querystatus}" == "0" ]; then diff --git a/lgsm/functions/command_monitor.sh b/lgsm/functions/command_monitor.sh index 89524ab91..3f8b48334 100644 --- a/lgsm/functions/command_monitor.sh +++ b/lgsm/functions/command_monitor.sh @@ -85,12 +85,12 @@ fn_query_gsquery(){ if [ ! -f "${functionsdir}/query_gsquery.py" ]; then fn_fetch_file_github "lgsm/functions" "query_gsquery.py" "${functionsdir}" "chmodx" "norun" "noforce" "nomd5" fi - "${functionsdir}"/query_gsquery.py -a "${ip}" -p "${queryport}" -e "${querytype}" > /dev/null 2>&1 + "${functionsdir}"/query_gsquery.py -a "${queryip}" -p "${queryport}" -e "${querytype}" > /dev/null 2>&1 querystatus="$?" } fn_query_tcp(){ - bash -c 'exec 3<> /dev/tcp/'${ip}'/'${queryport}'' > /dev/null 2>&1 + bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}'' > /dev/null 2>&1 querystatus="$?" } @@ -99,14 +99,14 @@ fn_monitor_query(){ # Query will wait up to 60 seconds to confirm server is down as server can become non-responsive during map changes. totalseconds=0 for queryattempt in {1..5}; do - fn_print_dots "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_dots "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_querying_eol - fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : QUERYING" + fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : QUERYING" # querydelay if [ "$(cat "${lockdir}/${selfname}.lock")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then - fn_print_ok "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_delay_eol_nl - fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : DELAY" + fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : DELAY" fn_script_log_info "Query bypassed: ${gameservername} started less than ${querydelay} minutes ago" fn_script_log_info "Server started: $(date -d @$(cat "${lockdir}/${selfname}.lock"))" fn_script_log_info "Current time: $(date)" @@ -126,9 +126,9 @@ for queryattempt in {1..5}; do if [ "${querystatus}" == "0" ]; then # Server query OK. - fn_print_ok "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_ok_eol_nl - fn_script_log_pass "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt}: OK" + fn_script_log_pass "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: OK" monitorpass=1 if [ "${querystatus}" == "0" ]; then # Add query data to log. @@ -156,17 +156,17 @@ for queryattempt in {1..5}; do core_exit.sh else # Server query FAIL. - fn_print_fail "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_fail_eol - fn_script_log_warn "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt}: FAIL" + fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" # Monitor will try gamedig (if supported) for first 30s then gsquery before restarting. if [ "${querymethod}" == "gsquery" ]||[ "${querymethod}" == "tcp" ]; then # gsquery will fail if longer than 60s if [ "${totalseconds}" -ge "59" ]; then # Monitor will FAIL if over 60s and trigger gane server reboot. - fn_print_fail "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_fail_eol_nl - fn_script_log_warn "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt}: FAIL" + fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" # Send alert if enabled. alert="restartquery" alert.sh @@ -183,7 +183,7 @@ for queryattempt in {1..5}; do # Second counter will wait for 15s before breaking loop. for seconds in {1..15}; do - fn_print_fail "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: ${cyan}WAIT${default}" + fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: ${cyan}WAIT${default}" sleep 0.5 totalseconds=$((totalseconds + 1)) if [ "${seconds}" == "15" ]; then diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index 47071bc24..82eb77691 100644 --- a/lgsm/functions/core_getopt.sh +++ b/lgsm/functions/core_getopt.sh @@ -62,9 +62,9 @@ currentopt+=( "${cmd_update_linuxgsm[@]}" ) # Exclude noupdate games here. if [ "${shortname}" == "jk2" ]||[ "${engine}" != "idtech3" ];then - if [ "${engine}" != "quake" ]&&[ "${engine}" != "idtech2" ]&&[ "${engine}" != "iw2.0" ]&&[ "${engine}" != "iw3.0" ]&&[ "${shortname}" != "bf1942" ]&&[ "${shortname}" != "bfv" ]&&[ "${shortname}" != "samp" ]; then + if [ "${shortname}" != "bf1942" ]&&[ "${shortname}" != "bfv" ]&&[ "${engine}" != "idtech2" ]&&[ "${engine}" != "iw2.0" ]&&[ "${engine}" != "iw3.0" ]&&[ "${engine}" != "quake" ]&&[ "${shortname}" != "samp" ]&&[ "${shortname}" != "ut2k4" ]&&[ "${shortname}" != "ut99" ]; then currentopt+=( "${cmd_update[@]}" ) - # force update for SteamCMD only or MTA. + # force update for SteamCMD or Multi Theft Auto only. if [ "${appid}" ]||[ "${shortname}" == "mta" ]; then currentopt+=( "${cmd_force_update[@]}" ) fi diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 071645b49..3c5ff38bf 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -14,13 +14,13 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; check_status.sh if [ "${status}" != "0" ]; then # checks if query is working null = pass. - gamedigcmd=$(echo -e "gamedig --type \"${querytype}\" --host \"${ip}\" --query_port \"${queryport}\"|jq") - gamedigraw=$(gamedig --type "${querytype}" --host "${ip}" --query_port "${queryport}") + gamedigcmd=$(echo -e "gamedig --type \"${querytype}\" --host \"${queryip}\" --query_port \"${queryport}\"|jq") + gamedigraw=$(gamedig --type "${querytype}" --host "${queryip}" --query_port "${queryport}") querystatus=$(echo "${gamedigraw}" | jq '.error|length') if [ "${querystatus}" != "null" ]; then - gamedigcmd=$(echo -e "gamedig --type \"${querytype}\" --host \"${ip}\" --port \"${queryport}\"|jq") - gamedigraw=$(gamedig --type "${querytype}" --host "${ip}" --port "${queryport}") + gamedigcmd=$(echo -e "gamedig --type \"${querytype}\" --host \"${queryip}\" --port \"${queryport}\"|jq") + gamedigraw=$(gamedig --type "${querytype}" --host "${queryip}" --port "${queryport}") querystatus=$(echo "${gamedigraw}" | jq '.error|length') fi