0 Replies - 1208 Views - Last Post: 31 August 2012 - 12:13 PM

#1 G0rman  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 46
  • Joined: 16-October 11

Automated remote webform submission using curl

Posted 31 August 2012 - 12:13 PM

Description: This simple, fun script uses codepad.org to compile/interpret and execute a script.

The principles outlined in this snippets can be used to automatically log in to websites, run search queries, even reply to this snippet using command line.

By scraping the output and aliasing the command, you could pretend to have a Ocaml compiler, which is nice if you need a quick Ocaml compilers (I know, it happens all the time).

$ wget http://dl.dropbox.co.../remote_compile
$ chmod +x remote_compile
$ echo "print "Hello, World"" >> helloworld.py
$ ./remote_compile
Incorrect number of arguments passed!
Usage: ./remote_compile FILE LANGUAGE
$ ./remote_compile helloworld.py Java
Unsupported language!
Supported languages are:
C, C++, D, haskell, Lua, OCaml, PHP, Perl, Plain Text, Python, Ruby, Scheme, Tcl
$ ./remote_compile helloworld.py Python

Language and file arguments correct, preparing to compile
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
130 237 100 237 0 73 148 45 0:00:01 0:00:01 --:--:-- 415

Compiling completed.
Please visit http://codepad.org/9Vb8NEeA to view code.
$ wget codepad.org/9Vb8NEeA -O - 2>/dev/null | grep "^Hello, .*$" -o
Hello, World
$ echo "Yup, proof that it works. Well, close enough..."
Yup, proof that it works. Well, close enough...A script showing how to populate and submit a webform, and scrape the output. The script actually uploads and compiles a source file using codepad.org and returns the link to view the code.
if [ ! "$#" = 2 ]; then
	echo "Incorrect number of arguments passed!"
	echo "Usage: ./remote_compile FILE LANGUAGE"
	exit 0
fi

if [ ! -f "$1" ]; then
	echo "ERROR: script file not found!"
	exit 0;
fi

if [ "$2" = "C" -o "$2" = "C++" -o "$2" = "D" -o "$2" = "Haskell" -o "$2" = "Lua" -o "$2" = "OCaml" -o "$2" = "PHP" -o "$2" = "Perl" -o "$2" = "Plain Text" -o "$2" = "Python" -o "$2" = "Ruby" -o "$2" = "Scheme" -o "$2" = "Tcl" ]; then
	echo "Language and file arguments correct, preparing to compile"
else
	echo "Unsupported language!"
	echo "Supported languages are:"
	echo "C, C++, D, haskell, Lua, OCaml, PHP, Perl, Plain Text, Python, Ruby, Scheme, Tcl"
	exit 0;
fi

SCRIPT=script

cp $1 $SCRIPT

output=`curl -d "lang=$2&run=True&submit=Submit" --data-urlencode [email protected] codepad.org`
rm $SCRIPT
url=`echo "$output" | grep -o -m 1 'http://codepad.org/[a-zA-Z0-9]*' | head -1`
echo ""

if [ -z "$url" ] ; then
	echo "ERROR: An error occured and the compiling could no be completed. Please try again later."	
else
	echo "Compiling completed."
	echo "Please visit" $url "to view code."
fi



Is This A Good Question/Topic? 0
  • +

Page 1 of 1