Skip to content

Commit

Permalink
lurl, perl version
Browse files Browse the repository at this point in the history
  • Loading branch information
rootTHC committed Sep 1, 2024
1 parent 52d25fe commit b5e831a
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions hackshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ xssh() {
stty "${ttyp}"
}

purl() {
local opts="timeout=10"
local opts_init
local url="${1:?}"
{ [[ "${url:0:8}" == "https://" ]] || [[ "${url:0:7}" == "http://" ]]; } || url="https://${url}"
[ -n "$UNSAFE" ] && {
opts_init="import ssl;ctx = ssl.create_default_context();ctx.check_hostname = False;ctx.verify_mode = ssl.CERT_NONE;"
opts+=", context=ctx"
}
"$HS_PY" -c "import urllib.request;import sys;${opts_init}sys.stdout.buffer.write(urllib.request.urlopen(\"$url\", $opts).read())"
}

surl() {
local r="${1#*://}"
local opts=("-quiet" "-ign_eof")
Expand All @@ -118,6 +130,14 @@ surl() {
| sed '1,/^\r\{0,1\}$/d'
}

lurl() {
local url="${1:?}"
{ [[ "${url:0:8}" == "https://" ]] || [[ "${url:0:7}" == "http://" ]]; } || url="https://${url}"
perl -e 'use LWP::Simple qw(get);
my $url = '"'${1:?}'"';
print(get $url);'
}

burl() {
local proto x host query
IFS=/ read -r proto x host query <<<"$1"
Expand Down Expand Up @@ -1013,17 +1033,7 @@ hs_init_dl() {
wget -O- "${opts[@]}" --connect-timeout=7 --dns-timeout=7 "${1:?}"
}
elif [ -n "$HS_PY" ]; then
dl() {
local opts="timeout=10"
local opts_init
local url="${1:?}"
{ [[ "${url:0:8}" == "https://" ]] || [[ "${url:0:7}" == "http://" ]]; } || url="https://${url}"
[ -n "$UNSAFE" ] && {
opts_init="import ssl;ctx = ssl.create_default_context();ctx.check_hostname = False;ctx.verify_mode = ssl.CERT_NONE;"
opts+=", context=ctx"
}
"$HS_PY" -c "import urllib.request;import sys;${opts_init}sys.stdout.buffer.write(urllib.request.urlopen(\"$url\", $opts).read())"
}
dl() { purl "$@"; }
elif which openssl >/dev/null; then
dl() { surl "$@"; }
else
Expand Down

0 comments on commit b5e831a

Please sign in to comment.