Python Based CLI Utility tool for eLab, SRM University
'''
How to Run:
$ python elab.py -sess <PHP Session ID from Cookies> --level 3 -qid 2 --code 1.c --input 1.test.c --eval 0 # Checks the code for level3 question 2
$ python elab.py -sess <PHP Session ID from Cookies> --level 3 -qid 2 --code 1.c --input 1.test.c --eval 1 # Evaluate the code for level3 question 2
'''
import requests
import argparse
import urllib2 as ul
def call(sess, level, qid, code, inp, eval_):
url = ""
if eval_:
print "Evaluating..."
url = "http://ulc.srmuniv.ac.in/elab/login/student/code/c/code.evaluate.elab.php"
else:
print "Checking..."
url = "http://ulc.srmuniv.ac.in/elab/login/student/code/c/code.check.elab.php"
payload = "code="+ul.quote(code)+"&input="+ul.quote(inp)
headers = {
'pragma': "no-cache",
'origin': "http://ulc.srmuniv.ac.in",
'accept-encoding': "gzip, deflate",
'accept-language': "en-US,en;q=0.8",
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
'content-type': "application/x-www-form-urlencoded; charset=UTF-8",
'accept': "application/json, text/javascript, */*; q=0.01",
'cache-control': "no-cache",
'x-requested-with': "XMLHttpRequest",
'cookie': "__utma=207659728.1341786413.1437904906.1450973325.1470856326.35; _ga=GA1.3.1341786413.1437904906; PHPSESSID="+sess,
'connection': "keep-alive",
'referer': "http://ulc.srmuniv.ac.in/elab/login/student/code/c/c.code.php?id="+str(level)+"&value="+str(qid),
'save-data': "on"
}
print "Waiting For Response..."
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="eLab Request Handler")
parser.add_argument('-sess', '--sessionId', type=str, help="PHP Session ID")
parser.add_argument('-l', '--level', type=int, help="Level number")
parser.add_argument('-qid', '--questionId', type=int, help="Question ID")
parser.add_argument('-sc', '--code', type=str, help="Source Code File Name")
parser.add_argument('-i', '--input', type=str, help="Input File Name")
parser.add_argument('--eval', type=int, help="Execute The Code")
args = parser.parse_args()
print "Source Code:", args.code
print "Test File:", args.input
print ""
with open(args.code, 'r') as scf:
with open(args.input, 'r') as inf:
call(args.sessionId, args.level, args.questionId, scf.read(), inf.read(), args.eval)