Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions files/usr/share/functions/api_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,15 @@ check_and_set_default_traceroute() {
}

create_time_object_traceroute() {
# $1: ip
# $2: hops
local _ip="$1"
local _hops="$2"
# $1: index of the hop
# $2: ip
# $3: hops
local _index="$1"
local _ip="$2"
local _hops="$3"

json_add_object
json_add_int hop_index "$_index"
json_add_string ip "$_ip"

# Create an array for storing the times
Expand Down Expand Up @@ -479,6 +482,9 @@ get_traceroute() {
# Only process the traceroute if it is not empty
if [ -n "$_traceroute" ]
then
# Get all hops with index
local _hops_index="$(echo "$_traceroute" | grep -E -o '^ *[0-9]+.+[0-9]*(\.[0-9]*){3}')"

# Get all hops, might find more than one per line
local _hops="$(echo "$_traceroute" | grep -E -o '[0-9]*(\.[0-9]*){3}(( \*)* [0-9]*\.[0-9]* ms)+')"

Expand Down Expand Up @@ -540,21 +546,30 @@ get_traceroute() {
# Get the ip of the hop
local _ip="$(echo "$_hop" | awk '{print $1}')"

# Get the index of the hop
local _index="$(echo "$_hops_index" | grep "$_ip" | awk '{print $1}' | head -1)"

# Check if ip is in _repeated_hops, add them, joining the time values
local _hops_to_add="$(echo "$_repeated_hops" | grep "$_ip")"

if [ -n "$_hops_to_add" ] && [ -z "$(echo "$_blacklist_hops" | grep "$_ip")" ]
then
create_time_object_traceroute "$_ip" "$_hops_to_add"
create_time_object_traceroute "$_index" "$_ip" "$_hops_to_add"

# Add the ip to blacklist
_blacklist_hops="${_blacklist_hops}"$'\n'"${_ip}"

# Update _hops_index to remove the line
_hops_index="$(echo "$_hops_index" | grep -vE "^ *$_index ")"
fi

# Check if the ip is in _blacklist_hops, otherwise append to array
if [ -z "$(echo "$_blacklist_hops" | grep "$_ip")" ]
then
create_time_object_traceroute "$_ip" "$_hop"
create_time_object_traceroute "$_index" "$_ip" "$_hop"

# Update _hops_index to remove the line
_hops_index="$(echo "$_hops_index" | grep -vE "^ *$_index ")"
fi
done

Expand Down