Skip to content

Instantly share code, notes, and snippets.

@ojasookert
Last active October 14, 2021 14:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojasookert/a25953347820a61b50e732fe561495f8 to your computer and use it in GitHub Desktop.
Save ojasookert/a25953347820a61b50e732fe561495f8 to your computer and use it in GitHub Desktop.
A crude script to extract Meteor methods exposed to the client
#!/bin/bash
# A crude script to extract Meteor methods exposed to the client.
#
# Be sure to have npm and js-beautify installed.
# - $ npm install -g js-beautify
#
# Tested on:
# - GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
# - Meteor 1.8.1
# - npm 3.5.2
# - js-beautify@1.10.1
# @author Kert Ojasoo
# Created: July 31, 2019
while getopts ":u:" opt; do
case $opt in
u) JS_URL="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [[ "$JS_URL" == "" ]]; then
echo "Meteor Methods Scraper"
echo "Usage:"
echo "$0 -u 'http://localhost:3000/355e110bdcdb733c64348b706c8a03d6848604c4.js' "
exit 1
fi
npm list -g | grep js-beautify > /dev/null || npm i -g js-beautify
if [ $? -ne 0 ]; then echo "Could not find js-beautify, exiting..." ; exit 1 ; fi
TEMP="site.js" # $(mktemp)
echo "Downloading '$JS_URL' to '$TEMP'..."
curl -s -o $TEMP.1 $JS_URL
echo "Extracting application specific code..."
grep -ve '^$' $TEMP.1 | tail -1 > $TEMP.2
echo "Beautifing javascript..."
js-beautify $TEMP.2 > $TEMP.3
cp $TEMP.3 $TEMP
echo "Finding methods from '.call(\"'..."
METHODS=$(grep -oP '(?<!Spacebars)\.call\(".*$' $TEMP.3 | cut -d '"' -f 2)
echo "$METHODS" > $TEMP.methods
echo "Sorting found methods..."
GREEN='\033[1;32m'
NC='\033[0m'
for method in $(cat $TEMP.methods | sort | uniq); do
echo -e "${GREEN}$method${NC}"
done
echo "Cleaning temporary files..."
rm $TEMP.*
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment