From 54b6c8479bb1dfe092c272b1eb0ab1cb25e24e1f Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Thu, 30 May 2024 13:20:43 -0400 Subject: [PATCH] 6-public now excludes fc* addresses, cloudflare will use grepcidr if available to ensure public ip, git *-all scripts now sort their output, and a few other minor tweaks. --- 6-public-ip.sh | 2 +- cloudflare.sh | 36 ++++++++++++++++++++++++++++ fetch-all.sh | 2 +- list-all.sh | 2 +- one-time-stuff/conf/sshd_config.conf | 2 +- one-time-stuff/vim/vimrc | 4 ++++ pull-all.sh | 2 +- status-all.sh | 2 +- 8 files changed, 46 insertions(+), 6 deletions(-) diff --git a/6-public-ip.sh b/6-public-ip.sh index bf18a5b..1f0caf4 100755 --- a/6-public-ip.sh +++ b/6-public-ip.sh @@ -4,7 +4,7 @@ # keep trying until we get a result # device info -address=$(ip -6 addr list scope global | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1) +address=$(ip -6 addr list scope global | grep -v " fc" | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1) # dig if [[ -z "$address" ]] && [[ -n $(command -v "dig") ]]; then diff --git a/cloudflare.sh b/cloudflare.sh index 29c54ba..fd2637f 100755 --- a/cloudflare.sh +++ b/cloudflare.sh @@ -12,6 +12,10 @@ print_usage() { echo "Usage: [token=] [zone=] [prefix=] $0 [-q] [-f 'query-filters'] ('content' | 'regex-replace' 'regex-find')" } +# known private ranges +local4='192.168.0.0/16 172.16.0.0/12 10.0.0.0/8' +local6='fc00::/7 fe80::/10' + # handle all arguments provided while getopts 'f:qt' flag; do case "$flag" in @@ -69,6 +73,14 @@ fi if [[ "$content" = *''* ]]; then ipv4=$("$scriptRoot/4-public-ip.sh") content=$(echo "$content" | sed "s//$ipv4/g") + + # check if address is actually public + if [[ -n $(command -v "grepcidr") ]]; then + if [[ -z $(echo "$ipv4" | grepcidr -v "$local4") ]]; then + echo "IPv4 lookup failed, stopping" + exit 2 + fi + fi fi # limit 1 @@ -77,12 +89,28 @@ if [[ "$content" = *']+(?=\>)') ipv4=$(dig +short A "$domain" | head -n 1) content=$(echo "$content" | sed "s//$ipv4/g") + + # check if address is actually public + if [[ -n $(command -v "grepcidr") ]]; then + if [[ -z $(echo "$ipv4" | grepcidr -v "$local4") ]]; then + echo "IPv4 lookup for '$domain' failed, stopping" + exit 2 + fi + fi fi # "" becomes current public ipv6 if [[ "$content" = *''* ]]; then ipv6=$("$scriptRoot/6-public-ip.sh") content=$(echo "$content" | sed "s//$ipv6/g") + + # check if address is actually public + if [[ -n $(command -v "grepcidr") ]]; then + if [[ -z $(echo "$ipv6" | grepcidr -v "$local6") ]]; then + echo "IPv6 lookup failed, stopping" + exit 2 + fi + fi fi # limit 1 @@ -91,6 +119,14 @@ if [[ "$content" = *']+(?=\>)') ipv6=$(dig +short AAAA "$domain" | head -n 1) content=$(echo "$content" | sed "s//$ipv6/g") + + # check if address is actually public + if [[ -n $(command -v "grepcidr") ]]; then + if [[ -z $(echo "$ipv6" | grepcidr -v "$local6") ]]; then + echo "IPv6 lookup for '$domain' failed, stopping" + exit 2 + fi + fi fi # --- update regex --- diff --git a/fetch-all.sh b/fetch-all.sh index 58d1eab..bb38821 100755 --- a/fetch-all.sh +++ b/fetch-all.sh @@ -48,5 +48,5 @@ function process_git_fetch () { # and call process_git_fetch on each location that was found. # we then work on the folder that contained the ".git" folder. -find "$followLinks" "$@" -type d -name ".git" $checkHidden | while read -r file; do process_git_fetch "$file"; done +find "$followLinks" "$@" -type d -name ".git" $checkHidden | sort | while read -r file; do process_git_fetch "$file"; done diff --git a/list-all.sh b/list-all.sh index b9ebcb6..c8f20d4 100755 --- a/list-all.sh +++ b/list-all.sh @@ -48,5 +48,5 @@ function process_git_list () { # and call process_git_list on each location that was found. # we then work on the folder that contained the ".git" folder. -find "$followLinks" "$@" -type d -name ".git" $checkHidden | while read -r file; do process_git_list "$file"; done +find "$followLinks" "$@" -type d -name ".git" $checkHidden | sort | while read -r file; do process_git_list "$file"; done diff --git a/one-time-stuff/conf/sshd_config.conf b/one-time-stuff/conf/sshd_config.conf index 4a619fa..1903fd2 100644 --- a/one-time-stuff/conf/sshd_config.conf +++ b/one-time-stuff/conf/sshd_config.conf @@ -5,7 +5,7 @@ PubkeyAuthentication yes PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication no -UsePAM no +UsePAM yes LogLevel VERBOSE X11Forwarding yes diff --git a/one-time-stuff/vim/vimrc b/one-time-stuff/vim/vimrc index 7116cf6..03749f9 100644 --- a/one-time-stuff/vim/vimrc +++ b/one-time-stuff/vim/vimrc @@ -57,3 +57,7 @@ highlight GitGutterDelete cterm=reverse ctermfg=1 ctermbg=none gui=reverse gui " style vim-airline let g:airline_theme='light' +" style context +let g:context_ellipsis_char='•' +let g:context_border_char='═' + diff --git a/pull-all.sh b/pull-all.sh index cd204c9..3c82bc0 100755 --- a/pull-all.sh +++ b/pull-all.sh @@ -48,5 +48,5 @@ function process_git_pull () { # and call process_git_pull on each location that was found. # we then work on the folder that contained the ".git" folder. -find "$followLinks" "$@" -type d -name ".git" $checkHidden | while read -r file; do process_git_pull "$file"; done +find "$followLinks" "$@" -type d -name ".git" $checkHidden | sort | while read -r file; do process_git_pull "$file"; done diff --git a/status-all.sh b/status-all.sh index c900b02..6790781 100755 --- a/status-all.sh +++ b/status-all.sh @@ -97,5 +97,5 @@ function process_git_status () { # and call process_git_list on each location that was found. # we then work on the folder that contained the ".git" folder. -find "$followLinks" "$@" -type d -name ".git" $checkHidden | while read -r file; do process_git_status "$file"; done +find "$followLinks" "$@" -type d -name ".git" $checkHidden | sort | while read -r file; do process_git_status "$file"; done