diff options
-rw-r--r-- | R_on_Cloud/default_config.py | 7 | ||||
-rw-r--r-- | R_on_Cloud/settings.py | 3 | ||||
-rw-r--r-- | instances.py | 5 | ||||
-rw-r--r-- | requirments.txt | 66 | ||||
-rw-r--r-- | static/website/js/cloud.js | 53 | ||||
-rw-r--r-- | static/website/templates/index.html | 27 | ||||
-rw-r--r-- | tornado_main.py | 6 |
7 files changed, 151 insertions, 16 deletions
diff --git a/R_on_Cloud/default_config.py b/R_on_Cloud/default_config.py index ad4aee5..6ad9982 100644 --- a/R_on_Cloud/default_config.py +++ b/R_on_Cloud/default_config.py @@ -7,11 +7,16 @@ DB_HOST_DEFAULT = '' DB_PORT_DEFAULT = '' -BIN = '/usr/bin/R' +BIN = '/usr/bin/R' # Path of R bin file API_URL = "http://127.0.0.1:8001/rscript" API_URL_PLOT = "http://127.0.0.1:8001/file" +ALLOWED_HOST_IP = ['Host IP'] + +TORNADO_IP = '0.0.0.0' +TORNADO_PORT = '8000' # default port + SECRET_KEY_STRING = SECRET_KEY # request_count keeps track of the number of requests at hand, it is incremented diff --git a/R_on_Cloud/settings.py b/R_on_Cloud/settings.py index f245582..cf9de2d 100644 --- a/R_on_Cloud/settings.py +++ b/R_on_Cloud/settings.py @@ -27,7 +27,7 @@ SECRET_KEY = SECRET_KEY_STRING # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ALLOWED_HOST_IP # Application definition @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'website', ] MIDDLEWARE = [ diff --git a/instances.py b/instances.py index 9eebbd0..c57d164 100644 --- a/instances.py +++ b/instances.py @@ -26,11 +26,12 @@ def execute_code(code, session_id, R_file_id): system_commands = re.compile( r'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|' r'unix_x\(.*\)|unix_s\(.*\)|host|newfun' - r'|execstr|ascii|mputl|dir\(\)' + r'|execstr|ascii|mputl|dir\(\)|' + r'system\(.*\)|system.call\(.*\)' ) if system_commands.search(code): return { - 'output': 'System Commands not allowed', + 'output': 'System Commands are not allowed', } code = re.sub(r"View\(", "print(", code) diff --git a/requirments.txt b/requirments.txt new file mode 100644 index 0000000..15033d9 --- /dev/null +++ b/requirments.txt @@ -0,0 +1,66 @@ +atomicwrites==1.3.0 +attrs==19.1.0 +autopep8==1.4.4 +backports.ssl-match-hostname==3.7.0.1 +certifi==2019.6.16 +cffi==1.12.3 +chardet==3.0.4 +defusedxml==0.6.0 +Django==2.2.2 +django-dajax==0.9.2 +django-dajaxice==0.7 +futures==3.1.1 +get==2019.4.13 +gitdb2==2.0.5 +GitPython==2.1.11 +h2==2.6.2 +hpack==3.0.0 +hyper==0.7.0 +hyperframe==3.2.0 +idna==2.8 +importlib-metadata==0.18 +Jinja2==2.10.1 +MarkupSafe==1.1.1 +more-itertools==7.0.0 +mysqlclient==1.4.2.post1 +numpy==1.16.4 +oauthlib==3.0.1 +packaging==19.0 +pandas==0.24.2 +pexpect==4.7.0 +pluggy==0.12.0 +post==2019.4.13 +postgres==2.2.2 +psutil==5.6.3 +psycopg2-binary==2.8.3 +ptyprocess==0.6.0 +public==2019.4.13 +py==1.8.0 +pycodestyle==2.5.0 +pycparser==2.19 +PyJWT==1.7.1 +PyMySQL==0.9.3 +pyparsing==2.4.0 +pytest==4.6.3 +python-dateutil==2.8.0 +python-openid==2.2.5 +python-social-auth==0.3.6 +python-utils==2.3.0 +python3-openid==3.1.0 +pytz==2019.1 +query-string==2019.4.13 +request==2019.4.13 +requests==2.22.0 +requests-oauthlib==1.2.0 +rpy2==3.0.4 +simplegeneric==0.8.1 +simplejson==3.16.0 +six==1.12.0 +smmap2==2.0.5 +social-auth-app-django==3.1.0 +social-auth-core==3.2.0 +sqlparse==0.3.0 +tornado==6.0.2 +urllib3==1.25.3 +wcwidth==0.1.7 +zipp==0.5.1 diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js index fc0bbfc..7d7d5dd 100644 --- a/static/website/js/cloud.js +++ b/static/website/js/cloud.js @@ -1005,13 +1005,50 @@ $(document.body).ready(function() { e.preventDefault(); }); - //on hover pop the disclaimer - /* - $("#disclaimer").hover(function() { - $('#disclaimer-text').modal({ - show: true - }); - }); - */ + +$(document).on("click", "#fileuploadsubmit", function() { + + if(confirm("Uploaded file last only till sesstion. Use direct file name for execution.")){ + var name = doSubmit(); + $("<span>" + name + "</span>").insertAfter("#uploaddataset"); + $("#uploaddatasetModal").modal('hide'); + $("#uploaddataset").hide(); + } + else{ + return false; + } + + + +}); + +$(document).on("click", "#reset", function() { + if(confirm("Are you sure you want to reset? Reset will clear of your data/uploaded file.")){ + document.location.reload(true); + } + else{ + return false; + } +}); }); //document.readOnly() + +function doSubmit(){ + // Form Data + var formData = new FormData(); + + var fileSelect = document.getElementById("fileSelect"); + if(fileSelect.files && fileSelect.files.length == 1){ + var file = fileSelect.files[0] + formData.set("file", file , file.name); + } + + var session_id = document.getElementById("session_id"); + formData.set("session_id", session_id.value) + // Http Request + var request = new XMLHttpRequest(); + request.open('POST', "http://10.101.201.190:8001/upload"); + request.send(formData); + return (fileSelect.files[0].name); +} + diff --git a/static/website/templates/index.html b/static/website/templates/index.html index 56989ab..d34f097 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -215,6 +215,29 @@ <br> <input type="hidden" id="session_id" name="session_id" value="{{ session_id }}"> <a id="execute" class="btn btn-dark text-white"><span id="execute-inner">Execute</span></a> + <!-- Trigger the modal with a button --> + <button id="uploaddataset" type="button" class="btn btn-dark text-white" data-toggle="modal" data-target="#uploaddatasetModal">Upload Dataset</button> + <button id="reset" type="button" class="btn btn-dark text-white" data-dismiss="modal">Reset</button> + + <!-- Modal --> + <div class="modal fade" id="uploaddatasetModal" role="dialog"> + <div class="modal-dialog"> + <!-- Modal content--> + <div class="modal-content"> + <div class="modal-header"> + </div> + <div class="modal-body"> + <form> + <input type="file" id="fileSelect" accept="text/csv" /> + <button id="fileuploadsubmit" type="button" >Upload</button> + </form> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> + </div> + </div> + </div> + </div> </div> </div> @@ -571,14 +594,14 @@ </div> </div> <!-- Global site tag (gtag.js) - Google Analytics --> - <script async src="https://www.googletagmanager.com/gtag/js?id=UA-82999923-4"></script> + <!-- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-82999923-4"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-82999923-4'); - </script> + </script> --> <!-- -- diff wrapper ends---------------------------------- --> <script src="{% static 'website/bootstrap-4.1.0/js/jquery.min.js' %}"></script> <script src="{% static 'website/bootstrap-4.1.0/js/popper.min.js' %}"></script> diff --git a/tornado_main.py b/tornado_main.py index 8b542a9..7683e85 100644 --- a/tornado_main.py +++ b/tornado_main.py @@ -43,8 +43,10 @@ from tornado import gen from instances import execute_code import threading import pwd +from R_on_Cloud.config import TORNADO_IP, TORNADO_PORT -define('port', type=int, default=8000) +define('port', type=int, default=TORNADO_PORT) +define("ip", default=TORNADO_IP, help="Run on any given IP", type=str) # Custom settings from R_on_Cloud.settings import PROJECT_DIR @@ -140,7 +142,7 @@ def main(): ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)), ], debug=False) server = tornado.httpserver.HTTPServer(tornado_app) - server.listen(options.port) + server.listen(options.port, options.ip) try: |