#!/bin/bash echo "Content-type: application/json" echo url="$(echo -n "$REQUEST_URI" | sed "s/^\/cgi-bin\/json?url=//g")" if ! [[ "$url" =~ ^https?:// ]] && ! [[ "$url" =~ ^ipfs:// ]]; then echo "Error: Invalid link." else if [[ "$url" =~ ^https?://(localhost|127\.|10\.|172\.16\.|172\.17\.|172\.18\.|172\.19\.|172\.20\.|172\.21\.|172\.22\.|172\.23\.|172\.24\.|172\.25\.|172\.26\.|172\.27\.|172\.28\.|172\.29\.|172\.30\.|172\.31\.|192\.168\.|169\.254\.) ]]; then echo "Error: Nonpublic URL" else # Not "curl -L" as some websites redirect to localhost if [[ "$url" =~ ^ipfs:// ]]; then url2="$(echo "$url" | sed "s/^ipfs../http:\/\/127.0.0.1:8080\/ipfs\//g")" curl -sk --max-redirs 0 "$url2" | jq else curl -sk --max-redirs 0 "$url" | jq fi fi fi