1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +00:00

Unblock script checks if own network is blocked

This commit is contained in:
Cadence Ember 2020-06-19 18:27:58 +12:00
parent 6e1e5e6996
commit 36530e5db4
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
3 changed files with 28 additions and 7 deletions

View File

@ -1,4 +1,5 @@
const {Readable} = require("stream") const {Readable} = require("stream")
const fs = require("fs").promises
const db = require("../../lib/db") const db = require("../../lib/db")
const collectors = require("../../lib/collectors") const collectors = require("../../lib/collectors")
@ -189,15 +190,13 @@ module.exports = [
{ {
route: `/u/(${constants.external.username_regex})/unblock.sh`, methods: ["GET"], code: async ({fill}) => { route: `/u/(${constants.external.username_regex})/unblock.sh`, methods: ["GET"], code: async ({fill}) => {
const username = fill[0] const username = fill[0]
let script = await fs.readFile(__dirname+"/utils/unblock.sh", "utf8")
script = script.replace(/<website_origin>/g, constants.website_origin)
script = script.replace(/<username>/g, username)
return { return {
statusCode: 200, statusCode: 200,
contentType: "text/plain", contentType: "text/plain",
content: content: script
`# 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'`
} }
} }
} }

View File

@ -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/<username>/' -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=<username>' --data-urlencode 'user_id@-' '<website_origin>/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

View File

@ -24,7 +24,7 @@ html#bibliogram-identifier-blocked
| #[a(href="#unblock-on-mac-or-linux") Unblock with shell], no download, Mac and Linux only | #[a(href="#unblock-on-mac-or-linux") Unblock with shell], no download, Mac and Linux only
.hidden-section#unblock-on-mac-or-linux .hidden-section#unblock-on-mac-or-linux
p Open the Terminal application, then paste this code: 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 li
| #[a(href="#unblock-with-userscript") Unblock automatically with userscript], any modern browser | #[a(href="#unblock-with-userscript") Unblock automatically with userscript], any modern browser
.hidden-section#unblock-with-userscript .hidden-section#unblock-with-userscript