diff --git a/src/site/api/suggest.js b/src/site/api/suggest.js index 9efb12c..f3bde03 100644 --- a/src/site/api/suggest.js +++ b/src/site/api/suggest.js @@ -1,4 +1,5 @@ const {Readable} = require("stream") +const fs = require("fs").promises const db = require("../../lib/db") const collectors = require("../../lib/collectors") @@ -189,15 +190,13 @@ module.exports = [ { route: `/u/(${constants.external.username_regex})/unblock.sh`, methods: ["GET"], code: async ({fill}) => { const username = fill[0] + let script = await fs.readFile(__dirname+"/utils/unblock.sh", "utf8") + script = script.replace(//g, constants.website_origin) + script = script.replace(//g, username) return { statusCode: 200, contentType: "text/plain", - content: - `# Good on you for looking at shell scripts before blindly running them.` - +`\n# This script contacts Instagram to get the profile's user ID, then sends the ID to Bibliogram. Bibliogram can take over from there.` - +`\ncurl 'https://www.instagram.com/${username}/' -Ss | grep -oE '"id":"[0-9]+"'` - +` | head -n 1 | grep -oE '[0-9]+' | curl --data-urlencode 'username=${username}' --data-urlencode 'user_id@-'` - +` '${constants.website_origin}/api/suggest_user/v1?plaintext=1'` + content: script } } } diff --git a/src/site/api/utils/unblock.sh b/src/site/api/utils/unblock.sh new file mode 100644 index 0000000..3e5b568 --- /dev/null +++ b/src/site/api/utils/unblock.sh @@ -0,0 +1,22 @@ +# Good on you for looking at shell scripts before blindly running them. +# This script contacts Instagram to get the profile's user ID, then sends the ID to Bibliogram. Bibliogram can take over from there. + +# Make a temporary directory +tempdir=$(mktemp -d) || exit 1 + +# Try to request from Instagram +curl 'https://www.instagram.com//' -Ss > $tempdir/page.html + +if test -s $tempdir/page.html; then + # Request returned a page (file not empty) + grep -oE '"id":"[0-9]+"' $tempdir/page.html | head -n 1 | grep -oE '[0-9]+' | curl --data-urlencode 'username=' --data-urlencode 'user_id@-' '/api/suggest_user/v1?plaintext=1' +else + # Request was a redirect + echo "Your network is blocked by Instagram." + echo "You won't be able to unblock any more profiles." + echo "To be unblocked, wait a few hours without running this script." +fi + +# Clean up, safely. +rm -f $tempdir/page.html +rm -d $tempdir diff --git a/src/site/pug/blocked.pug b/src/site/pug/blocked.pug index 188a8d0..8fd693a 100644 --- a/src/site/pug/blocked.pug +++ b/src/site/pug/blocked.pug @@ -24,7 +24,7 @@ html#bibliogram-identifier-blocked | #[a(href="#unblock-on-mac-or-linux") Unblock with shell], no download, Mac and Linux only .hidden-section#unblock-on-mac-or-linux p Open the Terminal application, then paste this code: - pre curl -Ss #{website_origin}/u/#{username}/unblock.sh | $SHELL + pre curl -Ss #{website_origin}/u/#{username}/unblock.sh | bash li | #[a(href="#unblock-with-userscript") Unblock automatically with userscript], any modern browser .hidden-section#unblock-with-userscript