Finish this evening project

This commit is contained in:
Michael De Roover 2025-04-01 22:35:01 +02:00
commit 3c7fe723a3
2 changed files with 75 additions and 0 deletions

9
readme.md Normal file
View File

@ -0,0 +1,9 @@
#### urldeconstruct
A program that deconstructs URLs! I'm sure that's news to you...
It was an evening project at 2025-04-01, and served as a means to discover why a Greenpeace link of all things would cause my Linux system to generate a fork bomb.
[url](https://act.greenpeace.org/page/168809/action/1?locale=nl-BE&utm_medium=email&utm_source=email&utm_campaign=Send%20a%20letter%20Ship%20Tour%202025%20-%20NL%20&utm_content=Send+a+letter+Ship+Tour+2025+-+NL+&ea.url.id=7993625&forwarded=true)
So I guess that's another evening wasted. Gotta admire that training though, AI won't give you any of that :)

66
urldeconstruct Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# May cause fork bomb, do not use this!
#url="$1"
# Set a user limit just to be safe.
# Current process count seems to be between 512 and 600.
# Quite unsettling...
ulimit -u 600
# And query interactively from user instead.
read -sp "URL: " url
#printf "%s\n\n" "$url"
printf "\n"
# Prepare URL
url=$(sed 's/\?/\n/g' <<< $url)
url=$(sed 's/\&/\n/g' <<< $url)
# Turn it into an array
url_array=$(sed 's/\n/ /g' <<< $url)
url_array=($url_array)
#printf "%s\n" "${url_array[*]}"
#printf "%s %s\n" "Base URL:" "${url_array[0]}"
# https://stackoverflow.com/questions/6723426
for url_argument in "${!url_array[@]}"
do
# Zero is base URL, everything else is arguments
if [ "$url_argument" = "0" ]
then
export url_property="Base URL:"
elif [ "$url_argument" != "0" ]
then
export url_property="Argument:"
fi
# Separate key=value pairs into an array
url_parameter=($(sed 's/\=/ /g' <<< ${url_array[$url_argument]}))
# Differentiate trackers from other arguments
if grep -q utm <<< ${url_parameter[0]}
then
url_property="Tracker:"
fi
# Turn %20 / + urlencoding into human-readable spaces
url_despace=${url_parameter[1]}
[ $(grep '%20' <<< "$url_despace") ] && \
url_despaced="$(sed 's/\%20/ /g' <<< $url_despace)"
[ $(grep '+' <<< "$url_despace") ] && \
url_despaced="$(sed 's/\+/ /g' <<< $url_despace)"
# For publication purposes only
[ ${url_parameter[0]} = "ea.url.id" ] && \
url_parameter[1]="redacted"
# Print out the resulting text
printf "%-10s%-15s%-15s\n" "$url_property" "${url_parameter[0]}" "${url_parameter[1]}" #"${url_array[$url_argument]}"
[ ! -z "$url_despaced" ] &&
printf "%-25s%15s\n" "" "$url_despaced"
# Clear variables for next loop
unset url_despaced
done