summaryrefslogtreecommitdiff
path: root/urititle
diff options
context:
space:
mode:
authorepoch <epoch@hack.thebackupbox.net>2021-10-30 00:26:47 +0000
committerepoch <epoch@hack.thebackupbox.net>2021-10-30 00:26:47 +0000
commit66e0f644263439515203f4e0aaaaf4925a29a38e (patch)
tree831039d7731e7d077d286a3aed3fcde98f80786a /urititle
parent7f92814f2200657a58b68bf2ff0376550446d42e (diff)
downloaduritools-66e0f644263439515203f4e0aaaaf4925a29a38e.tar.gz
uritools-66e0f644263439515203f4e0aaaaf4925a29a38e.zip
added a few more things that can be titled
Diffstat (limited to 'urititle')
-rwxr-xr-xurititle66
1 files changed, 55 insertions, 11 deletions
diff --git a/urititle b/urititle
index 5034cec..1889784 100755
--- a/urititle
+++ b/urititle
@@ -13,15 +13,15 @@ if [ ! "$port" ];then
port=80
fi
fi
-if [ "$qs" ];then
- path="${path}?${qs}"
-fi
case "$scheme" in
http*)
+ if [ "$qs" ];then
+ path="${path}?${qs}"
+ fi
if [ "$port" ];then
UA="Mozilla/5.0 (impersonator)"
# content_type="$(printf "HEAD %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | grep -i '^Content-Type: ' | head -n1 | cut '-d ' -f2 | cut '-d;' -f1 | tr -d '\r\n')"
- a_header="$((curl -Lsi "$1" || echo curl failed) | head -c 10000 | egrep -ai '^curl failed|^Location: |^Content-Type: ' | head -n1 | tr -d '\r\n')"
+ a_header="$((curl -gA "$UA" -Lsi "$1" || echo curl failed) | head -c 10000 | egrep -ai '^curl failed|^Location: |^Content-Type: ' | head -n1 | tr -d '\r\n')"
if printf "%s\n" "${a_header}" | grep -i '^Content-Type: ' 2>&1 >/dev/null 2>&1;then
content_type="$(printf '%s\n' "${a_header}" | cut '-d ' -f2- | cut '-d;' -f1)"
fi
@@ -31,16 +31,25 @@ http*)
if printf "%s\n" "${a_hreader}" | grep -i '^curl failed' 2>&1 >/dev/null 2>&1;then
content_type="curl failed. cert expired? dunno yet. TODO: code openssl checker."
fi
- if [ "${content_type}" = "text/html" -o "${content_type}" = "application/xhtml+xml" ];then
+### main.lv doesn't have content-type on some pages, so if the content-type is missing or empty, we're assuming html
+ if [ "${content_type}" = "text/html" -o "${content_type}" = "application/xhtml+xml" -o "${content_type}" = "" ];then
# title="$(printf "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | head -c 10000 | tr -d '\n' | tr '<' '\n' | grep -A 10 '^title>' | grep -B 10 '^\/title>' | cut '-d>' -f2)"
- title="$(curl -si "$1" | head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .)"
- printf "title: %s\n" "$title" | html_entities_decode
+ title="$(curl -gsi "$1" | head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .)"
+ if [ "${content_type}" = "" ];then
+ printf "WTF: header: %s\n" "${a_header}"
+ printf "WARNING: NO CONTENT-TYPE RETURNED FROM SERVER. Assuming text/html. title: %s\n" "$title" | html_entities_decode
+ else
+ printf "title: %s\n" "$title" | html_entities_decode
+ fi
else
printf "%s\n" "${a_header}"
fi
fi
;;
gemini)
+ if [ "$qs" ];then
+ path="${path}?${qs}"
+ fi
first=1
gemini-get "$1" | while read -r line;do
if [ "$first" ];then
@@ -49,6 +58,8 @@ gemini)
if [ "$type" != 'text/gemini' ];then
if [ "$type" = "text/html" ];then
head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .
+ elif [ "$type" = "text/plain" ];then
+ printf "title: %s\n" "$(head -n1)"
else
printf "title: %s\n" "$(printf "%s\n" "$line" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
fi
@@ -61,17 +72,34 @@ gemini)
magnet)
printf "title: %s\n" "$(printf "%s\n" "$1" | tr '&' '\n' | grep ^dn= | cut -d= -f2- | uriunescape)"
;;
+dns)
+ if [ "$qs" ] ; then
+ export QUERY_STRING="$qs"
+ type="-t $(query_param "type")"
+ fi
+ if [ "$domain" ];then
+ server="@$domain"
+ path="$(printf "%s\n" "$path" | sed "s|^/||")"
+ else
+ server=""
+ fi
+ dig $type "$path" +short $server | tr '\n' ' '
+ echo # the tr above strips out the trailing \n
+ ;;
ftp)
- curl "$1" 2>&1 | tail -n1
+ curl -g "$1" 2>&1 | tail -n1
;;
gopher)
+ if [ "$qs" ];then
+ path="${path}?${qs}"
+ fi
type="$(printf "%s\n" "$1" | uricut -p | cut -b2- | cut -b1)"
if [ "$type" = 1 -o "$type" = "" ];then
- printf "title: %s\n" "$(curl -s "$1" | grep ^i | head -n1 | cut -f1 | cut -b2-)"
+ printf "title: %s\n" "$(curl -gs "$1" | grep ^i | head -n1 | cut -f1 | cut -b2-)"
elif [ "$type" = 0 ];then
- printf "title: %s\n" "$(curl -s "$1" | head -n1)"
+ printf "title: %s\n" "$(curl -gs "$1" | head -n1)"
elif [ "$type" = "h" ];then
- printf "title: %s\n" "$(curl -s "$1" | head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .)"
+ printf "title: %s\n" "$(curl -gs "$1" | head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .)"
else
printf "title: don't know how to get title of non-1 gopher links"
fi
@@ -83,8 +111,24 @@ urn)
if [ "$nid" = "ietf" ];then
if [ "$nss" = "rfc" ];then
cat "/var/db/rfc/rfc${nss2}.json" | jq .title
+ exit 0
+ fi
+ fi
+ if [ "$nid" = "phrack" ];then
+ if [ ! "${nss2}" ];then
+ printf "issue %s of phrack has %d articles\n" "${nss}" "$(grep -c '.' /var/db/phrack/meta/${nss}.tsv)"
+ exit 0
+ fi
+ cat /var/db/phrack/meta/${nss}.tsv | grep "^${nss}/${nss2}"$'\t' | sed 's|/|\t|' | tr '\n\t' '\0\0' | xargs -n4 -0 printf 'issue %2s article %2s %79s by [%s]\n'
+ exit 0
+ fi
+ if [ "$nid" = "mitre" ];then
+ if [ "$nss" = "cve" ];then
+ urititle "$(urnresolve "$1")"
+ exit 0
fi
fi
+ urnresolve "$1"
;;
ssh)
if [ ! "$port" ];then