Commit 3e5f05e8 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: implement is_strange_url and use it to prevent break correct URL, try check all locations

parent 0dbcdadb
...@@ -204,6 +204,13 @@ is_url() ...@@ -204,6 +204,13 @@ is_url()
echo "$1" | grep -q "^[filehtps]*:/" echo "$1" | grep -q "^[filehtps]*:/"
} }
is_strange_url()
{
local URL="$1"
is_url "$URL" || return
echo "$URL" | grep -q "[?&]"
}
is_ipfs_hash() is_ipfs_hash()
{ {
echo "$1" | grep -q -E "^Qm[[:alnum:]]{44}$" echo "$1" | grep -q -E "^Qm[[:alnum:]]{44}$"
...@@ -779,11 +786,13 @@ url_get_real_url() ...@@ -779,11 +786,13 @@ url_get_real_url()
# don't check location if we have made form of the URL # don't check location if we have made form of the URL
[ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return [ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return
local loc="$(url_get_header "$URL" "Location" | tail -n1)" local loc
if is_url "$loc" ; then for loc in $(url_get_header "$URL" "Location" | tac) ; do
echo "$loc" if ! is_strange_url "$loc" ; then
return echo "$loc"
fi return
fi
done
echo "$URL" echo "$URL"
} }
...@@ -867,11 +876,13 @@ url_get_real_url() ...@@ -867,11 +876,13 @@ url_get_real_url()
# don't check location if we have made form of the URL # don't check location if we have made form of the URL
[ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return [ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return
local loc="$(url_get_header "$URL" "location" | tail -n1)" local loc
if is_url "$loc" ; then for loc in $(url_get_header "$URL" "location" | tac) ; do
echo "$loc" if ! is_strange_url "$loc" ; then
return echo "$loc"
fi return
fi
done
echo "$URL" echo "$URL"
} }
...@@ -921,7 +932,9 @@ scat() ...@@ -921,7 +932,9 @@ scat()
url_scat "$URL" url_scat "$URL"
# It is list only function. Don't save to IPFS # It is list only function. Don't save to IPFS
exit return
###################
local CID="$(get_cid_by_url "$URL")" local CID="$(get_cid_by_url "$URL")"
if [ -n "$CID" ] ; then if [ -n "$CID" ] ; then
...@@ -958,11 +971,11 @@ sget() ...@@ -958,11 +971,11 @@ sget()
exit exit
fi fi
if echo "$REALURL" | grep -q "[?&]" ; then #if is_strange_url "$REALURL" ; then
info "Just download strange URL, skipping IPFS" # info "Just download strange URL $REALURL, skipping IPFS"
url_sget "$REALURL" "$TARGET" # url_sget "$REALURL" "$TARGET"
return # return
fi #fi
local CID="$(get_cid_by_url "$REALURL")" local CID="$(get_cid_by_url "$REALURL")"
if [ -n "$CID" ] ; then if [ -n "$CID" ] ; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment