From e216473476495be043cdf7169ba616784995570a Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Sat, 9 Mar 2013 12:18:16 +0100 Subject: [PATCH] .functions: Improve `getcertnames` Follow-up to 12bb9dac8ee7f4bcdf3e74fcbc0455a04be0211f. Many thanks to @dserodio! --- .functions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.functions b/.functions index d3ae86050bf..f440be4994b 100644 --- a/.functions +++ b/.functions @@ -82,7 +82,7 @@ function gz() { # Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL. # Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!) function httpcompression() { - encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" + local encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" } # Syntax-highlight JSON strings or files @@ -126,15 +126,15 @@ function getcertnames() { return 1 fi - domain="${1}" + local domain="${1}" echo "Testing ${domain}…" echo # newline - tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ + local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ | openssl s_client -connect "${domain}:443" 2>&1); if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then - certText=$(echo "${tmp}" \ + local certText=$(echo "${tmp}" \ | openssl x509 -text -certopt "no_header, no_serial, no_version, \ no_signame, no_validity, no_issuer, no_pubkey, no_sigdump, no_aux"); echo "Common Name:" @@ -144,7 +144,7 @@ function getcertnames() { echo "Subject Alternative Name(s):" echo # newline echo "${certText}" | grep -A 1 "Subject Alternative Name:" \ - | head -2 | tail -1 | sed "s/DNS://g" | sed "s/ //g" | tr "," "\n" + | sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2 return 0 else echo "ERROR: Certificate not found.";