From 87b533642db245fe3c03c9b1fd8220f0f7a195f8 Mon Sep 17 00:00:00 2001 From: Jayaram R Pai Date: Thu, 4 Sep 2014 13:23:42 +0530 Subject: added timertask --- website/helpers.py | 16 ++++++---------- website/views.py | 6 ------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/website/helpers.py b/website/helpers.py index 016f2fd..f137541 100644 --- a/website/helpers.py +++ b/website/helpers.py @@ -1,14 +1,12 @@ -import os -import re -import time -import subprocess +import os, re, sys, time, subprocess from soc.settings import PROJECT_DIR +from timeout import TimerTask def scilab_run(code, token, example_id): #Check for system commands system_commands = re.compile( - 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)' + 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)|host|newfun|execstr|ascii|mputl|dir\(\)' ) if system_commands.search(code): return "System Commands not allowed" @@ -36,7 +34,6 @@ def scilab_run(code, token, example_id): file_path = PROJECT_DIR + '/static/tmp/' + token + '.sci' - #thanks @prathamesh920 github #traps even syntax errors eg: endfunton f = open(file_path, "w") f.write('mode(2);\n') @@ -50,11 +47,10 @@ def scilab_run(code, token, example_id): cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(file_path) cmd += ' | /home/cheese/scilab-5.4.1/bin/scilab-adv-cli -nw' - output = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True - ).communicate()[0] + task = TimerTask(cmd, timeout=10) + output = task.run().communicate()[0] + e = task.wait() - #os.remove(file_path) output = trim(output) data = { 'output': output, diff --git a/website/views.py b/website/views.py index 785337f..050ec92 100644 --- a/website/views.py +++ b/website/views.py @@ -82,9 +82,3 @@ def ajax_execute(request): token = request.POST['csrfmiddlewaretoken'] data = scilab_run(code, token, example_id) return render(request, 'website/templates/ajax-execute.html', data) - - - - - - -- cgit