From b2dd75d68fb3e527c006d434c30c25e206971aec Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 12 Oct 2018 11:56:13 +0100 Subject: [PATCH] Use a more reliable API for evaling python --- modules/eval_python.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/eval_python.py b/modules/eval_python.py index 281cba97..f6765134 100644 --- a/modules/eval_python.py +++ b/modules/eval_python.py @@ -1,7 +1,7 @@ import socket from src import ModuleManager, utils -EVAL_URL = "https://eval.appspot.com/eval" +EVAL_URL = "https://pyeval.appspot.com/exec" class Module(ModuleManager.BaseModule): _name = "Python" @@ -12,17 +12,27 @@ class Module(ModuleManager.BaseModule): :help: Evaluate a python statement :usage: """ + id = None try: - code, page = utils.http.get_url(EVAL_URL, get_params={ - "statement": event["args"]}, code=True) - except socket.timeout: - event["stderr"].write("%s: eval timed out" % - event["user"].nickname) - return + id = utils.http.get_url(EVAL_URL, + post_data={"input": event["args"]}, + method="POST") + except: + pass - if not page == None and code == 200: - event["stdout"].write("%s: %s" % (event["user"].nickname, - page)) - else: - event["stderr"].write("%s: failed to eval" % - event["user"].nickname) + if not id == None: + try: + page = utils.http.get_url(EVAL_URL, + get_params={"id": id}, + json=True) + except socket.timeout: + event["stderr"].write("%s: eval timed out" % + event["user"].nickname) + return + + if page: + event["stdout"].write("%s: %s" % (event["user"].nickname, + page["output"].strip("\n"))) + return + + event["stderr"].write("%s: failed to eval" % event["user"].nickname)